From 2253060b8a3ed6b594ccfeb5b69e48796c28ead4 Mon Sep 17 00:00:00 2001 From: john30 Date: Wed, 31 Dec 2014 09:16:33 +0100 Subject: [PATCH] neither update last found timestamp nor empty last found value if decoding failed, added decode() for combined master/slave decoding --- src/lib/ebus/message.cpp | 27 ++++++++++++++++++++++++--- src/lib/ebus/message.h | 19 ++++++++++++++++++- src/lib/ebus/test/test_message.cpp | 4 +--- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index e3b3610b..31b8f7de 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -315,13 +315,12 @@ result_t Message::decode(const PartType partType, SymbolString& data, offset = m_id.size() - 2; else offset = 0; - int startPos = output.str().length(); + size_t startPos = output.str().length(); result_t result = m_data->read(partType, data, offset, output, leadingSeparator, verbose, filterName, separator); - time(&m_lastUpdateTime); if (result < RESULT_OK) { - m_lastValue.clear(); return result; } + time(&m_lastUpdateTime); m_lastValue = output.str().substr(startPos); /*if (m_isPassive == false && answer == true) { istringstream input; // TODO create input from database of internal variables @@ -332,6 +331,28 @@ result_t Message::decode(const PartType partType, SymbolString& data, return RESULT_OK; } +result_t Message::decode(SymbolString& masterData, SymbolString& slaveData, + ostringstream& output, bool leadingSeparator, + bool verbose, const char* filterName, + char separator) +{ + unsigned char offset = m_id.size() - 2; + size_t startPos = output.str().length(); + result_t result = m_data->read(pt_masterData, masterData, offset, output, leadingSeparator, verbose, filterName, separator); + if (result < RESULT_OK) { + return result; + } + offset = 0; + leadingSeparator = output.str().length() > startPos; + result = m_data->read(pt_slaveData, slaveData, offset, output, leadingSeparator, verbose, filterName, separator); + if (result < RESULT_OK) { + return result; + } + time(&m_lastUpdateTime); + m_lastValue = output.str().substr(startPos); + return RESULT_OK; +} + bool Message::isLessPollWeight(const Message* other) { unsigned int tw = m_pollPriority * m_pollCount; diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index d6831109..3ede74a1 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -176,7 +176,7 @@ public: result_t prepareSlave(SymbolString& slaveData); /** - * @brief Decode a received message. + * @brief Decode a singular part of a received message. * @param partType the @a PartType of the data. * @param data the unescaped data @a SymbolString for reading binary data. * @param output the @a ostringstream to append the formatted value to. @@ -192,6 +192,23 @@ public: bool verbose=false, const char* filterName=NULL, char separator=UI_FIELD_SEPARATOR); + /** + * @brief Decode all parts of a received message. + * @param masterData the unescaped master data @a SymbolString to decode. + * @param slaveData the unescaped slave data @a SymbolString to decode. + * @param output the @a ostringstream to append the formatted value to. + * @param leadingSeparator whether to prepend a separator before the formatted value. + * @param verbose whether to prepend the name, append the unit (if present), and append + * the comment in square brackets (if present). + * @param filterName the optional name of a field to limit the output to. + * @param separator the separator character between multiple fields. + * @return @a RESULT_OK on success, or an error code. + */ + result_t decode(SymbolString& masterData, SymbolString& slaveData, + ostringstream& output, bool leadingSeparator=false, + bool verbose=false, const char* filterName=NULL, + char separator=UI_FIELD_SEPARATOR); + /** * @brief Get the last decoded value. * @return the last decoded value, or the empty string if it was not successful. diff --git a/src/lib/ebus/test/test_message.cpp b/src/lib/ebus/test/test_message.cpp index 72f649ea..f74f4ead 100644 --- a/src/lib/ebus/test/test_message.cpp +++ b/src/lib/ebus/test/test_message.cpp @@ -151,9 +151,7 @@ int main() SymbolString writeMstr; if (message->isPassive() == true) { ostringstream output; - result = message->decode(pt_masterData, mstr, output); - if (result == RESULT_OK) - result = message->decode(pt_slaveData, sstr, output, output.str().empty() == false); + result = message->decode(mstr, sstr, output); if (result != RESULT_OK) { cout << " \"" << inputStr << "\": decode error: " << getResultCode(result) << endl;