From 33c8776706865044a3b5e174ca1fb52e1fceacb9 Mon Sep 17 00:00:00 2001 From: john30 Date: Sat, 14 Mar 2015 11:02:24 +0100 Subject: [PATCH] renamed class in message definition and commands to circuit --- src/ebusd/bushandler.cpp | 18 +++++++------- src/ebusd/mainloop.cpp | 54 ++++++++++++++++++++-------------------- src/lib/ebus/message.cpp | 50 ++++++++++++++++++------------------- src/lib/ebus/message.h | 38 ++++++++++++++-------------- 4 files changed, 80 insertions(+), 80 deletions(-) diff --git a/src/ebusd/bushandler.cpp b/src/ebusd/bushandler.cpp index d8fad1ef..b6e9eeb6 100644 --- a/src/ebusd/bushandler.cpp +++ b/src/ebusd/bushandler.cpp @@ -74,9 +74,9 @@ bool PollRequest::notify(result_t result, SymbolString& slave) result = m_message->decode(pt_slaveData, slave, output); // decode data } if (result < RESULT_OK) - logError(lf_bus, "poll %s %s failed: %s", m_message->getClass().c_str(), m_message->getName().c_str(), getResultCode(result)); + logError(lf_bus, "poll %s %s failed: %s", m_message->getCircuit().c_str(), m_message->getName().c_str(), getResultCode(result)); else - logNotice(lf_bus, "poll %s %s: %s", m_message->getClass().c_str(), m_message->getName().c_str(), output.str().c_str()); + logNotice(lf_bus, "poll %s %s: %s", m_message->getCircuit().c_str(), m_message->getName().c_str(), output.str().c_str()); return false; } @@ -735,27 +735,27 @@ void BusHandler::receiveCompleted() logNotice(lf_update, "unknown MS cmd: %s / %s", m_command.getDataStr().c_str(), m_response.getDataStr().c_str()); } else { - string clazz = message->getClass(); + string circuit = message->getCircuit(); string name = message->getName(); ostringstream output; result_t result = message->decode(m_command, m_response, output); if (result < RESULT_OK) - logError(lf_update, "unable to parse %s %s from %s / %s: %s", clazz.c_str(), name.c_str(), m_command.getDataStr().c_str(), m_response.getDataStr().c_str(), getResultCode(result)); + logError(lf_update, "unable to parse %s %s from %s / %s: %s", circuit.c_str(), name.c_str(), m_command.getDataStr().c_str(), m_response.getDataStr().c_str(), getResultCode(result)); else { string data = output.str(); if (m_answer && dstAddress == (master ? m_ownMasterAddress : m_ownSlaveAddress)) { - logNotice(lf_update, "self-update %s %s QQ=%2.2x: %s", clazz.c_str(), name.c_str(), srcAddress, data.c_str()); // TODO store in database of internal variables + logNotice(lf_update, "self-update %s %s QQ=%2.2x: %s", circuit.c_str(), name.c_str(), srcAddress, data.c_str()); // TODO store in database of internal variables } else if (message->getDstAddress() == SYN) { // any destination if (message->getSrcAddress() == SYN) // any destination and any source - logNotice(lf_update, "update %s %s QQ=%2.2x ZZ=%2.2x: %s", clazz.c_str(), name.c_str(), srcAddress, dstAddress, data.c_str()); + logNotice(lf_update, "update %s %s QQ=%2.2x ZZ=%2.2x: %s", circuit.c_str(), name.c_str(), srcAddress, dstAddress, data.c_str()); else - logNotice(lf_update, "update %s %s ZZ=%2.2x: %s", clazz.c_str(), name.c_str(), dstAddress, data.c_str()); + logNotice(lf_update, "update %s %s ZZ=%2.2x: %s", circuit.c_str(), name.c_str(), dstAddress, data.c_str()); } else if (message->getSrcAddress() == SYN) // any source - logNotice(lf_update, "update %s %s QQ=%2.2x: %s", clazz.c_str(), name.c_str(), srcAddress, data.c_str()); + logNotice(lf_update, "update %s %s QQ=%2.2x: %s", circuit.c_str(), name.c_str(), srcAddress, data.c_str()); else - logNotice(lf_update, "update %s %s: %s", clazz.c_str(), name.c_str(), data.c_str()); + logNotice(lf_update, "update %s %s: %s", circuit.c_str(), name.c_str(), data.c_str()); } } } diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index 37d26574..e3507c13 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -192,7 +192,7 @@ string MainLoop::executeRead(vector &args) size_t argPos = 1; time_t maxAge = 5*60; bool verbose = false; - string clazz; + string circuit; unsigned char dstAddress = SYN; while (args.size() > argPos && args[argPos][0] == '-') { if (args[argPos] == "-f") { @@ -222,7 +222,7 @@ string MainLoop::executeRead(vector &args) argPos = 0; // print usage break; } - clazz = args[argPos]; + circuit = args[argPos]; } else if (args[argPos] == "-d") { argPos++; @@ -241,13 +241,13 @@ string MainLoop::executeRead(vector &args) argPos++; } if (argPos == 0 || args.size() < argPos + 1 || args.size() > argPos + 2) - return "usage: read [-v] [-f] [-m SECONDS] [-d ZZ] [-c CLASS] NAME [FIELD[.N]]\n" + return "usage: read [-v] [-f] [-m SECONDS] [-d ZZ] [-c CIRCUIT] NAME [FIELD[.N]]\n" " Read value(s).\n" " -v be verbose (include field names, units, and comments)\n" " -f force reading from the bus (same as '-m 0')\n" " -m SECONDS only return cached value if age is less than SECONDS [300]\n" " -d ZZ override destination address ZZ\n" - " -c CLASS limit to messages of CLASS\n" + " -c CIRCUIT limit to messages of CIRCUIT\n" " NAME the NAME of the message to send\n" " FIELD only retrieve the field named FIELD\n" " N only retrieve the N'th field named FIELD (0-based)"; @@ -270,10 +270,10 @@ string MainLoop::executeRead(vector &args) time(&now); ostringstream result; - Message* message = m_messages->find(clazz, args[argPos], false); + Message* message = m_messages->find(circuit, args[argPos], false); if (dstAddress==SYN && maxAge > 0) { - Message* cacheMessage = m_messages->find(clazz, args[argPos], false, true); + Message* cacheMessage = m_messages->find(circuit, args[argPos], false, true); bool hasCache = cacheMessage != NULL; if (!hasCache || (message != NULL && message->getLastUpdateTime() > cacheMessage->getLastUpdateTime())) cacheMessage = message; // message is newer/better @@ -374,10 +374,10 @@ string MainLoop::executeWrite(vector &args) argPos++; } if (argPos == 0 || (args.size() != argPos + 3 && args.size() != argPos + 2)) - return "usage: write [-c] CLASS NAME [VALUE[;VALUE]*]\n" + return "usage: write [-c] CIRCUIT NAME [VALUE[;VALUE]*]\n" " or: write -h ZZPBSBNNDx\n" " Write value(s) or hex message.\n" - " CLASS the CLASS of the message to send\n" + " CIRCUIT the CIRCUIT of the message to send\n" " NAME the NAME of the message to send\n" " VALUE a single field VALUE\n" " -h directly write hex message:\n" @@ -424,7 +424,7 @@ string MainLoop::executeFind(vector &args) { size_t argPos = 1; bool verbose = false, configFormat = false, withRead = true, withWrite = false, withPassive = true, first = true, onlyWithData = false; - string clazz; + string circuit; short pb = -1; while (args.size() > argPos && args[argPos][0] == '-') { if (args[argPos] == "-v") @@ -476,7 +476,7 @@ string MainLoop::executeFind(vector &args) argPos = 0; // print usage break; } - clazz = args[argPos]; + circuit = args[argPos]; } else { argPos = 0; // print usage @@ -485,23 +485,23 @@ string MainLoop::executeFind(vector &args) argPos++; } if (argPos == 0 || args.size() < argPos || args.size() > argPos + 1) - return "usage: find [-v] [-r] [-w] [-p] [-d] [-i PB] [-f] [-c CLASS] [NAME]\n" + return "usage: find [-v] [-r] [-w] [-p] [-d] [-i PB] [-f] [-c CIRCUIT] [NAME]\n" " Find message(s).\n" - " -v be verbose (append destination address and update time)\n" - " -r limit to active read messages (default: read + passive)\n" - " -w limit to active write messages (default: read + passive)\n" - " -p limit to passive messages (default: read + passive)\n" - " -d only include messages with actual data\n" - " -i PB limit to messages with primary command byte PB ('0xPB' for hex)\n" - " -f list messages in CSV configuration file format\n" - " -c CLASS limit to messages of CLASS (or a part thereof)\n" - " NAME the NAME of the message to find (or a part thereof)"; + " -v be verbose (append destination address and update time)\n" + " -r limit to active read messages (default: read + passive)\n" + " -w limit to active write messages (default: read + passive)\n" + " -p limit to passive messages (default: read + passive)\n" + " -d only include messages with actual data\n" + " -i PB limit to messages with primary command byte PB ('0xPB' for hex)\n" + " -f list messages in CSV configuration file format\n" + " -c CIRCUIT limit to messages of CIRCUIT (or a part thereof)\n" + " NAME the NAME of the messages to find (or a part thereof)"; deque messages; if (args.size() == argPos) - messages = m_messages->findAll(clazz, "", pb, false, withRead, withWrite, withPassive); + messages = m_messages->findAll(circuit, "", pb, false, withRead, withWrite, withPassive); else - messages = m_messages->findAll(clazz, args[argPos], pb, false, withRead, withWrite, withPassive); + messages = m_messages->findAll(circuit, args[argPos], pb, false, withRead, withWrite, withPassive); bool found = false; ostringstream result; @@ -521,7 +521,7 @@ string MainLoop::executeFind(vector &args) continue; if (found) result << endl; - result << message->getClass() << " " << message->getName() << " = "; + result << message->getCircuit() << " " << message->getName() << " = "; if (lastup == 0) result << "no data stored"; else @@ -699,10 +699,10 @@ string MainLoop::executeQuit(vector &args, bool& connected) string MainLoop::executeHelp() { return "usage:\n" - " read|r Read value(s): read [-v] [-f] [-m SECONDS] [-d ZZ] [-c CLASS] NAME [FIELD[.N]]\n" - " write|w Write value(s): write [-c] CLASS NAME [VALUE[;VALUE]*]\n" + " read|r Read value(s): read [-v] [-f] [-m SECONDS] [-d ZZ] [-c CIRCUIT] NAME [FIELD[.N]]\n" + " write|w Write value(s): write [-c] CIRCUIT NAME [VALUE[;VALUE]*]\n" " Write hex message: write -h ZZPBSBNNDx'\n" - " find|f Find message(s): find [-v] [-r] [-w] [-p] [-d] [-i PB] [-f] [-c CLASS] [NAME]\n" + " find|f Find message(s): find [-v] [-r] [-w] [-p] [-d] [-i PB] [-f] [-c CIRCUIT] [NAME]\n" " listen|l Listen for updates: listen [stop]\n" " state|s Report bus state\n" " scan Scan slaves: scan [full]\n" @@ -734,7 +734,7 @@ string MainLoop::getUpdates(time_t since, time_t until) time_t lastchg = message->getLastChangeTime(); if (lastchg < since || lastchg >= until) continue; - result << message->getClass() << " " << message->getName() << " = "; + result << message->getCircuit() << " " << message->getName() << " = "; message->decodeLastData(result); result << endl; } diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index ef793b9b..99a46df6 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -33,12 +33,12 @@ using namespace std; /** the bit mask of the source master number in the message key. */ #define ID_SOURCE_MASK (0x1fLL << (8 * 7)) -Message::Message(const string clazz, const string name, const bool isWrite, +Message::Message(const string circuit, const string name, const bool isWrite, const bool isPassive, const string comment, const unsigned char srcAddress, const unsigned char dstAddress, const vector id, DataField* data, const bool deleteData, const unsigned char pollPriority) - : m_class(clazz), m_name(name), m_isWrite(isWrite), + : m_circuit(circuit), m_name(name), m_isWrite(isWrite), m_isPassive(isPassive), m_comment(comment), m_srcAddress(srcAddress), m_dstAddress(dstAddress), m_id(id), m_data(data), m_deleteData(deleteData), @@ -60,7 +60,7 @@ Message::Message(const string clazz, const string name, const bool isWrite, Message::Message(const bool isWrite, const bool isPassive, const unsigned char pb, const unsigned char sb, DataField* data) - : m_class(), m_name(), m_isWrite(isWrite), + : m_circuit(), m_name(), m_isWrite(isWrite), m_isPassive(isPassive), m_comment(), m_srcAddress(SYN), m_dstAddress(SYN), m_data(data), m_deleteData(true), m_pollPriority(0), @@ -91,7 +91,7 @@ result_t Message::create(vector::iterator& it, const vector::ite vector< vector >* defaultsRows, DataFieldTemplates* templates, vector& messages) { - // [type],[class],name,[comment],[QQ],[ZZ],id,fields... + // [type],[circuit],name,[comment],[QQ[;QQ]*],[ZZ],id,fields... result_t result; bool isWrite = false, isPassive = false; string defaultName; @@ -136,7 +136,7 @@ result_t Message::create(vector::iterator& it, const vector::ite } } - string clazz = getDefault(*it++, defaults, defaultPos++); + string circuit = getDefault(*it++, defaults, defaultPos++); if (it == end) return RESULT_ERR_EOF; @@ -271,12 +271,12 @@ result_t Message::create(vector::iterator& it, const vector::ite char num[10]; for (vector::iterator it = dstAddresses.begin(); it != dstAddresses.end(); it++, index++) { unsigned char dstAddress = *it; - string useClass = clazz; + string useCircuit = circuit; if (multiple) { sprintf(num, ".%d", index); - useClass = useClass + num; + useCircuit = useCircuit + num; } - messages.push_back(new Message(useClass, name, isWrite, isPassive, comment, srcAddress, dstAddress, id, data, index==0, pollPriority)); + messages.push_back(new Message(useCircuit, name, isWrite, isPassive, comment, srcAddress, dstAddress, id, data, index==0, pollPriority)); } return RESULT_OK; } @@ -461,7 +461,7 @@ void Message::dump(ostream& output) if (m_pollPriority>0) output << static_cast(m_pollPriority); } - DataField::dumpString(output, m_class); + DataField::dumpString(output, m_circuit); DataField::dumpString(output, m_name); DataField::dumpString(output, m_comment); output << FIELD_SEPARATOR; @@ -500,9 +500,9 @@ result_t MessageMap::add(Message* message) } bool isPassive = message->isPassive(); bool isWrite = message->isWrite(); - string clazz = strtolower(message->getClass()); + string circuit = strtolower(message->getCircuit()); string name = strtolower(message->getName()); - string nameKey = string(isPassive ? "P" : (isWrite ? "W" : "R")) + clazz + FIELD_SEPARATOR + name; + string nameKey = string(isPassive ? "P" : (isWrite ? "W" : "R")) + circuit + FIELD_SEPARATOR + name; map::iterator nameIt = m_messagesByName.find(nameKey); if (nameIt != m_messagesByName.end()) { return RESULT_ERR_DUPLICATE; // duplicate key @@ -513,10 +513,10 @@ result_t MessageMap::add(Message* message) if (isPassive) m_passiveMessageCount++; - nameKey = string(isPassive ? "-P" : (isWrite ? "-W" : "-R")) + name; // also store without class + nameKey = string(isPassive ? "-P" : (isWrite ? "-W" : "-R")) + name; // also store without circuit nameIt = m_messagesByName.find(nameKey); if (nameIt == m_messagesByName.end()) { - m_messagesByName[nameKey] = message; // only store first key without class + m_messagesByName[nameKey] = message; // only store first key without circuit } unsigned char idLength = (unsigned char)(message->getId().size() - 2); @@ -564,18 +564,18 @@ result_t MessageMap::addFromFile(vector::iterator& begin, const vector::iterator it = m_messagesByName.find(key); if (it != m_messagesByName.end()) return it->second; @@ -584,23 +584,23 @@ Message* MessageMap::find(const string& clazz, const string& name, const bool is return NULL; } -deque MessageMap::findAll(const string& clazz, const string& name, const short pb, const bool completeMatch, +deque MessageMap::findAll(const string& circuit, const string& name, const short pb, const bool completeMatch, const bool withRead, const bool withWrite, const bool withPassive) { deque ret; - string lclass = strtolower(clazz); + string lcircuit = strtolower(circuit); string lname = strtolower(name); - bool checkClass = clazz.length() > 0; + bool checkCircuit = lcircuit.length() > 0; bool checkName = name.length() > 0; bool checkPb = pb >= 0; for (map::iterator it = m_messagesByName.begin(); it != m_messagesByName.end(); it++) { if (it->first[0] == '-') // avoid duplicates: instances stored multiple times have a key starting with "-" continue; Message* message = it->second; - if (checkClass) { - string check = strtolower(message->getClass()); - if (completeMatch ? (check != lclass) : (check.find(lclass) == check.npos)) + if (checkCircuit) { + string check = strtolower(message->getCircuit()); + if (completeMatch ? (check != lcircuit) : (check.find(lcircuit) == check.npos)) continue; } if (checkName) { diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index 101fcbb0..7a05aab2 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -44,8 +44,8 @@ public: /** * Construct a new instance. - * @param clazz the optional device class. - * @param name the message name (unique within the same class and type). + * @param circuit the optional circuit name. + * @param name the message name (unique within the same circuit and type). * @param isWrite whether this is a write message. * @param isPassive true if message can only be initiated by a participant other than us, * false if message can be initiated by any participant. @@ -57,7 +57,7 @@ public: * @param deleteData whether to delete the @a DataField during destruction. * @param pollPriority the priority for polling, or 0 for no polling at all. */ - Message(const string clazz, const string name, const bool isWrite, + Message(const string circuit, const string name, const bool isWrite, const bool isPassive, const string comment, const unsigned char srcAddress, const unsigned char dstAddress, const vector id, DataField* data, const bool deleteData, @@ -96,14 +96,14 @@ public: DataFieldTemplates* templates, vector& messages); /** - * Get the optional device class. - * @return the optional device class. + * Get the optional circuit name. + * @return the optional circuit name. */ - string getClass() const { return m_class; } + string getCircuit() const { return m_circuit; } /** - * Get the message name (unique within the same class and type). - * @return the message name (unique within the same class and type). + * Get the message name (unique within the same circuit and type). + * @return the message name (unique within the same circuit and type). */ string getName() const { return m_name; } @@ -256,10 +256,10 @@ public: private: - /** the optional device class. */ - const string m_class; + /** the optional circuit name. */ + const string m_circuit; - /** the message name (unique within the same class and type). */ + /** the message name (unique within the same circuit and type). */ const string m_name; /** whether this is a write message. */ @@ -358,29 +358,29 @@ public: virtual result_t addFromFile(vector::iterator& begin, const vector::iterator end, DataFieldTemplates* arg, vector< vector >* defaults, const string& filename, unsigned int lineNo); /** - * Find the @a Message instance for the specified class and name. - * @param clazz the optional device class. + * Find the @a Message instance for the specified circuit and name. + * @param circuit the optional circuit name. * @param name the message name. * @param isWrite whether this is a write message. * @param isPassive whether this is a passive message. * @return the @a Message instance, or NULL. * Note: the caller may not free the returned instance. */ - Message* find(const string& clazz, const string& name, const bool isWrite, const bool isPassive=false); + Message* find(const string& circuit, const string& name, const bool isWrite, const bool isPassive=false); /** - * Find all active get @a Message instances for the specified class and name. - * @param clazz the device class, or empty for any. + * Find all active get @a Message instances for the specified circuit and name. + * @param circuit the circuit name, or empty for any. * @param name the message name, or empty for any. * @param pb the primary ID byte, or -1 for any (default any). - * @param completeMatch false to also include messages where the class and name matches only a part of the given class and name (default true). + * @param completeMatch false to also include messages where the circuit and name matches only a part of the given circuit and name (default true). * @param withRead true to include read messages (default true). * @param withWrite true to include write messages (default false). * @param withPassive true to include passive messages (default false). * @return the found @a Message instances. * Note: the caller may not free the returned instances. */ - deque findAll(const string& clazz, const string& name, const short pb=-1, const bool completeMatch=true, + deque findAll(const string& circuit, const string& name, const short pb=-1, const bool completeMatch=true, const bool withRead=true, const bool withWrite=false, const bool withPassive=false); /** @@ -436,7 +436,7 @@ private: /** the number of distinct passive @a Message instances stored in @a m_messagesByKey. */ size_t m_passiveMessageCount; - /** the known @a Message instances by lowercase class and name. */ + /** the known @a Message instances by lowercase circuit and name. */ map m_messagesByName; /** the known @a Message instances by key. */