|
20 | 20 | #include <app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h>
|
21 | 21 | #include <app/clusters/resource-monitoring-server/resource-monitoring-server.h>
|
22 | 22 | #include <lib/core/TLVReader.h>
|
| 23 | +#include <lib/support/BufferReader.h> |
| 24 | +#include <lib/support/BufferWriter.h> |
23 | 25 | #include <resource-monitoring/chef-resource-monitoring-delegates.h>
|
24 | 26 | #include <utility>
|
25 | 27 |
|
@@ -123,12 +125,17 @@ ChefResourceMonitorInstance::ExternalAttributeWrite(const EmberAfAttributeMetada
|
123 | 125 | }
|
124 | 126 | break;
|
125 | 127 | case HepaFilterMonitoring::Attributes::LastChangedTime::Id: {
|
| 128 | + // We already know the input is a buffer started with a uint16_t as the length |
| 129 | + chip::Encoding::LittleEndian::Reader bufReader(buffer, sizeof(uint16_t)); |
| 130 | + uint16_t tlvLen; |
| 131 | + VerifyOrReturnError( CHIP_NO_ERROR == bufReader.Read16(&tlvLen).StatusCode(), Protocols::InteractionModel::Status::UnsupportedWrite); |
| 132 | + |
| 133 | + // Read from TLV |
126 | 134 | uint32_t newValue = 0;
|
127 |
| - uint16_t tlvLen = *(uint16_t *) buffer; |
128 |
| - chip::TLV::TLVReader reader; |
129 |
| - reader.Init(buffer + sizeof(uint16_t), tlvLen); |
130 |
| - reader.Next(); |
131 |
| - reader.Get(newValue); |
| 135 | + chip::TLV::TLVReader tlvReader; |
| 136 | + tlvReader.Init(buffer + sizeof(uint16_t), tlvLen); |
| 137 | + tlvReader.Next(); |
| 138 | + tlvReader.Get(newValue); |
132 | 139 | DataModel::Nullable<uint32_t> newLastChangedTime = DataModel::MakeNullable(newValue);
|
133 | 140 | ret = UpdateLastChangedTime(newLastChangedTime);
|
134 | 141 | }
|
@@ -163,7 +170,7 @@ chefResourceMonitoringExternalWriteCallback(chip::EndpointId endpoint, chip::Clu
|
163 | 170 | {
|
164 | 171 | Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success;
|
165 | 172 | AttributeId attributeId = attributeMetadata->attributeId;
|
166 |
| - ChipLogProgress(Zcl, "chefResourceMonitoringExternalWriteCallback EP: %d, Cluster: %d, Att: %d", static_cast<int>(endpoint), |
| 173 | + ChipLogProgress(Zcl, "chefResourceMonitoringExternalWriteCallback EP: %d, Cluster: %04x, Att: %04x", static_cast<int>(endpoint), |
167 | 174 | static_cast<int>(clusterId), static_cast<int>(attributeId));
|
168 | 175 |
|
169 | 176 | switch (clusterId)
|
@@ -232,8 +239,11 @@ ChefResourceMonitorInstance::ExternalAttributeRead(const EmberAfAttributeMetadat
|
232 | 239 | }
|
233 | 240 | break;
|
234 | 241 | case HepaFilterMonitoring::Attributes::LastChangedTime::Id: {
|
| 242 | + // Only LastChangedTime needs to handle Endianness |
235 | 243 | DataModel::Nullable<uint32_t> lastChangedTime = GetLastChangedTime();
|
236 |
| - *(uint32_t *) buffer = lastChangedTime.IsNull() ? 0 : lastChangedTime.Value(); |
| 244 | + chip::Encoding::LittleEndian::BufferWriter bufWriter(buffer, sizeof(uint16_t)); |
| 245 | + |
| 246 | + bufWriter.Put32(lastChangedTime.IsNull() ? 0 : lastChangedTime.Value()); |
237 | 247 | }
|
238 | 248 | break;
|
239 | 249 | case HepaFilterMonitoring::Attributes::DegradationDirection::Id:
|
|
0 commit comments