Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 39 additions & 8 deletions examples/all-clusters-app/realtek/common/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ CHIP_ERROR AppTask::StartAppTask()
void AppTask::AppTaskMain(void * pvParameter)
{
uint8_t event;
CHIP_ERROR err = CHIP_NO_ERROR;

#if defined(FEATURE_TRUSTZONE_ENABLE) && (FEATURE_TRUSTZONE_ENABLE == 1)
os_alloc_secure_ctx(1024);
Expand All @@ -222,7 +223,12 @@ void AppTask::AppTaskMain(void * pvParameter)
gap_start_bt_stack(app_evt_queue_handle, app_io_queue_handle, MAX_NUMBER_OF_GAP_MESSAGE);
matter_ble_queue_init(app_evt_queue_handle, app_io_queue_handle);

sAppTask.Init();
err = sAppTask.Init();
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "sAppTask.Init() failed: %" CHIP_ERROR_FORMAT, err.Format());
return;
}

while (true)
{
Expand Down Expand Up @@ -266,6 +272,8 @@ void AppTask::AppTaskMain(void * pvParameter)

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

// Init ZCL Data Model and start server
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();
Expand All @@ -292,10 +300,19 @@ void AppTask::InitServer(intptr_t arg)
(void) initParams.InitializeStaticResourcesBeforeServerInit();
initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate;

chip::Server::GetInstance().Init(initParams);
err = chip::Server::GetInstance().Init(initParams);
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "Server::GetInstance().Init() failed: %" CHIP_ERROR_FORMAT, err.Format());
return;
}

static RealtekObserver sRealtekObserver;
chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(&sRealtekObserver);
err = chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(&sRealtekObserver);
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "AddFabricDelegate failed: %" CHIP_ERROR_FORMAT, err.Format());
}

ConfigurationMgr().LogDeviceConfig();
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
Expand Down Expand Up @@ -334,7 +351,10 @@ CHIP_ERROR AppTask::Init()
}

// Init ZCL Data Model and start server
PlatformMgr().ScheduleWork(InitServer, 0);
// ScheduleWork is asynchronous, failure means work couldn't be queued.
// Since this is init time, if it fails the system won't work anyway,
// so the return value can be safely ignored.
RETURN_SAFELY_IGNORED(PlatformMgr().ScheduleWork(InitServer, 0));

#if CONFIG_ENABLE_CHIP_SHELL
chip::Shell::Engine::Root().Init();
Expand All @@ -358,13 +378,18 @@ CHIP_ERROR AppTask::Init()

void AppTask::BLEStartAdvertising(intptr_t arg)
{
CHIP_ERROR setErr = CHIP_NO_ERROR;
if (ConnectivityMgr().IsBLEAdvertisingEnabled())
{
ConnectivityMgr().SetBLEAdvertisingEnabled(false);
setErr = ConnectivityMgr().SetBLEAdvertisingEnabled(false);
}
else
{
ConnectivityMgr().SetBLEAdvertisingEnabled(true);
setErr = ConnectivityMgr().SetBLEAdvertisingEnabled(true);
}
if (setErr != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "SetBLEAdvertisingEnabled failed: %" CHIP_ERROR_FORMAT, setErr.Format());
}
}

Expand Down Expand Up @@ -433,7 +458,10 @@ void AppTask::ButtonHandler(T_IO_MSG * p_msg)
case APP_BLE_ADV_BUTTON:
if (btnPressed)
{
PlatformMgr().ScheduleWork(AppTask::BLEStartAdvertising, 0);
// ScheduleWork is asynchronous and returns immediately.
// Failure means the work couldn't be queued, but there's nothing
// we can do about it here, so the return value can be safely ignored.
RETURN_SAFELY_IGNORED(PlatformMgr().ScheduleWork(AppTask::BLEStartAdvertising, 0));
}
break;

Expand Down Expand Up @@ -467,7 +495,10 @@ void AppTask::ButtonHandler(T_IO_MSG * p_msg)
sAppTask.CancelTimer();
sAppTask.mFunction = kFunction_NoneSelected;

PlatformMgr().ScheduleWork(AppTask::BLEStartAdvertising, 0);
// ScheduleWork is asynchronous and returns immediately.
// Failure means the work couldn't be queued, but there's nothing
// we can do about it here, so the return value can be safely ignored.
RETURN_SAFELY_IGNORED(PlatformMgr().ScheduleWork(AppTask::BLEStartAdvertising, 0));
}
else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb)
SetDeviceInstanceInfoProvider(&mFactoryDataProvider);

