Skip to content

Commit

Permalink
Implement event support for General Diagnostics cluster (#12502)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored and pull[bot] committed Jan 4, 2022
1 parent abad8f8 commit 1199903
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<kMaxHardwareFaults> & previous,
GeneralFaults<kMaxHardwareFaults> & current) override
{
ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnHardwareFaultsDetected");

Expand All @@ -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<kMaxRadioFaults> & previous, GeneralFaults<kMaxRadioFaults> & current) override
{
ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnHardwareFaultsDetected");

Expand All @@ -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<kMaxNetworkFaults> & previous, GeneralFaults<kMaxNetworkFaults> & current) override
{
ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnHardwareFaultsDetected");

Expand Down
7 changes: 4 additions & 3 deletions src/include/platform/DiagnosticDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<kMaxHardwareFaults> & previous, GeneralFaults<kMaxHardwareFaults> & current)
{}

/**
* @brief
* Called when the Node detects a radio fault has been raised.
*/
virtual void OnRadioFaultsDetected() {}
virtual void OnRadioFaultsDetected(GeneralFaults<kMaxRadioFaults> & previous, GeneralFaults<kMaxRadioFaults> & current) {}

/**
* @brief
* Called when the Node detects a network fault has been raised.
*/
virtual void OnNetworkFaultsDetected() {}
virtual void OnNetworkFaultsDetected(GeneralFaults<kMaxNetworkFaults> & previous, GeneralFaults<kMaxNetworkFaults> & current) {}
};

/**
Expand Down
72 changes: 57 additions & 15 deletions src/platform/Linux/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<kMaxHardwareFaults> previous;
GeneralFaults<kMaxHardwareFaults> 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<kMaxRadioFaults> previous;
GeneralFaults<kMaxRadioFaults> 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<kMaxNetworkFaults> previous;
GeneralFaults<kMaxNetworkFaults> 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;
}
}
}

Expand Down

0 comments on commit 1199903

Please sign in to comment.