add option to stop after inject, check invalid combination of inject/check args
This commit is contained in:
+1
-1
@@ -95,7 +95,7 @@ if [ -n "$RUNTEST" ]; then
|
|||||||
echo "test failed"
|
echo "test failed"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
($RELEASE/usr/bin/ebusd -f -c src/lib/ebus/test -d /dev/null --checkconfig -i 10fe0900040000803e/ | egrep "received update-read broadcast test QQ=10: 0\.25$") || testdie
|
($RELEASE/usr/bin/ebusd -f -c src/lib/ebus/test -d /dev/null --inject=stop 10fe0900040000803e/ | egrep "received update-read broadcast test QQ=10: 0\.25$") || testdie
|
||||||
if [ "$RUNTEST" = "full" ]; then
|
if [ "$RUNTEST" = "full" ]; then
|
||||||
(cd src/lib/ebus/test && make >/dev/null && ./test_filereader && ./test_data && ./test_message && ./test_symbol) || testdie
|
(cd src/lib/ebus/test && make >/dev/null && ./test_filereader && ./test_data && ./test_message && ./test_symbol) || testdie
|
||||||
fi
|
fi
|
||||||
|
|||||||
+19
-5
@@ -93,6 +93,7 @@ static struct options opt = {
|
|||||||
OF_NONE, // dumpConfig
|
OF_NONE, // dumpConfig
|
||||||
5, // pollInterval
|
5, // pollInterval
|
||||||
false, // injectMessages
|
false, // injectMessages
|
||||||
|
false, // stopAfterInject
|
||||||
|
|
||||||
0x31, // address
|
0x31, // address
|
||||||
false, // answer
|
false, // answer
|
||||||
@@ -205,8 +206,8 @@ static const struct argp_option argpoptions[] = {
|
|||||||
{"dumpconfig", O_DMPCFG, "FORMAT", OPTION_ARG_OPTIONAL,
|
{"dumpconfig", O_DMPCFG, "FORMAT", OPTION_ARG_OPTIONAL,
|
||||||
"Check and dump config files in FORMAT (\"json\" or \"csv\"), then stop", 0 },
|
"Check and dump config files in FORMAT (\"json\" or \"csv\"), then stop", 0 },
|
||||||
{"pollinterval", O_POLINT, "SEC", 0, "Poll for data every SEC seconds (0=disable) [5]", 0 },
|
{"pollinterval", O_POLINT, "SEC", 0, "Poll for data every SEC seconds (0=disable) [5]", 0 },
|
||||||
{"inject", 'i', nullptr, 0, "Inject remaining arguments as already seen messages (e.g. "
|
{"inject", 'i', "stop", OPTION_ARG_OPTIONAL, "Inject remaining arguments as already seen messages (e.g. "
|
||||||
"\"FF08070400/0AB5454850303003277201\")", 0 },
|
"\"FF08070400/0AB5454850303003277201\"), optionally stop afterwards", 0 },
|
||||||
|
|
||||||
{nullptr, 0, nullptr, 0, "eBUS options:", 3 },
|
{nullptr, 0, nullptr, 0, "eBUS options:", 3 },
|
||||||
{"address", 'a', "ADDR", 0, "Use ADDR as own bus address [31]", 0 },
|
{"address", 'a', "ADDR", 0, "Use ADDR as own bus address [31]", 0 },
|
||||||
@@ -349,9 +350,17 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
|||||||
opt->preferLanguage = arg;
|
opt->preferLanguage = arg;
|
||||||
break;
|
break;
|
||||||
case O_CHKCFG: // --checkconfig
|
case O_CHKCFG: // --checkconfig
|
||||||
|
if (opt->injectMessages) {
|
||||||
|
argp_error(state, "invalid checkconfig");
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
opt->checkConfig = true;
|
opt->checkConfig = true;
|
||||||
break;
|
break;
|
||||||
case O_DMPCFG: // --dumpconfig[=json|csv]
|
case O_DMPCFG: // --dumpconfig[=json|csv]
|
||||||
|
if (opt->injectMessages) {
|
||||||
|
argp_error(state, "invalid checkconfig");
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
opt->dumpConfig = OF_DEFINITION;
|
opt->dumpConfig = OF_DEFINITION;
|
||||||
if (!arg || arg[0] == 0 || strcmp("csv", arg) == 0) {
|
if (!arg || arg[0] == 0 || strcmp("csv", arg) == 0) {
|
||||||
// no further flags
|
// no further flags
|
||||||
@@ -374,12 +383,13 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
|||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'i': // --inject
|
case 'i': // --inject[=stop]
|
||||||
if (opt->injectMessages) {
|
if (opt->injectMessages || opt->checkConfig) {
|
||||||
argp_error(state, "invalid inject");
|
argp_error(state, "invalid inject");
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
opt->injectMessages = true;
|
opt->injectMessages = true;
|
||||||
|
opt->stopAfterInject = arg && strcmp("stop", arg) == 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// eBUS options:
|
// eBUS options:
|
||||||
@@ -1290,7 +1300,7 @@ int main(int argc, char* argv[]) {
|
|||||||
if (err != 0 && idx == -1) { // ignore args for non-arg boolean options
|
if (err != 0 && idx == -1) { // ignore args for non-arg boolean options
|
||||||
logError(lf_main, "invalid/unknown argument in env: %s", envopt);
|
logError(lf_main, "invalid/unknown argument in env: %s", envopt);
|
||||||
}
|
}
|
||||||
opt.injectMessages = false; // restore
|
opt.injectMessages = false; // restore (was not parsed from cmdline args yet)
|
||||||
}
|
}
|
||||||
|
|
||||||
int arg_index = -1;
|
int arg_index = -1;
|
||||||
@@ -1418,6 +1428,10 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
busHandler->injectMessage(master, slave);
|
busHandler->injectMessage(master, slave);
|
||||||
}
|
}
|
||||||
|
if (opt.stopAfterInject) {
|
||||||
|
shutdown();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
s_mainLoop->start("mainloop");
|
s_mainLoop->start("mainloop");
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ struct options {
|
|||||||
OutputFormat dumpConfig; //!< dump config files, then stop
|
OutputFormat dumpConfig; //!< dump config files, then stop
|
||||||
unsigned int pollInterval; //!< poll interval in seconds, 0 to disable [5]
|
unsigned int pollInterval; //!< poll interval in seconds, 0 to disable [5]
|
||||||
bool injectMessages; //!< inject remaining arguments as already seen messages
|
bool injectMessages; //!< inject remaining arguments as already seen messages
|
||||||
|
bool stopAfterInject; //!< only inject messages once, then stop
|
||||||
|
|
||||||
symbol_t address; //!< own bus address [31]
|
symbol_t address; //!< own bus address [31]
|
||||||
bool answer; //!< answer to requests from other masters
|
bool answer; //!< answer to requests from other masters
|
||||||
|
|||||||
Reference in New Issue
Block a user