#if CONFIG_NETWORK_LAYER_BLE
ConnectivityMgr().SetBLEAdvertisingEnabled(true);
err = ConnectivityMgr().SetBLEAdvertisingEnabled(true);
SuccessOrExit(err);
#endif

PlatformMgr().AddEventHandler(CHIPDeviceManager::CommonDeviceEventHandler, reinterpret_cast<intptr_t>(cb));
err = PlatformMgr().AddEventHandler(CHIPDeviceManager::CommonDeviceEventHandler, reinterpret_cast<intptr_t>(cb));
SuccessOrExit(err);

// Start a task to run the CHIP Device event loop.
err = PlatformMgr().StartEventLoopTask();
Expand Down Expand Up @@ -114,7 +116,7 @@ CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb)
#endif // CHIP_DEVICE_CONFIG_THREAD_FTD
SuccessOrExit(err);

sThreadNetworkDriver.Init();
(void) sThreadNetworkDriver.Init();

ChipLogProgress(DeviceLayer, "Start OpenThread task");
err = ThreadStackMgrImpl().StartThreadTask();
Expand Down
28 changes: 24 additions & 4 deletions examples/light-switch-app/realtek/common/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ CHIP_ERROR AppTask::StartAppTask()
void AppTask::AppTaskMain(void * pvParameter)
{
uint8_t event;
CHIP_ERROR err = CHIP_NO_ERROR;

#if defined(FEATURE_TRUSTZONE_ENABLE) && (FEATURE_TRUSTZONE_ENABLE == 1)
os_alloc_secure_ctx(1024);
Expand All @@ -274,7 +275,12 @@ void AppTask::AppTaskMain(void * pvParameter)
gap_start_bt_stack(app_evt_queue_handle, app_io_queue_handle, MAX_NUMBER_OF_GAP_MESSAGE);
matter_ble_queue_init(app_evt_queue_handle, app_io_queue_handle);

sAppTask.Init();
err = sAppTask.Init();
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "sAppTask.Init() failed: %" CHIP_ERROR_FORMAT, err.Format());
return;
}

while (true)
{
Expand Down Expand Up @@ -318,6 +324,8 @@ void AppTask::AppTaskMain(void * pvParameter)

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

// Init ZCL Data Model and start server
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();
Expand All @@ -339,12 +347,21 @@ void AppTask::InitServer(intptr_t arg)
(void) initParams.InitializeStaticResourcesBeforeServerInit();
initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate;

chip::Server::GetInstance().Init(initParams);
err = chip::Server::GetInstance().Init(initParams);
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "Server::GetInstance().Init() failed: %" CHIP_ERROR_FORMAT, err.Format());
return;
}

InitTag();

static RealtekObserver sRealtekObserver;
chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(&sRealtekObserver);
err = chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(&sRealtekObserver);
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "AddFabricDelegate failed: %" CHIP_ERROR_FORMAT, err.Format());
}

ConfigurationMgr().LogDeviceConfig();
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
Expand Down Expand Up @@ -381,7 +398,10 @@ CHIP_ERROR AppTask::Init()
}

// Init ZCL Data Model and start server
PlatformMgr().ScheduleWork(InitServer, 0);
// ScheduleWork is asynchronous, failure means work couldn't be queued.
// Since this is init time, if it fails the system won't work anyway,
// so the return value can be safely ignored.
RETURN_SAFELY_IGNORED(PlatformMgr().ScheduleWork(InitServer, 0));

