From fcab8f2b241b4418605029ec74d101d62984667d Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 19 Apr 2021 08:28:42 +0200 Subject: [PATCH] Hide YAML traces behind DEBUG_YAML --- radio/src/CMakeLists.txt | 5 +++++ radio/src/debug.h | 6 ++++++ radio/src/storage/yaml/yaml_parser.cpp | 20 ++++++++++---------- radio/src/storage/yaml/yaml_tree_walker.cpp | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/radio/src/CMakeLists.txt b/radio/src/CMakeLists.txt index 0d72f1aeb..6c10b140b 100644 --- a/radio/src/CMakeLists.txt +++ b/radio/src/CMakeLists.txt @@ -44,6 +44,7 @@ option(TEMPLATES "Model templates menu" OFF) option(TRACE_SIMPGMSPACE "Turn on traces in simpgmspace.cpp" ON) option(TRACE_LUA_INTERNALS "Turn on traces for Lua internals" OFF) option(DEBUG_WINDOWS "Turn on windows traces" OFF) +option(DEBUG_YAML "Turn on YAML traces" OFF) option(FRSKY_STICKS "Reverse sticks for FrSky sticks" OFF) option(NANO "Use nano newlib and binalloc") option(TEST_BUILD_WARNING "Warn this is a test build" OFF) @@ -377,6 +378,10 @@ if(DEBUG_WINDOWS) add_definitions(-DDEBUG_WINDOWS) endif() +if(DEBUG_YAML) + add_definitions(-DDEBUG_YAML) +endif() + if(FRSKY_STICKS) add_definitions(-DFRSKY_STICKS) endif() diff --git a/radio/src/debug.h b/radio/src/debug.h index 7eed0b864..d616f7f24 100644 --- a/radio/src/debug.h +++ b/radio/src/debug.h @@ -93,6 +93,12 @@ uint8_t aux2SerialTracesEnabled(); #define TRACE_LUA_INTERNALS_WITH_LINEINFO(L, f_, ...) #endif +#if defined(DEBUG_YAML) +#define TRACE_YAML(f_, ...) TRACE(f_, ##__VA_ARGS__) +#else +#define TRACE_YAML(f_, ...) +#endif + #if defined(DEBUG) && !defined(SIMU) #define TIME_MEASURE_START(id) uint16_t t0 ## id = getTmr2MHz() #define TIME_MEASURE_STOP(id) TRACE("Measure(" # id ") = %.1fus", float((uint16_t)(getTmr2MHz() - t0 ## id))/2) diff --git a/radio/src/storage/yaml/yaml_parser.cpp b/radio/src/storage/yaml/yaml_parser.cpp index bc0b0a224..69794505f 100644 --- a/radio/src/storage/yaml/yaml_parser.cpp +++ b/radio/src/storage/yaml/yaml_parser.cpp @@ -80,7 +80,7 @@ YamlParser::parse(const char* buffer, unsigned int size) if(s_len < MAX_STR) \ s[s_len++] = c; \ else { \ - TRACE("STRING_OVERFLOW"); \ + TRACE_YAML("STRING_OVERFLOW"); \ return STRING_OVERFLOW; \ } \ } @@ -109,7 +109,7 @@ YamlParser::parse(const char* buffer, unsigned int size) // go up as many levels as necessary do { if (!toParent()) { - TRACE("STOP (no parent)!\n"); + TRACE_YAML("STOP (no parent)!\n"); return DONE_PARSING; } } while (indent < getLastIndent()); @@ -123,7 +123,7 @@ YamlParser::parse(const char* buffer, unsigned int size) // go down one level else if (indent > getLastIndent()) { if (!toChild()) { - TRACE("STOP (stack full)!\n"); + TRACE_YAML("STOP (stack full)!\n"); return DONE_PARSING; // ERROR } } @@ -142,7 +142,7 @@ YamlParser::parse(const char* buffer, unsigned int size) if (*c == ' ') {// assumes nothing else comes after spaces start node_found = calls->find_node(ctx, scratch_buf, scratch_len); if (!node_found) { - TRACE("YAML_PARSER: Could not find node '%.*s' (1)\n", + TRACE_YAML("YAML_PARSER: Could not find node '%.*s' (1)\n", scratch_len, scratch_buf); } state = ps_AttrSP; @@ -156,7 +156,7 @@ YamlParser::parse(const char* buffer, unsigned int size) if (state == ps_Attr) { node_found = calls->find_node(ctx, scratch_buf, scratch_len); if (!node_found) { - TRACE("YAML_PARSER: Could not find node '%.*s' (2)\n", + TRACE_YAML("YAML_PARSER: Could not find node '%.*s' (2)\n", scratch_len, scratch_buf); } } @@ -167,7 +167,7 @@ YamlParser::parse(const char* buffer, unsigned int size) if (state == ps_Attr) { node_found = calls->find_node(ctx, scratch_buf, scratch_len); if (!node_found) { - TRACE("YAML_PARSER: Could not find node '%.*s' (3)\n", + TRACE_YAML("YAML_PARSER: Could not find node '%.*s' (3)\n", scratch_len, scratch_buf); } } @@ -210,12 +210,12 @@ YamlParser::parse(const char* buffer, unsigned int size) break; } //TODO: more escapes needed??? - TRACE("unknown escape char '%c'",*c); + TRACE_YAML("unknown escape char '%c'",*c); return DONE_PARSING; case ps_ValEsc2: if(scratch_len >= MAX_STR) { - TRACE("STRING_OVERFLOW"); + TRACE_YAML("STRING_OVERFLOW"); return STRING_OVERFLOW; } else if (*c >= '0' && *c <= '9') { @@ -228,7 +228,7 @@ YamlParser::parse(const char* buffer, unsigned int size) state = ps_ValEsc3; break; } - TRACE("wrong hex digit '%c'",*c); + TRACE_YAML("wrong hex digit '%c'",*c); return DONE_PARSING; case ps_ValEsc3: @@ -242,7 +242,7 @@ YamlParser::parse(const char* buffer, unsigned int size) state = ps_ValQuo; break; } - TRACE("wrong hex digit '%c'",*c); + TRACE_YAML("wrong hex digit '%c'",*c); return DONE_PARSING; case ps_Val: diff --git a/radio/src/storage/yaml/yaml_tree_walker.cpp b/radio/src/storage/yaml/yaml_tree_walker.cpp index 88f15ac5a..4a2e0db28 100644 --- a/radio/src/storage/yaml/yaml_tree_walker.cpp +++ b/radio/src/storage/yaml/yaml_tree_walker.cpp @@ -358,7 +358,7 @@ bool YamlTreeWalker::isElmtEmpty(uint8_t* data) bit_ofs = getLevelOfs(); - TRACE(""); + TRACE_YAML(""); return false;//node->u._array.u.select_member; //TODO! // // assume structs aligned on 8bit boundaries // && !node->_array.is_active(data + (bit_ofs >> 3));