From 1151984aa0f81e99961afb666556c5620e6b44fb Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Tue, 23 Nov 2021 06:19:41 -0800 Subject: [PATCH] Reporting relevant attribute change when various faults are detected (#12116) * Reporting relevant attribute change when various faults are detected * Update src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp Co-authored-by: Michael Sandstedt * Update src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp Co-authored-by: Michael Sandstedt Co-authored-by: Michael Sandstedt --- .../general_diagnostics_server.cpp | 63 +++++++++++++++++++ src/include/platform/DiagnosticDataProvider.h | 20 +++++- 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp b/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp index dc35be5453494c..daa3b6b90b98eb 100644 --- a/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp +++ b/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp @@ -213,6 +213,69 @@ class GeneralDiagnosticDelegate : public DeviceLayer::ConnectivityManagerDelegat } } } + + // Get called when the Node detects a hardware fault has been raised. + void OnHardwareFaultsDetected() override + { + ChipLogProgress(Zcl, "GeneralDiagnosticDelegate: OnHardwareFaultsDetected"); + + for (uint16_t index = 0; index < emberAfEndpointCount(); index++) + { + if (emberAfEndpointIndexIsEnabled(index)) + { + EndpointId endpointId = emberAfEndpointFromIndex(index); + + if (emberAfContainsServer(endpointId, GeneralDiagnostics::Id)) + { + // If General Diagnostics cluster is implemented on this endpoint + MatterReportingAttributeChangeCallback(endpointId, GeneralDiagnostics::Id, + GeneralDiagnostics::Attributes::ActiveHardwareFaults::Id); + } + } + } + } + + // Get called when the Node detects a radio fault has been raised. + void OnRadioFaultsDetected() override + { + ChipLogProgress(Zcl, "GeneralDiagnosticDelegate: OnHardwareFaultsDetected"); + + for (uint16_t index = 0; index < emberAfEndpointCount(); index++) + { + if (emberAfEndpointIndexIsEnabled(index)) + { + EndpointId endpointId = emberAfEndpointFromIndex(index); + + if (emberAfContainsServer(endpointId, GeneralDiagnostics::Id)) + { + // If General Diagnostics cluster is implemented on this endpoint + MatterReportingAttributeChangeCallback(endpointId, GeneralDiagnostics::Id, + GeneralDiagnostics::Attributes::ActiveRadioFaults::Id); + } + } + } + } + + // Get called when the Node detects a network fault has been raised. + void OnNetworkFaultsDetected() override + { + ChipLogProgress(Zcl, "GeneralDiagnosticDelegate: OnHardwareFaultsDetected"); + + for (uint16_t index = 0; index < emberAfEndpointCount(); index++) + { + if (emberAfEndpointIndexIsEnabled(index)) + { + EndpointId endpointId = emberAfEndpointFromIndex(index); + + if (emberAfContainsServer(endpointId, GeneralDiagnostics::Id)) + { + // If General Diagnostics cluster is implemented on this endpoint + MatterReportingAttributeChangeCallback(endpointId, GeneralDiagnostics::Id, + GeneralDiagnostics::Attributes::ActiveNetworkFaults::Id); + } + } + } + } }; GeneralDiagnosticDelegate gDiagnosticDelegate; diff --git a/src/include/platform/DiagnosticDataProvider.h b/src/include/platform/DiagnosticDataProvider.h index b64914688c1d4d..e83f8f05f1088e 100644 --- a/src/include/platform/DiagnosticDataProvider.h +++ b/src/include/platform/DiagnosticDataProvider.h @@ -49,9 +49,27 @@ class DiagnosticsDelegate /** * @brief - * Called after the current device is rebooted + * Called after the current device is rebooted. */ virtual void OnDeviceRebooted() {} + + /** + * @brief + * Called when the Node detects a hardware fault has been raised. + */ + virtual void OnHardwareFaultsDetected() {} + + /** + * @brief + * Called when the Node detects a radio fault has been raised. + */ + virtual void OnRadioFaultsDetected() {} + + /** + * @brief + * Called when the Node detects a network fault has been raised. + */ + virtual void OnNetworkFaultsDetected() {} }; /**