From 62317ea47bdab8eab553dddbc1b75ba9a8c4b591 Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 3 Jan 2016 11:23:26 +0100 Subject: [PATCH] also store derived scan messages with circuit name extended by address on success --- src/lib/ebus/message.cpp | 31 +++++++++++++++++++++---------- src/lib/ebus/message.h | 13 +++++++++++-- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index f8a17cab..e23b82aa 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -378,15 +378,25 @@ result_t Message::create(vector::iterator& it, const vector::ite return RESULT_OK; } -Message* Message::derive(const unsigned char dstAddress, unsigned char srcAddress) +Message* Message::derive(const unsigned char dstAddress, const unsigned char srcAddress, const string circuit) { - return new Message(m_circuit, m_name, m_isWrite, - m_isPassive, m_comment, + return new Message(circuit.length()==0 ? m_circuit : circuit, m_name, + m_isWrite, m_isPassive, m_comment, srcAddress==SYN ? m_srcAddress : srcAddress, dstAddress, m_id, m_data, false, m_pollPriority, m_condition); } +Message* Message::derive(const unsigned char dstAddress, const bool extendCircuit) +{ + if (extendCircuit) { + ostringstream out; + out << m_circuit << '.' << hex << setw(2) << setfill('0') << static_cast(dstAddress); + return derive(dstAddress, SYN, out.str()); + } + return derive(dstAddress); +} + bool Message::checkIdPrefix(vector& id) { if (id.size() > m_id.size()) @@ -746,11 +756,12 @@ ChainedMessage::~ChainedMessage() free(m_lastSlaveUpdateTimes); } -Message* ChainedMessage::derive(const unsigned char dstAddress, unsigned char srcAddress) +Message* ChainedMessage::derive(const unsigned char dstAddress, const unsigned char srcAddress, const string circuit) { - return new ChainedMessage(m_circuit, m_name, m_isWrite, - m_comment, srcAddress==SYN ? m_srcAddress : srcAddress, dstAddress, m_id, - m_ids, m_lengths, m_data, false, + return new ChainedMessage(circuit.length()==0 ? m_circuit : circuit, m_name, + m_isWrite, m_comment, + srcAddress==SYN ? m_srcAddress : srcAddress, dstAddress, + m_id, m_ids, m_lengths, m_data, false, m_pollPriority, m_condition); } @@ -1075,7 +1086,7 @@ result_t SimpleCondition::resolve(MessageMap* messages, ostringstream& errorMess unsigned long long key = message->getDerivedKey(m_dstAddress); vector* derived = messages->getByKey(key); if (derived==NULL) { - message = message->derive(m_dstAddress); + message = message->derive(m_dstAddress, true); messages->add(message); } else { message = getFirstAvailable(*derived, *message); @@ -1349,8 +1360,8 @@ Message* MessageMap::getScanMessage(const unsigned char dstAddress) vector* msgs = getByKey(key); if (msgs!=NULL) return msgs->front(); - Message* message = m_scanMessage->derive(dstAddress); - add(message, false); + Message* message = m_scanMessage->derive(dstAddress, true); + add(message); return message; } diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index 9e7148dd..fb9d2a26 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -143,9 +143,18 @@ public: * Derive a new @a Message from this message. * @param dstAddress the new destination address. * @param srcAddress the new source address, or @a SYN to keep the current source address. + * @param circuit the new circuit name, or empty to use the current circuit name. * @return the derived @a Message instance. */ - virtual Message* derive(const unsigned char dstAddress, unsigned char srcAddress=SYN); + virtual Message* derive(const unsigned char dstAddress, const unsigned char srcAddress=SYN, const string circuit=""); + + /** + * Derive a new @a Message from this message. + * @param dstAddress the new destination address. + * @param extendCircuit whether to extend the current circuit name with a dot and the new destination address in hex. + * @return the derived @a Message instance. + */ + Message* derive(const unsigned char dstAddress, const bool extendCircuit); /** * Get the optional circuit name. @@ -548,7 +557,7 @@ public: virtual ~ChainedMessage(); // @copydoc - virtual Message* derive(const unsigned char dstAddress, unsigned char srcAddress=SYN); + virtual Message* derive(const unsigned char dstAddress, const unsigned char srcAddress=SYN, const string circuit=""); // @copydoc virtual unsigned char getIdLength() const { return (unsigned char)(m_ids[0].size() - 2); }