Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Jun 6, 2022
1 parent 42e5861 commit 9758bae
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 36 deletions.
11 changes: 6 additions & 5 deletions examples/all-clusters-app/linux/main-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ void HandleSoftwareFaultEvent(intptr_t arg)
Clusters::SoftwareDiagnostics::Structs::SoftwareFaultStruct::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::fromCharString(threadName);
softwareFault.faultRecording = ByteSpan(Uint8::from_const_char("FaultRecording"), strlen("FaultRecording"));
softwareFault.id = gettid();
const char * softwareFaultStr = std::to_string(softwareFault.id).c_str();
Platform::CopyString(threadName, kMaxThreadNameLength + 1, softwareFaultStr);

softwareFault.name = CharSpan::fromCharString(threadName);
softwareFault.faultRecording = ByteSpan(Uint8::from_const_char(softwareFaultStr), strlen(softwareFaultStr));

Clusters::SoftwareDiagnostics::Server::Instance().OnSoftwareFaultDetect(softwareFault);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,22 @@ void Server::OnDeviceReboot(BootReasonType bootReason)
ReportAttributeOnAllEndpoints(GeneralDiagnostics::Attributes::BootReasons::Id);

// GeneralDiagnostics cluster should exist only for endpoint 0.

Events::BootReason::Type event{ bootReason };
EventNumber eventNumber;

CHIP_ERROR err = LogEvent(event, 0, eventNumber);
if (CHIP_NO_ERROR != err)
if (emberAfContainsServer(0, GeneralDiagnostics::Id))
{
ChipLogError(Zcl, "GeneralDiagnostics: Failed to record BootReason event: %" CHIP_ERROR_FORMAT, err.Format());
Events::BootReason::Type event{ bootReason };
EventNumber eventNumber;

CHIP_ERROR err = LogEvent(event, 0, eventNumber);
if (CHIP_NO_ERROR != err)
{
ChipLogError(Zcl, "GeneralDiagnostics: Failed to record BootReason event: %" CHIP_ERROR_FORMAT, err.Format());
}
}
}

// Get called when the Node detects a hardware fault has been raised.
void Server::OnHardwareFaultsDetect(GeneralFaults<kMaxHardwareFaults> & previous, GeneralFaults<kMaxHardwareFaults> & current)
void Server::OnHardwareFaultsDetect(const GeneralFaults<kMaxHardwareFaults> & previous,
const GeneralFaults<kMaxHardwareFaults> & current)
{
ChipLogDetail(Zcl, "GeneralDiagnostics: OnHardwareFaultsDetect");

Expand All @@ -274,10 +277,10 @@ void Server::OnHardwareFaultsDetect(GeneralFaults<kMaxHardwareFaults> & previous

// Record HardwareFault event
EventNumber eventNumber;
DataModel::List<const HardwareFaultType> currentList =
DataModel::List<const HardwareFaultType>(reinterpret_cast<const HardwareFaultType *>(current.data()), current.size());
DataModel::List<const HardwareFaultType> previousList =
DataModel::List<const HardwareFaultType>(reinterpret_cast<const HardwareFaultType *>(previous.data()), previous.size());
DataModel::List<const HardwareFaultType> currentList(reinterpret_cast<const HardwareFaultType *>(current.data()),
current.size());
DataModel::List<const HardwareFaultType> previousList(reinterpret_cast<const HardwareFaultType *>(previous.data()),
previous.size());
Events::HardwareFaultChange::Type event{ currentList, previousList };

if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber))
Expand All @@ -288,7 +291,7 @@ void Server::OnHardwareFaultsDetect(GeneralFaults<kMaxHardwareFaults> & previous
}

// Get called when the Node detects a radio fault has been raised.
void Server::OnRadioFaultsDetect(GeneralFaults<kMaxRadioFaults> & previous, GeneralFaults<kMaxRadioFaults> & current)
void Server::OnRadioFaultsDetect(const GeneralFaults<kMaxRadioFaults> & previous, const GeneralFaults<kMaxRadioFaults> & current)
{
ChipLogDetail(Zcl, "GeneralDiagnostics: OnRadioFaultsDetect");

Expand All @@ -300,10 +303,9 @@ void Server::OnRadioFaultsDetect(GeneralFaults<kMaxRadioFaults> & previous, Gene

// Record RadioFault event
EventNumber eventNumber;
DataModel::List<const RadioFaultType> currentList =
DataModel::List<const RadioFaultType>(reinterpret_cast<const RadioFaultType *>(current.data()), current.size());
DataModel::List<const RadioFaultType> previousList =
DataModel::List<const RadioFaultType>(reinterpret_cast<const RadioFaultType *>(previous.data()), previous.size());
DataModel::List<const RadioFaultType> currentList(reinterpret_cast<const RadioFaultType *>(current.data()), current.size());
DataModel::List<const RadioFaultType> previousList(reinterpret_cast<const RadioFaultType *>(previous.data()),
previous.size());
Events::RadioFaultChange::Type event{ currentList, previousList };

if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber))
Expand All @@ -314,7 +316,8 @@ void Server::OnRadioFaultsDetect(GeneralFaults<kMaxRadioFaults> & previous, Gene
}

