diff --git a/make_debian.sh b/make_debian.sh index fc13e014..9d666d70 100755 --- a/make_debian.sh +++ b/make_debian.sh @@ -95,7 +95,7 @@ if [ -n "$RUNTEST" ]; then echo "test failed" 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 (cd src/lib/ebus/test && make >/dev/null && ./test_filereader && ./test_data && ./test_message && ./test_symbol) || testdie fi diff --git a/src/ebusd/main.cpp b/src/ebusd/main.cpp index f7115927..07b3b416 100644 --- a/src/ebusd/main.cpp +++ b/src/ebusd/main.cpp @@ -93,6 +93,7 @@ static struct options opt = { OF_NONE, // dumpConfig 5, // pollInterval false, // injectMessages + false, // stopAfterInject 0x31, // address false, // answer @@ -205,8 +206,8 @@ static const struct argp_option argpoptions[] = { {"dumpconfig", O_DMPCFG, "FORMAT", OPTION_ARG_OPTIONAL, "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 }, - {"inject", 'i', nullptr, 0, "Inject remaining arguments as already seen messages (e.g. " - "\"FF08070400/0AB5454850303003277201\")", 0 }, + {"inject", 'i', "stop", OPTION_ARG_OPTIONAL, "Inject remaining arguments as already seen messages (e.g. " + "\"FF08070400/0AB5454850303003277201\"), optionally stop afterwards", 0 }, {nullptr, 0, nullptr, 0, "eBUS options:", 3 }, {"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; break; case O_CHKCFG: // --checkconfig + if (opt->injectMessages) { + argp_error(state, "invalid checkconfig"); + return EINVAL; + } opt->checkConfig = true; break; case O_DMPCFG: // --dumpconfig[=json|csv] + if (opt->injectMessages) { + argp_error(state, "invalid checkconfig"); + return EINVAL; + } opt->dumpConfig = OF_DEFINITION; if (!arg || arg[0] == 0 || strcmp("csv", arg) == 0) { // no further flags @@ -374,12 +383,13 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) { return EINVAL; } break; - case 'i': // --inject - if (opt->injectMessages) { + case 'i': // --inject[=stop] + if (opt->injectMessages || opt->checkConfig) { argp_error(state, "invalid inject"); return EINVAL; } opt->injectMessages = true; + opt->stopAfterInject = arg && strcmp("stop", arg) == 0; break; // eBUS options: @@ -1290,7 +1300,7 @@ int main(int argc, char* argv[]) { if (err != 0 && idx == -1) { // ignore args for non-arg boolean options 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; @@ -1418,6 +1428,10 @@ int main(int argc, char* argv[]) { } busHandler->injectMessage(master, slave); } + if (opt.stopAfterInject) { + shutdown(); + return 0; + } } s_mainLoop->start("mainloop"); diff --git a/src/ebusd/main.h b/src/ebusd/main.h index 66945d39..756c4437 100644 --- a/src/ebusd/main.h +++ b/src/ebusd/main.h @@ -51,6 +51,7 @@ struct options { OutputFormat dumpConfig; //!< dump config files, then stop unsigned int pollInterval; //!< poll interval in seconds, 0 to disable [5] bool injectMessages; //!< inject remaining arguments as already seen messages + bool stopAfterInject; //!< only inject messages once, then stop symbol_t address; //!< own bus address [31] bool answer; //!< answer to requests from other masters