refactoring cmd

This commit is contained in:
Данила Горнушко 2023-11-28 15:49:01 +03:00
parent e98c330b67
commit c2ec00dcf2
2 changed files with 14 additions and 15 deletions

View file

@ -36,7 +36,7 @@ static struct {
static struct { static struct {
struct arg_str *speed; struct arg_str *speed;
struct arg_str *filters; struct arg_str *filters;
struct arg_str *autorecover; struct arg_lit *autorecover;
struct arg_str *mode; struct arg_str *mode;
struct arg_end *end; struct arg_end *end;
} canup_args; } canup_args;
@ -196,10 +196,10 @@ static void register_cansend(void) {
static void register_canup(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.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.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.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); canup_args.end = arg_end(4);
const esp_console_cmd_t cmd = { const esp_console_cmd_t cmd = {

View file

@ -17,31 +17,30 @@ void register_utils_commands(void) {
} }
static struct { static struct {
struct arg_str *enable; struct arg_lit *disable;
struct arg_end *end; struct arg_end *end;
} timestamp_args; } timestamp_args;
static int timestamp(int argc, char **argv) { static int timestamp(int argc, char **argv) {
bool en = true;
int nerrors = arg_parse(argc, argv, (void **) &timestamp_args); int nerrors = arg_parse(argc, argv, (void **) &timestamp_args);
if (nerrors == 0) { if (nerrors != 0) {
const char *arg_str_ptr = timestamp_args.enable->sval[0]; arg_print_errors(stderr, timestamp_args.end, argv[0]);
if (arg_str_ptr[0] == 'd') en = false; return 1;
} }
if (en) { if (timestamp_args.disable->count) {
print_w_clr_time("Enabled timestamps!", LOG_COLOR_PURPLE, true);
timestamp_enabled = true;
} else {
print_w_clr_time("Disabled timestamps!", LOG_COLOR_PURPLE, true); print_w_clr_time("Disabled timestamps!", LOG_COLOR_PURPLE, true);
timestamp_enabled = false; timestamp_enabled = false;
} else {
print_w_clr_time("Enabled timestamps!", LOG_COLOR_PURPLE, true);
timestamp_enabled = true;
} }
return 0; return 0;
} }
static void register_timestamp(void) { static void register_timestamp(void) {
timestamp_args.enable = arg_str1(NULL, NULL, "<enable|disable>", "Enable by default, can be abbreviations."); timestamp_args.disable = arg_litn("d", "disable", 0, 1, "Set to disable timestamps.");
timestamp_args.end = arg_end(2); timestamp_args.end = arg_end(1);
const esp_console_cmd_t cmd = { const esp_console_cmd_t cmd = {
.command = "timestamp", .command = "timestamp",