Skip to content

Commit

Permalink
Add support for single float type in RPC.
Browse files Browse the repository at this point in the history
  • Loading branch information
GinyWang committed Sep 30, 2024
1 parent 60128dc commit cc706cf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
13 changes: 2 additions & 11 deletions examples/chef/common/chef-concentration-measurement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,8 @@ Protocols::InteractionModel::Status chefConcentrationMeasurementWriteCallback(

if (attributeId == measuredValueId)
{
float newValue = 0;
uint16_t tlvLen = *(uint16_t *) buffer;
chip::TLV::TLVReader reader;
reader.Init(buffer + sizeof(uint16_t), tlvLen);
reader.Next();
reader.Get(newValue);

ChipLogDetail(DeviceLayer, "TLV Type %d, Length %d \n", static_cast<int>(reader.GetType()), tlvLen);
// 2 bytes buf length + 5 bytes TLV for float
ChipLogDetail(DeviceLayer, "buffer: %02x%02x%02x%02x%02x%02x%02x \n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4],
buffer[5], buffer[6]);
float newValue;
std::memcpy(&newValue, buffer, sizeof(float)); // Copy buffer content to float

CHIP_ERROR err = clusterInstance->SetMeasuredValue(MakeNullable(newValue));
if (CHIP_NO_ERROR == err)
Expand Down
1 change: 1 addition & 0 deletions examples/common/pigweed/protos/attributes_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ message AttributeData {
int32 data_int8 = 6;
int32 data_int16 = 7;
int32 data_int32 = 8;
float data_single = 10;
};
optional bytes tlv_data = 9;
}
Expand Down
8 changes: 7 additions & 1 deletion examples/common/pigweed/rpc_services/Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class Attributes : public pw_rpc::nanopb::Attributes::Service<Attributes>
case chip_rpc_AttributeData_data_bytes_tag:
data = &request.data.data.data_bytes;
break;
case chip_rpc_AttributeData_data_single_tag:
data = &request.data.data.data_single;
break;
default:
return pw::Status::InvalidArgument();
}
Expand Down Expand Up @@ -125,6 +128,10 @@ class Attributes : public pw_rpc::nanopb::Attributes::Service<Attributes>
PW_TRY(TlvBufferGetData(tlvBuffer, TLV::kTLVType_SignedInteger, response.data.data_int32));
response.which_data = chip_rpc_AttributeData_data_int32_tag;
break;
case chip_rpc_AttributeType_ZCL_SINGLE_ATTRIBUTE_TYPE:
PW_TRY(TlvBufferGetData(tlvBuffer, TLV::kTLVType_FloatingPointNumber, response.data.data_single));
response.which_data = chip_rpc_AttributeData_data_single_tag;
break;
case chip_rpc_AttributeType_ZCL_BITMAP8_ATTRIBUTE_TYPE:
case chip_rpc_AttributeType_ZCL_BITMAP16_ATTRIBUTE_TYPE:
case chip_rpc_AttributeType_ZCL_BITMAP32_ATTRIBUTE_TYPE:
Expand All @@ -140,7 +147,6 @@ class Attributes : public pw_rpc::nanopb::Attributes::Service<Attributes>
case chip_rpc_AttributeType_ZCL_INT48S_ATTRIBUTE_TYPE:
case chip_rpc_AttributeType_ZCL_INT56S_ATTRIBUTE_TYPE:
case chip_rpc_AttributeType_ZCL_INT64S_ATTRIBUTE_TYPE:
case chip_rpc_AttributeType_ZCL_SINGLE_ATTRIBUTE_TYPE:
case chip_rpc_AttributeType_ZCL_DOUBLE_ATTRIBUTE_TYPE:
case chip_rpc_AttributeType_ZCL_OCTET_STRING_ATTRIBUTE_TYPE:
case chip_rpc_AttributeType_ZCL_CHAR_STRING_ATTRIBUTE_TYPE:
Expand Down

0 comments on commit cc706cf

Please sign in to comment.