Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement event support for Software Diagnostics cluster #12492

Merged
merged 1 commit into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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