From 3cb9453329dccb609ad6dc65bf15680bf962838b Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 23 Apr 2017 11:41:15 +0200 Subject: [PATCH 1/7] removed unused code --- src/lib/ebus/filereader.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/ebus/filereader.cpp b/src/lib/ebus/filereader.cpp index 2d63388b..2df6bae7 100644 --- a/src/lib/ebus/filereader.cpp +++ b/src/lib/ebus/filereader.cpp @@ -267,7 +267,6 @@ result_t MappedFileReader::addFromFile(vector& row, string& errorDescrip } map rowMapped; vector< map > subRowsMapped; - vector::iterator it = row.begin(); bool isDefault = m_supportsDefaults && !row[0].empty() && row[0][0] == '*'; if (isDefault) { row[0] = row[0].substr(1); From 70150fd8f9e7dec0b67d4b8dc227d8ac68a273b8 Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 23 Apr 2017 11:56:53 +0200 Subject: [PATCH 2/7] added const[] accessor --- src/lib/ebus/symbol.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib/ebus/symbol.h b/src/lib/ebus/symbol.h index f414da66..0c88e31d 100644 --- a/src/lib/ebus/symbol.h +++ b/src/lib/ebus/symbol.h @@ -170,6 +170,18 @@ class SymbolString { return m_data[index]; } + /** + * Return a reference to the symbol at the specified index. + * @param index the index of the symbol to return. + * @return the reference to the symbol at the specified index, or SYN if not available. + */ + symbol_t operator[](const size_t index) const { + if (index >= m_data.size()) { + return SYN; + } + return m_data[index]; + } + /** * Return whether this instance is equal to the other instance. * @param other the other instance. From 611cb562e2379edb01db1b2318bfb226e98e08ba Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 23 Apr 2017 11:57:02 +0200 Subject: [PATCH 3/7] fixed potential iterator misuse, use auto and const where reasonable --- src/ebusd/bushandler.cpp | 39 +++++------ src/ebusd/bushandler.h | 3 +- src/ebusd/main.cpp | 45 ++++++------- src/ebusd/mainloop.cpp | 43 ++++++------- src/ebusd/mqtthandler.cpp | 7 +- src/ebusd/network.cpp | 12 ++-- src/lib/ebus/data.cpp | 56 ++++++++-------- src/lib/ebus/message.cpp | 132 +++++++++++++++++++------------------- src/lib/ebus/message.h | 7 +- 9 files changed, 167 insertions(+), 177 deletions(-) diff --git a/src/ebusd/bushandler.cpp b/src/ebusd/bushandler.cpp index 4970c086..24e77453 100644 --- a/src/ebusd/bushandler.cpp +++ b/src/ebusd/bushandler.cpp @@ -211,7 +211,7 @@ void GrabbedMessage::setLastData(MasterSymbolString& master, SlaveSymbolString& * @param firstOnly whether to read only the first non-erroneous offset. * @return @a RESULT_OK on success, or an error code. */ -bool decodeType(const DataType* type, SymbolString *input, size_t length, +bool decodeType(const DataType* type, const SymbolString *input, size_t length, size_t offsets, ostringstream& output, bool firstOnly = false) { bool first = true; string in = input->getStr(input->getDataOffset()); @@ -255,7 +255,7 @@ bool decodeType(const DataType* type, SymbolString *input, size_t length, } bool GrabbedMessage::dump(const bool unknown, MessageMap* messages, bool first, ostringstream& output, - const bool decode) { + const bool decode) const { Message* message = messages->find(m_lastMaster); if (unknown && message) { return false; @@ -278,7 +278,7 @@ bool GrabbedMessage::dump(const bool unknown, MessageMap* messages, bool first, return true; } bool master = isMaster(dstAddress) || dstAddress == BROADCAST || m_lastSlave.getDataSize() <= 0; - SymbolString *input; + const SymbolString *input; if (master) { input = &m_lastMaster; } else { @@ -288,7 +288,7 @@ bool GrabbedMessage::dump(const bool unknown, MessageMap* messages, bool first, if (remain == 0) { return true; } - for (auto it : *types) { + for (const auto it : *types) { const DataType* baseType = it.second; if ((baseType->getBitCount() % 8) != 0 || baseType->isIgnored()) { // skip bit and ignored types continue; @@ -1143,10 +1143,13 @@ result_t BusHandler::prepareScan(symbol_t slave, bool full, string levels, bool& } deque messages = m_messages->findAll("scan", "", levels, true); - for (deque::iterator it = messages.begin(); it < messages.end(); it++) { + auto it = messages.begin(); + while (it != messages.end()) { Message* message = *it; if (message->getPrimaryCommand() == 0x07 && message->getSecondaryCommand() == 0x04) { - messages.erase(it--); // query pb 0x07 / sb 0x04 only once + it = messages.erase(it); // query pb 0x07 / sb 0x04 only once + } else { + it++; } } @@ -1229,7 +1232,7 @@ void BusHandler::setScanFinished() { } bool BusHandler::formatScanResult(symbol_t slave, ostringstream& output, bool leadingNewline) { - map>::iterator it = m_scanResults.find(slave); + const auto it = m_scanResults.find(slave); if (it == m_scanResults.end()) { return false; } @@ -1237,7 +1240,7 @@ bool BusHandler::formatScanResult(symbol_t slave, ostringstream& output, bool le output << endl; } output << hex << setw(2) << setfill('0') << static_cast(slave); - for (auto result : it->second) { + for (const auto result : it->second) { output << result; } return true; @@ -1317,7 +1320,7 @@ void BusHandler::formatSeenInfo(ostringstream& output) { const vector& loadedFiles = m_messages->getLoadedFiles(address); if (!loadedFiles.empty()) { bool first = true; - for (auto& loadedFile : loadedFiles) { + for (const auto& loadedFile : loadedFiles) { if (first) { first = false; output << ", loaded \""; @@ -1347,9 +1350,8 @@ void BusHandler::formatUpdateInfo(ostringstream& output) { output << ",\"co\":" << (m_addressConflict ? 1 : 0); if (m_grabMessages) { size_t unknownCnt = 0; - for (map::iterator it = m_grabbedMessages.begin(); it != m_grabbedMessages.end(); - it++) { - Message* message = m_messages->find(it->second.getLastMasterData()); + for (auto it : m_grabbedMessages) { + Message* message = m_messages->find(it.second.getLastMasterData()); if (!message) { unknownCnt++; } @@ -1364,10 +1366,10 @@ void BusHandler::formatUpdateInfo(ostringstream& output) { } output << ",\"" << setfill('0') << setw(2) << hex << static_cast(address) << dec << setw(0); output << "\":{\"o\":" << (ownAddress ? 1 : 0); - map>::iterator it = m_scanResults.find(address); + const auto it = m_scanResults.find(address); if (it != m_scanResults.end()) { output << ",\"s\":\""; - for (auto result : it->second) { + for (const auto result : it->second) { output << result; } output << "\""; @@ -1383,7 +1385,7 @@ void BusHandler::formatUpdateInfo(ostringstream& output) { if (!loadedFiles.empty()) { output << ",\"f\":["; bool first = true; - for (auto& loadedFile : loadedFiles) { + for (const auto loadedFile : loadedFiles) { if (first) { first = false; } else { @@ -1406,7 +1408,7 @@ void BusHandler::formatUpdateInfo(ostringstream& output) { if (!loadedFiles.empty()) { output << ",\"l\":{"; bool first = true; - for (auto& loadedFile : loadedFiles) { + for (const auto& loadedFile : loadedFiles) { if (first) { first = false; } else { @@ -1489,9 +1491,8 @@ void BusHandler::formatGrabResult(const bool unknown, ostringstream& output, con output << "grab disabled"; } else { bool first = true; - for (map::iterator it = m_grabbedMessages.begin(); it != m_grabbedMessages.end(); - it++) { - if (it->second.dump(unknown, m_messages, first, output, decode)) { + for (const auto& it : m_grabbedMessages) { + if (it.second.dump(unknown, m_messages, first, output, decode)) { first = false; } } diff --git a/src/ebusd/bushandler.h b/src/ebusd/bushandler.h index 5007a1eb..d94b0911 100644 --- a/src/ebusd/bushandler.h +++ b/src/ebusd/bushandler.h @@ -329,7 +329,8 @@ class GrabbedMessage { * @param decode whether to add decoding hints. * @return whether the message was added to the output. */ - bool dump(const bool unknown, MessageMap* messages, bool first, ostringstream& output, const bool decode = false); + bool dump(const bool unknown, MessageMap* messages, bool first, ostringstream& output, + const bool decode = false) const; private: diff --git a/src/ebusd/main.cpp b/src/ebusd/main.cpp index 0b2ad941..622050d6 100644 --- a/src/ebusd/main.cpp +++ b/src/ebusd/main.cpp @@ -632,11 +632,10 @@ void shutdown() { s_messageMap = NULL; } // free templates - for (map::iterator it = s_templatesByPath.begin(); it != s_templatesByPath.end(); it++) { - if (it->second != &s_globalTemplates) { - delete it->second; + for (const auto it : s_templatesByPath) { + if (it.second != &s_globalTemplates) { + delete it.second; } - it->second = NULL; } s_templatesByPath.clear(); @@ -738,7 +737,7 @@ DataFieldTemplates* getTemplates(const string filename) { if (pos != string::npos) { path = filename.substr(0, pos); } - map::iterator it = s_templatesByPath.find(path); + const auto it = s_templatesByPath.find(path); if (it != s_templatesByPath.end()) { return it->second; } @@ -755,7 +754,7 @@ DataFieldTemplates* getTemplates(const string filename) { * @return the @a DataFieldTemplates. */ static bool readTemplates(const string path, const string extension, bool available, bool verbose = false) { - map::iterator it = s_templatesByPath.find(path); + const auto it = s_templatesByPath.find(path); if (it != s_templatesByPath.end()) { return false; } @@ -799,8 +798,7 @@ static result_t readConfigFiles(const string path, const string extension, Messa return result; } readTemplates(path, extension, hasTemplates, verbose); - for (vector::iterator it = files.begin(); it != files.end(); it++) { - string name = *it; + for (const auto& name : files) { logInfo(lf_main, "reading file %s", name.c_str()); result = messages->readFromFile(name, errorDescription, verbose); if (result != RESULT_OK) { @@ -808,8 +806,7 @@ static result_t readConfigFiles(const string path, const string extension, Messa } } if (recursive) { - for (vector::iterator it = dirs.begin(); it != dirs.end(); it++) { - string name = *it; + for (const auto& name : dirs) { logInfo(lf_main, "reading dir %s", name.c_str()); result = readConfigFiles(name, extension, messages, true, verbose, errorDescription); if (result != RESULT_OK) { @@ -864,12 +861,11 @@ result_t loadConfigFiles(MessageMap* messages, bool verbose, bool denyRecursive) logInfo(lf_main, "loading configuration files from %s", opt.configPath); messages->clear(); s_globalTemplates.clear(); - for (map::iterator it = s_templatesByPath.begin(); it != s_templatesByPath.end(); - it++) { - if (it->second != &s_globalTemplates) { - delete it->second; + for (auto& it : s_templatesByPath) { + if (it.second != &s_globalTemplates) { + delete it.second; } - it->second = NULL; + it.second = NULL; } s_templatesByPath.clear(); @@ -957,19 +953,20 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, string& rela } logDebug(lf_main, "found %d matching scan config files from %s with prefix %s: %s", files.size(), path.c_str(), prefix.c_str(), getResultCode(result)); - for (string::iterator it = ident.begin(); it != ident.end(); it++) { + auto it = ident.begin(); + while (it != ident.end()) { if (::isspace(*it)) { - ident.erase(it--); + it = ident.erase(it); } else { *it = static_cast(::tolower(*it)); + it++; } } // complete name: cfgpath/MANUFACTURER/ZZ[.C[C[C[C[C]]]]][.circuit][.suffix][.*][.SWxxxx][.HWxxxx][.*].csv size_t bestMatch = 0; string best; map bestDefaults; - for (vector::iterator it = files.begin(); it != files.end(); it++) { - string name = *it; + for (const auto& name : files) { symbol_t checkDest; unsigned int checkSw, checkHw; map defaults; @@ -1020,14 +1017,12 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, string& rela if (readCommon) { result = collectConfigFiles(path, "", ".csv", files); if (result == RESULT_OK && !files.empty()) { - for (vector::iterator it = files.begin(); it != files.end(); it++) { - string name = *it; - name = name.substr(path.length()+1, name.length()-path.length()-strlen(".csv")); // *. - if (name == "_templates.") { // skip templates + for (const auto& name : files) { + string baseName = name.substr(path.length()+1, name.length()-path.length()-strlen(".csv")); // *. + if (baseName == "_templates.") { // skip templates continue; } - if (name.length() < 3 || name.find_first_of('.') != 2) { // different from the scheme "ZZ." - name = *it; + if (baseName.length() < 3 || baseName.find_first_of('.') != 2) { // different from the scheme "ZZ." string errorDescription; result = messages->readFromFile(name, errorDescription, opt.checkConfig); if (result == RESULT_OK) { diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index 333a719b..0c0d2ace 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -50,7 +50,7 @@ result_t UserList::getFieldMap(vector& row, string& errorDescription, co return RESULT_OK; } map seen; - for (auto &name : row) { + for (auto& name : row) { tolower(name); if (name == "name" || name == "secret") { if (seen.find(name) != seen.end()) { @@ -82,13 +82,13 @@ result_t UserList::addFromFile(map& row, vector< mapsecond.empty()) { if (!levels.empty()) { levels += VALUE_SEPARATOR; } - levels += level; + levels += it->second; } } m_userSecrets[name] = secret; @@ -158,9 +158,10 @@ MainLoop::~MainLoop() { m_shutdown = true; join(); - for (list::iterator it = m_dataHandlers.begin(); it != m_dataHandlers.end(); it++) { - delete *it; + for (const auto dataHandler : m_dataHandlers) { + delete dataHandler; } + m_dataHandlers.clear(); if (m_dumpFile) { delete m_dumpFile; m_dumpFile = NULL; @@ -206,11 +207,11 @@ void MainLoop::run() { list dataSinks; deque messages; - for (list::iterator it = m_dataHandlers.begin(); it != m_dataHandlers.end(); it++) { - if ((*it)->isDataSink()) { - dataSinks.push_back(dynamic_cast(*it)); + for (const auto dataHandler : m_dataHandlers) { + if (dataHandler->isDataSink()) { + dataSinks.push_back(dynamic_cast(dataHandler)); } - (*it)->start(); + dataHandler->start(); } while (!m_shutdown) { // pick the next message to handle @@ -362,8 +363,8 @@ void MainLoop::run() { m_updateCheck = message == "" ? "unknown" : message; logNotice(lf_main, "update check: %s", message.c_str()); if (!dataSinks.empty()) { - for (list::iterator it = dataSinks.begin(); it != dataSinks.end(); it++) { - (*it)->notifyUpdateCheckResult(message == "OK" ? "" : m_updateCheck); + for (const auto dataSink : dataSinks) { + dataSink->notifyUpdateCheckResult(message == "OK" ? "" : m_updateCheck); } } } else { @@ -385,10 +386,9 @@ void MainLoop::run() { time(&now); if (!dataSinks.empty()) { messages = m_messages->findAll("", "", "*", false, true, true, true, true, true, sinkSince, now); - for (deque::iterator it = messages.begin(); it != messages.end(); it++) { - Message* message = *it; - for (list::iterator it = dataSinks.begin(); it != dataSinks.end(); it++) { - (*it)->notifyUpdate(message); + for (const auto message : messages) { + for (const auto dataSink : dataSinks) { + dataSink->notifyUpdate(message); } } sinkSince = now; @@ -425,8 +425,7 @@ void MainLoop::run() { if (listening) { string levels = getUserLevels(user); messages = m_messages->findAll("", "", levels, false, true, true, true, true, true, since, now); - for (deque::iterator it = messages.begin(); it != messages.end(); it++) { - Message* message = *it; + for (const auto message : messages) { ostream << message->getCircuit() << " " << message->getName() << " = " << dec; message->decodeLastData(ostream); ostream << endl; @@ -1252,8 +1251,7 @@ string MainLoop::executeFind(vector &args, string levels) { bool found = false; ostringstream result; char str[32]; - for (deque::iterator it = messages.begin(); it != messages.end();) { - Message* message = *it++; + for (const auto message : messages) { if (!id.empty() && !message->checkIdPrefix(id)) { continue; } @@ -1649,8 +1647,7 @@ string MainLoop::executeGet(vector &args, bool& connected) { deque messages = m_messages->findAll(circuit, name, getUserLevels(user), exact, true, false, true); bool first = true; verbosity |= (valueName ? OF_VALUENAME : numeric ? OF_NUMERIC : 0) | OF_JSON | (full ? OF_ALL_ATTRS : 0); - for (deque::iterator it = messages.begin(); it != messages.end();) { - Message* message = *it++; + for (const auto message : messages) { symbol_t dstAddress = message->getDstAddress(); if (dstAddress == SYN) { continue; diff --git a/src/ebusd/mqtthandler.cpp b/src/ebusd/mqtthandler.cpp index ccc76adb..f6ae4ee4 100644 --- a/src/ebusd/mqtthandler.cpp +++ b/src/ebusd/mqtthandler.cpp @@ -205,7 +205,7 @@ bool parseTopic(const string topic, vector &strs, vector &fields return false; } string fieldName = knownFieldNames[idx]; - for (auto& it : fields) { + for (const auto& it : fields) { if (it == fieldName) { return false; // duplicate column } @@ -521,12 +521,11 @@ void MqttHandler::run() { time(&lastTaskRun); } if (m_connected && !m_updatedMessages.empty()) { - for (map::iterator it = m_updatedMessages.begin(); it != m_updatedMessages.end(); it++) { - Message* message = it->first; + for (const auto it : m_updatedMessages) { updates.str(""); updates.clear(); updates << dec; - publishMessage(message, updates); + publishMessage(it.first, updates); } } m_updatedMessages.clear(); diff --git a/src/ebusd/network.cpp b/src/ebusd/network.cpp index 5a42e8bc..348304ec 100644 --- a/src/ebusd/network.cpp +++ b/src/ebusd/network.cpp @@ -291,15 +291,15 @@ void Network::run() { } void Network::cleanConnections() { - list::iterator c_it = m_connections.begin(); - while (c_it != m_connections.end()) { - if (!(*c_it)->isRunning()) { - Connection* connection = *c_it; - c_it = m_connections.erase(c_it); + auto it = m_connections.begin(); + while (it != m_connections.end()) { + if (!(*it)->isRunning()) { + Connection* connection = *it; + it = m_connections.erase(it); delete connection; logDebug(lf_network, "dead connection removed - %d", m_connections.size()); } else { - c_it++; + it++; } } } diff --git a/src/lib/ebus/data.cpp b/src/lib/ebus/data.cpp index 9ccddcf9..d2cade97 100644 --- a/src/lib/ebus/data.cpp +++ b/src/lib/ebus/data.cpp @@ -81,7 +81,7 @@ const string AttributedItem::formatInt(size_t value) { } const string AttributedItem::pluck(map& row, string key) { - map::iterator it = row.find(key); + const auto it = row.find(key); if (it == row.end()) { return ""; } @@ -127,8 +127,8 @@ void AttributedItem::appendJson(ostream& output, const string name, const string } void AttributedItem::mergeAttributes(map& attributes) const { - for (auto& entry : m_attributes) { - auto it = attributes.find(entry.first); + for (const auto& entry : m_attributes) { + const auto it = attributes.find(entry.first); if (it == attributes.end() || it->second.empty()) { attributes[entry.first] = entry.second; } @@ -140,13 +140,13 @@ void AttributedItem::dumpAttribute(ostream& output, const string name, const boo } string AttributedItem::getAttribute(const string name) const { - auto it = m_attributes.find(name); + const auto it = m_attributes.find(name); return it == m_attributes.end() ? "" : it->second; } bool AttributedItem::appendAttribute(ostringstream& output, OutputFormat outputFormat, const string name, const bool onlyIfNonEmpty, const string prefix, const string suffix) const { - auto it = m_attributes.find(name); + const auto it = m_attributes.find(name); string value = it == m_attributes.end() ? "" : it->second; if (onlyIfNonEmpty && value.empty()) { return false; @@ -168,7 +168,7 @@ bool AttributedItem::appendAttributes(ostringstream& output, OutputFormat output ret = appendAttribute(output, outputFormat, "comment", true, "[", "]") || ret; } if (outputFormat & OF_ALL_ATTRS) { - for (auto& entry : m_attributes) { + for (const auto entry : m_attributes) { ret = true; if (!entry.second.empty() && entry.first != "unit" && entry.first != "comment") { if (outputFormat & OF_JSON) { @@ -198,7 +198,7 @@ result_t DataField::create(vector< map >& rows, string& errorDes return RESULT_ERR_EOF; } size_t fieldIndex = -1; - for (auto row : rows) { + for (auto& row : rows) { if (result != RESULT_OK) { break; } @@ -681,7 +681,7 @@ void ValueListDataField::dump(ostream& output) const { output << FIELD_SEPARATOR; if (!m_dataType->dump(output, m_length)) { // no divisor appended bool first = true; - for (auto it : m_values) { + for (const auto it : m_values) { if (first) { first = false; } else { @@ -703,7 +703,7 @@ result_t ValueListDataField::readSymbols(const SymbolString& input, if (result != RESULT_OK) { return result; } - auto it = m_values.find(value); + const auto it = m_values.find(value); if (it == m_values.end() && value != m_dataType->getReplacement()) { // fall back to raw value in input output << setw(0) << dec << static_cast(value); @@ -743,7 +743,7 @@ result_t ValueListDataField::writeSymbols(istringstream& input, } const char* str = input.str().c_str(); - for (auto it : m_values) { + for (const auto it : m_values) { if (it.second.compare(str) == 0) { return numType->writeRawValue(it.first, offset, m_length, output, usedLength); } @@ -775,7 +775,7 @@ result_t ConstantDataField::derive(const string name, map attrib return RESULT_ERR_INVALID_PART; // cannot create a template from a concrete instance } string useName = name.empty() ? m_name : name; - for (auto entry : m_attributes) { // merge with this attributes + for (const auto entry : m_attributes) { // merge with this attributes if (attributes[entry.first].empty()) { attributes[entry.first] = entry.second; } @@ -881,15 +881,15 @@ DataFieldSet* DataFieldSet::getIdentFields() { } DataFieldSet::~DataFieldSet() { - for (auto it : m_fields) { - delete it; + for (const auto field : m_fields) { + delete field; } } const DataFieldSet* DataFieldSet::clone() const { vector fields; - for (auto it : m_fields) { - fields.push_back(it->clone()); + for (const auto field : m_fields) { + fields.push_back(field->clone()); } return new DataFieldSet(m_name, fields); } @@ -898,7 +898,7 @@ size_t DataFieldSet::getLength(PartType partType, size_t maxLength) const { size_t length = 0; bool previousFullByteOffset[] = { true, true, true, true }; - for (auto field : m_fields) { + for (const auto field : m_fields) { if (field->getPartType() == partType) { if (!previousFullByteOffset[partType] && !field->hasFullByteOffset(false)) { length--; @@ -938,8 +938,8 @@ result_t DataFieldSet::derive(const string name, map attributes, if (!values.empty()) { return RESULT_ERR_INVALID_ARG; // value list not allowed in set derive } - for (auto it : m_fields) { - result_t result = it->derive("", attributes, partType, divisor, values, fields); + for (const auto field : m_fields) { + result_t result = field->derive("", attributes, partType, divisor, values, fields); if (result != RESULT_OK) { return result; } @@ -951,7 +951,7 @@ result_t DataFieldSet::derive(const string name, map attributes, } bool DataFieldSet::hasField(const char* fieldName, bool numeric) const { - for (auto field : m_fields) { + for (const auto field : m_fields) { if (field->hasField(fieldName, numeric) == 0) { return true; } @@ -961,13 +961,13 @@ bool DataFieldSet::hasField(const char* fieldName, bool numeric) const { void DataFieldSet::dump(ostream& output) const { bool first = true; - for (auto it : m_fields) { + for (const auto field : m_fields) { if (first) { first = false; } else { output << FIELD_SEPARATOR; } - it->dump(output); + field->dump(output); } } @@ -975,7 +975,7 @@ result_t DataFieldSet::read(const SymbolString& data, size_t offset, unsigned int& output, const char* fieldName, ssize_t fieldIndex) const { bool previousFullByteOffset = true, found = false, findFieldIndex = fieldName != NULL && fieldIndex >= 0; PartType partType = data.isMaster() ? pt_masterData : pt_slaveData; - for (auto field : m_fields) { + for (const auto field : m_fields) { if (field->getPartType() != partType) { continue; } @@ -1017,7 +1017,7 @@ result_t DataFieldSet::read(const SymbolString& data, size_t offset, outputIndex = 0; } PartType partType = data.isMaster() ? pt_masterData : pt_slaveData; - for (auto field : m_fields) { + for (const auto field : m_fields) { if (field->getPartType() != partType) { if (outputIndex >= 0 && !field->isIgnored()) { outputIndex++; @@ -1064,7 +1064,7 @@ result_t DataFieldSet::write(istringstream& input, SymbolString& data, PartType partType = data.isMaster() ? pt_masterData : pt_slaveData; bool previousFullByteOffset = true; size_t baseOffset = offset; - for (auto field : m_fields) { + for (const auto field : m_fields) { if (field->getPartType() != partType) { continue; } @@ -1100,7 +1100,7 @@ result_t DataFieldSet::write(istringstream& input, SymbolString& data, DataFieldTemplates::DataFieldTemplates(DataFieldTemplates& other) : MappedFileReader::MappedFileReader(false) { - for (auto it : other.m_fieldsByName) { + for (const auto it : other.m_fieldsByName) { m_fieldsByName[it.first] = it.second->clone(); } } @@ -1117,7 +1117,7 @@ result_t DataFieldTemplates::add(const DataField* field, string name, bool repla if (name.length() == 0) { name = field->getName(); } - auto it = m_fieldsByName.find(name); + const auto it = m_fieldsByName.find(name); if (it != m_fieldsByName.end()) { if (!replace) { return RESULT_ERR_DUPLICATE_NAME; // duplicate key @@ -1136,7 +1136,7 @@ result_t DataFieldTemplates::getFieldMap(vector& row, string& errorDescr // name[:usename],basetype[:len]|template[:usename][,[divisor|values][,[unit][,[comment]]]] if (row.empty()) { // default map does not include separate field name - for (auto col : defaultTemplateFieldMap) { + for (const auto& col : defaultTemplateFieldMap) { row.push_back(col); } return RESULT_OK; @@ -1252,7 +1252,7 @@ result_t DataFieldTemplates::addFromFile(map& row, vector< map& defaults, const if (value.length() == 0 && replaceStar && required) { return value; } - auto it = defaults.find(fieldName); + const auto it = defaults.find(fieldName); const string defaultStr = it == defaults.end() ? "" : it->second; if (!replaceStar || defaultStr.empty()) { return value.length() > 0 ? value : defaultStr; @@ -186,8 +186,8 @@ uint64_t Message::createKey(const vector id, } key |= (uint64_t)dstAddress << (8 * 6); int exp = 5; - for (vector::const_iterator it = id.begin(); it < id.end(); it++) { - key ^= (uint64_t)*it << (8 * exp--); + for (const auto it : id) { + key ^= (uint64_t)it << (8 * exp--); if (exp == 0) { exp = 3; } @@ -195,7 +195,7 @@ uint64_t Message::createKey(const vector id, return key; } -uint64_t Message::createKey(MasterSymbolString& master, size_t maxIdLength, bool anyDestination) { +uint64_t Message::createKey(const MasterSymbolString& master, size_t maxIdLength, bool anyDestination) { if (master.size() < 5) { return INVALID_KEY; } @@ -473,8 +473,7 @@ result_t Message::create(map row, vector< map > unsigned int index = 0; bool multiple = dstAddresses.size() > 1; char num[10]; - for (vector::iterator it = dstAddresses.begin(); it != dstAddresses.end(); it++, index++) { - symbol_t dstAddress = *it; + for (const auto dstAddress : dstAddresses) { string useCircuit = circuit; if (multiple) { snprintf(num, sizeof(num), ".%d", index); @@ -489,6 +488,7 @@ result_t Message::create(map row, vector< map > index == 0, pollPriority, condition); } messages.push_back(message); + index++; } return RESULT_OK; } @@ -829,7 +829,7 @@ bool Message::isLessPollWeight(const Message* other) const { void Message::dumpHeader(ostream& output, vector* fieldNames) { bool first = true; if (fieldNames == NULL) { - for (auto fieldName : defaultMessageFieldMap) { + for (const auto& fieldName : defaultMessageFieldMap) { if (first) { first = false; } else { @@ -839,7 +839,7 @@ void Message::dumpHeader(ostream& output, vector* fieldNames) { } return; } - for (auto fieldName : *fieldNames) { + for (const auto& fieldName : *fieldNames) { if (first) { first = false; } else { @@ -852,7 +852,7 @@ void Message::dumpHeader(ostream& output, vector* fieldNames) { void Message::dump(ostream& output, vector* fieldNames, bool withConditions) const { bool first = true; if (fieldNames == NULL) { - for (auto fieldName : knownFieldNamesFull) { + for (const auto& fieldName : knownFieldNamesFull) { if (fieldName == FIELNAME_LEVEL) { continue; // access level not included in default dump format } @@ -865,7 +865,7 @@ void Message::dump(ostream& output, vector* fieldNames, bool withConditi } return; } - for (auto fieldName : *fieldNames) { + for (const auto& fieldName : *fieldNames) { if (first) { first = false; } else { @@ -920,13 +920,13 @@ void Message::dumpField(ostream& output, string fieldName, bool withConditions) return; } if (fieldName == "pbsb") { - for (vector::const_iterator it = m_id.begin(); it < m_id.begin()+2 && it < m_id.end(); it++) { + for (auto it = m_id.begin(); it < m_id.begin()+2 && it < m_id.end(); it++) { output << hex << setw(2) << setfill('0') << static_cast(*it); } return; } if (fieldName == "id") { - for (vector::const_iterator it = m_id.begin()+2; it < m_id.end(); it++) { + for (auto it = m_id.begin()+2; it < m_id.end(); it++) { output << hex << setw(2) << setfill('0') << static_cast(*it); } return; @@ -1218,7 +1218,7 @@ void ChainedMessage::dumpField(ostream& output, string fieldName, bool withCondi bool first = true; for (size_t index = 0; index < m_ids.size(); index++) { vector id = m_ids[index]; - for (vector::const_iterator it = id.begin()+2; it < id.end(); it++) { + for (auto it = id.begin()+2; it < id.end(); it++) { if (first) { first = false; } else { @@ -1570,14 +1570,14 @@ bool SimpleStringCondition::checkValue(Message* message, string field) { void CombinedCondition::dump(ostream& output, bool matched) const { - for (auto condition : m_conditions) { + for (const auto condition : m_conditions) { condition->dump(output, matched); } } result_t CombinedCondition::resolve(MessageMap* messages, ostringstream& errorMessage, void (*readMessageFunc)(Message* message)) { - for (auto condition : m_conditions) { + for (const auto condition : m_conditions) { ostringstream dummy; result_t ret = condition->resolve(messages, dummy, readMessageFunc); if (ret != RESULT_OK) { @@ -1589,8 +1589,8 @@ result_t CombinedCondition::resolve(MessageMap* messages, ostringstream& errorMe } bool CombinedCondition::isTrue() { - for (vector::iterator it = m_conditions.begin(); it != m_conditions.end(); it++) { - if (!(*it)->isTrue()) { + for (const auto condition : m_conditions) { + if (!condition->isTrue()) { return false; } } @@ -1616,7 +1616,7 @@ result_t Instruction::create(const string& contextPath, const string type, } string arg = row["file"]; row.erase("file"); - for (auto entry : row) { // fallback to first field + for (const auto entry : row) { // fallback to first field if (!entry.second.empty()) { arg = entry.second; break; @@ -1703,7 +1703,7 @@ result_t MessageMap::add(Message* message, bool storeByName) { uint64_t key = message->getKey(); bool conditional = message->isConditional(); if (!m_addAll) { - map >::iterator keyIt = m_messagesByKey.find(key); + const auto keyIt = m_messagesByKey.find(key); if (keyIt != m_messagesByKey.end()) { Message* other = getFirstAvailable(keyIt->second, message); if (other != NULL) { @@ -1729,7 +1729,7 @@ result_t MessageMap::add(Message* message, bool storeByName) { string suffix = FIELD_SEPARATOR + name + (isPassive ? "P" : (isWrite ? "W" : "R")); string nameKey = circuit + suffix; if (!m_addAll) { - map >::iterator nameIt = m_messagesByName.find(nameKey); + const auto nameIt = m_messagesByName.find(nameKey); if (nameIt != m_messagesByName.end()) { vector* messages = &nameIt->second; if (!message->isConditional() || !messages->front()->isConditional()) { @@ -1739,7 +1739,7 @@ result_t MessageMap::add(Message* message, bool storeByName) { } m_messagesByName[nameKey].push_back(message); nameKey = suffix; // also store without circuit - map >::iterator nameIt = m_messagesByName.find(nameKey); + const auto nameIt = m_messagesByName.find(nameKey); if (nameIt == m_messagesByName.end()) { // always store first message without circuit (in order of circuit name) m_messagesByName[nameKey].push_back(message); @@ -1779,7 +1779,7 @@ result_t MessageMap::getFieldMap(vector& row, string& errorDescription, // unit,comment // minimum: type,name,PBSB,field,datatype if (row.empty()) { - for (auto col : defaultMessageFieldMap) { + for (const auto& col : defaultMessageFieldMap) { row.push_back(col); } return RESULT_OK; @@ -1881,7 +1881,7 @@ result_t MessageMap::addDefaultFromFile(map& row, vector< map defaults; if (mainDefaults != getDefaults().end()) { defaults = mainDefaults->second; @@ -1894,7 +1894,7 @@ result_t MessageMap::addDefaultFromFile(map& row, vector< map::iterator it = m_conditions.find(key); + const auto it = m_conditions.find(key); if (it != m_conditions.end()) { errorDescription = "condition "+type+" already defined"; return RESULT_ERR_DUPLICATE_NAME; @@ -1918,7 +1918,7 @@ result_t MessageMap::addDefaultFromFile(map& row, vector< map 0 && types[0] == '[' && (pos=types.find_last_of(']')) != string::npos) { // check if combined or simple condition is already known const string combinedkey = filename+":"+types.substr(1, pos-1); - auto it = m_conditions.find(combinedkey); + const auto it = m_conditions.find(combinedkey); if (it != m_conditions.end()) { condition = it->second; types = types.substr(pos+1); @@ -1973,7 +1973,7 @@ result_t MessageMap::readConditions(string& types, const string filename, string while ((pos=types.find(']')) != string::npos) { // simple condition string key = filename+":"+types.substr(1, pos-1); - map::iterator it = m_conditions.find(key); + auto it = m_conditions.find(key); Condition* add = NULL; if (it == m_conditions.end()) { // check for on-the-fly condition @@ -2135,7 +2135,7 @@ result_t MessageMap::addFromFile(map& row, vector< map >::iterator it = m_instructions.find(filename); + const auto it = m_instructions.find(filename); if (it == m_instructions.end()) { vector instructions; instructions.push_back(instruction); @@ -2162,8 +2162,7 @@ result_t MessageMap::addFromFile(map& row, vector< map::iterator it = messages.begin(); it != messages.end(); it++) { - Message* message = *it; + for (const auto message : messages) { if (result == RESULT_OK) { result = add(message); if (result == RESULT_ERR_DUPLICATE_NAME) { @@ -2205,8 +2204,8 @@ Message* MessageMap::getScanMessage(const symbol_t dstAddress) { result_t MessageMap::resolveConditions(string& errorDescription, bool verbose) { result_t overallResult = RESULT_OK; - for (map::iterator it = m_conditions.begin(); it != m_conditions.end(); it++) { - Condition* condition = it->second; + for (const auto it : m_conditions) { + Condition* condition = it.second; result_t result = resolveCondition(condition, errorDescription); if (result != RESULT_OK) { overallResult = result; @@ -2234,11 +2233,11 @@ result_t MessageMap::resolveCondition(Condition* condition, string& errorDescrip result_t MessageMap::executeInstructions(ostringstream& log, void (*readMessageFunc)(Message* message)) { result_t overallResult = RESULT_OK; vector remove; - for (auto& it : m_instructions) { + for (auto it : m_instructions) { auto& instructions = it.second; bool removeSingletons = false; vector remain; - for (auto instruction : instructions) { + for (const auto instruction : instructions) { if (removeSingletons && instruction->isSingleton()) { delete instruction; continue; @@ -2276,8 +2275,7 @@ result_t MessageMap::executeInstructions(ostringstream& log, void (*readMessageF if (removeSingletons && !remain.empty()) { instructions = remain; remain.clear(); - for (vector::iterator lit = instructions.begin(); lit != instructions.end(); lit++) { - Instruction* instruction = *lit; + for (const auto instruction : instructions) { if (!instruction->isSingleton()) { remain.push_back(instruction); continue; @@ -2291,7 +2289,7 @@ result_t MessageMap::executeInstructions(ostringstream& log, void (*readMessageF it.second = remain; } } - for (auto it : remove) { + for (const auto it : remove) { m_instructions.erase(it); } return overallResult; @@ -2309,23 +2307,23 @@ void MessageMap::addLoadedFile(const symbol_t address, const string filename, st } const vector& MessageMap::getLoadedFiles(const symbol_t address) const { - auto files = m_loadedFiles.find(address); - if (files != m_loadedFiles.end()) { - return files->second; + const auto it = m_loadedFiles.find(address); + if (it != m_loadedFiles.end()) { + return it->second; } return s_noFiles; } vector MessageMap::getLoadedFiles() const { vector ret; - for (auto& loadedFile : m_loadedFileInfos) { + for (const auto& loadedFile : m_loadedFileInfos) { ret.push_back(loadedFile.first); } return ret; } -bool MessageMap::getLoadedFileInfo(string filename, string& comment, size_t* hash, size_t* size, time_t* time) const { - auto it = m_loadedFileInfos.find(filename); +bool MessageMap::getLoadedFileInfo(const string filename, string& comment, size_t* hash, size_t* size, time_t* time) const { + const auto it = m_loadedFileInfos.find(filename); if (it == m_loadedFileInfos.end()) { comment = ""; hash = size = 0; @@ -2346,7 +2344,7 @@ bool MessageMap::getLoadedFileInfo(string filename, string& comment, size_t* has } const vector* MessageMap::getByKey(const uint64_t key) const { - auto it = m_messagesByKey.find(key); + const auto it = m_messagesByKey.find(key); if (it != m_messagesByKey.end()) { return &it->second; } @@ -2369,7 +2367,7 @@ Message* MessageMap::find(const string& circuit, const string& name, const strin } else { continue; // not allowed without circuit } - auto it = m_messagesByName.find(nameKey); + const auto it = m_messagesByName.find(nameKey); if (it != m_messagesByName.end()) { Message* message = getFirstAvailable(it->second); if (message && message->hasLevel(levels)) { @@ -2392,11 +2390,11 @@ deque MessageMap::findAll(const string& circuit, const string& name, c bool checkCircuit = lcircuit.length() > 0; bool checkLevel = levels != "*"; bool checkName = lname.length() > 0; - for (auto it : m_messagesByName) { + for (const auto it : m_messagesByName) { if (it.first[0] == FIELD_SEPARATOR) { // avoid duplicates: instances stored multiple times have a special key continue; } - for (auto message : it.second) { + for (const auto message : it.second) { if (checkLevel && !message->hasLevel(levels, includeEmptyLevel)) { continue; } @@ -2446,7 +2444,7 @@ deque MessageMap::findAll(const string& circuit, const string& name, c return ret; } -Message* MessageMap::find(MasterSymbolString& master, const bool anyDestination, +Message* MessageMap::find(const MasterSymbolString& master, const bool anyDestination, const bool withRead, const bool withWrite, const bool withPassive, const bool onlyAvailable) const { if (anyDestination && master.size() >= 5 && master[4] == 0 && master[2] == 0x07 && master[3] == 0x04) { return m_scanMessage; @@ -2527,8 +2525,7 @@ void MessageMap::invalidateCache(Message* message) { string circuit = message->getCircuit(); string name = message->getName(); deque messages = findAll(circuit, name, "*", true, true, true, true); - for (deque::iterator it = messages.begin(); it != messages.end(); it++) { - Message* checkMessage = *it; + for (auto checkMessage : messages) { if (checkMessage != message) { checkMessage->m_lastUpdateTime = 0; } @@ -2543,7 +2540,7 @@ void MessageMap::addPollMessage(Message* message, bool toFront) { } bool MessageMap::decodeCircuit(const string circuit, ostringstream& output, OutputFormat outputFormat) const { - auto it = m_circuitData.find(circuit); + const auto it = m_circuitData.find(circuit); if (it == m_circuitData.end()) { return false; } @@ -2570,13 +2567,16 @@ void MessageMap::clear() { continue; } for (Message* message : it.second) { - map >::iterator keyIt = m_messagesByKey.find(message->getKey()); + const auto keyIt = m_messagesByKey.find(message->getKey()); if (keyIt != m_messagesByKey.end()) { vector* keyMessages = &keyIt->second; if (!keyMessages->empty()) { - for (vector::iterator kit = keyMessages->begin(); kit != keyMessages->end(); kit++) { + auto kit = keyMessages->begin(); + while (kit != keyMessages->end()) { if (*kit == message) { - keyMessages->erase(kit--); + kit = keyMessages->erase(kit); + } else { + kit++; } } } @@ -2586,23 +2586,21 @@ void MessageMap::clear() { it.second.clear(); } // free remaining message instances by key - for (map >::iterator it = m_messagesByKey.begin(); it != m_messagesByKey.end(); it++) { - vector keyMessages = it->second; - for (vector::iterator kit = keyMessages.begin(); kit != keyMessages.end(); kit++) { - Message* message = *kit; + for (const auto it : m_messagesByKey) { + vector keyMessages = it.second; + for (auto message : keyMessages) { delete message; } keyMessages.clear(); } // free condition instances - for (map::iterator it = m_conditions.begin(); it != m_conditions.end(); it++) { - delete it->second; + for (const auto it : m_conditions) { + delete it.second; } // free instruction instances - for (map >::iterator it = m_instructions.begin(); it != m_instructions.end(); it++) { - vector instructions = it->second; - for (vector::iterator lit = instructions.begin(); lit != instructions.end(); lit++) { - Instruction* instruction = *lit; + for (const auto it : m_instructions) { + vector instructions = it.second; + for (const auto instruction : instructions) { delete instruction; } instructions.clear(); @@ -2616,7 +2614,7 @@ void MessageMap::clear() { m_messagesByKey.clear(); m_conditions.clear(); m_instructions.clear(); - for (auto& it : m_circuitData) { + for (const auto it : m_circuitData) { delete it.second; } m_circuitData.clear(); @@ -2640,12 +2638,12 @@ void MessageMap::dump(ostream& output, bool withConditions) const { bool first = true; Message::dumpHeader(output, NULL); output << endl; - for (auto it : m_messagesByName) { + for (const auto it : m_messagesByName) { if (it.first[0] == '-') { // skip instances stored multiple times (key starting with "-") continue; } if (m_addAll) { - for (auto message : it.second) { + for (const auto message : it.second) { if (!message) { continue; } diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index b2cb9168..8d44faf1 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -145,8 +145,7 @@ class Message : public AttributedItem { * @param anyDestination @p true to use the special @a SYN as destination address in the key. * @return the key for the ID, or -1LL if the data is invalid. */ - static uint64_t createKey(MasterSymbolString& master, - size_t maxIdLength, bool anyDestination = false); + static uint64_t createKey(const MasterSymbolString& master, size_t maxIdLength, bool anyDestination = false); /** * Calculate the key for a scan message. @@ -1355,7 +1354,7 @@ class MessageMap : public MappedFileReader { * @param time optional pointer to a @a time_t value for storing the modification time of the file, or NULL. * @return true if the file info was found, false otherwise. */ - bool getLoadedFileInfo(string filename, string& comment, size_t* hash = NULL, size_t* size = NULL, + bool getLoadedFileInfo(const string filename, string& comment, size_t* hash = NULL, size_t* size = NULL, time_t* time = NULL) const; /** @@ -1417,7 +1416,7 @@ class MessageMap : public MappedFileReader { * @return the @a Message instance, or NULL. * Note: the caller may not free the returned instance. */ - Message* find(MasterSymbolString& master, const bool anyDestination = false, const bool withRead = true, + Message* find(const MasterSymbolString& master, const bool anyDestination = false, const bool withRead = true, const bool withWrite = true, const bool withPassive = true, const bool onlyAvailable = true) const; /** From 43042eec9d58a9bf892fbc8b7429de9780c6f3c9 Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 23 Apr 2017 11:58:54 +0200 Subject: [PATCH 4/7] style --- src/ebusd/mainloop.cpp | 2 +- src/lib/ebus/message.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index 0c0d2ace..0a9f7ac0 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -457,7 +457,7 @@ void MainLoop::notifyDeviceData(const symbol_t symbol, bool received) { } if (symbol != SYN) { if (received && !m_logRawLastReceived && symbol == m_logRawLastSymbol) { - return; // skip received echo of previously sent symbol + return; // skip received echo of previously sent symbol } if (m_logRawBuffer.tellp() == 0 || received != m_logRawLastReceived) { m_logRawLastReceived = received; diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index f4d06b21..0db7540e 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -2322,7 +2322,8 @@ vector MessageMap::getLoadedFiles() const { return ret; } -bool MessageMap::getLoadedFileInfo(const string filename, string& comment, size_t* hash, size_t* size, time_t* time) const { +bool MessageMap::getLoadedFileInfo(const string filename, string& comment, size_t* hash, size_t* size, time_t* time) + const { const auto it = m_loadedFileInfos.find(filename); if (it == m_loadedFileInfos.end()) { comment = ""; From e6b6e17db32247687854cacc6d6525f343b89aa9 Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 23 Apr 2017 12:08:35 +0200 Subject: [PATCH 5/7] allow logging raw bytes via command line again --- src/ebusd/main.cpp | 7 ++++--- src/ebusd/main.h | 2 +- src/ebusd/mainloop.cpp | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ebusd/main.cpp b/src/ebusd/main.cpp index 622050d6..de0282b9 100644 --- a/src/ebusd/main.cpp +++ b/src/ebusd/main.cpp @@ -116,7 +116,7 @@ static struct options opt = { ll_COUNT, // logLevel false, // multiLog - false, // logRaw + 0, // logRaw PACKAGE_LOGFILE, // logRawFile 100, // logRawSize @@ -216,7 +216,8 @@ static const struct argp_option argpoptions[] = { " [notice]", 0 }, {NULL, 0, NULL, 0, "Raw logging options:", 6 }, - {"lograwdata", O_RAW, NULL, 0, "Log each received/sent byte on the bus", 0 }, + {"lograwdata", O_RAW, "bytes", OPTION_ARG_OPTIONAL, + "Log messages or all received/sent bytes on the bus", 0 }, {"lograwdatafile", O_RAWFIL, "FILE", 0, "Write raw log to FILE [" PACKAGE_LOGFILE "]", 0 }, {"lograwdatasize", O_RAWSIZ, "SIZE", 0, "Make raw log file no larger than SIZE kB [100]", 0 }, @@ -504,7 +505,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) { // Raw logging options: case O_RAW: // --lograwdata - opt->logRaw = true; + opt->logRaw = arg && strcmp("bytes", arg) == 0 ? 2 : 1; break; case O_RAWFIL: // --lograwdatafile=/var/log/ebusd.log if (arg == NULL || arg[0] == 0 || strcmp("/", arg) == 0) { diff --git a/src/ebusd/main.h b/src/ebusd/main.h index 8f9af581..7bbdb0f9 100644 --- a/src/ebusd/main.h +++ b/src/ebusd/main.h @@ -74,7 +74,7 @@ struct options { LogLevel logLevel; //!< log level [notice] bool multiLog; //!< multiple log levels adjusted with --log=... - bool logRaw; //!< raw log each received/sent byte on the bus + unsigned int logRaw; //!< raw log each received/sent byte on the bus (1=messages, 2=bytes) const char* logRawFile; //!< name of raw log file [/var/log/ebusd.log] unsigned int logRawSize; //!< maximum size of raw log file in kB [100] diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index 0a9f7ac0..394b35ed 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -119,8 +119,8 @@ MainLoop::MainLoop(const struct options opt, Device *device, MessageMap* message } else { m_logRawFile = NULL; } - m_logRawEnabled = opt.logRaw; - m_logRawBytes = false; + m_logRawEnabled = opt.logRaw != 0; + m_logRawBytes = opt.logRaw == 2; m_logRawLastReceived = true; m_logRawLastSymbol = SYN; if (opt.aclFile[0]) { From ffc1d093c52471ebf7218486884b5c1cc30e6269 Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 23 Apr 2017 12:20:16 +0200 Subject: [PATCH 6/7] updated to latest changes --- ChangeLog.md | 3 +++ README.md | 16 +++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 50c52075..cd83146d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -7,6 +7,7 @@ * added automatic check for updates (ebusd and configuration) * use CSV header line for determining columns and picking multi-language columns by language preference * a circuit name is now required for all message configurations +* raw logging allows logging of messages or each sent/received byte defaulting to messages ## Bug Fixes * corrected numeric condition formatting @@ -22,6 +23,7 @@ * corrected missing update notification on master message part * corrected grouping of JSON output by circuit * corrected address conflict detection when in answer mode +* fixed potential memory leaks and misused iterator ## Features * added support for MQTT handling via libmosquitto (will be compiled in when library is available) @@ -46,6 +48,7 @@ * allow TTQ/TTH types to use less than 8 bits * added support for optional user-defined columns to config files * added circuit-level attributes to config files for use in JSON +* added -N option to "read" command # 2.4 (2016-12-17) diff --git a/README.md b/README.md index 3c5f2486..9c276824 100644 --- a/README.md +++ b/README.md @@ -20,16 +20,18 @@ The main features of the daemon are: * regularly poll for messages * cache all messages * scan for bus participants - * parse messages to human readable values by using CSV message configuration files - * automatically pick CSV message configuration files by scan result + * parse messages to human readable values and vice versa via message configuration files + * automatically pick message configuration files by scan result + * automatically check for updates of daemon and configuration files + * pick preferred language for translatable message configuration parts * grab all messages on the eBUS and provide decoding hints * log messages and problems to a log file - * capture sent/received bytes to a log file as text + * capture messages or sent/received bytes to a log file as text * dump received bytes to binary files for later playback/analysis - * listen for client connections on a dedicated TCP port (command line style and/or HTTP) - * optionally format messages and data in JSON on dedicated HTTP port + * listen for command line client connections on a dedicated TCP port + * optionally provide rudimentary HTML interface and allow data retrieval as JSON on HTTP port * optionally publish received message data to MQTT topics and vice versa (if authorized) - * optional ACL and required user authentication for access to certain messages + * optional user authentication via ACL file for access to certain messages Installation @@ -70,7 +72,7 @@ Check the Wiki and/or the configuration repository: Docker image ------------ -A Docker image is available on the hub and it contains the latest German configuration files. +A Docker image including the latest message configuration files is available on the hub. You can use it like this: > docker pull john30/ebusd > docker run -it --rm --device=/dev/ttyUSB0 -p 8888 john30/ebusd From e5aa25dd68bcf1641de6ec5eed1a35fbda208c59 Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 23 Apr 2017 12:37:49 +0200 Subject: [PATCH 7/7] added raw bytes command --- test_coverage.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test_coverage.sh b/test_coverage.sh index 851c20c8..e55f726a 100755 --- a/test_coverage.sh +++ b/test_coverage.sh @@ -209,7 +209,7 @@ echo "ebusd: $pid" kill -1 $pid #client: readarray lines <