diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index 6de65aec..d9e8d666 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -101,12 +101,10 @@ Message::Message(const string circuit, const string name, key |= (unsigned long long)pb << (8 * 5); key |= (unsigned long long)sb << (8 * 4); m_key = key; - if (circuit=="scan") { - setScanMessage(); - m_pollPriority = 0; - } + setScanMessage(); } + /** * Helper method for getting a default if the value is empty. * @param value the value to check. @@ -387,13 +385,32 @@ result_t Message::create(vector::iterator& it, const vector::ite return RESULT_OK; } +Message* Message::createScanMessage() +{ + return new Message("scan", "", false, false, 0x07, 0x04, DataFieldSet::getIdentFields(), true); +} + Message* Message::derive(const unsigned char dstAddress, const unsigned char srcAddress, const string circuit) { - return new Message(circuit.length()==0 ? m_circuit : circuit, m_name, + Message* result = 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); + if (m_isScanMessage) { + result->setScanMessage(); + } + return result; +} + +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, SYN, m_circuit); } bool Message::checkIdPrefix(vector& id) @@ -717,22 +734,6 @@ void Message::dumpColumn(ostream& output, size_t column, bool withConditions) } -Message* ScanMessage::derive(const unsigned char dstAddress, const unsigned char srcAddress, const string circuit) -{ - return new ScanMessage(circuit, dstAddress, this); -} - -ScanMessage* ScanMessage::derive(const unsigned char dstAddress, const bool extendCircuit) -{ - if (extendCircuit) { - ostringstream out; - out << m_circuit << '.' << hex << setw(2) << setfill('0') << static_cast(dstAddress); - return new ScanMessage(out.str(), dstAddress, this); - } - return new ScanMessage(m_circuit, dstAddress, this); -} - - ChainedMessage::ChainedMessage(const string circuit, const string name, const bool isWrite, const string comment, const unsigned char srcAddress, const unsigned char dstAddress, @@ -774,11 +775,15 @@ ChainedMessage::~ChainedMessage() Message* ChainedMessage::derive(const unsigned char dstAddress, const unsigned char srcAddress, const string circuit) { - return new ChainedMessage(circuit.length()==0 ? m_circuit : circuit, m_name, + ChainedMessage* result = 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); + if (m_isScanMessage) { + result->setScanMessage(); + } + return result; } bool ChainedMessage::checkId(SymbolString& master, unsigned char* index) @@ -1598,7 +1603,7 @@ result_t MessageMap::addFromFile(vector::iterator& begin, const vectorgetDerivedKey(dstAddress); vector* msgs = getByKey(key); if (msgs!=NULL) - return (ScanMessage*)msgs->front(); - ScanMessage* message = m_scanMessage->derive(dstAddress, true); + return msgs->front(); + 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 f21b0a2c..207f9e20 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -93,8 +93,9 @@ public: const unsigned char pollPriority=0, Condition* condition=NULL); +private: /** - * Construct a new simple instance (e.g. for scanning). + * Construct a new scan @a Message instance. * @param circuit the circuit name, or empty for not storing by name. * @param name the message name (unique within the same circuit and type), or empty for not storing by name. * @param isWrite whether this is a write message. @@ -110,6 +111,7 @@ public: const unsigned char pb, const unsigned char sb, DataField* data, const bool deleteData); +public: /** * Destructor. */ @@ -139,6 +141,11 @@ public: vector< vector >* defaultsRows, Condition* condition, const string& filename, DataFieldTemplates* templates, vector& messages); + /** + * Create a new scan @a Message instance. + */ + static Message* createScanMessage(); + /** * Set that this is a special scanning @a Message instance. */ @@ -159,6 +166,14 @@ public: */ 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 ScanMessage instance. + */ + Message* derive(const unsigned char dstAddress, const bool extendCircuit); + /** * Get the optional circuit name. * @return the optional circuit name. @@ -528,52 +543,6 @@ protected: }; -/** - * A marker subclass of @a Message for identifying ebusd created scanning @a Message instances. - */ -class ScanMessage : public Message -{ -public: - - /** - * Construct a new instance. - * @param circuit the optional circuit name. - * @param dstAddress the destination address, or @a SYN for any (set later). - * @param copyFrom the @a ScanMessage from which to copy the ID and data. - */ - ScanMessage(const string circuit, - const unsigned char dstAddress, - ScanMessage* copyFrom) - : Message(circuit, "id", false, false, "", SYN, dstAddress, - copyFrom->m_id, copyFrom->m_data, false) { - setScanMessage(); - } - - /** - * Construct a new instance. - * @param data the @a DataField for encoding/decoding the chained message. - * @param deleteData whether to delete the @a DataField during destruction. - */ - ScanMessage(DataField* data, const bool deleteData) - : Message("scan", "id", false, false, 0x07, 0x04, data, deleteData) { - } - - virtual ~ScanMessage() {} - - // @copydoc - virtual Message* derive(const unsigned char dstAddress, const unsigned char srcAddress, const string circuit); - - /** - * Derive a new @a ScanMessage 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 ScanMessage instance. - */ - ScanMessage* derive(const unsigned char dstAddress, const bool extendCircuit); - -}; - - /** * A chained @a Message that needs more than one read/write on the bus to collect/send the data. */ @@ -1117,7 +1086,7 @@ public: MessageMap(const bool addAll=false) : FileReader::FileReader(true), m_addAll(addAll), m_maxIdLength(0), m_messageCount(0), m_conditionalMessageCount(0), m_passiveMessageCount(0) { - m_scanMessage = new ScanMessage(DataFieldSet::getIdentFields(), true); + m_scanMessage = Message::createScanMessage(); } /** @@ -1157,11 +1126,11 @@ public: const string& filename, unsigned int lineNo); /** - * Get the scan @a ScanMessage instance for the specified address. + * Get the scan @a Message instance for the specified address. * @param dstAddress the destination address, or @a SYN for the base scan @a Message. - * @return the scan @a ScanMessage instance, or NULL if the dstAddress is no slave. + * @return the scan @a Message instance, or NULL if the dstAddress is no slave. */ - ScanMessage* getScanMessage(const unsigned char dstAddress=SYN); + Message* getScanMessage(const unsigned char dstAddress=SYN); /** * Resolve all @a Condition instances. @@ -1324,8 +1293,8 @@ private: /** whether to add all messages, even if duplicate. */ const bool m_addAll; - /** the @a ScanMessage instance used for scanning. */ - ScanMessage* m_scanMessage; + /** the @a Message instance used for scanning. */ + Message* m_scanMessage; /** the loaded configuration files by slave address. */ map m_loadedFiles;