diff options
author | HampusM <hampus@hampusmat.com> | 2022-05-23 14:30:22 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-05-23 14:30:22 +0200 |
commit | 191ea9f5e37da96bb3b7d3dbc6ce34c248f8a2fc (patch) | |
tree | aab7b4cfd48b2d3da522fddb0301dc303e12e9c9 /minion | |
parent | 5e36f47e681f1c9b19d0d39c2ec7d9ee81f213ad (diff) |
refactor(minion): fix memory alloc error messages & simplify WiFiModule _read
Diffstat (limited to 'minion')
-rw-r--r-- | minion/src/wifi_module.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
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++; } } |