Skip to content

Commit 5433f31

Browse files
Merge branch 'master' into idm-4.2-troubleshoot
2 parents e65e4cd + c3ef110 commit 5433f31

26 files changed

+416
-256
lines changed

examples/fabric-bridge-app/linux/main.cpp

+35-49
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <app/ConcreteAttributePath.h>
2727
#include <app/EventLogging.h>
2828
#include <app/reporting/reporting.h>
29+
#include <app/server/Server.h>
2930
#include <app/util/af-types.h>
3031
#include <app/util/attribute-storage.h>
3132
#include <app/util/endpoint-config-api.h>
@@ -39,16 +40,14 @@
3940
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
4041
#include <setup_payload/SetupPayload.h>
4142

42-
#include <pthread.h>
43-
#include <sys/ioctl.h>
44-
4543
#include "CommissionableInit.h"
4644
#include "Device.h"
47-
#include <app/server/Server.h>
4845

4946
#include <cassert>
5047
#include <iostream>
5148
#include <string>
49+
#include <sys/ioctl.h>
50+
#include <thread>
5251

5352
using namespace chip;
5453
using namespace chip::app;
@@ -58,12 +57,41 @@ using namespace chip::Transport;
5857
using namespace chip::DeviceLayer;
5958
using namespace chip::app::Clusters;
6059

60+
#define POLL_INTERVAL_MS (100)
61+
6162
namespace {
6263

6364
EndpointId gCurrentEndpointId;
6465
EndpointId gFirstDynamicEndpointId;
6566
Device * gDevices[CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT + 1];
6667

68+
bool KeyboardHit()
69+
{
70+
int bytesWaiting;
71+
ioctl(0, FIONREAD, &bytesWaiting);
72+
return bytesWaiting > 0;
73+
}
74+
75+
void BridgePollingThread()
76+
{
77+
while (true)
78+
{
79+
if (KeyboardHit())
80+
{
81+
int ch = getchar();
82+
if (ch == 'e')
83+
{
84+
ChipLogProgress(DeviceLayer, "Exiting.....");
85+
exit(0);
86+
}
87+
continue;
88+
}
89+
90+
// Sleep to avoid tight loop reading commands
91+
usleep(POLL_INTERVAL_MS * 1000);
92+
}
93+
}
94+
6795
} // namespace
6896

6997
// REVISION DEFINITIONS:
@@ -245,42 +273,6 @@ Protocols::InteractionModel::Status emberAfExternalAttributeWriteCallback(Endpoi
245273
return ret;
246274
}
247275

248-
#define POLL_INTERVAL_MS (100)
249-
uint8_t poll_prescale = 0;
250-
251-
bool kbhit()
252-
{
253-
int byteswaiting;
254-
ioctl(0, FIONREAD, &byteswaiting);
255-
return byteswaiting > 0;
256-
}
257-
258-
const int16_t oneDegree = 100;
259-
260-
void * bridge_polling_thread(void * context)
261-
{
262-
while (true)
263-
{
264-
if (kbhit())
265-
{
266-
int ch = getchar();
267-
268-
// Commands used for the actions bridge test plan.
269-
if (ch == 'e')
270-
{
271-
ChipLogProgress(DeviceLayer, "Exiting.....");
272-
exit(0);
273-
}
274-
continue;
275-
}
276-
277-
// Sleep to avoid tight loop reading commands
278-
usleep(POLL_INTERVAL_MS * 1000);
279-
}
280-
281-
return nullptr;
282-
}
283-
284276
void ApplicationInit()
285277
{
286278
// Clear out the device database
@@ -292,15 +284,9 @@ void ApplicationInit()
292284
static_cast<int>(emberAfEndpointFromIndex(static_cast<uint16_t>(emberAfFixedEndpointCount() - 1))) + 1);
293285
gCurrentEndpointId = gFirstDynamicEndpointId;
294286

295-
{
296-
pthread_t poll_thread;
297-
int res = pthread_create(&poll_thread, nullptr, bridge_polling_thread, nullptr);
298-
if (res)
299-
{
300-
printf("Error creating polling thread: %d\n", res);
301-
exit(1);
302-
}
303-
}
287+
// Start a thread for bridge polling
288+
std::thread pollingThread(BridgePollingThread);
289+
pollingThread.detach();
304290
}
305291

306292
void ApplicationShutdown() {}

examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/MatterCastingPlayer-JNI.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ JNI_METHOD(jobject, verifyOrEstablishConnection)
120120
matter::casting::core::ConnectionCallbacks connectionCallbacks;
121121
connectionCallbacks.mOnConnectionComplete = connectCallback;
122122

