diff --git a/src/app/clusters/software_diagnostics_server/software_diagnostics_server.cpp b/src/app/clusters/software_diagnostics_server/software_diagnostics_server.cpp index 7ed40d6d29a0a7..8d93b297ab57b9 100644 --- a/src/app/clusters/software_diagnostics_server/software_diagnostics_server.cpp +++ b/src/app/clusters/software_diagnostics_server/software_diagnostics_server.cpp @@ -127,7 +127,24 @@ CHIP_ERROR SoftwareDiagosticsAttrAccess::ReadThreadMetrics(AttributeValueEncoder class SoftwareDiagnosticsDelegate : public DeviceLayer::SoftwareDiagnosticsDelegate { // Gets called when a software fault that has taken place on the Node. - void OnSoftwareFaultDetected() override { ChipLogProgress(Zcl, "SoftwareDiagnosticsDelegate: OnSoftwareFaultDetected"); } + void OnSoftwareFaultDetected(SoftwareDiagnostics::Structs::SoftwareFault::Type & softwareFault) override + { + ChipLogProgress(Zcl, "SoftwareDiagnosticsDelegate: OnSoftwareFaultDetected"); + + for (uint16_t index = 0; index < emberAfEndpointCount(); index++) + { + if (emberAfEndpointIndexIsEnabled(index)) + { + EndpointId endpointId = emberAfEndpointFromIndex(index); + + if (emberAfContainsServer(endpointId, SoftwareDiagnostics::Id)) + { + // If Software Diagnostics cluster is implemented on this endpoint + // TODO: Log SoftwareFault event + } + } + } + } }; SoftwareDiagnosticsDelegate gDiagnosticDelegate; diff --git a/src/include/platform/DiagnosticDataProvider.h b/src/include/platform/DiagnosticDataProvider.h index 3ac8a47f6ae05b..f28e33477fdf52 100644 --- a/src/include/platform/DiagnosticDataProvider.h +++ b/src/include/platform/DiagnosticDataProvider.h @@ -94,7 +94,7 @@ class SoftwareDiagnosticsDelegate * @brief * Called when a software fault that has taken place on the Node. */ - virtual void OnSoftwareFaultDetected() {} + virtual void OnSoftwareFaultDetected(chip::app::Clusters::SoftwareDiagnostics::Structs::SoftwareFault::Type & softwareFault) {} }; /** diff --git a/src/platform/Linux/PlatformManagerImpl.cpp b/src/platform/Linux/PlatformManagerImpl.cpp index c3c7b668e2b6ff..e1623903140b9f 100644 --- a/src/platform/Linux/PlatformManagerImpl.cpp +++ b/src/platform/Linux/PlatformManagerImpl.cpp @@ -300,7 +300,16 @@ void PlatformManagerImpl::HandleSoftwareFault(uint32_t EventId) if (delegate != nullptr) { - delegate->OnSoftwareFaultDetected(); + SoftwareDiagnostics::Structs::SoftwareFault::Type softwareFault; + char threadName[kMaxThreadNameLength + 1]; + + softwareFault.id = gettid(); + strncpy(threadName, std::to_string(softwareFault.id).c_str(), kMaxThreadNameLength); + threadName[kMaxThreadNameLength] = '\0'; + softwareFault.name = CharSpan(threadName, strlen(threadName)); + softwareFault.faultRecording = ByteSpan(Uint8::from_const_char("FaultRecording"), strlen("FaultRecording")); + + delegate->OnSoftwareFaultDetected(softwareFault); } }