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,55 @@ 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
+ // Gets when the Node’s connection status to a Thread network has changed.
142
+ void OnConnectionStatusChanged (uint8_t connectionStatus) override
143
+ {
144
+ MATTER_TRACE_SCOPE (" OnConnectionStatusChanged" , " ThreadDiagnosticsDelegate" );
145
+ ChipLogProgress (Zcl, " ThreadDiagnosticsDelegate: OnConnectionStatusChanged" );
146
+
147
+ Events::ConnectionStatus::Type event{ static_cast <ConnectionStatusEnum>(connectionStatus) };
148
+ for (auto endpoint : EnabledEndpointsWithServerCluster (ThreadNetworkDiagnostics::Id))
149
+ {
150
+ // If Thread Network Diagnostics cluster is implemented on this endpoint
151
+ EventNumber eventNumber;
152
+
153
+ if (CHIP_NO_ERROR != LogEvent (event, endpoint, eventNumber))
154
+ {
155
+ ChipLogError (Zcl, " ThreadDiagnosticsDelegate: Failed to record ConnectionStatus event" );
156
+ }
157
+ }
158
+ }
159
+
160
+ // Gets when the Node’s default in a Thread network has occurred.
161
+ void OnNetworkFaultChanged (const GeneralFaults<kMaxNetworkFaults > & previous,
162
+ const GeneralFaults<kMaxNetworkFaults > & current) override
163
+ {
164
+ MATTER_TRACE_SCOPE (" OnNetworkFaultChanged" , " ThreadDiagnosticsDelegate" );
165
+ ChipLogProgress (Zcl, " ThreadDiagnosticsDelegate: OnNetworkFaultChanged" );
166
+
167
+ DataModel::List<const NetworkFaultEnum> currentList (reinterpret_cast <const NetworkFaultEnum *>(current.data ()),
168
+ current.size ());
169
+ DataModel::List<const NetworkFaultEnum> previousList (reinterpret_cast <const NetworkFaultEnum *>(previous.data ()),
170
+ previous.size ());
171
+
172
+ Events::NetworkFaultChange::Type event{ currentList, previousList };
173
+ for (auto endpoint : EnabledEndpointsWithServerCluster (ThreadNetworkDiagnostics::Id))
174
+ {
175
+ // If Thread Network Diagnostics cluster is implemented on this endpoint
176
+ EventNumber eventNumber;
177
+
178
+ if (CHIP_NO_ERROR != LogEvent (event, endpoint, eventNumber))
179
+ {
180
+ ChipLogError (Zcl, " ThreadDiagnosticsDelegate: Failed to record NetworkFaultChange event" );
181
+ }
182
+ }
183
+ }
184
+ };
185
+
186
+ ThreadDiagnosticsDelegate gDiagnosticDelegate ;
187
+
135
188
} // anonymous namespace
136
189
137
190
bool emberAfThreadNetworkDiagnosticsClusterResetCountsCallback (app::CommandHandler * commandObj,
@@ -146,4 +199,5 @@ bool emberAfThreadNetworkDiagnosticsClusterResetCountsCallback(app::CommandHandl
146
199
void MatterThreadNetworkDiagnosticsPluginServerInitCallback ()
147
200
{
148
201
registerAttributeAccessOverride (&gAttrAccess );
202
+ GetDiagnosticDataProvider ().SetThreadDiagnosticsDelegate (&gDiagnosticDelegate );
149
203
}
0 commit comments