added Symbol::compareMaster to avoid updating last message change time when only the querying master was modified
This commit is contained in:
@@ -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);
|
result = m_data->write(input, pt_masterData, master, (unsigned char)(m_id.size() - 2), separator);
|
||||||
if (result != RESULT_OK)
|
if (result != RESULT_OK)
|
||||||
return result;
|
return result;
|
||||||
if (master != m_lastMasterData) {
|
switch (master.compareMaster(m_lastMasterData)) {
|
||||||
|
case 1: // completely different
|
||||||
m_lastChangeTime = m_lastUpdateTime;
|
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);
|
masterData.addAll(master);
|
||||||
return result;
|
return result;
|
||||||
@@ -366,9 +371,14 @@ result_t Message::decode(const PartType partType, SymbolString& data,
|
|||||||
|
|
||||||
time(&m_lastUpdateTime);
|
time(&m_lastUpdateTime);
|
||||||
if (partType == pt_masterData) {
|
if (partType == pt_masterData) {
|
||||||
if (data != m_lastMasterData) {
|
switch (data.compareMaster(m_lastMasterData)) {
|
||||||
|
case 1: // completely different
|
||||||
m_lastChangeTime = m_lastUpdateTime;
|
m_lastChangeTime = m_lastUpdateTime;
|
||||||
m_lastMasterData = data;
|
m_lastMasterData = data;
|
||||||
|
break;
|
||||||
|
case 2: // only master address is different
|
||||||
|
m_lastMasterData = data;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else if (partType == pt_slaveData) {
|
} else if (partType == pt_slaveData) {
|
||||||
if (data != m_lastSlaveData) {
|
if (data != m_lastSlaveData) {
|
||||||
@@ -397,9 +407,14 @@ result_t Message::decode(SymbolString& masterData, SymbolString& slaveData,
|
|||||||
if (result == RESULT_EMPTY && !empty)
|
if (result == RESULT_EMPTY && !empty)
|
||||||
result = RESULT_OK; // OK if at least one part was non-empty
|
result = RESULT_OK; // OK if at least one part was non-empty
|
||||||
time(&m_lastUpdateTime);
|
time(&m_lastUpdateTime);
|
||||||
if (masterData != m_lastMasterData) {
|
switch (masterData.compareMaster(m_lastMasterData)) {
|
||||||
|
case 1: // completely different
|
||||||
m_lastChangeTime = m_lastUpdateTime;
|
m_lastChangeTime = m_lastUpdateTime;
|
||||||
m_lastMasterData = masterData;
|
m_lastMasterData = masterData;
|
||||||
|
break;
|
||||||
|
case 2: // only master address is different
|
||||||
|
m_lastMasterData = masterData;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (slaveData != m_lastSlaveData) {
|
if (slaveData != m_lastSlaveData) {
|
||||||
m_lastChangeTime = m_lastUpdateTime;
|
m_lastChangeTime = m_lastUpdateTime;
|
||||||
|
|||||||
@@ -93,6 +93,21 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool operator!=(SymbolString& other) { return m_unescapeState!=other.m_unescapeState || m_data!=other.m_data; }
|
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.
|
* Appends a the symbol to the end of the symbol string and escapes/unescapes it if necessary.
|
||||||
* @param value the symbol to append.
|
* @param value the symbol to append.
|
||||||
|
|||||||
Reference in New Issue
Block a user