Skip to content

Commit 1601e05

Browse files
[Silabs] Remove global function from the SilabsTestEventTriggerDelegate (project-chip#32969)
* Refactor Silabs Test Event Trigger to remove global function * Enable test event trigger on the lit-icd sample apps * Add the support lib to the data provider dependencies
1 parent 07f4b35 commit 1601e05

File tree

9 files changed

+47
-60
lines changed

9 files changed

+47
-60
lines changed

examples/lit-icd-app/silabs/build_for_wifi_args.gni

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import("${chip_root}/src/platform/silabs/wifi_args.gni")
2323
chip_enable_ota_requestor = true
2424
app_data_model = "${chip_root}/examples/lit-icd-app/lit-icd-common"
2525

26+
sl_enable_test_event_trigger = true
27+
2628
# ICD Default configurations
2729
chip_enable_icd_server = true
2830
chip_subscription_timeout_resumption = false

examples/lit-icd-app/silabs/openthread.gni

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ chip_enable_openthread = true
2626
openthread_external_platform =
2727
"${chip_root}/third_party/openthread/platforms/efr32:libopenthread-efr32"
2828

29+
sl_enable_test_event_trigger = true
30+
2931
# ICD Default configurations
3032
chip_enable_icd_server = true
3133
chip_subscription_timeout_resumption = false

examples/platform/silabs/SiWx917/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ source_set("silabs-factory-data-provider") {
145145

146146
public_deps = [
147147
"${chip_root}/src/credentials",
148+
"${chip_root}/src/lib/support",
148149
"${chip_root}/src/platform:platform_base",
149150
"${chip_root}/src/setup_payload",
150151
]

examples/platform/silabs/SilabsDeviceDataProvider.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "SilabsDeviceDataProvider.h"
1919
#include <crypto/CHIPCryptoPAL.h>
2020
#include <lib/support/Base64.h>
21+
#include <lib/support/BytesToHex.h>
2122
#include <lib/support/CHIPMemString.h>
2223
#include <platform/silabs/SilabsConfig.h>
2324
#include <setup_payload/Base38Encode.h>

examples/platform/silabs/SilabsTestEventTriggerDelegate.h

+2-30
Original file line numberDiff line numberDiff line change
@@ -25,47 +25,19 @@
2525
#include <lib/support/CodeUtils.h>
2626
#include <lib/support/Span.h>
2727

28-
/**
29-
* @brief User handler for handling the test event trigger
30-
*
31-
* @note If TestEventTrigger is enabled, it needs to be implemented in the app
32-
*
33-
* @param eventTrigger Event trigger to handle
34-
*
35-
* @warning *** DO NOT USE FOR STANDARD CLUSTER EVENT TRIGGERS ***
36-
*
37-
* TODO(#31723): Rename `emberAfHandleEventTrigger` to `SilabsHandleGlobalTestEventTrigger`
38-
*
39-
* @retval true on success
40-
* @retval false if error happened
41-
*/
42-
bool emberAfHandleEventTrigger(uint64_t eventTrigger);
43-
4428
namespace chip {
4529

46-
class SilabsTestEventTriggerDelegate : public TestEventTriggerDelegate, TestEventTriggerHandler
30+
class SilabsTestEventTriggerDelegate : public TestEventTriggerDelegate
4731
{
4832
public:
49-
explicit SilabsTestEventTriggerDelegate() { VerifyOrDie(AddHandler(this) == CHIP_NO_ERROR); }
33+
explicit SilabsTestEventTriggerDelegate() = default;
5034

5135
/**
5236
* @brief Checks to see if `enableKey` provided matches value chosen by the manufacturer.
5337
* @param enableKey Buffer of the key to verify.
5438
* @return True or False.
5539
*/
5640
bool DoesEnableKeyMatch(const ByteSpan & enableKey) const override;
57-
58-
/**
59-
* @brief Delegates handling to global `emberAfHandleEventTrigger` function. DO NOT EXTEND.
60-
*
61-
* @param eventTrigger - trigger to process.
62-
* @return CHIP_NO_ERROR if properly handled, else another CHIP_ERROR.
63-
*/
64-
CHIP_ERROR HandleEventTrigger(uint64_t eventTrigger) override
65-
{
66-
// WARNING: LEGACY SUPPORT ONLY, DO NOT EXTEND FOR STANDARD CLUSTERS
67-
return (emberAfHandleEventTrigger(eventTrigger)) ? CHIP_NO_ERROR : CHIP_ERROR_INVALID_ARGUMENT;
68-
}
6941
};
7042

7143
} // namespace chip

examples/platform/silabs/efr32/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ source_set("silabs-factory-data-provider") {
178178

179179
public_deps = [
180180
"${chip_root}/src/credentials",
181+
"${chip_root}/src/lib/support",
181182
"${chip_root}/src/platform:platform_base",
182183
"${chip_root}/src/setup_payload",
183184
]

examples/smoke-co-alarm-app/silabs/include/SmokeCoAlarmManager.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@
2121
#include <stdint.h>
2222

2323
#include "AppEvent.h"
24-
24+
#include <app/TestEventTriggerDelegate.h>
2525
#include <app/clusters/smoke-co-alarm-server/smoke-co-alarm-server.h>
2626
#include <cmsis_os2.h>
2727
#include <lib/core/CHIPError.h>
2828

29-
class SmokeCoAlarmManager
29+
class SmokeCoAlarmManager : public chip::TestEventTriggerHandler
3030
{
3131
public:
32+
SmokeCoAlarmManager() = default;
33+
~SmokeCoAlarmManager() = default;
34+
3235
CHIP_ERROR Init();
3336

3437
/**
@@ -37,6 +40,14 @@ class SmokeCoAlarmManager
3740
*/
3841
void SelfTestingEventHandler();
3942

43+
/**
44+
* @brief Delegates handling to global `emberAfHandleEventTrigger` function. DO NOT EXTEND.
45+
*
46+
* @param eventTrigger - trigger to process.
47+
* @return CHIP_NO_ERROR if properly handled, else another CHIP_ERROR.
48+
*/
49+
CHIP_ERROR HandleEventTrigger(uint64_t eventTrigger) override;
50+
4051
private:
4152
friend SmokeCoAlarmManager & AlarmMgr(void);
4253

examples/smoke-co-alarm-app/silabs/src/AppTask.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,19 @@
1818
#include "AppTask.h"
1919
#include "AppConfig.h"
2020
#include "AppEvent.h"
21-
2221
#include "LEDWidget.h"
2322

2423
#include <app/clusters/smoke-co-alarm-server/smoke-co-alarm-server.h>
2524
#include <app/server/OnboardingCodesUtil.h>
2625
#include <app/server/Server.h>
2726
#include <app/util/attribute-storage.h>
28-
2927
#include <assert.h>
30-
28+
#include <lib/support/CodeUtils.h>
29+
#include <platform/CHIPDeviceLayer.h>
3130
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>
32-
3331
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
3432
#include <setup_payload/SetupPayload.h>
3533

36-
#include <lib/support/CodeUtils.h>
37-
38-
#include <platform/CHIPDeviceLayer.h>
39-
4034
#if (defined(SL_CATALOG_SIMPLE_LED_LED1_PRESENT) || defined(BRD4325B))
4135
#define LIGHT_LED 1
4236
#else
@@ -83,6 +77,9 @@ CHIP_ERROR AppTask::Init()
8377
appError(err);
8478
}
8579

80+
// Register Smoke & Co Test Event Trigger
81+
Server::GetInstance().GetTestEventTriggerDelegate()->AddHandler(&AlarmMgr());
82+
8683
sAlarmLED.Init(LIGHT_LED);
8784
sAlarmLED.Set(false);
8885

examples/smoke-co-alarm-app/silabs/src/SmokeCoAlarmManager.cpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -117,40 +117,40 @@ void SmokeCoAlarmManager::EndSelfTestingEventHandler(AppEvent * aEvent)
117117
SILABS_LOG("End self-testing!");
118118
}
119119

120-
bool emberAfHandleEventTrigger(uint64_t eventTrigger)
120+
CHIP_ERROR SmokeCoAlarmManager::HandleEventTrigger(uint64_t eventTrigger)
121121
{
122122
SmokeCOTrigger trigger = static_cast<SmokeCOTrigger>(eventTrigger);
123123

124124
switch (trigger)
125125
{
126126
case SmokeCOTrigger::kForceSmokeCritical:
127127
ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force smoke (critical)");
128-
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetSmokeState(1, AlarmStateEnum::kCritical), true);
128+
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetSmokeState(1, AlarmStateEnum::kCritical), CHIP_NO_ERROR);
129129
SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder);
130130
break;
131131
case SmokeCOTrigger::kForceSmokeWarning:
132132
ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force smoke (warning)");
133-
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetSmokeState(1, AlarmStateEnum::kWarning), true);
133+
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetSmokeState(1, AlarmStateEnum::kWarning), CHIP_NO_ERROR);
134134
SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder);
135135
break;
136136
case SmokeCOTrigger::kForceSmokeInterconnect:
137137
ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force smoke interconnect (warning)");
138-
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetInterconnectSmokeAlarm(1, AlarmStateEnum::kWarning), true);
138+
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetInterconnectSmokeAlarm(1, AlarmStateEnum::kWarning), CHIP_NO_ERROR);
139139
SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder);
140140
break;
141141
case SmokeCOTrigger::kForceCOCritical:
142142
ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force CO (critical)");
143-
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetCOState(1, AlarmStateEnum::kCritical), true);
143+
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetCOState(1, AlarmStateEnum::kCritical), CHIP_NO_ERROR);
144144
SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder);
145145
break;
146146
case SmokeCOTrigger::kForceCOWarning:
147147
ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force CO (warning)");
148-
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetCOState(1, AlarmStateEnum::kWarning), true);
148+
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetCOState(1, AlarmStateEnum::kWarning), CHIP_NO_ERROR);
149149
SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder);
150150
break;
151151
case SmokeCOTrigger::kForceCOInterconnect:
152152
ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force CO (warning)");
153-
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetInterconnectCOAlarm(1, AlarmStateEnum::kWarning), true);
153+
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetInterconnectCOAlarm(1, AlarmStateEnum::kWarning), CHIP_NO_ERROR);
154154
SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder);
155155
break;
156156
case SmokeCOTrigger::kForceSmokeContaminationHigh:
@@ -171,22 +171,22 @@ bool emberAfHandleEventTrigger(uint64_t eventTrigger)
171171
break;
172172
case SmokeCOTrigger::kForceMalfunction:
173173
ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force malfunction");
174-
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetHardwareFaultAlert(1, true), true);
174+
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetHardwareFaultAlert(1, true), CHIP_NO_ERROR);
175175
SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder);
176176
break;
177177
case SmokeCOTrigger::kForceLowBatteryWarning:
178178
ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force low battery (warning)");
179-
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetBatteryAlert(1, AlarmStateEnum::kWarning), true);
179+
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetBatteryAlert(1, AlarmStateEnum::kWarning), CHIP_NO_ERROR);
180180
SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder);
181181
break;
182182
case SmokeCOTrigger::kForceLowBatteryCritical:
183183
ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force low battery (critical)");
184-
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetBatteryAlert(1, AlarmStateEnum::kCritical), true);
184+
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetBatteryAlert(1, AlarmStateEnum::kCritical), CHIP_NO_ERROR);
185185
SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder);
186186
break;
187187
case SmokeCOTrigger::kForceEndOfLife:
188188
ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force end-of-life");
189-
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetEndOfServiceAlert(1, EndOfServiceEnum::kExpired), true);
189+
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetEndOfServiceAlert(1, EndOfServiceEnum::kExpired), CHIP_NO_ERROR);
190190
SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder);
191191
break;
192192
case SmokeCOTrigger::kForceSilence:
@@ -195,32 +195,32 @@ bool emberAfHandleEventTrigger(uint64_t eventTrigger)
195195
break;
196196
case SmokeCOTrigger::kClearSmoke:
197197
ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Clear smoke");
198-
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetSmokeState(1, AlarmStateEnum::kNormal), true);
198+
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetSmokeState(1, AlarmStateEnum::kNormal), CHIP_NO_ERROR);
199199
SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder);
200200
break;
201201
case SmokeCOTrigger::kClearCO:
202202
ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Clear CO");
203-
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetCOState(1, AlarmStateEnum::kNormal), true);
203+
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetCOState(1, AlarmStateEnum::kNormal), CHIP_NO_ERROR);
204204
SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder);
205205
break;
206206
case SmokeCOTrigger::kClearSmokeInterconnect:
207207
ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Clear smoke interconnect");
208-
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetInterconnectSmokeAlarm(1, AlarmStateEnum::kNormal), true);
208+
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetInterconnectSmokeAlarm(1, AlarmStateEnum::kNormal), CHIP_NO_ERROR);
209209
SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder);
210210
break;
211211
case SmokeCOTrigger::kClearCOInterconnect:
212212
ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Clear CO interconnect");
213-
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetInterconnectCOAlarm(1, AlarmStateEnum::kNormal), true);
213+
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetInterconnectCOAlarm(1, AlarmStateEnum::kNormal), CHIP_NO_ERROR);
214214
SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder);
215215
break;
216216
case SmokeCOTrigger::kClearMalfunction:
217217
ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Clear malfunction");
218-
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetHardwareFaultAlert(1, false), true);
218+
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetHardwareFaultAlert(1, false), CHIP_NO_ERROR);
219219
SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder);
220220
break;
221221
case SmokeCOTrigger::kClearEndOfLife:
222222
ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Clear end-of-life");
223-
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetEndOfServiceAlert(1, EndOfServiceEnum::kNormal), true);
223+
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetEndOfServiceAlert(1, EndOfServiceEnum::kNormal), CHIP_NO_ERROR);
224224
SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder);
225225
break;
226226
case SmokeCOTrigger::kClearSilence:
@@ -229,7 +229,7 @@ bool emberAfHandleEventTrigger(uint64_t eventTrigger)
229229
break;
230230
case SmokeCOTrigger::kClearBatteryLevelLow:
231231
ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Clear low battery");
232-
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetBatteryAlert(1, AlarmStateEnum::kNormal), true);
232+
VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetBatteryAlert(1, AlarmStateEnum::kNormal), CHIP_NO_ERROR);
233233
SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder);
234234
break;
235235
case SmokeCOTrigger::kClearContamination:
@@ -242,8 +242,8 @@ bool emberAfHandleEventTrigger(uint64_t eventTrigger)
242242
break;
243243
default:
244244

245-
return false;
245+
return CHIP_ERROR_INVALID_ARGUMENT;
246246
}
247247

248-
return true;
248+
return CHIP_NO_ERROR;
249249
}

0 commit comments

Comments
 (0)