Skip to content

Commit

Permalink
Delay processing test event in Smoke CO Alarm (#28044)
Browse files Browse the repository at this point in the history
Co-authored-by: Hare <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jul 20, 2023
1 parent 4ba4c4a commit ef1a5e2
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,15 @@ class SmokeCoAlarmManager
int mExpressedStateMask = 1;

bool mEndSelfTesting;
uint64_t mEventTrigger;

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

static void TimerEventHandler(TimerHandle_t xTimer);
static void SelfTestingEventHandler(AppEvent * aEvent);
static void EndSelfTestingEventHandler(AppEvent * aEvent);
static void TriggerEventHandler(AppEvent * aEvent);

static SmokeCoAlarmManager sAlarm;
};
Expand Down
160 changes: 112 additions & 48 deletions examples/smoke-co-alarm-app/silabs/src/SmokeCoAlarmManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ CHIP_ERROR SmokeCoAlarmManager::Init()
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

mEndSelfTesting = false;
mEventTrigger = 0;

return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -141,10 +142,16 @@ void SmokeCoAlarmManager::TimerEventHandler(TimerHandle_t xTimer)
AppEvent event;
event.Type = AppEvent::kEventType_Timer;
event.TimerEvent.Context = alarm;

if (alarm->mEndSelfTesting)
{
event.Handler = EndSelfTestingEventHandler;
}
else if (alarm->mEventTrigger != 0)
{
event.Handler = TriggerEventHandler;
}

AppTask::GetAppTask().PostEvent(&event);
}

Expand Down Expand Up @@ -180,102 +187,90 @@ void SmokeCoAlarmManager::EndSelfTestingEventHandler(AppEvent * aEvent)
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
}

bool SmokeCoAlarmManager::OnSelfTesting()
{
AppEvent event;
event.Handler = SelfTestingEventHandler;
AppTask::GetAppTask().PostEvent(&event);

return true;
}

bool SmokeCoAlarmManager::ManualSelfTesting()
void SmokeCoAlarmManager::TriggerEventHandler(AppEvent * aEvent)
{
bool success = false;

if ((mExpressedStateMask & 0b110010110) == 0)
{
chip::DeviceLayer::PlatformMgr().LockChipStack();
success = AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kTesting, true);
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

if (success)
{
success = OnSelfTesting();
}
}

return success;
}
uint64_t eventTrigger = AlarmMgr().mEventTrigger;
AlarmMgr().mEventTrigger = 0;

bool SmokeCoAlarmManager::OnEventTriggerHandle(uint64_t eventTrigger)
{
bool isValidCommand = true;
chip::DeviceLayer::PlatformMgr().LockChipStack();

switch (eventTrigger)
{
case kTriggeredEvent_WarningSmokeAlarm:
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetSmokeState(1, AlarmStateEnum::kWarning), true);
VerifyOrReturn(SmokeCoAlarmServer::Instance().SetSmokeState(1, AlarmStateEnum::kWarning),
chip::DeviceLayer::PlatformMgr().UnlockChipStack());
AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kSmokeAlarm, true);
break;

case kTriggeredEvent_CriticalSmokeAlarm:
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetSmokeState(1, AlarmStateEnum::kCritical), true);
VerifyOrReturn(SmokeCoAlarmServer::Instance().SetSmokeState(1, AlarmStateEnum::kCritical),
chip::DeviceLayer::PlatformMgr().UnlockChipStack());
AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kSmokeAlarm, true);
break;

case kTriggeredEvent_SmokeAlarmClear:
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetSmokeState(1, AlarmStateEnum::kNormal), true);
VerifyOrReturn(SmokeCoAlarmServer::Instance().SetSmokeState(1, AlarmStateEnum::kNormal),
chip::DeviceLayer::PlatformMgr().UnlockChipStack());
AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kSmokeAlarm, false);
break;

case kTriggeredEvent_WarningCOAlarm:
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetCOState(1, AlarmStateEnum::kWarning), true);
VerifyOrReturn(SmokeCoAlarmServer::Instance().SetCOState(1, AlarmStateEnum::kWarning),
chip::DeviceLayer::PlatformMgr().UnlockChipStack());
AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kCOAlarm, true);
break;

