Skip to content

Commit

Permalink
make port in device string optional, updated help, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
john30 committed Mar 9, 2024
1 parent c063fb3 commit 393c9f8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/ebusd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ int main(int argc, char* argv[], char* envp[]) {
}

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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/ebusd/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace ebusd {

/** A structure holding all program 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 readOnly; //!< read-only access to the device
bool initialSend; //!< send an initial escape symbol after connecting device
Expand Down Expand Up @@ -79,7 +79,7 @@ typedef struct options {
const char* accessLevel; //!< default access level
const char* aclFile; //!< ACL file name
bool foreground; //!< run in foreground
bool enableHex; //!< enable hex command
bool enableHex; //!< enable hex/inject/answer commands
bool enableDefine; //!< enable define command
const char* pidFile; //!< PID file name [/var/run/ebusd.pid]
uint16_t port; //!< port to listen for command line connections [8888]
Expand Down
8 changes: 4 additions & 4 deletions src/ebusd/main_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static const argDef argDefs[] = {
{"device", 'd', "DEV", 0, "Use DEV as eBUS device ("
"prefix \"ens:\" for enhanced high speed device or "
"\"enh:\" for enhanced device, with "
"\"IP:PORT\" for network device or "
"\"IP[:PORT]\" for network device or "
"\"DEVICE\" for serial device"
") [/dev/ttyUSB0]"},
{"nodevicecheck", 'n', nullptr, 0, "Skip serial eBUS device test"},
Expand Down Expand Up @@ -193,7 +193,7 @@ static const argDef argDefs[] = {
{"accesslevel", O_ACLDEF, "LEVEL", 0, "Set default access level to LEVEL (\"*\" for everything) [\"\"]"},
{"aclfile", O_ACLFIL, "FILE", 0, "Read access control list from FILE"},
{"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"},
{"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]"},
Expand All @@ -205,11 +205,11 @@ static const argDef argDefs[] = {
{nullptr, 0, nullptr, 0, "Log options:"},
{"logfile", 'l', "FILE", 0, "Write log to FILE (only for daemon, empty string for using syslog) ["
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]"},
{"logareas", O_LOGARE, "AREAS", 0, "Only write log for matching AREA(S): main|network|bus|update|other"
"|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]"},

{nullptr, 0, nullptr, 0, "Raw logging options:"},
Expand Down
3 changes: 1 addition & 2 deletions src/ebusd/mainloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,8 +1261,7 @@ result_t MainLoop::executeAnswer(const vector<string>& args, ostringstream* ostr
} else if (dstAddress == SYN) {
dstAddress = master ? m_address : getSlaveAddress(m_address);
}
if (!m_protocol->setAnswer(srcAddress, dstAddress, id[0], id[1], id.data()+2
, id.size()-2, answer)) {
if (!m_protocol->setAnswer(srcAddress, dstAddress, id[0], id[1], id.data()+2, id.size()-2, answer)) {
return RESULT_ERR_INVALID_ARG;
}
return RESULT_OK;
Expand Down
23 changes: 12 additions & 11 deletions src/lib/ebus/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,28 @@ ProtocolHandler* ProtocolHandler::create(const ebus_protocol_config_t config,
}
}
Transport* transport;
if (strchr(name, '/') == nullptr && strchr(name, ':') != nullptr) {
if (strchr(name, '/') == nullptr || strchr(name, ':') != nullptr) {
char* in = strdup(name);
bool udp = false;
char* addrpos = in;
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)))) {
addrpos += 4;
portpos = strchr(addrpos, ':');
}
uint16_t port;
if (portpos == nullptr) {
free(in);
return nullptr; // invalid protocol or missing port
}
result_t result = RESULT_OK;
uint16_t port = (uint16_t)parseInt(portpos+1, 10, 1, 65535, &result);
if (result != RESULT_OK) {
free(in);
return nullptr; // invalid port
port = 9999;
} else {
result_t result = RESULT_OK;
port = (uint16_t)parseInt(portpos+1, 10, 1, 65535, &result);
if (result != RESULT_OK) {
free(in);
return nullptr; // invalid port
}
*portpos = 0;
}
*portpos = 0;
char* hostOrIp = strdup(addrpos);
free(in);
transport = new NetworkTransport(name, config.extraLatency, hostOrIp, port, udp);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ebus/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace ebusd {

/** settings for the eBUS protocol handler. */
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;
/** whether to skip serial eBUS device test. */
bool noDeviceCheck;
Expand Down

0 comments on commit 393c9f8

Please sign in to comment.