summaryrefslogtreecommitdiff
path: root/minion/src/wifi_module.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'minion/src/wifi_module.cpp')
-rw-r--r--minion/src/wifi_module.cpp28
1 files changed, 26 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());