Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for single float type in RPC. #35932

Merged
merged 4 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -219,6 +219,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 @@ -78,6 +78,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 @@ -133,6 +136,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 @@ -148,7 +155,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
Loading