Skip to content

Commit

Permalink
Implement event support for Software Diagnostics cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Dec 2, 2021
1 parent ae75d75 commit fbbb4b3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,33 @@ 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
#if 0
EventNumber eventNumber;
EventOptions eventOptions(EventOptions::Type::kNotUrgent);
Events::SoftwareFault::Type event{ softwareFault };
if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventOptions, eventNumber))
{
ChipLogError(Zcl, "SoftwareDiagnosticsDelegate: Failed to record SoftwareFault event with number: %ld",
eventNumber);
}
#endif
}
}
}
}
};

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 fbbb4b3

Please sign in to comment.