From 154df68cb2a74a3b22456e8ec5af3af54352a41f Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 17 May 2022 22:37:09 +0200 Subject: fix buffer overflow in error handling module - fixed ring buffer overflow in errcatch module - fixed naming of commands in sercomm module - added comments to macro's in consts.h - properly handle `W2_E_WARN_UNCAUGHT_ERROR` and `W2_E_WARN_ERR_BUFFER_FULL` (these used to cause infinite loops) - added buffer full warning code - added options to hide some simulation messages - more boilerplate sercomm module code --- robot/sim.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'robot/sim.h') diff --git a/robot/sim.h b/robot/sim.h index 15a1b4b..9c80ecf 100644 --- a/robot/sim.h +++ b/robot/sim.h @@ -4,6 +4,11 @@ #include #include +// debug fine-tuning +#define DBG_ENABLE_PRINTFUNC (0) +#define DBG_ENABLE_SIMWARN (1) +#define DBG_ENABLE_SIMINFO (1) + // debug print options #define DBG_BYTES_PER_LINE 16 @@ -21,10 +26,10 @@ // debug stdout print macros #define simprintf(message, ...) printf(COL_RED "[SIM] " COL_RST message, ##__VA_ARGS__) #define simprint(message) simprintf(message "\n") -#define simprintfunc(name, fmt, ...) simprintf(COL_BLU "[FUNC] " \ - COL_CYN name COL_RST "(" COL_YEL fmt COL_RST ")\n", ##__VA_ARGS__) -#define simwarn(message, ...) simprintf(COL_YEL "[WARN] " COL_RST message, ##__VA_ARGS__) -#define siminfo(message, ...) simprintf(COL_MAG "[INFO] " COL_RST message, ##__VA_ARGS__) +#define simprintfunc(name, fmt, ...) if (DBG_ENABLE_PRINTFUNC) { simprintf(COL_BLU "[FUNC] " \ + COL_CYN name COL_RST "(" COL_YEL fmt COL_RST ")\n", ##__VA_ARGS__); } +#define simwarn(message, ...) if (DBG_ENABLE_SIMWARN) { simprintf(COL_YEL "[WARN] " COL_RST message, ##__VA_ARGS__); } +#define siminfo(message, ...) if (DBG_ENABLE_SIMINFO) { simprintf(COL_MAG "[INFO] " COL_RST message, ##__VA_ARGS__); } /** * simulates pololu library functions for local testing -- cgit v1.2.3