From f26e1d0835c9112c32b972e14c037594dd183d2a Mon Sep 17 00:00:00 2001 From: john30 Date: Thu, 10 Dec 2015 08:21:09 +0100 Subject: [PATCH] skip everything after and including dot when parsing int values --- src/lib/ebus/data.cpp | 6 +++--- src/lib/ebus/test/test_data.cpp | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/ebus/data.cpp b/src/lib/ebus/data.cpp index a9829e53..39d2446f 100644 --- a/src/lib/ebus/data.cpp +++ b/src/lib/ebus/data.cpp @@ -1115,7 +1115,7 @@ result_t NumberDataField::writeSymbols(istringstream& input, return RESULT_ERR_EOF; // input too short else { char* strEnd = NULL; - if (m_divisor >= 0 && m_divisor <= 1) { + if (m_divisor == 1) { if ((m_dataType.flags & SIG) != 0) { long int signedValue = strtol(str, &strEnd, 10); if (signedValue < 0 && m_bitCount != 32) @@ -1125,7 +1125,7 @@ result_t NumberDataField::writeSymbols(istringstream& input, } else value = (unsigned int)strtoul(str, &strEnd, 10); - if (strEnd == NULL || strEnd == str || *strEnd != 0) + if (strEnd == NULL || strEnd == str || (*strEnd != 0 && *strEnd != '.')) return RESULT_ERR_INVALID_NUM; // invalid value } else { char* strEnd = NULL; @@ -1261,7 +1261,7 @@ result_t ValueListDataField::writeSymbols(istringstream& input, char* strEnd = NULL; // fall back to raw value in input unsigned int value; value = (unsigned int)strtoul(str, &strEnd, 10); - if (strEnd == NULL || strEnd == str || *strEnd != 0) + if (strEnd == NULL || strEnd == str || (*strEnd != 0 && *strEnd != '.')) return RESULT_ERR_INVALID_NUM; // invalid value if (m_values.find(value) != m_values.end()) return writeRawValue(value, baseOffset, output); diff --git a/src/lib/ebus/test/test_data.cpp b/src/lib/ebus/test/test_data.cpp index 9b516fb5..262458ff 100644 --- a/src/lib/ebus/test/test_data.cpp +++ b/src/lib/ebus/test/test_data.cpp @@ -153,6 +153,7 @@ int main() {"x,s,uch", "0", "1025ffff00", "0100", ""}, {"x,s,uch,,,,y,m,uch", "3;2","1025ffff0103", "0102", ""}, {"x,,uch", "38", "10feffff0126", "00", ""}, + {"x,,uch", "38.5", "10feffff0126", "00", "R"}, {"x,,uch", "0", "10feffff0100", "00", ""}, {"x,,uch", "254", "10feffff01fe", "00", ""}, {"x,,uch", "-", "10feffff01ff", "00", ""}, @@ -235,6 +236,7 @@ int main() {"x,,bi3:2,1=on","on", "10feffff0108", "00", ""}, {"x,,bi3:2,1=on","-", "10feffff0100", "00", ""}, {"x,,bi3:2,0=off;1=on;2=auto;3=eco","auto", "10feffff0110", "00", ""}, + {"x,,bi3:2,0=off;1=on;2=auto;3=eco","2.5", "10feffff0110", "00", "R"}, {"x,,bi3:2,0=off;1=on","on", "10feffff0108", "00", ""}, {"x,,bi3:2,0=off;1=on","off","10feffff0100", "00", ""}, {"x,,bi3:2,0=off;1=on","1", "10feffff0108", "00", "n"},