Skip to content

Commit

Permalink
fix ignored message id key for NN>3, fix longer message key check (fixes
Browse files Browse the repository at this point in the history
 #1436), add log message on exceeded max length
  • Loading branch information
john30 committed Jan 12, 2025
1 parent 0445e44 commit 34552ea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/ebusd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 9 additions & 6 deletions src/lib/ebus/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ uint64_t Message::createKey(const vector<symbol_t>& 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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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<unsigned>(m_maxIdLength)
<< " (broadcast only: " << static_cast<unsigned>(m_maxBroadcastIdLength) << ")";
}
}
if (!(outputFormat & OF_SHORT)) {
*output << endl;
Expand Down
11 changes: 4 additions & 7 deletions src/lib/ebus/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(). */
Expand Down

0 comments on commit 34552ea

Please sign in to comment.