From ac7654e14d7169e2b9f51ee6fcc82d924ff9ac10 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 1 May 2022 08:37:08 +0200 Subject: [PATCH] prefer known bitcount instead of passed in length --- src/lib/ebus/datatype.cpp | 13 ++++--------- src/lib/ebus/datatype.h | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/lib/ebus/datatype.cpp b/src/lib/ebus/datatype.cpp index 34ff5b04..b68abb33 100755 --- a/src/lib/ebus/datatype.cpp +++ b/src/lib/ebus/datatype.cpp @@ -731,13 +731,7 @@ result_t NumberDataType::derive(int divisor, size_t bitCount, const NumberDataTy } result_t NumberDataType::getMinMax(bool getMax, const OutputFormat outputFormat, ostream* output) const { - size_t length; - if (m_bitCount < 8) { - length = 1; - } else { - length = m_bitCount/8; - } - return readFromRawValue(length, getMax ? m_maxValue : m_minValue, outputFormat, output); + return readFromRawValue(getMax ? m_maxValue : m_minValue, outputFormat, output); } result_t NumberDataType::readRawValue(size_t offset, size_t length, const SymbolString& input, @@ -796,11 +790,12 @@ result_t NumberDataType::readSymbols(size_t offset, size_t length, const SymbolS if (result != RESULT_OK) { return result; } - return readFromRawValue(length, value, outputFormat, output); + return readFromRawValue(value, outputFormat, output); } -result_t NumberDataType::readFromRawValue(size_t length, unsigned int value, +result_t NumberDataType::readFromRawValue(unsigned int value, OutputFormat outputFormat, ostream* output) const { + size_t length = (m_bitCount < 8) ? 1 : (m_bitCount/8); int signedValue; // initialize output *output << setw(0) << std::resetiosflags(output->flags()) << dec << std::skipws << setprecision(6); diff --git a/src/lib/ebus/datatype.h b/src/lib/ebus/datatype.h index 188034c1..65de328c 100755 --- a/src/lib/ebus/datatype.h +++ b/src/lib/ebus/datatype.h @@ -546,7 +546,7 @@ class NumberDataType : public DataType { * @param output the ostream to append the formatted value to. * @return @a RESULT_OK on success, or an error code. */ - result_t readFromRawValue(size_t length, unsigned int value, + result_t readFromRawValue(unsigned int value, OutputFormat outputFormat, ostream* output) const; /**