// Get called when the Node detects a network fault has been raised.
void Server::OnNetworkFaultsDetect(GeneralFaults<kMaxNetworkFaults> & previous, GeneralFaults<kMaxNetworkFaults> & current)
void Server::OnNetworkFaultsDetect(const GeneralFaults<kMaxNetworkFaults> & previous,
const GeneralFaults<kMaxNetworkFaults> & current)
{
ChipLogDetail(Zcl, "GeneralDiagnostics: OnNetworkFaultsDetect");

Expand All @@ -326,10 +329,10 @@ void Server::OnNetworkFaultsDetect(GeneralFaults<kMaxNetworkFaults> & previous,

// Record NetworkFault event
EventNumber eventNumber;
DataModel::List<const NetworkFaultType> currentList =
DataModel::List<const NetworkFaultType>(reinterpret_cast<const NetworkFaultType *>(current.data()), current.size());
DataModel::List<const NetworkFaultType> previousList =
DataModel::List<const NetworkFaultType>(reinterpret_cast<const NetworkFaultType *>(previous.data()), previous.size());
DataModel::List<const NetworkFaultType> currentList(reinterpret_cast<const NetworkFaultType *>(current.data()),
current.size());
DataModel::List<const NetworkFaultType> previousList(reinterpret_cast<const NetworkFaultType *>(previous.data()),
previous.size());
Events::NetworkFaultChange::Type event{ currentList, previousList };

if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ class Server
* @brief
* Called when the Node detects a hardware fault has been raised.
*/
void OnHardwareFaultsDetect(DeviceLayer::GeneralFaults<DeviceLayer::kMaxHardwareFaults> & previous,
DeviceLayer::GeneralFaults<DeviceLayer::kMaxHardwareFaults> & current);
void OnHardwareFaultsDetect(const DeviceLayer::GeneralFaults<DeviceLayer::kMaxHardwareFaults> & previous,
const DeviceLayer::GeneralFaults<DeviceLayer::kMaxHardwareFaults> & current);

/**
* @brief
* Called when the Node detects a radio fault has been raised.
*/
void OnRadioFaultsDetect(DeviceLayer::GeneralFaults<DeviceLayer::kMaxRadioFaults> & previous,
DeviceLayer::GeneralFaults<DeviceLayer::kMaxRadioFaults> & current);
void OnRadioFaultsDetect(const DeviceLayer::GeneralFaults<DeviceLayer::kMaxRadioFaults> & previous,
const DeviceLayer::GeneralFaults<DeviceLayer::kMaxRadioFaults> & current);

/**
* @brief
* Called when the Node detects a network fault has been raised.
*/
void OnNetworkFaultsDetect(DeviceLayer::GeneralFaults<DeviceLayer::kMaxNetworkFaults> & previous,
DeviceLayer::GeneralFaults<DeviceLayer::kMaxNetworkFaults> & current);
void OnNetworkFaultsDetect(const DeviceLayer::GeneralFaults<DeviceLayer::kMaxNetworkFaults> & previous,
const DeviceLayer::GeneralFaults<DeviceLayer::kMaxNetworkFaults> & current);

private:
static Server instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Server & Server::Instance()
}

// Gets called when a software fault that has taken place on the Node.
void Server::OnSoftwareFaultDetect(SoftwareDiagnostics::Structs::SoftwareFaultStruct::Type & softwareFault)
void Server::OnSoftwareFaultDetect(const SoftwareDiagnostics::Structs::SoftwareFaultStruct::Type & softwareFault)
{
ChipLogDetail(Zcl, "SoftwareDiagnosticsDelegate: OnSoftwareFaultDetected");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Server
* @brief
* Called when a software fault that has taken place on the Node.
*/
void OnSoftwareFaultDetect(chip::app::Clusters::SoftwareDiagnostics::Structs::SoftwareFaultStruct::Type & softwareFault);
void OnSoftwareFaultDetect(const chip::app::Clusters::SoftwareDiagnostics::Structs::SoftwareFaultStruct::Type & softwareFault);

private:
static Server instance;
Expand Down
2 changes: 1 addition & 1 deletion src/include/platform/GeneralFaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class GeneralFaults

CHIP_ERROR add(const uint8_t value);

uint8_t * data() { return mData; }
const uint8_t * data() const { return mData; }
size_t size() const;
uint8_t operator[](int index) const;

Expand Down

0 comments on commit 9758bae

Please sign in to comment.