20
20
#include < app-common/zap-generated/ids/Attributes.h>
21
21
#include < app-common/zap-generated/ids/Clusters.h>
22
22
#include < app/AttributeAccessInterface.h>
23
+ #include < app/reporting/reporting.h>
23
24
#include < app/util/attribute-storage.h>
24
25
#include < platform/ConnectivityManager.h>
25
26
#include < platform/PlatformManager.h>
@@ -29,7 +30,7 @@ using namespace chip::app;
29
30
using namespace chip ::app::Clusters;
30
31
using namespace chip ::app::Clusters::GeneralDiagnostics::Attributes;
31
32
using chip::DeviceLayer::ConnectivityMgr;
32
- using chip::DeviceLayer::PlatformManager ;
33
+ using chip::DeviceLayer::PlatformMgr ;
33
34
34
35
namespace {
35
36
@@ -43,12 +44,12 @@ class GeneralDiagosticsAttrAccess : public AttributeAccessInterface
43
44
44
45
private:
45
46
template <typename T>
46
- CHIP_ERROR ReadIfSupported (CHIP_ERROR (PlatformManager::*getter)(T &), AttributeValueEncoder & aEncoder);
47
+ CHIP_ERROR ReadIfSupported (CHIP_ERROR (DeviceLayer:: PlatformManager::*getter)(T &), AttributeValueEncoder & aEncoder);
47
48
CHIP_ERROR ReadNetworkInterfaces (AttributeValueEncoder & aEncoder);
48
49
};
49
50
50
51
template <typename T>
51
- CHIP_ERROR GeneralDiagosticsAttrAccess::ReadIfSupported (CHIP_ERROR (PlatformManager::*getter)(T &),
52
+ CHIP_ERROR GeneralDiagosticsAttrAccess::ReadIfSupported (CHIP_ERROR (DeviceLayer:: PlatformManager::*getter)(T &),
52
53
AttributeValueEncoder & aEncoder)
53
54
{
54
55
T data;
@@ -107,26 +108,82 @@ CHIP_ERROR GeneralDiagosticsAttrAccess::Read(const ConcreteAttributePath & aPath
107
108
return ReadNetworkInterfaces (aEncoder);
108
109
}
109
110
case RebootCount::Id: {
110
- return ReadIfSupported (&PlatformManager::GetRebootCount, aEncoder);
111
+ return ReadIfSupported (&DeviceLayer:: PlatformManager::GetRebootCount, aEncoder);
111
112
}
112
113
case UpTime ::Id: {
113
- return ReadIfSupported (&PlatformManager::GetUpTime, aEncoder);
114
+ return ReadIfSupported (&DeviceLayer:: PlatformManager::GetUpTime, aEncoder);
114
115
}
115
116
case TotalOperationalHours::Id: {
116
- return ReadIfSupported (&PlatformManager::GetTotalOperationalHours, aEncoder);
117
+ return ReadIfSupported (&DeviceLayer:: PlatformManager::GetTotalOperationalHours, aEncoder);
117
118
}
118
119
case BootReasons::Id: {
119
- return ReadIfSupported (&PlatformManager::GetBootReasons, aEncoder);
120
+ return ReadIfSupported (&DeviceLayer:: PlatformManager::GetBootReasons, aEncoder);
120
121
}
121
122
default : {
122
123
break ;
123
124
}
124
125
}
125
126
return CHIP_NO_ERROR;
126
127
}
128
+
129
+ class GeneralDiagnosticDelegate : public DeviceLayer ::ConnectivityManagerDelegate, public DeviceLayer::PlatformManagerDelegate
130
+ {
131
+
132
+ // Gets called when any network interface on the Node is updated.
133
+ void OnNetworkInfoChanged () override
134
+ {
135
+ ChipLogProgress (Zcl, " GeneralDiagnosticDelegate: OnNetworkInfoChanged" );
136
+
137
+ for (uint16_t index = 0 ; index < emberAfEndpointCount (); index ++)
138
+ {
139
+ if (emberAfEndpointIndexIsEnabled (index ))
140
+ {
141
+ EndpointId endpointId = emberAfEndpointFromIndex (index );
142
+ if (endpointId == 0 )
143
+ continue ;
144
+
145
+ if (emberAfContainsServer (endpointId, GeneralDiagnostics::Id))
146
+ {
147
+ // If General Diagnostics cluster is implemented on this endpoint
148
+ MatterReportingAttributeChangeCallback (endpointId, GeneralDiagnostics::Id,
149
+ GeneralDiagnostics::Attributes::NetworkInterfaces::Id);
150
+ }
151
+ }
152
+ }
153
+ }
154
+
155
+ // Gets called when the device has been rebooted.
156
+ void OnDeviceRebooted () override
157
+ {
158
+ ChipLogProgress (Zcl, " GeneralDiagnosticDelegate: OnDeviceRebooted" );
159
+
160
+ for (uint16_t index = 0 ; index < emberAfEndpointCount (); index ++)
161
+ {
162
+ if (emberAfEndpointIndexIsEnabled (index ))
163
+ {
164
+ EndpointId endpointId = emberAfEndpointFromIndex (index );
165
+
166
+ if (emberAfContainsServer (endpointId, GeneralDiagnostics::Id))
167
+ {
168
+ // If General Diagnostics cluster is implemented on this endpoint
169
+ MatterReportingAttributeChangeCallback (endpointId, GeneralDiagnostics::Id,
170
+ GeneralDiagnostics::Attributes::RebootCount::Id);
171
+ MatterReportingAttributeChangeCallback (endpointId, GeneralDiagnostics::Id,
172
+ GeneralDiagnostics::Attributes::BootReasons::Id);
173
+ }
174
+ }
175
+ }
176
+ }
177
+ };
178
+
179
+ GeneralDiagnosticDelegate gDiagnosticDelegate ;
180
+
127
181
} // anonymous namespace
128
182
129
183
void MatterGeneralDiagnosticsPluginServerInitCallback ()
130
184
{
131
185
registerAttributeAccessOverride (&gAttrAccess );
186
+
187
+ PlatformMgr ().SetDelegate (&gDiagnosticDelegate );
188
+ ConnectivityMgr ().SetDelegate (&gDiagnosticDelegate );
132
189
}
0 commit comments