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 -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;
}
+7 -7
View File
@@ -359,8 +359,8 @@ result_t DateTimeDataType::readSymbols(size_t offset, size_t length, const Symbo
return RESULT_ERR_INVALID_POS;
}
// number of minutes since 01.01.2009
minutes |= symbol*(1<<(8*i));
if (i<3) {
minutes |= symbol*(1 << (8*i));
if (i < 3) {
break;
}
int mjd = static_cast<int>(minutes/(24*60)) + 54832; // 01.01.2009
@@ -424,7 +424,7 @@ result_t DateTimeDataType::writeSymbols(size_t offset, size_t length, istringstr
if (length == 4 && i == 2 && !m_hasTime) {
continue; // skip weekday in between
}
if (input->eof() || !getline(*input, token, m_hasTime && i==2 ? ' ' : '.')) {
if (input->eof() || !getline(*input, token, m_hasTime && i == 2 ? ' ' : '.')) {
return RESULT_ERR_EOF; // incomplete
}
if (!hasFlag(REQ) && token == NULL_VALUE) {
@@ -464,7 +464,7 @@ result_t DateTimeDataType::writeSymbols(size_t offset, size_t length, istringstr
index = start + incr;
i = 1;
type = 1;
skip = true; // switch to second pass for parsing the time
skip = true; // switch to second pass for parsing the time
} else {
// calculate local week day
int daysSinceSunday = (mjd + 3) % 7; // Sun=0
@@ -546,7 +546,7 @@ result_t DateTimeDataType::writeSymbols(size_t offset, size_t length, istringstr
}
break;
case 3: // date and time in store phase
case 3: // date and time in store phase
value = lastLast & 0xff;
last = lastLast >> 8;
break;
@@ -677,7 +677,7 @@ result_t NumberDataType::derive(int divisor, size_t bitCount, const NumberDataTy
result_t NumberDataType::getMinMax(bool getMax, const OutputFormat outputFormat, ostream* output) const {
size_t length;
if (m_bitCount<8) {
if (m_bitCount < 8) {
length = 1;
} else {
length = m_bitCount/8;
@@ -1135,7 +1135,7 @@ DataTypeList* DataTypeList::getInstance() {
void DataTypeList::dump(OutputFormat outputFormat, bool appendDivisor, ostream* output) const {
bool json = outputFormat & OF_JSON;
string sep = "\n";
for (const auto &it: m_typesById) {
for (const auto &it : m_typesById) {
const DataType *dataType = it.second;
if (dataType->hasFlag(DUP)) {
continue;
+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.
+12 -10
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));
@@ -184,7 +184,7 @@ result_t Device::requestEnhancedInfo(symbol_t infoId) {
if (!m_enhancedProto || m_extraFatures == 0 || infoId == 0xff) {
return RESULT_ERR_INVALID_ARG;
}
for (unsigned int i=0; i<4; i++) {
for (unsigned int i = 0; i < 4; i++) {
if (m_infoId == 0xff) {
break;
}
@@ -602,7 +602,7 @@ bool Device::read(symbol_t* value, bool isAvailable, ArbitrationState* arbitrati
break;
case ENH_RES_INFO:
if (m_infoLen == 0) {
if (data<=16) { // max length
if (data <= 16) { // max length
m_infoLen = data;
m_infoPos = 0;
}
@@ -611,9 +611,10 @@ bool Device::read(symbol_t* value, bool isAvailable, ArbitrationState* arbitrati
if (m_infoPos >= m_infoLen) {
unsigned int val;
ostringstream stream;
switch ((m_infoLen<<8) | m_infoId) {
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:
@@ -624,12 +625,12 @@ bool Device::read(symbol_t* value, bool isAvailable, ArbitrationState* arbitrati
}
break;
case 0x0203:
val = (static_cast<unsigned>(m_infoBuf[0])<<8) | static_cast<unsigned>(m_infoBuf[1]);
val = (static_cast<unsigned>(m_infoBuf[0]) << 8) | static_cast<unsigned>(m_infoBuf[1]);
stream << "temperature " << static_cast<unsigned>(val) << " °C";
m_enhInfoTemperature = stream.str();
break;
case 0x0204:
val = (static_cast<unsigned>(m_infoBuf[0])<<8) | static_cast<unsigned>(m_infoBuf[1]);
val = (static_cast<unsigned>(m_infoBuf[0]) << 8) | static_cast<unsigned>(m_infoBuf[1]);
stream << "supply voltage " << static_cast<unsigned>(val) << " mV";
m_enhInfoSupplyVoltage = stream.str();
break;
@@ -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"
+4 -4
View File
@@ -142,7 +142,7 @@ bool FileReader::matches(const string& input, const string& search, bool ignoreC
} else {
found = true;
}
if (from==to) {
if (from == to) {
return true; // empty pattern matches everything
}
size_t nextStart = to+1;
@@ -150,11 +150,11 @@ bool FileReader::matches(const string& input, const string& search, bool ignoreC
if (matchStart) {
from++;
}
bool matchEnd = from<to && search[to-1] == '$';
bool matchEnd = from < to && search[to-1] == '$';
if (matchEnd) {
to--;
}
if (matchEnd && matchStart && from==to) { // pattern is "^$"
if (matchEnd && matchStart && from == to) { // pattern is "^$"
if (input.empty()) {
return true;
}
@@ -189,7 +189,7 @@ bool FileReader::matches(const string& input, const string& search, bool ignoreC
}
if (prefix.length() <= checkEnd) {
if (matchStart) {
if (input.substr(0, prefix.length()) == prefix && (!matchEnd || prefix.length()==checkEnd)) {
if (input.substr(0, prefix.length()) == prefix && (!matchEnd || prefix.length() == checkEnd)) {
return true;
}
} else {
+15 -11
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);
@@ -969,7 +971,7 @@ void Message::decodeJson(bool leadingSeparator, bool appendDirectionCondition, b
if (outputFormat & OF_ALL_ATTRS) {
*output << ",\n \"filename\": \"" << m_filename << "\"";
*output << ",\n \"level\": \"" << getLevel() << "\"";
if (getPollPriority()>0) {
if (getPollPriority() > 0) {
*output << ",\n \"pollprio\": " << setw(0) << dec << getPollPriority();
}
if (isConditional()) {
@@ -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: