Skip to content

Commit 2256962

Browse files
yufengwangcapull[bot]
authored andcommitted
Record events when diagnostic events occurs on platform side (#12709)
1 parent 9aa2c3f commit 2256962

File tree

4 files changed

+158
-7
lines changed

4 files changed

+158
-7
lines changed

src/app/clusters/general_diagnostics_server/general_diagnostics_server.cpp

+85
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <app-common/zap-generated/ids/Attributes.h>
2121
#include <app-common/zap-generated/ids/Clusters.h>
2222
#include <app/AttributeAccessInterface.h>
23+
#include <app/EventLogging.h>
2324
#include <app/reporting/reporting.h>
2425
#include <app/util/attribute-storage.h>
2526
#include <platform/ConnectivityManager.h>
@@ -211,6 +212,34 @@ class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelega
211212
ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnHardwareFaultsDetected");
212213

213214
ReportAttributeOnAllEndpoints(GeneralDiagnostics::Attributes::ActiveHardwareFaults::Id);
215+
216+
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
217+
{
218+
if (emberAfEndpointIndexIsEnabled(index))
219+
{
220+
EndpointId endpointId = emberAfEndpointFromIndex(index);
221+
222+
if (emberAfContainsServer(endpointId, GeneralDiagnostics::Id))
223+
{
224+
// If General Diagnostics cluster is implemented on this endpoint
225+
MatterReportingAttributeChangeCallback(endpointId, GeneralDiagnostics::Id,
226+
GeneralDiagnostics::Attributes::ActiveHardwareFaults::Id);
227+
228+
// Record HardwareFault event
229+
EventNumber eventNumber;
230+
DataModel::List<const HardwareFaultType> currentList = DataModel::List<const HardwareFaultType>(
231+
reinterpret_cast<const HardwareFaultType *>(current.data()), current.size());
232+
DataModel::List<const HardwareFaultType> previousList = DataModel::List<const HardwareFaultType>(
233+
reinterpret_cast<const HardwareFaultType *>(previous.data()), previous.size());
234+
Events::HardwareFaultChange::Type event{ currentList, previousList };
235+
236+
if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber, EventOptions::Type::kUrgent))
237+
{
238+
ChipLogError(Zcl, "GeneralDiagnosticsDelegate: Failed to record HardwareFault event");
239+
}
240+
}
241+
}
242+
}
214243
}
215244

216245
// Get called when the Node detects a radio fault has been raised.
@@ -219,6 +248,34 @@ class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelega
219248
ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnHardwareFaultsDetected");
220249

221250
ReportAttributeOnAllEndpoints(GeneralDiagnostics::Attributes::ActiveRadioFaults::Id);
251+
252+
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
253+
{
254+
if (emberAfEndpointIndexIsEnabled(index))
255+
{
256+
EndpointId endpointId = emberAfEndpointFromIndex(index);
257+
258+
if (emberAfContainsServer(endpointId, GeneralDiagnostics::Id))
259+
{
260+
// If General Diagnostics cluster is implemented on this endpoint
261+
MatterReportingAttributeChangeCallback(endpointId, GeneralDiagnostics::Id,
262+
GeneralDiagnostics::Attributes::ActiveRadioFaults::Id);
263+
264+
// Record RadioFault event
265+
EventNumber eventNumber;
266+
DataModel::List<const RadioFaultType> currentList = DataModel::List<const RadioFaultType>(
267+
reinterpret_cast<const RadioFaultType *>(current.data()), current.size());
268+
DataModel::List<const RadioFaultType> previousList = DataModel::List<const RadioFaultType>(
269+
reinterpret_cast<const RadioFaultType *>(previous.data()), previous.size());
270+
Events::RadioFaultChange::Type event{ currentList, previousList };
271+
272+
if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber, EventOptions::Type::kUrgent))
273+
{
274+
ChipLogError(Zcl, "GeneralDiagnosticsDelegate: Failed to record RadioFault event");
275+
}
276+
}
277+
}
278+
}
222279
}
223280

