Skip to content

Commit

Permalink
Implement event support for Software Diagnostics cluster (#12492)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored and pull[bot] committed Dec 7, 2021
1 parent fd51c3f commit 1401972
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/include/platform/DiagnosticDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
};

/**
Expand Down
11 changes: 10 additions & 1 deletion src/platform/Linux/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 1401972

Please sign in to comment.