case kTriggeredEvent_CriticalCOAlarm:
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetCOState(1, AlarmStateEnum::kCritical), true);
VerifyOrReturn(SmokeCoAlarmServer::Instance().SetCOState(1, AlarmStateEnum::kCritical),
chip::DeviceLayer::PlatformMgr().UnlockChipStack());
AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kCOAlarm, true);
break;

case kTriggeredEvent_COAlarmClear:
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetCOState(1, AlarmStateEnum::kNormal), true);
VerifyOrReturn(SmokeCoAlarmServer::Instance().SetCOState(1, AlarmStateEnum::kNormal),
chip::DeviceLayer::PlatformMgr().UnlockChipStack());
AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kCOAlarm, false);
break;

case kTriggeredEvent_WarningBatteryAlert:
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetBatteryAlert(1, AlarmStateEnum::kWarning), true);
VerifyOrReturn(SmokeCoAlarmServer::Instance().SetBatteryAlert(1, AlarmStateEnum::kWarning),
chip::DeviceLayer::PlatformMgr().UnlockChipStack());
AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kBatteryAlert, true);
break;

case kTriggeredEvent_CriticalBatteryAlert:
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetBatteryAlert(1, AlarmStateEnum::kCritical), true);
VerifyOrReturn(SmokeCoAlarmServer::Instance().SetBatteryAlert(1, AlarmStateEnum::kCritical),
chip::DeviceLayer::PlatformMgr().UnlockChipStack());
AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kBatteryAlert, true);
break;

case kTriggeredEvent_BatteryAlertClear:
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetBatteryAlert(1, AlarmStateEnum::kNormal), true);
VerifyOrReturn(SmokeCoAlarmServer::Instance().SetBatteryAlert(1, AlarmStateEnum::kNormal),
chip::DeviceLayer::PlatformMgr().UnlockChipStack());
AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kBatteryAlert, false);
break;

case kTriggeredEvent_HardwareFaultAlert:
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetHardwareFaultAlert(1, true), true);
VerifyOrReturn(SmokeCoAlarmServer::Instance().SetHardwareFaultAlert(1, true),
chip::DeviceLayer::PlatformMgr().UnlockChipStack());
AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kHardwareFault, true);
break;

case kTriggeredEvent_HardwareFaultAlertClear:
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetHardwareFaultAlert(1, false), true);
VerifyOrReturn(SmokeCoAlarmServer::Instance().SetHardwareFaultAlert(1, false),
chip::DeviceLayer::PlatformMgr().UnlockChipStack());
AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kHardwareFault, false);
break;

case kTriggeredEvent_EndofServiceAlert:
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetEndOfServiceAlert(1, EndOfServiceEnum::kExpired), true);
VerifyOrReturn(SmokeCoAlarmServer::Instance().SetEndOfServiceAlert(1, EndOfServiceEnum::kExpired),
chip::DeviceLayer::PlatformMgr().UnlockChipStack());
AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kEndOfService, true);
break;

case kTriggeredEvent_EndofServiceAlertClear:
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetEndOfServiceAlert(1, EndOfServiceEnum::kNormal), true);
VerifyOrReturn(SmokeCoAlarmServer::Instance().SetEndOfServiceAlert(1, EndOfServiceEnum::kNormal),
chip::DeviceLayer::PlatformMgr().UnlockChipStack());
AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kEndOfService, false);
break;

Expand All @@ -288,22 +283,26 @@ bool SmokeCoAlarmManager::OnEventTriggerHandle(uint64_t eventTrigger)
break;

case kTriggeredEvent_InterconnectSmokeAlarm:
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetInterconnectSmokeAlarm(1, AlarmStateEnum::kWarning), true);
VerifyOrReturn(SmokeCoAlarmServer::Instance().SetInterconnectSmokeAlarm(1, AlarmStateEnum::kWarning),
chip::DeviceLayer::PlatformMgr().UnlockChipStack());
AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kInterconnectSmoke, true);
break;

