code style

This commit is contained in:
John
2022-02-12 12:42:35 +01:00
parent 04c6b40704
commit 7ae43351da
16 changed files with 181 additions and 164 deletions
+2 -1
View File
@@ -308,7 +308,8 @@ bool GrabbedMessage::dump(bool unknown, MessageMap* messages, bool first, Output
}
for (const auto& it : *types) {
const DataType* baseType = it.second;
if ((baseType->getBitCount() % 8) != 0 || baseType->isIgnored() || baseType->hasFlag(DUP)) { // skip bit and ignored types
if ((baseType->getBitCount() % 8) != 0 || baseType->isIgnored() || baseType->hasFlag(DUP)) {
// skip bit and ignored types
continue;
}
size_t maxLength = baseType->getBitCount()/8;
+4 -4
View File
@@ -1046,7 +1046,8 @@ result_t loadScanConfigFile(MessageMap* messages, symbol_t address, bool verbose
size_t offset = 0;
size_t field = 0;
bool fromLocal = s_configUriPrefix.empty();
result_t result = (*identFields)[field]->read(data, offset, false, nullptr, -1, OF_NONE, -1, &out); // manufacturer name
// manufacturer name
result_t result = (*identFields)[field]->read(data, offset, false, nullptr, -1, OF_NONE, -1, &out);
if (result == RESULT_ERR_NOTFOUND && fromLocal) {
result = (*identFields)[field]->read(data, offset, false, nullptr, -1, OF_NUMERIC, -1, &out); // manufacturer name
}
@@ -1263,7 +1264,7 @@ int main(int argc, char* argv[]) {
continue;
}
for (size_t i=0; i<len; i++) {
envopt[i] = (char)tolower(start[i]);
envopt[i] = static_cast<char>(tolower(start[i]));
}
envopt[len] = 0;
if (strcmp(envopt, "version") == 0 || strcmp(envopt, "image") == 0 || strcmp(envopt, "arch") == 0
@@ -1398,8 +1399,7 @@ int main(int argc, char* argv[]) {
: opt.initialScan == BROADCAST ? " with broadcast scan" : opt.initialScan == SYN ? " with full scan"
: " with single scan" : "",
device->isEnhancedProto() ? " enhanced" : "",
device->getName()
);
device->getName());
// load configuration files
loadConfigFiles(s_messageMap);
+12 -7
View File
@@ -23,6 +23,8 @@
#include "ebusd/mqtthandler.h"
#include <csignal>
#include <deque>
#include <algorithm>
#include <utility>
#include "lib/utils/log.h"
#include "lib/ebus/symbol.h"
@@ -64,7 +66,8 @@ static const struct argp_option g_mqtt_argp_options[] = {
{"mqttpass", O_PASS, "PASSWORD", 0, "Use PASSWORD when connecting to MQTT broker (no default)", 0 },
{"mqtttopic", O_TOPI, "TOPIC", 0,
"Use MQTT TOPIC (prefix before /%circuit/%name or complete format) [ebusd]", 0 },
{"mqttglobal", O_GTOP, "TOPIC", 0, "Use TOPIC for global data (default is \"global/\" suffix to mqtttopic prefix)", 0 },
{"mqttglobal", O_GTOP, "TOPIC", 0,
"Use TOPIC for global data (default is \"global/\" suffix to mqtttopic prefix)", 0 },
{"mqttretain", O_RETA, nullptr, 0, "Retain all topics instead of only selected global ones", 0 },
{"mqttqos", O_PQOS, "QOS", 0, "Set the QoS value for all topics (0-2) [0]", 0 },
{"mqttint", O_INTF, "FILE", 0, "Read MQTT integration settings from FILE (no default)", 0 },
@@ -381,7 +384,7 @@ std::pair<string, int> makeField(const string& name, bool isField) {
if (!isField) {
return {name, -1};
}
for (int idx = 0; idx < (int)knownFieldCount; idx++) {
for (int idx = 0; idx < static_cast<int>(knownFieldCount); idx++) {
if (name == knownFieldNames[idx]) {
return {name, idx};
}
@@ -1172,7 +1175,7 @@ void MqttHandler::notifyConnected() {
if (!m_staticTopic) {
check(mosquitto_subscribe(m_mosquitto, nullptr, m_subscribeTopic.c_str(), 0), "subscribe");
if (!m_subscribeConfigRestartTopic.empty()) {
check(mosquitto_subscribe(m_mosquitto, nullptr, m_subscribeConfigRestartTopic.c_str(), 0), "subscribe definition");
check(mosquitto_subscribe(m_mosquitto, nullptr, m_subscribeConfigRestartTopic.c_str(), 0), "subscribe def.");
}
}
}
@@ -1388,7 +1391,8 @@ void MqttHandler::run() {
}
}
if (m_connected && m_definitionsSince == 0) {
publishDefinition(m_replacers, "def_global_running-", m_globalTopic.get("", "running"), "global", "running", "def_global-");
publishDefinition(m_replacers, "def_global_running-", m_globalTopic.get("", "running"), "global", "running",
"def_global-");
if (globalHasName) {
publishDefinition(m_replacers, "def_global_version-", m_globalTopic.get("", "version"), "global", "version",
"def_global-");
@@ -1523,10 +1527,10 @@ void MqttHandler::run() {
if (dt->getMinMax(false, OF_NONE, &ostr) == RESULT_OK) {
values.set("min", ostr.str());
ostr.str("");
};
}
if (dt->getMinMax(true, OF_NONE, &ostr) == RESULT_OK) {
values.set("max", ostr.str());
};
}
}
if (!m_typeSwitches.empty()) {
values.reduce(true);
@@ -1763,7 +1767,8 @@ void MqttHandler::publishMessage(const Message* message, ostringstream* updates,
if (json) {
*updates << "{";
if (m_staticTopic) {
*updates << "\"circuit\":\"" << message->getCircuit() << "\",\"name\":\"" << message->getName() << "\",\"fields\":{";
*updates << "\"circuit\":\"" << message->getCircuit() << "\",\"name\":\"" << message->getName()
<< "\",\"fields\":{";
}
} else {
*updates << message->getCircuit() << UI_FIELD_SEPARATOR << message->getName() << UI_FIELD_SEPARATOR;
+1
View File
@@ -24,6 +24,7 @@
#include <string>
#include <list>
#include <vector>
#include <utility>
#include "ebusd/datahandler.h"
#include "ebusd/bushandler.h"
#include "lib/ebus/message.h"
+2 -2
View File
@@ -130,8 +130,8 @@ void AttributedItem::mergeAttributes(map<string, string>* attributes) const {
}
}
void AttributedItem::dumpAttribute(bool prependFieldSeparator, OutputFormat outputFormat, const string& name, ostream* output)
const {
void AttributedItem::dumpAttribute(bool prependFieldSeparator, OutputFormat outputFormat, const string& name,
ostream* output) const {
if (outputFormat & OF_JSON) {
appendJson(prependFieldSeparator, name, getAttribute(name), false, output);
} else {
+2 -2
View File
@@ -426,12 +426,12 @@ class SingleDataField : public DataField {
size_t getCount(PartType partType = pt_any, const char* fieldName = nullptr) const override;
// @copydoc
virtual string getName(ssize_t fieldIndex) const override {
string getName(ssize_t fieldIndex) const override {
return isIgnored() || fieldIndex > 0 ? "" : m_name;
}
// @copydoc
virtual const SingleDataField* getField(ssize_t fieldIndex) const override {
const SingleDataField* getField(ssize_t fieldIndex) const override {
if (isIgnored() || fieldIndex > 0) {
return nullptr;
}
+4 -4
View File
@@ -437,8 +437,8 @@ class NumberDataType : public DataType {
NumberDataType(const string& id, size_t bitCount, uint16_t flags, unsigned int replacement,
unsigned int minValue, unsigned int maxValue, int divisor,
const NumberDataType* baseType = nullptr)
: DataType(id, bitCount, flags|NUM, replacement), m_minValue(minValue), m_maxValue(maxValue), m_divisor(divisor==0 ? 1 : divisor),
m_precision(calcPrecision(divisor)), m_firstBit(0), m_baseType(baseType) {}
: DataType(id, bitCount, flags|NUM, replacement), m_minValue(minValue), m_maxValue(maxValue),
m_divisor(divisor == 0 ? 1 : divisor), m_precision(calcPrecision(divisor)), m_firstBit(0), m_baseType(baseType) {}
/**
* Constructs a new instance for less than 8 bits.
@@ -452,8 +452,8 @@ class NumberDataType : public DataType {
*/
NumberDataType(const string& id, size_t bitCount, uint16_t flags, unsigned int replacement,
int16_t firstBit, int divisor, const NumberDataType* baseType = nullptr)
: DataType(id, bitCount, flags|NUM, replacement), m_minValue(0), m_maxValue((1 << bitCount)-1), m_divisor(divisor==0 ? 1 : divisor),
m_precision(0), m_firstBit(firstBit), m_baseType(baseType) {}
: DataType(id, bitCount, flags|NUM, replacement), m_minValue(0), m_maxValue((1 << bitCount)-1),
m_divisor(divisor == 0 ? 1 : divisor), m_precision(0), m_firstBit(firstBit), m_baseType(baseType) {}
/**
* Destructor.
+7 -5
View File
@@ -79,8 +79,8 @@ namespace ebusd {
Device::Device(const char* name, bool checkDevice, unsigned int latency, bool readOnly, bool initialSend,
bool enhancedProto)
: m_name(name), m_checkDevice(checkDevice),
m_latency(HOST_LATENCY_MS+(enhancedProto?ENHANCED_LATENCY_MS:0)+latency), m_readOnly(readOnly), m_initialSend(initialSend),
m_enhancedProto(enhancedProto), m_fd(-1), m_listener(nullptr), m_arbitrationMaster(SYN),
m_latency(HOST_LATENCY_MS+(enhancedProto?ENHANCED_LATENCY_MS:0)+latency), m_readOnly(readOnly),
m_initialSend(initialSend), m_enhancedProto(enhancedProto), m_fd(-1), m_listener(nullptr), m_arbitrationMaster(SYN),
m_arbitrationCheck(false), m_bufSize(((MAX_LEN+1+3)/4)*4), m_bufLen(0), m_bufPos(0),
m_extraFatures(0), m_infoId(0xff), m_infoLen(0), m_infoPos(0) {
m_buffer = reinterpret_cast<symbol_t*>(malloc(m_bufSize));
@@ -613,7 +613,8 @@ bool Device::read(symbol_t* value, bool isAvailable, ArbitrationState* arbitrati
ostringstream stream;
switch ((m_infoLen << 8) | m_infoId) {
case 0x0200:
stream << "firmware " << static_cast<unsigned>(m_infoBuf[0]) << "." << std::hex << static_cast<unsigned>(m_infoBuf[1]);
stream << "firmware " << static_cast<unsigned>(m_infoBuf[0]) << "." << std::hex
<< static_cast<unsigned>(m_infoBuf[1]);
break;
case 0x0901:
case 0x0802:
@@ -640,8 +641,9 @@ bool Device::read(symbol_t* value, bool isAvailable, ArbitrationState* arbitrati
m_enhInfoBusVoltage = stream.str();
break;
default:
stream << "unknown 0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast<unsigned>(m_infoId)
<< ", len " << std::dec << std::setw(0) << static_cast<unsigned>(m_infoPos);
stream << "unknown 0x" << std::hex << std::setfill('0') << std::setw(2)
<< static_cast<unsigned>(m_infoId) << ", len " << std::dec << std::setw(0)
<< static_cast<unsigned>(m_infoPos);
break;
}
m_listener->notifyStatus(false, ("extra info: "+stream.str()).c_str());
+1
View File
@@ -26,6 +26,7 @@
#include <netdb.h>
#include <iostream>
#include <fstream>
#include <string>
#include "lib/ebus/result.h"
#include "lib/ebus/symbol.h"
+14 -10
View File
@@ -483,11 +483,11 @@ result_t Message::create(const string& filename, const DataFieldTemplates* templ
}
Message* message;
if (chainIds.size() > 1) {
message = new ChainedMessage(filename, useCircuit, level, name, isWrite, *row, srcAddress, dstAddress, id, chainIds,
chainLengths, data, index == 0, pollPriority, condition);
message = new ChainedMessage(filename, useCircuit, level, name, isWrite, *row, srcAddress, dstAddress, id,
chainIds, chainLengths, data, index == 0, pollPriority, condition);
} else {
message = new Message(filename, useCircuit, level, name, isWrite, isPassive, *row, srcAddress, dstAddress, id, data,
index == 0, pollPriority, condition);
message = new Message(filename, useCircuit, level, name, isWrite, isPassive, *row, srcAddress, dstAddress, id,
data, index == 0, pollPriority, condition);
}
messages->push_back(message);
index++;
@@ -853,7 +853,8 @@ void Message::dumpHeader(const vector<string>* fieldNames, ostream* output) {
}
}
void Message::dump(const vector<string>* fieldNames, bool withConditions, OutputFormat outputFormat, ostream* output) const {
void Message::dump(const vector<string>* fieldNames, bool withConditions, OutputFormat outputFormat, ostream* output)
const {
// not to be used together with OF_JSON
bool first = true;
if (fieldNames == nullptr) {
@@ -880,7 +881,8 @@ void Message::dump(const vector<string>* fieldNames, bool withConditions, Output
}
}
void Message::dumpField(const string& fieldName, bool withConditions, OutputFormat outputFormat, ostream* output) const {
void Message::dumpField(const string& fieldName, bool withConditions, OutputFormat outputFormat, ostream* output)
const {
if (fieldName == "type") {
if (withConditions && m_condition != nullptr) {
m_condition->dump(false, output);
@@ -1278,7 +1280,8 @@ result_t ChainedMessage::combineLastParts() {
return result;
}
void ChainedMessage::dumpField(const string& fieldName, bool withConditions, OutputFormat outputFormat, ostream* output) const {
void ChainedMessage::dumpField(const string& fieldName, bool withConditions, OutputFormat outputFormat, ostream* output)
const {
if (fieldName != "id") {
Message::dumpField(fieldName, withConditions, outputFormat, output);
return;
@@ -2164,10 +2167,11 @@ result_t MessageMap::readConditions(const string& filename, string* types, strin
bool MessageMap::extractDefaultsFromFilename(const string& filename, map<string, string>* defaults,
symbol_t* destAddress, unsigned int* software, unsigned int* hardware) const {
// check filename to match (glob style with optionals in brackets): ZZ.[ID.][*.][CIRCUIT.[?.]][*.][HW????.][*.][SW????.][*.]csv
// check filename to match (glob style with optionals in brackets):
// ZZ.[ID.][*.][CIRCUIT.[?.]][*.][HW????.][*.][SW????.][*.]csv
// ZZ is the address, ID is the 5 char identifier (reduced by trailing 0 one by one for finding a match), CIRCUIT is
// the optional circuit name, ? behind the circuit name is the circuit number suffix (when having more than one of these),
// ???? behind HW is the hardware version, ???? behind SW is the software version
// the optional circuit name, ? behind the circuit name is the circuit number suffix (when having more than one of
// these), ???? behind HW is the hardware version, ???? behind SW is the software version
string ident, circuit, suffix;
unsigned int sw = UINT_MAX, hw = UINT_MAX;
string remain = filename;
+4 -2
View File
@@ -586,7 +586,8 @@ class Message : public AttributedItem {
* @param outputFormat the @a OutputFormat options.
* @param output the @a ostream to append the formatted value to.
*/
virtual void dumpField(const string& fieldName, bool withConditions, OutputFormat outputFormat, ostream* output) const;
virtual void dumpField(const string& fieldName, bool withConditions, OutputFormat outputFormat, ostream* output)
const;
/**
* Decode the message from the last stored data in JSON format.
@@ -767,7 +768,8 @@ class ChainedMessage : public Message {
protected:
// @copydoc
void dumpField(const string& fieldName, bool withConditions, OutputFormat outputFormat, ostream* output) const override;
void dumpField(const string& fieldName, bool withConditions, OutputFormat outputFormat, ostream* output) const
override;
private:
+3 -2
View File
@@ -17,11 +17,11 @@
*/
#include "lib/utils/httpclient.h"
#include "lib/utils/log.h"
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <csignal>
#include "lib/utils/log.h"
namespace ebusd {
@@ -273,7 +273,8 @@ bool HttpClient::parseUrl(const string& url, string* proto, string* host, uint16
return true;
}
bool HttpClient::connect(const string& host, const uint16_t port, const bool https, const string& userAgent, const int timeout) {
bool HttpClient::connect(const string& host, const uint16_t port, bool https, const string& userAgent,
const int timeout) {
disconnect();
#ifdef HAVE_SSL
m_socket = SSLSocket::connect(host, port, https, timeout);
+1 -1
View File
@@ -160,7 +160,7 @@ class HttpClient {
* @param userAgent the optional user agent to send in the request header.
* @return true on success, false on connect failure.
*/
bool connect(const string& host, uint16_t port, const bool https = false, const string& userAgent = "", int timeout = 5);
bool connect(const string& host, uint16_t port, bool https = false, const string& userAgent = "", int timeout = 5);
/**
* Re-connect to the last specified server.