diff --git a/src/ebusd/baseloop.cpp b/src/ebusd/baseloop.cpp index b5291666..42bd1ce0 100644 --- a/src/ebusd/baseloop.cpp +++ b/src/ebusd/baseloop.cpp @@ -320,7 +320,7 @@ string BaseLoop::decodeMessage(const string& data) message = m_messages->find(cmd[1], cmd[2], false, true); if (message != NULL) { - token = m_busHandler->getReceivedData(message); + token = message->getLastValue(); if (token.empty() == false) { result << token; } else { diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index 87d6c2bc..4e245ae0 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -35,7 +35,8 @@ Message::Message(const string clazz, const string name, const bool isSet, : m_class(clazz), m_name(name), m_isSet(isSet), m_isPassive(isPassive), m_comment(comment), m_srcAddress(srcAddress), m_dstAddress(dstAddress), - m_id(id), m_data(data), m_pollPriority(pollPriority) + m_id(id), m_data(data), m_pollPriority(pollPriority), + m_lastUpdateTime(0) { int exp = 7; unsigned long long key = (unsigned long long)(id.size()-2) << (8 * exp + 5); @@ -280,9 +281,14 @@ result_t Message::decode(const PartType partType, SymbolString& data, offset = m_id.size() - 2; else offset = 0; + int startPos = output.str().length(); result_t result = m_data->read(partType, data, offset, output, leadingSeparator, false, separator); - if (result != RESULT_OK) + time(&m_lastUpdateTime); + if (result != RESULT_OK) { + m_lastValue.clear(); return result; + } + m_lastValue = output.str().substr(startPos); /*if (m_isPassive == false && answer == true) { istringstream input; // TODO create input from database of internal variables result_t result = m_data->write(input, masterData, m_id.size() - 2, slaveData, 0, separator); @@ -292,7 +298,6 @@ result_t Message::decode(const PartType partType, SymbolString& data, return RESULT_OK; } - result_t MessageMap::add(Message* message) { unsigned long long pkey = message->getKey(); @@ -422,4 +427,3 @@ void MessageMap::clear() m_passiveMessagesByKey.clear(); m_maxIdLength = 0; } - diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index 6e10b64a..a5bef802 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -144,6 +144,18 @@ public: result_t decode(const PartType partType, SymbolString& data, ostringstream& output, bool leadingSeparator=false, char separator=';'); + /** + * @brief Get the last decoded value. + * @return the last decoded value, or the empty string if it was not successful. + */ + string getLastValue() { return m_lastValue; } + + /** + * @brief Get the system time when @a m_lastValue was updated. + * @return the system time when @a m_lastValue was updated, or 0 if this message was not decoded yet. + */ + time_t getLastUpdateTime() { return m_lastUpdateTime; } + private: /** the optional device class. */ @@ -169,7 +181,10 @@ private: DataField* m_data; /** the priority for polling, or 0 for no polling at all. */ const unsigned char m_pollPriority; - + /** the last decoded value. */ + string m_lastValue; + /** the system time when @a m_lastValue was updated. */ + time_t m_lastUpdateTime; }; /** @@ -218,7 +233,6 @@ public: */ void clear(); - private: /** the minimum ID length used by any of the known @a Message instances. */