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