33
33
34
34
// VendorId of the Endpoint on the CastingPlayer that the CastingApp desires to interact with after connection
35
35
const uint16_t kDesiredEndpointVendorId = 65521 ;
36
+ // EndpointId of the Endpoint on the CastingPlayer that the CastingApp desires to interact with after connection using the
37
+ // Commissioner-Generated passcode commissioning flow
38
+ const uint8_t kDesiredEndpointId = 1 ;
39
+ // Indicates that the Commissioner-Generated passcode commissioning flow is in progress.
40
+ bool gCommissionerGeneratedPasscodeFlowRunning = false ;
36
41
37
42
DiscoveryDelegateImpl * DiscoveryDelegateImpl::_discoveryDelegateImpl = nullptr ;
38
43
bool gAwaitingCommissionerPasscodeInput = false ;
@@ -244,6 +249,16 @@ CHIP_ERROR InitCommissionableDataProvider(LinuxCommissionableDataProvider & prov
244
249
options.payload .discriminator .GetLongValue ());
245
250
}
246
251
252
+ void LogEndpointsDetails (const std::vector<matter::casting::memory::Strong<matter::casting::core::Endpoint>> & endpoints)
253
+ {
254
+ ChipLogProgress (AppServer, " simple-app-helper.cpp::LogEndpointsDetails() Number of Endpoints: %d" ,
255
+ static_cast <int >(endpoints.size ()));
256
+ for (const auto & endpoint : endpoints)
257
+ {
258
+ endpoint->LogDetail ();
259
+ }
260
+ }
261
+
247
262
void ConnectionHandler (CHIP_ERROR err, matter::casting::core::CastingPlayer * castingPlayer)
248
263
{
249
264
ChipLogProgress (AppServer, " simple-app-helper.cpp::ConnectionHandler()" );
@@ -256,23 +271,51 @@ void ConnectionHandler(CHIP_ERROR err, matter::casting::core::CastingPlayer * ca
256
271
" simple-app-helper.cpp::ConnectionHandler(): Failed to connect to CastingPlayer (ID: %s) with err %" CHIP_ERROR_FORMAT,
257
272
targetCastingPlayer->GetId (), err.Format ()));
258
273
259
- ChipLogProgress (AppServer, " simple-app-helper.cpp::ConnectionHandler(): Successfully connected to CastingPlayer (ID: %s)" ,
260
- castingPlayer->GetId ());
261
- ChipLogProgress (AppServer,
262
- " simple-app-helper.cpp::ConnectionHandler(): Triggering demo interactions with CastingPlayer (ID: %s)" ,
263
- castingPlayer->GetId ());
274
+ if (gCommissionerGeneratedPasscodeFlowRunning )
275
+ {
276
+ ChipLogProgress (AppServer,
277
+ " simple-app-helper.cpp::ConnectionHandler(): Successfully connected to CastingPlayer (ID: %s) using "
278
+ " Commissioner-Generated passcode" ,
279
+ castingPlayer->GetId ());
280
+ ChipLogProgress (AppServer, " simple-app-helper.cpp::ConnectionHandler(): Desired Endpoint ID for demo interactions: 1" );
281
+ }
282
+ else
283
+ {
284
+ ChipLogProgress (AppServer, " simple-app-helper.cpp::ConnectionHandler(): Successfully connected to CastingPlayer (ID: %s)" ,
285
+ castingPlayer->GetId ());
286
+ ChipLogProgress (AppServer,
287
+ " simple-app-helper.cpp::ConnectionHandler(): Desired Endpoint Vendor ID for demo interactions: %d" ,
288
+ kDesiredEndpointVendorId );
289
+ }
264
290
291
+ ChipLogProgress (AppServer, " simple-app-helper.cpp::ConnectionHandler(): Getting endpoints avaiable for demo interactions" );
265
292
std::vector<matter::casting::memory::Strong<matter::casting::core::Endpoint>> endpoints = castingPlayer->GetEndpoints ();
293
+ LogEndpointsDetails (endpoints);
294
+
266
295
// Find the desired Endpoint and auto-trigger some Matter Casting demo interactions
267
296
auto it = std::find_if (endpoints.begin (), endpoints.end (),
268
297
[](const matter::casting::memory::Strong<matter::casting::core::Endpoint> & endpoint) {
298
+ if (gCommissionerGeneratedPasscodeFlowRunning )
299
+ {
300
+ // For the example Commissioner-Generated passcode commissioning flow, run demo interactions with
301
+ // the Endpoint with ID 1. For this flow, we commissioned with the Target Content Application
302
+ // with Vendor ID 1111. Since this target content application does not report its Endpoint's
303
+ // Vendor IDs, we find the desired endpoint based on the Endpoint ID. See
304
+ // connectedhomeip/examples/tv-app/tv-common/include/AppTv.h.
305
+ return endpoint->GetId () == kDesiredEndpointId ;
306
+ }
269
307
return endpoint->GetVendorId () == kDesiredEndpointVendorId ;
270
308
});
271
309
if (it != endpoints.end ())
272
310
{
273
311
// The desired endpoint is endpoints[index]
274
312
unsigned index = (unsigned int ) std::distance (endpoints.begin (), it);
275
313
314
+ ChipLogProgress (
315
+ AppServer,
316
+ " simple-app-helper.cpp::ConnectionHandler(): Triggering demo interactions with CastingPlayer (ID: %s). Endpoint ID: %d" ,
317
+ castingPlayer->GetId (), endpoints[index ]->GetId ());
318
+
276
319
// demonstrate invoking a command
277
320
InvokeContentLauncherLaunchURL (endpoints[index ]);
278
321
@@ -286,8 +329,8 @@ void ConnectionHandler(CHIP_ERROR err, matter::casting::core::CastingPlayer * ca
286
329
{
287
330
ChipLogError (
288
331
AppServer,
289
- " simple-app-helper.cpp::ConnectionHandler():Desired Endpoint Vendor Id (%d) not found on the CastingPlayer (ID: %s)" ,
290
- kDesiredEndpointVendorId , castingPlayer->GetId ());
332
+ " simple-app-helper.cpp::ConnectionHandler():Desired Endpoint Vendor ID not found on the CastingPlayer (ID: %s)" ,
333
+ castingPlayer->GetId ());
291
334
}
292
335
}
293
336
@@ -350,9 +393,14 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
350
393
ChipLogError (AppServer, " Invalid casting player index provided: %lu" , index ));
351
394
targetCastingPlayer = castingPlayers.at (index );
352
395
396
+ gCommissionerGeneratedPasscodeFlowRunning = false ;
353
397
matter::casting::core::IdentificationDeclarationOptions idOptions;
398
+ chip::Protocols::UserDirectedCommissioning::TargetAppInfo targetAppInfo;
399
+ targetAppInfo.vendorId = kDesiredEndpointVendorId ;
400
+
354
401
if (argc == 3 )
355
402
{
403
+
356
404
if (strcmp (argv[2 ], " commissioner-generated-passcode" ) == 0 )
357
405
{
358
406
// Attempt Commissioner-Generated Passcode (commissioner-generated-passcode) commissioning flow only if the
@@ -364,6 +412,14 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
364
412
" Commissioner-Generated Passcode commissioning flow" ,
365
413
index );
366
414
idOptions.mCommissionerPasscode = true ;
415
+
416
+ // For the example Commissioner-Generated passcode commissioning flow, override the default Target Content
417
+ // Application Vendor ID, which is configured on the tv-app. This Target Content Application Vendor ID (1111),
418
+ // does not implement the AccountLogin cluster, which would otherwise auto commission using the
419
+ // Commissionee-Generated passcode upon recieving the IdentificationDeclaration Message. See
420
+ // connectedhomeip/examples/tv-app/tv-common/include/AppTv.h.
421
+ targetAppInfo.vendorId = 1111 ;
422
+ gCommissionerGeneratedPasscodeFlowRunning = true ;
367
423
}
368
424
else
369
425
{
@@ -374,9 +430,8 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
374
430
}
375
431
}
376
432
}
377
- chip::Protocols::UserDirectedCommissioning::TargetAppInfo targetAppInfo;
378
- targetAppInfo.vendorId = kDesiredEndpointVendorId ;
379
- CHIP_ERROR result = idOptions.addTargetAppInfo (targetAppInfo);
433
+
434
+ CHIP_ERROR result = idOptions.addTargetAppInfo (targetAppInfo);
380
435
if (result != CHIP_NO_ERROR)
381
436
{
382
437
ChipLogError (AppServer, " CommandHandler() request, failed to add targetAppInfo: %" CHIP_ERROR_FORMAT, result.Format ());
@@ -430,11 +485,8 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
430
485
err.Format ());
431
486
}
432
487
433
- matter::casting::core::ConnectionCallbacks connectionCallbacks;
434
- connectionCallbacks.mOnConnectionComplete = ConnectionHandler;
435
-
436
488
// Continue Connecting to the target CastingPlayer with the user entered Commissioner-generated Passcode.
437
- targetCastingPlayer->ContinueConnecting (connectionCallbacks, matter::casting::core:: kCommissioningWindowTimeoutSec );
489
+ targetCastingPlayer->ContinueConnecting ();
438
490
}
439
491
else
440
492
{
0 commit comments