summaryrefslogtreecommitdiff
path: root/minion/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-05-09 14:53:39 +0200
committerHampusM <hampus@hampusmat.com>2022-05-11 23:14:29 +0200
commit6decaf83fc2b1e751876a76d72c4370b3b66a507 (patch)
tree5e8fc58672be037add2d33582c369e18c70cbf64 /minion/src
parentbb6f2ce801e5c4ee617b27beaf30a746807384ea (diff)
fix(minion): properly read request data length
Diffstat (limited to 'minion/src')
-rw-r--r--minion/src/wifi_module.cpp28
-rw-r--r--minion/src/wifi_module.hpp2
2 files changed, 28 insertions, 2 deletions
diff --git a/minion/src/wifi_module.cpp b/minion/src/wifi_module.cpp
index 70fd6f9..8b04b70 100644
--- a/minion/src/wifi_module.cpp
+++ b/minion/src/wifi_module.cpp
@@ -242,10 +242,17 @@ auto WiFiModule::read_incoming_request(char *raw_request_out) noexcept -> size_t
const auto connection_id = _serial.read() - ASCII_TO_CHAR;
- const auto data_length = _serial.read();
+ // Skip the comma
+ _serial.read();
+
+ char data_length_buf[16] = { '\0' };
+
+ _read_buffer(&data_length_buf[0], sizeof(data_length_buf) - 1, ':');
+
+ auto data_length = atoi(data_length_buf);
Serial.print("Data length: ");
- Serial.print(data_length);
+ Serial.println(data_length);
auto read_bytes = 0;
const auto start_time = millis();
@@ -410,6 +417,23 @@ auto WiFiModule::_read(uint64_t timeout, char *response_out) noexcept -> Respons
return status;
}
+void WiFiModule::_read_buffer(char *buffer_out, size_t length, char stop_char) noexcept
+{
+ byte position = 0;
+
+ while (get_available() != 0 && position < length)
+ {
+ auto character = _read_byte();
+
+ if (character == stop_char)
+ break;
+
+ buffer_out[position++] = character;
+ }
+
+ buffer_out[position] = '\0';
+}
+
auto WiFiModule::_read_byte() noexcept -> char
{
return static_cast<char>(_serial.read());
diff --git a/minion/src/wifi_module.hpp b/minion/src/wifi_module.hpp
index 5de898e..43999d6 100644
--- a/minion/src/wifi_module.hpp
+++ b/minion/src/wifi_module.hpp
@@ -115,5 +115,7 @@ private:
*/
auto _read(uint64_t timeout, char *response_out) noexcept -> ResponseStatus;
+ void _read_buffer(char *buffer_out, size_t length, char stop_char) noexcept;
+
auto _read_byte() noexcept -> char;
};