avoid unnecessary includes, avoid unnecessary casts, better initialization, corrected readTemplates() return value on failure, separate options values
This commit is contained in:
+14
-19
@@ -22,21 +22,16 @@
|
|||||||
|
|
||||||
#include "ebusd/main.h"
|
#include "ebusd/main.h"
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <argp.h>
|
#include <argp.h>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "ebusd/mainloop.h"
|
#include "ebusd/mainloop.h"
|
||||||
#include "ebusd/bushandler.h"
|
|
||||||
#include "lib/utils/log.h"
|
#include "lib/utils/log.h"
|
||||||
#include "lib/utils/rotatefile.h"
|
|
||||||
|
|
||||||
namespace ebusd {
|
namespace ebusd {
|
||||||
|
|
||||||
@@ -83,7 +78,8 @@ static struct options opt = {
|
|||||||
CONFIG_PATH, // configPath
|
CONFIG_PATH, // configPath
|
||||||
false, // scanConfig
|
false, // scanConfig
|
||||||
BROADCAST, // initialScan
|
BROADCAST, // initialScan
|
||||||
0, // checkConfig
|
false, // checkConfig
|
||||||
|
false, // dumpConfig
|
||||||
5, // pollInterval
|
5, // pollInterval
|
||||||
0x31, // address
|
0x31, // address
|
||||||
false, // answer
|
false, // answer
|
||||||
@@ -287,12 +283,11 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case O_CHKCFG: // --checkconfig
|
case O_CHKCFG: // --checkconfig
|
||||||
if (opt->checkConfig == 0) {
|
opt->checkConfig = true;
|
||||||
opt->checkConfig = 1;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case O_DMPCFG: // --dumpconfig
|
case O_DMPCFG: // --dumpconfig
|
||||||
opt->checkConfig = 2;
|
opt->checkConfig = true;
|
||||||
|
opt->dumpConfig = true;
|
||||||
break;
|
break;
|
||||||
case O_POLINT: // --pollinterval=5
|
case O_POLINT: // --pollinterval=5
|
||||||
opt->pollInterval = parseInt(arg, 10, 0, 3600, result);
|
opt->pollInterval = parseInt(arg, 10, 0, 3600, result);
|
||||||
@@ -436,7 +431,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
|||||||
opt->logRawFile = arg;
|
opt->logRawFile = arg;
|
||||||
break;
|
break;
|
||||||
case O_RAWSIZ: // --lograwdatasize=100
|
case O_RAWSIZ: // --lograwdatasize=100
|
||||||
opt->logRawSize = (unsigned int)parseInt(arg, 10, 1, 1000000, result);
|
opt->logRawSize = parseInt(arg, 10, 1, 1000000, result);
|
||||||
if (result != RESULT_OK) {
|
if (result != RESULT_OK) {
|
||||||
argp_error(state, "invalid lograwdatasize");
|
argp_error(state, "invalid lograwdatasize");
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@@ -456,7 +451,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
|||||||
opt->dumpFile = arg;
|
opt->dumpFile = arg;
|
||||||
break;
|
break;
|
||||||
case O_DMPSIZ: // --dumpsize=100
|
case O_DMPSIZ: // --dumpsize=100
|
||||||
opt->dumpSize = (unsigned int)parseInt(arg, 10, 1, 1000000, result);
|
opt->dumpSize = parseInt(arg, 10, 1, 1000000, result);
|
||||||
if (result != RESULT_OK) {
|
if (result != RESULT_OK) {
|
||||||
argp_error(state, "invalid dumpsize");
|
argp_error(state, "invalid dumpsize");
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@@ -695,11 +690,11 @@ static bool readTemplates(const string path, const string extension, bool availa
|
|||||||
result_t result = templates->readFromFile(path+"/_templates"+extension, verbose);
|
result_t result = templates->readFromFile(path+"/_templates"+extension, verbose);
|
||||||
if (result == RESULT_OK) {
|
if (result == RESULT_OK) {
|
||||||
logInfo(lf_main, "read templates in %s", path.c_str());
|
logInfo(lf_main, "read templates in %s", path.c_str());
|
||||||
} else {
|
return true;
|
||||||
|
}
|
||||||
logError(lf_main, "error reading templates in %s: %s, last error: %s", path.c_str(), getResultCode(result),
|
logError(lf_main, "error reading templates in %s: %s, last error: %s", path.c_str(), getResultCode(result),
|
||||||
templates->getLastError().c_str());
|
templates->getLastError().c_str());
|
||||||
}
|
return false;
|
||||||
return templates;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -723,7 +718,7 @@ static result_t readConfigFiles(const string path, const string extension, Messa
|
|||||||
for (vector<string>::iterator it = files.begin(); it != files.end(); it++) {
|
for (vector<string>::iterator it = files.begin(); it != files.end(); it++) {
|
||||||
string name = *it;
|
string name = *it;
|
||||||
logInfo(lf_main, "reading file %s", name.c_str());
|
logInfo(lf_main, "reading file %s", name.c_str());
|
||||||
result_t result = messages->readFromFile(name, verbose);
|
result = messages->readFromFile(name, verbose);
|
||||||
if (result != RESULT_OK) {
|
if (result != RESULT_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -732,7 +727,7 @@ static result_t readConfigFiles(const string path, const string extension, Messa
|
|||||||
for (vector<string>::iterator it = dirs.begin(); it != dirs.end(); it++) {
|
for (vector<string>::iterator it = dirs.begin(); it != dirs.end(); it++) {
|
||||||
string name = *it;
|
string name = *it;
|
||||||
logInfo(lf_main, "reading dir %s", name.c_str());
|
logInfo(lf_main, "reading dir %s", name.c_str());
|
||||||
result_t result = readConfigFiles(name, extension, messages, true, verbose);
|
result = readConfigFiles(name, extension, messages, true, verbose);
|
||||||
if (result != RESULT_OK) {
|
if (result != RESULT_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -824,7 +819,7 @@ result_t loadScanConfigFile(MessageMap* messages, unsigned char address, SymbolS
|
|||||||
}
|
}
|
||||||
DataFieldSet* identFields = DataFieldSet::getIdentFields();
|
DataFieldSet* identFields = DataFieldSet::getIdentFields();
|
||||||
string path, prefix, ident; // path: cfgpath/MANUFACTURER, prefix: ZZ., ident: C[C[C[C[C]]]], SW: xxxx, HW: xxxx
|
string path, prefix, ident; // path: cfgpath/MANUFACTURER, prefix: ZZ., ident: C[C[C[C[C]]]], SW: xxxx, HW: xxxx
|
||||||
unsigned int sw, hw;
|
unsigned int sw = 0, hw = 0;
|
||||||
ostringstream out;
|
ostringstream out;
|
||||||
unsigned char offset = 0;
|
unsigned char offset = 0;
|
||||||
unsigned char field = 0;
|
unsigned char field = 0;
|
||||||
@@ -1040,7 +1035,7 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result == RESULT_OK && opt.checkConfig > 1) {
|
if (result == RESULT_OK && opt.dumpConfig) {
|
||||||
logNotice(lf_main, "configuration dump:");
|
logNotice(lf_main, "configuration dump:");
|
||||||
s_messageMap->dump(cout, true);
|
s_messageMap->dump(cout, true);
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-7
@@ -44,16 +44,17 @@ struct options {
|
|||||||
/** the initial address to scan for scanconfig
|
/** the initial address to scan for scanconfig
|
||||||
* (@a ESC=none, 0xfe=broadcast ident, @a SYN=full scan, else: single slave address). */
|
* (@a ESC=none, 0xfe=broadcast ident, @a SYN=full scan, else: single slave address). */
|
||||||
unsigned char initialScan;
|
unsigned char initialScan;
|
||||||
int checkConfig; //!< check CSV config files ( != 0) and optionally dump (2), then stop
|
bool checkConfig; //!< check CSV config files, then stop
|
||||||
int pollInterval; //!< poll interval in seconds, 0 to disable [5]
|
bool dumpConfig; //!< dump CSV config files, then stop
|
||||||
|
unsigned int pollInterval; //!< poll interval in seconds, 0 to disable [5]
|
||||||
|
|
||||||
unsigned char address; //!< own bus address [31]
|
unsigned char address; //!< own bus address [31]
|
||||||
bool answer; //!< answer to requests from other masters
|
bool answer; //!< answer to requests from other masters
|
||||||
int acquireTimeout; //!< bus acquisition timeout in us [9400]
|
unsigned int acquireTimeout; //!< bus acquisition timeout in us [9400]
|
||||||
int acquireRetries; //!< number of retries for bus acquisition [3]
|
unsigned int acquireRetries; //!< number of retries for bus acquisition [3]
|
||||||
int sendRetries; //!< number of retries for failed sends [2]
|
unsigned int sendRetries; //!< number of retries for failed sends [2]
|
||||||
int receiveTimeout; //!< timeout for receiving answer from slave in us [25000]
|
unsigned int receiveTimeout; //!< timeout for receiving answer from slave in us [25000]
|
||||||
int masterCount; //!< expected number of masters for arbitration [0]
|
unsigned int masterCount; //!< expected number of masters for arbitration [0]
|
||||||
bool generateSyn; //!< enable AUTO-SYN symbol generation
|
bool generateSyn; //!< enable AUTO-SYN symbol generation
|
||||||
|
|
||||||
bool foreground; //!< run in foreground
|
bool foreground; //!< run in foreground
|
||||||
|
|||||||
Reference in New Issue
Block a user