diff options
author | HampusM <hampus@hampusmat.com> | 2022-05-08 18:55:42 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-05-08 18:55:42 +0200 |
commit | 2809f92eeb8b727e20167fe82e4cb9c3627d4870 (patch) | |
tree | 06a01c862088333aa388e74dfa4381a87568bfc1 /minion/src/wifi_module.hpp | |
parent | 3a11866cb6a8fd46d86cb6e04dc1022344ea8d45 (diff) |
chore: move most files to minion folder
Diffstat (limited to 'minion/src/wifi_module.hpp')
-rw-r--r-- | minion/src/wifi_module.hpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/minion/src/wifi_module.hpp b/minion/src/wifi_module.hpp new file mode 100644 index 0000000..5a4148c --- /dev/null +++ b/minion/src/wifi_module.hpp @@ -0,0 +1,93 @@ +#pragma once + +#include <SoftwareSerial.h> +#include <stddef.h> +#include <stdint.h> + +constexpr auto MAX_NETWORK_MODULE_RESPONSE_LENGTH = 128U; + +enum WifiMode +{ + Station = 1, + SoftAP = 2, + SoftAPAndStation = 3 +}; + +enum ResponseStatus +{ + OK, + FAIL, + ERROR, + TIMEOUT +}; + +class WiFiModule +{ +public: + WiFiModule(uint8_t receive_pin, uint8_t transmit_pin) noexcept; + + void begin(size_t baudrate) noexcept; + + int get_available() noexcept; + + void reset() noexcept; + + /** + * Connects to a wifi network. + * + * @param ssid The service set identifier of a wifi network. + * @param password The wifi network password. + * + * @returns Whether or not it succeeded. + */ + bool connect(const char *ssid, const char *password) noexcept; + + void set_wifi_mode(WifiMode wifi_mode) noexcept; + + void set_multiple_connections_enabled(bool is_enabled) noexcept; + + void set_echo_enabled(bool is_enabled) noexcept; + + void create_tcp_server(size_t port) noexcept; + + /** + * Tests the connection to the wifi module. + * + * @returns Whether or not the test succeeded. + */ + bool test() noexcept; + + /** + * Gets local IP address of the wifi module. + * + * @param local_ip_out Local IP output buffer. + * + * @returns A pointer to the local IP output buffer. + */ + const char *get_local_ip(char *local_ip_out) noexcept; + +private: + SoftwareSerial _serial; + + /** + * Sends a command to the wifi module. + * + * @param command A command without the "AT+" in the beginning. + * + * @returns Whether or not it succeeded. + */ + bool _send_serial(const char *command) noexcept; + + /** + * Reads from the wifi module until it responds with a status. + * + * @param timeout Timeout in milliseconds. + * @param response_out Response output buffer. + * + * @returns The response status. + * + */ + ResponseStatus _read(uint64_t timeout, char *response_out) noexcept; + + char _read_byte() noexcept; +}; |