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(); 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 * diff --git a/stm32/lib/controller/src/wifi.c b/stm32/lib/controller/src/wifi.c index 45800ddc..16ed6821 100644 --- a/stm32/lib/controller/src/wifi.c +++ b/stm32/lib/controller/src/wifi.c @@ -6,8 +6,17 @@ /** 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) { + if (!wifi_initialized) { + return CONTROLLER_ERROR; + } + // get reference to tx and rx buffers Buffer *tx = ControllerTx(); Buffer *rx = ControllerRx();