From ec20c707ea677c9b2c8e585b78c9837a2f6e7372 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 30 May 2022 13:11:38 +0200 Subject: refactor(minion): make reading wifi module more reliable --- minion/src/wifi_module.cpp | 15 +++++++++++---- 1 file changed, 11 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 5174168..953e9fa 100644 --- a/minion/src/wifi_module.cpp +++ b/minion/src/wifi_module.cpp @@ -498,22 +498,29 @@ auto WiFiModule::_read(uint64_t timeout, char *response_out) noexcept { char character = _read_byte(); + if (has_end) + { + continue; + } + + const auto end_pos = index + 1U; + response_out[index] = character; - response_out[index + 1] = '\0'; + response_out[end_pos] = '\0'; - if (util::str_ends_with(response_out, "OK")) + if (util::str_ends_with(response_out, end_pos, "OK")) { status = WiFiModuleResponseStatus::OK; has_end = true; } - if (util::str_ends_with(response_out, "ERROR")) + if (util::str_ends_with(response_out, end_pos, "ERROR")) { status = WiFiModuleResponseStatus::ERROR; has_end = true; } - if (util::str_ends_with(response_out, "FAIL")) + if (util::str_ends_with(response_out, end_pos, "FAIL")) { status = WiFiModuleResponseStatus::FAIL; has_end = true; -- cgit v1.2.3-18-g5258