#if CONFIG_ENABLE_CHIP_SHELL
chip::Shell::Engine::Root().Init();
Expand Down
28 changes: 23 additions & 5 deletions examples/light-switch-app/realtek/common/main/BindingHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ void BindingHandler::Init()
// The initialization of binding manager will try establishing connection with unicast peers
// so it requires the Server instance to be correctly initialized. Post the init function to
// the event queue so that everything is ready when initialization is conducted.
chip::DeviceLayer::PlatformMgr().ScheduleWork(InitInternal);
// ScheduleWork is asynchronous, failure means work couldn't be queued.
// Since this is init time, if it fails the system won't work anyway,
// so the return value can be safely ignored.
RETURN_SAFELY_IGNORED(chip::DeviceLayer::PlatformMgr().ScheduleWork(InitInternal));
#if CONFIG_ENABLE_CHIP_SHELL
RegisterSwitchCommands();
#endif
Expand Down Expand Up @@ -253,9 +256,15 @@ void BindingHandler::LightSwitchContextReleaseHandler(void * context)
void BindingHandler::InitInternal(intptr_t arg)
{
ChipLogProgress(NotSpecified, "Initialize binding Handler");
auto & server = chip::Server::GetInstance();
Binding::Manager::GetInstance().Init(
CHIP_ERROR bindErr = CHIP_NO_ERROR;
auto & server = chip::Server::GetInstance();
bindErr = Binding::Manager::GetInstance().Init(
{ &server.GetFabricTable(), server.GetCASESessionManager(), &server.GetPersistentStorage() });
if (bindErr != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "Binding::Manager::Init() failed: %" CHIP_ERROR_FORMAT, bindErr.Format());
return;
}
Binding::Manager::GetInstance().RegisterBoundDeviceChangedHandler(LightSwitchChangedHandler);
Binding::Manager::GetInstance().RegisterBoundDeviceContextReleaseHandler(LightSwitchContextReleaseHandler);
}
Expand Down Expand Up @@ -567,12 +576,21 @@ void BindingHandler::SwitchWorkerFunction(intptr_t context)
#if CONFIG_ENABLE_CHIP_SHELL
streamer_printf(streamer_get(), "Notify Bounded Cluster | endpoint: %d CLuster: %d\r\n", data->EndpointId, data->ClusterId);
#endif
Binding::Manager::GetInstance().NotifyBoundClusterChanged(data->EndpointId, data->ClusterId, static_cast<void *>(data));
CHIP_ERROR notifyErr =
Binding::Manager::GetInstance().NotifyBoundClusterChanged(data->EndpointId, data->ClusterId, static_cast<void *>(data));
if (notifyErr != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "NotifyBoundClusterChanged failed: %" CHIP_ERROR_FORMAT, notifyErr.Format());
}
}

void BindingHandler::SwitchWorkerFunction2(int localEndpointId)
{
Binding::Manager::GetInstance().NotifyBoundClusterChanged(localEndpointId, Clusters::OnOff::Id, nullptr);
CHIP_ERROR notifyErr = Binding::Manager::GetInstance().NotifyBoundClusterChanged(localEndpointId, Clusters::OnOff::Id, nullptr);
if (notifyErr != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "NotifyBoundClusterChanged failed: %" CHIP_ERROR_FORMAT, notifyErr.Format());
}
}

void BindingHandler::SwitchWorkerFunction3(intptr_t context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb)
SetDeviceInstanceInfoProvider(&mFactoryDataProvider);

#if CONFIG_NETWORK_LAYER_BLE
ConnectivityMgr().SetBLEAdvertisingEnabled(true);
err = ConnectivityMgr().SetBLEAdvertisingEnabled(true);
SuccessOrExit(err);
#endif

PlatformMgr().AddEventHandler(CHIPDeviceManager::CommonDeviceEventHandler, reinterpret_cast<intptr_t>(cb));
err = PlatformMgr().AddEventHandler(CHIPDeviceManager::CommonDeviceEventHandler, reinterpret_cast<intptr_t>(cb));
SuccessOrExit(err);

// Start a task to run the CHIP Device event loop.
err = PlatformMgr().StartEventLoopTask();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ void LightSwitch::InitiateActionSwitch(chip::EndpointId endpointId, uint8_t acti
Platform::Delete(data);
return;
}
DeviceLayer::PlatformMgr().ScheduleWork(BindingHandler::SwitchWorkerFunction, reinterpret_cast<intptr_t>(data));
// ScheduleWork is asynchronous and returns immediately.
// Failure means the work couldn't be queued, but there's nothing
// we can do about it here, so the return value can be safely ignored.
RETURN_SAFELY_IGNORED(
DeviceLayer::PlatformMgr().ScheduleWork(BindingHandler::SwitchWorkerFunction, reinterpret_cast<intptr_t>(data)));
}
}

