forked from test34/can_wizard
refactoring cmd
This commit is contained in:
parent
e98c330b67
commit
c2ec00dcf2
2 changed files with 14 additions and 15 deletions
|
@ -36,7 +36,7 @@ static struct {
|
|||
static struct {
|
||||
struct arg_str *speed;
|
||||
struct arg_str *filters;
|
||||
struct arg_str *autorecover;
|
||||
struct arg_lit *autorecover;
|
||||
struct arg_str *mode;
|
||||
struct arg_end *end;
|
||||
} canup_args;
|
||||
|
@ -196,10 +196,10 @@ static void register_cansend(void) {
|
|||
|
||||
static void register_canup(void) {
|
||||
|
||||
canup_args.speed = arg_str1(NULL, NULL, "<speed>", "CAN bus speed, in bps. See helo for supported speeds.");
|
||||
canup_args.mode = arg_str0("m", "mode", "<normal|no_ack|listen_only", "Set CAN mode. Normal (default), No Ack (for self-testing) or Listen Only (to prevent transmitting, for monitoring).");
|
||||
canup_args.speed = arg_str1(NULL, NULL, "<speed>", "CAN bus speed, in bps. See help for supported speeds.");
|
||||
canup_args.mode = arg_str0("m", "mode", "<normal|no_ack|listen_only>", "Set CAN mode. Normal (default), No Ack (for self-testing) or Listen Only (to prevent transmitting, for monitoring).");
|
||||
canup_args.filters = arg_str0("f", "filters", "<filters>", "CAN filters to receive only selected frames.");
|
||||
canup_args.autorecover = arg_str0("r", "auto-recovery", "<1|0>", "Set 1 to enable auto-recovery of CAN bus if case of bus-off event, disabled by default.");
|
||||
canup_args.autorecover = arg_litn("r", "auto-recovery", 0, 1, "Set to enable auto-recovery of CAN bus if case of bus-off event");
|
||||
canup_args.end = arg_end(4);
|
||||
|
||||
const esp_console_cmd_t cmd = {
|
||||
|
|
|
@ -17,31 +17,30 @@ void register_utils_commands(void) {
|
|||
}
|
||||
|
||||
static struct {
|
||||
struct arg_str *enable;
|
||||
struct arg_lit *disable;
|
||||
struct arg_end *end;
|
||||
} timestamp_args;
|
||||
|
||||
static int timestamp(int argc, char **argv) {
|
||||
bool en = true;
|
||||
int nerrors = arg_parse(argc, argv, (void **) ×tamp_args);
|
||||
if (nerrors == 0) {
|
||||
const char *arg_str_ptr = timestamp_args.enable->sval[0];
|
||||
if (arg_str_ptr[0] == 'd') en = false;
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, timestamp_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
if (en) {
|
||||
print_w_clr_time("Enabled timestamps!", LOG_COLOR_PURPLE, true);
|
||||
timestamp_enabled = true;
|
||||
} else {
|
||||
if (timestamp_args.disable->count) {
|
||||
print_w_clr_time("Disabled timestamps!", LOG_COLOR_PURPLE, true);
|
||||
timestamp_enabled = false;
|
||||
} else {
|
||||
print_w_clr_time("Enabled timestamps!", LOG_COLOR_PURPLE, true);
|
||||
timestamp_enabled = true;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void register_timestamp(void) {
|
||||
|
||||
timestamp_args.enable = arg_str1(NULL, NULL, "<enable|disable>", "Enable by default, can be abbreviations.");
|
||||
timestamp_args.end = arg_end(2);
|
||||
timestamp_args.disable = arg_litn("d", "disable", 0, 1, "Set to disable timestamps.");
|
||||
timestamp_args.end = arg_end(1);
|
||||
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "timestamp",
|
||||
|
|
Loading…
Reference in a new issue