From 36af7aa6fdbdd259fb18fa4610c6bf6e31994a96 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: Fri, 24 Nov 2023 08:30:27 +0300 Subject: [PATCH] remove extra code from cmd_system --- main/can.c | 10 +++++++++- main/cmd_system.c | 17 +---------------- main/cmd_system.h | 7 ------- main/console.c | 4 +++- 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/main/can.c b/main/can.c index 9a7aa38..d49cd1e 100644 --- a/main/can.c +++ b/main/can.c @@ -9,6 +9,7 @@ #include "sdkconfig.h" #include #include +#include #include "freertos/ringbuf.h" #include "xvprintf.h" @@ -72,6 +73,8 @@ void can_bus_off_check() { void can_task(void* arg) { twai_message_t rx_msg; + char byte_str[3]; + char data_bytes_str[20]; // ESP_ERROR_CHECK(esp_task_wdt_add(NULL)); for (;;) { // A Task shall never return or exit. // esp_task_wdt_reset(); @@ -80,7 +83,12 @@ void can_task(void* arg) { // TODO: add software filtering // if ((((rx_msg.identifier >> 8) & 0xFF) != CONFIG_DEVICE_ID) && (((rx_msg.identifier >> 8) & 0xFF) != 0xFF)) continue; // ESP_LOGI(LOG_TAG, "received can frame: %" PRIu32, rx_msg.identifier); - xprintf("received can frame: %" PRIu32 "\n", rx_msg.identifier); + data_bytes_str[0] = '\0'; + for (int i = 0; i < rx_msg.data_length_code; i++) { + sprintf(byte_str, "%02X", rx_msg.data[i]); + strcat(data_bytes_str, byte_str); + } + xprintf("received can frame: ID: %" PRIu32 " dlc: %d data: %s\n", rx_msg.identifier, rx_msg.data_length_code, data_bytes_str); } } diff --git a/main/cmd_system.c b/main/cmd_system.c index 145ff55..04ece50 100644 --- a/main/cmd_system.c +++ b/main/cmd_system.c @@ -1,12 +1,3 @@ -/* Console example — various system commands - - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ - #include #include #include @@ -40,7 +31,7 @@ static void register_tasks(void); #endif static void register_log_level(void); -void register_system_common(void) +void register_system(void) { register_free(); register_heap(); @@ -52,12 +43,6 @@ void register_system_common(void) register_log_level(); } - -void register_system(void) -{ - register_system_common(); -} - /* 'version' command */ static int get_version(int argc, char **argv) { diff --git a/main/cmd_system.h b/main/cmd_system.h index ccdac3f..a71ea4b 100644 --- a/main/cmd_system.h +++ b/main/cmd_system.h @@ -1,13 +1,6 @@ #ifndef MAIN_CMD_SYSTEM_H #define MAIN_CMD_SYSTEM_H -// Register all system functions void register_system(void); -// Register common system functions: "version", "restart", "free", "heap", "tasks" -void register_system_common(void); - -// Register deep and light sleep functions -void register_system_sleep(void); - #endif // MAIN_CMD_SYSTEM_H diff --git a/main/console.c b/main/console.c index 2c31dc2..dd56f98 100644 --- a/main/console.c +++ b/main/console.c @@ -33,7 +33,8 @@ char prompt[50]; static void get_prompt(char* prompt_buf) { static const char* text = "can_wizard > "; static const char* prompt_color = LOG_COLOR_E; - memset(prompt_buf,0,strlen(prompt_buf)); + // memset(prompt_buf,0,strlen(prompt_buf)); + prompt_buf[0] = '\0'; if (use_colors) { strcat(prompt_buf, prompt_color); strcat(prompt_buf, text); @@ -114,6 +115,7 @@ void console_task_interactive(void* arg) { } /* linenoise allocates line buffer on the heap, so need to free it */ linenoiseFree(line); + get_prompt(prompt); linenoiseEditStart(&ls, buf, console_config.max_cmdline_length, prompt); }