case kTriggeredEvent_InterconnectSmokeAlarmClear:
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetInterconnectSmokeAlarm(1, AlarmStateEnum::kNormal), true);
VerifyOrReturn(SmokeCoAlarmServer::Instance().SetInterconnectSmokeAlarm(1, AlarmStateEnum::kNormal),
chip::DeviceLayer::PlatformMgr().UnlockChipStack());
AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kInterconnectSmoke, false);
break;

case kTriggeredEvent_InterconnectCOAlarm:
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetInterconnectCOAlarm(1, AlarmStateEnum::kWarning), true);
VerifyOrReturn(SmokeCoAlarmServer::Instance().SetInterconnectCOAlarm(1, AlarmStateEnum::kWarning),
chip::DeviceLayer::PlatformMgr().UnlockChipStack());
AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kInterconnectCO, true);
break;

case kTriggeredEvent_InterconnectCOAlarmClear:
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetInterconnectCOAlarm(1, AlarmStateEnum::kNormal), true);
VerifyOrReturn(SmokeCoAlarmServer::Instance().SetInterconnectCOAlarm(1, AlarmStateEnum::kNormal),
chip::DeviceLayer::PlatformMgr().UnlockChipStack());
AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kInterconnectCO, false);
break;

Expand All @@ -330,9 +329,74 @@ bool SmokeCoAlarmManager::OnEventTriggerHandle(uint64_t eventTrigger)
case kTriggeredEvent_SensitivityLevelClear:
SmokeCoAlarmServer::Instance().SetSensitivityLevel(1, SensitivityEnum::kStandard);
break;
}

chip::DeviceLayer::PlatformMgr().UnlockChipStack();
}

bool SmokeCoAlarmManager::OnSelfTesting()
{
AppEvent event;
event.Handler = SelfTestingEventHandler;
AppTask::GetAppTask().PostEvent(&event);

return true;
}

bool SmokeCoAlarmManager::ManualSelfTesting()
{
bool success = false;

if ((mExpressedStateMask & 0b110010110) == 0)
{
chip::DeviceLayer::PlatformMgr().LockChipStack();
success = AlarmMgr().SetExpressedState(1, ExpressedStateEnum::kTesting, true);
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

if (success)
{
success = OnSelfTesting();
}
}

return success;
}

bool SmokeCoAlarmManager::OnEventTriggerHandle(uint64_t eventTrigger)
{
bool isValidCommand = false;

default:
isValidCommand = false;
switch (eventTrigger)
{
case kTriggeredEvent_WarningSmokeAlarm:
case kTriggeredEvent_CriticalSmokeAlarm:
case kTriggeredEvent_SmokeAlarmClear:
case kTriggeredEvent_WarningCOAlarm:
case kTriggeredEvent_CriticalCOAlarm:
case kTriggeredEvent_COAlarmClear:
case kTriggeredEvent_WarningBatteryAlert:
case kTriggeredEvent_CriticalBatteryAlert:
case kTriggeredEvent_BatteryAlertClear:
case kTriggeredEvent_HardwareFaultAlert:
case kTriggeredEvent_HardwareFaultAlertClear:
case kTriggeredEvent_EndofServiceAlert:
case kTriggeredEvent_EndofServiceAlertClear:
case kTriggeredEvent_DeviceMute:
case kTriggeredEvent_DeviceMuteClear:
case kTriggeredEvent_InterconnectSmokeAlarm:
case kTriggeredEvent_InterconnectSmokeAlarmClear:
case kTriggeredEvent_InterconnectCOAlarm:
case kTriggeredEvent_InterconnectCOAlarmClear:
case kTriggeredEvent_ContaminationStateHigh:
case kTriggeredEvent_ContaminationStateLow:
case kTriggeredEvent_ContaminationStateClear:
case kTriggeredEvent_SensitivityLevelHigh:
case kTriggeredEvent_SensitivityLevelLow:
case kTriggeredEvent_SensitivityLevelClear:
isValidCommand = true;
AlarmMgr().mEventTrigger = eventTrigger;
AlarmMgr().StartTimer(5000);
break;
}

return isValidCommand;
Expand Down

0 comments on commit ef1a5e2

Please sign in to comment.