diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index 1a4e38e0..56e07bdb 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -326,12 +326,19 @@ result_t Message::decode(const PartType partType, SymbolString& data, return RESULT_OK; } -bool Message::isLessPollWeight(Message* other) { - if (m_pollPriority * m_pollCount < other->m_pollPriority * other->m_pollCount) +bool Message::isLessPollWeight(const Message* other) +{ + unsigned int tw = m_pollPriority * m_pollCount; + unsigned int ow = other->m_pollPriority * other->m_pollCount; + if (tw > ow) + return true; + if (tw < ow) + return false; + if (m_pollPriority > other->m_pollPriority) return true; if (m_pollPriority < other->m_pollPriority) - return true; - if (m_lastPollTime < other->m_lastPollTime) + return false; + if (m_lastPollTime > other->m_lastPollTime) return true; return false; @@ -373,8 +380,10 @@ result_t MessageMap::add(Message* message) m_maxIdLength = idLength; m_messagesByKey[key] = message; - if (message->getPollPriority() > 0) + if (message->getPollPriority() > 0) { + message->m_lastPollTime = m_pollMessages.size(); m_pollMessages.push(message); + } return RESULT_OK; } diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index 5d333662..f882cafb 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -211,11 +211,11 @@ public: time_t getLastPollTime() { return m_lastPollTime; } /** - * @brief Return whether this @a Message needs to be polled before the other one. + * @brief Return whether this @a Message needs to be polled after the other one. * @param other the other @a Message to compare with. - * @return true if this @a Message needs to be polled before the other one. + * @return true if this @a Message needs to be polled after the other one. */ - bool isLessPollWeight(Message* other); + bool isLessPollWeight(const Message* other); private: @@ -276,9 +276,9 @@ struct compareMessagePriority : binary_function { * @brief Compare the weighted poll priority of the two @a Message instances. * @param x the first @a Message. * @param y the second @a Message. - * @return whether @a x is bigger than or equal to @a y with regard to their weighted poll priority. + * @return whether @a x is smaller than @a y with regard to their weighted poll priority. */ - bool operator() (Message* x, Message* y) const { return x->isLessPollWeight(y) == false; }; + bool operator() (Message* x, Message* y) const { return x->isLessPollWeight(y); }; };