From 20a8576106fbdff3610a6a15f0eb5b81b17d0dec Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Sat, 10 Jan 2026 15:25:55 -0600 Subject: [PATCH] Bugfixes. --- components/Console/Console.c | 50 +++++++++--------------------------- 1 file changed, 12 insertions(+), 38 deletions(-) diff --git a/components/Console/Console.c b/components/Console/Console.c index 8790cb7..4f2be68 100644 --- a/components/Console/Console.c +++ b/components/Console/Console.c @@ -44,11 +44,9 @@ typedef struct } tag_entry_t; static esp_log_level_t Saved_Global_Level = ESP_LOG_INFO; -static tag_entry_t Tag_Table[MAX_TAGS]; +static tag_entry_t Tag_Table[MAX_TAGS] = {0}; static size_t Tag_Count = 0; -/* ---------------- Utility ---------------- */ - static bool parse_level(const char *s, esp_log_level_t *out) { if (!strcmp(s, "none")) @@ -89,19 +87,6 @@ static const char *level_str(esp_log_level_t lvl) } } -static void normalize_tag(char *dst, const char *src) -{ - size_t i; - for (i = 0; i < MAX_TAGLEN - 1 && src[i]; i++) - { - //dst[i] = toupper((unsigned char)src[i]); - dst[i] = src[i]; - } - dst[i] = 0; -} - -/* ---------------- NVS ---------------- */ - static void nvs_save(void) { nvs_handle_t h; @@ -167,8 +152,6 @@ static void log_config_load(void) nvs_close(h); } -/* ---------------- Tag table ---------------- */ - static void clear_tag_levels(void) { esp_log_level_t def = esp_log_get_default_level(); @@ -183,7 +166,7 @@ static bool set_tag_level(const char *tag, esp_log_level_t level) { for (size_t i = 0; i < Tag_Count; i++) { - if (!strcmp(Tag_Table[i].tag, tag)) + if (Tag_Table[i].tag[0] != '\0' && !strcmp(Tag_Table[i].tag, tag)) { Tag_Table[i].level = level; return true; @@ -200,14 +183,11 @@ static bool set_tag_level(const char *tag, esp_log_level_t level) return true; } -/* ---------------- Command helpers ---------------- */ - static void print_usage(void) { printf( "Usage:\n" " log show\n" - " log clear\n" " log reset\n" " log off | on\n" " log \n" @@ -237,14 +217,6 @@ static int log_cmd_show(void) return 0; } -static int log_cmd_clear(void) -{ - clear_tag_levels(); - nvs_clear_tags(); - printf("All tag overrides cleared\n"); - return 0; -} - static int log_cmd_reset(void) { esp_log_level_set("*", ESP_LOG_INFO); @@ -275,8 +247,16 @@ static int log_cmd_on(void) static int log_cmd_tag(int argc, char **argv) { + if (argc < 3) + { + printf("Usage: log tag [level|off]\n"); + return 0; + } + + // Ensure tag is null-terminated and within bounds char tag[MAX_TAGLEN]; - normalize_tag(tag, argv[2]); + strncpy(tag, argv[2], MAX_TAGLEN - 1); + tag[MAX_TAGLEN - 1] = '\0'; if (argc == 3) { @@ -325,8 +305,6 @@ static int log_cmd_set_global(const char *lvl) return 0; } -/* ---------------- Dispatcher ---------------- */ - static int cmd_log(int argc, char **argv) { if (argc < 2) @@ -337,8 +315,6 @@ static int cmd_log(int argc, char **argv) if (!strcmp(argv[1], "show")) return log_cmd_show(); - if (!strcmp(argv[1], "clear")) - return log_cmd_clear(); if (!strcmp(argv[1], "reset")) return log_cmd_reset(); if (!strcmp(argv[1], "off")) @@ -351,8 +327,6 @@ static int cmd_log(int argc, char **argv) return log_cmd_set_global(argv[1]); } -/* ---------------- Registration ---------------- */ - static void log_completion(const char *buf, linenoiseCompletions *lc) { if (!strncmp(buf, "log", 3)) @@ -399,4 +373,4 @@ void Initialize_Console(void) ESP_ERROR_CHECK( esp_console_new_repl_uart(&hw_cfg, &repl_cfg, &repl)); ESP_ERROR_CHECK(esp_console_start_repl(repl)); -} +} \ No newline at end of file