make port in device string optional, updated help, formatting

This commit is contained in:
John
2024-03-09 10:10:16 +01:00
parent c063fb3bff
commit 393c9f81e5
6 changed files with 21 additions and 21 deletions
+1 -1
View File
@@ -256,7 +256,7 @@ int main(int argc, char* argv[], char* envp[]) {
} }
if (s_opt.logAreas != -1 || s_opt.logLevel != ll_COUNT) { if (s_opt.logAreas != -1 || s_opt.logLevel != ll_COUNT) {
setFacilitiesLogLevel(1<<ll_COUNT, ll_none); setFacilitiesLogLevel(1 << ll_COUNT, ll_none);
setFacilitiesLogLevel(s_opt.logAreas, s_opt.logLevel); setFacilitiesLogLevel(s_opt.logAreas, s_opt.logLevel);
} }
+2 -2
View File
@@ -37,7 +37,7 @@ namespace ebusd {
/** A structure holding all program options. */ /** A structure holding all program options. */
typedef struct options { typedef struct options {
const char* device; //!< eBUS device (serial device or [udp:]ip:port) [/dev/ttyUSB0] const char* device; //!< eBUS device (serial device or [udp:]ip[:port]) [/dev/ttyUSB0]
bool noDeviceCheck; //!< skip serial eBUS device test bool noDeviceCheck; //!< skip serial eBUS device test
bool readOnly; //!< read-only access to the device bool readOnly; //!< read-only access to the device
bool initialSend; //!< send an initial escape symbol after connecting device bool initialSend; //!< send an initial escape symbol after connecting device
@@ -79,7 +79,7 @@ typedef struct options {
const char* accessLevel; //!< default access level const char* accessLevel; //!< default access level
const char* aclFile; //!< ACL file name const char* aclFile; //!< ACL file name
bool foreground; //!< run in foreground bool foreground; //!< run in foreground
bool enableHex; //!< enable hex command bool enableHex; //!< enable hex/inject/answer commands
bool enableDefine; //!< enable define command bool enableDefine; //!< enable define command
const char* pidFile; //!< PID file name [/var/run/ebusd.pid] const char* pidFile; //!< PID file name [/var/run/ebusd.pid]
uint16_t port; //!< port to listen for command line connections [8888] uint16_t port; //!< port to listen for command line connections [8888]
+4 -4
View File
@@ -143,7 +143,7 @@ static const argDef argDefs[] = {
{"device", 'd', "DEV", 0, "Use DEV as eBUS device (" {"device", 'd', "DEV", 0, "Use DEV as eBUS device ("
"prefix \"ens:\" for enhanced high speed device or " "prefix \"ens:\" for enhanced high speed device or "
"\"enh:\" for enhanced device, with " "\"enh:\" for enhanced device, with "
"\"IP:PORT\" for network device or " "\"IP[:PORT]\" for network device or "
"\"DEVICE\" for serial device" "\"DEVICE\" for serial device"
") [/dev/ttyUSB0]"}, ") [/dev/ttyUSB0]"},
{"nodevicecheck", 'n', nullptr, 0, "Skip serial eBUS device test"}, {"nodevicecheck", 'n', nullptr, 0, "Skip serial eBUS device test"},
@@ -193,7 +193,7 @@ static const argDef argDefs[] = {
{"accesslevel", O_ACLDEF, "LEVEL", 0, "Set default access level to LEVEL (\"*\" for everything) [\"\"]"}, {"accesslevel", O_ACLDEF, "LEVEL", 0, "Set default access level to LEVEL (\"*\" for everything) [\"\"]"},
{"aclfile", O_ACLFIL, "FILE", 0, "Read access control list from FILE"}, {"aclfile", O_ACLFIL, "FILE", 0, "Read access control list from FILE"},
{"foreground", 'f', nullptr, 0, "Run in foreground"}, {"foreground", 'f', nullptr, 0, "Run in foreground"},
{"enablehex", O_HEXCMD, nullptr, 0, "Enable hex command"}, {"enablehex", O_HEXCMD, nullptr, 0, "Enable hex/inject/answer commands"},
{"enabledefine", O_DEFCMD, nullptr, 0, "Enable define command"}, {"enabledefine", O_DEFCMD, nullptr, 0, "Enable define command"},
{"pidfile", O_PIDFIL, "FILE", 0, "PID file name (only for daemon) [" PACKAGE_PIDFILE "]"}, {"pidfile", O_PIDFIL, "FILE", 0, "PID file name (only for daemon) [" PACKAGE_PIDFILE "]"},
{"port", 'p', "PORT", 0, "Listen for command line connections on PORT [8888]"}, {"port", 'p', "PORT", 0, "Listen for command line connections on PORT [8888]"},
@@ -205,11 +205,11 @@ static const argDef argDefs[] = {
{nullptr, 0, nullptr, 0, "Log options:"}, {nullptr, 0, nullptr, 0, "Log options:"},
{"logfile", 'l', "FILE", 0, "Write log to FILE (only for daemon, empty string for using syslog) [" {"logfile", 'l', "FILE", 0, "Write log to FILE (only for daemon, empty string for using syslog) ["
PACKAGE_LOGFILE "]"}, PACKAGE_LOGFILE "]"},
{"log", O_LOG, "AREAS:LEVEL", 0, "Only write log for matching AREA(S) below or equal to LEVEL" {"log", O_LOG, "AREAS:LEVEL", 0, "Only write log for matching AREA(S) up to LEVEL"
" (alternative to --logareas/--logevel, may be used multiple times) [all:notice]"}, " (alternative to --logareas/--logevel, may be used multiple times) [all:notice]"},
{"logareas", O_LOGARE, "AREAS", 0, "Only write log for matching AREA(S): main|network|bus|update|other" {"logareas", O_LOGARE, "AREAS", 0, "Only write log for matching AREA(S): main|network|bus|update|other"
"|all [all]"}, "|all [all]"},
{"loglevel", O_LOGLEV, "LEVEL", 0, "Only write log below or equal to LEVEL: error|notice|info|debug" {"loglevel", O_LOGLEV, "LEVEL", 0, "Only write log up to LEVEL: error|notice|info|debug"
" [notice]"}, " [notice]"},
{nullptr, 0, nullptr, 0, "Raw logging options:"}, {nullptr, 0, nullptr, 0, "Raw logging options:"},
+1 -2
View File
@@ -1261,8 +1261,7 @@ result_t MainLoop::executeAnswer(const vector<string>& args, ostringstream* ostr
} else if (dstAddress == SYN) { } else if (dstAddress == SYN) {
dstAddress = master ? m_address : getSlaveAddress(m_address); dstAddress = master ? m_address : getSlaveAddress(m_address);
} }
if (!m_protocol->setAnswer(srcAddress, dstAddress, id[0], id[1], id.data()+2 if (!m_protocol->setAnswer(srcAddress, dstAddress, id[0], id[1], id.data()+2, id.size()-2, answer)) {
, id.size()-2, answer)) {
return RESULT_ERR_INVALID_ARG; return RESULT_ERR_INVALID_ARG;
} }
return RESULT_OK; return RESULT_OK;
+7 -6
View File
@@ -70,27 +70,28 @@ ProtocolHandler* ProtocolHandler::create(const ebus_protocol_config_t config,
} }
} }
Transport* transport; Transport* transport;
if (strchr(name, '/') == nullptr && strchr(name, ':') != nullptr) { if (strchr(name, '/') == nullptr || strchr(name, ':') != nullptr) {
char* in = strdup(name); char* in = strdup(name);
bool udp = false; bool udp = false;
char* addrpos = in; char* addrpos = in;
char* portpos = strchr(addrpos, ':'); char* portpos = strchr(addrpos, ':');
// support tcp:<ip>:<port> and udp:<ip>:<port> // support tcp:<ip>[:<port>] and udp:<ip>[:<port>]
if (portpos == addrpos+3 && (strncmp(addrpos, "tcp", 3) == 0 || (udp=(strncmp(addrpos, "udp", 3) == 0)))) { if (portpos == addrpos+3 && (strncmp(addrpos, "tcp", 3) == 0 || (udp=(strncmp(addrpos, "udp", 3) == 0)))) {
addrpos += 4; addrpos += 4;
portpos = strchr(addrpos, ':'); portpos = strchr(addrpos, ':');
} }
uint16_t port;
if (portpos == nullptr) { if (portpos == nullptr) {
free(in); port = 9999;
return nullptr; // invalid protocol or missing port } else {
}
result_t result = RESULT_OK; result_t result = RESULT_OK;
uint16_t port = (uint16_t)parseInt(portpos+1, 10, 1, 65535, &result); port = (uint16_t)parseInt(portpos+1, 10, 1, 65535, &result);
if (result != RESULT_OK) { if (result != RESULT_OK) {
free(in); free(in);
return nullptr; // invalid port return nullptr; // invalid port
} }
*portpos = 0; *portpos = 0;
}
char* hostOrIp = strdup(addrpos); char* hostOrIp = strdup(addrpos);
free(in); free(in);
transport = new NetworkTransport(name, config.extraLatency, hostOrIp, port, udp); transport = new NetworkTransport(name, config.extraLatency, hostOrIp, port, udp);
+1 -1
View File
@@ -56,7 +56,7 @@ namespace ebusd {
/** settings for the eBUS protocol handler. */ /** settings for the eBUS protocol handler. */
typedef struct ebus_protocol_config { typedef struct ebus_protocol_config {
/** eBUS device string (serial device or [udp:]ip:port) with optional protocol prefix (enh: or ens:). */ /** eBUS device string (serial device or [udp:]ip[:port]) with optional protocol prefix (enh: or ens:). */
const char* device; const char* device;
/** whether to skip serial eBUS device test. */ /** whether to skip serial eBUS device test. */
bool noDeviceCheck; bool noDeviceCheck;