From cc79d4e954dfde529bdc47a7f301b6b2b6b873af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D0=BB=D0=B0=20=D0=93=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D1=83=D1=88=D0=BA=D0=BE?= Date: Tue, 28 Nov 2023 14:24:17 +0300 Subject: [PATCH] add timestamp control --- main/CMakeLists.txt | 1 + main/cmd_utils.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ main/cmd_utils.h | 8 +++++++ main/console.c | 2 ++ main/xvprintf.c | 2 +- 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 main/cmd_utils.c create mode 100644 main/cmd_utils.h 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);