diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index af54de9..1ae9e21 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -6,6 +6,7 @@ set(COMPONENT_SRCS "fs.c" "xvprintf.c" "cmd_can.c" + "cmd_utils.c" ) set(COMPONENT_ADD_INCLUDEDIRS diff --git a/main/cmd_utils.c b/main/cmd_utils.c new file mode 100644 index 0000000..418ce56 --- /dev/null +++ b/main/cmd_utils.c @@ -0,0 +1,54 @@ +#include "cmd_utils.h" +#include "esp_log.h" +#include "inttypes.h" +#include "freertos/projdefs.h" +#include "string.h" +#include "esp_console.h" +#include "argtable3/argtable3.h" +#include "xvprintf.h" +#include +#include +#include + +static void register_timestamp(void); + +void register_utils_commands(void) { + register_timestamp(); +} + +static struct { + struct arg_str *enable; + 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 (en) { + print_w_clr_time("Enabled timestamps!", LOG_COLOR_PURPLE, true); + timestamp_enabled = true; + } else { + print_w_clr_time("Disabled timestamps!", LOG_COLOR_PURPLE, true); + timestamp_enabled = false; + } + return 0; +} + +static void register_timestamp(void) { + + timestamp_args.enable = arg_str1(NULL, NULL, "", "Enable by default, can be abbreviations."); + timestamp_args.end = arg_end(2); + + const esp_console_cmd_t cmd = { + .command = "timestamp", + .help = "Enable or disable timestamp in messages.", + .hint = NULL, + .func = ×tamp, + .argtable = ×tamp_args, + }; + ESP_ERROR_CHECK(esp_console_cmd_register(&cmd)); +} diff --git a/main/cmd_utils.h b/main/cmd_utils.h new file mode 100644 index 0000000..d29529d --- /dev/null +++ b/main/cmd_utils.h @@ -0,0 +1,8 @@ +#ifndef MAIN_CMD_UTILS_H +#define MAIN_CMD_UTILS_H + +// functions + +void register_utils_commands(void); + +#endif // MAIN_CMD_UTILS_H diff --git a/main/console.c b/main/console.c index 382a455..4558200 100644 --- a/main/console.c +++ b/main/console.c @@ -18,6 +18,7 @@ #include "driver/usb_serial_jtag.h" #include "cmd_system.h" #include "cmd_can.h" +#include "cmd_utils.h" #include "can.h" #include "fs.h" #include "xvprintf.h" @@ -210,4 +211,5 @@ void initialize_console(void) { esp_console_register_help_command(); register_system(); register_can_commands(); + register_utils_commands(); } diff --git a/main/xvprintf.c b/main/xvprintf.c index 5e321eb..1c45976 100644 --- a/main/xvprintf.c +++ b/main/xvprintf.c @@ -5,7 +5,7 @@ #include "esp_log.h" RingbufHandle_t can_messages; -bool timestamp_enabled = true; +bool timestamp_enabled = false; void init_tx_ringbuf() { can_messages = xRingbufferCreate(2200, RINGBUF_TYPE_NOSPLIT);