Skip to content

Commit 8c4911d

Browse files
authored
Merge pull request #22 from erwinpan1/add-type
Add support for single float type in RPC.
2 parents 60128dc + cc706cf commit 8c4911d

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

examples/chef/common/chef-concentration-measurement.cpp

+2-11
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,8 @@ Protocols::InteractionModel::Status chefConcentrationMeasurementWriteCallback(
7676

7777
if (attributeId == measuredValueId)
7878
{
79-
float newValue = 0;
80-
uint16_t tlvLen = *(uint16_t *) buffer;
81-
chip::TLV::TLVReader reader;
82-
reader.Init(buffer + sizeof(uint16_t), tlvLen);
83-
reader.Next();
84-
reader.Get(newValue);
85-
86-
ChipLogDetail(DeviceLayer, "TLV Type %d, Length %d \n", static_cast<int>(reader.GetType()), tlvLen);
87-
// 2 bytes buf length + 5 bytes TLV for float
88-
ChipLogDetail(DeviceLayer, "buffer: %02x%02x%02x%02x%02x%02x%02x \n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4],
89-
buffer[5], buffer[6]);
79+
float newValue;
80+
std::memcpy(&newValue, buffer, sizeof(float)); // Copy buffer content to float
9081

9182
CHIP_ERROR err = clusterInstance->SetMeasuredValue(MakeNullable(newValue));
9283
if (CHIP_NO_ERROR == err)

examples/common/pigweed/protos/attributes_service.proto

+1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ message AttributeData {
228228
int32 data_int8 = 6;
229229
int32 data_int16 = 7;
230230
int32 data_int32 = 8;
231+
float data_single = 10;
231232
};
232233
optional bytes tlv_data = 9;
233234
}

examples/common/pigweed/rpc_services/Attributes.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class Attributes : public pw_rpc::nanopb::Attributes::Service<Attributes>
7070
case chip_rpc_AttributeData_data_bytes_tag:
7171
data = &request.data.data.data_bytes;
7272
break;
73+
case chip_rpc_AttributeData_data_single_tag:
74+
data = &request.data.data.data_single;
75+
break;
7376
default:
7477
return pw::Status::InvalidArgument();
7578
}
@@ -125,6 +128,10 @@ class Attributes : public pw_rpc::nanopb::Attributes::Service<Attributes>
125128
PW_TRY(TlvBufferGetData(tlvBuffer, TLV::kTLVType_SignedInteger, response.data.data_int32));
126129
response.which_data = chip_rpc_AttributeData_data_int32_tag;
127130
break;
131+
case chip_rpc_AttributeType_ZCL_SINGLE_ATTRIBUTE_TYPE:
132+
PW_TRY(TlvBufferGetData(tlvBuffer, TLV::kTLVType_FloatingPointNumber, response.data.data_single));
133+
response.which_data = chip_rpc_AttributeData_data_single_tag;
134+
break;
128135
case chip_rpc_AttributeType_ZCL_BITMAP8_ATTRIBUTE_TYPE:
129136
case chip_rpc_AttributeType_ZCL_BITMAP16_ATTRIBUTE_TYPE:
130137
case chip_rpc_AttributeType_ZCL_BITMAP32_ATTRIBUTE_TYPE:
@@ -140,7 +147,6 @@ class Attributes : public pw_rpc::nanopb::Attributes::Service<Attributes>
140147
case chip_rpc_AttributeType_ZCL_INT48S_ATTRIBUTE_TYPE:
141148
case chip_rpc_AttributeType_ZCL_INT56S_ATTRIBUTE_TYPE:
142149
case chip_rpc_AttributeType_ZCL_INT64S_ATTRIBUTE_TYPE:
143-
case chip_rpc_AttributeType_ZCL_SINGLE_ATTRIBUTE_TYPE:
144150
case chip_rpc_AttributeType_ZCL_DOUBLE_ATTRIBUTE_TYPE:
145151
case chip_rpc_AttributeType_ZCL_OCTET_STRING_ATTRIBUTE_TYPE:
146152
case chip_rpc_AttributeType_ZCL_CHAR_STRING_ATTRIBUTE_TYPE:

0 commit comments

Comments
 (0)