diff --git a/Software/src/debugger.cpp b/Software/src/debugger.cpp index 013c5c1..5b1c13c 100644 --- a/Software/src/debugger.cpp +++ b/Software/src/debugger.cpp @@ -1,6 +1,6 @@ #include "debugger.h" -Debugger_t debugger; +DebugStatus_t DebuggerStatus[dbg_cntElements]; #ifdef FEATURE_ENABLE_REMOTE_DEBUG RemoteDebug Debug; @@ -19,8 +19,8 @@ void RemoteDebug_dumpGlobals(); void initDebugger() { - debugger.serial_debug_enabled = false; - debugger.webui_live_debug_enabled = false; + DebuggerStatus[dbg_Serial] = disabled; + DebuggerStatus[dbg_Webui] = disabled; Serial.setDebugOutput(false); @@ -45,27 +45,41 @@ void Debugger_Process() #endif } +void SetDebugportStatus(DebugPorts_t port, DebugStatus_t status) +{ + if (status == disabled) + Debug_pushMessage("disable DebugPort %s", sDebugPorts[port]); + + DebuggerStatus[port] = status; + + if (status == enabled) + Debug_pushMessage("enabled DebugPort %s", sDebugPorts[port]); +} + void Debug_pushMessage(const char *format, ...) { - char buff[64]; - va_list arg; - va_start(arg, format); - vsnprintf(buff, sizeof(buff), format, arg); - va_end(arg); + if ((DebuggerStatus[dbg_Serial] == enabled) || (DebuggerStatus[dbg_Webui] == enabled)) + { + char buff[64]; + va_list arg; + va_start(arg, format); + vsnprintf(buff, sizeof(buff), format, arg); + va_end(arg); - if (debugger.serial_debug_enabled == true) - { - Serial.print(buff); - } - if (debugger.webui_live_debug_enabled == true) - { - Websocket_PushLiveDebug(String(buff)); + if (DebuggerStatus[dbg_Serial] == enabled) + { + Serial.print(buff); + } + if (DebuggerStatus[dbg_Webui] == enabled) + { + Websocket_PushLiveDebug(String(buff)); + } } } -void pushCANDebug(uint32_t id, uint8_t dlc, uint8_t *data[]) +void pushCANDebug(uint32_t id, uint8_t dlc, uint8_t *data) { - if (debugger.webui_live_debug_enabled == true) + if ((DebuggerStatus[dbg_Serial] == enabled) || (DebuggerStatus[dbg_Webui] == enabled)) { char buff[100]; char *p = buff; @@ -76,7 +90,15 @@ void pushCANDebug(uint32_t id, uint8_t dlc, uint8_t *data[]) } *(p++) = '\n'; *p = '\0'; - Websocket_PushLiveDebug(String(buff)); + + if (DebuggerStatus[dbg_Serial] == enabled) + { + Serial.print(buff); + } + if (DebuggerStatus[dbg_Webui] == enabled) + { + Websocket_PushLiveDebug(String(buff)); + } } } diff --git a/Software/src/debugger.h b/Software/src/debugger.h index f4e9d2f..a661f8e 100644 --- a/Software/src/debugger.h +++ b/Software/src/debugger.h @@ -9,17 +9,28 @@ #include "rmtdbghelp.h" #endif -typedef struct Debugger_s -{ - bool webui_live_debug_enabled; - bool serial_debug_enabled; -} Debugger_t; +typedef enum DebugStatus_e{ + enabled, + disabled +}DebugStatus_t; -extern Debugger_t debugger; +typedef enum DebugPorts_e{ + dbg_Serial, + dbg_Webui, + dbg_cntElements +}DebugPorts_t; + +const char sDebugPorts[dbg_cntElements][7] = { + "Serial", + "WebUI" +}; + +extern DebugStatus_t DebuggerStatus[dbg_cntElements]; void initDebugger(); void Debugger_Process(); -void pushCANDebug(uint32_t id, uint8_t dlc, uint8_t *data[]); +void pushCANDebug(uint32_t id, uint8_t dlc, uint8_t *data); void Debug_pushMessage(const char *format, ...); +void SetDebugportStatus(DebugPorts_t port, DebugStatus_t status); #endif \ No newline at end of file diff --git a/Software/src/webui.cpp b/Software/src/webui.cpp index b360392..a77c868 100644 --- a/Software/src/webui.cpp +++ b/Software/src/webui.cpp @@ -552,13 +552,11 @@ void Websocket_HandleMessage(void *arg, uint8_t *data, size_t len) if (strcmp((char *)data, "start") == 0) { - Debug_pushMessage("Got WebSocket Message 'start' from client\n"); - debugger.webui_live_debug_enabled = true; + SetDebugportStatus(dbg_Webui, enabled); } else if (strcmp((char *)data, "stop") == 0) { - Debug_pushMessage("Got WebSocket Message 'stop' from client\n"); - debugger.webui_live_debug_enabled = false; + SetDebugportStatus(dbg_Webui, disabled); } else if (strcmp((char *)data, "foo") == 0) {