Skip to content

Commit

Permalink
Add commissioning complete callback and timer. (#6673)
Browse files Browse the repository at this point in the history
Adds a timer to the arm failsafe call, and generates a device event
(kCommissioningComplete) when the commissioning complete call happens
or when the failsafe timer is triggered.
  • Loading branch information
cecille authored and pull[bot] committed Sep 13, 2021
1 parent 077405f commit 14345d4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/include/platform/CHIPDeviceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ enum PublicEventTypes
* wifi/ethernet interface.
*/
kInterfaceIpAddressChanged,

/**
* Commissioning has completed either through timer expiry or by a call to the general commissioning cluster command.
*/
kCommissioningComplete,
};

/**
Expand Down Expand Up @@ -401,6 +406,11 @@ struct ChipDeviceEvent final
{
InterfaceIpChangeType Type;
} InterfaceIpAddressChanged;

struct
{
CHIP_ERROR status;
} CommissioningComplete;
};

void Clear() { memset(this, 0, sizeof(*this)); }
Expand Down
2 changes: 2 additions & 0 deletions src/include/platform/PlatformManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class TraitManager;
class ThreadStackManagerImpl;
class TimeSyncManager;
namespace Internal {
class DeviceControlServer;
class FabricProvisioningServer;
class ServiceProvisioningServer;
class BLEManagerImpl;
Expand Down Expand Up @@ -109,6 +110,7 @@ class PlatformManager
friend class TraitManager;
friend class ThreadStackManagerImpl;
friend class TimeSyncManager;
friend class Internal::DeviceControlServer;
friend class Internal::FabricProvisioningServer;
friend class Internal::ServiceProvisioningServer;
friend class Internal::BLEManagerImpl;
Expand Down
2 changes: 2 additions & 0 deletions src/include/platform/internal/DeviceControlServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class DeviceControlServer final
private:
// ===== Members for internal use by the following friends.
static DeviceControlServer sInstance;
friend void CommissioningTimerFunction(System::Layer * layer, void * aAppState, System::Error aError);
void CommissioningFailedTimerComplete(System::Error aErrror);

// ===== Private members reserved for use by this class only.

Expand Down
27 changes: 23 additions & 4 deletions src/platform/DeviceControlServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,32 @@ namespace chip {
namespace DeviceLayer {
namespace Internal {

void CommissioningTimerFunction(System::Layer * layer, void * aAppState, System::Error aError)
{
DeviceControlServer * server = reinterpret_cast<DeviceControlServer *>(aAppState);
server->CommissioningFailedTimerComplete(aError);
}

DeviceControlServer DeviceControlServer::sInstance;

DeviceControlServer & DeviceControlServer::DeviceControlSvr()
{
return sInstance;
}

void DeviceControlServer::CommissioningFailedTimerComplete(System::Error aError)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kCommissioningComplete;
event.CommissioningComplete.status = CHIP_ERROR_TIMEOUT;
PlatformMgr().PostEvent(&event);
}

CHIP_ERROR DeviceControlServer::ArmFailSafe(uint16_t expiryLengthSeconds)
{
// TODO
return CHIP_ERROR_NOT_IMPLEMENTED;
uint32_t timerMs = expiryLengthSeconds * 1000;
SystemLayer.StartTimer(timerMs, CommissioningTimerFunction, this);
return CHIP_NO_ERROR;
}

CHIP_ERROR DeviceControlServer::DisarmFailSafe()
Expand All @@ -49,8 +64,12 @@ CHIP_ERROR DeviceControlServer::DisarmFailSafe()

CHIP_ERROR DeviceControlServer::CommissioningComplete()
{
// TODO
return CHIP_ERROR_NOT_IMPLEMENTED;
SystemLayer.CancelTimer(CommissioningTimerFunction, this);
ChipDeviceEvent event;
event.Type = DeviceEventType::kCommissioningComplete;
event.CommissioningComplete.status = CHIP_NO_ERROR;
PlatformMgr().PostEvent(&event);
return CHIP_NO_ERROR;
}

CHIP_ERROR DeviceControlServer::SetRegulatoryConfig(uint8_t location, const char * countryCode, uint64_t breadcrumb)
Expand Down

0 comments on commit 14345d4

Please sign in to comment.