224281
// Get called when the Node detects a network fault has been raised.
@@ -227,6 +284,34 @@ class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelega
227284
ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnHardwareFaultsDetected");
228285

229286
ReportAttributeOnAllEndpoints(GeneralDiagnostics::Attributes::ActiveNetworkFaults::Id);
287+
288+
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
289+
{
290+
if (emberAfEndpointIndexIsEnabled(index))
291+
{
292+
EndpointId endpointId = emberAfEndpointFromIndex(index);
293+
294+
if (emberAfContainsServer(endpointId, GeneralDiagnostics::Id))
295+
{
296+
// If General Diagnostics cluster is implemented on this endpoint
297+
MatterReportingAttributeChangeCallback(endpointId, GeneralDiagnostics::Id,
298+
GeneralDiagnostics::Attributes::ActiveNetworkFaults::Id);
299+
300+
// Record NetworkFault event
301+
EventNumber eventNumber;
302+
DataModel::List<const NetworkFaultType> currentList = DataModel::List<const NetworkFaultType>(
303+
reinterpret_cast<const NetworkFaultType *>(current.data()), current.size());
304+
DataModel::List<const NetworkFaultType> previousList = DataModel::List<const NetworkFaultType>(
305+
reinterpret_cast<const NetworkFaultType *>(previous.data()), previous.size());
306+
Events::NetworkFaultChange::Type event{ currentList, previousList };
307+
308+
if (CHIP_NO_ERROR != LogEvent(event, endpointId, eventNumber, EventOptions::Type::kUrgent))
309+
{
310+
ChipLogError(Zcl, "GeneralDiagnosticsDelegate: Failed to record NetworkFault event");
311+
}
312+
}
313+
}
314+
}
230315
}
231316
};
232317

src/app/clusters/software_diagnostics_server/software_diagnostics_server.cpp

+19-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <app/AttributeAccessInterface.h>
2323
#include <app/CommandHandler.h>
2424
#include <app/ConcreteCommandPath.h>
25+
#include <app/EventLogging.h>
2526
#include <app/util/af.h>
2627
#include <app/util/attribute-storage.h>
2728
#include <lib/core/Optional.h>
@@ -131,10 +132,24 @@ class SoftwareDiagnosticsDelegate : public DeviceLayer::SoftwareDiagnosticsDeleg
131132
{
132133
ChipLogProgress(Zcl, "SoftwareDiagnosticsDelegate: OnSoftwareFaultDetected");
133134

134-
ForAllEndpointsWithServerCluster(SoftwareDiagnostics::Id, [](EndpointId endpoint, intptr_t) -> Loop {
135-
// TODO: Log SoftwareFault event and walk them all.
136-
return Loop::Break;
137-
});
135+
ForAllEndpointsWithServerCluster(
136+
SoftwareDiagnostics::Id,
137+
[](EndpointId endpoint, intptr_t context) -> Loop {
138+
// If Software Diagnostics cluster is implemented on this endpoint
139+
SoftwareDiagnostics::Structs::SoftwareFault::Type * pSoftwareFault =
140+
reinterpret_cast<SoftwareDiagnostics::Structs::SoftwareFault::Type *>(context);
141+
142+
EventNumber eventNumber;
143+
Events::SoftwareFault::Type event{ *pSoftwareFault };
144+
145+
if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
146+
{
147+
ChipLogError(Zcl, "SoftwareDiagnosticsDelegate: Failed to record SoftwareFault event");
148+
}
149+
150+
return Loop::Continue;
151+
},
152+
reinterpret_cast<intptr_t>(&softwareFault));
138153
}
139154
};
140155

src/app/clusters/wifi_network_diagnostics_server/wifi_network_diagnostics_server.cpp

