Skip to content

Commit 1134196

Browse files
yufengwangcapull[bot]
authored andcommitted
Implement event support for General Diagnostics cluster (#12502)
1 parent 61bef92 commit 1134196

File tree

3 files changed

+66
-21
lines changed

3 files changed

+66
-21
lines changed

src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
using namespace chip;
2929
using namespace chip::app;
3030
using namespace chip::app::Clusters;
31+
using namespace chip::app::Clusters::GeneralDiagnostics;
3132
using namespace chip::app::Clusters::GeneralDiagnostics::Attributes;
3233
using namespace chip::DeviceLayer;
3334
using chip::DeviceLayer::ConnectivityMgr;
@@ -215,7 +216,8 @@ class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelega
215216
}
216217

217218
// Get called when the Node detects a hardware fault has been raised.
218-
void OnHardwareFaultsDetected() override
219+
void OnHardwareFaultsDetected(GeneralFaults<kMaxHardwareFaults> & previous,
220+
GeneralFaults<kMaxHardwareFaults> & current) override
219221
{
220222
ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnHardwareFaultsDetected");
221223

@@ -236,7 +238,7 @@ class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelega
236238
}
237239

238240
// Get called when the Node detects a radio fault has been raised.
239-
void OnRadioFaultsDetected() override
241+
void OnRadioFaultsDetected(GeneralFaults<kMaxRadioFaults> & previous, GeneralFaults<kMaxRadioFaults> & current) override
240242
{
241243
ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnHardwareFaultsDetected");
242244

@@ -257,7 +259,7 @@ class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelega
257259
}
258260

259261
// Get called when the Node detects a network fault has been raised.
260-
void OnNetworkFaultsDetected() override
262+
void OnNetworkFaultsDetected(GeneralFaults<kMaxNetworkFaults> & previous, GeneralFaults<kMaxNetworkFaults> & current) override
261263
{
262264
ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnHardwareFaultsDetected");
263265

src/include/platform/DiagnosticDataProvider.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,20 @@ class GeneralDiagnosticsDelegate
6767
* @brief
6868
* Called when the Node detects a hardware fault has been raised.
6969
*/
70-
virtual void OnHardwareFaultsDetected() {}
70+
virtual void OnHardwareFaultsDetected(GeneralFaults<kMaxHardwareFaults> & previous, GeneralFaults<kMaxHardwareFaults> & current)
71+
{}
7172

7273
/**
7374
* @brief
7475
* Called when the Node detects a radio fault has been raised.
7576
*/
76-
virtual void OnRadioFaultsDetected() {}
77+
virtual void OnRadioFaultsDetected(GeneralFaults<kMaxRadioFaults> & previous, GeneralFaults<kMaxRadioFaults> & current) {}
7778

7879
/**
7980
* @brief
8081
* Called when the Node detects a network fault has been raised.
8182
*/
82-
virtual void OnNetworkFaultsDetected() {}
83+
virtual void OnNetworkFaultsDetected(GeneralFaults<kMaxNetworkFaults> & previous, GeneralFaults<kMaxNetworkFaults> & current) {}
8384
};
8485

8586
/**

src/platform/Linux/PlatformManagerImpl.cpp

+57-15
Original file line numberDiff line numberDiff line change
@@ -275,22 +275,64 @@ void PlatformManagerImpl::HandleGeneralFault(uint32_t EventId)
275275
{
276276
GeneralDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetGeneralDiagnosticsDelegate();
277277

278-
if (delegate != nullptr)
278+
if (delegate == nullptr)
279+
{
280+
ChipLogError(DeviceLayer, "No delegate registered to handle General Diagnostics event");
281+
return;
282+
}
283+
284+
if (EventId == GeneralDiagnostics::Events::HardwareFaultChange::kEventId)
285+
{
286+
GeneralFaults<kMaxHardwareFaults> previous;
287+
GeneralFaults<kMaxHardwareFaults> current;
288+
289+
#if CHIP_CONFIG_TEST
290+
// On Linux Simulation, set following hardware faults statically.
291+
ReturnOnFailure(previous.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_RADIO));
292+
ReturnOnFailure(previous.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_POWER_SOURCE));
293+
294+
ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_RADIO));
295+
ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_SENSOR));
296+
ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_POWER_SOURCE));
297+
ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_USER_INTERFACE_FAULT));
298+
#endif
299+
delegate->OnHardwareFaultsDetected(previous, current);
300+
}
301+
else if (EventId == GeneralDiagnostics::Events::RadioFaultChange::kEventId)
302+
{
303+
GeneralFaults<kMaxRadioFaults> previous;
304+
GeneralFaults<kMaxRadioFaults> current;
305+
306+
#if CHIP_CONFIG_TEST
307+
// On Linux Simulation, set following radio faults statically.
308+
ReturnOnFailure(previous.add(EMBER_ZCL_RADIO_FAULT_TYPE_WI_FI_FAULT));
309+
ReturnOnFailure(previous.add(EMBER_ZCL_RADIO_FAULT_TYPE_THREAD_FAULT));
310+
311+
ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_WI_FI_FAULT));
312+
ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_CELLULAR_FAULT));
313+
ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_THREAD_FAULT));
314+
ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_NFC_FAULT));
315+
#endif
316+
delegate->OnRadioFaultsDetected(previous, current);
317+
}
318+
else if (EventId == GeneralDiagnostics::Events::NetworkFaultChange::kEventId)
319+
{
320+
GeneralFaults<kMaxNetworkFaults> previous;
321+
GeneralFaults<kMaxNetworkFaults> current;
322+
323+
#if CHIP_CONFIG_TEST
324+
// On Linux Simulation, set following radio faults statically.
325+
ReturnOnFailure(previous.add(EMBER_ZCL_NETWORK_FAULT_TYPE_HARDWARE_FAILURE));
326+
ReturnOnFailure(previous.add(EMBER_ZCL_NETWORK_FAULT_TYPE_NETWORK_JAMMED));
327+
328+
ReturnOnFailure(current.add(EMBER_ZCL_NETWORK_FAULT_TYPE_HARDWARE_FAILURE));
329+
ReturnOnFailure(current.add(EMBER_ZCL_NETWORK_FAULT_TYPE_NETWORK_JAMMED));
330+
ReturnOnFailure(current.add(EMBER_ZCL_NETWORK_FAULT_TYPE_CONNECTION_FAILED));
331+
#endif
332+
delegate->OnNetworkFaultsDetected(previous, current);
333+
}
334+
else
279335
{
280-
switch (EventId)
281-
{
282-
case GeneralDiagnostics::Events::HardwareFaultChange::kEventId:
283-
delegate->OnHardwareFaultsDetected();
284-
break;
285-
case GeneralDiagnostics::Events::RadioFaultChange::kEventId:
286-
delegate->OnRadioFaultsDetected();
287-
break;
288-
case GeneralDiagnostics::Events::NetworkFaultChange::kEventId:
289-
delegate->OnNetworkFaultsDetected();
290-
break;
291-
default:
292-
break;
293-
}
294336
}
295337
}
296338

0 commit comments

Comments
 (0)