diff --git a/src/ebusd/main.cpp b/src/ebusd/main.cpp index 5b24a0fe..de478d47 100644 --- a/src/ebusd/main.cpp +++ b/src/ebusd/main.cpp @@ -408,7 +408,10 @@ int main(int argc, char* argv[], char* envp[]) { fout.close(); } } - + if (overallResult == RESULT_OK && s_messageMap->getMaxIdLength() > 7) { + logNotice(lf_main, "max message ID length exceeded"); + overallResult = RESULT_CONTINUE; + } cleanup(); return overallResult == RESULT_OK ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index 5d281226..956a70bb 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -180,7 +180,7 @@ uint64_t Message::createKey(const vector& id, bool isWrite, bool isPas int exp = 5; for (const auto it : id) { key ^= (uint64_t)it << (8 * exp--); - if (exp == 0) { + if (exp < 0) { exp = 3; } } @@ -206,7 +206,7 @@ uint64_t Message::createKey(const MasterSymbolString& master, size_t maxIdLength int exp = 3; for (size_t i = 0; i < idLength; i++) { key ^= (uint64_t)master.dataAt(i) << (8 * exp--); - if (exp == 0) { + if (exp < 0) { exp = 3; } } @@ -2712,13 +2712,12 @@ Message* MessageMap::find(const MasterSymbolString& master, bool anyDestination, if (anyDestination && master.size() >= 5 && master[4] == 0 && master[2] == 0x07 && master[3] == 0x04) { return m_scanMessage; } - uint64_t baseKey = Message::createKey(master, - anyDestination || master[1] != BROADCAST ? m_maxIdLength : m_maxBroadcastIdLength, anyDestination); + size_t maxIdLength = anyDestination || master[1] != BROADCAST ? m_maxIdLength : m_maxBroadcastIdLength; + uint64_t baseKey = Message::createKey(master, maxIdLength, anyDestination); if (baseKey == INVALID_KEY) { return nullptr; } bool isWriteDest = isMaster(master[1]) || master[1] == BROADCAST; - size_t maxIdLength = Message::getKeyLength(baseKey); for (size_t idLength = maxIdLength; true; idLength--) { uint64_t key = baseKey; if (idLength == maxIdLength) { @@ -2728,7 +2727,7 @@ Message* MessageMap::find(const MasterSymbolString& master, bool anyDestination, int exp = 3; for (size_t i = 0; i < idLength; i++) { key ^= (uint64_t)master.dataAt(i) << (8 * exp--); - if (exp == 0) { + if (exp < 0) { exp = 3; } } @@ -2907,6 +2906,10 @@ void MessageMap::dump(bool withConditions, OutputFormat outputFormat, ostream* o *output << (m_addAll ? "[" : "{"); } else { Message::dumpHeader(nullptr, output); + if (m_addAll) { + *output << endl << "# max ID length: " << static_cast(m_maxIdLength) + << " (broadcast only: " << static_cast(m_maxBroadcastIdLength) << ")"; + } } if (!(outputFormat & OF_SHORT)) { *output << endl; diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index ca862ee9..b0a303b7 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -158,13 +158,6 @@ class Message : public AttributedItem { */ static uint64_t createKey(symbol_t pb, symbol_t sb, bool broadcast); - /** - * Get the length field from the key. - * @param key the key. - * @return the length field from the key. - */ - static size_t getKeyLength(uint64_t key) { return (size_t)(key >> (8 * 7 + 5)); } - /** * Parse an ID part from the input @a string. * @param input the input @a string, hex digits optionally separated by space. @@ -1651,6 +1644,10 @@ class MessageMap : public MappedFileReader { */ void dump(bool withConditions, OutputFormat outputFormat, ostream* output) const; + /** + * @return the maximum ID length used by any of the known @a Message instances. + */ + size_t getMaxIdLength() const { return m_maxIdLength; } private: /** empty vector for @a getLoadedFiles(). */