From d573fff746a1679542750c73eadcdd528b1cf22a Mon Sep 17 00:00:00 2001 From: john30 Date: Thu, 14 May 2015 09:50:28 +0200 Subject: [PATCH] added Symbol::compareMaster to avoid updating last message change time when only the querying master was modified --- src/lib/ebus/message.cpp | 23 +++++++++++++++++++---- src/lib/ebus/symbol.h | 15 +++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index ec311078..277be4c6 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -318,9 +318,14 @@ result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& ma result = m_data->write(input, pt_masterData, master, (unsigned char)(m_id.size() - 2), separator); if (result != RESULT_OK) return result; - if (master != m_lastMasterData) { + switch (master.compareMaster(m_lastMasterData)) { + case 1: // completely different m_lastChangeTime = m_lastUpdateTime; - m_lastMasterData = master; + m_lastMasterData = masterData; + break; + case 2: // only master address is different + m_lastMasterData = masterData; + break; } masterData.addAll(master); return result; @@ -366,9 +371,14 @@ result_t Message::decode(const PartType partType, SymbolString& data, time(&m_lastUpdateTime); if (partType == pt_masterData) { - if (data != m_lastMasterData) { + switch (data.compareMaster(m_lastMasterData)) { + case 1: // completely different m_lastChangeTime = m_lastUpdateTime; m_lastMasterData = data; + break; + case 2: // only master address is different + m_lastMasterData = data; + break; } } else if (partType == pt_slaveData) { if (data != m_lastSlaveData) { @@ -397,9 +407,14 @@ result_t Message::decode(SymbolString& masterData, SymbolString& slaveData, if (result == RESULT_EMPTY && !empty) result = RESULT_OK; // OK if at least one part was non-empty time(&m_lastUpdateTime); - if (masterData != m_lastMasterData) { + switch (masterData.compareMaster(m_lastMasterData)) { + case 1: // completely different m_lastChangeTime = m_lastUpdateTime; m_lastMasterData = masterData; + break; + case 2: // only master address is different + m_lastMasterData = masterData; + break; } if (slaveData != m_lastSlaveData) { m_lastChangeTime = m_lastUpdateTime; diff --git a/src/lib/ebus/symbol.h b/src/lib/ebus/symbol.h index 7914934d..be31b9e7 100644 --- a/src/lib/ebus/symbol.h +++ b/src/lib/ebus/symbol.h @@ -93,6 +93,21 @@ public: */ bool operator!=(SymbolString& other) { return m_unescapeState!=other.m_unescapeState || m_data!=other.m_data; } + /** + * Compares this instance to the other instance while treating both as master data (i.e. starting with the master address and ending with the CRC). + * @param other the other instance. + * @return 0 if this instance is equal to the other instance (i.e. both escaped or both unescaped and same symbols), + * 1 if this instance is completely different to the other instance, + * 2 if this instance only differs from the other instance in the first byte (the master address). + */ + int compareMaster(SymbolString& other) { + if (m_unescapeState!=other.m_unescapeState || m_data.size()!=other.m_data.size()) return 1; + if (m_data==other.m_data) return 0; + if (m_data.size()==1) return 2; + if (equal(m_data.begin()+1, m_data.end()-1, other.m_data.begin()+1)) return 2; + return 1; + } + /** * Appends a the symbol to the end of the symbol string and escapes/unescapes it if necessary. * @param value the symbol to append.