123-
// TODO: Verify why commissioningWindowTimeoutSec is a "unsigned long long int" type. Seems too big.
124-
castingPlayer->VerifyOrEstablishConnection(connectionCallbacks,
125-
static_cast<unsigned long long int>(commissioningWindowTimeoutSec), idOptions);
123+
castingPlayer->VerifyOrEstablishConnection(connectionCallbacks, static_cast<uint16_t>(commissioningWindowTimeoutSec),
124+
idOptions);
126125
return support::convertMatterErrorFromCppToJava(CHIP_NO_ERROR);
127126
}
128127

examples/tv-casting-app/linux/simple-app-helper.cpp

+66-14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333

3434
// VendorId of the Endpoint on the CastingPlayer that the CastingApp desires to interact with after connection
3535
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;
3641

3742
DiscoveryDelegateImpl * DiscoveryDelegateImpl::_discoveryDelegateImpl = nullptr;
3843
bool gAwaitingCommissionerPasscodeInput = false;
@@ -244,6 +249,16 @@ CHIP_ERROR InitCommissionableDataProvider(LinuxCommissionableDataProvider & prov
244249
options.payload.discriminator.GetLongValue());
245250
}
246251

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+
247262
void ConnectionHandler(CHIP_ERROR err, matter::casting::core::CastingPlayer * castingPlayer)
248263
{
249264
ChipLogProgress(AppServer, "simple-app-helper.cpp::ConnectionHandler()");
@@ -256,23 +271,51 @@ void ConnectionHandler(CHIP_ERROR err, matter::casting::core::CastingPlayer * ca
256271
"simple-app-helper.cpp::ConnectionHandler(): Failed to connect to CastingPlayer (ID: %s) with err %" CHIP_ERROR_FORMAT,
257272
targetCastingPlayer->GetId(), err.Format()));
258273

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+
}
264290

291+
ChipLogProgress(AppServer, "simple-app-helper.cpp::ConnectionHandler(): Getting endpoints avaiable for demo interactions");
265292
std::vector<matter::casting::memory::Strong<matter::casting::core::Endpoint>> endpoints = castingPlayer->GetEndpoints();
293+
LogEndpointsDetails(endpoints);
294+
266295
// Find the desired Endpoint and auto-trigger some Matter Casting demo interactions
267296
auto it = std::find_if(endpoints.begin(), endpoints.end(),
268297
[](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+
}
269307
return endpoint->GetVendorId() == kDesiredEndpointVendorId;
270308
});
271309
if (it != endpoints.end())
272310
{
273311
// The desired endpoint is endpoints[index]
274312
unsigned index = (unsigned int) std::distance(endpoints.begin(), it);
275313

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+
276319
// demonstrate invoking a command
277320
InvokeContentLauncherLaunchURL(endpoints[index]);
278321

@@ -286,8 +329,8 @@ void ConnectionHandler(CHIP_ERROR err, matter::casting::core::CastingPlayer * ca
286329
{
287330
ChipLogError(
288331
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());
291334
}
292335
}
293336

@@ -350,9 +393,14 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
350393
ChipLogError(AppServer, "Invalid casting player index provided: %lu", index));
351394
targetCastingPlayer = castingPlayers.at(index);
352395

396+
gCommissionerGeneratedPasscodeFlowRunning = false;
353397
matter::casting::core::IdentificationDeclarationOptions idOptions;
398+
chip::Protocols::UserDirectedCommissioning::TargetAppInfo targetAppInfo;
399+
targetAppInfo.vendorId = kDesiredEndpointVendorId;
400+
354401
if (argc == 3)
355402
{
403+
356404
if (strcmp(argv[2], "commissioner-generated-passcode") == 0)
357405
{
358406
// Attempt Commissioner-Generated Passcode (commissioner-generated-passcode) commissioning flow only if the
@@ -364,6 +412,14 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
364412
"Commissioner-Generated Passcode commissioning flow",
365413
index);
366414
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;
367423
}
368424
else
369425
{
@@ -374,9 +430,8 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
374430
}
375431
}
376432
}
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);
380435
if (result != CHIP_NO_ERROR)
381436
{
382437
ChipLogError(AppServer, "CommandHandler() request, failed to add targetAppInfo: %" CHIP_ERROR_FORMAT, result.Format());
@@ -430,11 +485,8 @@ CHIP_ERROR CommandHandler(int argc, char ** argv)
430485
err.Format());
431486
}
432487

433-
matter::casting::core::ConnectionCallbacks connectionCallbacks;
434-
connectionCallbacks.mOnConnectionComplete = ConnectionHandler;
435-
436488
// Continue Connecting to the target CastingPlayer with the user entered Commissioner-generated Passcode.
437-
targetCastingPlayer->ContinueConnecting(connectionCallbacks, matter::casting::core::kCommissioningWindowTimeoutSec);
489+
targetCastingPlayer->ContinueConnecting();
438490
}
439491
else
440492
{

0 commit comments

Comments
 (0)