reworked debugger enabling
This commit is contained in:
		| @@ -1,6 +1,6 @@ | |||||||
| #include "debugger.h" | #include "debugger.h" | ||||||
|  |  | ||||||
| Debugger_t debugger; | DebugStatus_t DebuggerStatus[dbg_cntElements]; | ||||||
|  |  | ||||||
| #ifdef FEATURE_ENABLE_REMOTE_DEBUG | #ifdef FEATURE_ENABLE_REMOTE_DEBUG | ||||||
| RemoteDebug Debug; | RemoteDebug Debug; | ||||||
| @@ -19,8 +19,8 @@ void RemoteDebug_dumpGlobals(); | |||||||
|  |  | ||||||
| void initDebugger() | void initDebugger() | ||||||
| { | { | ||||||
|     debugger.serial_debug_enabled = false; |     DebuggerStatus[dbg_Serial] = disabled; | ||||||
|     debugger.webui_live_debug_enabled = false; |     DebuggerStatus[dbg_Webui] = disabled; | ||||||
|  |  | ||||||
|     Serial.setDebugOutput(false); |     Serial.setDebugOutput(false); | ||||||
|  |  | ||||||
| @@ -45,27 +45,41 @@ void Debugger_Process() | |||||||
| #endif | #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, ...) | void Debug_pushMessage(const char *format, ...) | ||||||
| { | { | ||||||
|     char buff[64]; |     if ((DebuggerStatus[dbg_Serial] == enabled) || (DebuggerStatus[dbg_Webui] == enabled)) | ||||||
|     va_list arg; |     { | ||||||
|     va_start(arg, format); |         char buff[64]; | ||||||
|     vsnprintf(buff, sizeof(buff), format, arg); |         va_list arg; | ||||||
|     va_end(arg); |         va_start(arg, format); | ||||||
|  |         vsnprintf(buff, sizeof(buff), format, arg); | ||||||
|  |         va_end(arg); | ||||||
|  |  | ||||||
|     if (debugger.serial_debug_enabled == true) |         if (DebuggerStatus[dbg_Serial] == enabled) | ||||||
|     { |         { | ||||||
|         Serial.print(buff); |             Serial.print(buff); | ||||||
|     } |         } | ||||||
|     if (debugger.webui_live_debug_enabled == true) |         if (DebuggerStatus[dbg_Webui] == enabled) | ||||||
|     { |         { | ||||||
|         Websocket_PushLiveDebug(String(buff)); |             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 buff[100]; | ||||||
|         char *p = buff; |         char *p = buff; | ||||||
| @@ -76,7 +90,15 @@ void pushCANDebug(uint32_t id, uint8_t dlc, uint8_t *data[]) | |||||||
|         } |         } | ||||||
|         *(p++) = '\n'; |         *(p++) = '\n'; | ||||||
|         *p = '\0'; |         *p = '\0'; | ||||||
|         Websocket_PushLiveDebug(String(buff)); |  | ||||||
|  |         if (DebuggerStatus[dbg_Serial] == enabled) | ||||||
|  |         { | ||||||
|  |             Serial.print(buff); | ||||||
|  |         } | ||||||
|  |         if (DebuggerStatus[dbg_Webui] == enabled) | ||||||
|  |         { | ||||||
|  |             Websocket_PushLiveDebug(String(buff)); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -9,17 +9,28 @@ | |||||||
| #include "rmtdbghelp.h" | #include "rmtdbghelp.h" | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| typedef struct Debugger_s | typedef enum DebugStatus_e{ | ||||||
| { |     enabled, | ||||||
|     bool webui_live_debug_enabled; |     disabled | ||||||
|     bool serial_debug_enabled; | }DebugStatus_t; | ||||||
| } Debugger_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 initDebugger(); | ||||||
| void Debugger_Process(); | 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 Debug_pushMessage(const char *format, ...); | ||||||
|  | void SetDebugportStatus(DebugPorts_t port, DebugStatus_t status); | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
| @@ -552,13 +552,11 @@ void Websocket_HandleMessage(void *arg, uint8_t *data, size_t len) | |||||||
|  |  | ||||||
|     if (strcmp((char *)data, "start") == 0) |     if (strcmp((char *)data, "start") == 0) | ||||||
|     { |     { | ||||||
|       Debug_pushMessage("Got WebSocket Message 'start' from client\n"); |       SetDebugportStatus(dbg_Webui, enabled); | ||||||
|       debugger.webui_live_debug_enabled = true; |  | ||||||
|     } |     } | ||||||
|     else if (strcmp((char *)data, "stop") == 0) |     else if (strcmp((char *)data, "stop") == 0) | ||||||
|     { |     { | ||||||
|       Debug_pushMessage("Got WebSocket Message 'stop' from client\n"); |       SetDebugportStatus(dbg_Webui, disabled); | ||||||
|       debugger.webui_live_debug_enabled = false; |  | ||||||
|     } |     } | ||||||
|     else if (strcmp((char *)data, "foo") == 0) |     else if (strcmp((char *)data, "foo") == 0) | ||||||
|     { |     { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user