Skip to content

Commit

Permalink
* Schedule initialisation of Server to not mix with OpenThread Platfo…
Browse files Browse the repository at this point in the history
…rmEvents

* Only open commissioning window when no fabric exists (lighting-app)
  • Loading branch information
tima-q committed Jul 14, 2022
1 parent 64828b3 commit 77d33c2
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 58 deletions.
5 changes: 3 additions & 2 deletions examples/lighting-app/qpg/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ class AppTask
friend AppTask & GetAppTask(void);

CHIP_ERROR Init();
static void InitServer(intptr_t arg);
static void OpenCommissioning(intptr_t arg);

static void ActionInitiated(LightingManager::Action_t aAction);
static void ActionCompleted(LightingManager::Action_t aAction);

void CancelTimer(void);

void DispatchEvent(AppEvent * event);

static void FunctionTimerEventHandler(AppEvent * aEvent);
Expand All @@ -63,6 +63,7 @@ class AppTask
static void TimerEventHandler(chip::System::Layer * aLayer, void * aAppState);

void StartTimer(uint32_t aTimeoutMs);
void CancelTimer(void);

enum Function_t
{
Expand Down
73 changes: 42 additions & 31 deletions examples/lighting-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>

using namespace chip::TLV;
using namespace chip::Credentials;
using namespace chip::DeviceLayer;
using namespace ::chip::TLV;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceLayer;

#include <platform/CHIPDeviceLayer.h>

Expand Down Expand Up @@ -208,28 +208,8 @@ CHIP_ERROR AppTask::StartAppTask()
return CHIP_NO_ERROR;
}

CHIP_ERROR AppTask::Init()
void AppTask::InitServer(intptr_t arg)
{
CHIP_ERROR err = CHIP_NO_ERROR;

ChipLogProgress(NotSpecified, "Current Software Version: %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING);

err = LightingMgr().Init();
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "LightingMgr().Init() failed");
return err;
}
LightingMgr().SetCallbacks(ActionInitiated, ActionCompleted);

// Subscribe with our button callback to the qvCHIP button handler.
qvIO_SetBtnCallback(ButtonEventHandler);

#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY
chip::app::DnssdServer::Instance().SetExtendedDiscoveryTimeoutSecs(extDiscTimeoutSecs);
#endif

// Init ZCL Data Model
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();

Expand All @@ -243,21 +223,52 @@ CHIP_ERROR AppTask::Init()
initParams.endpointNativeParams = static_cast<void *>(&nativeParams);
chip::Server::GetInstance().Init(initParams);

// Init OTA engine
InitializeOTARequestor();
#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY
chip::app::DnssdServer::Instance().SetExtendedDiscoveryTimeoutSecs(extDiscTimeoutSecs);
#endif

// Open commissioning after boot if no fabric was available
if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0)
{
PlatformMgr().ScheduleWork(OpenCommissioning, 0);
}
}

void AppTask::OpenCommissioning(intptr_t arg)
{
// Enable BLE advertisements
chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow();
ChipLogProgress(NotSpecified, "BLE advertising started. Waiting for Pairing.");
}

CHIP_ERROR AppTask::Init()
{
CHIP_ERROR err = CHIP_NO_ERROR;

ChipLogProgress(NotSpecified, "Current Software Version: %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING);

// Init ZCL Data Model and start server
PlatformMgr().ScheduleWork(InitServer, 0);

// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());

UpdateClusterState();
// Setup light
err = LightingMgr().Init();
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "LightingMgr().Init() failed");
return err;
}
LightingMgr().SetCallbacks(ActionInitiated, ActionCompleted);

// Setup button handler
qvIO_SetBtnCallback(ButtonEventHandler);

// Log device configuration
ConfigurationMgr().LogDeviceConfig();
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));

// Enable BLE advertisements
chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow();
ChipLogProgress(NotSpecified, "BLE advertising started. Waiting for Pairing.");

return err;
}

Expand Down
1 change: 1 addition & 0 deletions examples/lock-app/qpg/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class AppTask
friend AppTask & GetAppTask(void);

CHIP_ERROR Init();
static void InitServer(intptr_t arg);

static void ActionInitiated(BoltLockManager::Action_t aAction, int32_t aActor);
static void ActionCompleted(BoltLockManager::Action_t aAction);
Expand Down
52 changes: 27 additions & 25 deletions examples/lock-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,30 +108,8 @@ CHIP_ERROR AppTask::StartAppTask()
return CHIP_NO_ERROR;
}

CHIP_ERROR AppTask::Init()
void AppTask::InitServer(intptr_t arg)
{
CHIP_ERROR err = CHIP_NO_ERROR;

ChipLogProgress(NotSpecified, "Current Software Version: %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING);

err = BoltLockMgr().Init();
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "BoltLockMgr().Init() failed");
return err;
}
BoltLockMgr().SetCallbacks(ActionInitiated, ActionCompleted);

// Subscribe with our button callback to the qvCHIP button handler.
qvIO_SetBtnCallback(ButtonEventHandler);

qvIO_LedSet(LOCK_STATE_LED, !BoltLockMgr().IsUnlocked());

#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY
chip::app::DnssdServer::Instance().SetExtendedDiscoveryTimeoutSecs(extDiscTimeoutSecs);
#endif

// Init ZCL Data Model
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();

Expand All @@ -145,12 +123,36 @@ CHIP_ERROR AppTask::Init()
initParams.endpointNativeParams = static_cast<void *>(&nativeParams);
chip::Server::GetInstance().Init(initParams);

// Init OTA engine
InitializeOTARequestor();
#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY
chip::app::DnssdServer::Instance().SetExtendedDiscoveryTimeoutSecs(extDiscTimeoutSecs);
#endif
}
CHIP_ERROR AppTask::Init()
{
CHIP_ERROR err = CHIP_NO_ERROR;

ChipLogProgress(NotSpecified, "Current Software Version: %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING);

// Init ZCL Data Model and start server
PlatformMgr().ScheduleWork(InitServer, 0);

// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());

// Setup Bolt
err = BoltLockMgr().Init();
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "BoltLockMgr().Init() failed");
return err;
}
BoltLockMgr().SetCallbacks(ActionInitiated, ActionCompleted);

// Setup button handler
qvIO_SetBtnCallback(ButtonEventHandler);

qvIO_LedSet(LOCK_STATE_LED, !BoltLockMgr().IsUnlocked());

UpdateClusterState();

ConfigurationMgr().LogDeviceConfig();
Expand Down

0 comments on commit 77d33c2

Please sign in to comment.