From 05cf212e79728c2bf1449ee5cfdf7dd6b1a8c4fd Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 10 May 2022 15:47:05 +0200 Subject: refactor(minion): create request class --- minion/src/wifi_module.hpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'minion/src/wifi_module.hpp') diff --git a/minion/src/wifi_module.hpp b/minion/src/wifi_module.hpp index 43999d6..62ea4f4 100644 --- a/minion/src/wifi_module.hpp +++ b/minion/src/wifi_module.hpp @@ -1,15 +1,23 @@ #pragma once +#include "http/request.hpp" + #include #include #include constexpr auto MAX_NETWORK_MODULE_RESPONSE_LENGTH = 128U; +constexpr auto REQUEST_DATA_LENGTH_BUF_SIZE = 16U; +constexpr auto REQUEST_METHOD_STR_MAX_LENGTH = 10U; +constexpr auto REQUEST_PATH_MAX_LENGTH = 64U; +constexpr auto REQUEST_HTTP_VERSION_MAX_LENGTH = 10U; + constexpr auto ASCII_TO_CHAR = 48U; constexpr auto TIMEOUT_SHORT = 1500U; -constexpr auto TIMEOUT_LONG = 4000U; +constexpr auto TIMEOUT_MEDIUM = 4000U; +constexpr auto TIMEOUT_LONG = 10000U; enum WifiMode { @@ -77,16 +85,13 @@ public: */ auto get_local_ip(char *local_ip_out) noexcept -> const char *; - auto has_incoming_request() noexcept -> bool; - /** * Reads a incoming HTTP request. * - * @param raw_request_out Raw request output buffer. - * - * @returns The connection ID. + * @returns A pointer to the request. Has to be deleted after use. Is nullptr if + * reading the request failed. */ - auto read_incoming_request(char *raw_request_out) noexcept -> size_t; + auto read_incoming_request() noexcept -> HTTPRequest *; auto close_connection(size_t connection_id) noexcept -> bool; @@ -104,6 +109,12 @@ private: */ auto _send_serial(const char *command) noexcept -> bool; + size_t _read_connection_id() noexcept; + + size_t _read_request_data_length() noexcept; + + HTTPRequestMethod _read_request_method(size_t &request_data_length) noexcept; + /** * Reads from the wifi module until it responds with a status. * @@ -115,7 +126,10 @@ private: */ auto _read(uint64_t timeout, char *response_out) noexcept -> ResponseStatus; - void _read_buffer(char *buffer_out, size_t length, char stop_char) noexcept; + void + _read_to(char *buffer_out, size_t length, char stop_char, uint64_t timeout) noexcept; + + void _read_bytes(char *buffer_out, size_t length, uint64_t timeout) noexcept; auto _read_byte() noexcept -> char; }; -- cgit v1.2.3-18-g5258