From d83d285c52bb43781cc325ef14190f645a0ac588 Mon Sep 17 00:00:00 2001 From: pritish Date: Fri, 20 Feb 2026 22:54:49 +0530 Subject: [PATCH 1/6] Implement assertion for unregistered command handling Add assertion for unregistered module commands. --- esp32/lib/module_handler/src/module_handler.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/esp32/lib/module_handler/src/module_handler.cpp b/esp32/lib/module_handler/src/module_handler.cpp index 9a0ed0ca..3480aac4 100644 --- a/esp32/lib/module_handler/src/module_handler.cpp +++ b/esp32/lib/module_handler/src/module_handler.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include "transcoder.h" @@ -94,6 +95,10 @@ void ModuleHandler::ModuleHandler::OnReceive(size_t num_bytes) { Log.errorln("No module registered for command type: %d", cmd.which_command); + assert(false && + "Received command for unregistered module. Ensure all required " + "modules are registered before use."); + // reset buffer receive_buffer.len = 0; receive_buffer.idx = 0; From 147c80a265343a250d271da79b3d5f98c2da4b89 Mon Sep 17 00:00:00 2001 From: pritish Date: Fri, 20 Feb 2026 22:57:25 +0530 Subject: [PATCH 2/6] Initialize WiFi controller in WiFiInit function Mark WiFi controller as initialized before connection attempts. --- stm32/Src/wifi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stm32/Src/wifi.c b/stm32/Src/wifi.c index 61968eff..3ef55011 100644 --- a/stm32/Src/wifi.c +++ b/stm32/Src/wifi.c @@ -130,6 +130,9 @@ bool Esp32Init(void); void WiFiInit(void) { APP_LOG(TS_OFF, VLEVEL_M, "WiFi app starting\r\n"); + // Mark WiFi controller as initialized so assert guards pass + ControllerWiFiSetInitialized(); + // loop until sucessful connection while (!Esp32Init()) { Disconnect(); From b96d3bbcd3ab83508f737a9680e4827da4919ccc Mon Sep 17 00:00:00 2001 From: pritish Date: Fri, 20 Feb 2026 22:58:39 +0530 Subject: [PATCH 3/6] Add ControllerWiFiSetInitialized function declaration --- stm32/lib/controller/include/controller/wifi.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stm32/lib/controller/include/controller/wifi.h b/stm32/lib/controller/include/controller/wifi.h index 25359201..3ab8a36f 100644 --- a/stm32/lib/controller/include/controller/wifi.h +++ b/stm32/lib/controller/include/controller/wifi.h @@ -82,6 +82,14 @@ typedef struct { size_t size; } ControllerWiFiResponse; +/** + * @brief Mark the WiFi controller as initialized + * + * Must be called before any other ControllerWiFi* functions. Subsequent calls + * to ControllerWiFi* functions without calling this will trigger an assert. + */ +void ControllerWiFiSetInitialized(void); + /** * @brief Initialize WiFi settings on the esp32 * From 298fc62146b2ec5879950035c27904c032178fa3 Mon Sep 17 00:00:00 2001 From: pritish Date: Fri, 20 Feb 2026 22:59:22 +0530 Subject: [PATCH 4/6] Implement WiFi controller initialization check Add initialization check for WiFi controller. --- stm32/lib/controller/src/wifi.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/stm32/lib/controller/src/wifi.c b/stm32/lib/controller/src/wifi.c index 45800ddc..6858591a 100644 --- a/stm32/lib/controller/src/wifi.c +++ b/stm32/lib/controller/src/wifi.c @@ -1,13 +1,24 @@ #include "controller/wifi.h" +#include + #include "communication.h" #include "transcoder.h" /** Timeout for i2c communication with esp32, in communication.h */ extern unsigned int g_controller_i2c_timeout; +/** Flag to track if the WiFi controller has been initialized */ +static bool wifi_initialized = false; + +void ControllerWiFiSetInitialized(void) { wifi_initialized = true; } + ControllerStatus WiFiCommandTransaction(const WiFiCommand *input, WiFiCommand *output) { + assert(wifi_initialized && + "WiFi controller used before ControllerWiFiSetInitialized() was " + "called. Ensure WiFi is enabled in user config."); + // get reference to tx and rx buffers Buffer *tx = ControllerTx(); Buffer *rx = ControllerRx(); From 0b281b7b83dc90504b0b5aaf3583e06434a0448e Mon Sep 17 00:00:00 2001 From: pritish Date: Sat, 21 Feb 2026 15:39:15 +0530 Subject: [PATCH 5/6] Refactor WiFi command transaction error handling Replace assert with conditional check for wifi_initialized. --- stm32/lib/controller/src/wifi.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/stm32/lib/controller/src/wifi.c b/stm32/lib/controller/src/wifi.c index 6858591a..16ed6821 100644 --- a/stm32/lib/controller/src/wifi.c +++ b/stm32/lib/controller/src/wifi.c @@ -1,7 +1,5 @@ #include "controller/wifi.h" -#include - #include "communication.h" #include "transcoder.h" @@ -15,9 +13,9 @@ void ControllerWiFiSetInitialized(void) { wifi_initialized = true; } ControllerStatus WiFiCommandTransaction(const WiFiCommand *input, WiFiCommand *output) { - assert(wifi_initialized && - "WiFi controller used before ControllerWiFiSetInitialized() was " - "called. Ensure WiFi is enabled in user config."); + if (!wifi_initialized) { + return CONTROLLER_ERROR; + } // get reference to tx and rx buffers Buffer *tx = ControllerTx(); From 4be8b64c4697c4c8f7e6721dcd365925c27673e8 Mon Sep 17 00:00:00 2001 From: pritish Date: Sat, 21 Feb 2026 15:40:13 +0530 Subject: [PATCH 6/6] Remove assert for unregistered module commands Removed assert statement for unregistered module commands. --- esp32/lib/module_handler/src/module_handler.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/esp32/lib/module_handler/src/module_handler.cpp b/esp32/lib/module_handler/src/module_handler.cpp index 3480aac4..9a0ed0ca 100644 --- a/esp32/lib/module_handler/src/module_handler.cpp +++ b/esp32/lib/module_handler/src/module_handler.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include "transcoder.h" @@ -95,10 +94,6 @@ void ModuleHandler::ModuleHandler::OnReceive(size_t num_bytes) { Log.errorln("No module registered for command type: %d", cmd.which_command); - assert(false && - "Received command for unregistered module. Ensure all required " - "modules are registered before use."); - // reset buffer receive_buffer.len = 0; receive_buffer.idx = 0;