Expand Down
47 changes: 39 additions & 8 deletions examples/lighting-app/realtek/common/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ CHIP_ERROR AppTask::StartAppTask()
void AppTask::AppTaskMain(void * pvParameter)
{
uint8_t event;
CHIP_ERROR err = CHIP_NO_ERROR;

#if defined(FEATURE_TRUSTZONE_ENABLE) && (FEATURE_TRUSTZONE_ENABLE == 1)
os_alloc_secure_ctx(1024);
Expand All @@ -217,7 +218,12 @@ void AppTask::AppTaskMain(void * pvParameter)
gap_start_bt_stack(app_evt_queue_handle, app_io_queue_handle, MAX_NUMBER_OF_GAP_MESSAGE);
matter_ble_queue_init(app_evt_queue_handle, app_io_queue_handle);

sAppTask.Init();
err = sAppTask.Init();
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "sAppTask.Init() failed: %" CHIP_ERROR_FORMAT, err.Format());
return;
}

while (true)
{
Expand Down Expand Up @@ -261,6 +267,8 @@ void AppTask::AppTaskMain(void * pvParameter)

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

// Init ZCL Data Model and start server
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();
Expand All @@ -282,10 +290,19 @@ void AppTask::InitServer(intptr_t arg)
(void) initParams.InitializeStaticResourcesBeforeServerInit();
initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate;

chip::Server::GetInstance().Init(initParams);
err = chip::Server::GetInstance().Init(initParams);
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "Server::GetInstance().Init() failed: %" CHIP_ERROR_FORMAT, err.Format());
return;
}

static RealtekObserver sRealtekObserver;
chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(&sRealtekObserver);
err = chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(&sRealtekObserver);
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "AddFabricDelegate failed: %" CHIP_ERROR_FORMAT, err.Format());
}

ConfigurationMgr().LogDeviceConfig();
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
Expand Down Expand Up @@ -324,7 +341,10 @@ CHIP_ERROR AppTask::Init()
}

// Init ZCL Data Model and start server
PlatformMgr().ScheduleWork(InitServer, 0);
// ScheduleWork is asynchronous, failure means work couldn't be queued.
// Since this is init time, if it fails the system won't work anyway,
// so the return value can be safely ignored.
RETURN_SAFELY_IGNORED(PlatformMgr().ScheduleWork(InitServer, 0));

#if CONFIG_ENABLE_CHIP_SHELL
chip::Shell::Engine::Root().Init();
Expand All @@ -348,13 +368,18 @@ CHIP_ERROR AppTask::Init()

void AppTask::BLEStartAdvertising(intptr_t arg)
{
CHIP_ERROR setErr = CHIP_NO_ERROR;
if (ConnectivityMgr().IsBLEAdvertisingEnabled())
{
ConnectivityMgr().SetBLEAdvertisingEnabled(false);
setErr = ConnectivityMgr().SetBLEAdvertisingEnabled(false);
}
else
{
ConnectivityMgr().SetBLEAdvertisingEnabled(true);
setErr = ConnectivityMgr().SetBLEAdvertisingEnabled(true);
}
if (setErr != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "SetBLEAdvertisingEnabled failed: %" CHIP_ERROR_FORMAT, setErr.Format());
}
}

Expand Down Expand Up @@ -423,7 +448,10 @@ void AppTask::ButtonHandler(T_IO_MSG * p_msg)
case APP_BLE_ADV_BUTTON:
if (btnPressed)
{
PlatformMgr().ScheduleWork(AppTask::BLEStartAdvertising, 0);
// ScheduleWork is asynchronous and returns immediately.
// Failure means the work couldn't be queued, but there's nothing
// we can do about it here, so the return value can be safely ignored.
RETURN_SAFELY_IGNORED(PlatformMgr().ScheduleWork(AppTask::BLEStartAdvertising, 0));
}
break;

Expand Down Expand Up @@ -457,7 +485,10 @@ void AppTask::ButtonHandler(T_IO_MSG * p_msg)
sAppTask.CancelTimer();
sAppTask.mFunction = kFunction_NoneSelected;

PlatformMgr().ScheduleWork(AppTask::BLEStartAdvertising, 0);
// ScheduleWork is asynchronous and returns immediately.
// Failure means the work couldn't be queued, but there's nothing
// we can do about it here, so the return value can be safely ignored.
RETURN_SAFELY_IGNORED(PlatformMgr().ScheduleWork(AppTask::BLEStartAdvertising, 0));
}
else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset)
{
Expand Down
Loading
Loading