This commit is contained in:
John
2023-11-04 09:31:08 +01:00
parent 607fc00c0e
commit 077d09b620
13 changed files with 38 additions and 33 deletions
-2
View File
@@ -31,8 +31,6 @@
namespace ebusd { namespace ebusd {
using std::dec;
bool check(int code, const char* method) { bool check(int code, const char* method) {
if (code == MOSQ_ERR_SUCCESS) { if (code == MOSQ_ERR_SUCCESS) {
+1 -1
View File
@@ -954,7 +954,7 @@ void MqttHandler::run() {
auto vl = (dynamic_cast<const ValueListDataField*>(field))->getList(); auto vl = (dynamic_cast<const ValueListDataField*>(field))->getList();
string entryFormat = values["field_values-entry"]; string entryFormat = values["field_values-entry"];
string::size_type pos = -1; string::size_type pos = -1;
while ((pos = entryFormat.find('$', pos+1)) != std::string::npos) { while ((pos = entryFormat.find('$', pos+1)) != string::npos) {
if (entryFormat.substr(pos+1, 4) == "text" || entryFormat.substr(pos+1, 5) == "value") { if (entryFormat.substr(pos+1, 4) == "text" || entryFormat.substr(pos+1, 5) == "value") {
entryFormat.replace(pos, 1, "%"); entryFormat.replace(pos, 1, "%");
} }
-1
View File
@@ -40,7 +40,6 @@ using std::hex;
using std::setfill; using std::setfill;
using std::setw; using std::setw;
using std::nouppercase; using std::nouppercase;
using std::cout;
ScanHelper::~ScanHelper() { ScanHelper::~ScanHelper() {
+1 -2
View File
@@ -32,7 +32,6 @@
namespace ebusd { namespace ebusd {
using std::dec; using std::dec;
using std::hex;
using std::setw; using std::setw;
/** the week day names. */ /** the week day names. */
@@ -1469,7 +1468,7 @@ bool DataFieldTemplates::dump(OutputFormat outputFormat, ostream* output) const
if (outputFormat & OF_JSON) { if (outputFormat & OF_JSON) {
if (dataField->isSet()) { if (dataField->isSet()) {
if (prependFieldSeparator) { if (prependFieldSeparator) {
*output << ",\n"; *output << ",\n";
} }
*output << "{\"name\":\"" << dataField->getName(-1) << "\", \"sequence\": ["; *output << "{\"name\":\"" << dataField->getName(-1) << "\", \"sequence\": [";
dataField->dump(false, outputFormat, output); dataField->dump(false, outputFormat, output);
-2
View File
@@ -34,13 +34,11 @@
namespace ebusd { namespace ebusd {
using std::dec; using std::dec;
using std::defaultfloat;
using std::hex; using std::hex;
using std::fixed; using std::fixed;
using std::setfill; using std::setfill;
using std::setprecision; using std::setprecision;
using std::setw; using std::setw;
using std::endl;
using std::isfinite; using std::isfinite;
+24 -16
View File
@@ -46,6 +46,14 @@
namespace ebusd { namespace ebusd {
using std::hex;
using std::dec;
using std::setfill;
using std::setw;
using std::setprecision;
using std::fixed;
#define MTU 1540 #define MTU 1540
#ifndef POLLRDHUP #ifndef POLLRDHUP
@@ -728,37 +736,37 @@ bool FileDevice::handleEnhancedBufferedData(symbol_t* value, ArbitrationState* a
case 0x0200: case 0x0200:
case 0x0500: // with firmware version and jumper info case 0x0500: // with firmware version and jumper info
case 0x0800: // with firmware version, jumper info, and bootloader version case 0x0800: // with firmware version, jumper info, and bootloader version
stream << std::hex << static_cast<unsigned>(m_infoBuf[1]) // features mask stream << hex << static_cast<unsigned>(m_infoBuf[1]) // features mask
<< "." << static_cast<unsigned>(m_infoBuf[0]); // version minor << "." << static_cast<unsigned>(m_infoBuf[0]); // version minor
if (m_infoLen >= 5) { if (m_infoLen >= 5) {
stream << "[" << std::setfill('0') << std::setw(2) << std::hex << static_cast<unsigned>(m_infoBuf[2]) stream << "[" << setfill('0') << setw(2) << hex << static_cast<unsigned>(m_infoBuf[2])
<< std::setw(2) << static_cast<unsigned>(m_infoBuf[3]) << "]"; << setw(2) << static_cast<unsigned>(m_infoBuf[3]) << "]";
} }
if (m_infoLen >= 8) { if (m_infoLen >= 8) {
stream << "." << std::dec << static_cast<unsigned>(m_infoBuf[5]); stream << "." << dec << static_cast<unsigned>(m_infoBuf[5]);
stream << "[" << std::setfill('0') << std::setw(2) << std::hex << static_cast<unsigned>(m_infoBuf[6]) stream << "[" << setfill('0') << setw(2) << hex << static_cast<unsigned>(m_infoBuf[6])
<< std::setw(2) << static_cast<unsigned>(m_infoBuf[7]) << "]"; << setw(2) << static_cast<unsigned>(m_infoBuf[7]) << "]";
} }
m_enhInfoVersion = stream.str(); m_enhInfoVersion = stream.str();
stream.str(" "); stream.str(" ");
stream << "firmware " << m_enhInfoVersion; stream << "firmware " << m_enhInfoVersion;
if (m_infoLen >= 5) { if (m_infoLen >= 5) {
stream << ", jumpers 0x" << std::setw(2) << static_cast<unsigned>(m_infoBuf[4]); stream << ", jumpers 0x" << setw(2) << static_cast<unsigned>(m_infoBuf[4]);
} }
stream << std::setfill(' '); // reset stream << setfill(' '); // reset
break; break;
case 0x0901: case 0x0901:
case 0x0802: case 0x0802:
case 0x0302: case 0x0302:
stream << (m_infoId == 1 ? "ID" : "config"); stream << (m_infoId == 1 ? "ID" : "config");
stream << std::hex << std::setfill('0'); stream << hex << setfill('0');
for (uint8_t pos = 0; pos < m_infoPos; pos++) { for (uint8_t pos = 0; pos < m_infoPos; pos++) {
stream << " " << std::setw(2) << static_cast<unsigned>(m_infoBuf[pos]); stream << " " << setw(2) << static_cast<unsigned>(m_infoBuf[pos]);
} }
if (m_infoId == 2 && (m_infoBuf[2]&0x3f) != 0x3f) { if (m_infoId == 2 && (m_infoBuf[2]&0x3f) != 0x3f) {
// non-default arbitration delay // non-default arbitration delay
val = (m_infoBuf[2]&0x3f)*10; // steps of 10us val = (m_infoBuf[2]&0x3f)*10; // steps of 10us
stream << ", arbitration delay " << std::dec << static_cast<unsigned>(val) << " us"; stream << ", arbitration delay " << dec << static_cast<unsigned>(val) << " us";
} }
break; break;
case 0x0203: case 0x0203:
@@ -779,7 +787,7 @@ bool FileDevice::handleEnhancedBufferedData(symbol_t* value, ArbitrationState* a
case 0x0205: case 0x0205:
stream << "bus voltage "; stream << "bus voltage ";
if (m_infoBuf[0] | m_infoBuf[1]) { if (m_infoBuf[0] | m_infoBuf[1]) {
stream << std::fixed << std::setprecision(1) stream << fixed << setprecision(1)
<< static_cast<float>(m_infoBuf[1] / 10.0) << " V - " << static_cast<float>(m_infoBuf[1] / 10.0) << " V - "
<< static_cast<float>(m_infoBuf[0] / 10.0) << " V"; << static_cast<float>(m_infoBuf[0] / 10.0) << " V";
} else { } else {
@@ -807,8 +815,8 @@ bool FileDevice::handleEnhancedBufferedData(symbol_t* value, ArbitrationState* a
} }
break; break;
default: default:
stream << "unknown 0x" << std::hex << std::setfill('0') << std::setw(2) stream << "unknown 0x" << hex << setfill('0') << setw(2)
<< static_cast<unsigned>(m_infoId) << ", len " << std::dec << std::setw(0) << static_cast<unsigned>(m_infoId) << ", len " << dec << setw(0)
<< static_cast<unsigned>(m_infoPos); << static_cast<unsigned>(m_infoPos);
break; break;
} }
@@ -834,7 +842,7 @@ bool FileDevice::handleEnhancedBufferedData(symbol_t* value, ArbitrationState* a
stream << "overrun"; stream << "overrun";
break; break;
default: default:
stream << "unknown 0x" << std::setw(2) << std::setfill('0') << std::hex << static_cast<unsigned>(data); stream << "unknown 0x" << setw(2) << setfill('0') << hex << static_cast<unsigned>(data);
break; break;
} }
string str = stream.str(); string str = stream.str();
@@ -845,7 +853,7 @@ bool FileDevice::handleEnhancedBufferedData(symbol_t* value, ArbitrationState* a
default: default:
if (m_listener != nullptr) { if (m_listener != nullptr) {
ostringstream stream; ostringstream stream;
stream << "unexpected enhanced command 0x" << std::setw(2) << std::setfill('0') << std::hex stream << "unexpected enhanced command 0x" << setw(2) << setfill('0') << hex
<< static_cast<unsigned>(cmd); << static_cast<unsigned>(cmd);
string str = stream.str(); string str = stream.str();
m_listener->notifyStatus(true, str.c_str()); m_listener->notifyStatus(true, str.c_str());
-2
View File
@@ -32,8 +32,6 @@ using std::ifstream;
using std::ostringstream; using std::ostringstream;
using std::cout; using std::cout;
using std::endl; using std::endl;
using std::setw;
using std::dec;
istream* FileReader::openFile(const string& filename, string* errorDescription, time_t* time) { istream* FileReader::openFile(const string& filename, string* errorDescription, time_t* time) {
+5 -1
View File
@@ -44,6 +44,10 @@ using std::string;
using std::map; using std::map;
using std::ostream; using std::ostream;
using std::istream; using std::istream;
using std::hex;
using std::dec;
using std::setw;
using std::setfill;
/** the separator character used between fields. */ /** the separator character used between fields. */
#define FIELD_SEPARATOR ',' #define FIELD_SEPARATOR ','
@@ -174,7 +178,7 @@ class FileReader {
* @param stream the @a ostream to write to. * @param stream the @a ostream to write to.
*/ */
static void formatHash(size_t hash, ostream* stream) { static void formatHash(size_t hash, ostream* stream) {
*stream << std::hex << std::setw(8) << std::setfill('0') << (hash & 0xffffffff) << std::dec << std::setw(0); *stream << hex << setw(8) << setfill('0') << (hash & 0xffffffff) << dec << setw(0);
} }
/** /**
+1 -1
View File
@@ -902,7 +902,7 @@ class Condition {
* Write the values part of the condition definition in JSON to the @a ostream. * Write the values part of the condition definition in JSON to the @a ostream.
* @param output the @a ostream to append to. * @param output the @a ostream to append to.
*/ */
virtual void dumpValuesJson(ostream* output) const { /* empty on top level*/ }; virtual void dumpValuesJson(ostream* output) const { /* empty on top level*/ }
/** /**
* Combine this condition with another instance using a logical and. * Combine this condition with another instance using a logical and.
+1 -1
View File
@@ -499,7 +499,7 @@ bool StringReplacers::set(const string& key, const string& value, bool removeRep
} }
void StringReplacers::set(const string& key, int value) { void StringReplacers::set(const string& key, int value) {
std::ostringstream str; ostringstream str;
str << static_cast<signed>(value); str << static_cast<signed>(value);
m_constants[key] = str.str(); m_constants[key] = str.str();
} }
+1 -1
View File
@@ -162,7 +162,7 @@ class StringReplacer {
* the number is negative for plain strings, the index to @a knownFieldNames for a known field, or the size of * the number is negative for plain strings, the index to @a knownFieldNames for a known field, or the size of
* @a knownFieldNames for an unknown field. * @a knownFieldNames for an unknown field.
*/ */
vector<std::pair<string, int>> m_parts; vector<pair<string, int>> m_parts;
/** true when the complete result is supposed to be empty when at least one referenced variable /** true when the complete result is supposed to be empty when at least one referenced variable
* is empty or not defined. */ * is empty or not defined. */
+2 -1
View File
@@ -35,7 +35,8 @@ enum ArgFlag {
typedef struct argDef { typedef struct argDef {
const char* name; //!< the (long) name of the argument, or nullptr for a group header or positional const char* name; //!< the (long) name of the argument, or nullptr for a group header or positional
int key; //!< the argument key, also used as short name if alphabetic or the question mark int key; //!< the argument key, also used as short name if alphabetic or the question mark
const char* valueName; //!< the optional argument value name, or nullptr for group header or argument without value name // the optional argument value name, or nullptr for group header or argument without value name
const char* valueName;
int flags; //!< flags for the argument, bit combination of @a ArgFlag int flags; //!< flags for the argument, bit combination of @a ArgFlag
const char* help; //!< help text (mandatory) const char* help; //!< help text (mandatory)
} argDef; } argDef;
+2 -2
View File
@@ -33,7 +33,6 @@ namespace ebusd {
using std::string; using std::string;
using std::ostringstream; using std::ostringstream;
using std::dec; using std::dec;
using std::hex;
#ifdef HAVE_SSL #ifdef HAVE_SSL
@@ -434,7 +433,8 @@ void HttpClient::disconnect() {
} }
} }
bool HttpClient::get(const string& uri, const string& body, string* response, bool* repeatable, time_t* time, bool* jsonString) { bool HttpClient::get(const string& uri, const string& body, string* response, bool* repeatable,
time_t* time, bool* jsonString) {
return request("GET", uri, body, response, repeatable, time, jsonString); return request("GET", uri, body, response, repeatable, time, jsonString);
} }