22
22
#include < app/AttributeAccessInterface.h>
23
23
#include < app/CommandHandler.h>
24
24
#include < app/ConcreteCommandPath.h>
25
+ #include < app/EventLogging.h>
25
26
#include < app/clusters/thread-network-diagnostics-server/thread-network-diagnostics-provider.h>
26
27
#include < app/util/attribute-storage.h>
27
28
#include < lib/core/CHIPEncoding.h>
28
29
#include < lib/core/Optional.h>
29
30
#include < lib/core/TLVTypes.h>
30
31
#include < lib/support/CHIPPlatformMemory.h>
31
32
#include < platform/CHIPDeviceLayer.h>
33
+ #include < platform/DiagnosticDataProvider.h>
34
+ #include < tracing/macros.h>
35
+ #include < tracing/metric_event.h>
32
36
33
37
using namespace chip ;
34
38
using namespace chip ::app;
@@ -132,6 +136,60 @@ CHIP_ERROR ThreadDiagosticsAttrAccess::Read(const ConcreteReadAttributePath & aP
132
136
return CHIP_NO_ERROR;
133
137
}
134
138
139
+ class ThreadDiagnosticsDelegate : public DeviceLayer ::ThreadDiagnosticsDelegate
140
+ {
141
+ // Notified when the Node’s connection status to a Thread network has changed.
142
+ void OnConnectionStatusChanged (ConnectionStatusEnum newConnectionStatus) override
143
+ {
144
+ ChipLogProgress (Zcl, " ThreadDiagnosticsDelegate: OnConnectionStatusChanged" );
145
+
146
+ Events::ConnectionStatus::Type event{ newConnectionStatus };
147
+
148
+ // ThreadNetworkDiagnostics cluster should exist only for endpoint 0.
149
+ if (emberAfContainsServer (0 , ThreadNetworkDiagnostics::Id))
150
+ {
151
+ // If Thread Network Diagnostics cluster is implemented on this endpoint
152
+ EventNumber eventNumber;
153
+
154
+ if (CHIP_NO_ERROR != LogEvent (event, 0 , eventNumber))
155
+ {
156
+ ChipLogError (Zcl, " ThreadDiagnosticsDelegate: Failed to record ConnectionStatus event" );
157
+ }
158
+ }
159
+ }
160
+
161
+ // Notified when the Node’s faults related to a Thread network have changed.
162
+ void OnNetworkFaultChanged (const GeneralFaults<kMaxNetworkFaults > & previous,
163
+ const GeneralFaults<kMaxNetworkFaults > & current) override
164
+ {
165
+ ChipLogProgress (Zcl, " ThreadDiagnosticsDelegate: OnNetworkFaultChanged" );
166
+
167
+ /* Verify that the data size matches the expected one. */
168
+ static_assert (sizeof (*current.data ()) == sizeof (NetworkFaultEnum));
169
+
170
+ DataModel::List<const NetworkFaultEnum> currentList (reinterpret_cast <const NetworkFaultEnum *>(current.data ()),
171
+ current.size ());
172
+ DataModel::List<const NetworkFaultEnum> previousList (reinterpret_cast <const NetworkFaultEnum *>(previous.data ()),
173
+ previous.size ());
174
+
175
+ Events::NetworkFaultChange::Type event{ currentList, previousList };
176
+
177
+ // ThreadNetworkDiagnostics cluster should exist only for endpoint 0.
178
+ if (emberAfContainsServer (0 , ThreadNetworkDiagnostics::Id))
179
+ {
180
+ // If Thread Network Diagnostics cluster is implemented on this endpoint
181
+ EventNumber eventNumber;
182
+
183
+ if (CHIP_NO_ERROR != LogEvent (event, 0 , eventNumber))
184
+ {
185
+ ChipLogError (Zcl, " ThreadDiagnosticsDelegate: Failed to record NetworkFaultChange event" );
186
+ }
187
+ }
188
+ }
189
+ };
190
+
191
+ ThreadDiagnosticsDelegate gDiagnosticDelegate ;
192
+
135
193
} // anonymous namespace
136
194
137
195
bool emberAfThreadNetworkDiagnosticsClusterResetCountsCallback (app::CommandHandler * commandObj,
@@ -146,4 +204,5 @@ bool emberAfThreadNetworkDiagnosticsClusterResetCountsCallback(app::CommandHandl
146
204
void MatterThreadNetworkDiagnosticsPluginServerInitCallback ()
147
205
{
148
206
registerAttributeAccessOverride (&gAttrAccess );
207
+ GetDiagnosticDataProvider ().SetThreadDiagnosticsDelegate (&gDiagnosticDelegate );
149
208
}
0 commit comments