summaryrefslogtreecommitdiff
path: root/minion/src/wifi_module.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-05-16 13:49:54 +0200
committerHampusM <hampus@hampusmat.com>2022-05-16 13:50:31 +0200
commit0529ac97653bc535c5c1db832d258f661d69309c (patch)
tree48c0b6ded9d82e01d5e96f12c66e0a9b6d385618 /minion/src/wifi_module.cpp
parent3ede86caf948d6e989fd056ea4f8d8c588939971 (diff)
refactor(minion): improve network code readability
Diffstat (limited to 'minion/src/wifi_module.cpp')
-rw-r--r--minion/src/wifi_module.cpp26
1 files changed, 11 insertions, 15 deletions
diff --git a/minion/src/wifi_module.cpp b/minion/src/wifi_module.cpp
index 2322582..ea509df 100644
--- a/minion/src/wifi_module.cpp
+++ b/minion/src/wifi_module.cpp
@@ -39,7 +39,8 @@ auto WiFiModule::connect_to_wifi(const char *ssid, const char *password) noexcep
{
const char cmd[] = "AT+CWJAP";
- auto command_length = strlen(cmd) + strlen(ssid) + strlen(password) + 6U + 1U;
+ auto command_length =
+ WIFI_CONNECT_COMMAND_BASE_LENGTH + strlen(cmd) + strlen(ssid) + strlen(password);
auto *command = util::malloc<char>(command_length);
@@ -104,8 +105,6 @@ void WiFiModule::set_multiple_connections_enabled(bool is_enabled) noexcept
char response[MAX_NETWORK_MODULE_RESPONSE_LENGTH] = "";
_read(TIMEOUT_SHORT, response);
-
- // Serial.println(response);
}
void WiFiModule::set_echo_enabled(bool is_enabled) noexcept
@@ -137,7 +136,7 @@ void WiFiModule::create_tcp_server(size_t port) noexcept
{
const auto *cmd = "AT+CIPSERVER";
- auto command_length = strlen(cmd) + 7U + 1U;
+ auto command_length = CREATE_TCP_SERVER_COMMAND_BASE_LENGTH + strlen(cmd);
auto *command = util::malloc<char>(command_length);
@@ -150,8 +149,6 @@ void WiFiModule::create_tcp_server(size_t port) noexcept
char response[MAX_NETWORK_MODULE_RESPONSE_LENGTH] = "";
_read(TIMEOUT_MEDIUM, response);
-
- // Serial.println(response);
}
auto WiFiModule::test() noexcept -> bool
@@ -295,7 +292,7 @@ auto WiFiModule::close_connection(NetworkConnection &connection) noexcept -> boo
{
const auto *cmd = "AT+CIPCLOSE";
- auto command_length = strlen(cmd) + 50U + 1U;
+ auto command_length = CLOSE_CONNECTION_COMMAND_BASE_LENGTH + strlen(cmd);
auto *command = util::malloc<char>(command_length);
@@ -341,7 +338,7 @@ auto WiFiModule::send_response(
const auto data_length = strlen(RESPONSE_HTTP_VERSION) + 1 +
RESPONSE_STATUS_CODE_LENGTH + 4 + strlen(data);
- auto command_length = strlen(cmd) + 50U + data_length + 1U;
+ auto command_length = SEND_RESPONSE_COMMAND_BASE_LENGTH + strlen(cmd) + data_length;
auto *command = util::malloc<char>(command_length);
@@ -382,6 +379,7 @@ auto WiFiModule::_send_serial(const char *command) noexcept -> bool
if (full_command == nullptr)
{
+ // NOLINTNEXTLINE(readability-simplify-boolean-expr)
return false;
}
@@ -389,15 +387,12 @@ auto WiFiModule::_send_serial(const char *command) noexcept -> bool
_serial.print(full_command);
- // Serial.print("Sent command: ");
- // Serial.println(full_command);
-
free(full_command);
return true;
}
-int8_t WiFiModule::_read_connection_id() noexcept
+auto WiFiModule::_read_connection_id() noexcept -> int8_t
{
const auto connection_id = _serial.read() - ASCII_TO_CHAR;
@@ -407,16 +402,17 @@ int8_t WiFiModule::_read_connection_id() noexcept
return static_cast<int8_t>(connection_id);
}
-size_t WiFiModule::_read_request_data_length() noexcept
+auto WiFiModule::_read_request_data_length() noexcept -> size_t
{
char data_length_buf[REQUEST_DATA_LENGTH_BUF_SIZE] = "";
_read_to(&data_length_buf[0], sizeof(data_length_buf) - 1U, ':', TIMEOUT_SHORT);
- return static_cast<size_t>(strtoul(data_length_buf, nullptr, 10));
+ return static_cast<size_t>(strtoul(data_length_buf, nullptr, NUMBER_BASE));
}
-HTTPRequestMethod WiFiModule::_read_request_method(size_t &request_data_length) noexcept
+auto WiFiModule::_read_request_method(size_t &request_data_length) noexcept
+ -> HTTPRequestMethod
{
char request_method_buf[REQUEST_METHOD_STR_MAX_LENGTH] = "";