From 11675404bbe7173cf6cfa134424f2d8d4415251b Mon Sep 17 00:00:00 2001 From: EricZijian_Siter Date: Mon, 24 Jul 2023 21:36:38 +0800 Subject: [PATCH] Revert "Delay processing test event in Smoke CO Alarm (#28044)" (#28191) This reverts commit 435aa960aecfdc9507534fac1e8e95502dfb5d9f. Co-authored-by: Hare --- .../silabs/include/SmokeCoAlarmManager.h | 2 - .../silabs/src/SmokeCoAlarmManager.cpp | 160 ++++++------------ 2 files changed, 48 insertions(+), 114 deletions(-) diff --git a/examples/smoke-co-alarm-app/silabs/include/SmokeCoAlarmManager.h b/examples/smoke-co-alarm-app/silabs/include/SmokeCoAlarmManager.h index c7a5b877f6b821..be1b38a8bb5e3a 100644 --- a/examples/smoke-co-alarm-app/silabs/include/SmokeCoAlarmManager.h +++ b/examples/smoke-co-alarm-app/silabs/include/SmokeCoAlarmManager.h @@ -108,7 +108,6 @@ class SmokeCoAlarmManager int mExpressedStateMask = 1; bool mEndSelfTesting; - uint64_t mEventTrigger; void CancelTimer(void); void StartTimer(uint32_t aTimeoutMs); @@ -116,7 +115,6 @@ class SmokeCoAlarmManager static void TimerEventHandler(TimerHandle_t xTimer); static void SelfTestingEventHandler(AppEvent * aEvent); static void EndSelfTestingEventHandler(AppEvent * aEvent); - static void TriggerEventHandler(AppEvent * aEvent); static SmokeCoAlarmManager sAlarm; }; diff --git a/examples/smoke-co-alarm-app/silabs/src/SmokeCoAlarmManager.cpp b/examples/smoke-co-alarm-app/silabs/src/SmokeCoAlarmManager.cpp index c006e92ad013ce..3fd076689d4e14 100644 --- a/examples/smoke-co-alarm-app/silabs/src/SmokeCoAlarmManager.cpp +++ b/examples/smoke-co-alarm-app/silabs/src/SmokeCoAlarmManager.cpp @@ -99,7 +99,6 @@ CHIP_ERROR SmokeCoAlarmManager::Init() chip::DeviceLayer::PlatformMgr().UnlockChipStack(); mEndSelfTesting = false; - mEventTrigger = 0; return CHIP_NO_ERROR; } @@ -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); } @@ -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; @@ -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; @@ -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;