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

[events] Added generating BootReason event #60

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ class SetupListModel : public TouchesMatterStackModel
}
else if (i == 1)
{
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}
else if (i == 2)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/light-switch-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
{
// Actually trigger Factory Reset
sAppTask.mFunction = kFunction_NoneSelected;
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
{
// Actually trigger Factory Reset
sAppTask.mFunction = kFunction_NoneSelected;
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/mbed/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
// Actually trigger Factory Reset
ChipLogProgress(NotSpecified, "Factory Reset initiated");
sAppTask.mFunction = kFunction_NoneSelected;
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}
}

Expand Down
3 changes: 2 additions & 1 deletion examples/lighting-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
{
// Actually trigger Factory Reset
sAppTask.mFunction = kFunction_NoneSelected;
ConfigurationMgr().InitiateFactoryReset();

chip::Server::GetInstance().FactoryReset();
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
K32W_LOG("Device will factory reset...");

// Actually trigger Factory Reset
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}

void AppTask::ResetActionEventHandler(AppEvent * aEvent)
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/p6/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
{
// Actually trigger Factory Reset
sAppTask.mFunction = Function::kNoneSelected;
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
{
// Actually trigger Factory Reset
sAppTask.mFunction = kFunction_NoneSelected;
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void AppTask::FactoryResetButtonEventHandler(void)
void AppTask::FactoryResetHandler(AppEvent * aEvent)
{
LOG_INF("Factory Reset triggered.");
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}

void AppTask::StartThreadButtonEventHandler(void)
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
{
// Actually trigger Factory Reset
sAppTask.mFunction = kFunction_NoneSelected;
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/esp32/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
{
// Actually trigger Factory Reset
sAppTask.mFunction = kFunction_NoneSelected;
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/mbed/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
// Actually trigger Factory Reset
ChipLogProgress(NotSpecified, "Factory Reset initiated");
sAppTask.mFunction = kFunction_NoneSelected;
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}
}

Expand Down
3 changes: 2 additions & 1 deletion examples/lock-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
{
// Actually trigger Factory Reset
sAppTask.mFunction = kFunction_NoneSelected;
ConfigurationMgr().InitiateFactoryReset();

chip::Server::GetInstance().FactoryReset();
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/nxp/k32w/k32w0/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ void AppTask::FunctionTimerEventHandler(void * aGenericEvent)
K32W_LOG("Device will factory reset...");

// Actually trigger Factory Reset
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}

void AppTask::ResetActionEventHandler(void * aGenericEvent)
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/p6/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * event)
{
// Actually trigger Factory Reset
sAppTask.mFunction = Function::kNoneSelected;
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
{
// Actually trigger Factory Reset
sAppTask.mFunction = kFunction_NoneSelected;
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/ota-requestor-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
{
// Actually trigger Factory Reset
sAppTask.mFunction = kFunction_NoneSelected;
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/ota-requestor-app/mbed/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
sAppTask.CancelTimer(kFunction_Button_1);
sAppTask.mFunction[kFunction_Button_1] = kFunction_NoneSelected;

ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}
break;
case kFunction_Button_2:
Expand Down
2 changes: 1 addition & 1 deletion examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
}
else if (AppEvent::kAppEventButtonType_LongPressed == aEvent->ButtonEvent.Type)
{
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}
break;

Expand Down
3 changes: 2 additions & 1 deletion examples/pump-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
{
// Actually trigger Factory Reset
sAppTask.mFunction = kFunction_NoneSelected;
ConfigurationMgr().InitiateFactoryReset();

chip::Server::GetInstance().FactoryReset();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
}
else if (AppEvent::kAppEventButtonType_LongPressed == aEvent->ButtonEvent.Type)
{
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}
break;

Expand Down
3 changes: 2 additions & 1 deletion examples/pump-controller-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
{
// Actually trigger Factory Reset
sAppTask.mFunction = kFunction_NoneSelected;
ConfigurationMgr().InitiateFactoryReset();

chip::Server::GetInstance().FactoryReset();
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/shell/nxp/k32w/k32w0/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
K32W_LOG("Device will factory reset...");

// Actually trigger Factory Reset
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
}

void AppTask::ResetActionEventHandler(AppEvent * aEvent)
Expand Down
2 changes: 1 addition & 1 deletion examples/window-app/common/src/WindowApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void WindowApp::DispatchEvent(const WindowApp::Event & event)
break;

case EventId::Reset:
ConfigurationMgr().InitiateFactoryReset();
chip::Server::GetInstance().FactoryReset();
break;

case EventId::UpPressed:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,23 @@ class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelega
}

// Gets called when the device has been rebooted.
void OnDeviceRebooted() override
void OnDeviceRebooted(uint8_t bootReason) override
{
ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnDeviceRebooted");

ReportAttributeOnAllEndpoints(GeneralDiagnostics::Attributes::BootReasons::Id);

for (auto endpoint : EnabledEndpointsWithServerCluster(GeneralDiagnostics::Id))
{
// If GeneralDiagnostics cluster is implemented on this endpoint
kkasperczyk-no marked this conversation as resolved.
Show resolved Hide resolved
Events::BootReason::Type event{ static_cast<BootReasonType>(bootReason) };
EventNumber eventNumber;

if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber, EventOptions::Type::kUrgent))
{
ChipLogError(Zcl, "GeneralDiagnosticsDelegate: Failed to record BootReason event");
kkasperczyk-no marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

// Get called when the Node detects a hardware fault has been raised.
Expand Down
3 changes: 2 additions & 1 deletion src/app/reporting/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ class Engine

uint32_t GetNumReportsInFlight() { return mNumReportsInFlight; }

void ScheduleUrgentEventDeliverySync();

private:
friend class TestReportingEngine;
/**
Expand Down Expand Up @@ -165,7 +167,6 @@ class Engine
CHIP_ERROR ScheduleUrgentEventDelivery(ConcreteEventPath & aPath);
CHIP_ERROR ScheduleBufferPressureEventDelivery(uint32_t aBytesWritten);
void GetMinEventLogPosition(uint32_t & aMinLogPosition);
void ScheduleUrgentEventDeliverySync();

/**
* If the provided path is a superset of our of our existing paths, update that existing path to match the
Expand Down
14 changes: 14 additions & 0 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,20 @@ void Server::DispatchShutDownAndStopEventLoop()
chip::DeviceLayer::PlatformMgr().ScheduleWork(StopEventLoop);
}

void Server::FactoryReset()
{
// Delete all fabrics and emit Leave event.
kkasperczyk-no marked this conversation as resolved.
Show resolved Hide resolved
GetFabricTable().DeleteAllFabrics();

// Emit Shutdown event, as shutdown will come after factory reset.
DispatchShutDownEvent(0);

// Flush all dispatched events.
chip::app::InteractionModelEngine::GetInstance()->GetReportingEngine().ScheduleUrgentEventDeliverySync();

chip::DeviceLayer::ConfigurationMgr().InitiateFactoryReset();
}

void Server::Shutdown()
{
chip::Dnssd::ServiceAdvertiser::Instance().Shutdown();
Expand Down
2 changes: 2 additions & 0 deletions src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class Server
*/
void DispatchShutDownAndStopEventLoop();

void FactoryReset();

void Shutdown();

static Server & GetInstance() { return sServer; }
Expand Down
2 changes: 1 addition & 1 deletion src/include/platform/DiagnosticDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class GeneralDiagnosticsDelegate
* @brief
* Called after the current device is rebooted.
*/
virtual void OnDeviceRebooted() {}
virtual void OnDeviceRebooted(uint8_t bootReason) {}

/**
* @brief
Expand Down
5 changes: 4 additions & 1 deletion src/include/platform/internal/GenericPlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ void GenericPlatformManagerImpl<ImplClass>::HandleDeviceRebooted(intptr_t arg)

if (generalDiagnosticsDelegate != nullptr)
{
generalDiagnosticsDelegate->OnDeviceRebooted();
uint8_t bootReason;

ReturnOnFailure(GetDiagnosticDataProvider().GetBootReason(bootReason));
kkasperczyk-no marked this conversation as resolved.
Show resolved Hide resolved
generalDiagnosticsDelegate->OnDeviceRebooted(bootReason);
}

// The StartUp event SHALL be emitted by a Node after completing a boot or reboot process
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include <system/SystemError.h>
#include <system/SystemLayer.h>

#include <power/reboot.h>
kkasperczyk-no marked this conversation as resolved.
Show resolved Hide resolved

#define DEFAULT_MIN_SLEEP_PERIOD (60 * 60 * 24 * 30) // Month [sec]

namespace chip {
Expand All @@ -46,6 +48,7 @@ System::LayerSocketsLoop & SystemLayerSocketsLoop()
{
return static_cast<System::LayerSocketsLoop &>(DeviceLayer::SystemLayer());
}

} // anonymous namespace

// Fully instantiate the generic implementation class in whatever compilation unit includes this file.
Expand Down Expand Up @@ -106,7 +109,12 @@ CHIP_ERROR GenericPlatformManagerImpl_Zephyr<ImplClass>::_StopEventLoopTask(void
template <class ImplClass>
CHIP_ERROR GenericPlatformManagerImpl_Zephyr<ImplClass>::_Shutdown(void)
{
#if CONFIG_REBOOT
sys_reboot(SYS_REBOOT_WARM);
return CHIP_NO_ERROR;
#else
return CHIP_ERROR_NOT_IMPLEMENTED;
#endif
}

template <class ImplClass>
Expand Down
6 changes: 1 addition & 5 deletions src/platform/Zephyr/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>

#include <power/reboot.h>

namespace chip {
namespace DeviceLayer {

Expand Down Expand Up @@ -204,9 +202,7 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
ThreadStackMgr().ErasePersistentInfo();
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD

#if CONFIG_REBOOT
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I guess this change isn't that necessary since we will probably need to support some custom reboot mechanism (to send the shutdown event in any case).

sys_reboot(SYS_REBOOT_WARM);
#endif
PlatformMgr().Shutdown();
}

} // namespace DeviceLayer
Expand Down
7 changes: 6 additions & 1 deletion src/platform/Zephyr/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ inline bool ConfigurationManagerImpl::CanFactoryReset()

inline CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value)
{
return Internal::ZephyrConfig::ReadConfigValueCounter(key, value);
CHIP_ERROR err = Internal::ZephyrConfig::ReadConfigValueCounter(key, value);
if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
{
err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND;
}
return err;
}

inline CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value)
Expand Down