From 191ea9f5e37da96bb3b7d3dbc6ce34c248f8a2fc Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 23 May 2022 14:30:22 +0200 Subject: refactor(minion): fix memory alloc error messages & simplify WiFiModule _read --- minion/src/wifi_module.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'minion/src/wifi_module.cpp') diff --git a/minion/src/wifi_module.cpp b/minion/src/wifi_module.cpp index 352cb79..d1f91c9 100644 --- a/minion/src/wifi_module.cpp +++ b/minion/src/wifi_module.cpp @@ -46,7 +46,7 @@ auto WiFiModule::connect_to_wifi(const char *ssid, const char *password) noexcep if (command == nullptr) { - Serial.println("Memory allocation failed for creating full connection command"); + Serial.println("Memory allocation failed for creating wifi connection command"); return false; } @@ -344,7 +344,7 @@ auto WiFiModule::send_response( if (command == nullptr) { - Serial.println("Memory allocation failed for creating close connection command"); + Serial.println("Memory allocation failed for creating send response command"); return false; } @@ -434,7 +434,7 @@ auto WiFiModule::_read(uint64_t timeout, char *response_out) noexcept -> WiFiModuleResponseStatus { const auto start_time = millis(); - + size_t index = 0U; bool has_end = false; auto status = WiFiModuleResponseStatus::TIMEOUT; @@ -444,7 +444,8 @@ auto WiFiModule::_read(uint64_t timeout, char *response_out) noexcept { char character = _read_byte(); - strncat(response_out, &character, 1U); + response_out[index] = character; + response_out[index + 1] = '\0'; if (util::str_ends_with(response_out, "OK")) { @@ -463,6 +464,8 @@ auto WiFiModule::_read(uint64_t timeout, char *response_out) noexcept status = WiFiModuleResponseStatus::FAIL; has_end = true; } + + index++; } } -- cgit v1.2.3-18-g5258