Skip to content

Commit

Permalink
Revert "Delay processing test event in Smoke CO Alarm (#28044)"
Browse files Browse the repository at this point in the history
This reverts commit 435aa96.
  • Loading branch information
hare-siterwell committed Jul 22, 2023
1 parent 0760d13 commit 16633a1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,13 @@ 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: 48 additions & 112 deletions examples/smoke-co-alarm-app/silabs/src/SmokeCoAlarmManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ CHIP_ERROR SmokeCoAlarmManager::Init()
chip::DeviceLayer::PlatformMgr().UnlockChipStack();

mEndSelfTesting = false;
mEventTrigger = 0;

return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -142,16 +141,10 @@ 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 @@ -187,90 +180,102 @@ void SmokeCoAlarmManager::EndSelfTestingEventHandler(AppEvent * aEvent)
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
}

void SmokeCoAlarmManager::TriggerEventHandler(AppEvent * aEvent)
bool SmokeCoAlarmManager::OnSelfTesting()
{
uint64_t eventTrigger = AlarmMgr().mEventTrigger;
AlarmMgr().mEventTrigger = 0;
AppEvent event;
event.Handler = SelfTestingEventHandler;
AppTask::GetAppTask().PostEvent(&event);

chip::DeviceLayer::PlatformMgr().LockChipStack();
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 = true;

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

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

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

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

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

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

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

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

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

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

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

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

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

Expand All @@ -283,26 +288,22 @@ void SmokeCoAlarmManager::TriggerEventHandler(AppEvent * aEvent)
break;

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

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

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

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

Expand All @@ -329,74 +330,9 @@ void SmokeCoAlarmManager::TriggerEventHandler(AppEvent * aEvent)
case kTriggeredEvent_SensitivityLevelClear:
SmokeCoAlarmServer::Instance().SetSmokeSensitivityLevel(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;

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;
default:
isValidCommand = false;
}

return isValidCommand;
Expand Down

0 comments on commit 16633a1

Please sign in to comment.