diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index e0a148d6..11eece65 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -282,6 +282,15 @@ result_t Message::create(vector::iterator& it, const vector::ite return RESULT_OK; } +bool Message::setPollPriority(unsigned char priority) +{ + if (priority == m_pollPriority || m_isPassive) + return false; + + m_pollPriority = priority; + return true; +} + result_t Message::prepareMaster(const unsigned char srcAddress, SymbolString& masterData, istringstream& input, char separator, const unsigned char dstAddress) { if (m_isPassive) @@ -538,10 +547,7 @@ result_t MessageMap::add(Message* message) m_maxIdLength = idLength; m_messagesByKey[key] = message; - if (message->getPollPriority() > 0) { - message->m_lastPollTime = m_pollMessages.size(); - m_pollMessages.push(message); - } + addPollMessage(message); return RESULT_OK; } @@ -680,6 +686,14 @@ Message* MessageMap::find(SymbolString& master) return NULL; } +void MessageMap::addPollMessage(Message* message) +{ + if (message != NULL && message->getPollPriority() > 0) { + message->m_lastPollTime = m_pollMessages.size(); + m_pollMessages.push(message); + } +} + void MessageMap::clear() { // clear poll messages diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index 87fc2ffc..0d9d739a 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -156,6 +156,13 @@ public: */ unsigned char getPollPriority() const { return m_pollPriority; } + /** + * Set the polling priority. + * @param priority the polling priority, or 0 for no polling at all. + * @return true when the priority was changed, false otherwise. + */ + bool setPollPriority(unsigned char priority); + /** * Prepare the master @a SymbolString for sending a query or command to the bus. * @param srcAddress the source address to set. @@ -290,7 +297,7 @@ private: const bool m_deleteData; /** the priority for polling, or 0 for no polling at all. */ - const unsigned char m_pollPriority; + unsigned char m_pollPriority; /** the last seen master data. */ SymbolString m_lastMasterData; @@ -390,6 +397,12 @@ public: */ Message* find(SymbolString& master); + /** + * Add a @a Message to the list of instances to poll. + * @param message the @a Message to poll. + */ + void addPollMessage(Message* message); + /** * Removes all @a Message instances. */