Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add commissioning complete callback and timer. #6673

Merged
merged 1 commit into from
May 11, 2021
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
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 @@ -49,6 +49,7 @@ class TraitManager;
class ThreadStackManagerImpl;
class TimeSyncManager;
namespace Internal {
class DeviceControlServer;
class FabricProvisioningServer;
class ServiceProvisioningServer;
class BLEManagerImpl;
Expand Down Expand Up @@ -104,6 +105,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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: static_cast would be enough

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