make port in device string optional, updated help, formatting
This commit is contained in:
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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
|
||||
@@ -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]
|
||||
|
||||
@@ -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"},
|
||||
@@ -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]"},
|
||||
@@ -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:"},
|
||||
|
||||
@@ -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;
|
||||
|
||||
+12
-11
@@ -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
|
||||
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;
|
||||
}
|
||||
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
|
||||
}
|
||||
*portpos = 0;
|
||||
char* hostOrIp = strdup(addrpos);
|
||||
free(in);
|
||||
transport = new NetworkTransport(name, config.extraLatency, hostOrIp, port, udp);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user