Merge branch 'modbus_string' into integration

This commit is contained in:
J. Nick Koston
2026-01-14 16:29:32 -10:00
2 changed files with 2 additions and 2 deletions

View File

@@ -286,7 +286,7 @@ class ServerRegister {
return std::to_string(value);
case SensorValueType::FP32_R:
case SensorValueType::FP32: {
// max 48: float with %.1f can be up to 41 chars (3.4e38 → 39 digits + sign + decimal + 1 digit) + null
// max 48: float with %.1f can be up to 42 chars incl. null (3.4e38 → 38 integer digits + decimal point + 1 decimal digit + optional sign)
char buf[48];
snprintf(buf, sizeof(buf), "%.1f", bit_cast<float>(static_cast<uint32_t>(value)));
return buf;

View File

@@ -24,7 +24,7 @@ void ModbusTextSensor::parse_and_publish(const std::vector<uint8_t> &data) {
break;
}
case RawEncoding::COMMA: {
// max 5: ","(1) + uint8(3) + null
// max 5: optional ','(1) + uint8(3) + null, for both ",%d" and "%d"
char dec_buf[5];
snprintf(dec_buf, sizeof(dec_buf), index != this->offset ? ",%d" : "%d", b);
output_str += dec_buf;