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 688c3ba1ef6722..d8495dc6df6593 100644 --- a/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp +++ b/src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp @@ -28,6 +28,7 @@ using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; +using namespace chip::app::Clusters::GeneralDiagnostics; using namespace chip::app::Clusters::GeneralDiagnostics::Attributes; using namespace chip::DeviceLayer; using chip::DeviceLayer::ConnectivityMgr; @@ -215,7 +216,8 @@ class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelega } // Get called when the Node detects a hardware fault has been raised. - void OnHardwareFaultsDetected() override + void OnHardwareFaultsDetected(GeneralFaults & previous, + GeneralFaults & current) override { ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnHardwareFaultsDetected"); @@ -236,7 +238,7 @@ class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelega } // Get called when the Node detects a radio fault has been raised. - void OnRadioFaultsDetected() override + void OnRadioFaultsDetected(GeneralFaults & previous, GeneralFaults & current) override { ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnHardwareFaultsDetected"); @@ -257,7 +259,7 @@ class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelega } // Get called when the Node detects a network fault has been raised. - void OnNetworkFaultsDetected() override + void OnNetworkFaultsDetected(GeneralFaults & previous, GeneralFaults & current) override { ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnHardwareFaultsDetected"); diff --git a/src/include/platform/DiagnosticDataProvider.h b/src/include/platform/DiagnosticDataProvider.h index f28e33477fdf52..e02a96201db182 100644 --- a/src/include/platform/DiagnosticDataProvider.h +++ b/src/include/platform/DiagnosticDataProvider.h @@ -67,19 +67,20 @@ class GeneralDiagnosticsDelegate * @brief * Called when the Node detects a hardware fault has been raised. */ - virtual void OnHardwareFaultsDetected() {} + virtual void OnHardwareFaultsDetected(GeneralFaults & previous, GeneralFaults & current) + {} /** * @brief * Called when the Node detects a radio fault has been raised. */ - virtual void OnRadioFaultsDetected() {} + virtual void OnRadioFaultsDetected(GeneralFaults & previous, GeneralFaults & current) {} /** * @brief * Called when the Node detects a network fault has been raised. */ - virtual void OnNetworkFaultsDetected() {} + virtual void OnNetworkFaultsDetected(GeneralFaults & previous, GeneralFaults & current) {} }; /** diff --git a/src/platform/Linux/PlatformManagerImpl.cpp b/src/platform/Linux/PlatformManagerImpl.cpp index e1623903140b9f..76ac2fa9679f55 100644 --- a/src/platform/Linux/PlatformManagerImpl.cpp +++ b/src/platform/Linux/PlatformManagerImpl.cpp @@ -275,22 +275,64 @@ void PlatformManagerImpl::HandleGeneralFault(uint32_t EventId) { GeneralDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetGeneralDiagnosticsDelegate(); - if (delegate != nullptr) + if (delegate == nullptr) + { + ChipLogError(DeviceLayer, "No delegate registered to handle General Diagnostics event"); + return; + } + + if (EventId == GeneralDiagnostics::Events::HardwareFaultChange::kEventId) + { + GeneralFaults previous; + GeneralFaults current; + +#if CHIP_CONFIG_TEST + // On Linux Simulation, set following hardware faults statically. + ReturnOnFailure(previous.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_RADIO)); + ReturnOnFailure(previous.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_POWER_SOURCE)); + + ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_RADIO)); + ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_SENSOR)); + ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_POWER_SOURCE)); + ReturnOnFailure(current.add(EMBER_ZCL_HARDWARE_FAULT_TYPE_USER_INTERFACE_FAULT)); +#endif + delegate->OnHardwareFaultsDetected(previous, current); + } + else if (EventId == GeneralDiagnostics::Events::RadioFaultChange::kEventId) + { + GeneralFaults previous; + GeneralFaults current; + +#if CHIP_CONFIG_TEST + // On Linux Simulation, set following radio faults statically. + ReturnOnFailure(previous.add(EMBER_ZCL_RADIO_FAULT_TYPE_WI_FI_FAULT)); + ReturnOnFailure(previous.add(EMBER_ZCL_RADIO_FAULT_TYPE_THREAD_FAULT)); + + ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_WI_FI_FAULT)); + ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_CELLULAR_FAULT)); + ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_THREAD_FAULT)); + ReturnOnFailure(current.add(EMBER_ZCL_RADIO_FAULT_TYPE_NFC_FAULT)); +#endif + delegate->OnRadioFaultsDetected(previous, current); + } + else if (EventId == GeneralDiagnostics::Events::NetworkFaultChange::kEventId) + { + GeneralFaults previous; + GeneralFaults current; + +#if CHIP_CONFIG_TEST + // On Linux Simulation, set following radio faults statically. + ReturnOnFailure(previous.add(EMBER_ZCL_NETWORK_FAULT_TYPE_HARDWARE_FAILURE)); + ReturnOnFailure(previous.add(EMBER_ZCL_NETWORK_FAULT_TYPE_NETWORK_JAMMED)); + + ReturnOnFailure(current.add(EMBER_ZCL_NETWORK_FAULT_TYPE_HARDWARE_FAILURE)); + ReturnOnFailure(current.add(EMBER_ZCL_NETWORK_FAULT_TYPE_NETWORK_JAMMED)); + ReturnOnFailure(current.add(EMBER_ZCL_NETWORK_FAULT_TYPE_CONNECTION_FAILED)); +#endif + delegate->OnNetworkFaultsDetected(previous, current); + } + else { - switch (EventId) - { - case GeneralDiagnostics::Events::HardwareFaultChange::kEventId: - delegate->OnHardwareFaultsDetected(); - break; - case GeneralDiagnostics::Events::RadioFaultChange::kEventId: - delegate->OnRadioFaultsDetected(); - break; - case GeneralDiagnostics::Events::NetworkFaultChange::kEventId: - delegate->OnNetworkFaultsDetected(); - break; - default: - break; - } } }