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,62 @@ 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
+ MATTER_TRACE_SCOPE (" OnConnectionStatusChanged" , " ThreadDiagnosticsDelegate" );
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 (0 , 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, 0 , 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
+ MATTER_TRACE_SCOPE (" OnNetworkFaultChanged" , " ThreadDiagnosticsDelegate" );
167
+ ChipLogProgress (Zcl, " ThreadDiagnosticsDelegate: OnNetworkFaultChanged" );
168
+
169
+ /* Verify that the data size matches the expected one. */
170
+ static_assert (sizeof (*current.data ()) == sizeof (NetworkFaultEnum));
171
+
172
+ DataModel::List<const NetworkFaultEnum> currentList (reinterpret_cast <const NetworkFaultEnum *>(current.data ()),
173
+ current.size ());
174
+ DataModel::List<const NetworkFaultEnum> previousList (reinterpret_cast <const NetworkFaultEnum *>(previous.data ()),
175
+ previous.size ());
176
+
177
+ Events::NetworkFaultChange::Type event{ currentList, previousList };
178
+
179
+ // ThreadNetworkDiagnostics cluster should exist only for endpoint 0.
180
+ if (emberAfContainsServer (0 , ThreadNetworkDiagnostics::Id))
181
+ {
182
+ // If Thread Network Diagnostics cluster is implemented on this endpoint
183
+ EventNumber eventNumber;
184
+
185
+ if (CHIP_NO_ERROR != LogEvent (event, 0 , eventNumber))
186
+ {
187
+ ChipLogError (Zcl, " ThreadDiagnosticsDelegate: Failed to record NetworkFaultChange event" );
188
+ }
189
+ }
190
+ }
191
+ };
192
+
193
+ ThreadDiagnosticsDelegate gDiagnosticDelegate ;
194
+
135
195
} // anonymous namespace
136
196
137
197
bool emberAfThreadNetworkDiagnosticsClusterResetCountsCallback (app::CommandHandler * commandObj,
@@ -146,4 +206,5 @@ bool emberAfThreadNetworkDiagnosticsClusterResetCountsCallback(app::CommandHandl
146
206
void MatterThreadNetworkDiagnosticsPluginServerInitCallback ()
147
207
{
148
208
registerAttributeAccessOverride (&gAttrAccess );
209
+ GetDiagnosticDataProvider ().SetThreadDiagnosticsDelegate (&gDiagnosticDelegate );
149
210
}
0 commit comments