+51
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <app/AttributeAccessInterface.h>
2323
#include <app/CommandHandler.h>
2424
#include <app/ConcreteCommandPath.h>
25+
#include <app/EventLogging.h>
2526
#include <app/util/af.h>
2627
#include <app/util/attribute-storage.h>
2728
#include <lib/core/Optional.h>
@@ -152,18 +153,68 @@ class WiFiDiagnosticsDelegate : public DeviceLayer::WiFiDiagnosticsDelegate
152153
void OnDisconnectionDetected(uint16_t reasonCode) override
153154
{
154155
ChipLogProgress(Zcl, "WiFiDiagnosticsDelegate: OnDisconnectionDetected");
156+
157+
ForAllEndpointsWithServerCluster(
158+
WiFiNetworkDiagnostics::Id,
159+
[](EndpointId endpoint, intptr_t context) -> Loop {
160+
// If WiFi Network Diagnostics cluster is implemented on this endpoint
161+
Events::Disconnection::Type event{ static_cast<uint16_t>(context) };
162+
EventNumber eventNumber;
163+
164+
if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
165+
{
166+
ChipLogError(Zcl, "WiFiDiagnosticsDelegate: Failed to record Disconnection event");
167+
}
168+
169+
return Loop::Continue;
170+
},
171+
static_cast<intptr_t>(reasonCode));
155172
}
156173

157174
// Gets called when the Node fails to associate or authenticate an access point.
158175
void OnAssociationFailureDetected(uint8_t associationFailureCause, uint16_t status) override
159176
{
160177
ChipLogProgress(Zcl, "WiFiDiagnosticsDelegate: OnAssociationFailureDetected");
178+
179+
Events::AssociationFailure::Type event{ static_cast<AssociationFailureCause>(associationFailureCause), status };
180+
181+
ForAllEndpointsWithServerCluster(
182+
WiFiNetworkDiagnostics::Id,
183+
[](EndpointId endpoint, intptr_t context) -> Loop {
184+
// If WiFi Network Diagnostics cluster is implemented on this endpoint
185+
Events::AssociationFailure::Type * pEvent = reinterpret_cast<Events::AssociationFailure::Type *>(context);
186+
EventNumber eventNumber;
187+
188+
if (CHIP_NO_ERROR != LogEvent(*pEvent, endpoint, eventNumber))
189+
{
190+
ChipLogError(Zcl, "WiFiDiagnosticsDelegate: Failed to record AssociationFailure event");
191+
}
192+
193+
return Loop::Continue;
194+
},
195+
reinterpret_cast<intptr_t>(&event));
161196
}
162197

163198
// Gets when the Node’s connection status to a Wi-Fi network has changed.
164199
void OnConnectionStatusChanged(uint8_t connectionStatus) override
165200
{
166201
ChipLogProgress(Zcl, "WiFiDiagnosticsDelegate: OnConnectionStatusChanged");
202+
203+
ForAllEndpointsWithServerCluster(
204+
WiFiNetworkDiagnostics::Id,
205+
[](EndpointId endpoint, intptr_t context) -> Loop {
206+
// If WiFi Network Diagnostics cluster is implemented on this endpoint
207+
Events::ConnectionStatus::Type event{ static_cast<WiFiConnectionStatus>(context) };
208+
EventNumber eventNumber;
209+
210+
if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
211+
{
212+
ChipLogError(Zcl, "WiFiDiagnosticsDelegate: Failed to record ConnectionStatus event");
213+
}
214+
215+
return Loop::Continue;
216+
},
217+
static_cast<intptr_t>(connectionStatus));
167218
}
168219
};
169220

src/include/platform/GeneralFaults.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class GeneralFaults
5656
CHIP_ERROR add(const uint8_t value);
5757

5858
uint8_t * data() { return mData; }
59-
int size() const;
59+
size_t size() const;
6060
uint8_t operator[](int index) const;
6161

6262
Iterator begin() const;
@@ -85,9 +85,9 @@ inline CHIP_ERROR GeneralFaults<N>::add(const uint8_t value)
8585
}
8686

8787
template <size_t N>
88-
inline int GeneralFaults<N>::size() const
88+
inline size_t GeneralFaults<N>::size() const
8989
{
90-
return mSize;
90+
return static_cast<size_t>(mSize);
9191
}
9292

9393
template <size_t N>

0 commit comments

Comments
 (0)