diff --git a/src/ebusd/bushandler.cpp b/src/ebusd/bushandler.cpp index fb27ad88..dce9872d 100644 --- a/src/ebusd/bushandler.cpp +++ b/src/ebusd/bushandler.cpp @@ -269,7 +269,7 @@ bool GrabbedMessage::dump(bool unknown, MessageMap* messages, bool first, bool d if (dstAddress != BROADCAST && !isMaster(dstAddress)) { *output << " / " << m_lastSlave.getStr(); } - *output << " = " << static_cast(m_count); + *output << " = " << m_count; if (message) { *output << ": " << message->getCircuit() << " " << message->getName(); } @@ -1107,7 +1107,7 @@ void BusHandler::receiveCompleted() { } else { logNotice(lf_update, "unknown MS cmd: %s / %s", m_command.getStr().c_str(), m_response.getStr().c_str()); if (m_command.size() >= 5 && m_command[2] == 0x07 && m_command[3] == 0x04) { - Message* message = m_messages->getScanMessage(dstAddress); + message = m_messages->getScanMessage(dstAddress); if (message && (message->getLastUpdateTime() == 0 || message->getLastSlaveData().getDataSize() < 10)) { result_t result = message->storeLastData(m_command, m_response); if (result == RESULT_OK) { @@ -1314,7 +1314,7 @@ void BusHandler::formatSeenInfo(ostringstream* output) const { master = getMasterAddress(address); } if (master != SYN) { - *output << " #" << setw(0) << dec << static_cast(getMasterNumber(master)); + *output << " #" << setw(0) << dec << getMasterNumber(master); } if (ownAddress) { *output << ", ebusd"; diff --git a/src/ebusd/main.cpp b/src/ebusd/main.cpp index 7864b882..94572072 100644 --- a/src/ebusd/main.cpp +++ b/src/ebusd/main.cpp @@ -1009,7 +1009,6 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, bool verbose best = name; bestDefaults = defaults; } - break; } if (best.empty()) { @@ -1031,7 +1030,7 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, bool verbose } if (baseName.length() < 3 || baseName.find_first_of('.') != 2) { // different from the scheme "ZZ." string errorDescription; - result = messages->readFromFile(name, opt.checkConfig, NULL, &errorDescription, NULL, NULL, NULL); + result = messages->readFromFile(name, verbose, NULL, &errorDescription, NULL, NULL, NULL); if (result == RESULT_OK) { logNotice(lf_main, "read common config file %s", name.c_str()); } else { @@ -1044,7 +1043,7 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, bool verbose } string errorDescription; bestDefaults["name"] = ident; - result = messages->readFromFile(best, opt.checkConfig, &bestDefaults, &errorDescription, NULL, NULL, NULL); + result = messages->readFromFile(best, verbose, &bestDefaults, &errorDescription, NULL, NULL, NULL); if (result != RESULT_OK) { logError(lf_main, "error reading scan config file %s for ID \"%s\", SW%4.4d, HW%4.4d: %s, %s", best.c_str(), ident.c_str(), sw, hw, getResultCode(result), errorDescription.c_str()); diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index 528322ac..4966456a 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -125,7 +125,7 @@ MainLoop::MainLoop(const struct options& opt, Device *device, MessageMap* messag m_logRawLastSymbol = SYN; if (opt.aclFile[0]) { string errorDescription; - result_t result = m_userList.readFromFile(opt.aclFile, false, NULL, &errorDescription, NULL, NULL, NULL); + result = m_userList.readFromFile(opt.aclFile, false, NULL, &errorDescription, NULL, NULL, NULL); if (result != RESULT_OK) { logError(lf_main, "error reading ACL file \"%s\": %s", opt.aclFile, getResultCode(result)); } @@ -236,7 +236,7 @@ void MainLoop::run() { bool loadDelay = false; if (m_initialScan != ESC && reload && m_busHandler->hasSignal()) { loadDelay = true; - result_t result = RESULT_ERR_NO_SIGNAL; + result_t result; if (m_initialScan == SYN) { logNotice(lf_main, "starting initial full scan"); result = m_busHandler->startScan(true, "*"); @@ -449,14 +449,14 @@ void MainLoop::run() { void MainLoop::notifyDeviceData(symbol_t symbol, bool received) { if (received && m_dumpFile) { - m_dumpFile->write((unsigned char*)&symbol, 1); + m_dumpFile->write(&symbol, 1); } if (!m_logRawFile && !m_logRawEnabled) { return; } if (m_logRawBytes) { if (m_logRawFile) { - m_logRawFile->write((unsigned char*)&symbol, 1, received); + m_logRawFile->write(&symbol, 1, received); } else if (m_logRawEnabled) { if (received) { logNotice(lf_bus, "<%02x", symbol); @@ -1607,7 +1607,7 @@ string MainLoop::executeGet(const vector& args, bool* connected) { string user = ""; if (args.size() > argPos) { string secret; - string query = args[argPos++]; + string query = args[argPos]; istringstream stream(query); string token; while (getline(stream, token, '&')) { @@ -1679,7 +1679,6 @@ string MainLoop::executeGet(const vector& args, bool* connected) { if (m_busHandler->readFromBus(message, "") != RESULT_OK) { continue; } - lastup = message->getLastUpdateTime(); } else { if (since > 0 && lastup <= since) { continue; @@ -1699,7 +1698,7 @@ string MainLoop::executeGet(const vector& args, bool* connected) { first = false; } } - message->decode(!first, NULL, verbosity, &result); + message->decode(!first, verbosity, &result); first = false; } diff --git a/src/ebusd/network.cpp b/src/ebusd/network.cpp index 5e3de66b..56795f20 100644 --- a/src/ebusd/network.cpp +++ b/src/ebusd/network.cpp @@ -80,7 +80,7 @@ void Connection::run() { int sockFD = m_socket->getFD(); #ifdef HAVE_PPOLL - int nfds = 2; + nfds_t nfds = 2; struct pollfd fds[nfds]; memset(fds, 0, sizeof(fds)); @@ -234,7 +234,7 @@ void Network::run() { tdiff.tv_nsec = 0; #ifdef HAVE_PPOLL int socketCount = m_httpServer ? 2 : 1; - int nfds = 1+socketCount; + nfds_t nfds = 1+socketCount; struct pollfd fds[nfds]; memset(fds, 0, sizeof(fds)); diff --git a/src/lib/ebus/contrib/tem.cpp b/src/lib/ebus/contrib/tem.cpp index a810c6cb..ffe06ba8 100644 --- a/src/lib/ebus/contrib/tem.cpp +++ b/src/lib/ebus/contrib/tem.cpp @@ -81,7 +81,7 @@ result_t TemParamDataType::readSymbols(size_t offset, size_t length, const Symbo if (outputFormat & OF_JSON) { *output << '"'; } - *output << setfill('0') << setw(2) << dec << static_cast(grp) << '-' << setw(3) << static_cast(num); + *output << setfill('0') << setw(2) << dec << grp << '-' << setw(3) << num; if (outputFormat & OF_JSON) { *output << '"'; } @@ -92,7 +92,7 @@ result_t TemParamDataType::readSymbols(size_t offset, size_t length, const Symbo result_t TemParamDataType::writeSymbols(const size_t offset, const size_t length, istringstream* input, SymbolString* output, size_t* usedLength) const { unsigned int value; - int grp, num; + unsigned int grp, num; if (input->str() == NULL_VALUE) { value = m_replacement; // replacement value @@ -122,7 +122,7 @@ result_t TemParamDataType::writeSymbols(const size_t offset, const size_t length if (strEnd == NULL || strEnd == str || *strEnd != 0) { return RESULT_ERR_INVALID_NUM; // invalid value } - if (grp < 0 || grp > 0x1f || num < 0 || num > 0x7f) { + if (grp > 0x1f || num > 0x7f) { return RESULT_ERR_OUT_OF_RANGE; // value out of range } if (output->isMaster()) { diff --git a/src/lib/ebus/data.cpp b/src/lib/ebus/data.cpp index f71665b2..8ea037ae 100644 --- a/src/lib/ebus/data.cpp +++ b/src/lib/ebus/data.cpp @@ -193,12 +193,11 @@ result_t DataField::create(bool isWriteMessage, bool isTemplate, bool isBroadcas *errorDescription = "no fields"; return RESULT_ERR_EOF; } - size_t fieldIndex = -1; + size_t fieldIndex = 0; for (auto& row : *rows) { if (result != RESULT_OK) { break; } - fieldIndex++; const string name = pluck("name", &row); PartType partType; bool hasPart = false; @@ -377,6 +376,7 @@ result_t DataField::create(bool isWriteMessage, bool isTemplate, bool isBroadcas } firstType = false; } + fieldIndex++; } if (result != RESULT_OK) { @@ -686,7 +686,7 @@ void ValueListDataField::dump(ostream* output) const { } else { *output << VALUE_SEPARATOR; } - *output << static_cast(it.first) << "=" << it.second; + *output << it.first << "=" << it.second; } } // else: impossible since divisor is not allowed for ValueListDataField dumpSuffix(output); @@ -703,7 +703,7 @@ result_t ValueListDataField::readSymbols(const SymbolString& input, size_t offse 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); + *output << setw(0) << dec << value; return RESULT_OK; } if (it == m_values.end()) { @@ -713,17 +713,17 @@ result_t ValueListDataField::readSymbols(const SymbolString& input, size_t offse *output << NULL_VALUE; } } else if (outputFormat & OF_NUMERIC) { - *output << setw(0) << dec << static_cast(value); + *output << setw(0) << dec << value; } else if (outputFormat & OF_JSON) { if (outputFormat & OF_VALUENAME) { - *output << "{\"value\":" << setw(0) << dec << static_cast(value); + *output << "{\"value\":" << setw(0) << dec << value; *output << ",\"name\":\"" << it->second << "\"}"; } else { *output << '"' << it->second << '"'; } } else { if (outputFormat & OF_VALUENAME) { - *output << setw(0) << dec << static_cast(value) << '='; + *output << setw(0) << dec << value << '='; } *output << it->second; } diff --git a/src/lib/ebus/datatype.cpp b/src/lib/ebus/datatype.cpp index 7760a143..a123fdea 100644 --- a/src/lib/ebus/datatype.cpp +++ b/src/lib/ebus/datatype.cpp @@ -286,15 +286,15 @@ result_t DateTimeDataType::readSymbols(size_t offset, size_t length, const Symbo last = symbol; continue; } - int minutes = symbol*256 + last; + unsigned int minutes = symbol*256 + last; if (minutes > 24*60) { return RESULT_ERR_OUT_OF_RANGE; // invalid value } - int hour = minutes / 60; - if (hour > 24) { + unsigned int minutesHour = minutes / 60; + if (minutesHour > 24) { return RESULT_ERR_OUT_OF_RANGE; // invalid hour } - *output << setw(2) << dec << setfill('0') << static_cast(hour); + *output << setw(2) << dec << setfill('0') << minutesHour; symbol = (symbol_t)(minutes % 60); } else if (length == 1) { // truncated time if (m_bitCount < 8) { @@ -513,11 +513,11 @@ bool NumberDataType::dump(size_t length, bool appendSeparatorDivisor, ostream* o } if (m_baseType) { if (m_baseType->m_divisor != m_divisor) { - *output << static_cast(m_divisor / m_baseType->m_divisor); + *output << (m_divisor / m_baseType->m_divisor); return true; } } else if (m_divisor != 1) { - *output << static_cast(m_divisor); + *output << m_divisor; return true; } return false; @@ -699,7 +699,7 @@ result_t NumberDataType::readSymbols(size_t offset, size_t length, const SymbolS if (m_divisor < 0) { *output << (static_cast(value) * static_cast(-m_divisor)); } else if (m_divisor <= 1) { - *output << static_cast(value); + *output << value; } else { *output << setprecision(static_cast(m_precision)) << fixed << (static_cast(value) / static_cast(m_divisor)); @@ -719,12 +719,12 @@ result_t NumberDataType::readSymbols(size_t offset, size_t length, const SymbolS if (hasFlag(FIX) && hasFlag(BCD)) { if (outputFormat & OF_JSON) { *output << '"' << setw(static_cast(length * 2)) - << setfill('0') << static_cast(signedValue) << setw(0) << '"'; + << setfill('0') << signedValue << setw(0) << '"'; return RESULT_OK; } *output << setw(static_cast(length * 2)) << setfill('0'); } - *output << static_cast(signedValue) << setw(0); + *output << signedValue << setw(0); } else { *output << setprecision(static_cast(m_precision)) << fixed << (static_cast(signedValue) / static_cast(m_divisor)); @@ -842,7 +842,6 @@ result_t NumberDataType::writeSymbols(size_t offset, size_t length, istringstrea return RESULT_ERR_INVALID_NUM; // invalid value } } else { - char* strEnd = NULL; double dvalue = strtod(str, &strEnd); if (strEnd == NULL || strEnd == str || *strEnd != 0) { return RESULT_ERR_INVALID_NUM; // invalid value diff --git a/src/lib/ebus/device.cpp b/src/lib/ebus/device.cpp index 491d5f8b..8d78cfe9 100644 --- a/src/lib/ebus/device.cpp +++ b/src/lib/ebus/device.cpp @@ -124,7 +124,7 @@ result_t Device::recv(unsigned int timeout, symbol_t* value) { tdiff.tv_nsec = (timeout%1000000)*1000; #ifdef HAVE_PPOLL - int nfds = 1; + nfds_t nfds = 1; struct pollfd fds[nfds]; memset(fds, 0, sizeof(fds)); diff --git a/src/lib/ebus/filereader.cpp b/src/lib/ebus/filereader.cpp index 5ebe8c65..0129dded 100644 --- a/src/lib/ebus/filereader.cpp +++ b/src/lib/ebus/filereader.cpp @@ -208,7 +208,7 @@ result_t FileReader::formatError(const string& filename, unsigned int lineNo, re if (!errorDescription->empty()) { str << *errorDescription << ", "; } - str << filename << ":" << static_cast(lineNo) << ": " << getResultCode(result); + str << filename << ":" << lineNo << ": " << getResultCode(result); if (!error.empty()) { str << ", " << error; } diff --git a/src/lib/ebus/filereader.h b/src/lib/ebus/filereader.h index 77028a25..433eb68d 100644 --- a/src/lib/ebus/filereader.h +++ b/src/lib/ebus/filereader.h @@ -153,7 +153,6 @@ class FileReader { * Format the error description with the input data. * @param filename the name of the file. * @param lineNo the line number in the file. - * @param row the definition row. * @param result the result code. * @param error the error message. * @param errorDescription a string in which to store the error description. diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index e54bb391..084f3668 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -419,7 +419,7 @@ result_t Message::create(const string& filename, const DataFieldTemplates* templ maxLength = 0; } else if (chainPrefixLength > 2) { vector& front = chainIds.front(); - for (size_t pos = 2; pos < chainPrefixLength; pos++) { + for (pos = 2; pos < chainPrefixLength; pos++) { if (chainId[pos] != front[pos]) { chainPrefixLength = pos; break; @@ -812,10 +812,7 @@ bool Message::isLessPollWeight(const Message* other) const { if (tprio < oprio) { return false; } - if (m_lastPollTime > other->m_lastPollTime) { - return true; - } - return false; + return m_lastPollTime > other->m_lastPollTime; } void Message::dumpHeader(const vector* fieldNames, ostream* output) { @@ -930,8 +927,7 @@ void Message::dumpField(const string& fieldName, bool withConditions, ostream* o dumpAttribute(false, fieldName, output); } -void Message::decode(bool leadingSeparator, const vector* fields, - OutputFormat outputFormat, ostringstream* output) const { +void Message::decode(bool leadingSeparator, OutputFormat outputFormat, ostringstream* output) const { if (leadingSeparator) { *output << ","; } @@ -1541,9 +1537,7 @@ bool SimpleNumericCondition::checkValue(const Message* message, const string& fi if (result == RESULT_OK) { for (size_t i = 0; i+1 < m_valueRanges.size(); i+=2) { if (m_valueRanges[i] <= value && value <= m_valueRanges[i+1]) { - ostringstream out; - out << static_cast(value); - m_matchedValue = out.str(); + m_matchedValue = AttributedItem::formatInt(value); return true; } } @@ -1976,14 +1970,14 @@ result_t MessageMap::readConditions(const string& filename, string* types, strin Condition* add = NULL; if (it == m_conditions.end()) { // check for on-the-fly condition - size_t pos = key.find_first_of("=<>", filename.length()+1); - if (pos != string::npos) { - it = m_conditions.find(key.substr(0, pos)); + size_t sep = key.find_first_of("=<>", filename.length()+1); + if (sep != string::npos) { + it = m_conditions.find(key.substr(0, sep)); if (it != m_conditions.end()) { // derive from another condition - add = it->second->derive(key.substr(pos)); + add = it->second->derive(key.substr(sep)); if (add == NULL) { - *errorDescription = "derive condition with values "+key.substr(pos)+" failed"; + *errorDescription = "derive condition with values "+key.substr(sep)+" failed"; return RESULT_ERR_INVALID_ARG; } m_conditions[key] = add; // store derived condition @@ -2128,7 +2122,7 @@ result_t MessageMap::addFromFile(const string& filename, unsigned int lineNo, ma } types = types.substr(1); Instruction* instruction = NULL; - result_t result = Instruction::create(filename, types, condition, *row, getDefaults()[""], &instruction); + result = Instruction::create(filename, types, condition, *row, getDefaults()[""], &instruction); if (instruction == NULL || result != RESULT_OK) { *errorDescription = "invalid instruction"; return result; @@ -2330,8 +2324,15 @@ bool MessageMap::getLoadedFileInfo(const string& filename, string* comment, size const auto it = m_loadedFileInfos.find(filename); if (it == m_loadedFileInfos.end()) { *comment = ""; - hash = size = 0; - time = 0; + if (hash) { + *hash = 0; + } + if (size) { + *size = 0; + } + if (time) { + *time = 0; + } return false; } *comment = it->second.m_comment; diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index 23bc2c94..9450d06a 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -551,12 +551,10 @@ class Message : public AttributedItem { /** * Decode the message from the last stored data. * @param leadingSeparator whether to prepend a separator before the first value. - * @param fields the list of message and/or data field fields to write, or NULL for all. * @param outputFormat the @a OutputFormat options to use. * @param output the @a ostringstream to append the decoded value(s) to. */ - virtual void decode(bool leadingSeparator, const vector* fields, - OutputFormat outputFormat, ostringstream* output) const; + virtual void decode(bool leadingSeparator, OutputFormat outputFormat, ostringstream* output) const; protected: /** the optional circuit name. */