From 5e38b4974928917beeae2718d8f78d950c9d79f7 Mon Sep 17 00:00:00 2001 From: HentaiHeavenVR Date: Fri, 30 Aug 2024 11:18:37 +0200 Subject: [PATCH 01/41] Add custom zero-copy span-based integer converters with better error handling (#274) * Initial implementation * Take IntConv into use * Seperate tests * Remove STD's from integers * Fix typo for empty string check * Fix wrong testing values * Format intconv.cpp and intconv.h * Add tests for negative zero, leading zero's and trailing spaces --- include/intconv.h | 16 ++ src/intconv.cpp | 324 ++++++++++++++++++++++++++++++ src/serial/SerialInputHandler.cpp | 17 +- 3 files changed, 345 insertions(+), 12 deletions(-) create mode 100644 include/intconv.h create mode 100644 src/intconv.cpp diff --git a/include/intconv.h b/include/intconv.h new file mode 100644 index 00000000..5f41e877 --- /dev/null +++ b/include/intconv.h @@ -0,0 +1,16 @@ +#pragma once + +#include "StringView.h" + +#include + +namespace OpenShock::IntConv { + bool stoi8(OpenShock::StringView str, int8_t& val); + bool stou8(OpenShock::StringView str, uint8_t& val); + bool stoi16(OpenShock::StringView str, int16_t& val); + bool stou16(OpenShock::StringView str, uint16_t& val); + bool stoi32(OpenShock::StringView str, int32_t& val); + bool stou32(OpenShock::StringView str, uint32_t& val); + bool stoi64(OpenShock::StringView str, int64_t& val); + bool stou64(OpenShock::StringView str, uint64_t& val); +} // namespace OpenShock::IntConv diff --git a/src/intconv.cpp b/src/intconv.cpp new file mode 100644 index 00000000..3859b77f --- /dev/null +++ b/src/intconv.cpp @@ -0,0 +1,324 @@ +#include "intconv.h" + +#include +#include +#include + +template +constexpr unsigned int NumDigits() { + static_assert(std::is_integral::value); + uint64_t num = std::numeric_limits::max(); + + unsigned int digits = std::is_signed::value ? 2 : 1; + while (num >= 10) { + num /= 10; + digits++; + } + + return digits; +} + +// Base converter +template +constexpr bool spanToT(OpenShock::StringView str, T& val) { + static_assert(std::is_integral::value); + const T Threshold = std::numeric_limits::max() / 10; + + val = 0; + + // Special case for zero, also handles leading zeros + if (str.front() == '0') { + return str.length() == 1; + } + + for (char c : str) { + if (c < '0' || c > '9') { + return false; + } + + if (val > Threshold) { + return false; + } + + val *= 10; + + uint8_t digit = c - '0'; + if (digit > std::numeric_limits::max() - val) { + return false; + } + + val += digit; + } + + return true; +} + +// Unsigned converter +template +constexpr bool spanToUT(OpenShock::StringView str, T& val) { + static_assert(std::is_unsigned::value); + + if (str.isNullOrEmpty() || str.length() > NumDigits()) { + return false; + } + + return spanToT(str, val); +} + +// Signed converter +template +constexpr bool spanToST(OpenShock::StringView str, T& val) { + static_assert(std::is_signed::value); + + if (str.isNullOrEmpty() || str.length() > NumDigits()) { + return false; + } + + bool negative = str.front() == '-'; + if (negative) { + str = str.substr(1); + if (str.isNullOrEmpty()) { + return false; + } + } + + typename std::make_unsigned::type i = 0; + if (!spanToT(str, i)) { + return false; + } + + if (i > std::numeric_limits::max()) { + return false; + } + + val = negative ? -static_cast(i) : static_cast(i); + + return !(negative && i == 0); // "-0" is invalid +} + +using namespace OpenShock; + +// Specific converters +bool IntConv::stoi8(OpenShock::StringView str, int8_t& val) { + return spanToST(str, val); +} +bool IntConv::stou8(OpenShock::StringView str, uint8_t& val) { + return spanToUT(str, val); +} +bool IntConv::stoi16(OpenShock::StringView str, int16_t& val) { + return spanToST(str, val); +} +bool IntConv::stou16(OpenShock::StringView str, uint16_t& val) { + return spanToUT(str, val); +} +bool IntConv::stoi32(OpenShock::StringView str, int32_t& val) { + return spanToST(str, val); +} +bool IntConv::stou32(OpenShock::StringView str, uint32_t& val) { + return spanToUT(str, val); +} +bool IntConv::stoi64(OpenShock::StringView str, int64_t& val) { + return spanToST(str, val); +} +bool IntConv::stou64(OpenShock::StringView str, uint64_t& val) { + return spanToUT(str, val); +} + +static_assert(NumDigits() == 3, "NumDigits test for uint8_t failed"); +static_assert(NumDigits() == 5, "NumDigits test for uint16_t failed"); +static_assert(NumDigits() == 10, "NumDigits test for uint32_t failed"); +static_assert(NumDigits() == 20, "NumDigits test for uint64_t failed"); + +static_assert(NumDigits() == 4, "NumDigits test for int8_t failed"); +static_assert(NumDigits() == 6, "NumDigits test for int16_t failed"); +static_assert(NumDigits() == 11, "NumDigits test for int32_t failed"); +static_assert(NumDigits() == 20, "NumDigits test for int64_t failed"); + +constexpr bool test_spanToUT8() { + uint8_t u8 = 0; + return spanToUT("255"_sv, u8) && u8 == 255; +} + +static_assert(test_spanToUT8(), "test_spanToUT8 failed"); + +constexpr bool test_spanToUT16() { + uint16_t u16 = 0; + return spanToUT("65535"_sv, u16) && u16 == 65'535; +} + +static_assert(test_spanToUT16(), "test_spanToUT16 failed"); + +constexpr bool test_spanToUT32() { + uint32_t u32 = 0; + return spanToUT("4294967295"_sv, u32) && u32 == 4'294'967'295U; +} + +static_assert(test_spanToUT32(), "test_spanToUT32 failed"); + +constexpr bool test_spanToUT64() { + uint64_t u64 = 0; + return spanToUT("18446744073709551615"_sv, u64) && u64 == 18'446'744'073'709'551'615ULL; +} + +static_assert(test_spanToUT64(), "test_spanToUT64 failed"); + +constexpr bool test_spanToUT8Overflow() { + uint8_t u8 = 0; + return !spanToUT("256"_sv, u8); // Overflow +} + +static_assert(test_spanToUT8Overflow(), "test_spanToUT8Overflow failed"); + +constexpr bool test_spanToUT16Overflow() { + uint16_t u16 = 0; + return !spanToUT("70000"_sv, u16); // Overflow +} + +static_assert(test_spanToUT16Overflow(), "test_spanToUT16Overflow failed"); + +constexpr bool test_spanToUT32Overflow() { + uint32_t u32 = 0; + return !spanToUT("4294967296"_sv, u32); // Overflow +} + +static_assert(test_spanToUT32Overflow(), "test_spanToUT32Overflow failed"); + +constexpr bool test_spanToUT64Overflow() { + uint64_t u64 = 0; + return !spanToUT("18446744073709551616"_sv, u64); // Overflow +} + +static_assert(test_spanToUT64Overflow(), "test_spanToUT64Overflow failed"); + +constexpr bool test_spanToST8() { + int8_t i8 = 0; + return spanToST("-127"_sv, i8) && i8 == -127; +} + +static_assert(test_spanToST8(), "test_spanToST8 failed"); + +constexpr bool test_spanToST16() { + int16_t i16 = 0; + return spanToST("32767"_sv, i16) && i16 == 32'767; +} + +static_assert(test_spanToST16(), "test_spanToST16 failed"); + +constexpr bool test_spanToST32() { + int32_t i32 = 0; + return spanToST("-2147483647"_sv, i32) && i32 == -2'147'483'647; +} + +static_assert(test_spanToST32(), "test_spanToST32 failed"); + +constexpr bool test_spanToST64() { + int64_t i64 = 0; + return spanToST("9223372036854775807"_sv, i64) && i64 == 9'223'372'036'854'775'807LL; +} + +static_assert(test_spanToST64(), "test_spanToST64 failed"); + +constexpr bool test_spanToST8Underflow() { + int8_t i8 = 0; + return !spanToST("-128"_sv, i8); // Underflow +} + +static_assert(test_spanToST8Underflow(), "test_spanToST8Underflow failed"); + +constexpr bool test_spanToST8Overflow() { + int8_t i8 = 0; + return !spanToST("128"_sv, i8); // Overflow +} + +static_assert(test_spanToST8Overflow(), "test_spanToST8Overflow failed"); + +constexpr bool test_spanToST16Underflow() { + int16_t i16 = 0; + return !spanToST("-32769"_sv, i16); // Underflow +} + +static_assert(test_spanToST16Underflow(), "test_spanToST16Underflow failed"); + +constexpr bool test_spanToST16Overflow() { + int16_t i16 = 0; + return !spanToST("32768"_sv, i16); // Overflow +} + +static_assert(test_spanToST16Overflow(), "test_spanToST16Overflow failed"); + +constexpr bool test_spanToST32Underflow() { + int32_t i32 = 0; + return !spanToST("-2147483649"_sv, i32); // Underflow +} + +static_assert(test_spanToST32Underflow(), "test_spanToST32Underflow failed"); + +constexpr bool test_spanToST32Overflow() { + int32_t i32 = 0; + return !spanToST("2147483648"_sv, i32); // Overflow +} + +static_assert(test_spanToST32Overflow(), "test_spanToST32Overflow failed"); + +constexpr bool test_spanToST64Underflow() { + int64_t i64 = 0; + return !spanToST("-9223372036854775809"_sv, i64); // Underflow +} + +static_assert(test_spanToST64Underflow(), "test_spanToST64Underflow failed"); + +constexpr bool test_spanToST64Overflow() { + int64_t i64 = 0; + return !spanToST("9223372036854775808"_sv, i64); // Overflow +} + +static_assert(test_spanToST64Overflow(), "test_spanToST64Overflow failed"); + +constexpr bool test_spanToSTEmptyString() { + int8_t i8 = 0; + return !spanToST(""_sv, i8); // Empty string +} + +static_assert(test_spanToSTEmptyString(), "test_spanToSTEmptyString failed"); + +constexpr bool test_spanToSTJustNegativeSign() { + int16_t i16 = 0; + return !spanToST("-"_sv, i16); // Just a negative sign +} + +static_assert(test_spanToSTJustNegativeSign(), "test_spanToSTJustNegativeSign failed"); + +constexpr bool test_spanToSTNegativeZero() { + int32_t i32 = 0; + return !spanToST("-0"_sv, i32); // Negative zero +} + +static_assert(test_spanToSTNegativeZero(), "test_spanToSTNegativeZero failed"); + +constexpr bool test_spanToSTInvalidCharacter() { + int32_t i32 = 0; + return !spanToST("+123"_sv, i32); // Invalid character +} + +static_assert(test_spanToSTInvalidCharacter(), "test_spanToSTInvalidCharacter failed"); + +constexpr bool test_spanToSTLeadingSpace() { + int64_t i64 = 0; + return !spanToST(" 123"_sv, i64); // Leading space +} + +static_assert(test_spanToSTLeadingSpace(), "test_spanToSTLeadingSpace failed"); + +constexpr bool test_spanToSTTrailingSpace() { + int64_t i64 = 0; + return !spanToST("123 "_sv, i64); // Trailing space +} + +static_assert(test_spanToSTTrailingSpace(), "test_spanToSTTrailingSpace failed"); + +constexpr bool test_spanToSTLeadingZero() { + int64_t i64 = 0; + return !spanToST("0123"_sv, i64); // Leading zero +} + +static_assert(test_spanToSTLeadingZero(), "test_spanToSTLeadingZero failed"); diff --git a/src/serial/SerialInputHandler.cpp b/src/serial/SerialInputHandler.cpp index 66a6786e..fb7762f5 100644 --- a/src/serial/SerialInputHandler.cpp +++ b/src/serial/SerialInputHandler.cpp @@ -11,6 +11,7 @@ #include "serialization/JsonSerial.h" #include "StringView.h" #include "Time.h" +#include "intconv.h" #include "util/Base64Utils.h" #include "wifi/WiFiManager.h" @@ -107,20 +108,12 @@ void _handleRfTxPinCommand(StringView arg) { return; } - auto str = arg.toString(); // Copy the string to null-terminate it (VERY IMPORTANT) - - unsigned int pin; - if (sscanf(str.c_str(), "%u", &pin) != 1) { - SERPR_ERROR("Invalid argument (not a number)"); - return; - } - - if (pin > UINT8_MAX) { - SERPR_ERROR("Invalid argument (out of range)"); - return; + uint8_t pin; + if (!OpenShock::IntConv::stou8(arg, pin)) { + SERPR_ERROR("Invalid argument (number invalid or out of range)"); } - OpenShock::SetRfPinResultCode result = OpenShock::CommandHandler::SetRfTxPin(static_cast(pin)); + OpenShock::SetRfPinResultCode result = OpenShock::CommandHandler::SetRfTxPin(pin); switch (result) { case OpenShock::SetRfPinResultCode::InvalidPin: From e99bcc9c5de5ac4e790205ce05abb3c70c4a192c Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 30 Aug 2024 12:16:05 +0200 Subject: [PATCH 02/41] Remove unused include --- include/config/internal/utils.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/config/internal/utils.h b/include/config/internal/utils.h index c36b013c..af31c845 100644 --- a/include/config/internal/utils.h +++ b/include/config/internal/utils.h @@ -1,7 +1,6 @@ #pragma once #include "config/ConfigBase.h" -#include "Logging.h" #include From 23f9fedd2c10fddb3558a23aaa0ee2149d9d2edb Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 30 Aug 2024 12:21:00 +0200 Subject: [PATCH 03/41] Add missing Logging.h includes --- src/SemVer.cpp | 2 ++ src/http/HTTPRequestManager.cpp | 1 + src/util/ParitionUtils.cpp | 1 + 3 files changed, 4 insertions(+) diff --git a/src/SemVer.cpp b/src/SemVer.cpp index a9711d0a..99e612a7 100644 --- a/src/SemVer.cpp +++ b/src/SemVer.cpp @@ -1,5 +1,7 @@ #include "SemVer.h" +#include "Logging.h" + const char* const TAG = "SemVer"; using namespace OpenShock; diff --git a/src/http/HTTPRequestManager.cpp b/src/http/HTTPRequestManager.cpp index bbd26620..1f340f15 100644 --- a/src/http/HTTPRequestManager.cpp +++ b/src/http/HTTPRequestManager.cpp @@ -1,6 +1,7 @@ #include "http/HTTPRequestManager.h" #include "Common.h" +#include "Logging.h" #include "Time.h" #include diff --git a/src/util/ParitionUtils.cpp b/src/util/ParitionUtils.cpp index cf6dfd0f..2dc19b4f 100644 --- a/src/util/ParitionUtils.cpp +++ b/src/util/ParitionUtils.cpp @@ -2,6 +2,7 @@ #include "Hashing.h" #include "http/HTTPRequestManager.h" +#include "Logging.h" #include "Time.h" #include "util/HexUtils.h" From 00c2d534063c1a772818059f6be766cdad51d6d5 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 30 Aug 2024 12:32:20 +0200 Subject: [PATCH 04/41] Remove stray esp_log.h include --- src/util/ParitionUtils.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/util/ParitionUtils.cpp b/src/util/ParitionUtils.cpp index 2dc19b4f..009d8915 100644 --- a/src/util/ParitionUtils.cpp +++ b/src/util/ParitionUtils.cpp @@ -6,8 +6,6 @@ #include "Time.h" #include "util/HexUtils.h" -#include - const char* const TAG = "PartitionUtils"; bool OpenShock::TryGetPartitionHash(const esp_partition_t* partition, char (&hash)[65]) { From 75fb7376ae01d18647e5c86e65eb735be2d0548a Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 30 Aug 2024 13:16:52 +0200 Subject: [PATCH 05/41] Improve file structure consistency for logging --- include/Logging.h | 1 + src/CaptivePortal.cpp | 4 ++-- src/CaptivePortalInstance.cpp | 4 ++-- src/CommandHandler.cpp | 4 ++-- src/EStopManager.cpp | 4 ++-- src/GatewayClient.cpp | 4 ++-- src/GatewayConnectionManager.cpp | 3 ++- src/OtaUpdateManager.cpp | 4 ++-- src/PinPatternManager.cpp | 4 ++-- src/RGBPatternManager.cpp | 4 ++-- src/ReadWriteMutex.cpp | 4 ++-- src/SemVer.cpp | 4 ++-- src/VisualStateManager.cpp | 4 ++-- src/WebSocketDeFragger.cpp | 4 ++-- src/config/BackendConfig.cpp | 4 ++-- src/config/CaptivePortalConfig.cpp | 4 ++-- src/config/Config.cpp | 4 ++-- src/config/OtaUpdateConfig.cpp | 4 ++-- src/config/RFConfig.cpp | 6 +++--- src/config/RootConfig.cpp | 4 ++-- src/config/SerialInputConfig.cpp | 4 ++-- src/config/WiFiConfig.cpp | 4 ++-- src/config/WiFiCredentials.cpp | 4 ++-- src/config/internal/utils.cpp | 4 ++-- src/event_handlers/websocket/Gateway.cpp | 4 ++-- src/event_handlers/websocket/Local.cpp | 4 ++-- .../websocket/gateway/CaptivePortalConfig.cpp | 4 ++-- src/event_handlers/websocket/gateway/OtaInstall.cpp | 4 ++-- src/event_handlers/websocket/gateway/ShockerCommandList.cpp | 4 ++-- src/event_handlers/websocket/gateway/_InvalidMessage.cpp | 5 ++--- src/event_handlers/websocket/local/AccountLinkCommand.cpp | 4 ++-- src/event_handlers/websocket/local/AccountUnlinkCommand.cpp | 4 ++-- src/event_handlers/websocket/local/SetRfTxPinCommand.cpp | 4 ++-- .../websocket/local/WiFiNetworkConnectCommand.cpp | 4 ++-- .../websocket/local/WiFiNetworkDisconnectCommand.cpp | 4 ++-- .../websocket/local/WiFiNetworkForgetCommand.cpp | 4 ++-- .../websocket/local/WiFiNetworkSaveCommand.cpp | 4 ++-- src/event_handlers/websocket/local/WiFiScanCommand.cpp | 4 ++-- src/event_handlers/websocket/local/_InvalidMessage.cpp | 4 ++-- src/http/HTTPRequestManager.cpp | 4 ++-- src/main.cpp | 4 ++-- src/radio/RFTransmitter.cpp | 4 ++-- src/radio/rmt/MainEncoder.cpp | 6 +++--- src/serial/SerialInputHandler.cpp | 6 +++--- src/serialization/JsonAPI.cpp | 4 ++-- src/serialization/JsonSerial.cpp | 4 ++-- src/serialization/WSGateway.cpp | 4 ++-- src/serialization/WSLocal.cpp | 4 ++-- src/util/Base64Utils.cpp | 4 ++-- src/util/CertificateUtils.cpp | 4 ++-- src/util/ParitionUtils.cpp | 4 ++-- src/util/StringUtils.cpp | 4 ++-- src/wifi/WiFiManager.cpp | 4 ++-- src/wifi/WiFiScanManager.cpp | 4 ++-- 54 files changed, 110 insertions(+), 109 deletions(-) diff --git a/include/Logging.h b/include/Logging.h index 422f1a7e..c6cfcb23 100644 --- a/include/Logging.h +++ b/include/Logging.h @@ -1,6 +1,7 @@ #pragma once #include + #include #include #include diff --git a/src/CaptivePortal.cpp b/src/CaptivePortal.cpp index 45ddd555..ee70830b 100644 --- a/src/CaptivePortal.cpp +++ b/src/CaptivePortal.cpp @@ -1,5 +1,7 @@ #include "CaptivePortal.h" +const char* const TAG = "CaptivePortal"; + #include "CaptivePortalInstance.h" #include "CommandHandler.h" #include "config/Config.h" @@ -15,8 +17,6 @@ #include -static const char* TAG = "CaptivePortal"; - using namespace OpenShock; static bool s_alwaysEnabled = false; diff --git a/src/CaptivePortalInstance.cpp b/src/CaptivePortalInstance.cpp index 0629c755..77f299ae 100644 --- a/src/CaptivePortalInstance.cpp +++ b/src/CaptivePortalInstance.cpp @@ -2,6 +2,8 @@ #include "CaptivePortalInstance.h" +const char* const TAG = "CaptivePortalInstance"; + #include "CommandHandler.h" #include "event_handlers/WebSocket.h" #include "GatewayConnectionManager.h" @@ -16,8 +18,6 @@ #include -static const char* TAG = "CaptivePortalInstance"; - const uint16_t HTTP_PORT = 80; const uint16_t WEBSOCKET_PORT = 81; const uint16_t DNS_PORT = 53; diff --git a/src/CommandHandler.cpp b/src/CommandHandler.cpp index a9d64ac4..91534faf 100644 --- a/src/CommandHandler.cpp +++ b/src/CommandHandler.cpp @@ -2,6 +2,8 @@ #include "CommandHandler.h" +const char* const TAG = "CommandHandler"; + #include "Chipset.h" #include "Common.h" #include "config/Config.h" @@ -16,8 +18,6 @@ #include #include -const char* const TAG = "CommandHandler"; - const int64_t KEEP_ALIVE_INTERVAL = 60'000; const uint16_t KEEP_ALIVE_DURATION = 300; diff --git a/src/EStopManager.cpp b/src/EStopManager.cpp index d7299d1d..7eb8130f 100644 --- a/src/EStopManager.cpp +++ b/src/EStopManager.cpp @@ -2,6 +2,8 @@ #include "EStopManager.h" +const char* const TAG = "EStopManager"; + #include "CommandHandler.h" #include "config/Config.h" #include "Logging.h" @@ -11,8 +13,6 @@ #include #include -const char* const TAG = "EStopManager"; - using namespace OpenShock; const uint32_t k_estopHoldToClearTime = 5000; diff --git a/src/GatewayClient.cpp b/src/GatewayClient.cpp index 9fa3ca36..5315aec3 100644 --- a/src/GatewayClient.cpp +++ b/src/GatewayClient.cpp @@ -1,5 +1,7 @@ #include "GatewayClient.h" +const char* const TAG = "GatewayClient"; + #include "Common.h" #include "config/Config.h" #include "event_handlers/WebSocket.h" @@ -10,8 +12,6 @@ #include "util/CertificateUtils.h" #include "VisualStateManager.h" -const char* const TAG = "GatewayClient"; - using namespace OpenShock; static bool s_bootStatusSent = false; diff --git a/src/GatewayConnectionManager.cpp b/src/GatewayConnectionManager.cpp index ecaae295..22a43559 100644 --- a/src/GatewayConnectionManager.cpp +++ b/src/GatewayConnectionManager.cpp @@ -1,5 +1,7 @@ #include "GatewayConnectionManager.h" +const char* const TAG = "GatewayConnectionManager"; + #include "VisualStateManager.h" #include "config/Config.h" @@ -24,7 +26,6 @@ // #warning SSL certificate verification is currently not implemented, by RFC definition this is a security risk, and allows for MITM attacks, but the realistic risk is low -static const char* const TAG = "GatewayConnectionManager"; static const char* const AUTH_TOKEN_FILE = "/authToken"; const uint8_t FLAG_NONE = 0; diff --git a/src/OtaUpdateManager.cpp b/src/OtaUpdateManager.cpp index 79c5d72d..07566958 100644 --- a/src/OtaUpdateManager.cpp +++ b/src/OtaUpdateManager.cpp @@ -1,5 +1,7 @@ #include "OtaUpdateManager.h" +const char* const TAG = "OtaUpdateManager"; + #include "CaptivePortal.h" #include "Common.h" #include "config/Config.h" @@ -40,8 +42,6 @@ #define OPENSHOCK_FW_CDN_FILESYSTEM_URL_FORMAT OPENSHOCK_FW_CDN_VERSION_BASE_URL_FORMAT "/staticfs.bin" #define OPENSHOCK_FW_CDN_SHA256_HASHES_URL_FORMAT OPENSHOCK_FW_CDN_VERSION_BASE_URL_FORMAT "/hashes.sha256.txt" -const char* const TAG = "OtaUpdateManager"; - /// @brief Stops initArduino() from handling OTA rollbacks /// @todo Get rid of Arduino entirely. >:( /// diff --git a/src/PinPatternManager.cpp b/src/PinPatternManager.cpp index bbfc8500..6d5d7718 100644 --- a/src/PinPatternManager.cpp +++ b/src/PinPatternManager.cpp @@ -2,11 +2,11 @@ #include "PinPatternManager.h" +const char* const TAG = "PinPatternManager"; + #include "Chipset.h" #include "Logging.h" -const char* const TAG = "PinPatternManager"; - using namespace OpenShock; PinPatternManager::PinPatternManager(gpio_num_t gpioPin) : m_gpioPin(GPIO_NUM_NC), m_pattern(), m_taskHandle(nullptr), m_taskMutex(xSemaphoreCreateMutex()) { diff --git a/src/RGBPatternManager.cpp b/src/RGBPatternManager.cpp index f6ba2b64..eef7e8d0 100644 --- a/src/RGBPatternManager.cpp +++ b/src/RGBPatternManager.cpp @@ -2,14 +2,14 @@ #include "RGBPatternManager.h" +const char* const TAG = "RGBPatternManager"; + #include "Chipset.h" #include "Logging.h" #include "util/TaskUtils.h" #include -const char* const TAG = "RGBPatternManager"; - using namespace OpenShock; // Currently this assumes a single WS2812B LED diff --git a/src/ReadWriteMutex.cpp b/src/ReadWriteMutex.cpp index d7d02211..b9b4507a 100644 --- a/src/ReadWriteMutex.cpp +++ b/src/ReadWriteMutex.cpp @@ -2,10 +2,10 @@ #include "ReadWriteMutex.h" -#include "Logging.h" - const char* const TAG = "ReadWriteMutex"; +#include "Logging.h" + OpenShock::ReadWriteMutex::ReadWriteMutex() : m_mutex(xSemaphoreCreateMutex()), m_readSem(xSemaphoreCreateBinary()), m_readers(0) { xSemaphoreGive(m_readSem); } diff --git a/src/SemVer.cpp b/src/SemVer.cpp index 99e612a7..bdd2678a 100644 --- a/src/SemVer.cpp +++ b/src/SemVer.cpp @@ -1,9 +1,9 @@ #include "SemVer.h" -#include "Logging.h" - const char* const TAG = "SemVer"; +#include "Logging.h" + using namespace OpenShock; constexpr bool _semverIsLetter(char c) { diff --git a/src/VisualStateManager.cpp b/src/VisualStateManager.cpp index 11599654..1a880343 100644 --- a/src/VisualStateManager.cpp +++ b/src/VisualStateManager.cpp @@ -1,5 +1,7 @@ #include "VisualStateManager.h" +const char* const TAG = "VisualStateManager"; + #include "Logging.h" #include "PinPatternManager.h" #include "RGBPatternManager.h" @@ -8,8 +10,6 @@ #include -const char* const TAG = "VisualStateManager"; - const uint64_t kCriticalErrorFlag = 1 << 0; const uint64_t kEmergencyStoppedFlag = 1 << 1; const uint64_t kEmergencyStopAwaitingReleaseFlag = 1 << 2; diff --git a/src/WebSocketDeFragger.cpp b/src/WebSocketDeFragger.cpp index a59f9ede..ca0f635c 100644 --- a/src/WebSocketDeFragger.cpp +++ b/src/WebSocketDeFragger.cpp @@ -1,11 +1,11 @@ #include "WebSocketDeFragger.h" +const char* const TAG = "WebSocketDeFragger"; + #include "Logging.h" #include -const char* const TAG = "WebSocketDeFragger"; - using namespace OpenShock; uint8_t* _reallocOrFree(uint8_t* ptr, std::size_t size) { diff --git a/src/config/BackendConfig.cpp b/src/config/BackendConfig.cpp index 351f213a..f0084640 100644 --- a/src/config/BackendConfig.cpp +++ b/src/config/BackendConfig.cpp @@ -1,10 +1,10 @@ #include "config/BackendConfig.h" +const char* const TAG = "Config::BackendConfig"; + #include "config/internal/utils.h" #include "Logging.h" -const char* const TAG = "Config::BackendConfig"; - using namespace OpenShock::Config; BackendConfig::BackendConfig() : domain(OPENSHOCK_API_DOMAIN), authToken(), lcgOverride() { } diff --git a/src/config/CaptivePortalConfig.cpp b/src/config/CaptivePortalConfig.cpp index 52a16d9e..617eb513 100644 --- a/src/config/CaptivePortalConfig.cpp +++ b/src/config/CaptivePortalConfig.cpp @@ -1,10 +1,10 @@ #include "config/CaptivePortalConfig.h" +const char* const TAG = "Config::CaptivePortalConfig"; + #include "config/internal/utils.h" #include "Logging.h" -const char* const TAG = "Config::CaptivePortalConfig"; - using namespace OpenShock::Config; CaptivePortalConfig::CaptivePortalConfig() : alwaysEnabled(false) { } diff --git a/src/config/Config.cpp b/src/config/Config.cpp index a9eb7604..c91d9739 100644 --- a/src/config/Config.cpp +++ b/src/config/Config.cpp @@ -1,5 +1,7 @@ #include "config/Config.h" +const char* const TAG = "Config"; + #include "Common.h" #include "config/RootConfig.h" #include "Logging.h" @@ -12,8 +14,6 @@ #include -const char* const TAG = "Config"; - using namespace OpenShock; static fs::LittleFSFS _configFS; diff --git a/src/config/OtaUpdateConfig.cpp b/src/config/OtaUpdateConfig.cpp index b8c8f2a7..a3dbcbdb 100644 --- a/src/config/OtaUpdateConfig.cpp +++ b/src/config/OtaUpdateConfig.cpp @@ -1,10 +1,10 @@ #include "config/OtaUpdateConfig.h" +const char* const TAG = "Config::OtaUpdateConfig"; + #include "config/internal/utils.h" #include "Logging.h" -const char* const TAG = "Config::OtaUpdateConfig"; - using namespace OpenShock::Config; OtaUpdateConfig::OtaUpdateConfig() { diff --git a/src/config/RFConfig.cpp b/src/config/RFConfig.cpp index 360d6152..91b952c6 100644 --- a/src/config/RFConfig.cpp +++ b/src/config/RFConfig.cpp @@ -1,11 +1,11 @@ #include "config/RFConfig.h" -#include "config/internal/utils.h" +const char* const TAG = "Config::RFConfig"; + #include "Common.h" +#include "config/internal/utils.h" #include "Logging.h" -const char* const TAG = "Config::RFConfig"; - using namespace OpenShock::Config; RFConfig::RFConfig() : txPin(OPENSHOCK_RF_TX_GPIO), keepAliveEnabled(true) { } diff --git a/src/config/RootConfig.cpp b/src/config/RootConfig.cpp index c3d0cb62..14cc0302 100644 --- a/src/config/RootConfig.cpp +++ b/src/config/RootConfig.cpp @@ -1,9 +1,9 @@ #include "config/RootConfig.h" -#include "Logging.h" - const char* const TAG = "Config::RootConfig"; +#include "Logging.h" + using namespace OpenShock::Config; void RootConfig::ToDefault() { diff --git a/src/config/SerialInputConfig.cpp b/src/config/SerialInputConfig.cpp index 2274fbe4..6411b1c8 100644 --- a/src/config/SerialInputConfig.cpp +++ b/src/config/SerialInputConfig.cpp @@ -1,10 +1,10 @@ #include "config/SerialInputConfig.h" +const char* const TAG = "Config::SerialInputConfig"; + #include "config/internal/utils.h" #include "Logging.h" -const char* const TAG = "Config::SerialInputConfig"; - using namespace OpenShock::Config; SerialInputConfig::SerialInputConfig() : echoEnabled(true) { } diff --git a/src/config/WiFiConfig.cpp b/src/config/WiFiConfig.cpp index c8244b1b..9c6e6d64 100644 --- a/src/config/WiFiConfig.cpp +++ b/src/config/WiFiConfig.cpp @@ -1,10 +1,10 @@ #include "config/WiFiConfig.h" +const char* const TAG = "Config::WiFiConfig"; + #include "config/internal/utils.h" #include "Logging.h" -const char* const TAG = "Config::WiFiConfig"; - using namespace OpenShock::Config; WiFiConfig::WiFiConfig() : accessPointSSID(OPENSHOCK_FW_AP_PREFIX), hostname(OPENSHOCK_FW_HOSTNAME), credentialsList() { } diff --git a/src/config/WiFiCredentials.cpp b/src/config/WiFiCredentials.cpp index 6dedc477..39561194 100644 --- a/src/config/WiFiCredentials.cpp +++ b/src/config/WiFiCredentials.cpp @@ -1,11 +1,11 @@ #include "config/WiFiCredentials.h" +const char* const TAG = "Config::WiFiCredentials"; + #include "config/internal/utils.h" #include "Logging.h" #include "util/HexUtils.h" -const char* const TAG = "Config::WiFiCredentials"; - using namespace OpenShock::Config; WiFiCredentials::WiFiCredentials() : id(0), ssid(), password() { } diff --git a/src/config/internal/utils.cpp b/src/config/internal/utils.cpp index 0055fd3e..02fc1230 100644 --- a/src/config/internal/utils.cpp +++ b/src/config/internal/utils.cpp @@ -1,9 +1,9 @@ #include "config/internal/utils.h" -#include "Logging.h" - const char* const TAG = "Config::Internal::Utils"; +#include "Logging.h" + using namespace OpenShock; template diff --git a/src/event_handlers/websocket/Gateway.cpp b/src/event_handlers/websocket/Gateway.cpp index 5473891d..926826b0 100644 --- a/src/event_handlers/websocket/Gateway.cpp +++ b/src/event_handlers/websocket/Gateway.cpp @@ -1,5 +1,7 @@ #include "event_handlers/WebSocket.h" +const char* const TAG = "ServerMessageHandlers"; + #include "event_handlers/impl/WSGateway.h" #include "Logging.h" @@ -11,8 +13,6 @@ #include #include -static const char* TAG = "ServerMessageHandlers"; - namespace Schemas = OpenShock::Serialization::Gateway; namespace Handlers = OpenShock::MessageHandlers::Server::_Private; typedef Schemas::GatewayToHubMessagePayload PayloadType; diff --git a/src/event_handlers/websocket/Local.cpp b/src/event_handlers/websocket/Local.cpp index d386e5b2..c0521e2a 100644 --- a/src/event_handlers/websocket/Local.cpp +++ b/src/event_handlers/websocket/Local.cpp @@ -1,5 +1,7 @@ #include "event_handlers/WebSocket.h" +const char* const TAG = "LocalMessageHandlers"; + #include "event_handlers/impl/WSLocal.h" #include "Logging.h" @@ -10,8 +12,6 @@ #include #include -static const char* TAG = "LocalMessageHandlers"; - namespace Schemas = OpenShock::Serialization::Local; namespace Handlers = OpenShock::MessageHandlers::Local::_Private; typedef Schemas::LocalToHubMessagePayload PayloadType; diff --git a/src/event_handlers/websocket/gateway/CaptivePortalConfig.cpp b/src/event_handlers/websocket/gateway/CaptivePortalConfig.cpp index 4ee97ea1..1403659b 100644 --- a/src/event_handlers/websocket/gateway/CaptivePortalConfig.cpp +++ b/src/event_handlers/websocket/gateway/CaptivePortalConfig.cpp @@ -1,12 +1,12 @@ #include "event_handlers/impl/WSGateway.h" +const char* const TAG = "ServerMessageHandlers"; + #include "CaptivePortal.h" #include "Logging.h" #include -const char* const TAG = "ServerMessageHandlers"; - using namespace OpenShock::MessageHandlers::Server; void _Private::HandleCaptivePortalConfig(const OpenShock::Serialization::Gateway::GatewayToHubMessage* root) { diff --git a/src/event_handlers/websocket/gateway/OtaInstall.cpp b/src/event_handlers/websocket/gateway/OtaInstall.cpp index 0f0b9a4a..9b397e10 100644 --- a/src/event_handlers/websocket/gateway/OtaInstall.cpp +++ b/src/event_handlers/websocket/gateway/OtaInstall.cpp @@ -1,13 +1,13 @@ #include "event_handlers/impl/WSGateway.h" +const char* const TAG = "ServerMessageHandlers"; + #include "CaptivePortal.h" #include "Logging.h" #include "OtaUpdateManager.h" #include -const char* const TAG = "ServerMessageHandlers"; - using namespace OpenShock::MessageHandlers::Server; void _Private::HandleOtaInstall(const OpenShock::Serialization::Gateway::GatewayToHubMessage* root) { diff --git a/src/event_handlers/websocket/gateway/ShockerCommandList.cpp b/src/event_handlers/websocket/gateway/ShockerCommandList.cpp index a7602729..550f4a7d 100644 --- a/src/event_handlers/websocket/gateway/ShockerCommandList.cpp +++ b/src/event_handlers/websocket/gateway/ShockerCommandList.cpp @@ -1,13 +1,13 @@ #include "event_handlers/impl/WSGateway.h" +const char* const TAG = "ServerMessageHandlers"; + #include "CommandHandler.h" #include "Logging.h" #include "ShockerModelType.h" #include -const char* const TAG = "ServerMessageHandlers"; - using namespace OpenShock::MessageHandlers::Server; void _Private::HandleShockerCommandList(const OpenShock::Serialization::Gateway::GatewayToHubMessage* root) { diff --git a/src/event_handlers/websocket/gateway/_InvalidMessage.cpp b/src/event_handlers/websocket/gateway/_InvalidMessage.cpp index 426cdf7c..1cc55353 100644 --- a/src/event_handlers/websocket/gateway/_InvalidMessage.cpp +++ b/src/event_handlers/websocket/gateway/_InvalidMessage.cpp @@ -1,10 +1,9 @@ #include "event_handlers/impl/WSGateway.h" -#include "Logging.h" - - const char* const TAG = "ServerMessageHandlers"; +#include "Logging.h" + using namespace OpenShock::MessageHandlers::Server; void _Private::HandleInvalidMessage(const OpenShock::Serialization::Gateway::GatewayToHubMessage* root) { diff --git a/src/event_handlers/websocket/local/AccountLinkCommand.cpp b/src/event_handlers/websocket/local/AccountLinkCommand.cpp index 875fa229..bd726394 100644 --- a/src/event_handlers/websocket/local/AccountLinkCommand.cpp +++ b/src/event_handlers/websocket/local/AccountLinkCommand.cpp @@ -1,13 +1,13 @@ #include "event_handlers/impl/WSLocal.h" +const char* const TAG = "LocalMessageHandlers"; + #include "CaptivePortal.h" #include "GatewayConnectionManager.h" #include "Logging.h" #include -const char* const TAG = "LocalMessageHandlers"; - void serializeSetRfTxPinResult(uint8_t socketId, OpenShock::Serialization::Local::AccountLinkResultCode result) { flatbuffers::FlatBufferBuilder builder(1024); diff --git a/src/event_handlers/websocket/local/AccountUnlinkCommand.cpp b/src/event_handlers/websocket/local/AccountUnlinkCommand.cpp index 0dab26c9..e5315b32 100644 --- a/src/event_handlers/websocket/local/AccountUnlinkCommand.cpp +++ b/src/event_handlers/websocket/local/AccountUnlinkCommand.cpp @@ -1,12 +1,12 @@ #include "event_handlers/impl/WSLocal.h" +const char* const TAG = "LocalMessageHandlers"; + #include "GatewayConnectionManager.h" #include "Logging.h" #include -const char* const TAG = "LocalMessageHandlers"; - using namespace OpenShock::MessageHandlers::Local; void _Private::HandleAccountUnlinkCommand(uint8_t socketId, const OpenShock::Serialization::Local::LocalToHubMessage* root) { diff --git a/src/event_handlers/websocket/local/SetRfTxPinCommand.cpp b/src/event_handlers/websocket/local/SetRfTxPinCommand.cpp index 7e2a98ab..00ca23ff 100644 --- a/src/event_handlers/websocket/local/SetRfTxPinCommand.cpp +++ b/src/event_handlers/websocket/local/SetRfTxPinCommand.cpp @@ -1,5 +1,7 @@ #include "event_handlers/impl/WSLocal.h" +const char* const TAG = "LocalMessageHandlers"; + #include "CaptivePortal.h" #include "CommandHandler.h" #include "Common.h" @@ -7,8 +9,6 @@ #include -const char* const TAG = "LocalMessageHandlers"; - void serializeSetRfTxPinResult(uint8_t socketId, uint8_t pin, OpenShock::Serialization::Local::SetRfPinResultCode result) { flatbuffers::FlatBufferBuilder builder(1024); diff --git a/src/event_handlers/websocket/local/WiFiNetworkConnectCommand.cpp b/src/event_handlers/websocket/local/WiFiNetworkConnectCommand.cpp index 50bb39e6..0c568772 100644 --- a/src/event_handlers/websocket/local/WiFiNetworkConnectCommand.cpp +++ b/src/event_handlers/websocket/local/WiFiNetworkConnectCommand.cpp @@ -1,13 +1,13 @@ #include "event_handlers/impl/WSLocal.h" +const char* const TAG = "LocalMessageHandlers"; + #include "Logging.h" #include "util/HexUtils.h" #include "wifi/WiFiManager.h" #include -const char* const TAG = "LocalMessageHandlers"; - using namespace OpenShock::MessageHandlers::Local; void _Private::HandleWiFiNetworkConnectCommand(uint8_t socketId, const OpenShock::Serialization::Local::LocalToHubMessage* root) { diff --git a/src/event_handlers/websocket/local/WiFiNetworkDisconnectCommand.cpp b/src/event_handlers/websocket/local/WiFiNetworkDisconnectCommand.cpp index 6a4179d9..f6435c64 100644 --- a/src/event_handlers/websocket/local/WiFiNetworkDisconnectCommand.cpp +++ b/src/event_handlers/websocket/local/WiFiNetworkDisconnectCommand.cpp @@ -1,13 +1,13 @@ #include "event_handlers/impl/WSLocal.h" +const char* const TAG = "LocalMessageHandlers"; + #include "Logging.h" #include "util/HexUtils.h" #include "wifi/WiFiManager.h" #include -const char* const TAG = "LocalMessageHandlers"; - using namespace OpenShock::MessageHandlers::Local; void _Private::HandleWiFiNetworkDisconnectCommand(uint8_t socketId, const OpenShock::Serialization::Local::LocalToHubMessage* root) { diff --git a/src/event_handlers/websocket/local/WiFiNetworkForgetCommand.cpp b/src/event_handlers/websocket/local/WiFiNetworkForgetCommand.cpp index cf2410d0..a8c4afe8 100644 --- a/src/event_handlers/websocket/local/WiFiNetworkForgetCommand.cpp +++ b/src/event_handlers/websocket/local/WiFiNetworkForgetCommand.cpp @@ -1,13 +1,13 @@ #include "event_handlers/impl/WSLocal.h" +const char* const TAG = "LocalMessageHandlers"; + #include "Logging.h" #include "util/HexUtils.h" #include "wifi/WiFiManager.h" #include -const char* const TAG = "LocalMessageHandlers"; - using namespace OpenShock::MessageHandlers::Local; void _Private::HandleWiFiNetworkForgetCommand(uint8_t socketId, const OpenShock::Serialization::Local::LocalToHubMessage* root) { diff --git a/src/event_handlers/websocket/local/WiFiNetworkSaveCommand.cpp b/src/event_handlers/websocket/local/WiFiNetworkSaveCommand.cpp index c1f3f08c..a8648c14 100644 --- a/src/event_handlers/websocket/local/WiFiNetworkSaveCommand.cpp +++ b/src/event_handlers/websocket/local/WiFiNetworkSaveCommand.cpp @@ -1,13 +1,13 @@ #include "event_handlers/impl/WSLocal.h" +const char* const TAG = "LocalMessageHandlers"; + #include "Logging.h" #include "util/HexUtils.h" #include "wifi/WiFiManager.h" #include -const char* const TAG = "LocalMessageHandlers"; - using namespace OpenShock::MessageHandlers::Local; void _Private::HandleWiFiNetworkSaveCommand(uint8_t socketId, const OpenShock::Serialization::Local::LocalToHubMessage* root) { diff --git a/src/event_handlers/websocket/local/WiFiScanCommand.cpp b/src/event_handlers/websocket/local/WiFiScanCommand.cpp index 431215b9..bad3c16c 100644 --- a/src/event_handlers/websocket/local/WiFiScanCommand.cpp +++ b/src/event_handlers/websocket/local/WiFiScanCommand.cpp @@ -1,10 +1,10 @@ #include "event_handlers/impl/WSLocal.h" +const char* const TAG = "LocalMessageHandlers"; + #include "Logging.h" #include "wifi/WiFiScanManager.h" -const char* const TAG = "LocalMessageHandlers"; - using namespace OpenShock::MessageHandlers::Local; void _Private::HandleWiFiScanCommand(uint8_t socketId, const OpenShock::Serialization::Local::LocalToHubMessage* root) { diff --git a/src/event_handlers/websocket/local/_InvalidMessage.cpp b/src/event_handlers/websocket/local/_InvalidMessage.cpp index ecc4c022..79bacdeb 100644 --- a/src/event_handlers/websocket/local/_InvalidMessage.cpp +++ b/src/event_handlers/websocket/local/_InvalidMessage.cpp @@ -1,9 +1,9 @@ #include "event_handlers/impl/WSLocal.h" -#include "Logging.h" - const char* const TAG = "LocalMessageHandlers"; +#include "Logging.h" + using namespace OpenShock::MessageHandlers::Local; void _Private::HandleInvalidMessage(uint8_t socketId, const OpenShock::Serialization::Local::LocalToHubMessage* root) { diff --git a/src/http/HTTPRequestManager.cpp b/src/http/HTTPRequestManager.cpp index 1f340f15..26726efd 100644 --- a/src/http/HTTPRequestManager.cpp +++ b/src/http/HTTPRequestManager.cpp @@ -1,5 +1,7 @@ #include "http/HTTPRequestManager.h" +const char* const TAG = "HTTPRequestManager"; + #include "Common.h" #include "Logging.h" #include "Time.h" @@ -15,8 +17,6 @@ const std::size_t HTTP_BUFFER_SIZE = 4096LLU; const int HTTP_DOWNLOAD_SIZE_LIMIT = 200 * 1024 * 1024; // 200 MB -const char* const TAG = "HTTPRequestManager"; - struct RateLimit { RateLimit() : m_mutex(xSemaphoreCreateMutex()), m_blockUntilMs(0), m_limits(), m_requests() { } diff --git a/src/main.cpp b/src/main.cpp index f62331e5..a13f0929 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,5 @@ +const char* const TAG = "main"; + #include "CaptivePortal.h" #include "CommandHandler.h" #include "Common.h" @@ -17,8 +19,6 @@ #include -const char* const TAG = "OpenShock"; - // Internal setup function, returns true if setup succeeded, false otherwise. bool trySetup() { OpenShock::EventHandlers::Init(); diff --git a/src/radio/RFTransmitter.cpp b/src/radio/RFTransmitter.cpp index 4179378f..9cdf33f0 100644 --- a/src/radio/RFTransmitter.cpp +++ b/src/radio/RFTransmitter.cpp @@ -2,6 +2,8 @@ #include "radio/RFTransmitter.h" +const char* const TAG = "RFTransmitter"; + #include "EStopManager.h" #include "Logging.h" @@ -11,8 +13,6 @@ #include -const char* const TAG = "RFTransmitter"; - const UBaseType_t RFTRANSMITTER_QUEUE_SIZE = 64; const BaseType_t RFTRANSMITTER_TASK_PRIORITY = 1; const uint32_t RFTRANSMITTER_TASK_STACK_SIZE = 4096; // PROFILED: 1.4KB stack usage diff --git a/src/radio/rmt/MainEncoder.cpp b/src/radio/rmt/MainEncoder.cpp index ada85fef..51951a1f 100644 --- a/src/radio/rmt/MainEncoder.cpp +++ b/src/radio/rmt/MainEncoder.cpp @@ -1,14 +1,14 @@ #include "radio/rmt/MainEncoder.h" +const char* const TAG = "RmtMainEncoder"; + #include "Logging.h" #include "radio/rmt/CaiXianlinEncoder.h" -#include "radio/rmt/PetrainerEncoder.h" #include "radio/rmt/Petrainer998DREncoder.h" +#include "radio/rmt/PetrainerEncoder.h" #include -const char* const TAG = "RmtMainEncoder"; - using namespace OpenShock; std::vector Rmt::GetSequence(ShockerModelType model, uint16_t shockerId, ShockerCommandType type, uint8_t intensity) { diff --git a/src/serial/SerialInputHandler.cpp b/src/serial/SerialInputHandler.cpp index fb7762f5..52b022ac 100644 --- a/src/serial/SerialInputHandler.cpp +++ b/src/serial/SerialInputHandler.cpp @@ -1,17 +1,19 @@ #include "serial/SerialInputHandler.h" +const char* const TAG = "SerialInputHandler"; + #include "Chipset.h" #include "CommandHandler.h" #include "config/Config.h" #include "config/SerialInputConfig.h" #include "FormatHelpers.h" #include "http/HTTPRequestManager.h" +#include "intconv.h" #include "Logging.h" #include "serialization/JsonAPI.h" #include "serialization/JsonSerial.h" #include "StringView.h" #include "Time.h" -#include "intconv.h" #include "util/Base64Utils.h" #include "wifi/WiFiManager.h" @@ -22,8 +24,6 @@ #include -const char* const TAG = "SerialInputHandler"; - #define SERPR_SYS(format, ...) Serial.printf("$SYS$|" format "\n", ##__VA_ARGS__) #define SERPR_RESPONSE(format, ...) SERPR_SYS("Response|" format, ##__VA_ARGS__) #define SERPR_SUCCESS(format, ...) SERPR_SYS("Success|" format, ##__VA_ARGS__) diff --git a/src/serialization/JsonAPI.cpp b/src/serialization/JsonAPI.cpp index d1f5749c..815f4d1b 100644 --- a/src/serialization/JsonAPI.cpp +++ b/src/serialization/JsonAPI.cpp @@ -1,9 +1,9 @@ #include "serialization/JsonAPI.h" -#include "Logging.h" - const char* const TAG = "JsonAPI"; +#include "Logging.h" + #define ESP_LOGJSONE(err, root) ESP_LOGE(TAG, "Invalid JSON response (" err "): %s", cJSON_PrintUnformatted(root)) using namespace OpenShock::Serialization; diff --git a/src/serialization/JsonSerial.cpp b/src/serialization/JsonSerial.cpp index 49ef5ee3..a3588d8c 100644 --- a/src/serialization/JsonSerial.cpp +++ b/src/serialization/JsonSerial.cpp @@ -1,9 +1,9 @@ #include "serialization/JsonSerial.h" -#include "Logging.h" - const char* const TAG = "JsonSerial"; +#include "Logging.h" + using namespace OpenShock::Serialization; bool JsonSerial::ParseShockerCommand(const cJSON* root, JsonSerial::ShockerCommand& out) { diff --git a/src/serialization/WSGateway.cpp b/src/serialization/WSGateway.cpp index bc4c3b3f..98911bc6 100644 --- a/src/serialization/WSGateway.cpp +++ b/src/serialization/WSGateway.cpp @@ -1,11 +1,11 @@ #include "serialization/WSGateway.h" +const char* const TAG = "WSGateway"; + #include "config/Config.h" #include "Logging.h" #include "Time.h" -const char* const TAG = "WSGateway"; - using namespace OpenShock::Serialization; bool Gateway::SerializeKeepAliveMessage(Common::SerializationCallbackFn callback) { diff --git a/src/serialization/WSLocal.cpp b/src/serialization/WSLocal.cpp index 88c1e5b9..d81a9e42 100644 --- a/src/serialization/WSLocal.cpp +++ b/src/serialization/WSLocal.cpp @@ -1,5 +1,7 @@ #include "serialization/WSLocal.h" +const char* const TAG = "WSLocal"; + #include "config/Config.h" #include "Logging.h" #include "util/HexUtils.h" @@ -7,8 +9,6 @@ #include "serialization/_fbs/HubToLocalMessage_generated.h" -const char* const TAG = "WSLocal"; - using namespace OpenShock::Serialization; typedef OpenShock::Serialization::Types::WifiAuthMode WiFiAuthMode; diff --git a/src/util/Base64Utils.cpp b/src/util/Base64Utils.cpp index 5298e876..bf25f848 100644 --- a/src/util/Base64Utils.cpp +++ b/src/util/Base64Utils.cpp @@ -1,11 +1,11 @@ #include "util/Base64Utils.h" +const char* const TAG = "Base64Utils"; + #include "Logging.h" #include -const char* const TAG = "Base64Utils"; - using namespace OpenShock; std::size_t Base64Utils::Encode(const uint8_t* data, std::size_t dataLen, char* output, std::size_t outputLen) noexcept { diff --git a/src/util/CertificateUtils.cpp b/src/util/CertificateUtils.cpp index 35e9b281..07036a1e 100644 --- a/src/util/CertificateUtils.cpp +++ b/src/util/CertificateUtils.cpp @@ -1,11 +1,11 @@ #include "util/CertificateUtils.h" +const char* const TAG = "CertificateUtils"; + #include "Logging.h" #include -const char* const TAG = "CertificateUtils"; - const char* const PEM_HEADER = "-----BEGIN CERTIFICATE-----\n"; const char* const PEM_FOOTER = "-----END CERTIFICATE-----\n"; diff --git a/src/util/ParitionUtils.cpp b/src/util/ParitionUtils.cpp index 009d8915..da969b9b 100644 --- a/src/util/ParitionUtils.cpp +++ b/src/util/ParitionUtils.cpp @@ -1,13 +1,13 @@ #include "util/PartitionUtils.h" +const char* const TAG = "PartitionUtils"; + #include "Hashing.h" #include "http/HTTPRequestManager.h" #include "Logging.h" #include "Time.h" #include "util/HexUtils.h" -const char* const TAG = "PartitionUtils"; - bool OpenShock::TryGetPartitionHash(const esp_partition_t* partition, char (&hash)[65]) { uint8_t buffer[32]; esp_err_t err = esp_partition_get_sha256(partition, buffer); diff --git a/src/util/StringUtils.cpp b/src/util/StringUtils.cpp index d32c6d55..a14d05e2 100644 --- a/src/util/StringUtils.cpp +++ b/src/util/StringUtils.cpp @@ -1,12 +1,12 @@ #include "util/StringUtils.h" +const char* const TAG = "StringUtils"; + #include "Logging.h" #include #include -static const char* TAG = "StringUtils"; - bool OpenShock::FormatToString(std::string& out, const char* format, ...) { const std::size_t STACK_BUFFER_SIZE = 128; diff --git a/src/wifi/WiFiManager.cpp b/src/wifi/WiFiManager.cpp index 644b6c13..98c4236e 100644 --- a/src/wifi/WiFiManager.cpp +++ b/src/wifi/WiFiManager.cpp @@ -1,5 +1,7 @@ #include "wifi/WiFiManager.h" +const char* const TAG = "WiFiManager"; + #include "CaptivePortal.h" #include "config/Config.h" #include "FormatHelpers.h" @@ -18,8 +20,6 @@ #include #include -const char* const TAG = "WiFiManager"; - using namespace OpenShock; enum class WiFiState : uint8_t { diff --git a/src/wifi/WiFiScanManager.cpp b/src/wifi/WiFiScanManager.cpp index e9e78416..af2b4c2a 100644 --- a/src/wifi/WiFiScanManager.cpp +++ b/src/wifi/WiFiScanManager.cpp @@ -1,13 +1,13 @@ #include "wifi/WiFiScanManager.h" +const char* const TAG = "WiFiScanManager"; + #include "Logging.h" #include #include -const char* const TAG = "WiFiScanManager"; - const uint8_t OPENSHOCK_WIFI_SCAN_MAX_CHANNEL = 13; const uint32_t OPENSHOCK_WIFI_SCAN_MAX_MS_PER_CHANNEL = 300; // Adjusting this value will affect the scan rate, but may also affect the scan results const uint32_t OPENSHOCK_WIFI_SCAN_TIMEOUT_MS = 10 * 1000; From c6834319471161dd083f110ae76817f82e9f24e0 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 30 Aug 2024 13:24:20 +0200 Subject: [PATCH 06/41] Remove static in front of global constants --- src/GatewayConnectionManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GatewayConnectionManager.cpp b/src/GatewayConnectionManager.cpp index 22a43559..b0943b36 100644 --- a/src/GatewayConnectionManager.cpp +++ b/src/GatewayConnectionManager.cpp @@ -26,7 +26,7 @@ const char* const TAG = "GatewayConnectionManager"; // #warning SSL certificate verification is currently not implemented, by RFC definition this is a security risk, and allows for MITM attacks, but the realistic risk is low -static const char* const AUTH_TOKEN_FILE = "/authToken"; +const char* const AUTH_TOKEN_FILE = "/authToken"; const uint8_t FLAG_NONE = 0; const uint8_t FLAG_HAS_IP = 1 << 0; From c9d763b047282dd1c3d25ff8e3da088eccd14789 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 30 Aug 2024 14:03:36 +0200 Subject: [PATCH 07/41] Fix plaformio.ini build_flag concationation --- platformio.ini | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/platformio.ini b/platformio.ini index 7c73215a..45328ef2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,6 +13,7 @@ platform = espressif32 @ 6.8.1 board = az-delivery-devkit-v4 ; Overridden per board framework = arduino build_flags = + -std=c++2a -std=gnu++2a build_unflags = -std=gnu++11 @@ -50,7 +51,7 @@ check_flags = [env:Wemos-D1-Mini-ESP32] board = Wemos-D1-Mini-ESP32 custom_openshock.chip = ESP32 -build_flags = +build_flags = ${env.build_flags} -DOPENSHOCK_LED_GPIO=2 -DOPENSHOCK_RF_TX_GPIO=15 @@ -66,7 +67,7 @@ build_flags = board = Wemos-Lolin-S3 ; override custom_openshock.chip = ESP32-S3 custom_openshock.flash_size = 16MB -build_flags = +build_flags = ${env.build_flags} -DOPENSHOCK_LED_WS2812B=38 ; https://docs.platformio.org/en/latest/boards/espressif32/lolin_s3_mini.html @@ -74,7 +75,7 @@ build_flags = board = lolin_s3_mini ; builtin custom_openshock.chip = ESP32-S3 custom_openshock.flash_size = 4MB -build_flags = +build_flags = ${env.build_flags} -DOPENSHOCK_LED_WS2812B=47 -DOPENSHOCK_LED_FLIP_RG_CHANNELS=1 -DARDUINO_USB_CDC_ON_BOOT=1 @@ -84,7 +85,7 @@ build_flags = board = esp32-s3-devkitc-1 custom_openshock.chip = ESP32-S3 custom_openshock.flash_size = 4MB -build_flags = +build_flags = ${env.build_flags} -DOPENSHOCK_RF_TX_GPIO=1 -DOPENSHOCK_LED_WS2812B=21 -DOPENSHOCK_LED_FLIP_RG_CHANNELS=1 @@ -93,14 +94,14 @@ build_flags = [env:Pishock-2023] board = Wemos-D1-Mini-ESP32 ; override custom_openshock.chip = ESP32 -build_flags = +build_flags = ${env.build_flags} -DOPENSHOCK_LED_GPIO=2 -DOPENSHOCK_RF_TX_GPIO=12 [env:Pishock-Lite-2021] board = Wemos-D1-Mini-ESP32 ; override custom_openshock.chip = ESP32 -build_flags = +build_flags = ${env.build_flags} -DOPENSHOCK_LED_GPIO=2 -DOPENSHOCK_RF_TX_GPIO=15 @@ -115,7 +116,7 @@ custom_openshock.flash_size = 4MB board = seeed_xiao_esp32s3 ; builtin custom_openshock.chip = ESP32-S3 custom_openshock.flash_size = 8MB -build_flags = +build_flags = ${env.build_flags} -DOPENSHOCK_LED_GPIO=21 ; https://docs.platformio.org/en/latest//boards/espressif32/dfrobot_firebeetle2_esp32e.html @@ -123,7 +124,7 @@ build_flags = board = dfrobot_firebeetle2_esp32e ; builtin custom_openshock.chip = ESP32 custom_openshock.flash_size = 4MB -build_flags = +build_flags = ${env.build_flags} -DOPENSHOCK_RF_TX_GPIO=13 -DOPENSHOCK_LED_WS2812B=5 -DOPENSHOCK_LED_GPIO=2 @@ -135,7 +136,7 @@ build_flags = board = esp32-s3-devkitc-1 ; builtin custom_openshock.chip = ESP32-S3 custom_openshock.flash_size = 8MB -build_flags = +build_flags = ${env.build_flags} -DOPENSHOCK_LED_WS2812B=48 -DOPENSHOCK_LED_GPIO=35 -DOPENSHOCK_RF_TX_GPIO=15 @@ -148,7 +149,7 @@ build_flags = board = esp32-s3-devkitc-1 ; builtin custom_openshock.chip = ESP32-S3 custom_openshock.flash_size = 8MB -build_flags = +build_flags = ${env.build_flags} -DOPENSHOCK_LED_WS2812B=14 -DOPENSHOCK_LED_GPIO=13 -DOPENSHOCK_RF_TX_GPIO=1 From 75e9555929e96c632bd1de6d9345e44835b71dc2 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 30 Aug 2024 14:10:43 +0200 Subject: [PATCH 08/41] Add C++ version checks --- include/Common.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/Common.h b/include/Common.h index a4c557ea..bec0778b 100644 --- a/include/Common.h +++ b/include/Common.h @@ -41,6 +41,24 @@ #warning "Let it be known that Arduino hath finally been cast aside in favor of the noble ESP-IDF! I beseech thee, kind sir or madam, wouldst thou kindly partake in the honors of expunging 'arduino-esp32' from yonder useragent aloft, and in its stead, bestow the illustrious 'ESP-IDF'?" #endif +#if __cplusplus >= 202'302L +#warning "C++23 compiler detected" +#elif __cplusplus >= 202'002L +#warning "C++20 compiler detected" +#elif __cplusplus >= 201'703L +// C++17 :3 +#elif __cplusplus >= 201'402L +#error "C++14 compiler detected, OpenShock requires a C++17 compliant compiler" +#elif __cplusplus >= 201'103L +#error "C++11 compiler detected, OpenShock requires a C++17 compliant compiler" +#elif __cplusplus >= 199'711L +#error "C++98 compiler detected, OpenShock requires a C++17 compliant compiler" +#elif __cplusplus == 1 +#error "Pre-C++98 compiler detected, OpenShock requires a C++17 compliant compiler" +#else +#error "Unknown C++ standard detected, OpenShock requires a C++17 compliant compiler" +#endif + namespace OpenShock::Constants { const char* const FW_USERAGENT = OPENSHOCK_FW_USERAGENT; const StringView FW_USERAGENT_sv = OPENSHOCK_FW_USERAGENT ""_sv; From 9e48dc2b01ac55cfb624b19843e908a0766756b0 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 30 Aug 2024 14:17:19 +0200 Subject: [PATCH 09/41] Fix config for Wemos Lolin S2 Mini --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 45328ef2..12c2d5f1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -59,7 +59,7 @@ build_flags = ${env.build_flags} [env:Wemos-Lolin-S2-Mini] board = Wemos-Lolin-S2-Mini ; override custom_openshock.chip = ESP32-S2 -build_flags = +build_flags = ${env.build_flags} -DOPENSHOCK_LED_GPIO=15 ; https://docs.platformio.org/en/latest/boards/espressif32/lolin_s3.html From 0b78ec572b796c4b279407e881c7ad1c3848e66c Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 30 Aug 2024 14:29:27 +0200 Subject: [PATCH 10/41] C++17: Use std::clamp --- src/CommandHandler.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/CommandHandler.cpp b/src/CommandHandler.cpp index 91534faf..c91d566e 100644 --- a/src/CommandHandler.cpp +++ b/src/CommandHandler.cpp @@ -23,13 +23,9 @@ const uint16_t KEEP_ALIVE_DURATION = 300; using namespace OpenShock; -template -constexpr T saturate(T value, T min, T max) { - return std::min(std::max(value, min), max); -} uint32_t calculateEepyTime(int64_t timeToKeepAlive) { int64_t now = OpenShock::millis(); - return static_cast(saturate(timeToKeepAlive - now, 0LL, KEEP_ALIVE_INTERVAL)); + return static_cast(std::clamp(timeToKeepAlive - now, 0LL, KEEP_ALIVE_INTERVAL)); } struct KnownShocker { From c1d82b509a5b61e0885803beb8ba23c5b511a05c Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 30 Aug 2024 15:23:08 +0200 Subject: [PATCH 11/41] C++17: Add nodiscard attributes --- include/CommandHandler.h | 2 +- include/GatewayConnectionManager.h | 2 +- include/OtaUpdateManager.h | 2 +- include/VisualStateManager.h | 2 +- include/config/BackendConfig.h | 4 ++-- include/config/CaptivePortalConfig.h | 4 ++-- include/config/Config.h | 2 +- include/config/ConfigBase.h | 8 ++++---- include/config/OtaUpdateConfig.h | 4 ++-- include/config/RFConfig.h | 4 ++-- include/config/RootConfig.h | 4 ++-- include/config/SerialInputConfig.h | 4 ++-- include/config/WiFiConfig.h | 4 ++-- include/config/WiFiCredentials.h | 4 ++-- include/http/HTTPRequestManager.h | 2 +- include/serial/SerialInputHandler.h | 2 +- include/wifi/WiFiManager.h | 2 +- include/wifi/WiFiScanManager.h | 2 +- 18 files changed, 29 insertions(+), 29 deletions(-) diff --git a/include/CommandHandler.h b/include/CommandHandler.h index 399064ad..65f8c31f 100644 --- a/include/CommandHandler.h +++ b/include/CommandHandler.h @@ -9,7 +9,7 @@ // TODO: This is horrible architecture. Fix it. namespace OpenShock::CommandHandler { - bool Init(); + [[nodiscard]] bool Init(); bool Ok(); SetRfPinResultCode SetRfTxPin(uint8_t txPin); diff --git a/include/GatewayConnectionManager.h b/include/GatewayConnectionManager.h index 855c2ae5..e32cbacf 100644 --- a/include/GatewayConnectionManager.h +++ b/include/GatewayConnectionManager.h @@ -7,7 +7,7 @@ #include namespace OpenShock::GatewayConnectionManager { - bool Init(); + [[nodiscard]] bool Init(); bool IsConnected(); diff --git a/include/OtaUpdateManager.h b/include/OtaUpdateManager.h index f4f8bda0..9b64873a 100644 --- a/include/OtaUpdateManager.h +++ b/include/OtaUpdateManager.h @@ -11,7 +11,7 @@ #include namespace OpenShock::OtaUpdateManager { - bool Init(); + [[nodiscard]] bool Init(); struct FirmwareRelease { std::string appBinaryUrl; diff --git a/include/VisualStateManager.h b/include/VisualStateManager.h index b7a56198..2831f960 100644 --- a/include/VisualStateManager.h +++ b/include/VisualStateManager.h @@ -4,7 +4,7 @@ #include namespace OpenShock::VisualStateManager { - bool Init(); + [[nodiscard]] bool Init(); void SetCriticalError(); void SetScanningStarted(); diff --git a/include/config/BackendConfig.h b/include/config/BackendConfig.h index 4f2b3b48..ef4b429b 100644 --- a/include/config/BackendConfig.h +++ b/include/config/BackendConfig.h @@ -17,9 +17,9 @@ namespace OpenShock::Config { void ToDefault() override; bool FromFlatbuffers(const Serialization::Configuration::BackendConfig* config) override; - flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const override; + [[nodiscard]] flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const override; bool FromJSON(const cJSON* json) override; - cJSON* ToJSON(bool withSensitiveData) const override; + [[nodiscard]] cJSON* ToJSON(bool withSensitiveData) const override; }; } // namespace OpenShock::Config diff --git a/include/config/CaptivePortalConfig.h b/include/config/CaptivePortalConfig.h index fd33edc9..359321ca 100644 --- a/include/config/CaptivePortalConfig.h +++ b/include/config/CaptivePortalConfig.h @@ -12,9 +12,9 @@ namespace OpenShock::Config { void ToDefault() override; bool FromFlatbuffers(const Serialization::Configuration::CaptivePortalConfig* config) override; - flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const override; + [[nodiscard]] flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const override; bool FromJSON(const cJSON* json) override; - cJSON* ToJSON(bool withSensitiveData) const override; + [[nodiscard]] cJSON* ToJSON(bool withSensitiveData) const override; }; } // namespace OpenShock::Config diff --git a/include/config/Config.h b/include/config/Config.h index ad901c0e..6a865b3b 100644 --- a/include/config/Config.h +++ b/include/config/Config.h @@ -20,7 +20,7 @@ namespace OpenShock::Config { bool SaveFromJSON(StringView json); /* GetAsFlatBuffer and SaveFromFlatBuffer are used for Reading/Writing the config file in its binary form. */ - flatbuffers::Offset GetAsFlatBuffer(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData); + [[nodiscard]] flatbuffers::Offset GetAsFlatBuffer(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData); bool SaveFromFlatBuffer(const Serialization::Configuration::HubConfig* config); /* GetRaw and SetRaw are used for Reading/Writing the config file in its binary form. */ diff --git a/include/config/ConfigBase.h b/include/config/ConfigBase.h index 88a417ab..3bd7abc7 100644 --- a/include/config/ConfigBase.h +++ b/include/config/ConfigBase.h @@ -9,11 +9,11 @@ namespace OpenShock::Config { struct ConfigBase { virtual void ToDefault() = 0; - virtual bool FromFlatbuffers(const T* config) = 0; - virtual flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const = 0; + virtual bool FromFlatbuffers(const T* config) = 0; + [[nodiscard]] virtual flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const = 0; - virtual bool FromJSON(const cJSON* json) = 0; - virtual cJSON* ToJSON(bool withSensitiveData) const = 0; + virtual bool FromJSON(const cJSON* json) = 0; + [[nodiscard]] virtual cJSON* ToJSON(bool withSensitiveData) const = 0; }; } // namespace OpenShock::Config diff --git a/include/config/OtaUpdateConfig.h b/include/config/OtaUpdateConfig.h index e02fe39d..3bcec5ef 100644 --- a/include/config/OtaUpdateConfig.h +++ b/include/config/OtaUpdateConfig.h @@ -37,9 +37,9 @@ namespace OpenShock::Config { void ToDefault() override; bool FromFlatbuffers(const Serialization::Configuration::OtaUpdateConfig* config) override; - flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const override; + [[nodiscard]] flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const override; bool FromJSON(const cJSON* json) override; - cJSON* ToJSON(bool withSensitiveData) const override; + [[nodiscard]] cJSON* ToJSON(bool withSensitiveData) const override; }; } // namespace OpenShock::Config diff --git a/include/config/RFConfig.h b/include/config/RFConfig.h index fb16590a..59e76124 100644 --- a/include/config/RFConfig.h +++ b/include/config/RFConfig.h @@ -13,9 +13,9 @@ namespace OpenShock::Config { void ToDefault() override; bool FromFlatbuffers(const Serialization::Configuration::RFConfig* config) override; - flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const override; + [[nodiscard]] flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const override; bool FromJSON(const cJSON* json) override; - cJSON* ToJSON(bool withSensitiveData) const override; + [[nodiscard]] cJSON* ToJSON(bool withSensitiveData) const override; }; } // namespace OpenShock::Config diff --git a/include/config/RootConfig.h b/include/config/RootConfig.h index 44e2fe6c..8488941e 100644 --- a/include/config/RootConfig.h +++ b/include/config/RootConfig.h @@ -20,9 +20,9 @@ namespace OpenShock::Config { void ToDefault() override; bool FromFlatbuffers(const Serialization::Configuration::HubConfig* config) override; - flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const override; + [[nodiscard]] flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const override; bool FromJSON(const cJSON* json) override; - cJSON* ToJSON(bool withSensitiveData) const override; + [[nodiscard]] cJSON* ToJSON(bool withSensitiveData) const override; }; } // namespace OpenShock::Config diff --git a/include/config/SerialInputConfig.h b/include/config/SerialInputConfig.h index 44c27aaf..a9ac7746 100644 --- a/include/config/SerialInputConfig.h +++ b/include/config/SerialInputConfig.h @@ -12,9 +12,9 @@ namespace OpenShock::Config { void ToDefault() override; bool FromFlatbuffers(const Serialization::Configuration::SerialInputConfig* config) override; - flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const override; + [[nodiscard]] flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const override; bool FromJSON(const cJSON* json) override; - cJSON* ToJSON(bool withSensitiveData) const override; + [[nodiscard]] cJSON* ToJSON(bool withSensitiveData) const override; }; } // namespace OpenShock::Config diff --git a/include/config/WiFiConfig.h b/include/config/WiFiConfig.h index e29dfafc..f8958d40 100644 --- a/include/config/WiFiConfig.h +++ b/include/config/WiFiConfig.h @@ -19,9 +19,9 @@ namespace OpenShock::Config { void ToDefault() override; bool FromFlatbuffers(const Serialization::Configuration::WiFiConfig* config) override; - flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const override; + [[nodiscard]] flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const override; bool FromJSON(const cJSON* json) override; - cJSON* ToJSON(bool withSensitiveData) const override; + [[nodiscard]] cJSON* ToJSON(bool withSensitiveData) const override; }; } // namespace OpenShock::Config diff --git a/include/config/WiFiCredentials.h b/include/config/WiFiCredentials.h index 50a15ff7..b25c0767 100644 --- a/include/config/WiFiCredentials.h +++ b/include/config/WiFiCredentials.h @@ -17,9 +17,9 @@ namespace OpenShock::Config { void ToDefault() override; bool FromFlatbuffers(const Serialization::Configuration::WiFiCredentials* config) override; - flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const override; + [[nodiscard]] flatbuffers::Offset ToFlatbuffers(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData) const override; bool FromJSON(const cJSON* json) override; - cJSON* ToJSON(bool withSensitiveData) const override; + [[nodiscard]] cJSON* ToJSON(bool withSensitiveData) const override; }; } // namespace OpenShock::Config diff --git a/include/http/HTTPRequestManager.h b/include/http/HTTPRequestManager.h index 81390ca9..8b82f2a4 100644 --- a/include/http/HTTPRequestManager.h +++ b/include/http/HTTPRequestManager.h @@ -22,7 +22,7 @@ namespace OpenShock::HTTP { }; template - struct Response { + struct [[nodiscard]] Response { RequestResult result; int code; T data; diff --git a/include/serial/SerialInputHandler.h b/include/serial/SerialInputHandler.h index 448d6475..350ac8de 100644 --- a/include/serial/SerialInputHandler.h +++ b/include/serial/SerialInputHandler.h @@ -3,7 +3,7 @@ #include namespace OpenShock::SerialInputHandler { - bool Init(); + [[nodiscard]] bool Init(); void Update(); void PrintWelcomeHeader(); diff --git a/include/wifi/WiFiManager.h b/include/wifi/WiFiManager.h index 2fd67fe2..36054e0f 100644 --- a/include/wifi/WiFiManager.h +++ b/include/wifi/WiFiManager.h @@ -10,7 +10,7 @@ namespace OpenShock::WiFiManager { /// @brief Initializes the WiFiManager /// @return True if the WiFiManager was initialized successfully - bool Init(); + [[nodiscard]] bool Init(); /// @brief Saves a network to the config /// @param ssid SSID of the network diff --git a/include/wifi/WiFiScanManager.h b/include/wifi/WiFiScanManager.h index c06c0941..691c03ba 100644 --- a/include/wifi/WiFiScanManager.h +++ b/include/wifi/WiFiScanManager.h @@ -8,7 +8,7 @@ #include namespace OpenShock::WiFiScanManager { - bool Init(); + [[nodiscard]] bool Init(); bool IsScanning(); From 7855e80ae1f169e439b11eb6b778e087046207ef Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 30 Aug 2024 15:45:51 +0200 Subject: [PATCH 12/41] Add FunctionProxy utility --- include/util/FnProxy.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 include/util/FnProxy.h diff --git a/include/util/FnProxy.h b/include/util/FnProxy.h new file mode 100644 index 00000000..7b66da5e --- /dev/null +++ b/include/util/FnProxy.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +namespace OpenShock::Util { + namespace FnProxyImpl { + template + class MemFunTraits; + + template + struct MemFunTraits { + constexpr static const std::size_t arity = sizeof...(Ts); + using ReturnType = R; + using Class = C; + }; + } // namespace FnProxyImpl + + // Proxies a member function pointer to a void(void*) function pointer, allowing it to be passed to C-style APIs that expect a callback. + template + inline void FnProxy(void* p) { + using T = decltype(MemberFunction); + using C = typename FnProxyImpl::MemFunTraits::Class; + (reinterpret_cast(p)->*MemberFunction)(); + } +} // namespace OpenShock::Util From d7b54b2a6806d601f0c68532c73a06ae5b5af3bd Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 30 Aug 2024 16:26:15 +0200 Subject: [PATCH 13/41] Clean up tasking code --- include/CaptivePortalInstance.h | 2 +- include/radio/RFTransmitter.h | 14 ++++++-------- src/CaptivePortalInstance.cpp | 9 ++++----- src/EStopManager.cpp | 3 ++- src/radio/RFTransmitter.cpp | 18 +++++++----------- src/wifi/WiFiScanManager.cpp | 5 ++++- 6 files changed, 24 insertions(+), 27 deletions(-) diff --git a/include/CaptivePortalInstance.h b/include/CaptivePortalInstance.h index 75388705..02a3b377 100644 --- a/include/CaptivePortalInstance.h +++ b/include/CaptivePortalInstance.h @@ -24,7 +24,7 @@ namespace OpenShock { bool broadcastMessageBIN(const uint8_t* data, std::size_t len) { return m_socketServer.broadcastBIN(data, len); } private: - static void task(void* arg); + void task(); void handleWebSocketClientConnected(uint8_t socketId); void handleWebSocketClientDisconnected(uint8_t socketId); void handleWebSocketClientError(uint8_t socketId, uint16_t code, const char* message); diff --git a/include/radio/RFTransmitter.h b/include/radio/RFTransmitter.h index 2a687297..9305d8de 100644 --- a/include/radio/RFTransmitter.h +++ b/include/radio/RFTransmitter.h @@ -3,14 +3,12 @@ #include "ShockerCommandType.h" #include "ShockerModelType.h" -#include +#include + +#include +#include -// Forward definitions to remove clutter -struct rmt_obj_s; -typedef rmt_obj_s rmt_obj_t; -struct QueueDefinition; -typedef QueueDefinition* QueueHandle_t; -typedef void* TaskHandle_t; +#include namespace OpenShock { class RFTransmitter { @@ -27,7 +25,7 @@ namespace OpenShock { private: void destroy(); - static void TransmitTask(void* arg); + void TransmitTask(); uint8_t m_txPin; rmt_obj_t* m_rmtHandle; diff --git a/src/CaptivePortalInstance.cpp b/src/CaptivePortalInstance.cpp index 77f299ae..1271cd6f 100644 --- a/src/CaptivePortalInstance.cpp +++ b/src/CaptivePortalInstance.cpp @@ -9,6 +9,7 @@ const char* const TAG = "CaptivePortalInstance"; #include "GatewayConnectionManager.h" #include "Logging.h" #include "serialization/WSLocal.h" +#include "util/FnProxy.h" #include "util/HexUtils.h" #include "util/PartitionUtils.h" #include "util/TaskUtils.h" @@ -123,7 +124,7 @@ discord.gg/OpenShock m_webServer.begin(); if (fsOk) { - if (TaskUtils::TaskCreateExpensive(CaptivePortalInstance::task, TAG, 8192, this, 1, &m_taskHandle) != pdPASS) { // PROFILED: 4-6KB stack usage + if (TaskUtils::TaskCreateExpensive(&Util::FnProxy<&CaptivePortalInstance::task>, TAG, 8192, this, 1, &m_taskHandle) != pdPASS) { // PROFILED: 4-6KB stack usage ESP_LOGE(TAG, "Failed to create task"); } } @@ -140,11 +141,9 @@ CaptivePortalInstance::~CaptivePortalInstance() { m_dnsServer.stop(); } -void CaptivePortalInstance::task(void* arg) { - CaptivePortalInstance* instance = reinterpret_cast(arg); - +void CaptivePortalInstance::task() { while (true) { - instance->m_socketServer.loop(); + m_socketServer.loop(); // instance->m_dnsServer.processNextRequest(); vTaskDelay(pdMS_TO_TICKS(WEBSOCKET_UPDATE_INTERVAL)); } diff --git a/src/EStopManager.cpp b/src/EStopManager.cpp index 7eb8130f..d66e50c7 100644 --- a/src/EStopManager.cpp +++ b/src/EStopManager.cpp @@ -8,6 +8,7 @@ const char* const TAG = "EStopManager"; #include "config/Config.h" #include "Logging.h" #include "Time.h" +#include "util/TaskUtils.h" #include "VisualStateManager.h" #include @@ -146,7 +147,7 @@ void EStopManager::Init() { ESP_PANIC(TAG, "Failed to add EStop ISR handler"); } - if (xTaskCreate(_estopEventHandler, TAG, 4096, nullptr, 5, &s_estopEventHandlerTask) != pdPASS) { + if (TaskUtils::TaskCreateUniversal(_estopEventHandler, TAG, 4096, nullptr, 5, &s_estopEventHandlerTask, 1) != pdPASS) { ESP_PANIC(TAG, "Failed to create EStop event handler task"); } diff --git a/src/radio/RFTransmitter.cpp b/src/radio/RFTransmitter.cpp index 9cdf33f0..447e8e54 100644 --- a/src/radio/RFTransmitter.cpp +++ b/src/radio/RFTransmitter.cpp @@ -9,6 +9,7 @@ const char* const TAG = "RFTransmitter"; #include "Logging.h" #include "radio/rmt/MainEncoder.h" #include "Time.h" +#include "util/FnProxy.h" #include "util/TaskUtils.h" #include @@ -52,7 +53,7 @@ RFTransmitter::RFTransmitter(uint8_t gpioPin) : m_txPin(gpioPin), m_rmtHandle(nu char name[32]; snprintf(name, sizeof(name), "RFTransmitter-%u", m_txPin); - if (TaskUtils::TaskCreateExpensive(TransmitTask, name, RFTRANSMITTER_TASK_STACK_SIZE, this, RFTRANSMITTER_TASK_PRIORITY, &m_taskHandle) != pdPASS) { + if (TaskUtils::TaskCreateExpensive(&Util::FnProxy<&RFTransmitter::TransmitTask>, name, RFTRANSMITTER_TASK_STACK_SIZE, this, RFTRANSMITTER_TASK_PRIORITY, &m_taskHandle) != pdPASS) { ESP_LOGE(TAG, "[pin-%u] Failed to create task", m_txPin); destroy(); return; @@ -130,19 +131,14 @@ void RFTransmitter::destroy() { } } -void RFTransmitter::TransmitTask(void* arg) { - RFTransmitter* transmitter = reinterpret_cast(arg); - uint8_t m_txPin = transmitter->m_txPin; // This must be defined here, because the THIS_LOG macro uses it - rmt_obj_t* rmtHandle = transmitter->m_rmtHandle; - QueueHandle_t queueHandle = transmitter->m_queueHandle; - +void RFTransmitter::TransmitTask() { ESP_LOGD(TAG, "[pin-%u] RMT loop running on core %d", m_txPin, xPortGetCoreID()); std::vector commands; while (true) { // Receive commands command_t* cmd = nullptr; - while (xQueueReceive(queueHandle, &cmd, commands.empty() ? portMAX_DELAY : 0) == pdTRUE) { + while (xQueueReceive(m_queueHandle, &cmd, commands.empty() ? portMAX_DELAY : 0) == pdTRUE) { if (cmd == nullptr) { ESP_LOGD(TAG, "[pin-%u] Received nullptr (stop command), cleaning up...", m_txPin); @@ -203,10 +199,10 @@ void RFTransmitter::TransmitTask(void* arg) { if (expired || empty) { // If the command is not empty, send the zero sequence to stop the shocker if (!empty) { - rmtWriteBlocking(rmtHandle, cmd->zeroSequence.data(), cmd->zeroSequence.size()); + rmtWriteBlocking(m_rmtHandle, cmd->zeroSequence.data(), cmd->zeroSequence.size()); } - if(cmd->until + TRANSMIT_END_DURATION < OpenShock::millis()) { + if (cmd->until + TRANSMIT_END_DURATION < OpenShock::millis()) { // Remove the command and move to the next one it = commands.erase(it); delete cmd; @@ -216,7 +212,7 @@ void RFTransmitter::TransmitTask(void* arg) { } } else { // Send the command - rmtWriteBlocking(rmtHandle, cmd->sequence.data(), cmd->sequence.size()); + rmtWriteBlocking(m_rmtHandle, cmd->sequence.data(), cmd->sequence.size()); // Move to the next command ++it; diff --git a/src/wifi/WiFiScanManager.cpp b/src/wifi/WiFiScanManager.cpp index af2b4c2a..758ed58c 100644 --- a/src/wifi/WiFiScanManager.cpp +++ b/src/wifi/WiFiScanManager.cpp @@ -1,8 +1,11 @@ +#include + #include "wifi/WiFiScanManager.h" const char* const TAG = "WiFiScanManager"; #include "Logging.h" +#include "util/TaskUtils.h" #include @@ -226,7 +229,7 @@ bool WiFiScanManager::StartScan() { } // Start the scan task - if (xTaskCreate(_scanningTask, "WiFiScanManager", 4096, nullptr, 1, &s_scanTaskHandle) != pdPASS) { // PROFILED: 1.8KB stack usage + if (TaskUtils::TaskCreateExpensive(_scanningTask, "WiFiScanManager", 4096, nullptr, 1, &s_scanTaskHandle) != pdPASS) { // PROFILED: 1.8KB stack usage ESP_LOGE(TAG, "Failed to create scan task"); xSemaphoreGive(s_scanTaskMutex); From daa6e79cb6b92c8548a49b48b56b6dda16c730a4 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Sun, 1 Sep 2024 01:13:43 +0200 Subject: [PATCH 14/41] Fix naming of sum8 function --- include/Checksum.h | 6 +++--- src/radio/rmt/CaiXianlinEncoder.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/Checksum.h b/include/Checksum.h index 0f3527cc..66509115 100644 --- a/include/Checksum.h +++ b/include/Checksum.h @@ -3,7 +3,7 @@ #include namespace OpenShock::Checksum { - constexpr uint8_t CRC8(const uint8_t* data, std::size_t size) { + constexpr uint8_t Sum8(const uint8_t* data, std::size_t size) { uint8_t checksum = 0; for (std::size_t i = 0; i < size; ++i) { checksum += data[i]; @@ -11,7 +11,7 @@ namespace OpenShock::Checksum { return checksum; } template - constexpr uint8_t CRC8(T data) { - return CRC8(reinterpret_cast(&data), sizeof(T)); + constexpr uint8_t Sum8(T data) { + return Sum8(reinterpret_cast(&data), sizeof(T)); } } // namespace OpenShock::Checksum diff --git a/src/radio/rmt/CaiXianlinEncoder.cpp b/src/radio/rmt/CaiXianlinEncoder.cpp index 1d756023..18ef4737 100644 --- a/src/radio/rmt/CaiXianlinEncoder.cpp +++ b/src/radio/rmt/CaiXianlinEncoder.cpp @@ -39,7 +39,7 @@ std::vector Rmt::CaiXianlinEncoder::GetSequence(uint16_t transmitter uint32_t payload = (static_cast(transmitterId & 0xFFFF) << 16) | (static_cast(channelId & 0xF) << 12) | (static_cast(typeVal) << 8) | static_cast(intensity & 0xFF); // Calculate the checksum of the payload - uint8_t checksum = Checksum::CRC8(payload); + uint8_t checksum = Checksum::Sum8(payload); // Add the checksum to the payload uint64_t data = (static_cast(payload) << 8) | static_cast(checksum); From a5cf585b8290982f78358af5a5ea7d72e5f66488 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Sep 2024 08:49:43 +0200 Subject: [PATCH 15/41] build(deps-dev): Bump the frontend group in /frontend with 5 updates (#276) Bumps the frontend group in /frontend with 5 updates: | Package | From | To | | --- | --- | --- | | [@sveltejs/kit](https://github.com/sveltejs/kit/tree/HEAD/packages/kit) | `2.5.24` | `2.5.25` | | [@tailwindcss/forms](https://github.com/tailwindlabs/tailwindcss-forms) | `0.5.7` | `0.5.8` | | [@tailwindcss/typography](https://github.com/tailwindlabs/tailwindcss-typography) | `0.5.14` | `0.5.15` | | [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) | `22.5.0` | `22.5.2` | | [postcss](https://github.com/postcss/postcss) | `8.4.41` | `8.4.43` | Updates `@sveltejs/kit` from 2.5.24 to 2.5.25 - [Release notes](https://github.com/sveltejs/kit/releases) - [Changelog](https://github.com/sveltejs/kit/blob/main/packages/kit/CHANGELOG.md) - [Commits](https://github.com/sveltejs/kit/commits/@sveltejs/kit@2.5.25/packages/kit) Updates `@tailwindcss/forms` from 0.5.7 to 0.5.8 - [Release notes](https://github.com/tailwindlabs/tailwindcss-forms/releases) - [Changelog](https://github.com/tailwindlabs/tailwindcss-forms/blob/main/CHANGELOG.md) - [Commits](https://github.com/tailwindlabs/tailwindcss-forms/compare/v0.5.7...v0.5.8) Updates `@tailwindcss/typography` from 0.5.14 to 0.5.15 - [Release notes](https://github.com/tailwindlabs/tailwindcss-typography/releases) - [Changelog](https://github.com/tailwindlabs/tailwindcss-typography/blob/main/CHANGELOG.md) - [Commits](https://github.com/tailwindlabs/tailwindcss-typography/compare/v0.5.14...v0.5.15) Updates `@types/node` from 22.5.0 to 22.5.2 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Updates `postcss` from 8.4.41 to 8.4.43 - [Release notes](https://github.com/postcss/postcss/releases) - [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md) - [Commits](https://github.com/postcss/postcss/compare/8.4.41...8.4.43) --- updated-dependencies: - dependency-name: "@sveltejs/kit" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: "@tailwindcss/forms" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: "@tailwindcss/typography" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: postcss dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- frontend/package-lock.json | 44 +++++++++++++++++++------------------- frontend/package.json | 10 ++++----- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index d0bcc7f0..52286af6 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -15,17 +15,17 @@ "@skeletonlabs/skeleton": "2.10.2", "@skeletonlabs/tw-plugin": "0.4.0", "@sveltejs/adapter-static": "^3.0.4", - "@sveltejs/kit": "2.5.24", + "@sveltejs/kit": "2.5.25", "@sveltejs/vite-plugin-svelte": "^3.1.2", - "@tailwindcss/forms": "0.5.7", - "@tailwindcss/typography": "0.5.14", - "@types/node": "22.5.0", + "@tailwindcss/forms": "0.5.8", + "@tailwindcss/typography": "0.5.15", + "@types/node": "22.5.2", "autoprefixer": "10.4.20", "eslint": "^9.9.1", "eslint-config-prettier": "9.1.0", "eslint-plugin-svelte": "2.43.0", "flatbuffers": "24.3.25", - "postcss": "8.4.41", + "postcss": "8.4.43", "prettier": "3.3.3", "prettier-plugin-svelte": "3.2.6", "svelte": "4.2.19", @@ -993,9 +993,9 @@ } }, "node_modules/@sveltejs/kit": { - "version": "2.5.24", - "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.5.24.tgz", - "integrity": "sha512-Nr2oxsCsDfEkdS/zzQQQbsPYTbu692Qs3/iE3L7VHzCVjG2+WujF9oMUozWI7GuX98KxYSoPMlAsfmDLSg44hQ==", + "version": "2.5.25", + "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.5.25.tgz", + "integrity": "sha512-5hBSEN8XEjDZ5+2bHkFh8Z0QyOk0C187cyb12aANe1c8aeKbfu5ZD5XaC2vEH4h0alJFDXPdUkXQBmeeXeMr1A==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -1064,21 +1064,21 @@ } }, "node_modules/@tailwindcss/forms": { - "version": "0.5.7", - "resolved": "https://registry.npmjs.org/@tailwindcss/forms/-/forms-0.5.7.tgz", - "integrity": "sha512-QE7X69iQI+ZXwldE+rzasvbJiyV/ju1FGHH0Qn2W3FKbuYtqp8LKcy6iSw79fVUT5/Vvf+0XgLCeYVG+UV6hOw==", + "version": "0.5.8", + "resolved": "https://registry.npmjs.org/@tailwindcss/forms/-/forms-0.5.8.tgz", + "integrity": "sha512-DJs7B7NPD0JH7BVvdHWNviWmunlFhuEkz7FyFxE4japOWYMLl9b1D6+Z9mivJJPWr6AEbmlPqgiFRyLwFB1SgQ==", "dev": true, "dependencies": { "mini-svg-data-uri": "^1.2.3" }, "peerDependencies": { - "tailwindcss": ">=3.0.0 || >= 3.0.0-alpha.1" + "tailwindcss": ">=3.0.0 || >= 3.0.0-alpha.1 || >= 4.0.0-alpha.20" } }, "node_modules/@tailwindcss/typography": { - "version": "0.5.14", - "resolved": "https://registry.npmjs.org/@tailwindcss/typography/-/typography-0.5.14.tgz", - "integrity": "sha512-ZvOCjUbsJBjL9CxQBn+VEnFpouzuKhxh2dH8xMIWHILL+HfOYtlAkWcyoon8LlzE53d2Yo6YO6pahKKNW3q1YQ==", + "version": "0.5.15", + "resolved": "https://registry.npmjs.org/@tailwindcss/typography/-/typography-0.5.15.tgz", + "integrity": "sha512-AqhlCXl+8grUz8uqExv5OTtgpjuVIwFTSXTrh8y9/pw6q2ek7fJ+Y8ZEVw7EB2DCcuCOtEjf9w3+J3rzts01uA==", "dev": true, "dependencies": { "lodash.castarray": "^4.4.0", @@ -1087,7 +1087,7 @@ "postcss-selector-parser": "6.0.10" }, "peerDependencies": { - "tailwindcss": ">=3.0.0 || insiders" + "tailwindcss": ">=3.0.0 || insiders || >=4.0.0-alpha.20" } }, "node_modules/@types/cookie": { @@ -1103,9 +1103,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.5.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.0.tgz", - "integrity": "sha512-DkFrJOe+rfdHTqqMg0bSNlGlQ85hSoh2TPzZyhHsXnMtligRWpxUySiyw8FY14ITt24HVCiQPWxS3KO/QlGmWg==", + "version": "22.5.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.2.tgz", + "integrity": "sha512-acJsPTEqYqulZS/Yp/S3GgeE6GZ0qYODUR8aVr/DkhHQ8l9nd4j5x1/ZJy9/gHrRlFMqkO6i0I3E27Alu4jjPg==", "dev": true, "dependencies": { "undici-types": "~6.19.2" @@ -3264,9 +3264,9 @@ } }, "node_modules/postcss": { - "version": "8.4.41", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.41.tgz", - "integrity": "sha512-TesUflQ0WKZqAvg52PWL6kHgLKP6xB6heTOdoYM0Wt2UHyxNa4K25EZZMgKns3BH1RLVbZCREPpLY0rhnNoHVQ==", + "version": "8.4.43", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.43.tgz", + "integrity": "sha512-gJAQVYbh5R3gYm33FijzCZj7CHyQ3hWMgJMprLUlIYqCwTeZhBQ19wp0e9mA25BUbEvY5+EXuuaAjqQsrBxQBQ==", "dev": true, "funding": [ { diff --git a/frontend/package.json b/frontend/package.json index 01098ade..993b88a0 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -19,17 +19,17 @@ "@skeletonlabs/skeleton": "2.10.2", "@skeletonlabs/tw-plugin": "0.4.0", "@sveltejs/adapter-static": "^3.0.4", - "@sveltejs/kit": "2.5.24", + "@sveltejs/kit": "2.5.25", "@sveltejs/vite-plugin-svelte": "^3.1.2", - "@tailwindcss/forms": "0.5.7", - "@tailwindcss/typography": "0.5.14", - "@types/node": "22.5.0", + "@tailwindcss/forms": "0.5.8", + "@tailwindcss/typography": "0.5.15", + "@types/node": "22.5.2", "autoprefixer": "10.4.20", "eslint": "^9.9.1", "eslint-config-prettier": "9.1.0", "eslint-plugin-svelte": "2.43.0", "flatbuffers": "24.3.25", - "postcss": "8.4.41", + "postcss": "8.4.43", "prettier": "3.3.3", "prettier-plugin-svelte": "3.2.6", "svelte": "4.2.19", From 54eff50f71a79605fc52b2e65bd1add84f78db97 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Mon, 2 Sep 2024 11:30:18 +0200 Subject: [PATCH 16/41] Add IPAddressUtils from closed PR --- include/config/internal/utils.h | 3 ++ include/util/IPAddressUtils.h | 9 +++++ src/config/internal/utils.cpp | 39 +++++++++++++++++++++ src/util/IPAddressUtils.cpp | 60 +++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 include/util/IPAddressUtils.h create mode 100644 src/util/IPAddressUtils.cpp diff --git a/include/config/internal/utils.h b/include/config/internal/utils.h index af31c845..92bec784 100644 --- a/include/config/internal/utils.h +++ b/include/config/internal/utils.h @@ -3,17 +3,20 @@ #include "config/ConfigBase.h" #include +#include #include #include namespace OpenShock::Config::Internal::Utils { void FromFbsStr(std::string& str, const flatbuffers::String* fbsStr, const char* defaultStr); + bool FromFbsIPAddress(IPAddress& ip, const flatbuffers::String* fbsIP, const IPAddress& defaultIP); bool FromJsonBool(bool& val, const cJSON* json, const char* name, bool defaultVal); bool FromJsonU8(uint8_t& val, const cJSON* json, const char* name, uint8_t defaultVal); bool FromJsonU16(uint16_t& val, const cJSON* json, const char* name, uint16_t defaultVal); bool FromJsonI32(int32_t& val, const cJSON* json, const char* name, int32_t defaultVal); bool FromJsonStr(std::string& str, const cJSON* json, const char* name, const char* defaultStr); + bool FromJsonIPAddress(IPAddress& ip, const cJSON* json, const char* name, const IPAddress& defaultIP); template // T inherits from ConfigBase void FromFbsVec(std::vector& vec, const flatbuffers::Vector>* fbsVec) { diff --git a/include/util/IPAddressUtils.h b/include/util/IPAddressUtils.h new file mode 100644 index 00000000..f78db480 --- /dev/null +++ b/include/util/IPAddressUtils.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +#include "StringView.h" + +namespace OpenShock { + bool IPAddressFromStringView(IPAddress& ip, StringView sv); +} diff --git a/src/config/internal/utils.cpp b/src/config/internal/utils.cpp index 02fc1230..8d4e7397 100644 --- a/src/config/internal/utils.cpp +++ b/src/config/internal/utils.cpp @@ -3,6 +3,7 @@ const char* const TAG = "Config::Internal::Utils"; #include "Logging.h" +#include "util/IPAddressUtils.h" using namespace OpenShock; @@ -46,6 +47,22 @@ void Config::Internal::Utils::FromFbsStr(std::string& str, const flatbuffers::St } } +bool Config::Internal::Utils::FromFbsIPAddress(IPAddress& ip, const flatbuffers::String* fbsIP, const IPAddress& defaultIP) { + if (fbsIP == nullptr) { + ESP_LOGE(TAG, "IP address is null"); + return false; + } + + StringView view(*fbsIP); + + if (!OpenShock::IPAddressFromStringView(ip, view)) { + ESP_LOGE(TAG, "failed to parse IP address"); + return false; + } + + return true; +} + bool Config::Internal::Utils::FromJsonBool(bool& val, const cJSON* json, const char* name, bool defaultVal) { const cJSON* jsonVal = cJSON_GetObjectItemCaseSensitive(json, name); if (jsonVal == nullptr) { @@ -91,3 +108,25 @@ bool Config::Internal::Utils::FromJsonStr(std::string& str, const cJSON* json, c return true; } + +bool Config::Internal::Utils::FromJsonIPAddress(IPAddress& ip, const cJSON* json, const char* name, const IPAddress& defaultIP) { + const cJSON* jsonVal = cJSON_GetObjectItemCaseSensitive(json, name); + if (jsonVal == nullptr) { + ESP_LOGE(TAG, "value at '%s' is null", name); + return false; + } + + if (cJSON_IsString(jsonVal) == 0) { + ESP_LOGE(TAG, "value at '%s' is not a string", name); + return false; + } + + StringView view(jsonVal->valuestring); + + if (!OpenShock::IPAddressFromStringView(ip, view)) { + ESP_LOGE(TAG, "failed to parse IP address at '%s'", name); + return false; + } + + return true; +} diff --git a/src/util/IPAddressUtils.cpp b/src/util/IPAddressUtils.cpp new file mode 100644 index 00000000..de8ec96f --- /dev/null +++ b/src/util/IPAddressUtils.cpp @@ -0,0 +1,60 @@ +#include "util/IPAddressUtils.h" + +#include "FormatHelpers.h" + +const char* const TAG = "Util::IPAddressUtils"; + +bool OpenShock::IPAddressFromStringView(IPAddress& ip, StringView sv) { + if (sv.isNullOrEmpty()) { + return false; + } + + int octetIndex = 0; + std::uint8_t octets[4]; + std::uint16_t octetValue = 0; + + std::size_t digits = 0; + + for (std::size_t i = 0; i < sv.length(); ++i) { + char c = sv[i]; + + if (c >= '0' && c <= '9') { + if (digits > 0 && octetValue == 0) { + return false; // No leading zeros allowed + } + if (++digits > 3) { + return false; // Maximum of 3 digits per octet + } + + octetValue = (octetValue * 10) + (c - '0'); + if (octetValue > 255) { + return false; // Each octet must be between 0 and 255 + } + continue; + } + + if (c != '.') { + return false; // Only digits and dots allowed + } + if (digits == 0) { + return false; // No empty octets allowed + } + + octets[octetIndex++] = static_cast(octetValue); + if (octetIndex > 3) { + return false; // Only 3 dots allowed + } + octetValue = 0; + digits = 0; + } + + if (octetIndex != 3 || digits == 0) { + return false; // Must have 3 dots and no trailing dot + } + + octets[octetIndex] = static_cast(octetValue); + + ip = IPAddress(octets); + + return true; +} From 32f7a685746f676c7b3aab4bca8e61ea5bfc3967 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Mon, 2 Sep 2024 11:41:13 +0200 Subject: [PATCH 17/41] Improve IPAddressUtils --- include/util/IPAddressUtils.h | 2 +- src/config/internal/utils.cpp | 4 +-- src/util/IPAddressUtils.cpp | 51 ++++++----------------------------- 3 files changed, 11 insertions(+), 46 deletions(-) diff --git a/include/util/IPAddressUtils.h b/include/util/IPAddressUtils.h index f78db480..ee5eadae 100644 --- a/include/util/IPAddressUtils.h +++ b/include/util/IPAddressUtils.h @@ -5,5 +5,5 @@ #include "StringView.h" namespace OpenShock { - bool IPAddressFromStringView(IPAddress& ip, StringView sv); + bool IPV4AddressFromStringView(IPAddress& ip, StringView sv); } diff --git a/src/config/internal/utils.cpp b/src/config/internal/utils.cpp index 8d4e7397..d0f7ab28 100644 --- a/src/config/internal/utils.cpp +++ b/src/config/internal/utils.cpp @@ -55,7 +55,7 @@ bool Config::Internal::Utils::FromFbsIPAddress(IPAddress& ip, const flatbuffers: StringView view(*fbsIP); - if (!OpenShock::IPAddressFromStringView(ip, view)) { + if (!OpenShock::IPV4AddressFromStringView(ip, view)) { ESP_LOGE(TAG, "failed to parse IP address"); return false; } @@ -123,7 +123,7 @@ bool Config::Internal::Utils::FromJsonIPAddress(IPAddress& ip, const cJSON* json StringView view(jsonVal->valuestring); - if (!OpenShock::IPAddressFromStringView(ip, view)) { + if (!OpenShock::IPV4AddressFromStringView(ip, view)) { ESP_LOGE(TAG, "failed to parse IP address at '%s'", name); return false; } diff --git a/src/util/IPAddressUtils.cpp b/src/util/IPAddressUtils.cpp index de8ec96f..a6dbc5c3 100644 --- a/src/util/IPAddressUtils.cpp +++ b/src/util/IPAddressUtils.cpp @@ -1,59 +1,24 @@ #include "util/IPAddressUtils.h" -#include "FormatHelpers.h" +#include "intconv.h" const char* const TAG = "Util::IPAddressUtils"; -bool OpenShock::IPAddressFromStringView(IPAddress& ip, StringView sv) { +bool OpenShock::IPV4AddressFromStringView(IPAddress& ip, StringView sv) { if (sv.isNullOrEmpty()) { return false; } - int octetIndex = 0; - std::uint8_t octets[4]; - std::uint16_t octetValue = 0; - - std::size_t digits = 0; - - for (std::size_t i = 0; i < sv.length(); ++i) { - char c = sv[i]; - - if (c >= '0' && c <= '9') { - if (digits > 0 && octetValue == 0) { - return false; // No leading zeros allowed - } - if (++digits > 3) { - return false; // Maximum of 3 digits per octet - } - - octetValue = (octetValue * 10) + (c - '0'); - if (octetValue > 255) { - return false; // Each octet must be between 0 and 255 - } - continue; - } - - if (c != '.') { - return false; // Only digits and dots allowed - } - if (digits == 0) { - return false; // No empty octets allowed - } - - octets[octetIndex++] = static_cast(octetValue); - if (octetIndex > 3) { - return false; // Only 3 dots allowed - } - octetValue = 0; - digits = 0; + auto parts = sv.split('.'); + if (parts.size() != 4) { + return false; // Must have 4 octets } - if (octetIndex != 3 || digits == 0) { - return false; // Must have 3 dots and no trailing dot + std::uint8_t octets[4]; + if (!IntConv::stou8(parts[0], octets[0]) || !IntConv::stou8(parts[1], octets[1]) || !IntConv::stou8(parts[2], octets[2]) || !IntConv::stou8(parts[3], octets[3])) { + return false; } - octets[octetIndex] = static_cast(octetValue); - ip = IPAddress(octets); return true; From 2e44c5fe265fe65f07737fd39ff713d7c324d640 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Tue, 3 Sep 2024 16:35:11 +0200 Subject: [PATCH 18/41] Update CHANGELOG.md --- CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f87ade6c..f14fba59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ +# Version 1.3.0 Release Notes + +This release adds support for more boards, has more bugfixes, better error handling, and optimization/cleanup. + +## Highlight + +- Added support for **DFRobot Firebeetle**, **Wemos S3 Mini** and **WaveShare S3 Zero** boards. + +## Minor Updates + +- Re-Add **PET998DR** Quiet Postamble. +- Fix CaiXianlin protocol sending non-zero when doing a beep command. +- Moved schema files to seperate repository. +- Improve error handling and logging. +- Dependency updates. +- Code cleanup, optimization and refactoring. + # Version 1.3.0-rc.1 Release Notes This is the first release candidate for version 1.3.0. From a604fe0366666a4b5e27e1ba76342ef7ff2c56f3 Mon Sep 17 00:00:00 2001 From: HentaiHeavenVR Date: Fri, 6 Sep 2024 08:51:31 +0200 Subject: [PATCH 19/41] Remove Arduino log spam by replacing entire logging system (#279) * Replace logging system to get rid of Arduino garbage This also reduces image sizes by 5% :3 * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- include/Logging.h | 83 ++++++++-- scripts/embed_env_vars.py | 3 +- src/CaptivePortal.cpp | 38 ++--- src/CaptivePortalInstance.cpp | 24 +-- src/CommandHandler.cpp | 56 +++---- src/EStopManager.cpp | 18 +-- src/GatewayClient.cpp | 40 ++--- src/GatewayConnectionManager.cpp | 54 +++---- src/OtaUpdateManager.cpp | 146 +++++++++--------- src/PinPatternManager.cpp | 8 +- src/RGBPatternManager.cpp | 10 +- src/ReadWriteMutex.cpp | 6 +- src/SemVer.cpp | 12 +- src/VisualStateManager.cpp | 8 +- src/WebSocketDeFragger.cpp | 2 +- src/config/BackendConfig.cpp | 6 +- src/config/CaptivePortalConfig.cpp | 6 +- src/config/Config.cpp | 64 ++++---- src/config/OtaUpdateConfig.cpp | 6 +- src/config/RFConfig.cpp | 6 +- src/config/RootConfig.cpp | 30 ++-- src/config/SerialInputConfig.cpp | 6 +- src/config/WiFiConfig.cpp | 10 +- src/config/WiFiCredentials.cpp | 10 +- src/config/internal/utils.cpp | 20 +-- src/event_handlers/websocket/Gateway.cpp | 4 +- src/event_handlers/websocket/Local.cpp | 4 +- .../websocket/gateway/CaptivePortalConfig.cpp | 4 +- .../websocket/gateway/OtaInstall.cpp | 8 +- .../websocket/gateway/ShockerCommandList.cpp | 10 +- .../websocket/gateway/_InvalidMessage.cpp | 4 +- .../websocket/local/AccountLinkCommand.cpp | 2 +- .../websocket/local/AccountUnlinkCommand.cpp | 2 +- .../websocket/local/SetRfTxPinCommand.cpp | 2 +- .../local/WiFiNetworkConnectCommand.cpp | 8 +- .../local/WiFiNetworkDisconnectCommand.cpp | 2 +- .../local/WiFiNetworkForgetCommand.cpp | 8 +- .../local/WiFiNetworkSaveCommand.cpp | 12 +- .../websocket/local/WiFiScanCommand.cpp | 2 +- .../websocket/local/_InvalidMessage.cpp | 4 +- src/http/HTTPRequestManager.cpp | 42 ++--- src/main.cpp | 20 +-- src/radio/RFTransmitter.cpp | 28 ++-- src/radio/rmt/MainEncoder.cpp | 4 +- src/serial/SerialInputHandler.cpp | 14 +- src/serialization/JsonAPI.cpp | 2 +- src/serialization/JsonSerial.cpp | 32 ++-- src/serialization/WSGateway.cpp | 2 +- src/serialization/WSLocal.cpp | 2 +- src/util/Base64Utils.cpp | 10 +- src/util/CertificateUtils.cpp | 10 +- src/util/ParitionUtils.cpp | 20 +-- src/util/StringUtils.cpp | 4 +- src/wifi/WiFiManager.cpp | 62 ++++---- src/wifi/WiFiScanManager.cpp | 24 +-- 55 files changed, 543 insertions(+), 481 deletions(-) diff --git a/include/Logging.h b/include/Logging.h index c6cfcb23..3439449d 100644 --- a/include/Logging.h +++ b/include/Logging.h @@ -1,24 +1,85 @@ #pragma once -#include +#include "Time.h" + +#include #include #include #include -#define ESP_PANIC_PRINT(TAG, format, ...) ESP_LOGE(TAG, "PANIC: " format, ##__VA_ARGS__) +extern "C" int log_printf(const char* fmt, ...); + +template +constexpr const char* openshockPathToFileName(const char (&path)[N]) { + std::size_t pos = 0; + for (std::size_t i = 0; i < N; i++) { + char c = path[i]; + if (c == '/' || c == '\\') { + pos = i + 1; + } + } + return path + pos; +} + +#define OPENSHOCK_LOG_LEVEL_NONE (0) +#define OPENSHOCK_LOG_LEVEL_ERROR (1) +#define OPENSHOCK_LOG_LEVEL_WARN (2) +#define OPENSHOCK_LOG_LEVEL_INFO (3) +#define OPENSHOCK_LOG_LEVEL_DEBUG (4) +#define OPENSHOCK_LOG_LEVEL_VERBOSE (5) + +#define OPENSHOCK_LOG_FORMAT(letter, format) "[%lli][" #letter "][%s:%u] %s(): " format "\r\n", OpenShock::millis(), openshockPathToFileName(__FILE__), __LINE__, __FUNCTION__ + +#if OPENSHOCK_LOG_LEVEL >= OPENSHOCK_LOG_LEVEL_VERBOSE +#define OS_LOGV(TAG, format, ...) log_printf(OPENSHOCK_LOG_FORMAT(V, "[%s] " format), TAG, ##__VA_ARGS__) +#else +#define OS_LOGV(TAG, format, ...) do {} while(0) +#endif + +#if OPENSHOCK_LOG_LEVEL >= OPENSHOCK_LOG_LEVEL_DEBUG +#define OS_LOGD(TAG, format, ...) log_printf(OPENSHOCK_LOG_FORMAT(D, "[%s] " format), TAG, ##__VA_ARGS__) +#else +#define OS_LOGD(TAG, format, ...) do {} while(0) +#endif + +#if OPENSHOCK_LOG_LEVEL >= OPENSHOCK_LOG_LEVEL_INFO +#define OS_LOGI(TAG, format, ...) log_printf(OPENSHOCK_LOG_FORMAT(I, "[%s] " format), TAG, ##__VA_ARGS__) +#else +#define OS_LOGI(TAG, format, ...) do {} while(0) +#endif + +#if OPENSHOCK_LOG_LEVEL >= OPENSHOCK_LOG_LEVEL_WARN +#define OS_LOGW(TAG, format, ...) log_printf(OPENSHOCK_LOG_FORMAT(W, "[%s] " format), TAG, ##__VA_ARGS__) +#else +#define OS_LOGW(TAG, format, ...) do {} while(0) +#endif + +#if OPENSHOCK_LOG_LEVEL >= OPENSHOCK_LOG_LEVEL_ERROR +#define OS_LOGE(TAG, format, ...) log_printf(OPENSHOCK_LOG_FORMAT(E, "[%s] " format), TAG, ##__VA_ARGS__) +#else +#define OS_LOGE(TAG, format, ...) do {} while(0) +#endif + +#if OPENSHOCK_LOG_LEVEL >= OPENSHOCK_LOG_LEVEL_NONE +#define OS_LOGN(TAG, format, ...) log_printf(OPENSHOCK_LOG_FORMAT(E, "[%s] " format), TAG, ##__VA_ARGS__) +#else +#define OS_LOGN(TAG, format, ...) do {} while(0) +#endif + +#define OS_PANIC_PRINT(TAG, format, ...) OS_LOGE(TAG, "PANIC: " format, ##__VA_ARGS__) -#define ESP_PANIC(TAG, format, ...) \ - ESP_PANIC_PRINT(TAG, format ", restarting in 5 seconds...", ##__VA_ARGS__); \ - vTaskDelay(pdMS_TO_TICKS(5000)); \ +#define OS_PANIC(TAG, format, ...) \ + OS_PANIC_PRINT(TAG, format ", restarting in 5 seconds...", ##__VA_ARGS__); \ + vTaskDelay(pdMS_TO_TICKS(5000)); \ esp_restart() -#define ESP_PANIC_OTA(TAG, format, ...) \ - ESP_PANIC_PRINT(TAG, format ", invalidating update partition and restarting in 5 seconds...", ##__VA_ARGS__); \ - vTaskDelay(pdMS_TO_TICKS(5000)); \ - esp_ota_mark_app_invalid_rollback_and_reboot(); \ +#define OS_PANIC_OTA(TAG, format, ...) \ + OS_PANIC_PRINT(TAG, format ", invalidating update partition and restarting in 5 seconds...", ##__VA_ARGS__); \ + vTaskDelay(pdMS_TO_TICKS(5000)); \ + esp_ota_mark_app_invalid_rollback_and_reboot(); \ esp_restart() -#define ESP_PANIC_INSTANT(TAG, format, ...) \ - ESP_PANIC_PRINT(TAG, format, ##__VA_ARGS__); \ +#define OS_PANIC_INSTANT(TAG, format, ...) \ + OS_PANIC_PRINT(TAG, format, ##__VA_ARGS__); \ esp_restart() diff --git a/scripts/embed_env_vars.py b/scripts/embed_env_vars.py index a3613bd8..49bc04a5 100644 --- a/scripts/embed_env_vars.py +++ b/scripts/embed_env_vars.py @@ -166,7 +166,8 @@ def print_dump(name: str, map: Mapping[str, str | int | bool]) -> None: log_level_int = dot.get_loglevel('LOG_LEVEL') if log_level_int is None: raise ValueError('LOG_LEVEL must be set in environment variables.') -cpp_defines['CORE_DEBUG_LEVEL'] = log_level_int +cpp_defines['OPENSHOCK_LOG_LEVEL'] = log_level_int +cpp_defines['CORE_DEBUG_LEVEL'] = 2 # Warning level. (FUCK Arduino) # Serialize and inject CPP Defines. print_dump('CPP Defines', cpp_defines) diff --git a/src/CaptivePortal.cpp b/src/CaptivePortal.cpp index ee70830b..3d203509 100644 --- a/src/CaptivePortal.cpp +++ b/src/CaptivePortal.cpp @@ -25,40 +25,40 @@ static std::unique_ptr s_instance = nullptr; bool _startCaptive() { if (s_instance != nullptr) { - ESP_LOGD(TAG, "Already started"); + OS_LOGD(TAG, "Already started"); return true; } - ESP_LOGI(TAG, "Starting captive portal"); + OS_LOGI(TAG, "Starting captive portal"); if (!WiFi.enableAP(true)) { - ESP_LOGE(TAG, "Failed to enable AP mode"); + OS_LOGE(TAG, "Failed to enable AP mode"); return false; } if (!WiFi.softAP((OPENSHOCK_FW_AP_PREFIX + WiFi.macAddress()).c_str())) { - ESP_LOGE(TAG, "Failed to start AP"); + OS_LOGE(TAG, "Failed to start AP"); WiFi.enableAP(false); return false; } IPAddress apIP(10, 10, 10, 10); if (!WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0))) { - ESP_LOGE(TAG, "Failed to configure AP"); + OS_LOGE(TAG, "Failed to configure AP"); WiFi.softAPdisconnect(true); return false; } esp_err_t err = mdns_init(); if (err != ESP_OK) { - ESP_LOGE(TAG, "Failed to initialize mDNS"); + OS_LOGE(TAG, "Failed to initialize mDNS"); WiFi.softAPdisconnect(true); return false; } err = mdns_hostname_set(OPENSHOCK_FW_HOSTNAME); if (err != ESP_OK) { - ESP_LOGE(TAG, "Failed to set mDNS hostname"); + OS_LOGE(TAG, "Failed to set mDNS hostname"); WiFi.softAPdisconnect(true); return false; } @@ -69,11 +69,11 @@ bool _startCaptive() { } void _stopCaptive() { if (s_instance == nullptr) { - ESP_LOGD(TAG, "Already stopped"); + OS_LOGD(TAG, "Already stopped"); return; } - ESP_LOGI(TAG, "Stopping captive portal"); + OS_LOGI(TAG, "Stopping captive portal"); s_instance = nullptr; @@ -123,22 +123,22 @@ void CaptivePortal::Update() { if (s_instance == nullptr) { if (shouldBeRunning) { - ESP_LOGD(TAG, "Starting captive portal"); - ESP_LOGD(TAG, " alwaysEnabled: %s", s_alwaysEnabled ? "true" : "false"); - ESP_LOGD(TAG, " forceClosed: %s", s_forceClosed ? "true" : "false"); - ESP_LOGD(TAG, " isConnected: %s", gatewayConnected ? "true" : "false"); - ESP_LOGD(TAG, " commandHandlerOk: %s", commandHandlerOk ? "true" : "false"); + OS_LOGD(TAG, "Starting captive portal"); + OS_LOGD(TAG, " alwaysEnabled: %s", s_alwaysEnabled ? "true" : "false"); + OS_LOGD(TAG, " forceClosed: %s", s_forceClosed ? "true" : "false"); + OS_LOGD(TAG, " isConnected: %s", gatewayConnected ? "true" : "false"); + OS_LOGD(TAG, " commandHandlerOk: %s", commandHandlerOk ? "true" : "false"); _startCaptive(); } return; } if (!shouldBeRunning) { - ESP_LOGD(TAG, "Stopping captive portal"); - ESP_LOGD(TAG, " alwaysEnabled: %s", s_alwaysEnabled ? "true" : "false"); - ESP_LOGD(TAG, " forceClosed: %s", s_forceClosed ? "true" : "false"); - ESP_LOGD(TAG, " isConnected: %s", gatewayConnected ? "true" : "false"); - ESP_LOGD(TAG, " commandHandlerOk: %s", commandHandlerOk ? "true" : "false"); + OS_LOGD(TAG, "Stopping captive portal"); + OS_LOGD(TAG, " alwaysEnabled: %s", s_alwaysEnabled ? "true" : "false"); + OS_LOGD(TAG, " forceClosed: %s", s_forceClosed ? "true" : "false"); + OS_LOGD(TAG, " isConnected: %s", gatewayConnected ? "true" : "false"); + OS_LOGD(TAG, " commandHandlerOk: %s", commandHandlerOk ? "true" : "false"); _stopCaptive(); return; } diff --git a/src/CaptivePortalInstance.cpp b/src/CaptivePortalInstance.cpp index 1271cd6f..187c1335 100644 --- a/src/CaptivePortalInstance.cpp +++ b/src/CaptivePortalInstance.cpp @@ -68,7 +68,7 @@ CaptivePortalInstance::CaptivePortalInstance() m_socketServer.begin(); m_socketServer.enableHeartbeat(WEBSOCKET_PING_INTERVAL, WEBSOCKET_PING_TIMEOUT, WEBSOCKET_PING_RETRIES); - ESP_LOGI(TAG, "Setting up DNS server"); + OS_LOGI(TAG, "Setting up DNS server"); m_dnsServer.start(DNS_PORT, "*", WiFi.softAPIP()); bool fsOk = true; @@ -76,14 +76,14 @@ CaptivePortalInstance::CaptivePortalInstance() // Get the hash of the filesystem const char* fsHash = _getPartitionHash(); if (fsHash == nullptr) { - ESP_LOGE(TAG, "Failed to get filesystem hash"); + OS_LOGE(TAG, "Failed to get filesystem hash"); fsOk = false; } if (fsOk) { // Mounting LittleFS if (!m_fileSystem.begin(false, "/static", 10U, "static0")) { - ESP_LOGE(TAG, "Failed to mount LittleFS"); + OS_LOGE(TAG, "Failed to mount LittleFS"); fsOk = false; } else { fsOk = m_fileSystem.exists("/www/index.html.gz"); @@ -91,8 +91,8 @@ CaptivePortalInstance::CaptivePortalInstance() } if (fsOk) { - ESP_LOGI(TAG, "Serving files from LittleFS"); - ESP_LOGI(TAG, "Filesystem hash: %s", fsHash); + OS_LOGI(TAG, "Serving files from LittleFS"); + OS_LOGI(TAG, "Filesystem hash: %s", fsHash); char softAPURL[64]; snprintf(softAPURL, sizeof(softAPURL), "http://%s", WiFi.softAPIP().toString().c_str()); @@ -103,7 +103,7 @@ CaptivePortalInstance::CaptivePortalInstance() // Redirecting connection tests to the captive portal, triggering the "login to network" prompt m_webServer.onNotFound([softAPURL](AsyncWebServerRequest* request) { request->redirect(softAPURL); }); } else { - ESP_LOGE(TAG, "/www/index.html or hash files not found, serving error page"); + OS_LOGE(TAG, "/www/index.html or hash files not found, serving error page"); m_webServer.onNotFound([](AsyncWebServerRequest* request) { request->send( @@ -125,7 +125,7 @@ discord.gg/OpenShock if (fsOk) { if (TaskUtils::TaskCreateExpensive(&Util::FnProxy<&CaptivePortalInstance::task>, TAG, 8192, this, 1, &m_taskHandle) != pdPASS) { // PROFILED: 4-6KB stack usage - ESP_LOGE(TAG, "Failed to create task"); + OS_LOGE(TAG, "Failed to create task"); } } } @@ -150,7 +150,7 @@ void CaptivePortalInstance::task() { } void CaptivePortalInstance::handleWebSocketClientConnected(uint8_t socketId) { - ESP_LOGD(TAG, "WebSocket client #%u connected from %s", socketId, m_socketServer.remoteIP(socketId).toString().c_str()); + OS_LOGD(TAG, "WebSocket client #%u connected from %s", socketId, m_socketServer.remoteIP(socketId).toString().c_str()); WiFiNetwork connectedNetwork; WiFiNetwork* connectedNetworkPtr = nullptr; @@ -167,11 +167,11 @@ void CaptivePortalInstance::handleWebSocketClientConnected(uint8_t socketId) { } void CaptivePortalInstance::handleWebSocketClientDisconnected(uint8_t socketId) { - ESP_LOGD(TAG, "WebSocket client #%u disconnected", socketId); + OS_LOGD(TAG, "WebSocket client #%u disconnected", socketId); } void CaptivePortalInstance::handleWebSocketClientError(uint8_t socketId, uint16_t code, const char* message) { - ESP_LOGE(TAG, "WebSocket client #%u error %u: %s", socketId, code, message); + OS_LOGE(TAG, "WebSocket client #%u error %u: %s", socketId, code, message); } void CaptivePortalInstance::handleWebSocketEvent(uint8_t socketId, WebSocketMessageType type, const uint8_t* payload, std::size_t length) { @@ -183,7 +183,7 @@ void CaptivePortalInstance::handleWebSocketEvent(uint8_t socketId, WebSocketMess handleWebSocketClientDisconnected(socketId); break; case WebSocketMessageType::Text: - ESP_LOGE(TAG, "Message type is not supported"); + OS_LOGE(TAG, "Message type is not supported"); break; case WebSocketMessageType::Binary: EventHandlers::WebSocket::HandleLocalBinary(socketId, payload, length); @@ -197,7 +197,7 @@ void CaptivePortalInstance::handleWebSocketEvent(uint8_t socketId, WebSocketMess break; default: m_socketDeFragger.clear(); - ESP_LOGE(TAG, "Unknown WebSocket event type: %u", type); + OS_LOGE(TAG, "Unknown WebSocket event type: %u", type); break; } } diff --git a/src/CommandHandler.cpp b/src/CommandHandler.cpp index c91d566e..d6d38925 100644 --- a/src/CommandHandler.cpp +++ b/src/CommandHandler.cpp @@ -57,7 +57,7 @@ void _keepAliveTask(void* arg) { KnownShocker cmd; while (xQueueReceive(s_keepAliveQueue, &cmd, pdMS_TO_TICKS(eepyTime)) == pdTRUE) { if (cmd.killTask) { - ESP_LOGI(TAG, "Received kill command, exiting keep-alive task"); + OS_LOGI(TAG, "Received kill command, exiting keep-alive task"); vTaskDelete(nullptr); break; // This should never be reached } @@ -78,15 +78,15 @@ void _keepAliveTask(void* arg) { auto& cmdRef = it->second; if (cmdRef.lastActivityTimestamp + KEEP_ALIVE_INTERVAL < now) { - ESP_LOGV(TAG, "Sending keep-alive for shocker %u", cmdRef.shockerId); + OS_LOGV(TAG, "Sending keep-alive for shocker %u", cmdRef.shockerId); if (s_rfTransmitter == nullptr) { - ESP_LOGW(TAG, "RF Transmitter is not initialized, ignoring keep-alive"); + OS_LOGW(TAG, "RF Transmitter is not initialized, ignoring keep-alive"); break; } if (!s_rfTransmitter->SendCommand(cmdRef.model, cmdRef.shockerId, ShockerCommandType::Vibrate, 0, KEEP_ALIVE_DURATION, false)) { - ESP_LOGW(TAG, "Failed to send keep-alive for shocker %u", cmdRef.shockerId); + OS_LOGW(TAG, "Failed to send keep-alive for shocker %u", cmdRef.shockerId); } cmdRef.lastActivityTimestamp = now; @@ -107,18 +107,18 @@ bool _internalSetKeepAliveEnabled(bool enabled) { xSemaphoreTake(s_keepAliveMutex, portMAX_DELAY); if (enabled) { - ESP_LOGV(TAG, "Enabling keep-alive task"); + OS_LOGV(TAG, "Enabling keep-alive task"); s_keepAliveQueue = xQueueCreate(32, sizeof(KnownShocker)); if (s_keepAliveQueue == nullptr) { - ESP_LOGE(TAG, "Failed to create keep-alive task"); + OS_LOGE(TAG, "Failed to create keep-alive task"); xSemaphoreGive(s_keepAliveMutex); return false; } if (TaskUtils::TaskCreateExpensive(_keepAliveTask, "KeepAliveTask", 4096, nullptr, 1, &s_keepAliveTaskHandle) != pdPASS) { // PROFILED: 1.5KB stack usage - ESP_LOGE(TAG, "Failed to create keep-alive task"); + OS_LOGE(TAG, "Failed to create keep-alive task"); vQueueDelete(s_keepAliveQueue); s_keepAliveQueue = nullptr; @@ -127,7 +127,7 @@ bool _internalSetKeepAliveEnabled(bool enabled) { return false; } } else { - ESP_LOGV(TAG, "Disabling keep-alive task"); + OS_LOGV(TAG, "Disabling keep-alive task"); if (s_keepAliveTaskHandle != nullptr && s_keepAliveQueue != nullptr) { // Wait for the task to stop KnownShocker cmd {.killTask = true}; @@ -140,7 +140,7 @@ bool _internalSetKeepAliveEnabled(bool enabled) { vQueueDelete(s_keepAliveQueue); s_keepAliveQueue = nullptr; } else { - ESP_LOGW(TAG, "keep-alive task is already disabled? Something might be wrong."); + OS_LOGW(TAG, "keep-alive task is already disabled? Something might be wrong."); } } @@ -151,7 +151,7 @@ bool _internalSetKeepAliveEnabled(bool enabled) { bool CommandHandler::Init() { if (s_rfTransmitterMutex != nullptr) { - ESP_LOGW(TAG, "RF Transmitter is already initialized"); + OS_LOGW(TAG, "RF Transmitter is already initialized"); return true; } @@ -161,30 +161,30 @@ bool CommandHandler::Init() { Config::RFConfig rfConfig; if (!Config::GetRFConfig(rfConfig)) { - ESP_LOGE(TAG, "Failed to get RF config"); + OS_LOGE(TAG, "Failed to get RF config"); return false; } uint8_t txPin = rfConfig.txPin; if (!OpenShock::IsValidOutputPin(txPin)) { if (!OpenShock::IsValidOutputPin(OPENSHOCK_RF_TX_GPIO)) { - ESP_LOGE(TAG, "Configured RF TX pin (%u) is invalid, and default pin (%u) is invalid. Unable to initialize RF transmitter", txPin, OPENSHOCK_RF_TX_GPIO); + OS_LOGE(TAG, "Configured RF TX pin (%u) is invalid, and default pin (%u) is invalid. Unable to initialize RF transmitter", txPin, OPENSHOCK_RF_TX_GPIO); - ESP_LOGD(TAG, "Setting RF TX pin to GPIO_INVALID"); + OS_LOGD(TAG, "Setting RF TX pin to GPIO_INVALID"); return Config::SetRFConfigTxPin(OPENSHOCK_GPIO_INVALID); // This is not a error yet, unless we are unable to save the RF TX Pin as invalid } - ESP_LOGW(TAG, "Configured RF TX pin (%u) is invalid, using default pin (%u)", txPin, OPENSHOCK_RF_TX_GPIO); + OS_LOGW(TAG, "Configured RF TX pin (%u) is invalid, using default pin (%u)", txPin, OPENSHOCK_RF_TX_GPIO); txPin = OPENSHOCK_RF_TX_GPIO; if (!Config::SetRFConfigTxPin(txPin)) { - ESP_LOGE(TAG, "Failed to set RF TX pin in config"); + OS_LOGE(TAG, "Failed to set RF TX pin in config"); return false; } } s_rfTransmitter = std::make_unique(txPin); if (!s_rfTransmitter->ok()) { - ESP_LOGE(TAG, "Failed to initialize RF Transmitter"); + OS_LOGE(TAG, "Failed to initialize RF Transmitter"); s_rfTransmitter = nullptr; return false; } @@ -208,21 +208,21 @@ SetRfPinResultCode CommandHandler::SetRfTxPin(uint8_t txPin) { xSemaphoreTake(s_rfTransmitterMutex, portMAX_DELAY); if (s_rfTransmitter != nullptr) { - ESP_LOGV(TAG, "Destroying existing RF transmitter"); + OS_LOGV(TAG, "Destroying existing RF transmitter"); s_rfTransmitter = nullptr; } - ESP_LOGV(TAG, "Creating new RF transmitter"); + OS_LOGV(TAG, "Creating new RF transmitter"); auto rfxmit = std::make_unique(txPin); if (!rfxmit->ok()) { - ESP_LOGE(TAG, "Failed to initialize RF transmitter"); + OS_LOGE(TAG, "Failed to initialize RF transmitter"); xSemaphoreGive(s_rfTransmitterMutex); return SetRfPinResultCode::InternalError; } if (!Config::SetRFConfigTxPin(txPin)) { - ESP_LOGE(TAG, "Failed to set RF TX pin in config"); + OS_LOGE(TAG, "Failed to set RF TX pin in config"); xSemaphoreGive(s_rfTransmitterMutex); return SetRfPinResultCode::InternalError; @@ -240,7 +240,7 @@ bool CommandHandler::SetKeepAliveEnabled(bool enabled) { } if (!Config::SetRFConfigKeepAliveEnabled(enabled)) { - ESP_LOGE(TAG, "Failed to set keep-alive enabled in config"); + OS_LOGE(TAG, "Failed to set keep-alive enabled in config"); return false; } @@ -250,12 +250,12 @@ bool CommandHandler::SetKeepAliveEnabled(bool enabled) { bool CommandHandler::SetKeepAlivePaused(bool paused) { bool keepAliveEnabled = false; if (!Config::GetRFConfigKeepAliveEnabled(keepAliveEnabled)) { - ESP_LOGE(TAG, "Failed to get keep-alive enabled from config"); + OS_LOGE(TAG, "Failed to get keep-alive enabled from config"); return false; } if (keepAliveEnabled == false && paused == false) { - ESP_LOGW(TAG, "Keep-alive is disabled in config, ignoring unpause command"); + OS_LOGW(TAG, "Keep-alive is disabled in config, ignoring unpause command"); return false; } if (!_internalSetKeepAliveEnabled(!paused)) { @@ -268,7 +268,7 @@ bool CommandHandler::SetKeepAlivePaused(bool paused) { uint8_t CommandHandler::GetRfTxPin() { uint8_t txPin; if (!Config::GetRFConfigTxPin(txPin)) { - ESP_LOGE(TAG, "Failed to get RF TX pin from config"); + OS_LOGE(TAG, "Failed to get RF TX pin from config"); txPin = OPENSHOCK_GPIO_INVALID; } @@ -279,7 +279,7 @@ bool CommandHandler::HandleCommand(ShockerModelType model, uint16_t shockerId, S xSemaphoreTake(s_rfTransmitterMutex, portMAX_DELAY); if (s_rfTransmitter == nullptr) { - ESP_LOGW(TAG, "RF Transmitter is not initialized, ignoring command"); + OS_LOGW(TAG, "RF Transmitter is not initialized, ignoring command"); xSemaphoreGive(s_rfTransmitterMutex); return false; @@ -287,7 +287,7 @@ bool CommandHandler::HandleCommand(ShockerModelType model, uint16_t shockerId, S // Stop logic if (type == ShockerCommandType::Stop) { - ESP_LOGV(TAG, "Stop command received, clearing pending commands"); + OS_LOGV(TAG, "Stop command received, clearing pending commands"); type = ShockerCommandType::Vibrate; intensity = 0; @@ -295,7 +295,7 @@ bool CommandHandler::HandleCommand(ShockerModelType model, uint16_t shockerId, S s_rfTransmitter->ClearPendingCommands(); } else { - ESP_LOGD(TAG, "Command received: %u %u %u %u", model, shockerId, type, intensity); + OS_LOGD(TAG, "Command received: %u %u %u %u", model, shockerId, type, intensity); } bool ok = s_rfTransmitter->SendCommand(model, shockerId, type, intensity, durationMs); @@ -306,7 +306,7 @@ bool CommandHandler::HandleCommand(ShockerModelType model, uint16_t shockerId, S if (ok && s_keepAliveQueue != nullptr) { KnownShocker cmd {.model = model, .shockerId = shockerId, .lastActivityTimestamp = OpenShock::millis() + durationMs}; if (xQueueSend(s_keepAliveQueue, &cmd, pdMS_TO_TICKS(10)) != pdTRUE) { - ESP_LOGE(TAG, "Failed to send keep-alive command to queue"); + OS_LOGE(TAG, "Failed to send keep-alive command to queue"); } } diff --git a/src/EStopManager.cpp b/src/EStopManager.cpp index d66e50c7..1582540d 100644 --- a/src/EStopManager.cpp +++ b/src/EStopManager.cpp @@ -56,13 +56,13 @@ void _estopEventHandler(void* pvParameters) { EstopEventQueueMessage message; if (xQueueReceive(s_estopEventQueue, &message, waitTime) == pdTRUE) { if (message.pressed) { - ESP_LOGI(TAG, "EStop pressed"); + OS_LOGI(TAG, "EStop pressed"); } else { - ESP_LOGI(TAG, "EStop released"); + OS_LOGI(TAG, "EStop released"); } if (message.deactivatesAtChanged) { - ESP_LOGI(TAG, "EStop deactivation time changed"); + OS_LOGI(TAG, "EStop deactivation time changed"); deactivatesAt = message.deactivatesAt; } @@ -76,7 +76,7 @@ void _estopEventHandler(void* pvParameters) { s_estopAwaitingRelease = true; OpenShock::VisualStateManager::SetEmergencyStopStatus(s_estopActive, s_estopAwaitingRelease); - ESP_LOGI(TAG, "EStop cleared, awaiting release"); + OS_LOGI(TAG, "EStop cleared, awaiting release"); } } } @@ -124,7 +124,7 @@ void EStopManager::Init() { #ifdef OPENSHOCK_ESTOP_PIN s_estopPin = static_cast(OPENSHOCK_ESTOP_PIN); - ESP_LOGI(TAG, "Initializing on pin %hhi", static_cast(s_estopPin)); + OS_LOGI(TAG, "Initializing on pin %hhi", static_cast(s_estopPin)); gpio_config_t io_conf; io_conf.pin_bit_mask = 1ULL << s_estopPin; @@ -139,20 +139,20 @@ void EStopManager::Init() { esp_err_t err = gpio_install_isr_service(ESP_INTR_FLAG_EDGE); if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) { // ESP_ERR_INVALID_STATE is fine, it just means the ISR service is already installed - ESP_PANIC(TAG, "Failed to install EStop ISR service"); + OS_PANIC(TAG, "Failed to install EStop ISR service"); } err = gpio_isr_handler_add(s_estopPin, _estopEdgeInterrupt, nullptr); if (err != ESP_OK) { - ESP_PANIC(TAG, "Failed to add EStop ISR handler"); + OS_PANIC(TAG, "Failed to add EStop ISR handler"); } if (TaskUtils::TaskCreateUniversal(_estopEventHandler, TAG, 4096, nullptr, 5, &s_estopEventHandlerTask, 1) != pdPASS) { - ESP_PANIC(TAG, "Failed to create EStop event handler task"); + OS_PANIC(TAG, "Failed to create EStop event handler task"); } #else - ESP_LOGI(TAG, "EStopManager disabled, no pin defined"); + OS_LOGI(TAG, "EStopManager disabled, no pin defined"); #endif } diff --git a/src/GatewayClient.cpp b/src/GatewayClient.cpp index 5315aec3..a42f2dea 100644 --- a/src/GatewayClient.cpp +++ b/src/GatewayClient.cpp @@ -17,7 +17,7 @@ using namespace OpenShock; static bool s_bootStatusSent = false; GatewayClient::GatewayClient(const std::string& authToken) : m_webSocket(), m_lastKeepAlive(0), m_state(State::Disconnected) { - ESP_LOGD(TAG, "Creating GatewayClient"); + OS_LOGD(TAG, "Creating GatewayClient"); std::string headers = "Firmware-Version: " OPENSHOCK_FW_VERSION "\r\n" "Device-Token: " @@ -28,7 +28,7 @@ GatewayClient::GatewayClient(const std::string& authToken) : m_webSocket(), m_la m_webSocket.onEvent(std::bind(&GatewayClient::_handleEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); } GatewayClient::~GatewayClient() { - ESP_LOGD(TAG, "Destroying GatewayClient"); + OS_LOGD(TAG, "Destroying GatewayClient"); m_webSocket.disconnect(); } @@ -53,7 +53,7 @@ void GatewayClient::connect(const char* lcgFqdn) { #warning SSL certificate verification is currently not implemented, by RFC definition this is a security risk, and allows for MITM attacks, but the realistic risk is low m_webSocket.beginSSL(lcgFqdn, 443, "/1/ws/device"); - ESP_LOGW(TAG, "WEBSOCKET CONNECTION BY RFC DEFINITION IS INSECURE, remote endpoint can not be verified due to lack of CA verification support, theoretically this is a security risk and allows for MITM attacks, but the realistic risk is low"); + OS_LOGW(TAG, "WEBSOCKET CONNECTION BY RFC DEFINITION IS INSECURE, remote endpoint can not be verified due to lack of CA verification support, theoretically this is a security risk and allows for MITM attacks, but the realistic risk is low"); } void GatewayClient::disconnect() { @@ -114,11 +114,11 @@ void GatewayClient::_setState(State state) { switch (m_state) { case State::Disconnected: - ESP_LOGI(TAG, "Disconnected from API"); + OS_LOGI(TAG, "Disconnected from API"); OpenShock::VisualStateManager::SetWebSocketConnected(false); break; case State::Connected: - ESP_LOGI(TAG, "Connected to API"); + OS_LOGI(TAG, "Connected to API"); OpenShock::VisualStateManager::SetWebSocketConnected(true); break; default: @@ -127,30 +127,30 @@ void GatewayClient::_setState(State state) { } void GatewayClient::_sendKeepAlive() { - ESP_LOGV(TAG, "Sending Gateway keep-alive message"); + OS_LOGV(TAG, "Sending Gateway keep-alive message"); Serialization::Gateway::SerializeKeepAliveMessage([this](const uint8_t* data, std::size_t len) { return m_webSocket.sendBIN(data, len); }); } void GatewayClient::_sendBootStatus() { if (s_bootStatusSent) return; - ESP_LOGV(TAG, "Sending Gateway boot status message"); + OS_LOGV(TAG, "Sending Gateway boot status message"); int32_t updateId; if (!Config::GetOtaUpdateId(updateId)) { - ESP_LOGE(TAG, "Failed to get OTA update ID"); + OS_LOGE(TAG, "Failed to get OTA update ID"); return; } OpenShock::OtaUpdateStep updateStep; if (!Config::GetOtaUpdateStep(updateStep)) { - ESP_LOGE(TAG, "Failed to get OTA firmware boot type"); + OS_LOGE(TAG, "Failed to get OTA firmware boot type"); return; } OpenShock::SemVer version; if (!OpenShock::TryParseSemVer(OPENSHOCK_FW_VERSION, version)) { - ESP_LOGE(TAG, "Failed to parse firmware version"); + OS_LOGE(TAG, "Failed to parse firmware version"); return; } @@ -158,7 +158,7 @@ void GatewayClient::_sendBootStatus() { if (s_bootStatusSent && updateStep != OpenShock::OtaUpdateStep::None) { if (!Config::SetOtaUpdateStep(OpenShock::OtaUpdateStep::None)) { - ESP_LOGE(TAG, "Failed to reset firmware boot type to normal"); + OS_LOGE(TAG, "Failed to reset firmware boot type to normal"); } } } @@ -176,34 +176,34 @@ void GatewayClient::_handleEvent(WStype_t type, uint8_t* payload, std::size_t le _sendBootStatus(); break; case WStype_TEXT: - ESP_LOGW(TAG, "Received text from API, JSON parsing is not supported anymore :D"); + OS_LOGW(TAG, "Received text from API, JSON parsing is not supported anymore :D"); break; case WStype_ERROR: - ESP_LOGE(TAG, "Received error from API"); + OS_LOGE(TAG, "Received error from API"); break; case WStype_FRAGMENT_TEXT_START: - ESP_LOGD(TAG, "Received fragment text start from API"); + OS_LOGD(TAG, "Received fragment text start from API"); break; case WStype_FRAGMENT: - ESP_LOGD(TAG, "Received fragment from API"); + OS_LOGD(TAG, "Received fragment from API"); break; case WStype_FRAGMENT_FIN: - ESP_LOGD(TAG, "Received fragment fin from API"); + OS_LOGD(TAG, "Received fragment fin from API"); break; case WStype_PING: - ESP_LOGD(TAG, "Received ping from API"); + OS_LOGD(TAG, "Received ping from API"); break; case WStype_PONG: - ESP_LOGD(TAG, "Received pong from API"); + OS_LOGD(TAG, "Received pong from API"); break; case WStype_BIN: EventHandlers::WebSocket::HandleGatewayBinary(payload, length); break; case WStype_FRAGMENT_BIN_START: - ESP_LOGE(TAG, "Received binary fragment start from API, this is not supported!"); + OS_LOGE(TAG, "Received binary fragment start from API, this is not supported!"); break; default: - ESP_LOGE(TAG, "Received unknown event from API"); + OS_LOGE(TAG, "Received unknown event from API"); break; } } diff --git a/src/GatewayConnectionManager.cpp b/src/GatewayConnectionManager.cpp index b0943b36..95811fd9 100644 --- a/src/GatewayConnectionManager.cpp +++ b/src/GatewayConnectionManager.cpp @@ -41,7 +41,7 @@ void _evGotIPHandler(arduino_event_t* event) { (void)event; s_flags |= FLAG_HAS_IP; - ESP_LOGD(TAG, "Got IP address"); + OS_LOGD(TAG, "Got IP address"); } void _evWiFiDisconnectedHandler(arduino_event_t* event) { @@ -49,7 +49,7 @@ void _evWiFiDisconnectedHandler(arduino_event_t* event) { s_flags = FLAG_NONE; s_wsClient = nullptr; - ESP_LOGD(TAG, "Lost IP address"); + OS_LOGD(TAG, "Lost IP address"); OpenShock::VisualStateManager::SetWebSocketConnected(false); } @@ -82,10 +82,10 @@ AccountLinkResultCode GatewayConnectionManager::Link(StringView linkCode) { } s_wsClient = nullptr; - ESP_LOGD(TAG, "Attempting to link to account using code %.*s", linkCode.length(), linkCode.data()); + OS_LOGD(TAG, "Attempting to link to account using code %.*s", linkCode.length(), linkCode.data()); if (linkCode.length() != LINK_CODE_LENGTH) { - ESP_LOGE(TAG, "Invalid link code length"); + OS_LOGE(TAG, "Invalid link code length"); return AccountLinkResultCode::InvalidCode; } @@ -95,7 +95,7 @@ AccountLinkResultCode GatewayConnectionManager::Link(StringView linkCode) { return AccountLinkResultCode::InternalError; // Just return false, don't spam the console with errors } if (response.result != HTTP::RequestResult::Success) { - ESP_LOGE(TAG, "Error while getting auth token: %d %d", response.result, response.code); + OS_LOGE(TAG, "Error while getting auth token: %d %d", response.result, response.code); return AccountLinkResultCode::InternalError; } @@ -105,24 +105,24 @@ AccountLinkResultCode GatewayConnectionManager::Link(StringView linkCode) { } if (response.code != 200) { - ESP_LOGE(TAG, "Unexpected response code: %d", response.code); + OS_LOGE(TAG, "Unexpected response code: %d", response.code); return AccountLinkResultCode::InternalError; } StringView authToken = response.data.authToken; if (authToken.isNullOrEmpty()) { - ESP_LOGE(TAG, "Received empty auth token"); + OS_LOGE(TAG, "Received empty auth token"); return AccountLinkResultCode::InternalError; } if (!Config::SetBackendAuthToken(authToken)) { - ESP_LOGE(TAG, "Failed to save auth token"); + OS_LOGE(TAG, "Failed to save auth token"); return AccountLinkResultCode::InternalError; } s_flags |= FLAG_LINKED; - ESP_LOGD(TAG, "Successfully linked to account"); + OS_LOGD(TAG, "Successfully linked to account"); return AccountLinkResultCode::Success; } @@ -160,26 +160,26 @@ bool FetchDeviceInfo(StringView authToken) { return false; // Just return false, don't spam the console with errors } if (response.result != HTTP::RequestResult::Success) { - ESP_LOGE(TAG, "Error while fetching device info: %d %d", response.result, response.code); + OS_LOGE(TAG, "Error while fetching device info: %d %d", response.result, response.code); return false; } if (response.code == 401) { - ESP_LOGD(TAG, "Auth token is invalid, clearing it"); + OS_LOGD(TAG, "Auth token is invalid, clearing it"); Config::ClearBackendAuthToken(); return false; } if (response.code != 200) { - ESP_LOGE(TAG, "Unexpected response code: %d", response.code); + OS_LOGE(TAG, "Unexpected response code: %d", response.code); return false; } - ESP_LOGI(TAG, "Device ID: %s", response.data.deviceId.c_str()); - ESP_LOGI(TAG, "Device Name: %s", response.data.deviceName.c_str()); - ESP_LOGI(TAG, "Shockers:"); + OS_LOGI(TAG, "Device ID: %s", response.data.deviceId.c_str()); + OS_LOGI(TAG, "Device Name: %s", response.data.deviceName.c_str()); + OS_LOGI(TAG, "Shockers:"); for (auto& shocker : response.data.shockers) { - ESP_LOGI(TAG, " [%s] rf=%u model=%u", shocker.id.c_str(), shocker.rfId, shocker.model); + OS_LOGI(TAG, " [%s] rf=%u model=%u", shocker.id.c_str(), shocker.rfId, shocker.model); } s_flags |= FLAG_LINKED; @@ -191,12 +191,12 @@ static int64_t _lastConnectionAttempt = 0; bool StartConnectingToLCG() { // TODO: this function is very slow, should be optimized! if (s_wsClient == nullptr) { // If wsClient is already initialized, we are already paired or connected - ESP_LOGD(TAG, "wsClient is null"); + OS_LOGD(TAG, "wsClient is null"); return false; } if (s_wsClient->state() != GatewayClient::State::Disconnected) { - ESP_LOGD(TAG, "WebSocketClient is not disconnected, waiting..."); + OS_LOGD(TAG, "WebSocketClient is not disconnected, waiting..."); s_wsClient->disconnect(); return false; } @@ -212,19 +212,19 @@ bool StartConnectingToLCG() { std::string lcgOverride; Config::GetBackendLCGOverride(lcgOverride); - ESP_LOGD(TAG, "Connecting to overridden LCG endpoint %s", lcgOverride.c_str()); + OS_LOGD(TAG, "Connecting to overridden LCG endpoint %s", lcgOverride.c_str()); s_wsClient->connect(lcgOverride.c_str()); return true; } if (!Config::HasBackendAuthToken()) { - ESP_LOGD(TAG, "No auth token, can't connect to LCG"); + OS_LOGD(TAG, "No auth token, can't connect to LCG"); return false; } std::string authToken; if (!Config::GetBackendAuthToken(authToken)) { - ESP_LOGE(TAG, "Failed to get auth token"); + OS_LOGE(TAG, "Failed to get auth token"); return false; } @@ -234,22 +234,22 @@ bool StartConnectingToLCG() { return false; // Just return false, don't spam the console with errors } if (response.result != HTTP::RequestResult::Success) { - ESP_LOGE(TAG, "Error while fetching LCG endpoint: %d %d", response.result, response.code); + OS_LOGE(TAG, "Error while fetching LCG endpoint: %d %d", response.result, response.code); return false; } if (response.code == 401) { - ESP_LOGD(TAG, "Auth token is invalid, clearing it"); + OS_LOGD(TAG, "Auth token is invalid, clearing it"); Config::ClearBackendAuthToken(); return false; } if (response.code != 200) { - ESP_LOGE(TAG, "Unexpected response code: %d", response.code); + OS_LOGE(TAG, "Unexpected response code: %d", response.code); return false; } - ESP_LOGD(TAG, "Connecting to LCG endpoint %s in country %s", response.data.fqdn.c_str(), response.data.country.c_str()); + OS_LOGD(TAG, "Connecting to LCG endpoint %s in country %s", response.data.fqdn.c_str(), response.data.country.c_str()); s_wsClient->connect(response.data.fqdn.c_str()); return true; @@ -264,7 +264,7 @@ void GatewayConnectionManager::Update() { std::string authToken; if (!Config::GetBackendAuthToken(authToken)) { - ESP_LOGE(TAG, "Failed to get auth token"); + OS_LOGE(TAG, "Failed to get auth token"); return; } @@ -274,7 +274,7 @@ void GatewayConnectionManager::Update() { } s_flags |= FLAG_LINKED; - ESP_LOGD(TAG, "Successfully verified auth token"); + OS_LOGD(TAG, "Successfully verified auth token"); s_wsClient = std::make_unique(authToken); } diff --git a/src/OtaUpdateManager.cpp b/src/OtaUpdateManager.cpp index 07566958..5d92c4cb 100644 --- a/src/OtaUpdateManager.cpp +++ b/src/OtaUpdateManager.cpp @@ -67,7 +67,7 @@ static SemaphoreHandle_t _requestedVersionMutex = xSemaphoreCreateMutex(); bool _tryQueueUpdateRequest(const OpenShock::SemVer& version) { if (xSemaphoreTake(_requestedVersionMutex, pdMS_TO_TICKS(1000)) != pdTRUE) { - ESP_LOGE(TAG, "Failed to take requested version mutex"); + OS_LOGE(TAG, "Failed to take requested version mutex"); return false; } @@ -82,7 +82,7 @@ bool _tryQueueUpdateRequest(const OpenShock::SemVer& version) { bool _tryGetRequestedVersion(OpenShock::SemVer& version) { if (xSemaphoreTake(_requestedVersionMutex, pdMS_TO_TICKS(1000)) != pdTRUE) { - ESP_LOGE(TAG, "Failed to take requested version mutex"); + OS_LOGE(TAG, "Failed to take requested version mutex"); return false; } @@ -105,12 +105,12 @@ void _otaEvWiFiDisconnectedHandler(arduino_event_t* event) { bool _sendProgressMessage(Serialization::Gateway::OtaInstallProgressTask task, float progress) { int32_t updateId; if (!Config::GetOtaUpdateId(updateId)) { - ESP_LOGE(TAG, "Failed to get OTA update ID"); + OS_LOGE(TAG, "Failed to get OTA update ID"); return false; } if (!Serialization::Gateway::SerializeOtaInstallProgressMessage(updateId, task, progress, GatewayConnectionManager::SendMessageBIN)) { - ESP_LOGE(TAG, "Failed to send OTA install progress message"); + OS_LOGE(TAG, "Failed to send OTA install progress message"); return false; } @@ -119,12 +119,12 @@ bool _sendProgressMessage(Serialization::Gateway::OtaInstallProgressTask task, f bool _sendFailureMessage(StringView message, bool fatal = false) { int32_t updateId; if (!Config::GetOtaUpdateId(updateId)) { - ESP_LOGE(TAG, "Failed to get OTA update ID"); + OS_LOGE(TAG, "Failed to get OTA update ID"); return false; } if (!Serialization::Gateway::SerializeOtaInstallFailedMessage(updateId, message, fatal, GatewayConnectionManager::SendMessageBIN)) { - ESP_LOGE(TAG, "Failed to send OTA install failed message"); + OS_LOGE(TAG, "Failed to send OTA install failed message"); return false; } @@ -132,14 +132,14 @@ bool _sendFailureMessage(StringView message, bool fatal = false) { } bool _flashAppPartition(const esp_partition_t* partition, StringView remoteUrl, const uint8_t (&remoteHash)[32]) { - ESP_LOGD(TAG, "Flashing app partition"); + OS_LOGD(TAG, "Flashing app partition"); if (!_sendProgressMessage(Serialization::Gateway::OtaInstallProgressTask::FlashingApplication, 0.0f)) { return false; } auto onProgress = [](std::size_t current, std::size_t total, float progress) -> bool { - ESP_LOGD(TAG, "Flashing app partition: %u / %u (%.2f%%)", current, total, progress * 100.0f); + OS_LOGD(TAG, "Flashing app partition: %u / %u (%.2f%%)", current, total, progress * 100.0f); _sendProgressMessage(Serialization::Gateway::OtaInstallProgressTask::FlashingApplication, progress); @@ -147,7 +147,7 @@ bool _flashAppPartition(const esp_partition_t* partition, StringView remoteUrl, }; if (!OpenShock::FlashPartitionFromUrl(partition, remoteUrl, remoteHash, onProgress)) { - ESP_LOGE(TAG, "Failed to flash app partition"); + OS_LOGE(TAG, "Failed to flash app partition"); _sendFailureMessage("Failed to flash app partition"_sv); return false; } @@ -158,7 +158,7 @@ bool _flashAppPartition(const esp_partition_t* partition, StringView remoteUrl, // Set app partition bootable. if (esp_ota_set_boot_partition(partition) != ESP_OK) { - ESP_LOGE(TAG, "Failed to set app partition bootable"); + OS_LOGE(TAG, "Failed to set app partition bootable"); _sendFailureMessage("Failed to set app partition bootable"_sv); return false; } @@ -173,19 +173,19 @@ bool _flashFilesystemPartition(const esp_partition_t* parition, StringView remot // Make sure captive portal is stopped, timeout after 5 seconds. if (!CaptivePortal::ForceClose(5000U)) { - ESP_LOGE(TAG, "Failed to force close captive portal (timed out)"); + OS_LOGE(TAG, "Failed to force close captive portal (timed out)"); _sendFailureMessage("Failed to force close captive portal (timed out)"_sv); return false; } - ESP_LOGD(TAG, "Flashing filesystem partition"); + OS_LOGD(TAG, "Flashing filesystem partition"); if (!_sendProgressMessage(Serialization::Gateway::OtaInstallProgressTask::FlashingFilesystem, 0.0f)) { return false; } auto onProgress = [](std::size_t current, std::size_t total, float progress) -> bool { - ESP_LOGD(TAG, "Flashing filesystem partition: %u / %u (%.2f%%)", current, total, progress * 100.0f); + OS_LOGD(TAG, "Flashing filesystem partition: %u / %u (%.2f%%)", current, total, progress * 100.0f); _sendProgressMessage(Serialization::Gateway::OtaInstallProgressTask::FlashingFilesystem, progress); @@ -193,7 +193,7 @@ bool _flashFilesystemPartition(const esp_partition_t* parition, StringView remot }; if (!OpenShock::FlashPartitionFromUrl(parition, remoteUrl, remoteHash, onProgress)) { - ESP_LOGE(TAG, "Failed to flash filesystem partition"); + OS_LOGE(TAG, "Failed to flash filesystem partition"); _sendFailureMessage("Failed to flash filesystem partition"_sv); return false; } @@ -205,7 +205,7 @@ bool _flashFilesystemPartition(const esp_partition_t* parition, StringView remot // Attempt to mount filesystem. fs::LittleFSFS test; if (!test.begin(false, "/static", 10, "static0")) { - ESP_LOGE(TAG, "Failed to mount filesystem"); + OS_LOGE(TAG, "Failed to mount filesystem"); _sendFailureMessage("Failed to mount filesystem"_sv); return false; } @@ -219,7 +219,7 @@ bool _flashFilesystemPartition(const esp_partition_t* parition, StringView remot void _otaUpdateTask(void* arg) { (void)arg; - ESP_LOGD(TAG, "OTA update task started"); + OS_LOGD(TAG, "OTA update task started"); bool connected = false; bool updateRequested = false; @@ -234,13 +234,13 @@ void _otaUpdateTask(void* arg) { updateRequested |= (eventBits & OTA_TASK_EVENT_UPDATE_REQUESTED) != 0; if ((eventBits & OTA_TASK_EVENT_WIFI_DISCONNECTED) != 0) { - ESP_LOGD(TAG, "WiFi disconnected"); + OS_LOGD(TAG, "WiFi disconnected"); connected = false; continue; // No further processing needed. } if ((eventBits & OTA_TASK_EVENT_WIFI_CONNECTED) != 0 && !connected) { - ESP_LOGD(TAG, "WiFi connected"); + OS_LOGD(TAG, "WiFi connected"); connected = true; } @@ -253,12 +253,12 @@ void _otaUpdateTask(void* arg) { Config::OtaUpdateConfig config; if (!Config::GetOtaUpdateConfig(config)) { - ESP_LOGE(TAG, "Failed to get OTA update config"); + OS_LOGE(TAG, "Failed to get OTA update config"); continue; } if (!config.isEnabled) { - ESP_LOGD(TAG, "OTA updates are disabled, skipping update check"); + OS_LOGD(TAG, "OTA updates are disabled, skipping update check"); continue; } @@ -278,7 +278,7 @@ void _otaUpdateTask(void* arg) { lastUpdateCheck = now; if (config.requireManualApproval) { - ESP_LOGD(TAG, "Manual approval required, skipping update check"); + OS_LOGD(TAG, "Manual approval required, skipping update check"); // TODO: IMPLEMENT continue; } @@ -288,41 +288,41 @@ void _otaUpdateTask(void* arg) { updateRequested = false; if (!_tryGetRequestedVersion(version)) { - ESP_LOGE(TAG, "Failed to get requested version"); + OS_LOGE(TAG, "Failed to get requested version"); continue; } - ESP_LOGD(TAG, "Update requested for version %s", version.toString().c_str()); // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this + OS_LOGD(TAG, "Update requested for version %s", version.toString().c_str()); // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this } else { - ESP_LOGD(TAG, "Checking for updates"); + OS_LOGD(TAG, "Checking for updates"); // Fetch current version. if (!OtaUpdateManager::TryGetFirmwareVersion(config.updateChannel, version)) { - ESP_LOGE(TAG, "Failed to fetch firmware version"); + OS_LOGE(TAG, "Failed to fetch firmware version"); continue; } - ESP_LOGD(TAG, "Remote version: %s", version.toString().c_str()); // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this + OS_LOGD(TAG, "Remote version: %s", version.toString().c_str()); // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this } if (version.toString() == OPENSHOCK_FW_VERSION) { // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this - ESP_LOGI(TAG, "Requested version is already installed"); + OS_LOGI(TAG, "Requested version is already installed"); continue; } // Generate random int32_t for this update. int32_t updateId = static_cast(esp_random()); if (!Config::SetOtaUpdateId(updateId)) { - ESP_LOGE(TAG, "Failed to set OTA update ID"); + OS_LOGE(TAG, "Failed to set OTA update ID"); continue; } if (!Config::SetOtaUpdateStep(OpenShock::OtaUpdateStep::Updating)) { - ESP_LOGE(TAG, "Failed to set OTA update step"); + OS_LOGE(TAG, "Failed to set OTA update step"); continue; } if (!Serialization::Gateway::SerializeOtaInstallStartedMessage(updateId, version, GatewayConnectionManager::SendMessageBIN)) { - ESP_LOGE(TAG, "Failed to serialize OTA install started message"); + OS_LOGE(TAG, "Failed to serialize OTA install started message"); continue; } @@ -333,23 +333,23 @@ void _otaUpdateTask(void* arg) { // Fetch current release. OtaUpdateManager::FirmwareRelease release; if (!OtaUpdateManager::TryGetFirmwareRelease(version, release)) { - ESP_LOGE(TAG, "Failed to fetch firmware release"); // TODO: Send error message to server + OS_LOGE(TAG, "Failed to fetch firmware release"); // TODO: Send error message to server _sendFailureMessage("Failed to fetch firmware release"_sv); continue; } // Print release. - ESP_LOGD(TAG, "Firmware release:"); - ESP_LOGD(TAG, " Version: %s", version.toString().c_str()); // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this - ESP_LOGD(TAG, " App binary URL: %s", release.appBinaryUrl.c_str()); - ESP_LOGD(TAG, " App binary hash: %s", HexUtils::ToHex<32>(release.appBinaryHash).data()); - ESP_LOGD(TAG, " Filesystem binary URL: %s", release.filesystemBinaryUrl.c_str()); - ESP_LOGD(TAG, " Filesystem binary hash: %s", HexUtils::ToHex<32>(release.filesystemBinaryHash).data()); + OS_LOGD(TAG, "Firmware release:"); + OS_LOGD(TAG, " Version: %s", version.toString().c_str()); // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this + OS_LOGD(TAG, " App binary URL: %s", release.appBinaryUrl.c_str()); + OS_LOGD(TAG, " App binary hash: %s", HexUtils::ToHex<32>(release.appBinaryHash).data()); + OS_LOGD(TAG, " Filesystem binary URL: %s", release.filesystemBinaryUrl.c_str()); + OS_LOGD(TAG, " Filesystem binary hash: %s", HexUtils::ToHex<32>(release.filesystemBinaryHash).data()); // Get available app update partition. const esp_partition_t* appPartition = esp_ota_get_next_update_partition(nullptr); if (appPartition == nullptr) { - ESP_LOGE(TAG, "Failed to get app update partition"); // TODO: Send error message to server + OS_LOGE(TAG, "Failed to get app update partition"); // TODO: Send error message to server _sendFailureMessage("Failed to get app update partition"_sv); continue; } @@ -357,7 +357,7 @@ void _otaUpdateTask(void* arg) { // Get filesystem partition. const esp_partition_t* filesystemPartition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, "static0"); if (filesystemPartition == nullptr) { - ESP_LOGE(TAG, "Failed to find filesystem partition"); // TODO: Send error message to server + OS_LOGE(TAG, "Failed to find filesystem partition"); // TODO: Send error message to server _sendFailureMessage("Failed to find filesystem partition"_sv); continue; } @@ -372,7 +372,7 @@ void _otaUpdateTask(void* arg) { // Set OTA boot type in config. if (!Config::SetOtaUpdateStep(OpenShock::OtaUpdateStep::Updated)) { - ESP_LOGE(TAG, "Failed to set OTA update step"); + OS_LOGE(TAG, "Failed to set OTA update step"); _sendFailureMessage("Failed to set OTA update step"_sv); continue; } @@ -384,7 +384,7 @@ void _otaUpdateTask(void* arg) { _sendProgressMessage(Serialization::Gateway::OtaInstallProgressTask::Rebooting, 0.0f); // Reboot into new firmware. - ESP_LOGI(TAG, "Restarting into new firmware..."); + OS_LOGI(TAG, "Restarting into new firmware..."); vTaskDelay(pdMS_TO_TICKS(200)); break; } @@ -402,7 +402,7 @@ bool _tryGetStringList(StringView url, std::vector& list) { {200, 304} ); if (response.result != OpenShock::HTTP::RequestResult::Success) { - ESP_LOGE(TAG, "Failed to fetch list: [%u] %s", response.code, response.data.c_str()); + OS_LOGE(TAG, "Failed to fetch list: [%u] %s", response.code, response.data.c_str()); return false; } @@ -427,28 +427,28 @@ bool _tryGetStringList(StringView url, std::vector& list) { } bool OtaUpdateManager::Init() { - ESP_LOGD(TAG, "Fetching current partition"); + OS_LOGN(TAG, "Fetching current partition"); // Fetch current partition info. const esp_partition_t* partition = esp_ota_get_running_partition(); if (partition == nullptr) { - ESP_PANIC(TAG, "Failed to get currently running partition"); + OS_PANIC(TAG, "Failed to get currently running partition"); return false; // This will never be reached, but the compiler doesn't know that. } - ESP_LOGD(TAG, "Fetching partition state"); + OS_LOGD(TAG, "Fetching partition state"); // Get OTA state for said partition. esp_err_t err = esp_ota_get_state_partition(partition, &_otaImageState); if (err != ESP_OK) { - ESP_PANIC(TAG, "Failed to get partition state: %s", esp_err_to_name(err)); + OS_PANIC(TAG, "Failed to get partition state: %s", esp_err_to_name(err)); return false; // This will never be reached, but the compiler doesn't know that. } - ESP_LOGD(TAG, "Fetching previous update step"); + OS_LOGD(TAG, "Fetching previous update step"); OtaUpdateStep updateStep; if (!Config::GetOtaUpdateStep(updateStep)) { - ESP_LOGE(TAG, "Failed to get OTA update step"); + OS_LOGE(TAG, "Failed to get OTA update step"); return false; } @@ -468,7 +468,7 @@ bool OtaUpdateManager::Init() { if (updateStep == OtaUpdateStep::Updated) { if (!Config::SetOtaUpdateStep(OtaUpdateStep::Validating)) { - ESP_PANIC(TAG, "Failed to set OTA update step in critical section"); // TODO: THIS IS A CRITICAL SECTION, WHAT DO WE DO? + OS_PANIC(TAG, "Failed to set OTA update step in critical section"); // TODO: THIS IS A CRITICAL SECTION, WHAT DO WE DO? } } @@ -495,11 +495,11 @@ bool OtaUpdateManager::TryGetFirmwareVersion(OtaUpdateChannel channel, OpenShock channelIndexUrl = StringView(OPENSHOCK_FW_CDN_DEVELOP_URL); break; default: - ESP_LOGE(TAG, "Unknown channel: %u", channel); + OS_LOGE(TAG, "Unknown channel: %u", channel); return false; } - ESP_LOGD(TAG, "Fetching firmware version from %s", channelIndexUrl); + OS_LOGD(TAG, "Fetching firmware version from %s", channelIndexUrl); auto response = OpenShock::HTTP::GetString( channelIndexUrl, @@ -509,12 +509,12 @@ bool OtaUpdateManager::TryGetFirmwareVersion(OtaUpdateChannel channel, OpenShock {200, 304} ); if (response.result != OpenShock::HTTP::RequestResult::Success) { - ESP_LOGE(TAG, "Failed to fetch firmware version: [%u] %s", response.code, response.data.c_str()); + OS_LOGE(TAG, "Failed to fetch firmware version: [%u] %s", response.code, response.data.c_str()); return false; } if (!OpenShock::TryParseSemVer(response.data, version)) { - ESP_LOGE(TAG, "Failed to parse firmware version: %.*s", response.data.size(), response.data.data()); + OS_LOGE(TAG, "Failed to parse firmware version: %.*s", response.data.size(), response.data.data()); return false; } @@ -524,14 +524,14 @@ bool OtaUpdateManager::TryGetFirmwareVersion(OtaUpdateChannel channel, OpenShock bool OtaUpdateManager::TryGetFirmwareBoards(const OpenShock::SemVer& version, std::vector& boards) { std::string channelIndexUrl; if (!FormatToString(channelIndexUrl, OPENSHOCK_FW_CDN_BOARDS_INDEX_URL_FORMAT, version.toString().c_str())) { // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this - ESP_LOGE(TAG, "Failed to format URL"); + OS_LOGE(TAG, "Failed to format URL"); return false; } - ESP_LOGD(TAG, "Fetching firmware boards from %s", channelIndexUrl.c_str()); + OS_LOGD(TAG, "Fetching firmware boards from %s", channelIndexUrl.c_str()); if (!_tryGetStringList(channelIndexUrl, boards)) { - ESP_LOGE(TAG, "Failed to fetch firmware boards"); + OS_LOGE(TAG, "Failed to fetch firmware boards"); return false; } @@ -540,7 +540,7 @@ bool OtaUpdateManager::TryGetFirmwareBoards(const OpenShock::SemVer& version, st bool _tryParseIntoHash(StringView hash, uint8_t (&hashBytes)[32]) { if (!HexUtils::TryParseHex(hash.data(), hash.size(), hashBytes, 32)) { - ESP_LOGE(TAG, "Failed to parse hash: %.*s", hash.size(), hash.data()); + OS_LOGE(TAG, "Failed to parse hash: %.*s", hash.size(), hash.data()); return false; } @@ -551,19 +551,19 @@ bool OtaUpdateManager::TryGetFirmwareRelease(const OpenShock::SemVer& version, F auto versionStr = version.toString(); // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this if (!FormatToString(release.appBinaryUrl, OPENSHOCK_FW_CDN_APP_URL_FORMAT, versionStr.c_str())) { - ESP_LOGE(TAG, "Failed to format URL"); + OS_LOGE(TAG, "Failed to format URL"); return false; } if (!FormatToString(release.filesystemBinaryUrl, OPENSHOCK_FW_CDN_FILESYSTEM_URL_FORMAT, versionStr.c_str())) { - ESP_LOGE(TAG, "Failed to format URL"); + OS_LOGE(TAG, "Failed to format URL"); return false; } // Construct hash URLs. std::string sha256HashesUrl; if (!FormatToString(sha256HashesUrl, OPENSHOCK_FW_CDN_SHA256_HASHES_URL_FORMAT, versionStr.c_str())) { - ESP_LOGE(TAG, "Failed to format URL"); + OS_LOGE(TAG, "Failed to format URL"); return false; } @@ -576,7 +576,7 @@ bool OtaUpdateManager::TryGetFirmwareRelease(const OpenShock::SemVer& version, F {200, 304} ); if (sha256HashesResponse.result != OpenShock::HTTP::RequestResult::Success) { - ESP_LOGE(TAG, "Failed to fetch hashes: [%u] %s", sha256HashesResponse.code, sha256HashesResponse.data.c_str()); + OS_LOGE(TAG, "Failed to fetch hashes: [%u] %s", sha256HashesResponse.code, sha256HashesResponse.data.c_str()); return false; } @@ -587,7 +587,7 @@ bool OtaUpdateManager::TryGetFirmwareRelease(const OpenShock::SemVer& version, F for (OpenShock::StringView line : hashesLines) { auto parts = line.splitWhitespace(); if (parts.size() != 2) { - ESP_LOGE(TAG, "Invalid hashes entry: %.*s", line.size(), line.data()); + OS_LOGE(TAG, "Invalid hashes entry: %.*s", line.size(), line.data()); return false; } @@ -599,13 +599,13 @@ bool OtaUpdateManager::TryGetFirmwareRelease(const OpenShock::SemVer& version, F } if (hash.size() != 64) { - ESP_LOGE(TAG, "Invalid hash: %.*s", hash.size(), hash.data()); + OS_LOGE(TAG, "Invalid hash: %.*s", hash.size(), hash.data()); return false; } if (file == "app.bin") { if (foundAppHash) { - ESP_LOGE(TAG, "Duplicate hash for app.bin"); + OS_LOGE(TAG, "Duplicate hash for app.bin"); return false; } @@ -616,7 +616,7 @@ bool OtaUpdateManager::TryGetFirmwareRelease(const OpenShock::SemVer& version, F foundAppHash = true; } else if (file == "staticfs.bin") { if (foundFilesystemHash) { - ESP_LOGE(TAG, "Duplicate hash for staticfs.bin"); + OS_LOGE(TAG, "Duplicate hash for staticfs.bin"); return false; } @@ -632,7 +632,7 @@ bool OtaUpdateManager::TryGetFirmwareRelease(const OpenShock::SemVer& version, F } bool OtaUpdateManager::TryStartFirmwareInstallation(const OpenShock::SemVer& version) { - ESP_LOGD(TAG, "Requesting firmware version %s", version.toString().c_str()); // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this + OS_LOGD(TAG, "Requesting firmware version %s", version.toString().c_str()); // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this return _tryQueueUpdateRequest(version); } @@ -648,25 +648,25 @@ bool OtaUpdateManager::IsValidatingApp() { void OtaUpdateManager::InvalidateAndRollback() { // Set OTA boot type in config. if (!Config::SetOtaUpdateStep(OpenShock::OtaUpdateStep::RollingBack)) { - ESP_PANIC(TAG, "Failed to set OTA firmware boot type in critical section"); // TODO: THIS IS A CRITICAL SECTION, WHAT DO WE DO? + OS_PANIC(TAG, "Failed to set OTA firmware boot type in critical section"); // TODO: THIS IS A CRITICAL SECTION, WHAT DO WE DO? return; } switch (esp_ota_mark_app_invalid_rollback_and_reboot()) { case ESP_FAIL: - ESP_LOGE(TAG, "Rollback failed (ESP_FAIL)"); + OS_LOGE(TAG, "Rollback failed (ESP_FAIL)"); break; case ESP_ERR_OTA_ROLLBACK_FAILED: - ESP_LOGE(TAG, "Rollback failed (ESP_ERR_OTA_ROLLBACK_FAILED)"); + OS_LOGE(TAG, "Rollback failed (ESP_ERR_OTA_ROLLBACK_FAILED)"); break; default: - ESP_LOGE(TAG, "Rollback failed (Unknown)"); + OS_LOGE(TAG, "Rollback failed (Unknown)"); break; } // Set OTA boot type in config. if (!Config::SetOtaUpdateStep(OpenShock::OtaUpdateStep::None)) { - ESP_LOGE(TAG, "Failed to set OTA firmware boot type"); + OS_LOGE(TAG, "Failed to set OTA firmware boot type"); } esp_restart(); @@ -674,12 +674,12 @@ void OtaUpdateManager::InvalidateAndRollback() { void OtaUpdateManager::ValidateApp() { if (esp_ota_mark_app_valid_cancel_rollback() != ESP_OK) { - ESP_PANIC(TAG, "Unable to mark app as valid, WTF?"); // TODO: Wtf do we do here? + OS_PANIC(TAG, "Unable to mark app as valid, WTF?"); // TODO: Wtf do we do here? } // Set OTA boot type in config. if (!Config::SetOtaUpdateStep(OpenShock::OtaUpdateStep::Validated)) { - ESP_PANIC(TAG, "Failed to set OTA firmware boot type in critical section"); // TODO: THIS IS A CRITICAL SECTION, WHAT DO WE DO? + OS_PANIC(TAG, "Failed to set OTA firmware boot type in critical section"); // TODO: THIS IS A CRITICAL SECTION, WHAT DO WE DO? } _otaImageState = ESP_OTA_IMG_VALID; diff --git a/src/PinPatternManager.cpp b/src/PinPatternManager.cpp index 6d5d7718..37d1c11e 100644 --- a/src/PinPatternManager.cpp +++ b/src/PinPatternManager.cpp @@ -11,12 +11,12 @@ using namespace OpenShock; PinPatternManager::PinPatternManager(gpio_num_t gpioPin) : m_gpioPin(GPIO_NUM_NC), m_pattern(), m_taskHandle(nullptr), m_taskMutex(xSemaphoreCreateMutex()) { if (gpioPin == GPIO_NUM_NC) { - ESP_LOGE(TAG, "Pin is not set"); + OS_LOGE(TAG, "Pin is not set"); return; } if (!IsValidOutputPin(gpioPin)) { - ESP_LOGE(TAG, "Pin %d is not a valid output pin", gpioPin); + OS_LOGE(TAG, "Pin %d is not a valid output pin", gpioPin); return; } @@ -27,7 +27,7 @@ PinPatternManager::PinPatternManager(gpio_num_t gpioPin) : m_gpioPin(GPIO_NUM_NC config.pull_down_en = GPIO_PULLDOWN_DISABLE; config.intr_type = GPIO_INTR_DISABLE; if (gpio_config(&config) != ESP_OK) { - ESP_LOGE(TAG, "Failed to configure pin %d", gpioPin); + OS_LOGE(TAG, "Failed to configure pin %d", gpioPin); return; } @@ -57,7 +57,7 @@ void PinPatternManager::SetPattern(const State* pattern, std::size_t patternLeng // Start the task BaseType_t result = xTaskCreate(RunPattern, name, 1024, this, 1, &m_taskHandle); // PROFILED: 0.5KB stack usage if (result != pdPASS) { - ESP_LOGE(TAG, "[pin-%u] Failed to create task: %d", m_gpioPin, result); + OS_LOGE(TAG, "[pin-%u] Failed to create task: %d", m_gpioPin, result); m_taskHandle = nullptr; m_pattern.clear(); diff --git a/src/RGBPatternManager.cpp b/src/RGBPatternManager.cpp index eef7e8d0..6527ee55 100644 --- a/src/RGBPatternManager.cpp +++ b/src/RGBPatternManager.cpp @@ -18,23 +18,23 @@ using namespace OpenShock; RGBPatternManager::RGBPatternManager(gpio_num_t gpioPin) : m_gpioPin(GPIO_NUM_NC), m_brightness(255), m_pattern(), m_rmtHandle(nullptr), m_taskHandle(nullptr), m_taskMutex(xSemaphoreCreateMutex()) { if (gpioPin == GPIO_NUM_NC) { - ESP_LOGE(TAG, "Pin is not set"); + OS_LOGE(TAG, "Pin is not set"); return; } if (!OpenShock::IsValidOutputPin(gpioPin)) { - ESP_LOGE(TAG, "Pin %d is not a valid output pin", gpioPin); + OS_LOGE(TAG, "Pin %d is not a valid output pin", gpioPin); return; } m_rmtHandle = rmtInit(gpioPin, RMT_TX_MODE, RMT_MEM_64); if (m_rmtHandle == NULL) { - ESP_LOGE(TAG, "Failed to initialize RMT for pin %d", gpioPin); + OS_LOGE(TAG, "Failed to initialize RMT for pin %d", gpioPin); return; } float realTick = rmtSetTick(m_rmtHandle, 100.F); - ESP_LOGD(TAG, "RMT tick is %f ns for pin %d", realTick, gpioPin); + OS_LOGD(TAG, "RMT tick is %f ns for pin %d", realTick, gpioPin); SetBrightness(20); @@ -57,7 +57,7 @@ void RGBPatternManager::SetPattern(const RGBState* pattern, std::size_t patternL // Start the task BaseType_t result = TaskUtils::TaskCreateExpensive(RunPattern, TAG, 4096, this, 1, &m_taskHandle); // PROFILED: 1.7KB stack usage if (result != pdPASS) { - ESP_LOGE(TAG, "[pin-%u] Failed to create task: %d", m_gpioPin, result); + OS_LOGE(TAG, "[pin-%u] Failed to create task: %d", m_gpioPin, result); m_taskHandle = nullptr; m_pattern.clear(); diff --git a/src/ReadWriteMutex.cpp b/src/ReadWriteMutex.cpp index b9b4507a..5987f6f4 100644 --- a/src/ReadWriteMutex.cpp +++ b/src/ReadWriteMutex.cpp @@ -17,7 +17,7 @@ OpenShock::ReadWriteMutex::~ReadWriteMutex() { bool OpenShock::ReadWriteMutex::lockRead(TickType_t xTicksToWait) { if (xSemaphoreTake(m_readSem, xTicksToWait) == pdFALSE) { - ESP_LOGE(TAG, "Failed to take read semaphore"); + OS_LOGE(TAG, "Failed to take read semaphore"); return false; } @@ -35,7 +35,7 @@ bool OpenShock::ReadWriteMutex::lockRead(TickType_t xTicksToWait) { void OpenShock::ReadWriteMutex::unlockRead() { if (xSemaphoreTake(m_readSem, portMAX_DELAY) == pdFALSE) { - ESP_LOGE(TAG, "Failed to take read semaphore"); + OS_LOGE(TAG, "Failed to take read semaphore"); return; } @@ -48,7 +48,7 @@ void OpenShock::ReadWriteMutex::unlockRead() { bool OpenShock::ReadWriteMutex::lockWrite(TickType_t xTicksToWait) { if (xSemaphoreTake(m_mutex, xTicksToWait) == pdFALSE) { - ESP_LOGE(TAG, "Failed to take mutex"); + OS_LOGE(TAG, "Failed to take mutex"); return false; } diff --git a/src/SemVer.cpp b/src/SemVer.cpp index bdd2678a..35fa0609 100644 --- a/src/SemVer.cpp +++ b/src/SemVer.cpp @@ -255,7 +255,7 @@ std::string SemVer::toString() const { bool OpenShock::TryParseSemVer(StringView semverStr, SemVer& semver) { auto parts = semverStr.split('.'); if (parts.size() < 3) { - ESP_LOGE(TAG, "Must have at least 3 parts: %.*s", semverStr.length(), semverStr.data()); + OS_LOGE(TAG, "Must have at least 3 parts: %.*s", semverStr.length(), semverStr.data()); return false; } @@ -274,27 +274,27 @@ bool OpenShock::TryParseSemVer(StringView semverStr, SemVer& semver) { } if (!_tryParseU16(majorStr, semver.major)) { - ESP_LOGE(TAG, "Invalid major version: %.*s", majorStr.length(), majorStr.data()); + OS_LOGE(TAG, "Invalid major version: %.*s", majorStr.length(), majorStr.data()); return false; } if (!_tryParseU16(minorStr, semver.minor)) { - ESP_LOGE(TAG, "Invalid minor version: %.*s", minorStr.length(), minorStr.data()); + OS_LOGE(TAG, "Invalid minor version: %.*s", minorStr.length(), minorStr.data()); return false; } if (!_tryParseU16(patchStr, semver.patch)) { - ESP_LOGE(TAG, "Invalid patch version: %.*s", patchStr.length(), patchStr.data()); + OS_LOGE(TAG, "Invalid patch version: %.*s", patchStr.length(), patchStr.data()); return false; } if (!semver.prerelease.empty() && !_semverIsPrerelease(semver.prerelease)) { - ESP_LOGE(TAG, "Invalid prerelease: %s", semver.prerelease.c_str()); + OS_LOGE(TAG, "Invalid prerelease: %s", semver.prerelease.c_str()); return false; } if (!semver.build.empty() && !_semverIsBuild(semver.build)) { - ESP_LOGE(TAG, "Invalid build: %s", semver.build.c_str()); + OS_LOGE(TAG, "Invalid build: %s", semver.build.c_str()); return false; } diff --git a/src/VisualStateManager.cpp b/src/VisualStateManager.cpp index 1a880343..b35798f2 100644 --- a/src/VisualStateManager.cpp +++ b/src/VisualStateManager.cpp @@ -243,7 +243,7 @@ void _updateVisualState() { return; } - ESP_LOGW(TAG, "Trying to update visual state, but no LED is active!"); + OS_LOGW(TAG, "Trying to update visual state, but no LED is active!"); } void _handleWiFiConnected(arduino_event_t* event) { @@ -293,7 +293,7 @@ bool VisualStateManager::Init() { if (OPENSHOCK_LED_GPIO != GPIO_NUM_NC) { s_builtInLedManager = std::make_shared(static_cast(OPENSHOCK_LED_GPIO)); if (!s_builtInLedManager->IsValid()) { - ESP_LOGE(TAG, "Failed to initialize built-in LED manager"); + OS_LOGE(TAG, "Failed to initialize built-in LED manager"); return false; } ledActive = true; @@ -302,14 +302,14 @@ bool VisualStateManager::Init() { if (OPENSHOCK_LED_WS2812B != GPIO_NUM_NC) { s_RGBLedManager = std::make_shared(static_cast(OPENSHOCK_LED_WS2812B)); if (!s_RGBLedManager->IsValid()) { - ESP_LOGE(TAG, "Failed to initialize RGB LED manager"); + OS_LOGE(TAG, "Failed to initialize RGB LED manager"); return false; } ledActive = true; } if (!ledActive) { - ESP_LOGW(TAG, "No LED type is defined, aborting initialization of VisualStateManager"); + OS_LOGW(TAG, "No LED type is defined, aborting initialization of VisualStateManager"); return true; } diff --git a/src/WebSocketDeFragger.cpp b/src/WebSocketDeFragger.cpp index ca0f635c..2106d885 100644 --- a/src/WebSocketDeFragger.cpp +++ b/src/WebSocketDeFragger.cpp @@ -12,7 +12,7 @@ uint8_t* _reallocOrFree(uint8_t* ptr, std::size_t size) { void* newPtr = realloc(ptr, size); if (newPtr == nullptr) { free(ptr); - ESP_PANIC(TAG, "Failed to allocate memory"); + OS_PANIC(TAG, "Failed to allocate memory"); } return reinterpret_cast(newPtr); diff --git a/src/config/BackendConfig.cpp b/src/config/BackendConfig.cpp index f0084640..e004f2a2 100644 --- a/src/config/BackendConfig.cpp +++ b/src/config/BackendConfig.cpp @@ -18,7 +18,7 @@ void BackendConfig::ToDefault() { bool BackendConfig::FromFlatbuffers(const Serialization::Configuration::BackendConfig* config) { if (config == nullptr) { - ESP_LOGE(TAG, "config is null"); + OS_LOGE(TAG, "config is null"); return false; } @@ -46,12 +46,12 @@ flatbuffers::Offset Back bool BackendConfig::FromJSON(const cJSON* json) { if (json == nullptr) { - ESP_LOGE(TAG, "json is null"); + OS_LOGE(TAG, "json is null"); return false; } if (cJSON_IsObject(json) == 0) { - ESP_LOGE(TAG, "json is not an object"); + OS_LOGE(TAG, "json is not an object"); return false; } diff --git a/src/config/CaptivePortalConfig.cpp b/src/config/CaptivePortalConfig.cpp index 617eb513..2ef1bfe6 100644 --- a/src/config/CaptivePortalConfig.cpp +++ b/src/config/CaptivePortalConfig.cpp @@ -19,7 +19,7 @@ void CaptivePortalConfig::ToDefault() { bool CaptivePortalConfig::FromFlatbuffers(const Serialization::Configuration::CaptivePortalConfig* config) { if (config == nullptr) { - ESP_LOGE(TAG, "config is null"); + OS_LOGE(TAG, "config is null"); return false; } @@ -34,12 +34,12 @@ flatbuffers::Offset(buffer); if (fbsConfig == nullptr) { - ESP_LOGE(TAG, "Failed to get deserialization root for config file"); + OS_LOGE(TAG, "Failed to get deserialization root for config file"); return false; } @@ -58,13 +58,13 @@ bool _tryDeserializeConfig(const uint8_t* buffer, std::size_t bufferLen, OpenSho }; flatbuffers::Verifier verifier(buffer, bufferLen, verifierOptions); if (!fbsConfig->Verify(verifier)) { - ESP_LOGE(TAG, "Failed to verify config file integrity"); + OS_LOGE(TAG, "Failed to verify config file integrity"); return false; } // Read config if (!config.FromFlatbuffers(fbsConfig)) { - ESP_LOGE(TAG, "Failed to read config file"); + OS_LOGE(TAG, "Failed to read config file"); return false; } @@ -73,7 +73,7 @@ bool _tryDeserializeConfig(const uint8_t* buffer, std::size_t bufferLen, OpenSho bool _tryLoadConfig(std::vector& buffer) { File file = _configFS.open("/config", "rb"); if (!file) { - ESP_LOGE(TAG, "Failed to open config file for reading"); + OS_LOGE(TAG, "Failed to open config file for reading"); return false; } @@ -85,7 +85,7 @@ bool _tryLoadConfig(std::vector& buffer) { // Read file if (file.read(buffer.data(), buffer.size()) != buffer.size()) { - ESP_LOGE(TAG, "Failed to read config file, size mismatch"); + OS_LOGE(TAG, "Failed to read config file, size mismatch"); return false; } @@ -104,13 +104,13 @@ bool _tryLoadConfig() { bool _trySaveConfig(const uint8_t* data, std::size_t dataLen) { File file = _configFS.open("/config", "wb"); if (!file) { - ESP_LOGE(TAG, "Failed to open config file for writing"); + OS_LOGE(TAG, "Failed to open config file for writing"); return false; } // Write file if (file.write(data, dataLen) != dataLen) { - ESP_LOGE(TAG, "Failed to write config file"); + OS_LOGE(TAG, "Failed to write config file"); return false; } @@ -132,19 +132,19 @@ void Config::Init() { CONFIG_LOCK_WRITE(); if (!_configFS.begin(true, "/config", 3, "config")) { - ESP_PANIC(TAG, "Unable to mount config LittleFS partition!"); + OS_PANIC(TAG, "Unable to mount config LittleFS partition!"); } if (_tryLoadConfig()) { return; } - ESP_LOGW(TAG, "Failed to load config, writing default config"); + OS_LOGW(TAG, "Failed to load config, writing default config"); _configData.ToDefault(); if (!_trySaveConfig()) { - ESP_PANIC(TAG, "Failed to save default config. Recommend formatting microcontroller and re-flashing firmware"); + OS_PANIC(TAG, "Failed to save default config. Recommend formatting microcontroller and re-flashing firmware"); } } @@ -170,7 +170,7 @@ std::string Config::GetAsJSON(bool withSensitiveData) { bool Config::SaveFromJSON(StringView json) { cJSON* root = cJSON_ParseWithLength(json.data(), json.size()); if (root == nullptr) { - ESP_LOGE(TAG, "Failed to parse JSON: %s", cJSON_GetErrorPtr()); + OS_LOGE(TAG, "Failed to parse JSON: %s", cJSON_GetErrorPtr()); return false; } @@ -181,7 +181,7 @@ bool Config::SaveFromJSON(StringView json) { cJSON_Delete(root); if (!result) { - ESP_LOGE(TAG, "Failed to read JSON"); + OS_LOGE(TAG, "Failed to read JSON"); return false; } @@ -198,7 +198,7 @@ bool Config::SaveFromFlatBuffer(const Serialization::Configuration::HubConfig* c CONFIG_LOCK_WRITE(false); if (!_configData.FromFlatbuffers(config)) { - ESP_LOGE(TAG, "Failed to read config file"); + OS_LOGE(TAG, "Failed to read config file"); return false; } @@ -216,7 +216,7 @@ bool Config::SetRaw(const uint8_t* buffer, std::size_t size) { OpenShock::Config::RootConfig config; if (!_tryDeserializeConfig(buffer, size, config)) { - ESP_LOGE(TAG, "Failed to deserialize config"); + OS_LOGE(TAG, "Failed to deserialize config"); return false; } @@ -229,14 +229,14 @@ void Config::FactoryReset() { _configData.ToDefault(); if (!_configFS.remove("/config") && _configFS.exists("/config")) { - ESP_PANIC(TAG, "Failed to remove existing config file for factory reset. Reccomend formatting microcontroller and re-flashing firmware"); + OS_PANIC(TAG, "Failed to remove existing config file for factory reset. Reccomend formatting microcontroller and re-flashing firmware"); } if (!_trySaveConfig()) { - ESP_PANIC(TAG, "Failed to save default config. Recommend formatting microcontroller and re-flashing firmware"); + OS_PANIC(TAG, "Failed to save default config. Recommend formatting microcontroller and re-flashing firmware"); } - ESP_LOGI(TAG, "Factory reset complete"); + OS_LOGI(TAG, "Factory reset complete"); } bool Config::GetRFConfig(Config::RFConfig& out) { @@ -300,7 +300,7 @@ bool Config::SetWiFiConfig(const Config::WiFiConfig& config) { bool Config::SetWiFiCredentials(const std::vector& credentials) { bool foundZeroId = std::any_of(credentials.begin(), credentials.end(), [](const Config::WiFiCredentials& creds) { return creds.id == 0; }); if (foundZeroId) { - ESP_LOGE(TAG, "Cannot set WiFi credentials: credential ID cannot be 0"); + OS_LOGE(TAG, "Cannot set WiFi credentials: credential ID cannot be 0"); return false; } @@ -401,7 +401,7 @@ uint8_t Config::AddWiFiCredentials(StringView ssid, StringView password) { } if (creds.id == 0) { - ESP_LOGW(TAG, "Found WiFi credentials with ID 0, removing"); + OS_LOGW(TAG, "Found WiFi credentials with ID 0, removing"); it = _configData.wifi.credentialsList.erase(it); continue; } @@ -419,7 +419,7 @@ uint8_t Config::AddWiFiCredentials(StringView ssid, StringView password) { } if (id == 0) { - ESP_LOGE(TAG, "Failed to add WiFi credentials: no available IDs"); + OS_LOGE(TAG, "Failed to add WiFi credentials: no available IDs"); return 0; } diff --git a/src/config/OtaUpdateConfig.cpp b/src/config/OtaUpdateConfig.cpp index a3dbcbdb..13582260 100644 --- a/src/config/OtaUpdateConfig.cpp +++ b/src/config/OtaUpdateConfig.cpp @@ -50,7 +50,7 @@ void OtaUpdateConfig::ToDefault() { bool OtaUpdateConfig::FromFlatbuffers(const Serialization::Configuration::OtaUpdateConfig* config) { if (config == nullptr) { - ESP_LOGE(TAG, "config is null"); + OS_LOGE(TAG, "config is null"); return false; } @@ -74,12 +74,12 @@ flatbuffers::Offset Ot bool OtaUpdateConfig::FromJSON(const cJSON* json) { if (json == nullptr) { - ESP_LOGE(TAG, "json is null"); + OS_LOGE(TAG, "json is null"); return false; } if (!cJSON_IsObject(json)) { - ESP_LOGE(TAG, "json is not an object"); + OS_LOGE(TAG, "json is not an object"); return false; } diff --git a/src/config/RFConfig.cpp b/src/config/RFConfig.cpp index 91b952c6..1d30bf0d 100644 --- a/src/config/RFConfig.cpp +++ b/src/config/RFConfig.cpp @@ -19,7 +19,7 @@ void RFConfig::ToDefault() { bool RFConfig::FromFlatbuffers(const Serialization::Configuration::RFConfig* config) { if (config == nullptr) { - ESP_LOGE(TAG, "config is null"); + OS_LOGE(TAG, "config is null"); return false; } @@ -35,12 +35,12 @@ flatbuffers::Offset RFConfig: bool RFConfig::FromJSON(const cJSON* json) { if (json == nullptr) { - ESP_LOGE(TAG, "json is null"); + OS_LOGE(TAG, "json is null"); return false; } if (cJSON_IsObject(json) == 0) { - ESP_LOGE(TAG, "json is not an object"); + OS_LOGE(TAG, "json is not an object"); return false; } diff --git a/src/config/RootConfig.cpp b/src/config/RootConfig.cpp index 14cc0302..14cf5d72 100644 --- a/src/config/RootConfig.cpp +++ b/src/config/RootConfig.cpp @@ -17,37 +17,37 @@ void RootConfig::ToDefault() { bool RootConfig::FromFlatbuffers(const Serialization::Configuration::HubConfig* config) { if (config == nullptr) { - ESP_LOGE(TAG, "config is null"); + OS_LOGE(TAG, "config is null"); return false; } if (!rf.FromFlatbuffers(config->rf())) { - ESP_LOGE(TAG, "Unable to load rf config"); + OS_LOGE(TAG, "Unable to load rf config"); return false; } if (!wifi.FromFlatbuffers(config->wifi())) { - ESP_LOGE(TAG, "Unable to load wifi config"); + OS_LOGE(TAG, "Unable to load wifi config"); return false; } if (!captivePortal.FromFlatbuffers(config->captive_portal())) { - ESP_LOGE(TAG, "Unable to load captive portal config"); + OS_LOGE(TAG, "Unable to load captive portal config"); return false; } if (!backend.FromFlatbuffers(config->backend())) { - ESP_LOGE(TAG, "Unable to load backend config"); + OS_LOGE(TAG, "Unable to load backend config"); return false; } if (!serialInput.FromFlatbuffers(config->serial_input())) { - ESP_LOGE(TAG, "Unable to load serial input config"); + OS_LOGE(TAG, "Unable to load serial input config"); return false; } if (!otaUpdate.FromFlatbuffers(config->ota_update())) { - ESP_LOGE(TAG, "Unable to load ota update config"); + OS_LOGE(TAG, "Unable to load ota update config"); return false; } @@ -67,42 +67,42 @@ flatbuffers::Offset RootConf bool RootConfig::FromJSON(const cJSON* json) { if (json == nullptr) { - ESP_LOGE(TAG, "json is null"); + OS_LOGE(TAG, "json is null"); return false; } if (cJSON_IsObject(json) == 0) { - ESP_LOGE(TAG, "json is not an object"); + OS_LOGE(TAG, "json is not an object"); return false; } if (!rf.FromJSON(cJSON_GetObjectItemCaseSensitive(json, "rf"))) { - ESP_LOGE(TAG, "Unable to load rf config"); + OS_LOGE(TAG, "Unable to load rf config"); return false; } if (!wifi.FromJSON(cJSON_GetObjectItemCaseSensitive(json, "wifi"))) { - ESP_LOGE(TAG, "Unable to load wifi config"); + OS_LOGE(TAG, "Unable to load wifi config"); return false; } if (!captivePortal.FromJSON(cJSON_GetObjectItemCaseSensitive(json, "captivePortal"))) { - ESP_LOGE(TAG, "Unable to load captive portal config"); + OS_LOGE(TAG, "Unable to load captive portal config"); return false; } if (!backend.FromJSON(cJSON_GetObjectItemCaseSensitive(json, "backend"))) { - ESP_LOGE(TAG, "Unable to load backend config"); + OS_LOGE(TAG, "Unable to load backend config"); return false; } if (!serialInput.FromJSON(cJSON_GetObjectItemCaseSensitive(json, "serialInput"))) { - ESP_LOGE(TAG, "Unable to load serial input config"); + OS_LOGE(TAG, "Unable to load serial input config"); return false; } if (!otaUpdate.FromJSON(cJSON_GetObjectItemCaseSensitive(json, "otaUpdate"))) { - ESP_LOGE(TAG, "Unable to load ota update config"); + OS_LOGE(TAG, "Unable to load ota update config"); return false; } diff --git a/src/config/SerialInputConfig.cpp b/src/config/SerialInputConfig.cpp index 6411b1c8..ee2f67c6 100644 --- a/src/config/SerialInputConfig.cpp +++ b/src/config/SerialInputConfig.cpp @@ -19,7 +19,7 @@ void SerialInputConfig::ToDefault() { bool SerialInputConfig::FromFlatbuffers(const Serialization::Configuration::SerialInputConfig* config) { if (config == nullptr) { - ESP_LOGE(TAG, "config is null"); + OS_LOGE(TAG, "config is null"); return false; } @@ -34,12 +34,12 @@ flatbuffers::Offset bool SerialInputConfig::FromJSON(const cJSON* json) { if (json == nullptr) { - ESP_LOGE(TAG, "json is null"); + OS_LOGE(TAG, "json is null"); return false; } if (cJSON_IsObject(json) == 0) { - ESP_LOGE(TAG, "json is not an object"); + OS_LOGE(TAG, "json is not an object"); return false; } diff --git a/src/config/WiFiConfig.cpp b/src/config/WiFiConfig.cpp index 9c6e6d64..1fb8b00b 100644 --- a/src/config/WiFiConfig.cpp +++ b/src/config/WiFiConfig.cpp @@ -19,7 +19,7 @@ void WiFiConfig::ToDefault() { bool WiFiConfig::FromFlatbuffers(const Serialization::Configuration::WiFiConfig* config) { if (config == nullptr) { - ESP_LOGE(TAG, "config is null"); + OS_LOGE(TAG, "config is null"); return false; } @@ -43,12 +43,12 @@ flatbuffers::Offset WiFiCon bool WiFiConfig::FromJSON(const cJSON* json) { if (json == nullptr) { - ESP_LOGE(TAG, "json is null"); + OS_LOGE(TAG, "json is null"); return false; } if (cJSON_IsObject(json) == 0) { - ESP_LOGE(TAG, "json is not an object"); + OS_LOGE(TAG, "json is not an object"); return false; } @@ -57,12 +57,12 @@ bool WiFiConfig::FromJSON(const cJSON* json) { const cJSON* credentialsListJson = cJSON_GetObjectItemCaseSensitive(json, "credentials"); if (credentialsListJson == nullptr) { - ESP_LOGE(TAG, "credentials is null"); + OS_LOGE(TAG, "credentials is null"); return false; } if (cJSON_IsArray(credentialsListJson) == 0) { - ESP_LOGE(TAG, "credentials is not an array"); + OS_LOGE(TAG, "credentials is not an array"); return false; } diff --git a/src/config/WiFiCredentials.cpp b/src/config/WiFiCredentials.cpp index 39561194..836c6afb 100644 --- a/src/config/WiFiCredentials.cpp +++ b/src/config/WiFiCredentials.cpp @@ -20,7 +20,7 @@ void WiFiCredentials::ToDefault() { bool WiFiCredentials::FromFlatbuffers(const Serialization::Configuration::WiFiCredentials* config) { if (config == nullptr) { - ESP_LOGE(TAG, "config is null"); + OS_LOGE(TAG, "config is null"); return false; } @@ -29,7 +29,7 @@ bool WiFiCredentials::FromFlatbuffers(const Serialization::Configuration::WiFiCr Internal::Utils::FromFbsStr(password, config->password(), ""); if (ssid.empty()) { - ESP_LOGE(TAG, "ssid is empty"); + OS_LOGE(TAG, "ssid is empty"); return false; } @@ -51,12 +51,12 @@ flatbuffers::Offset Wi bool WiFiCredentials::FromJSON(const cJSON* json) { if (json == nullptr) { - ESP_LOGE(TAG, "json is null"); + OS_LOGE(TAG, "json is null"); return false; } if (cJSON_IsObject(json) == 0) { - ESP_LOGE(TAG, "json is not an object"); + OS_LOGE(TAG, "json is not an object"); return false; } @@ -65,7 +65,7 @@ bool WiFiCredentials::FromJSON(const cJSON* json) { Internal::Utils::FromJsonStr(password, json, "password", ""); if (ssid.empty()) { - ESP_LOGE(TAG, "ssid is empty"); + OS_LOGE(TAG, "ssid is empty"); return false; } diff --git a/src/config/internal/utils.cpp b/src/config/internal/utils.cpp index d0f7ab28..69d3f916 100644 --- a/src/config/internal/utils.cpp +++ b/src/config/internal/utils.cpp @@ -18,19 +18,19 @@ bool _utilFromJsonInt(T& val, const cJSON* json, const char* name, T defaultVal, } if (cJSON_IsNumber(jsonVal) == 0) { - ESP_LOGE(TAG, "value at '%s' is not a number", name); + OS_LOGE(TAG, "value at '%s' is not a number", name); return false; } int intVal = jsonVal->valueint; if (intVal < minVal) { - ESP_LOGE(TAG, "value at '%s' is less than %d", name, minVal); + OS_LOGE(TAG, "value at '%s' is less than %d", name, minVal); return false; } if (intVal > maxVal) { - ESP_LOGE(TAG, "value at '%s' is greater than %d", name, maxVal); + OS_LOGE(TAG, "value at '%s' is greater than %d", name, maxVal); return false; } @@ -49,14 +49,14 @@ void Config::Internal::Utils::FromFbsStr(std::string& str, const flatbuffers::St bool Config::Internal::Utils::FromFbsIPAddress(IPAddress& ip, const flatbuffers::String* fbsIP, const IPAddress& defaultIP) { if (fbsIP == nullptr) { - ESP_LOGE(TAG, "IP address is null"); + OS_LOGE(TAG, "IP address is null"); return false; } StringView view(*fbsIP); if (!OpenShock::IPV4AddressFromStringView(ip, view)) { - ESP_LOGE(TAG, "failed to parse IP address"); + OS_LOGE(TAG, "failed to parse IP address"); return false; } @@ -71,7 +71,7 @@ bool Config::Internal::Utils::FromJsonBool(bool& val, const cJSON* json, const c } if (cJSON_IsBool(jsonVal) == 0) { - ESP_LOGE(TAG, "value at '%s' is not a bool", name); + OS_LOGE(TAG, "value at '%s' is not a bool", name); return false; } @@ -100,7 +100,7 @@ bool Config::Internal::Utils::FromJsonStr(std::string& str, const cJSON* json, c } if (cJSON_IsString(jsonVal) == 0) { - ESP_LOGE(TAG, "value at '%s' is not a string", name); + OS_LOGE(TAG, "value at '%s' is not a string", name); return false; } @@ -112,19 +112,19 @@ bool Config::Internal::Utils::FromJsonStr(std::string& str, const cJSON* json, c bool Config::Internal::Utils::FromJsonIPAddress(IPAddress& ip, const cJSON* json, const char* name, const IPAddress& defaultIP) { const cJSON* jsonVal = cJSON_GetObjectItemCaseSensitive(json, name); if (jsonVal == nullptr) { - ESP_LOGE(TAG, "value at '%s' is null", name); + OS_LOGE(TAG, "value at '%s' is null", name); return false; } if (cJSON_IsString(jsonVal) == 0) { - ESP_LOGE(TAG, "value at '%s' is not a string", name); + OS_LOGE(TAG, "value at '%s' is not a string", name); return false; } StringView view(jsonVal->valuestring); if (!OpenShock::IPV4AddressFromStringView(ip, view)) { - ESP_LOGE(TAG, "failed to parse IP address at '%s'", name); + OS_LOGE(TAG, "failed to parse IP address at '%s'", name); return false; } diff --git a/src/event_handlers/websocket/Gateway.cpp b/src/event_handlers/websocket/Gateway.cpp index 926826b0..1be52a78 100644 --- a/src/event_handlers/websocket/Gateway.cpp +++ b/src/event_handlers/websocket/Gateway.cpp @@ -38,7 +38,7 @@ void EventHandlers::WebSocket::HandleGatewayBinary(const uint8_t* data, std::siz // Deserialize auto msg = flatbuffers::GetRoot(data); if (msg == nullptr) { - ESP_LOGE(TAG, "Failed to deserialize message"); + OS_LOGE(TAG, "Failed to deserialize message"); return; } @@ -48,7 +48,7 @@ void EventHandlers::WebSocket::HandleGatewayBinary(const uint8_t* data, std::siz }; flatbuffers::Verifier verifier(data, len, verifierOptions); if (!msg->Verify(verifier)) { - ESP_LOGE(TAG, "Failed to verify message"); + OS_LOGE(TAG, "Failed to verify message"); return; } diff --git a/src/event_handlers/websocket/Local.cpp b/src/event_handlers/websocket/Local.cpp index c0521e2a..adbe664a 100644 --- a/src/event_handlers/websocket/Local.cpp +++ b/src/event_handlers/websocket/Local.cpp @@ -42,7 +42,7 @@ void EventHandlers::WebSocket::HandleLocalBinary(uint8_t socketId, const uint8_t // Deserialize auto msg = flatbuffers::GetRoot(data); if (msg == nullptr) { - ESP_LOGE(TAG, "Failed to deserialize message"); + OS_LOGE(TAG, "Failed to deserialize message"); return; } @@ -52,7 +52,7 @@ void EventHandlers::WebSocket::HandleLocalBinary(uint8_t socketId, const uint8_t }; flatbuffers::Verifier verifier(data, len, verifierOptions); if (!msg->Verify(verifier)) { - ESP_LOGE(TAG, "Failed to verify message"); + OS_LOGE(TAG, "Failed to verify message"); return; } diff --git a/src/event_handlers/websocket/gateway/CaptivePortalConfig.cpp b/src/event_handlers/websocket/gateway/CaptivePortalConfig.cpp index 1403659b..f30327c4 100644 --- a/src/event_handlers/websocket/gateway/CaptivePortalConfig.cpp +++ b/src/event_handlers/websocket/gateway/CaptivePortalConfig.cpp @@ -12,13 +12,13 @@ using namespace OpenShock::MessageHandlers::Server; void _Private::HandleCaptivePortalConfig(const OpenShock::Serialization::Gateway::GatewayToHubMessage* root) { auto msg = root->payload_as_CaptivePortalConfig(); if (msg == nullptr) { - ESP_LOGE(TAG, "Payload cannot be parsed as CaptivePortalConfig"); + OS_LOGE(TAG, "Payload cannot be parsed as CaptivePortalConfig"); return; } bool enabled = msg->enabled(); - ESP_LOGD(TAG, "Captive portal is %s", enabled ? "force enabled" : "normal"); + OS_LOGD(TAG, "Captive portal is %s", enabled ? "force enabled" : "normal"); OpenShock::CaptivePortal::SetAlwaysEnabled(enabled); } diff --git a/src/event_handlers/websocket/gateway/OtaInstall.cpp b/src/event_handlers/websocket/gateway/OtaInstall.cpp index 9b397e10..175ec29b 100644 --- a/src/event_handlers/websocket/gateway/OtaInstall.cpp +++ b/src/event_handlers/websocket/gateway/OtaInstall.cpp @@ -13,13 +13,13 @@ using namespace OpenShock::MessageHandlers::Server; void _Private::HandleOtaInstall(const OpenShock::Serialization::Gateway::GatewayToHubMessage* root) { auto msg = root->payload_as_OtaInstall(); if (msg == nullptr) { - ESP_LOGE(TAG, "Payload cannot be parsed as OtaInstall"); + OS_LOGE(TAG, "Payload cannot be parsed as OtaInstall"); return; } auto semver = msg->version(); if (semver == nullptr) { - ESP_LOGE(TAG, "Version cannot be parsed"); + OS_LOGE(TAG, "Version cannot be parsed"); return; } @@ -33,10 +33,10 @@ void _Private::HandleOtaInstall(const OpenShock::Serialization::Gateway::Gateway OpenShock::SemVer version(semver->major(), semver->minor(), semver->patch(), prerelease, build); - ESP_LOGI(TAG, "OTA install requested for version %s", version.toString().c_str()); // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this + OS_LOGI(TAG, "OTA install requested for version %s", version.toString().c_str()); // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this if (!OpenShock::OtaUpdateManager::TryStartFirmwareInstallation(version)) { - ESP_LOGE(TAG, "Failed to install firmware"); // TODO: Send error message to server + OS_LOGE(TAG, "Failed to install firmware"); // TODO: Send error message to server return; } } diff --git a/src/event_handlers/websocket/gateway/ShockerCommandList.cpp b/src/event_handlers/websocket/gateway/ShockerCommandList.cpp index 550f4a7d..620cf07f 100644 --- a/src/event_handlers/websocket/gateway/ShockerCommandList.cpp +++ b/src/event_handlers/websocket/gateway/ShockerCommandList.cpp @@ -13,17 +13,17 @@ using namespace OpenShock::MessageHandlers::Server; void _Private::HandleShockerCommandList(const OpenShock::Serialization::Gateway::GatewayToHubMessage* root) { auto msg = root->payload_as_ShockerCommandList(); if (msg == nullptr) { - ESP_LOGE(TAG, "Payload cannot be parsed as ShockerCommandList"); + OS_LOGE(TAG, "Payload cannot be parsed as ShockerCommandList"); return; } auto commands = msg->commands(); if (commands == nullptr) { - ESP_LOGE(TAG, "Received invalid command list from API"); + OS_LOGE(TAG, "Received invalid command list from API"); return; } - ESP_LOGV(TAG, "Received command list from API (%u commands)", commands->size()); + OS_LOGV(TAG, "Received command list from API (%u commands)", commands->size()); for (auto command : *commands) { uint16_t id = command->id(); @@ -35,10 +35,10 @@ void _Private::HandleShockerCommandList(const OpenShock::Serialization::Gateway: const char* modelStr = OpenShock::Serialization::Types::EnumNameShockerModelType(model); const char* typeStr = OpenShock::Serialization::Types::EnumNameShockerCommandType(type); - ESP_LOGV(TAG, " ID %u, Intensity %u, Duration %u, Model %s, Type %s", id, intensity, durationMs, modelStr, typeStr); + OS_LOGV(TAG, " ID %u, Intensity %u, Duration %u, Model %s, Type %s", id, intensity, durationMs, modelStr, typeStr); if (!OpenShock::CommandHandler::HandleCommand(model, id, type, intensity, durationMs)) { - ESP_LOGE(TAG, "Remote command failed/rejected!"); + OS_LOGE(TAG, "Remote command failed/rejected!"); } } } diff --git a/src/event_handlers/websocket/gateway/_InvalidMessage.cpp b/src/event_handlers/websocket/gateway/_InvalidMessage.cpp index 1cc55353..d6ff4754 100644 --- a/src/event_handlers/websocket/gateway/_InvalidMessage.cpp +++ b/src/event_handlers/websocket/gateway/_InvalidMessage.cpp @@ -8,9 +8,9 @@ using namespace OpenShock::MessageHandlers::Server; void _Private::HandleInvalidMessage(const OpenShock::Serialization::Gateway::GatewayToHubMessage* root) { if (root == nullptr) { - ESP_LOGE(TAG, "Message cannot be parsed"); + OS_LOGE(TAG, "Message cannot be parsed"); return; } - ESP_LOGE(TAG, "Invalid message type: %u", root->payload_type()); + OS_LOGE(TAG, "Invalid message type: %u", root->payload_type()); } diff --git a/src/event_handlers/websocket/local/AccountLinkCommand.cpp b/src/event_handlers/websocket/local/AccountLinkCommand.cpp index bd726394..d71f4aad 100644 --- a/src/event_handlers/websocket/local/AccountLinkCommand.cpp +++ b/src/event_handlers/websocket/local/AccountLinkCommand.cpp @@ -28,7 +28,7 @@ using namespace OpenShock::MessageHandlers::Local; void _Private::HandleAccountLinkCommand(uint8_t socketId, const OpenShock::Serialization::Local::LocalToHubMessage* root) { auto msg = root->payload_as_AccountLinkCommand(); if (msg == nullptr) { - ESP_LOGE(TAG, "Payload cannot be parsed as AccountLinkCommand"); + OS_LOGE(TAG, "Payload cannot be parsed as AccountLinkCommand"); return; } diff --git a/src/event_handlers/websocket/local/AccountUnlinkCommand.cpp b/src/event_handlers/websocket/local/AccountUnlinkCommand.cpp index e5315b32..1d91902f 100644 --- a/src/event_handlers/websocket/local/AccountUnlinkCommand.cpp +++ b/src/event_handlers/websocket/local/AccountUnlinkCommand.cpp @@ -14,7 +14,7 @@ void _Private::HandleAccountUnlinkCommand(uint8_t socketId, const OpenShock::Ser auto msg = root->payload_as_AccountUnlinkCommand(); if (msg == nullptr) { - ESP_LOGE(TAG, "Payload cannot be parsed as AccountUnlinkCommand"); + OS_LOGE(TAG, "Payload cannot be parsed as AccountUnlinkCommand"); return; } diff --git a/src/event_handlers/websocket/local/SetRfTxPinCommand.cpp b/src/event_handlers/websocket/local/SetRfTxPinCommand.cpp index 00ca23ff..8f869a2c 100644 --- a/src/event_handlers/websocket/local/SetRfTxPinCommand.cpp +++ b/src/event_handlers/websocket/local/SetRfTxPinCommand.cpp @@ -29,7 +29,7 @@ using namespace OpenShock::MessageHandlers::Local; void _Private::HandleSetRfTxPinCommand(uint8_t socketId, const OpenShock::Serialization::Local::LocalToHubMessage* root) { auto msg = root->payload_as_SetRfTxPinCommand(); if (msg == nullptr) { - ESP_LOGE(TAG, "Payload cannot be parsed as SetRfTxPinCommand"); + OS_LOGE(TAG, "Payload cannot be parsed as SetRfTxPinCommand"); return; } diff --git a/src/event_handlers/websocket/local/WiFiNetworkConnectCommand.cpp b/src/event_handlers/websocket/local/WiFiNetworkConnectCommand.cpp index 0c568772..80bb0029 100644 --- a/src/event_handlers/websocket/local/WiFiNetworkConnectCommand.cpp +++ b/src/event_handlers/websocket/local/WiFiNetworkConnectCommand.cpp @@ -15,23 +15,23 @@ void _Private::HandleWiFiNetworkConnectCommand(uint8_t socketId, const OpenShock auto msg = root->payload_as_WifiNetworkConnectCommand(); if (msg == nullptr) { - ESP_LOGE(TAG, "Payload cannot be parsed as WiFiNetworkConnectCommand"); + OS_LOGE(TAG, "Payload cannot be parsed as WiFiNetworkConnectCommand"); return; } auto ssid = msg->ssid(); if (ssid == nullptr) { - ESP_LOGE(TAG, "WiFi message is missing required properties"); + OS_LOGE(TAG, "WiFi message is missing required properties"); return; } if (ssid->size() > 31) { - ESP_LOGE(TAG, "WiFi SSID is too long"); + OS_LOGE(TAG, "WiFi SSID is too long"); return; } if (!WiFiManager::Connect(ssid->c_str())) { // TODO: support hidden networks - ESP_LOGE(TAG, "Failed to connect to WiFi network"); + OS_LOGE(TAG, "Failed to connect to WiFi network"); } } diff --git a/src/event_handlers/websocket/local/WiFiNetworkDisconnectCommand.cpp b/src/event_handlers/websocket/local/WiFiNetworkDisconnectCommand.cpp index f6435c64..52b309fd 100644 --- a/src/event_handlers/websocket/local/WiFiNetworkDisconnectCommand.cpp +++ b/src/event_handlers/websocket/local/WiFiNetworkDisconnectCommand.cpp @@ -15,7 +15,7 @@ void _Private::HandleWiFiNetworkDisconnectCommand(uint8_t socketId, const OpenSh auto msg = root->payload_as_WifiNetworkDisconnectCommand(); if (msg == nullptr) { - ESP_LOGE(TAG, "Payload cannot be parsed as WiFiNetworkDisconnectCommand"); + OS_LOGE(TAG, "Payload cannot be parsed as WiFiNetworkDisconnectCommand"); return; } diff --git a/src/event_handlers/websocket/local/WiFiNetworkForgetCommand.cpp b/src/event_handlers/websocket/local/WiFiNetworkForgetCommand.cpp index a8c4afe8..6cd1db1c 100644 --- a/src/event_handlers/websocket/local/WiFiNetworkForgetCommand.cpp +++ b/src/event_handlers/websocket/local/WiFiNetworkForgetCommand.cpp @@ -15,23 +15,23 @@ void _Private::HandleWiFiNetworkForgetCommand(uint8_t socketId, const OpenShock: auto msg = root->payload_as_WifiNetworkForgetCommand(); if (msg == nullptr) { - ESP_LOGE(TAG, "Payload cannot be parsed as WiFiNetworkForgetCommand"); + OS_LOGE(TAG, "Payload cannot be parsed as WiFiNetworkForgetCommand"); return; } auto ssid = msg->ssid(); if (ssid == nullptr) { - ESP_LOGE(TAG, "WiFi message is missing required properties"); + OS_LOGE(TAG, "WiFi message is missing required properties"); return; } if (ssid->size() > 31) { - ESP_LOGE(TAG, "WiFi SSID is too long"); + OS_LOGE(TAG, "WiFi SSID is too long"); return; } if (!WiFiManager::Forget(ssid->c_str())) { // TODO: support hidden networks - ESP_LOGE(TAG, "Failed to forget WiFi network"); + OS_LOGE(TAG, "Failed to forget WiFi network"); } } diff --git a/src/event_handlers/websocket/local/WiFiNetworkSaveCommand.cpp b/src/event_handlers/websocket/local/WiFiNetworkSaveCommand.cpp index a8648c14..6ddf9fba 100644 --- a/src/event_handlers/websocket/local/WiFiNetworkSaveCommand.cpp +++ b/src/event_handlers/websocket/local/WiFiNetworkSaveCommand.cpp @@ -15,7 +15,7 @@ void _Private::HandleWiFiNetworkSaveCommand(uint8_t socketId, const OpenShock::S auto msg = root->payload_as_WifiNetworkSaveCommand(); if (msg == nullptr) { - ESP_LOGE(TAG, "Payload cannot be parsed as WiFiNetworkSaveCommand"); + OS_LOGE(TAG, "Payload cannot be parsed as WiFiNetworkSaveCommand"); return; } @@ -23,28 +23,28 @@ void _Private::HandleWiFiNetworkSaveCommand(uint8_t socketId, const OpenShock::S auto password = msg->password() ? msg->password()->str() : ""; if (ssid == nullptr) { - ESP_LOGE(TAG, "WiFi message is missing SSID"); + OS_LOGE(TAG, "WiFi message is missing SSID"); return; } if (ssid->size() > 31) { - ESP_LOGE(TAG, "WiFi SSID is too long"); + OS_LOGE(TAG, "WiFi SSID is too long"); return; } std::size_t passwordLength = password.size(); if (passwordLength != 0 && passwordLength < 8) { - ESP_LOGE(TAG, "WiFi password is too short"); + OS_LOGE(TAG, "WiFi password is too short"); return; } if (passwordLength > 63) { - ESP_LOGE(TAG, "WiFi password is too long"); + OS_LOGE(TAG, "WiFi password is too long"); return; } if (!WiFiManager::Save(ssid->c_str(), password)) { - ESP_LOGE(TAG, "Failed to save WiFi network"); + OS_LOGE(TAG, "Failed to save WiFi network"); } } diff --git a/src/event_handlers/websocket/local/WiFiScanCommand.cpp b/src/event_handlers/websocket/local/WiFiScanCommand.cpp index bad3c16c..06000867 100644 --- a/src/event_handlers/websocket/local/WiFiScanCommand.cpp +++ b/src/event_handlers/websocket/local/WiFiScanCommand.cpp @@ -12,7 +12,7 @@ void _Private::HandleWiFiScanCommand(uint8_t socketId, const OpenShock::Serializ auto msg = root->payload_as_WifiScanCommand(); if (msg == nullptr) { - ESP_LOGE(TAG, "Payload cannot be parsed as WiFiScanCommand"); + OS_LOGE(TAG, "Payload cannot be parsed as WiFiScanCommand"); return; } diff --git a/src/event_handlers/websocket/local/_InvalidMessage.cpp b/src/event_handlers/websocket/local/_InvalidMessage.cpp index 79bacdeb..59723167 100644 --- a/src/event_handlers/websocket/local/_InvalidMessage.cpp +++ b/src/event_handlers/websocket/local/_InvalidMessage.cpp @@ -10,9 +10,9 @@ void _Private::HandleInvalidMessage(uint8_t socketId, const OpenShock::Serializa (void)socketId; if (root == nullptr) { - ESP_LOGE(TAG, "Message cannot be parsed"); + OS_LOGE(TAG, "Message cannot be parsed"); return; } - ESP_LOGE(TAG, "Invalid message type: %d", root->payload_type()); + OS_LOGE(TAG, "Invalid message type: %d", root->payload_type()); } diff --git a/src/http/HTTPRequestManager.cpp b/src/http/HTTPRequestManager.cpp index 26726efd..ebcd9619 100644 --- a/src/http/HTTPRequestManager.cpp +++ b/src/http/HTTPRequestManager.cpp @@ -225,7 +225,7 @@ ParserState _parseChunkHeader(const uint8_t* buffer, std::size_t bufferLen, std: // Header must have at least one character if (headerLen == 0) { - ESP_LOGW(TAG, "Invalid chunk header length"); + OS_LOGW(TAG, "Invalid chunk header length"); return ParserState::Invalid; } @@ -240,7 +240,7 @@ ParserState _parseChunkHeader(const uint8_t* buffer, std::size_t bufferLen, std: // Bounds check if (sizeFieldEnd == 0 || sizeFieldEnd > 16) { - ESP_LOGW(TAG, "Invalid chunk size field length"); + OS_LOGW(TAG, "Invalid chunk size field length"); return ParserState::Invalid; } @@ -248,12 +248,12 @@ ParserState _parseChunkHeader(const uint8_t* buffer, std::size_t bufferLen, std: // Parse the chunk size if (!_tryParseHexSizeT(payloadLen, sizeField)) { - ESP_LOGW(TAG, "Failed to parse chunk size"); + OS_LOGW(TAG, "Failed to parse chunk size"); return ParserState::Invalid; } if (payloadLen > HTTP_DOWNLOAD_SIZE_LIMIT) { - ESP_LOGW(TAG, "Chunk size too large"); + OS_LOGW(TAG, "Chunk size too large"); return ParserState::Invalid; } @@ -278,7 +278,7 @@ ParserState _parseChunk(const uint8_t* buffer, std::size_t bufferLen, std::size_ // Check for CRLF if (!_isCRLF(buffer + totalLen - 2)) { - ESP_LOGW(TAG, "Invalid chunk payload CRLF"); + OS_LOGW(TAG, "Invalid chunk payload CRLF"); return ParserState::Invalid; } @@ -302,7 +302,7 @@ StreamReaderResult _readStreamDataChunked(HTTPClient& client, WiFiClient* stream uint8_t* buffer = static_cast(malloc(HTTP_BUFFER_SIZE)); if (buffer == nullptr) { - ESP_LOGE(TAG, "Out of memory"); + OS_LOGE(TAG, "Out of memory"); return {HTTP::RequestResult::RequestFailed, 0}; } @@ -311,7 +311,7 @@ StreamReaderResult _readStreamDataChunked(HTTPClient& client, WiFiClient* stream while (client.connected() && state != ParserState::Invalid) { if (begin + timeoutMs < OpenShock::millis()) { - ESP_LOGW(TAG, "Request timed out"); + OS_LOGW(TAG, "Request timed out"); result = HTTP::RequestResult::TimedOut; break; } @@ -324,7 +324,7 @@ StreamReaderResult _readStreamDataChunked(HTTPClient& client, WiFiClient* stream std::size_t bytesRead = stream->readBytes(buffer + bufferCursor, HTTP_BUFFER_SIZE - bufferCursor); if (bytesRead == 0) { - ESP_LOGW(TAG, "No bytes read"); + OS_LOGW(TAG, "No bytes read"); result = HTTP::RequestResult::RequestFailed; break; } @@ -334,15 +334,15 @@ StreamReaderResult _readStreamDataChunked(HTTPClient& client, WiFiClient* stream parseMore: state = _parseChunk(buffer, bufferCursor, payloadPos, payloadSize); if (state == ParserState::Invalid) { - ESP_LOGE(TAG, "Failed to parse chunk"); + OS_LOGE(TAG, "Failed to parse chunk"); result = HTTP::RequestResult::RequestFailed; break; } - ESP_LOGD(TAG, "Chunk parsed: %zu %zu", payloadPos, payloadSize); + OS_LOGD(TAG, "Chunk parsed: %zu %zu", payloadPos, payloadSize); if (state == ParserState::NeedMoreData) { if (bufferCursor == HTTP_BUFFER_SIZE) { - ESP_LOGE(TAG, "Chunk too large"); + OS_LOGE(TAG, "Chunk too large"); result = HTTP::RequestResult::RequestFailed; break; } @@ -384,7 +384,7 @@ StreamReaderResult _readStreamData(HTTPClient& client, WiFiClient* stream, std:: while (client.connected() && nWritten < contentLength) { if (begin + timeoutMs < OpenShock::millis()) { - ESP_LOGW(TAG, "Request timed out"); + OS_LOGW(TAG, "Request timed out"); result = HTTP::RequestResult::TimedOut; break; } @@ -399,13 +399,13 @@ StreamReaderResult _readStreamData(HTTPClient& client, WiFiClient* stream, std:: std::size_t bytesRead = stream->readBytes(buffer, bytesToRead); if (bytesRead == 0) { - ESP_LOGW(TAG, "No bytes read"); + OS_LOGW(TAG, "No bytes read"); result = HTTP::RequestResult::RequestFailed; break; } if (!downloadCallback(nWritten, buffer, bytesRead)) { - ESP_LOGW(TAG, "Request cancelled by callback"); + OS_LOGW(TAG, "Request cancelled by callback"); result = HTTP::RequestResult::Cancelled; break; } @@ -432,7 +432,7 @@ HTTP::Response _doGetStream( ) { int64_t begin = OpenShock::millis(); if (!client.begin(url.toArduinoString())) { - ESP_LOGE(TAG, "Failed to begin HTTP request"); + OS_LOGE(TAG, "Failed to begin HTTP request"); return {HTTP::RequestResult::RequestFailed, 0}; } @@ -443,7 +443,7 @@ HTTP::Response _doGetStream( int responseCode = client.GET(); if (responseCode == HTTP_CODE_REQUEST_TIMEOUT || begin + timeoutMs < OpenShock::millis()) { - ESP_LOGW(TAG, "Request timed out"); + OS_LOGW(TAG, "Request timed out"); return {HTTP::RequestResult::TimedOut, responseCode, 0}; } @@ -474,11 +474,11 @@ HTTP::Response _doGetStream( } if (responseCode == 418) { - ESP_LOGW(TAG, "The server refused to brew coffee because it is, permanently, a teapot."); + OS_LOGW(TAG, "The server refused to brew coffee because it is, permanently, a teapot."); } if (std::find(acceptedCodes.begin(), acceptedCodes.end(), responseCode) == acceptedCodes.end()) { - ESP_LOGE(TAG, "Received unexpected response code %d", responseCode); + OS_LOGE(TAG, "Received unexpected response code %d", responseCode); return {HTTP::RequestResult::CodeRejected, responseCode, 0}; } @@ -489,19 +489,19 @@ HTTP::Response _doGetStream( if (contentLength > 0) { if (contentLength > HTTP_DOWNLOAD_SIZE_LIMIT) { - ESP_LOGE(TAG, "Content-Length too large"); + OS_LOGE(TAG, "Content-Length too large"); return {HTTP::RequestResult::RequestFailed, responseCode, 0}; } if (!contentLengthCallback(contentLength)) { - ESP_LOGW(TAG, "Request cancelled by callback"); + OS_LOGW(TAG, "Request cancelled by callback"); return {HTTP::RequestResult::Cancelled, responseCode, 0}; } } WiFiClient* stream = client.getStreamPtr(); if (stream == nullptr) { - ESP_LOGE(TAG, "Failed to get stream"); + OS_LOGE(TAG, "Failed to get stream"); return {HTTP::RequestResult::RequestFailed, 0}; } diff --git a/src/main.cpp b/src/main.cpp index a13f0929..c93f838d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,28 +24,28 @@ bool trySetup() { OpenShock::EventHandlers::Init(); if (!OpenShock::VisualStateManager::Init()) { - ESP_PANIC(TAG, "Unable to initialize VisualStateManager"); + OS_PANIC(TAG, "Unable to initialize VisualStateManager"); } OpenShock::EStopManager::Init(); if (!OpenShock::SerialInputHandler::Init()) { - ESP_LOGE(TAG, "Unable to initialize SerialInputHandler"); + OS_LOGE(TAG, "Unable to initialize SerialInputHandler"); return false; } if (!OpenShock::CommandHandler::Init()) { - ESP_LOGW(TAG, "Unable to initialize CommandHandler"); + OS_LOGW(TAG, "Unable to initialize CommandHandler"); return false; } if (!OpenShock::WiFiManager::Init()) { - ESP_LOGE(TAG, "Unable to initialize WiFiManager"); + OS_LOGE(TAG, "Unable to initialize WiFiManager"); return false; } if (!OpenShock::GatewayConnectionManager::Init()) { - ESP_LOGE(TAG, "Unable to initialize GatewayConnectionManager"); + OS_LOGE(TAG, "Unable to initialize GatewayConnectionManager"); return false; } @@ -54,24 +54,24 @@ bool trySetup() { // OTA setup is the same as normal setup, but we invalidate the currently running app, and roll back if it fails. void otaSetup() { - ESP_LOGI(TAG, "Validating OTA app"); + OS_LOGI(TAG, "Validating OTA app"); if (!trySetup()) { - ESP_LOGE(TAG, "Unable to validate OTA app, rolling back"); + OS_LOGE(TAG, "Unable to validate OTA app, rolling back"); OpenShock::OtaUpdateManager::InvalidateAndRollback(); } - ESP_LOGI(TAG, "Marking OTA app as valid"); + OS_LOGI(TAG, "Marking OTA app as valid"); OpenShock::OtaUpdateManager::ValidateApp(); - ESP_LOGI(TAG, "Done validating OTA app"); + OS_LOGI(TAG, "Done validating OTA app"); } // App setup is the same as normal setup, but we restart if it fails. void appSetup() { if (!trySetup()) { - ESP_LOGI(TAG, "Restarting in 5 seconds..."); + OS_LOGI(TAG, "Restarting in 5 seconds..."); vTaskDelay(pdMS_TO_TICKS(5000)); esp_restart(); } diff --git a/src/radio/RFTransmitter.cpp b/src/radio/RFTransmitter.cpp index 447e8e54..64121436 100644 --- a/src/radio/RFTransmitter.cpp +++ b/src/radio/RFTransmitter.cpp @@ -31,21 +31,21 @@ struct command_t { }; RFTransmitter::RFTransmitter(uint8_t gpioPin) : m_txPin(gpioPin), m_rmtHandle(nullptr), m_queueHandle(nullptr), m_taskHandle(nullptr) { - ESP_LOGD(TAG, "[pin-%u] Creating RFTransmitter", m_txPin); + OS_LOGD(TAG, "[pin-%u] Creating RFTransmitter", m_txPin); m_rmtHandle = rmtInit(gpioPin, RMT_TX_MODE, RMT_MEM_64); if (m_rmtHandle == nullptr) { - ESP_LOGE(TAG, "[pin-%u] Failed to create rmt object", m_txPin); + OS_LOGE(TAG, "[pin-%u] Failed to create rmt object", m_txPin); destroy(); return; } float realTick = rmtSetTick(m_rmtHandle, RFTRANSMITTER_TICKRATE_NS); - ESP_LOGD(TAG, "[pin-%u] real tick set to: %fns", m_txPin, realTick); + OS_LOGD(TAG, "[pin-%u] real tick set to: %fns", m_txPin, realTick); m_queueHandle = xQueueCreate(RFTRANSMITTER_QUEUE_SIZE, sizeof(command_t*)); if (m_queueHandle == nullptr) { - ESP_LOGE(TAG, "[pin-%u] Failed to create queue", m_txPin); + OS_LOGE(TAG, "[pin-%u] Failed to create queue", m_txPin); destroy(); return; } @@ -54,7 +54,7 @@ RFTransmitter::RFTransmitter(uint8_t gpioPin) : m_txPin(gpioPin), m_rmtHandle(nu snprintf(name, sizeof(name), "RFTransmitter-%u", m_txPin); if (TaskUtils::TaskCreateExpensive(&Util::FnProxy<&RFTransmitter::TransmitTask>, name, RFTRANSMITTER_TASK_STACK_SIZE, this, RFTRANSMITTER_TASK_PRIORITY, &m_taskHandle) != pdPASS) { - ESP_LOGE(TAG, "[pin-%u] Failed to create task", m_txPin); + OS_LOGE(TAG, "[pin-%u] Failed to create task", m_txPin); destroy(); return; } @@ -66,7 +66,7 @@ RFTransmitter::~RFTransmitter() { bool RFTransmitter::SendCommand(ShockerModelType model, uint16_t shockerId, ShockerCommandType type, uint8_t intensity, uint16_t durationMs, bool overwriteExisting) { if (m_queueHandle == nullptr) { - ESP_LOGE(TAG, "[pin-%u] Queue is null", m_txPin); + OS_LOGE(TAG, "[pin-%u] Queue is null", m_txPin); return false; } @@ -74,13 +74,13 @@ bool RFTransmitter::SendCommand(ShockerModelType model, uint16_t shockerId, Shoc // We will use nullptr commands to end the task, if we got a nullptr here, we are out of memory... :( if (cmd == nullptr) { - ESP_LOGE(TAG, "[pin-%u] Failed to allocate command", m_txPin); + OS_LOGE(TAG, "[pin-%u] Failed to allocate command", m_txPin); return false; } // Add the command to the queue, wait max 10 ms (Adjust this) if (xQueueSend(m_queueHandle, &cmd, pdMS_TO_TICKS(10)) != pdTRUE) { - ESP_LOGE(TAG, "[pin-%u] Failed to send command to queue", m_txPin); + OS_LOGE(TAG, "[pin-%u] Failed to send command to queue", m_txPin); delete cmd; return false; } @@ -93,7 +93,7 @@ void RFTransmitter::ClearPendingCommands() { return; } - ESP_LOGI(TAG, "[pin-%u] Clearing pending commands", m_txPin); + OS_LOGI(TAG, "[pin-%u] Clearing pending commands", m_txPin); command_t* command; while (xQueueReceive(m_queueHandle, &command, 0) == pdPASS) { @@ -103,7 +103,7 @@ void RFTransmitter::ClearPendingCommands() { void RFTransmitter::destroy() { if (m_taskHandle != nullptr) { - ESP_LOGD(TAG, "[pin-%u] Stopping task", m_txPin); + OS_LOGD(TAG, "[pin-%u] Stopping task", m_txPin); // Wait for the task to stop command_t* cmd = nullptr; @@ -114,7 +114,7 @@ void RFTransmitter::destroy() { xQueueSend(m_queueHandle, &cmd, pdMS_TO_TICKS(10)); } - ESP_LOGD(TAG, "[pin-%u] Task stopped", m_txPin); + OS_LOGD(TAG, "[pin-%u] Task stopped", m_txPin); // Clear the queue ClearPendingCommands(); @@ -132,7 +132,7 @@ void RFTransmitter::destroy() { } void RFTransmitter::TransmitTask() { - ESP_LOGD(TAG, "[pin-%u] RMT loop running on core %d", m_txPin, xPortGetCoreID()); + OS_LOGD(TAG, "[pin-%u] RMT loop running on core %d", m_txPin, xPortGetCoreID()); std::vector commands; while (true) { @@ -140,13 +140,13 @@ void RFTransmitter::TransmitTask() { command_t* cmd = nullptr; while (xQueueReceive(m_queueHandle, &cmd, commands.empty() ? portMAX_DELAY : 0) == pdTRUE) { if (cmd == nullptr) { - ESP_LOGD(TAG, "[pin-%u] Received nullptr (stop command), cleaning up...", m_txPin); + OS_LOGD(TAG, "[pin-%u] Received nullptr (stop command), cleaning up...", m_txPin); for (auto it = commands.begin(); it != commands.end(); ++it) { delete *it; } - ESP_LOGD(TAG, "[pin-%u] Cleanup done, stopping task", m_txPin); + OS_LOGD(TAG, "[pin-%u] Cleanup done, stopping task", m_txPin); vTaskDelete(nullptr); return; diff --git a/src/radio/rmt/MainEncoder.cpp b/src/radio/rmt/MainEncoder.cpp index 51951a1f..619505c9 100644 --- a/src/radio/rmt/MainEncoder.cpp +++ b/src/radio/rmt/MainEncoder.cpp @@ -20,7 +20,7 @@ std::vector Rmt::GetSequence(ShockerModelType model, uint16_t shocke case ShockerModelType::CaiXianlin: return Rmt::CaiXianlinEncoder::GetSequence(shockerId, 0, type, intensity); default: - ESP_LOGE(TAG, "Unknown shocker model: %u", model); + OS_LOGE(TAG, "Unknown shocker model: %u", model); return {}; } } @@ -43,7 +43,7 @@ std::shared_ptr> Rmt::GetZeroSequence(ShockerModelType m sequence = std::make_shared>(Rmt::CaiXianlinEncoder::GetSequence(shockerId, 0, ShockerCommandType::Vibrate, 0)); break; default: - ESP_LOGE(TAG, "Unknown shocker model: %u", model); + OS_LOGE(TAG, "Unknown shocker model: %u", model); sequence = nullptr; break; } diff --git a/src/serial/SerialInputHandler.cpp b/src/serial/SerialInputHandler.cpp index 52b022ac..0e8eb6c7 100644 --- a/src/serial/SerialInputHandler.cpp +++ b/src/serial/SerialInputHandler.cpp @@ -171,7 +171,7 @@ void _handleDomainCommand(StringView arg) { return; } - ESP_LOGI( + OS_LOGI( TAG, "Successfully connected to \"%.*s\", version: %s, commit: %s, current time: %s", arg.length(), @@ -274,7 +274,7 @@ void _handleLcgOverrideCommand(StringView arg) { return; } - ESP_LOGI( + OS_LOGI( TAG, "Successfully connected to \"%.*s\", name: %s, version: %s, current time: %s, country code: %s, FQDN: %s", domain.size(), @@ -353,7 +353,7 @@ void _handleNetworksCommand(StringView arg) { cred.id = id++; } - ESP_LOGI(TAG, "Adding network \"%s\" to config, id=%u", cred.ssid.c_str(), cred.id); + OS_LOGI(TAG, "Adding network \"%s\" to config, id=%u", cred.ssid.c_str(), cred.id); creds.emplace_back(std::move(cred)); } @@ -876,7 +876,7 @@ void processSerialLine(StringView line) { bool SerialInputHandler::Init() { static bool s_initialized = false; if (s_initialized) { - ESP_LOGW(TAG, "Serial input handler already initialized"); + OS_LOGW(TAG, "Serial input handler already initialized"); return false; } s_initialized = true; @@ -904,7 +904,7 @@ bool SerialInputHandler::Init() { Serial.println(); if (!Config::GetSerialInputConfigEchoEnabled(s_echoEnabled)) { - ESP_LOGE(TAG, "Failed to get serial echo status from config"); + OS_LOGE(TAG, "Failed to get serial echo status from config"); return false; } @@ -992,7 +992,7 @@ void SerialInputHandler::Update() { bufferIndex = 0; // Free buffer if it's too big if (bufferSize > SERIAL_BUFFER_CLEAR_THRESHOLD) { - ESP_LOGV(TAG, "Clearing serial input buffer"); + OS_LOGV(TAG, "Clearing serial input buffer"); bufferSize = 0; free(buffer); buffer = nullptr; @@ -1008,7 +1008,7 @@ void SerialInputHandler::Update() { bufferIndex = 0; // Free buffer if it's too big if (bufferSize > SERIAL_BUFFER_CLEAR_THRESHOLD) { - ESP_LOGV(TAG, "Clearing serial input buffer"); + OS_LOGV(TAG, "Clearing serial input buffer"); bufferSize = 0; free(buffer); buffer = nullptr; diff --git a/src/serialization/JsonAPI.cpp b/src/serialization/JsonAPI.cpp index 815f4d1b..0e96f5b1 100644 --- a/src/serialization/JsonAPI.cpp +++ b/src/serialization/JsonAPI.cpp @@ -4,7 +4,7 @@ const char* const TAG = "JsonAPI"; #include "Logging.h" -#define ESP_LOGJSONE(err, root) ESP_LOGE(TAG, "Invalid JSON response (" err "): %s", cJSON_PrintUnformatted(root)) +#define ESP_LOGJSONE(err, root) OS_LOGE(TAG, "Invalid JSON response (" err "): %s", cJSON_PrintUnformatted(root)) using namespace OpenShock::Serialization; diff --git a/src/serialization/JsonSerial.cpp b/src/serialization/JsonSerial.cpp index a3588d8c..3e14569b 100644 --- a/src/serialization/JsonSerial.cpp +++ b/src/serialization/JsonSerial.cpp @@ -8,83 +8,83 @@ using namespace OpenShock::Serialization; bool JsonSerial::ParseShockerCommand(const cJSON* root, JsonSerial::ShockerCommand& out) { if (cJSON_IsObject(root) == 0) { - ESP_LOGE(TAG, "not an object"); + OS_LOGE(TAG, "not an object"); return false; } const cJSON* model = cJSON_GetObjectItemCaseSensitive(root, "model"); if (model == nullptr) { - ESP_LOGE(TAG, "missing 'model' field"); + OS_LOGE(TAG, "missing 'model' field"); return false; } if (cJSON_IsString(model) == 0) { - ESP_LOGE(TAG, "value at 'model' is not a string"); + OS_LOGE(TAG, "value at 'model' is not a string"); return false; } ShockerModelType modelType; if (!ShockerModelTypeFromString(model->valuestring, modelType)) { - ESP_LOGE(TAG, "value at 'model' is not a valid shocker model (caixianlin, petrainer, petrainer998dr)"); + OS_LOGE(TAG, "value at 'model' is not a valid shocker model (caixianlin, petrainer, petrainer998dr)"); return false; } const cJSON* id = cJSON_GetObjectItemCaseSensitive(root, "id"); if (id == nullptr) { - ESP_LOGE(TAG, "missing 'id' field"); + OS_LOGE(TAG, "missing 'id' field"); return false; } if (cJSON_IsNumber(id) == 0) { - ESP_LOGE(TAG, "value at 'id' is not a number"); + OS_LOGE(TAG, "value at 'id' is not a number"); return false; } int idInt = id->valueint; if (idInt < 0 || idInt > UINT16_MAX) { - ESP_LOGE(TAG, "value at 'id' is out of range (0-65535)"); + OS_LOGE(TAG, "value at 'id' is out of range (0-65535)"); return false; } uint16_t idU16 = static_cast(idInt); const cJSON* command = cJSON_GetObjectItemCaseSensitive(root, "type"); if (command == nullptr) { - ESP_LOGE(TAG, "missing 'type' field"); + OS_LOGE(TAG, "missing 'type' field"); return false; } if (cJSON_IsString(command) == 0) { - ESP_LOGE(TAG, "value at 'type' is not a string"); + OS_LOGE(TAG, "value at 'type' is not a string"); return false; } ShockerCommandType commandType; if (!ShockerCommandTypeFromString(command->valuestring, commandType)) { - ESP_LOGE(TAG, "value at 'type' is not a valid shocker command (stop, shock, vibrate, sound)"); + OS_LOGE(TAG, "value at 'type' is not a valid shocker command (stop, shock, vibrate, sound)"); return false; } const cJSON* intensity = cJSON_GetObjectItemCaseSensitive(root, "intensity"); if (intensity == nullptr) { - ESP_LOGE(TAG, "missing 'intensity' field"); + OS_LOGE(TAG, "missing 'intensity' field"); return false; } if (cJSON_IsNumber(intensity) == 0) { - ESP_LOGE(TAG, "value at 'intensity' is not a number"); + OS_LOGE(TAG, "value at 'intensity' is not a number"); return false; } int intensityInt = intensity->valueint; if (intensityInt < 0 || intensityInt > UINT8_MAX) { - ESP_LOGE(TAG, "value at 'intensity' is out of range (0-255)"); + OS_LOGE(TAG, "value at 'intensity' is out of range (0-255)"); return false; } uint8_t intensityU8 = static_cast(intensityInt); const cJSON* durationMs = cJSON_GetObjectItemCaseSensitive(root, "durationMs"); if (durationMs == nullptr) { - ESP_LOGE(TAG, "missing 'durationMs' field"); + OS_LOGE(TAG, "missing 'durationMs' field"); return false; } if (cJSON_IsNumber(durationMs) == 0) { - ESP_LOGE(TAG, "value at 'durationMs' is not a number"); + OS_LOGE(TAG, "value at 'durationMs' is not a number"); return false; } if (durationMs->valueint < 0 || durationMs->valueint > UINT16_MAX) { - ESP_LOGE(TAG, "value at 'durationMs' is out of range (0-65535)"); + OS_LOGE(TAG, "value at 'durationMs' is out of range (0-65535)"); return false; } uint16_t durationMsU16 = static_cast(durationMs->valueint); diff --git a/src/serialization/WSGateway.cpp b/src/serialization/WSGateway.cpp index 98911bc6..d0fb56de 100644 --- a/src/serialization/WSGateway.cpp +++ b/src/serialization/WSGateway.cpp @@ -13,7 +13,7 @@ bool Gateway::SerializeKeepAliveMessage(Common::SerializationCallbackFn callback int64_t uptime = OpenShock::millis(); if (uptime < 0) { - ESP_LOGE(TAG, "Failed to get uptime"); + OS_LOGE(TAG, "Failed to get uptime"); return false; } diff --git a/src/serialization/WSLocal.cpp b/src/serialization/WSLocal.cpp index d81a9e42..c0a438ad 100644 --- a/src/serialization/WSLocal.cpp +++ b/src/serialization/WSLocal.cpp @@ -74,7 +74,7 @@ bool Local::SerializeReadyMessage(const WiFiNetwork* connectedNetwork, bool acco auto configOffset = OpenShock::Config::GetAsFlatBuffer(builder, false); if (configOffset.IsNull()) { - ESP_LOGE(TAG, "Failed to serialize config"); + OS_LOGE(TAG, "Failed to serialize config"); return false; } diff --git a/src/util/Base64Utils.cpp b/src/util/Base64Utils.cpp index bf25f848..5b8dac92 100644 --- a/src/util/Base64Utils.cpp +++ b/src/util/Base64Utils.cpp @@ -14,9 +14,9 @@ std::size_t Base64Utils::Encode(const uint8_t* data, std::size_t dataLen, char* int retval = mbedtls_base64_encode(reinterpret_cast(output), outputLen, &requiredLen, data, dataLen); if (retval != 0) { if (retval == MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) { - ESP_LOGW(TAG, "Output buffer too small (expected %zu, got %zu)", requiredLen, outputLen); + OS_LOGW(TAG, "Output buffer too small (expected %zu, got %zu)", requiredLen, outputLen); } else { - ESP_LOGW(TAG, "Failed to encode data, unknown error: %d", retval); + OS_LOGW(TAG, "Failed to encode data, unknown error: %d", retval); } return 0; } @@ -54,11 +54,11 @@ std::size_t Base64Utils::Decode(const char* data, std::size_t dataLen, uint8_t* int retval = mbedtls_base64_decode(output, outputLen, &requiredLen, reinterpret_cast(data), dataLen); if (retval != 0) { if (retval == MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) { - ESP_LOGW(TAG, "Output buffer too small (expected %zu, got %zu)", requiredLen, outputLen); + OS_LOGW(TAG, "Output buffer too small (expected %zu, got %zu)", requiredLen, outputLen); } else if (retval == MBEDTLS_ERR_BASE64_INVALID_CHARACTER) { - ESP_LOGW(TAG, "Invalid character in input data"); + OS_LOGW(TAG, "Invalid character in input data"); } else { - ESP_LOGW(TAG, "Failed to decode data, unknown error: %d", retval); + OS_LOGW(TAG, "Failed to decode data, unknown error: %d", retval); } return 0; } diff --git a/src/util/CertificateUtils.cpp b/src/util/CertificateUtils.cpp index 07036a1e..2a76a809 100644 --- a/src/util/CertificateUtils.cpp +++ b/src/util/CertificateUtils.cpp @@ -25,16 +25,16 @@ bool OpenShock::CertificateUtils::GetHostCertificate(const char* host, std::vect client.connect(host, 443); if (client.connected() == 0) { - ESP_LOGE(TAG, "Failed to connect to host %s", host); + OS_LOGE(TAG, "Failed to connect to host %s", host); return false; } - ESP_LOGD(TAG, "Connected to host %s, fetching certificate", host); + OS_LOGD(TAG, "Connected to host %s, fetching certificate", host); const mbedtls_x509_crt* cert = client.getPeerCertificate(); if (cert == nullptr) { - ESP_LOGE(TAG, "Certificate is null"); + OS_LOGE(TAG, "Certificate is null"); return false; } @@ -47,11 +47,11 @@ bool OpenShock::CertificateUtils::GetHostCertificate(const char* host, std::vect pem.resize(pemLen); int retval = mbedtls_pem_write_buffer(PEM_HEADER, PEM_FOOTER, der.p, der.len, reinterpret_cast(pem.data()), pem.size(), nullptr); if (retval != 0) { - ESP_LOGE(TAG, "Failed to write pem buffer: %d", retval); + OS_LOGE(TAG, "Failed to write pem buffer: %d", retval); return false; } - ESP_LOGD(TAG, "Successfully fetched certificate from host %s", host); + OS_LOGD(TAG, "Successfully fetched certificate from host %s", host); return true; } diff --git a/src/util/ParitionUtils.cpp b/src/util/ParitionUtils.cpp index da969b9b..dd219cbf 100644 --- a/src/util/ParitionUtils.cpp +++ b/src/util/ParitionUtils.cpp @@ -12,7 +12,7 @@ bool OpenShock::TryGetPartitionHash(const esp_partition_t* partition, char (&has uint8_t buffer[32]; esp_err_t err = esp_partition_get_sha256(partition, buffer); if (err != ESP_OK) { - ESP_LOGE(TAG, "Failed to get partition hash: %s", esp_err_to_name(err)); + OS_LOGE(TAG, "Failed to get partition hash: %s", esp_err_to_name(err)); return false; } @@ -25,7 +25,7 @@ bool OpenShock::TryGetPartitionHash(const esp_partition_t* partition, char (&has bool OpenShock::FlashPartitionFromUrl(const esp_partition_t* partition, StringView remoteUrl, const uint8_t (&remoteHash)[32], std::function progressCallback) { OpenShock::SHA256 sha256; if (!sha256.begin()) { - ESP_LOGE(TAG, "Failed to initialize SHA256 hash"); + OS_LOGE(TAG, "Failed to initialize SHA256 hash"); return false; } @@ -35,13 +35,13 @@ bool OpenShock::FlashPartitionFromUrl(const esp_partition_t* partition, StringVi auto sizeValidator = [partition, &contentLength, progressCallback, &lastProgress](std::size_t size) -> bool { if (size > partition->size) { - ESP_LOGE(TAG, "Remote partition binary is too large"); + OS_LOGE(TAG, "Remote partition binary is too large"); return false; } // Erase app partition. if (esp_partition_erase_range(partition, 0, partition->size) != ESP_OK) { - ESP_LOGE(TAG, "Failed to erase partition in preparation for update"); + OS_LOGE(TAG, "Failed to erase partition in preparation for update"); return false; } @@ -54,12 +54,12 @@ bool OpenShock::FlashPartitionFromUrl(const esp_partition_t* partition, StringVi }; auto dataWriter = [partition, &sha256, &contentLength, &contentWritten, progressCallback, &lastProgress](std::size_t offset, const uint8_t* data, std::size_t length) -> bool { if (esp_partition_write(partition, offset, data, length) != ESP_OK) { - ESP_LOGE(TAG, "Failed to write to partition"); + OS_LOGE(TAG, "Failed to write to partition"); return false; } if (!sha256.update(data, length)) { - ESP_LOGE(TAG, "Failed to update SHA256 hash"); + OS_LOGE(TAG, "Failed to update SHA256 hash"); return false; } @@ -86,22 +86,22 @@ bool OpenShock::FlashPartitionFromUrl(const esp_partition_t* partition, StringVi 180'000 ); // 3 minutes if (appBinaryResponse.result != OpenShock::HTTP::RequestResult::Success) { - ESP_LOGE(TAG, "Failed to download remote partition binary: [%u]", appBinaryResponse.code); + OS_LOGE(TAG, "Failed to download remote partition binary: [%u]", appBinaryResponse.code); return false; } progressCallback(contentLength, contentLength, 1.0f); - ESP_LOGD(TAG, "Wrote %u bytes to partition", appBinaryResponse.data); + OS_LOGD(TAG, "Wrote %u bytes to partition", appBinaryResponse.data); std::array localHash; if (!sha256.finish(localHash)) { - ESP_LOGE(TAG, "Failed to finish SHA256 hash"); + OS_LOGE(TAG, "Failed to finish SHA256 hash"); return false; } // Compare hashes. if (memcmp(localHash.data(), remoteHash, 32) != 0) { - ESP_LOGE(TAG, "App binary hash mismatch"); + OS_LOGE(TAG, "App binary hash mismatch"); return false; } diff --git a/src/util/StringUtils.cpp b/src/util/StringUtils.cpp index a14d05e2..6e331c06 100644 --- a/src/util/StringUtils.cpp +++ b/src/util/StringUtils.cpp @@ -22,7 +22,7 @@ bool OpenShock::FormatToString(std::string& out, const char* format, ...) { // If result is negative, something went wrong. if (result < 0) { - ESP_LOGE(TAG, "Failed to format string"); + OS_LOGE(TAG, "Failed to format string"); return false; } @@ -42,7 +42,7 @@ bool OpenShock::FormatToString(std::string& out, const char* format, ...) { // Free heap buffer and return false. if (result < 0) { delete[] bufferPtr; - ESP_LOGE(TAG, "Failed to format string"); + OS_LOGE(TAG, "Failed to format string"); return false; } } diff --git a/src/wifi/WiFiManager.cpp b/src/wifi/WiFiManager.cpp index 98c4236e..787f8b7a 100644 --- a/src/wifi/WiFiManager.cpp +++ b/src/wifi/WiFiManager.cpp @@ -119,7 +119,7 @@ bool _getNextWiFiNetwork(OpenShock::Config::WiFiCredentials& creds) { } bool _connectImpl(const char* ssid, const char* password, const uint8_t (&bssid)[6]) { - ESP_LOGV(TAG, "Connecting to network %s (" BSSID_FMT ")", ssid, BSSID_ARG(bssid)); + OS_LOGV(TAG, "Connecting to network %s (" BSSID_FMT ")", ssid, BSSID_ARG(bssid)); _markNetworkAsAttempted(bssid); @@ -135,22 +135,22 @@ bool _connectImpl(const char* ssid, const char* password, const uint8_t (&bssid) bool _connectHidden(const uint8_t (&bssid)[6], const std::string& password) { (void)password; - ESP_LOGV(TAG, "Connecting to hidden network " BSSID_FMT, BSSID_ARG(bssid)); + OS_LOGV(TAG, "Connecting to hidden network " BSSID_FMT, BSSID_ARG(bssid)); // TODO: Implement hidden network support - ESP_LOGE(TAG, "Connecting to hidden networks is not yet supported"); + OS_LOGE(TAG, "Connecting to hidden networks is not yet supported"); return false; } bool _connect(const std::string& ssid, const std::string& password) { if (ssid.empty()) { - ESP_LOGW(TAG, "Cannot connect to network with empty SSID"); + OS_LOGW(TAG, "Cannot connect to network with empty SSID"); return false; } auto it = _findNetworkBySSID(ssid.c_str()); if (it == s_wifiNetworks.end()) { - ESP_LOGE(TAG, "Failed to find network with SSID %s", ssid.c_str()); + OS_LOGE(TAG, "Failed to find network with SSID %s", ssid.c_str()); return false; } @@ -158,13 +158,13 @@ bool _connect(const std::string& ssid, const std::string& password) { } bool _connect(const uint8_t (&bssid)[6], const std::string& password) { if (_isZeroBSSID(bssid)) { - ESP_LOGW(TAG, "Cannot connect to network with zero BSSID"); + OS_LOGW(TAG, "Cannot connect to network with zero BSSID"); return false; } auto it = _findNetworkByBSSID(bssid); if (it == s_wifiNetworks.end()) { - ESP_LOGE(TAG, "Failed to find network " BSSID_FMT, BSSID_ARG(bssid)); + OS_LOGE(TAG, "Failed to find network " BSSID_FMT, BSSID_ARG(bssid)); return false; } @@ -193,14 +193,14 @@ void _evWiFiConnected(arduino_event_t* event) { if (it == s_wifiNetworks.end()) { s_connectedCredentialsID = 0; - ESP_LOGW(TAG, "Connected to unscanned network \"%s\", BSSID: " BSSID_FMT, reinterpret_cast(info.ssid), BSSID_ARG(info.bssid)); + OS_LOGW(TAG, "Connected to unscanned network \"%s\", BSSID: " BSSID_FMT, reinterpret_cast(info.ssid), BSSID_ARG(info.bssid)); return; } s_connectedCredentialsID = it->credentialsID; - ESP_LOGI(TAG, "Connected to network %s (" BSSID_FMT ")", reinterpret_cast(info.ssid), BSSID_ARG(info.bssid)); + OS_LOGI(TAG, "Connected to network %s (" BSSID_FMT ")", reinterpret_cast(info.ssid), BSSID_ARG(info.bssid)); Serialization::Local::SerializeWiFiNetworkEvent(Serialization::Types::WifiNetworkEventType::Connected, *it, CaptivePortal::BroadcastMessageBIN); } @@ -210,14 +210,14 @@ void _evWiFiGotIP(arduino_event_t* event) { uint8_t ip[4]; memcpy(ip, &info.ip_info.ip.addr, sizeof(ip)); - ESP_LOGI(TAG, "Got IP address " IPV4ADDR_FMT " from network " BSSID_FMT, IPV4ADDR_ARG(ip), BSSID_ARG(s_connectedBSSID)); + OS_LOGI(TAG, "Got IP address " IPV4ADDR_FMT " from network " BSSID_FMT, IPV4ADDR_ARG(ip), BSSID_ARG(s_connectedBSSID)); } void _evWiFiGotIP6(arduino_event_t* event) { auto& info = event->event_info.got_ip6; uint8_t* ip6 = reinterpret_cast(&info.ip6_info.ip.addr); - ESP_LOGI(TAG, "Got IPv6 address " IPV6ADDR_FMT " from network " BSSID_FMT, IPV6ADDR_ARG(ip6), BSSID_ARG(s_connectedBSSID)); + OS_LOGI(TAG, "Got IPv6 address " IPV6ADDR_FMT " from network " BSSID_FMT, IPV6ADDR_ARG(ip6), BSSID_ARG(s_connectedBSSID)); } void _evWiFiDisconnected(arduino_event_t* event) { s_wifiState = WiFiState::Disconnected; @@ -226,11 +226,11 @@ void _evWiFiDisconnected(arduino_event_t* event) { Config::WiFiCredentials creds; if (!Config::TryGetWiFiCredentialsBySSID(reinterpret_cast(info.ssid), creds)) { - ESP_LOGW(TAG, "Disconnected from unknown network... WTF?"); + OS_LOGW(TAG, "Disconnected from unknown network... WTF?"); return; } - ESP_LOGI(TAG, "Disconnected from network %s (" BSSID_FMT ")", info.ssid, BSSID_ARG(info.bssid)); + OS_LOGI(TAG, "Disconnected from network %s (" BSSID_FMT ")", info.ssid, BSSID_ARG(info.bssid)); if (info.reason == WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT || info.reason == WIFI_REASON_AUTH_EXPIRE || info.reason == WIFI_REASON_AUTH_FAIL) { Serialization::Local::SerializeErrorMessage("WiFi authentication failed", CaptivePortal::BroadcastMessageBIN); @@ -246,7 +246,7 @@ void _evWiFiScanStatusChanged(OpenShock::WiFiScanStatus status) { if (status == OpenShock::WiFiScanStatus::Started) { for (auto it = s_wifiNetworks.begin(); it != s_wifiNetworks.end();) { if (it->scansMissed++ > 3) { - ESP_LOGV(TAG, "Network %s (" BSSID_FMT ") has not been seen in 3 scans, removing from list", it->ssid, BSSID_ARG(it->bssid)); + OS_LOGV(TAG, "Network %s (" BSSID_FMT ") has not been seen in 3 scans, removing from list", it->ssid, BSSID_ARG(it->bssid)); Serialization::Local::SerializeWiFiNetworkEvent(Serialization::Types::WifiNetworkEventType::Lost, *it, CaptivePortal::BroadcastMessageBIN); it = s_wifiNetworks.erase(it); } else { @@ -282,7 +282,7 @@ void _evWiFiNetworksDiscovery(const std::vector& record it->scansMissed = 0; updatedNetworks.push_back(*it); - ESP_LOGV(TAG, "Updated network %s (" BSSID_FMT ") with new scan info", it->ssid, BSSID_ARG(it->bssid)); + OS_LOGV(TAG, "Updated network %s (" BSSID_FMT ") with new scan info", it->ssid, BSSID_ARG(it->bssid)); continue; } @@ -290,7 +290,7 @@ void _evWiFiNetworksDiscovery(const std::vector& record WiFiNetwork network(record->ssid, record->bssid, record->primary, record->rssi, record->authmode, credsId); discoveredNetworks.push_back(network); - ESP_LOGV(TAG, "Discovered new network %s (" BSSID_FMT ")", network.ssid, BSSID_ARG(network.bssid)); + OS_LOGV(TAG, "Discovered new network %s (" BSSID_FMT ")", network.ssid, BSSID_ARG(network.bssid)); // Insert the network into the list of networks sorted by RSSI s_wifiNetworks.insert(std::lower_bound(s_wifiNetworks.begin(), s_wifiNetworks.end(), network, [](const WiFiNetwork& a, const WiFiNetwork& b) { return a.rssi > b.rssi; }), std::move(network)); @@ -315,7 +315,7 @@ bool WiFiManager::Init() { WiFiScanManager::RegisterNetworksDiscoveredHandler(_evWiFiNetworksDiscovery); if (!WiFiScanManager::Init()) { - ESP_LOGE(TAG, "Failed to initialize WiFiScanManager"); + OS_LOGE(TAG, "Failed to initialize WiFiScanManager"); return false; } @@ -335,7 +335,7 @@ bool WiFiManager::Init() { } if (set_esp_interface_dns(ESP_IF_WIFI_STA, IPAddress(1, 1, 1, 1), IPAddress(8, 8, 8, 8), IPAddress(9, 9, 9, 9)) != ESP_OK) { - ESP_LOGE(TAG, "Failed to set DNS servers"); + OS_LOGE(TAG, "Failed to set DNS servers"); return false; } @@ -343,11 +343,11 @@ bool WiFiManager::Init() { } bool WiFiManager::Save(const char* ssid, StringView password) { - ESP_LOGV(TAG, "Authenticating to network %s", ssid); + OS_LOGV(TAG, "Authenticating to network %s", ssid); auto it = _findNetworkBySSID(ssid); if (it == s_wifiNetworks.end()) { - ESP_LOGE(TAG, "Failed to find network with SSID %s", ssid); + OS_LOGE(TAG, "Failed to find network with SSID %s", ssid); Serialization::Local::SerializeErrorMessage("network_not_found", CaptivePortal::BroadcastMessageBIN); @@ -358,11 +358,11 @@ bool WiFiManager::Save(const char* ssid, StringView password) { } bool WiFiManager::Forget(const char* ssid) { - ESP_LOGV(TAG, "Forgetting network %s", ssid); + OS_LOGV(TAG, "Forgetting network %s", ssid); auto it = _findNetworkBySSID(ssid); if (it == s_wifiNetworks.end()) { - ESP_LOGE(TAG, "Failed to find network with SSID %s", ssid); + OS_LOGE(TAG, "Failed to find network with SSID %s", ssid); return false; } @@ -384,15 +384,15 @@ bool WiFiManager::Forget(const char* ssid) { } bool WiFiManager::RefreshNetworkCredentials() { - ESP_LOGV(TAG, "Refreshing network credentials"); + OS_LOGV(TAG, "Refreshing network credentials"); for (auto& net : s_wifiNetworks) { Config::WiFiCredentials creds; if (Config::TryGetWiFiCredentialsBySSID(net.ssid, creds)) { - ESP_LOGV(TAG, "Found credentials for network %s (" BSSID_FMT ")", net.ssid, BSSID_ARG(net.bssid)); + OS_LOGV(TAG, "Found credentials for network %s (" BSSID_FMT ")", net.ssid, BSSID_ARG(net.bssid)); net.credentialsID = creds.id; } else { - ESP_LOGV(TAG, "Failed to find credentials for network %s (" BSSID_FMT ")", net.ssid, BSSID_ARG(net.bssid)); + OS_LOGV(TAG, "Failed to find credentials for network %s (" BSSID_FMT ")", net.ssid, BSSID_ARG(net.bssid)); net.credentialsID = 0; } } @@ -407,7 +407,7 @@ bool WiFiManager::IsSaved(const char* ssid) { bool WiFiManager::Connect(const char* ssid) { Config::WiFiCredentials creds; if (!Config::TryGetWiFiCredentialsBySSID(ssid, creds)) { - ESP_LOGE(TAG, "Failed to find credentials for network %s", ssid); + OS_LOGE(TAG, "Failed to find credentials for network %s", ssid); return false; } @@ -428,13 +428,13 @@ bool WiFiManager::Connect(const char* ssid) { bool WiFiManager::Connect(const uint8_t (&bssid)[6]) { auto it = _findNetworkByBSSID(bssid); if (it == s_wifiNetworks.end()) { - ESP_LOGE(TAG, "Failed to find network " BSSID_FMT, BSSID_ARG(bssid)); + OS_LOGE(TAG, "Failed to find network " BSSID_FMT, BSSID_ARG(bssid)); return false; } Config::WiFiCredentials creds; if (!Config::TryGetWiFiCredentialsBySSID(it->ssid, creds)) { - ESP_LOGE(TAG, "Failed to find credentials for network %s (" BSSID_FMT ")", it->ssid, BSSID_ARG(it->bssid)); + OS_LOGE(TAG, "Failed to find credentials for network %s (" BSSID_FMT ")", it->ssid, BSSID_ARG(it->bssid)); return false; } @@ -517,7 +517,7 @@ void WiFiManager::Update() { s_preferredCredentialsID = 0; if (!foundCreds) { - ESP_LOGE(TAG, "Failed to find credentials with ID %u", s_preferredCredentialsID); + OS_LOGE(TAG, "Failed to find credentials with ID %u", s_preferredCredentialsID); return; } @@ -525,7 +525,7 @@ void WiFiManager::Update() { return; } - ESP_LOGE(TAG, "Failed to connect to network %s", creds.ssid.c_str()); + OS_LOGE(TAG, "Failed to connect to network %s", creds.ssid.c_str()); } Config::WiFiCredentials creds; @@ -534,7 +534,7 @@ void WiFiManager::Update() { if (s_lastScanRequest == 0 || now - s_lastScanRequest > 30'000) { s_lastScanRequest = now; - ESP_LOGV(TAG, "No networks to connect to, starting scan..."); + OS_LOGV(TAG, "No networks to connect to, starting scan..."); WiFiScanManager::StartScan(); } return; diff --git a/src/wifi/WiFiScanManager.cpp b/src/wifi/WiFiScanManager.cpp index 758ed58c..23074e06 100644 --- a/src/wifi/WiFiScanManager.cpp +++ b/src/wifi/WiFiScanManager.cpp @@ -61,16 +61,16 @@ void _handleScanError(int16_t retval) { _notifyTask(WiFiScanTaskNotificationFlags::ERROR); if (retval == WIFI_SCAN_FAILED) { - ESP_LOGE(TAG, "Failed to start scan on channel %u", s_currentChannel); + OS_LOGE(TAG, "Failed to start scan on channel %u", s_currentChannel); return; } if (retval == WIFI_SCAN_RUNNING) { - ESP_LOGE(TAG, "Scan is running on channel %u", s_currentChannel); + OS_LOGE(TAG, "Scan is running on channel %u", s_currentChannel); return; } - ESP_LOGE(TAG, "Scan returned an unknown error"); + OS_LOGE(TAG, "Scan returned an unknown error"); } int16_t _scanChannel(uint8_t channel) { @@ -104,19 +104,19 @@ WiFiScanStatus _scanningTaskImpl() { // Wait for the scan to complete, _evScanCompleted will notify us when it's done if (xTaskNotifyWait(0, WiFiScanTaskNotificationFlags::CLEAR_FLAGS, ¬ificationFlags, pdMS_TO_TICKS(OPENSHOCK_WIFI_SCAN_TIMEOUT_MS)) != pdTRUE) { - ESP_LOGE(TAG, "Scan timed out"); + OS_LOGE(TAG, "Scan timed out"); return WiFiScanStatus::TimedOut; } // Check if we were notified of an error or if WiFi was disabled if (notificationFlags != WiFiScanTaskNotificationFlags::CHANNEL_DONE) { if (notificationFlags & WiFiScanTaskNotificationFlags::WIFI_DISABLED) { - ESP_LOGE(TAG, "Scan task exiting due to being notified that WiFi was disabled"); + OS_LOGE(TAG, "Scan task exiting due to being notified that WiFi was disabled"); return WiFiScanStatus::Aborted; } if (notificationFlags & WiFiScanTaskNotificationFlags::ERROR) { - ESP_LOGE(TAG, "Scan task exiting due to being notified of an error"); + OS_LOGE(TAG, "Scan task exiting due to being notified of an error"); return WiFiScanStatus::Error; } @@ -167,7 +167,7 @@ void _evScanCompleted(arduino_event_id_t event, arduino_event_info_t info) { } if (numNetworks == WIFI_SCAN_RUNNING) { - ESP_LOGE(TAG, "Scan completed but scan is still running... WTF?"); + OS_LOGE(TAG, "Scan completed but scan is still running... WTF?"); return; } @@ -177,7 +177,7 @@ void _evScanCompleted(arduino_event_id_t event, arduino_event_info_t info) { for (int16_t i = 0; i < numNetworks; i++) { wifi_ap_record_t* record = reinterpret_cast(WiFi.getScanInfoByIndex(i)); if (record == nullptr) { - ESP_LOGE(TAG, "Failed to get scan info for network #%d", i); + OS_LOGE(TAG, "Failed to get scan info for network #%d", i); return; } @@ -201,7 +201,7 @@ void _evSTAStopped(arduino_event_id_t event, arduino_event_info_t info) { bool WiFiScanManager::Init() { if (s_initialized) { - ESP_LOGW(TAG, "WiFiScanManager is already initialized"); + OS_LOGW(TAG, "WiFiScanManager is already initialized"); return true; } @@ -222,7 +222,7 @@ bool WiFiScanManager::StartScan() { // Check if a scan is already in progress if (s_scanTaskHandle != nullptr && eTaskGetState(s_scanTaskHandle) != eDeleted) { - ESP_LOGW(TAG, "Cannot start scan: scan task is already running"); + OS_LOGW(TAG, "Cannot start scan: scan task is already running"); xSemaphoreGive(s_scanTaskMutex); return false; @@ -230,7 +230,7 @@ bool WiFiScanManager::StartScan() { // Start the scan task if (TaskUtils::TaskCreateExpensive(_scanningTask, "WiFiScanManager", 4096, nullptr, 1, &s_scanTaskHandle) != pdPASS) { // PROFILED: 1.8KB stack usage - ESP_LOGE(TAG, "Failed to create scan task"); + OS_LOGE(TAG, "Failed to create scan task"); xSemaphoreGive(s_scanTaskMutex); return false; @@ -244,7 +244,7 @@ bool WiFiScanManager::AbortScan() { // Check if a scan is in progress if (s_scanTaskHandle == nullptr || eTaskGetState(s_scanTaskHandle) == eDeleted) { - ESP_LOGW(TAG, "Cannot abort scan: no scan is in progress"); + OS_LOGW(TAG, "Cannot abort scan: no scan is in progress"); xSemaphoreGive(s_scanTaskMutex); return false; From 16bd881d1710c3e8757750f0b8b9569a96927563 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 6 Sep 2024 09:57:57 +0200 Subject: [PATCH 20/41] Remove linter spam --- .github/workflows/cpp-linter.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index d0bbbdc0..6b5ff5bb 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -23,7 +23,9 @@ jobs: with: style: file version: 18 - step-summary: true + lines-changed-only: diff + thread-comments: true + step-summary: false format-review: true - name: Fail fast?! From fed47699cf28d1c96de7126fcd066cccf203ecd1 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 6 Sep 2024 10:01:39 +0200 Subject: [PATCH 21/41] Update cpp-linter.yml --- .github/workflows/cpp-linter.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index 6b5ff5bb..9224f310 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -3,9 +3,9 @@ name: cpp-linter on: pull_request: types: [opened, reopened, synchronize] - paths: [ '**.c', '**.h', '**.cpp', '**.hpp', '.clang-format' ] + paths: ['**.c', '**.h', '**.cpp', '**.hpp', '.clang-format'] push: - paths: [ '**.c', '**.h', '**.cpp', '**.hpp', '.clang-format' ] + paths: ['**.c', '**.h', '**.cpp', '**.hpp', '.clang-format'] workflow_dispatch: # Manually invoked by user. jobs: @@ -26,7 +26,6 @@ jobs: lines-changed-only: diff thread-comments: true step-summary: false - format-review: true - name: Fail fast?! if: steps.linter.outputs.checks-failed > 0 From 7fc6feff1307f4d8bb0e5255000892a3fc820f1a Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 6 Sep 2024 10:10:08 +0200 Subject: [PATCH 22/41] Update cpp-linter.yml --- .github/workflows/cpp-linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index 9224f310..497d627d 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -25,7 +25,7 @@ jobs: version: 18 lines-changed-only: diff thread-comments: true - step-summary: false + file-annotations: false - name: Fail fast?! if: steps.linter.outputs.checks-failed > 0 From 258188b5d19eed3440aaf12801ae49925150bae5 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 6 Sep 2024 11:36:56 +0200 Subject: [PATCH 23/41] Add missing FreeRTOS.h includes --- src/CaptivePortal.cpp | 2 ++ src/VisualStateManager.cpp | 2 ++ src/config/Config.cpp | 2 ++ src/main.cpp | 2 ++ 4 files changed, 8 insertions(+) diff --git a/src/CaptivePortal.cpp b/src/CaptivePortal.cpp index 3d203509..6cd68910 100644 --- a/src/CaptivePortal.cpp +++ b/src/CaptivePortal.cpp @@ -1,3 +1,5 @@ +#include + #include "CaptivePortal.h" const char* const TAG = "CaptivePortal"; diff --git a/src/VisualStateManager.cpp b/src/VisualStateManager.cpp index b35798f2..c5bacd82 100644 --- a/src/VisualStateManager.cpp +++ b/src/VisualStateManager.cpp @@ -1,3 +1,5 @@ +#include + #include "VisualStateManager.h" const char* const TAG = "VisualStateManager"; diff --git a/src/config/Config.cpp b/src/config/Config.cpp index 88c5c32c..c2a2f544 100644 --- a/src/config/Config.cpp +++ b/src/config/Config.cpp @@ -1,3 +1,5 @@ +#include + #include "config/Config.h" const char* const TAG = "Config"; diff --git a/src/main.cpp b/src/main.cpp index c93f838d..2690e731 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,5 @@ +#include + const char* const TAG = "main"; #include "CaptivePortal.h" From 286837455bb20d11e194ac952edadfea36443376 Mon Sep 17 00:00:00 2001 From: HeavenVR Date: Fri, 6 Sep 2024 16:52:09 +0200 Subject: [PATCH 24/41] Replace custom StringView with standard library std::string_view (#280) * Start replacement work * Fix the rest of the problems * Some extra fixes * Move non-constexpr functions out of header * Better string split for fixed lengths * Fix const qualifier --- include/CaptivePortal.h | 7 +- include/CaptivePortalInstance.h | 6 +- include/Common.h | 7 +- include/GatewayClient.h | 5 +- include/GatewayConnectionManager.h | 6 +- include/OtaUpdateManager.h | 1 - include/SemVer.h | 12 +- include/StringView.h | 469 ------------------ include/config/BackendConfig.h | 4 +- include/config/Config.h | 12 +- include/config/WiFiConfig.h | 4 +- include/config/WiFiCredentials.h | 4 +- include/http/HTTPRequestManager.h | 9 +- include/http/JsonAPI.h | 8 +- include/intconv.h | 19 +- include/serialization/WSGateway.h | 5 +- include/util/IPAddressUtils.h | 4 +- include/util/PartitionUtils.h | 5 +- include/util/StringUtils.h | 62 ++- include/wifi/WiFiManager.h | 4 +- src/CaptivePortal.cpp | 4 +- src/EStopManager.cpp | 1 + src/GatewayClient.cpp | 2 +- src/GatewayConnectionManager.cpp | 10 +- src/OtaUpdateManager.cpp | 62 +-- src/SemVer.cpp | 87 ++-- src/config/BackendConfig.cpp | 2 +- src/config/Config.cpp | 22 +- src/config/WiFiConfig.cpp | 2 +- src/config/WiFiCredentials.cpp | 2 +- src/config/internal/utils.cpp | 4 +- .../websocket/gateway/OtaInstall.cpp | 6 +- src/http/HTTPRequestManager.cpp | 61 ++- src/http/JsonAPI.cpp | 13 +- src/intconv.cpp | 85 ++-- src/serial/SerialInputHandler.cpp | 167 ++++--- src/serialization/WSGateway.cpp | 2 +- src/util/IPAddressUtils.cpp | 9 +- src/util/ParitionUtils.cpp | 2 +- src/util/StringUtils.cpp | 69 +++ src/wifi/WiFiManager.cpp | 6 +- 41 files changed, 485 insertions(+), 786 deletions(-) delete mode 100644 include/StringView.h diff --git a/include/CaptivePortal.h b/include/CaptivePortal.h index 6272488a..80d412ba 100644 --- a/include/CaptivePortal.h +++ b/include/CaptivePortal.h @@ -1,10 +1,9 @@ #pragma once -#include "StringView.h" - #include #include +#include namespace OpenShock::CaptivePortal { void SetAlwaysEnabled(bool alwaysEnabled); @@ -15,9 +14,9 @@ namespace OpenShock::CaptivePortal { bool IsRunning(); void Update(); - bool SendMessageTXT(uint8_t socketId, StringView data); + bool SendMessageTXT(uint8_t socketId, std::string_view data); bool SendMessageBIN(uint8_t socketId, const uint8_t* data, std::size_t len); - bool BroadcastMessageTXT(StringView data); + bool BroadcastMessageTXT(std::string_view data); bool BroadcastMessageBIN(const uint8_t* data, std::size_t len); } // namespace OpenShock::CaptivePortal diff --git a/include/CaptivePortalInstance.h b/include/CaptivePortalInstance.h index 02a3b377..4b0c4fa5 100644 --- a/include/CaptivePortalInstance.h +++ b/include/CaptivePortalInstance.h @@ -1,6 +1,5 @@ #pragma once -#include "StringView.h" #include "WebSocketDeFragger.h" #include @@ -11,6 +10,7 @@ #include #include +#include namespace OpenShock { class CaptivePortalInstance { @@ -18,9 +18,9 @@ namespace OpenShock { CaptivePortalInstance(); ~CaptivePortalInstance(); - bool sendMessageTXT(uint8_t socketId, StringView data) { return m_socketServer.sendTXT(socketId, data.data(), data.length()); } + bool sendMessageTXT(uint8_t socketId, std::string_view data) { return m_socketServer.sendTXT(socketId, data.data(), data.length()); } bool sendMessageBIN(uint8_t socketId, const uint8_t* data, std::size_t len) { return m_socketServer.sendBIN(socketId, data, len); } - bool broadcastMessageTXT(StringView data) { return m_socketServer.broadcastTXT(data.data(), data.length()); } + bool broadcastMessageTXT(std::string_view data) { return m_socketServer.broadcastTXT(data.data(), data.length()); } bool broadcastMessageBIN(const uint8_t* data, std::size_t len) { return m_socketServer.broadcastBIN(data, len); } private: diff --git a/include/Common.h b/include/Common.h index bec0778b..e4c67de0 100644 --- a/include/Common.h +++ b/include/Common.h @@ -1,8 +1,7 @@ #pragma once -#include "StringView.h" - #include +#include #define DISABLE_COPY(TypeName) \ TypeName(const TypeName&) = delete; \ @@ -11,7 +10,6 @@ TypeName(TypeName&&) = delete; \ void operator=(TypeName&&) = delete - #ifndef OPENSHOCK_API_DOMAIN #error "OPENSHOCK_API_DOMAIN must be defined" #endif @@ -60,6 +58,5 @@ #endif namespace OpenShock::Constants { - const char* const FW_USERAGENT = OPENSHOCK_FW_USERAGENT; - const StringView FW_USERAGENT_sv = OPENSHOCK_FW_USERAGENT ""_sv; + const char* const FW_USERAGENT = OPENSHOCK_FW_USERAGENT; } // namespace OpenShock::Constants diff --git a/include/GatewayClient.h b/include/GatewayClient.h index 87cf3d71..99012e3e 100644 --- a/include/GatewayClient.h +++ b/include/GatewayClient.h @@ -1,11 +1,10 @@ #pragma once -#include "StringView.h" - #include #include #include +#include #include namespace OpenShock { @@ -26,7 +25,7 @@ namespace OpenShock { void connect(const char* lcgFqdn); void disconnect(); - bool sendMessageTXT(StringView data); + bool sendMessageTXT(std::string_view data); bool sendMessageBIN(const uint8_t* data, std::size_t length); bool loop(); diff --git a/include/GatewayConnectionManager.h b/include/GatewayConnectionManager.h index e32cbacf..c767fb62 100644 --- a/include/GatewayConnectionManager.h +++ b/include/GatewayConnectionManager.h @@ -1,10 +1,10 @@ #pragma once #include "AccountLinkResultCode.h" -#include "StringView.h" #include #include +#include namespace OpenShock::GatewayConnectionManager { [[nodiscard]] bool Init(); @@ -12,10 +12,10 @@ namespace OpenShock::GatewayConnectionManager { bool IsConnected(); bool IsLinked(); - AccountLinkResultCode Link(StringView linkCode); + AccountLinkResultCode Link(std::string_view linkCode); void UnLink(); - bool SendMessageTXT(StringView data); + bool SendMessageTXT(std::string_view data); bool SendMessageBIN(const uint8_t* data, std::size_t length); void Update(); diff --git a/include/OtaUpdateManager.h b/include/OtaUpdateManager.h index 9b64873a..fc2b6b6a 100644 --- a/include/OtaUpdateManager.h +++ b/include/OtaUpdateManager.h @@ -3,7 +3,6 @@ #include "FirmwareBootType.h" #include "OtaUpdateChannel.h" #include "SemVer.h" -#include "StringView.h" #include #include diff --git a/include/SemVer.h b/include/SemVer.h index d7a57093..24805232 100644 --- a/include/SemVer.h +++ b/include/SemVer.h @@ -1,8 +1,8 @@ #pragma once -#include "StringView.h" - #include +#include +#include namespace OpenShock { struct SemVer { @@ -16,8 +16,8 @@ namespace OpenShock { SemVer(uint16_t major, uint16_t minor, uint16_t patch) : major(major), minor(minor), patch(patch), prerelease(), build() {} - SemVer(uint16_t major, uint16_t minor, uint16_t patch, StringView prerelease, StringView build) - : major(major), minor(minor), patch(patch), prerelease(prerelease.toString()), build(build.toString()) + SemVer(uint16_t major, uint16_t minor, uint16_t patch, std::string_view prerelease, std::string_view build) + : major(major), minor(minor), patch(patch), prerelease(std::string(prerelease)), build(std::string(build)) {} bool operator==(const SemVer& other) const { @@ -72,5 +72,5 @@ namespace OpenShock { std::string toString() const; }; - bool TryParseSemVer(StringView str, SemVer& out); -} // namespace OpenShock + bool TryParseSemVer(std::string_view str, SemVer& out); +} // namespace OpenShock diff --git a/include/StringView.h b/include/StringView.h deleted file mode 100644 index b1b77c67..00000000 --- a/include/StringView.h +++ /dev/null @@ -1,469 +0,0 @@ -#pragma once - -#include - -#include - -#include -#include -#include -#include -#include -#include - -namespace OpenShock { - struct StringView { - using value_type = char; - using const_iterator = const value_type*; - using const_reverse_iterator = std::reverse_iterator; - - static const std::size_t npos = std::numeric_limits::max(); - - static constexpr StringView Null() { return StringView(nullptr); } - static constexpr StringView Empty() { return StringView(""); } - - constexpr StringView() : _ptrBeg(nullptr), _ptrEnd(nullptr) { } - constexpr StringView(const char* const ptr) : _ptrBeg(ptr), _ptrEnd(_getStringEnd(ptr)) { } - constexpr StringView(const char* const ptr, std::size_t len) : _ptrBeg(ptr), _ptrEnd(ptr + len) { } - constexpr StringView(const char* const ptrBeg, const char* const ptrEnd) : _ptrBeg(ptrBeg), _ptrEnd(ptrEnd) { } - constexpr StringView(const StringView& str) : _ptrBeg(str._ptrBeg), _ptrEnd(str._ptrEnd) { } - inline StringView(const String& str) : _ptrBeg(str.c_str()), _ptrEnd(str.c_str() + str.length()) { } - inline StringView(const std::string& str) : _ptrBeg(str.c_str()), _ptrEnd(str.c_str() + str.size()) { } - inline StringView(const flatbuffers::String& str) : _ptrBeg(str.c_str()), _ptrEnd(str.c_str() + str.size()) { } - - constexpr bool isNull() const { return _ptrBeg == nullptr || _ptrEnd == nullptr; } - constexpr bool isEmpty() const { return _ptrBeg >= _ptrEnd; } - constexpr bool isNullOrEmpty() const { return isNull() || isEmpty(); } - - constexpr const char* data() const { return _ptrBeg; } - - constexpr const_iterator begin() const { return _ptrBeg; } - const_reverse_iterator rbegin() const { return std::make_reverse_iterator(end()); } - - constexpr const_iterator end() const { return _ptrEnd; } - const_reverse_iterator rend() const { return std::make_reverse_iterator(begin()); } - - constexpr char front() const { return *_ptrBeg; } - constexpr char back() const { return *(_ptrEnd - 1); } - - constexpr std::size_t size() const { - if (isNullOrEmpty()) { - return 0; - } - - return _ptrEnd - _ptrBeg; - } - constexpr std::size_t length() const { return size(); } - - constexpr StringView substr(std::size_t pos, std::size_t count = StringView::npos) const { - if (isNullOrEmpty()) { - return *this; - } - - if (pos > size()) { - return Null(); - } - - if (count == StringView::npos) { - count = size() - pos; - } else if (pos + count > size()) { - return Null(); - } - - return StringView(_ptrBeg + pos, _ptrBeg + pos + count); - } - - constexpr std::size_t find(char needle, std::size_t pos = 0) const { - if (isNullOrEmpty() || pos >= size()) { - return StringView::npos; - } - - std::size_t _size = this->size(); - - for (std::size_t i = pos; i < _size; ++i) { - if (_ptrBeg[i] == needle) { - return i; - } - } - - return StringView::npos; - } - inline std::size_t find(StringView needle, std::size_t pos = 0) const { - if (isNullOrEmpty() || needle.isNullOrEmpty() || pos + needle.size() >= size()) { - return StringView::npos; - } - - const char* ptr = std::search(_ptrBeg + pos, _ptrEnd, needle._ptrBeg, needle._ptrEnd); - if (ptr == _ptrEnd) { - return StringView::npos; - } - - return ptr - _ptrBeg; - } - - inline std::size_t rfind(char needle, std::size_t pos = StringView::npos) const { - if (isNullOrEmpty() || pos >= size()) { - return StringView::npos; - } - - std::size_t _size = this->size(); - - if (pos == StringView::npos) { - pos = _size - 1; - } else if (pos >= _size) { - return StringView::npos; - } - - for (std::size_t i = pos; i > 0; --i) { - if (_ptrBeg[i] == needle) { - return i; - } - } - - return StringView::npos; - } - inline std::size_t rfind(StringView needle, std::size_t pos = StringView::npos) const { - if (isNullOrEmpty() || needle.isNullOrEmpty() || pos + needle.size() >= size()) { - return StringView::npos; - } - - if (pos == StringView::npos) { - pos = size() - 1; - } else if (pos + needle.size() >= size()) { - return StringView::npos; - } - - const char* ptr = std::find_end(_ptrBeg, _ptrBeg + pos, needle._ptrBeg, needle._ptrEnd); - if (ptr == _ptrBeg + pos) { - return StringView::npos; - } - - return ptr - _ptrBeg; - } - - inline StringView beforeDelimiter(char delimiter) const { - std::size_t pos = find(delimiter); - if (pos != StringView::npos) { - return substr(0, pos); - } - - return *this; - } - inline StringView beforeDelimiter(StringView delimiter) const { - std::size_t pos = find(delimiter); - if (pos != StringView::npos) { - return substr(0, pos); - } - - return *this; - } - - inline StringView afterDelimiter(char delimiter) const { - std::size_t pos = find(delimiter); - if (pos != StringView::npos) { - return substr(pos + 1); - } - - return *this; - } - inline StringView afterDelimiter(StringView delimiter) const { - std::size_t pos = find(delimiter); - if (pos != StringView::npos) { - return substr(pos + delimiter.size()); - } - - return *this; - } - - inline std::vector split(char delimiter, std::size_t maxSplits = StringView::npos) const { - if (isNullOrEmpty()) { - return {}; - } - - std::vector result = {}; - - std::size_t pos = 0; - std::size_t splits = 0; - while (pos < size() && splits < maxSplits) { - std::size_t nextPos = find(delimiter, pos); - if (nextPos == StringView::npos) { - nextPos = size(); - } - - result.push_back(substr(pos, nextPos - pos)); - pos = nextPos + 1; - ++splits; - } - - if (pos < size()) { - result.push_back(substr(pos)); - } - - return result; - } - inline std::vector split(StringView delimiter) const { - if (isNullOrEmpty() || delimiter.isNullOrEmpty()) { - return {}; - } - - std::vector result = {}; - - std::size_t pos = 0; - while (pos < size()) { - std::size_t nextPos = find(delimiter, pos); - if (nextPos == StringView::npos) { - nextPos = size(); - } - - result.push_back(substr(pos, nextPos - pos)); - pos = nextPos + delimiter.size(); - } - - return result; - } - inline std::vector split(std::function predicate) const { - if (isNullOrEmpty()) { - return {}; - } - - std::vector result = {}; - - const char* start = nullptr; - for (const char* ptr = _ptrBeg; ptr < _ptrEnd; ++ptr) { - if (predicate(*ptr)) { - if (start != nullptr) { - result.emplace_back(StringView(start, ptr)); - start = nullptr; - } - } else if (start == nullptr) { - start = ptr; - } - } - - if (start != nullptr) { - result.emplace_back(StringView(start, _ptrEnd)); - } - - return result; - } - - inline std::vector splitLines() const { - return split([](char c) { return c == '\r' || c == '\n'; }); - } - inline std::vector splitWhitespace() const { return split(isspace); } - - constexpr bool startsWith(char needle) const { - if (isNull()) { - return false; - } - - return _ptrBeg[0] == needle; - } - constexpr bool startsWith(StringView needle) const { - if (isNull()) { - return needle.isNullOrEmpty(); - } - - return _strEquals(_ptrBeg, _ptrBeg + needle.size(), needle._ptrBeg, needle._ptrEnd); - } - - constexpr bool endsWith(char needle) const { - if (isNullOrEmpty()) { - return false; - } - - return _ptrEnd[-1] == needle; - } - constexpr bool endsWith(StringView needle) const { - if (isNullOrEmpty()) { - return needle.isNullOrEmpty(); - } - - return _strEquals(_ptrEnd - needle.size(), _ptrEnd, needle._ptrBeg, needle._ptrEnd); - } - - constexpr StringView& trimLeft() { - if (isNullOrEmpty()) { - return *this; - } - - while (_ptrBeg < _ptrEnd && isspace(*_ptrBeg)) { - ++_ptrBeg; - } - - return *this; - } - - constexpr StringView& trimRight() { - if (isNullOrEmpty()) { - return *this; - } - - while (_ptrBeg < _ptrEnd && isspace(_ptrEnd[-1])) { - --_ptrEnd; - } - - return *this; - } - - constexpr StringView& trim() { - trimLeft(); - trimRight(); - return *this; - } - - constexpr void clear() { - _ptrBeg = nullptr; - _ptrEnd = nullptr; - } - - inline String toArduinoString() const { - if (isNullOrEmpty()) { - return String(); - } - - return String(_ptrBeg, size()); - } - - inline std::string toString() const { - if (isNullOrEmpty()) { - return std::string(); - } - - return std::string(_ptrBeg, _ptrEnd); - } - - constexpr operator const char*() const { return _ptrBeg; } - - explicit operator String() const { return toArduinoString(); } - - explicit operator std::string() const { return toString(); } - - /// Returns a reference to the character at the specified index, Going out of bounds is undefined behavior - constexpr char const& operator[](int index) const { return _ptrBeg[index]; } - /// Returns a const reference to the character at the specified index, Going out of bounds is undefined behavior - constexpr char const& operator[](std::size_t index) const { return _ptrBeg[index]; } - - constexpr bool operator==(const StringView& other) { - if (this == &other) return true; - - return _strEquals(_ptrBeg, _ptrEnd, other._ptrBeg, other._ptrEnd); - } - constexpr bool operator!=(const StringView& other) { return !(*this == other); } - constexpr bool operator==(const char* const other) { return *this == StringView(other); } - constexpr bool operator!=(const char* const other) { return !(*this == other); } - inline bool operator==(const std::string& other) { return *this == StringView(other); } - inline bool operator!=(const std::string& other) { return !(*this == other); } - - inline bool operator<(const StringView& other) const { - if (this == &other) return false; - - return std::lexicographical_compare(_ptrBeg, _ptrEnd, other._ptrBeg, other._ptrEnd); - } - inline bool operator<=(const StringView& other) const { return *this < other || *this == other; } - inline bool operator>(const StringView& other) const { return !(*this <= other); } - inline bool operator>=(const StringView& other) const { return !(*this < other); } - - constexpr StringView& operator=(const char* const ptr) { - _ptrBeg = ptr; - _ptrEnd = _getStringEnd(ptr); - return *this; - } - constexpr StringView& operator=(const StringView& str) { - _ptrBeg = str._ptrBeg; - _ptrEnd = str._ptrEnd; - return *this; - } - inline StringView& operator=(const std::string& str) { - _ptrBeg = str.c_str(); - _ptrEnd = str.c_str() + str.size(); - return *this; - } - - private: - static constexpr bool _strEquals(const char* aStart, const char* aEnd, const char* bStart, const char* bEnd) { - if (aStart == bStart && aEnd == bEnd) { - return true; - } - if (aStart == nullptr || bStart == nullptr) { - return false; - } - if (aEnd == nullptr) { - aEnd = _getStringEnd(aStart); - } - if (bEnd == nullptr) { - bEnd = _getStringEnd(bStart); - } - - std::size_t aLen = aEnd - aStart; - std::size_t bLen = bEnd - bStart; - if (aLen != bLen) { - return false; - } - - while (aStart < aEnd) { - if (*aStart != *bStart) { - return false; - } - ++aStart; - ++bStart; - } - - return true; - } - static constexpr const char* _getStringEnd(const char* ptr) { - if (ptr == nullptr) { - return nullptr; - } - - while (*ptr != '\0') { - ++ptr; - } - - return ptr; - } - - const char* _ptrBeg; - const char* _ptrEnd; - }; -} // namespace OpenShock - -constexpr OpenShock::StringView operator"" _sv(const char* str, std::size_t len) { - return OpenShock::StringView(str, len); -} - -namespace std { - template<> - struct hash { - std::size_t operator()(OpenShock::StringView str) const { - std::size_t hash = 7; - - for (int i = 0; i < str.size(); ++i) { - hash = hash * 31 + str[i]; - } - - return hash; - } - }; - - struct hash_ci { - std::size_t operator()(OpenShock::StringView str) const { - std::size_t hash = 7; - - for (int i = 0; i < str.size(); ++i) { - hash = hash * 31 + tolower(str[i]); - } - - return hash; - } - }; - - template<> - struct less { - bool operator()(OpenShock::StringView a, OpenShock::StringView b) const { return a < b; } - }; - - struct equals_ci { - bool operator()(OpenShock::StringView a, OpenShock::StringView b) const { return strncasecmp(a.data(), b.data(), std::max(a.size(), b.size())) == 0; } - }; -} // namespace std diff --git a/include/config/BackendConfig.h b/include/config/BackendConfig.h index ef4b429b..1027c80e 100644 --- a/include/config/BackendConfig.h +++ b/include/config/BackendConfig.h @@ -1,14 +1,14 @@ #pragma once #include "config/ConfigBase.h" -#include "StringView.h" #include +#include namespace OpenShock::Config { struct BackendConfig : public ConfigBase { BackendConfig(); - BackendConfig(StringView domain, StringView authToken, StringView lcgOverride); + BackendConfig(std::string_view domain, std::string_view authToken, std::string_view lcgOverride); std::string domain; std::string authToken; diff --git a/include/config/Config.h b/include/config/Config.h index 6a865b3b..b22e3bec 100644 --- a/include/config/Config.h +++ b/include/config/Config.h @@ -7,9 +7,9 @@ #include "config/SerialInputConfig.h" #include "config/WiFiConfig.h" #include "config/WiFiCredentials.h" -#include "StringView.h" #include +#include #include namespace OpenShock::Config { @@ -17,7 +17,7 @@ namespace OpenShock::Config { /* GetAsJSON and SaveFromJSON are used for Reading/Writing the config file in its human-readable form. */ std::string GetAsJSON(bool withSensitiveData); - bool SaveFromJSON(StringView json); + bool SaveFromJSON(std::string_view json); /* GetAsFlatBuffer and SaveFromFlatBuffer are used for Reading/Writing the config file in its binary form. */ [[nodiscard]] flatbuffers::Offset GetAsFlatBuffer(flatbuffers::FlatBufferBuilder& builder, bool withSensitiveData); @@ -57,7 +57,7 @@ namespace OpenShock::Config { bool AnyWiFiCredentials(std::function predicate); - uint8_t AddWiFiCredentials(StringView ssid, StringView password); + uint8_t AddWiFiCredentials(std::string_view ssid, std::string_view password); bool TryGetWiFiCredentialsByID(uint8_t id, WiFiCredentials& out); bool TryGetWiFiCredentialsBySSID(const char* ssid, WiFiCredentials& out); uint8_t GetWiFiCredentialsIDbySSID(const char* ssid); @@ -70,13 +70,13 @@ namespace OpenShock::Config { bool SetOtaUpdateStep(OtaUpdateStep updateStep); bool GetBackendDomain(std::string& out); - bool SetBackendDomain(StringView domain); + bool SetBackendDomain(std::string_view domain); bool HasBackendAuthToken(); bool GetBackendAuthToken(std::string& out); - bool SetBackendAuthToken(StringView token); + bool SetBackendAuthToken(std::string_view token); bool ClearBackendAuthToken(); bool HasBackendLCGOverride(); bool GetBackendLCGOverride(std::string& out); - bool SetBackendLCGOverride(StringView lcgOverride); + bool SetBackendLCGOverride(std::string_view lcgOverride); bool ClearBackendLCGOverride(); } // namespace OpenShock::Config diff --git a/include/config/WiFiConfig.h b/include/config/WiFiConfig.h index f8958d40..f3671608 100644 --- a/include/config/WiFiConfig.h +++ b/include/config/WiFiConfig.h @@ -2,15 +2,15 @@ #include "config/ConfigBase.h" #include "config/WiFiCredentials.h" -#include "StringView.h" #include +#include #include namespace OpenShock::Config { struct WiFiConfig : public ConfigBase { WiFiConfig(); - WiFiConfig(StringView accessPointSSID, StringView hostname, const std::vector& credentialsList); + WiFiConfig(std::string_view accessPointSSID, std::string_view hostname, const std::vector& credentialsList); std::string accessPointSSID; std::string hostname; diff --git a/include/config/WiFiCredentials.h b/include/config/WiFiCredentials.h index b25c0767..c072d2e3 100644 --- a/include/config/WiFiCredentials.h +++ b/include/config/WiFiCredentials.h @@ -1,14 +1,14 @@ #pragma once #include "config/ConfigBase.h" -#include "StringView.h" #include +#include namespace OpenShock::Config { struct WiFiCredentials : public ConfigBase { WiFiCredentials(); - WiFiCredentials(uint8_t id, StringView ssid, StringView password); + WiFiCredentials(uint8_t id, std::string_view ssid, std::string_view password); uint8_t id; std::string ssid; diff --git a/include/http/HTTPRequestManager.h b/include/http/HTTPRequestManager.h index 8b82f2a4..26402f0d 100644 --- a/include/http/HTTPRequestManager.h +++ b/include/http/HTTPRequestManager.h @@ -1,11 +1,12 @@ #pragma once -#include "StringView.h" +#include #include #include #include +#include #include namespace OpenShock::HTTP { @@ -33,11 +34,11 @@ namespace OpenShock::HTTP { using GotContentLengthCallback = std::function; using DownloadCallback = std::function; - Response Download(StringView url, const std::map& headers, GotContentLengthCallback contentLengthCallback, DownloadCallback downloadCallback, const std::vector& acceptedCodes = {200}, uint32_t timeoutMs = 10'000); - Response GetString(StringView url, const std::map& headers, const std::vector& acceptedCodes = {200}, uint32_t timeoutMs = 10'000); + Response Download(std::string_view url, const std::map& headers, GotContentLengthCallback contentLengthCallback, DownloadCallback downloadCallback, const std::vector& acceptedCodes = {200}, uint32_t timeoutMs = 10'000); + Response GetString(std::string_view url, const std::map& headers, const std::vector& acceptedCodes = {200}, uint32_t timeoutMs = 10'000); template - Response GetJSON(StringView url, const std::map& headers, JsonParser jsonParser, const std::vector& acceptedCodes = {200}, uint32_t timeoutMs = 10'000) { + Response GetJSON(std::string_view url, const std::map& headers, JsonParser jsonParser, const std::vector& acceptedCodes = {200}, uint32_t timeoutMs = 10'000) { auto response = GetString(url, headers, acceptedCodes, timeoutMs); if (response.result != RequestResult::Success) { return {response.result, response.code, {}}; diff --git a/include/http/JsonAPI.h b/include/http/JsonAPI.h index 934c50a0..43b8070d 100644 --- a/include/http/JsonAPI.h +++ b/include/http/JsonAPI.h @@ -3,19 +3,21 @@ #include "http/HTTPRequestManager.h" #include "serialization/JsonAPI.h" +#include + namespace OpenShock::HTTP::JsonAPI { /// @brief Links the device to the account with the given account link code, returns the device token. Valid response codes: 200, 404 /// @param deviceToken /// @return - HTTP::Response LinkAccount(const char* accountLinkCode); + HTTP::Response LinkAccount(std::string_view accountLinkCode); /// @brief Gets the device info for the given device token. Valid response codes: 200, 401 /// @param deviceToken /// @return - HTTP::Response GetDeviceInfo(StringView deviceToken); + HTTP::Response GetDeviceInfo(std::string_view deviceToken); /// @brief Requests a Live Control Gateway to connect to. Valid response codes: 200, 401 /// @param deviceToken /// @return - HTTP::Response AssignLcg(StringView deviceToken); + HTTP::Response AssignLcg(std::string_view deviceToken); } // namespace OpenShock::HTTP::JsonAPI diff --git a/include/intconv.h b/include/intconv.h index 5f41e877..f0074383 100644 --- a/include/intconv.h +++ b/include/intconv.h @@ -1,16 +1,15 @@ #pragma once -#include "StringView.h" - #include +#include namespace OpenShock::IntConv { - bool stoi8(OpenShock::StringView str, int8_t& val); - bool stou8(OpenShock::StringView str, uint8_t& val); - bool stoi16(OpenShock::StringView str, int16_t& val); - bool stou16(OpenShock::StringView str, uint16_t& val); - bool stoi32(OpenShock::StringView str, int32_t& val); - bool stou32(OpenShock::StringView str, uint32_t& val); - bool stoi64(OpenShock::StringView str, int64_t& val); - bool stou64(OpenShock::StringView str, uint64_t& val); + bool stoi8(std::string_view str, int8_t& val); + bool stou8(std::string_view str, uint8_t& val); + bool stoi16(std::string_view str, int16_t& val); + bool stou16(std::string_view str, uint16_t& val); + bool stoi32(std::string_view str, int32_t& val); + bool stou32(std::string_view str, uint32_t& val); + bool stoi64(std::string_view str, int64_t& val); + bool stou64(std::string_view str, uint64_t& val); } // namespace OpenShock::IntConv diff --git a/include/serialization/WSGateway.h b/include/serialization/WSGateway.h index 770bf9a4..72f52faf 100644 --- a/include/serialization/WSGateway.h +++ b/include/serialization/WSGateway.h @@ -3,14 +3,15 @@ #include "FirmwareBootType.h" #include "SemVer.h" #include "serialization/CallbackFn.h" -#include "StringView.h" #include "serialization/_fbs/HubToGatewayMessage_generated.h" +#include + namespace OpenShock::Serialization::Gateway { bool SerializeKeepAliveMessage(Common::SerializationCallbackFn callback); bool SerializeBootStatusMessage(int32_t otaUpdateId, OpenShock::FirmwareBootType bootType, const OpenShock::SemVer& version, Common::SerializationCallbackFn callback); bool SerializeOtaInstallStartedMessage(int32_t updateId, const OpenShock::SemVer& version, Common::SerializationCallbackFn callback); bool SerializeOtaInstallProgressMessage(int32_t updateId, Gateway::OtaInstallProgressTask task, float progress, Common::SerializationCallbackFn callback); - bool SerializeOtaInstallFailedMessage(int32_t updateId, StringView message, bool fatal, Common::SerializationCallbackFn callback); + bool SerializeOtaInstallFailedMessage(int32_t updateId, std::string_view message, bool fatal, Common::SerializationCallbackFn callback); } // namespace OpenShock::Serialization::Gateway diff --git a/include/util/IPAddressUtils.h b/include/util/IPAddressUtils.h index ee5eadae..d9cfe9c9 100644 --- a/include/util/IPAddressUtils.h +++ b/include/util/IPAddressUtils.h @@ -2,8 +2,8 @@ #include -#include "StringView.h" +#include namespace OpenShock { - bool IPV4AddressFromStringView(IPAddress& ip, StringView sv); + bool IPV4AddressFromStringView(IPAddress& ip, std::string_view sv); } diff --git a/include/util/PartitionUtils.h b/include/util/PartitionUtils.h index b99b7843..22669020 100644 --- a/include/util/PartitionUtils.h +++ b/include/util/PartitionUtils.h @@ -1,13 +1,12 @@ #pragma once -#include "StringView.h" - #include #include #include +#include namespace OpenShock { bool TryGetPartitionHash(const esp_partition_t* partition, char (&hash)[65]); - bool FlashPartitionFromUrl(const esp_partition_t* partition, StringView remoteUrl, const uint8_t (&remoteHash)[32], std::function progressCallback = nullptr); + bool FlashPartitionFromUrl(const esp_partition_t* partition, std::string_view remoteUrl, const uint8_t (&remoteHash)[32], std::function progressCallback = nullptr); } diff --git a/include/util/StringUtils.h b/include/util/StringUtils.h index 1b2cc8c0..08feb6e5 100644 --- a/include/util/StringUtils.h +++ b/include/util/StringUtils.h @@ -1,8 +1,66 @@ #pragma once -#include +#include + #include +#include +#include +#include +#include namespace OpenShock { bool FormatToString(std::string& out, const char* format, ...); -} // namespace OpenShock + + constexpr std::string_view StringTrimLeft(const std::string_view view) { + if (view.empty()) { + return view; + } + + std::size_t pos = 0; + while (pos < view.size() && isspace(view[pos])) { + ++pos; + } + + return view.substr(pos); + } + constexpr std::string_view StringTrimRight(const std::string_view view) { + if (view.empty()) { + return view; + } + + std::size_t pos = view.size() - 1; + while (pos > 0 && isspace(view[pos])) { + --pos; + } + + return view.substr(0, pos + 1); + } + constexpr std::string_view StringTrim(const std::string_view view) { + return StringTrimLeft(StringTrimRight(view)); + } + constexpr bool StringStartsWith(const std::string_view view, std::string_view prefix) { + return view.size() >= prefix.size() && view.substr(0, prefix.size()) == prefix; + } + template + constexpr bool TryStringSplit(const std::string_view view, char delimiter, std::string_view (&out)[N]) { + std::size_t pos = 0; + std::size_t idx = 0; + while (pos < view.size() && idx < N) { + std::size_t nextPos = view.find(delimiter, pos); + if (nextPos == std::string_view::npos) { + nextPos = view.size(); + } + + out[idx] = view.substr(pos, nextPos - pos); + pos = nextPos + 1; + ++idx; + } + + return idx == N; + } + std::vector StringSplit(const std::string_view view, char delimiter, std::size_t maxSplits = std::numeric_limits::max()); + std::vector StringSplit(const std::string_view view, bool (*predicate)(char delimiter), std::size_t maxSplits = std::numeric_limits::max()); + std::vector StringSplitNewLines(const std::string_view view, std::size_t maxSplits = std::numeric_limits::max()); + std::vector StringSplitWhiteSpace(const std::string_view view, std::size_t maxSplits = std::numeric_limits::max()); + String StringToArduinoString(std::string_view view); +} // namespace OpenShock diff --git a/include/wifi/WiFiManager.h b/include/wifi/WiFiManager.h index 36054e0f..82157a49 100644 --- a/include/wifi/WiFiManager.h +++ b/include/wifi/WiFiManager.h @@ -1,10 +1,10 @@ #pragma once #include "wifi/WiFiNetwork.h" -#include "StringView.h" #include #include +#include #include namespace OpenShock::WiFiManager { @@ -16,7 +16,7 @@ namespace OpenShock::WiFiManager { /// @param ssid SSID of the network /// @param password Password of the network /// @return True if the network was saved successfully - bool Save(const char* ssid, StringView password); + bool Save(const char* ssid, std::string_view password); /// @brief Removes a network from the config by it's SSID /// @param ssid SSID of the network diff --git a/src/CaptivePortal.cpp b/src/CaptivePortal.cpp index 6cd68910..9698ca5f 100644 --- a/src/CaptivePortal.cpp +++ b/src/CaptivePortal.cpp @@ -146,7 +146,7 @@ void CaptivePortal::Update() { } } -bool CaptivePortal::SendMessageTXT(uint8_t socketId, StringView data) { +bool CaptivePortal::SendMessageTXT(uint8_t socketId, std::string_view data) { if (s_instance == nullptr) return false; s_instance->sendMessageTXT(socketId, data); @@ -161,7 +161,7 @@ bool CaptivePortal::SendMessageBIN(uint8_t socketId, const uint8_t* data, std::s return true; } -bool CaptivePortal::BroadcastMessageTXT(StringView data) { +bool CaptivePortal::BroadcastMessageTXT(std::string_view data) { if (s_instance == nullptr) return false; s_instance->broadcastMessageTXT(data); diff --git a/src/EStopManager.cpp b/src/EStopManager.cpp index 1582540d..676acf45 100644 --- a/src/EStopManager.cpp +++ b/src/EStopManager.cpp @@ -12,6 +12,7 @@ const char* const TAG = "EStopManager"; #include "VisualStateManager.h" #include +#include #include using namespace OpenShock; diff --git a/src/GatewayClient.cpp b/src/GatewayClient.cpp index a42f2dea..876642ae 100644 --- a/src/GatewayClient.cpp +++ b/src/GatewayClient.cpp @@ -64,7 +64,7 @@ void GatewayClient::disconnect() { m_webSocket.disconnect(); } -bool GatewayClient::sendMessageTXT(StringView data) { +bool GatewayClient::sendMessageTXT(std::string_view data) { if (m_state != State::Connected) { return false; } diff --git a/src/GatewayConnectionManager.cpp b/src/GatewayConnectionManager.cpp index 95811fd9..a21dfd94 100644 --- a/src/GatewayConnectionManager.cpp +++ b/src/GatewayConnectionManager.cpp @@ -76,7 +76,7 @@ bool GatewayConnectionManager::IsLinked() { return (s_flags & FLAG_LINKED) != 0; } -AccountLinkResultCode GatewayConnectionManager::Link(StringView linkCode) { +AccountLinkResultCode GatewayConnectionManager::Link(std::string_view linkCode) { if ((s_flags & FLAG_HAS_IP) == 0) { return AccountLinkResultCode::NoInternetConnection; } @@ -109,9 +109,9 @@ AccountLinkResultCode GatewayConnectionManager::Link(StringView linkCode) { return AccountLinkResultCode::InternalError; } - StringView authToken = response.data.authToken; + std::string_view authToken = response.data.authToken; - if (authToken.isNullOrEmpty()) { + if (authToken.empty()) { OS_LOGE(TAG, "Received empty auth token"); return AccountLinkResultCode::InternalError; } @@ -132,7 +132,7 @@ void GatewayConnectionManager::UnLink() { Config::ClearBackendAuthToken(); } -bool GatewayConnectionManager::SendMessageTXT(StringView data) { +bool GatewayConnectionManager::SendMessageTXT(std::string_view data) { if (s_wsClient == nullptr) { return false; } @@ -148,7 +148,7 @@ bool GatewayConnectionManager::SendMessageBIN(const uint8_t* data, std::size_t l return s_wsClient->sendMessageBIN(data, length); } -bool FetchDeviceInfo(StringView authToken) { +bool FetchDeviceInfo(std::string_view authToken) { // TODO: this function is very slow, should be optimized! if ((s_flags & FLAG_HAS_IP) == 0) { return false; diff --git a/src/OtaUpdateManager.cpp b/src/OtaUpdateManager.cpp index 5d92c4cb..907bda9a 100644 --- a/src/OtaUpdateManager.cpp +++ b/src/OtaUpdateManager.cpp @@ -11,7 +11,6 @@ const char* const TAG = "OtaUpdateManager"; #include "Logging.h" #include "SemVer.h" #include "serialization/WSGateway.h" -#include "StringView.h" #include "Time.h" #include "util/HexUtils.h" #include "util/PartitionUtils.h" @@ -26,6 +25,9 @@ const char* const TAG = "OtaUpdateManager"; #include #include +#include + +using namespace std::string_view_literals; #define OPENSHOCK_FW_CDN_CHANNEL_URL(ch) OPENSHOCK_FW_CDN_URL("/version-" ch ".txt") @@ -116,7 +118,7 @@ bool _sendProgressMessage(Serialization::Gateway::OtaInstallProgressTask task, f return true; } -bool _sendFailureMessage(StringView message, bool fatal = false) { +bool _sendFailureMessage(std::string_view message, bool fatal = false) { int32_t updateId; if (!Config::GetOtaUpdateId(updateId)) { OS_LOGE(TAG, "Failed to get OTA update ID"); @@ -131,7 +133,7 @@ bool _sendFailureMessage(StringView message, bool fatal = false) { return true; } -bool _flashAppPartition(const esp_partition_t* partition, StringView remoteUrl, const uint8_t (&remoteHash)[32]) { +bool _flashAppPartition(const esp_partition_t* partition, std::string_view remoteUrl, const uint8_t (&remoteHash)[32]) { OS_LOGD(TAG, "Flashing app partition"); if (!_sendProgressMessage(Serialization::Gateway::OtaInstallProgressTask::FlashingApplication, 0.0f)) { @@ -148,7 +150,7 @@ bool _flashAppPartition(const esp_partition_t* partition, StringView remoteUrl, if (!OpenShock::FlashPartitionFromUrl(partition, remoteUrl, remoteHash, onProgress)) { OS_LOGE(TAG, "Failed to flash app partition"); - _sendFailureMessage("Failed to flash app partition"_sv); + _sendFailureMessage("Failed to flash app partition"sv); return false; } @@ -159,14 +161,14 @@ bool _flashAppPartition(const esp_partition_t* partition, StringView remoteUrl, // Set app partition bootable. if (esp_ota_set_boot_partition(partition) != ESP_OK) { OS_LOGE(TAG, "Failed to set app partition bootable"); - _sendFailureMessage("Failed to set app partition bootable"_sv); + _sendFailureMessage("Failed to set app partition bootable"sv); return false; } return true; } -bool _flashFilesystemPartition(const esp_partition_t* parition, StringView remoteUrl, const uint8_t (&remoteHash)[32]) { +bool _flashFilesystemPartition(const esp_partition_t* parition, std::string_view remoteUrl, const uint8_t (&remoteHash)[32]) { if (!_sendProgressMessage(Serialization::Gateway::OtaInstallProgressTask::PreparingForInstall, 0.0f)) { return false; } @@ -174,7 +176,7 @@ bool _flashFilesystemPartition(const esp_partition_t* parition, StringView remot // Make sure captive portal is stopped, timeout after 5 seconds. if (!CaptivePortal::ForceClose(5000U)) { OS_LOGE(TAG, "Failed to force close captive portal (timed out)"); - _sendFailureMessage("Failed to force close captive portal (timed out)"_sv); + _sendFailureMessage("Failed to force close captive portal (timed out)"sv); return false; } @@ -194,7 +196,7 @@ bool _flashFilesystemPartition(const esp_partition_t* parition, StringView remot if (!OpenShock::FlashPartitionFromUrl(parition, remoteUrl, remoteHash, onProgress)) { OS_LOGE(TAG, "Failed to flash filesystem partition"); - _sendFailureMessage("Failed to flash filesystem partition"_sv); + _sendFailureMessage("Failed to flash filesystem partition"sv); return false; } @@ -206,7 +208,7 @@ bool _flashFilesystemPartition(const esp_partition_t* parition, StringView remot fs::LittleFSFS test; if (!test.begin(false, "/static", 10, "static0")) { OS_LOGE(TAG, "Failed to mount filesystem"); - _sendFailureMessage("Failed to mount filesystem"_sv); + _sendFailureMessage("Failed to mount filesystem"sv); return false; } test.end(); @@ -334,7 +336,7 @@ void _otaUpdateTask(void* arg) { OtaUpdateManager::FirmwareRelease release; if (!OtaUpdateManager::TryGetFirmwareRelease(version, release)) { OS_LOGE(TAG, "Failed to fetch firmware release"); // TODO: Send error message to server - _sendFailureMessage("Failed to fetch firmware release"_sv); + _sendFailureMessage("Failed to fetch firmware release"sv); continue; } @@ -350,7 +352,7 @@ void _otaUpdateTask(void* arg) { const esp_partition_t* appPartition = esp_ota_get_next_update_partition(nullptr); if (appPartition == nullptr) { OS_LOGE(TAG, "Failed to get app update partition"); // TODO: Send error message to server - _sendFailureMessage("Failed to get app update partition"_sv); + _sendFailureMessage("Failed to get app update partition"sv); continue; } @@ -358,7 +360,7 @@ void _otaUpdateTask(void* arg) { const esp_partition_t* filesystemPartition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, "static0"); if (filesystemPartition == nullptr) { OS_LOGE(TAG, "Failed to find filesystem partition"); // TODO: Send error message to server - _sendFailureMessage("Failed to find filesystem partition"_sv); + _sendFailureMessage("Failed to find filesystem partition"sv); continue; } @@ -373,7 +375,7 @@ void _otaUpdateTask(void* arg) { // Set OTA boot type in config. if (!Config::SetOtaUpdateStep(OpenShock::OtaUpdateStep::Updated)) { OS_LOGE(TAG, "Failed to set OTA update step"); - _sendFailureMessage("Failed to set OTA update step"_sv); + _sendFailureMessage("Failed to set OTA update step"sv); continue; } @@ -393,7 +395,7 @@ void _otaUpdateTask(void* arg) { esp_restart(); } -bool _tryGetStringList(StringView url, std::vector& list) { +bool _tryGetStringList(std::string_view url, std::vector& list) { auto response = OpenShock::HTTP::GetString( url, { @@ -408,19 +410,19 @@ bool _tryGetStringList(StringView url, std::vector& list) { list.clear(); - OpenShock::StringView data = response.data; + std::string_view data = response.data; - auto lines = data.splitLines(); + auto lines = OpenShock::StringSplitNewLines(data); list.reserve(lines.size()); for (auto line : lines) { - line = line.trim(); + line = OpenShock::StringTrim(line); - if (line.isNullOrEmpty()) { + if (line.empty()) { continue; } - list.push_back(line.toString()); + list.push_back(std::string(line)); } return true; @@ -483,16 +485,16 @@ bool OtaUpdateManager::Init() { } bool OtaUpdateManager::TryGetFirmwareVersion(OtaUpdateChannel channel, OpenShock::SemVer& version) { - StringView channelIndexUrl; + std::string_view channelIndexUrl; switch (channel) { case OtaUpdateChannel::Stable: - channelIndexUrl = StringView(OPENSHOCK_FW_CDN_STABLE_URL); + channelIndexUrl = std::string_view(OPENSHOCK_FW_CDN_STABLE_URL); break; case OtaUpdateChannel::Beta: - channelIndexUrl = StringView(OPENSHOCK_FW_CDN_BETA_URL); + channelIndexUrl = std::string_view(OPENSHOCK_FW_CDN_BETA_URL); break; case OtaUpdateChannel::Develop: - channelIndexUrl = StringView(OPENSHOCK_FW_CDN_DEVELOP_URL); + channelIndexUrl = std::string_view(OPENSHOCK_FW_CDN_DEVELOP_URL); break; default: OS_LOGE(TAG, "Unknown channel: %u", channel); @@ -538,7 +540,7 @@ bool OtaUpdateManager::TryGetFirmwareBoards(const OpenShock::SemVer& version, st return true; } -bool _tryParseIntoHash(StringView hash, uint8_t (&hashBytes)[32]) { +bool _tryParseIntoHash(std::string_view hash, uint8_t (&hashBytes)[32]) { if (!HexUtils::TryParseHex(hash.data(), hash.size(), hashBytes, 32)) { OS_LOGE(TAG, "Failed to parse hash: %.*s", hash.size(), hash.data()); return false; @@ -580,21 +582,21 @@ bool OtaUpdateManager::TryGetFirmwareRelease(const OpenShock::SemVer& version, F return false; } - auto hashesLines = OpenShock::StringView(sha256HashesResponse.data).splitLines(); + auto hashesLines = OpenShock::StringSplitNewLines(sha256HashesResponse.data); // Parse hashes. bool foundAppHash = false, foundFilesystemHash = false; - for (OpenShock::StringView line : hashesLines) { - auto parts = line.splitWhitespace(); + for (std::string_view line : hashesLines) { + auto parts = OpenShock::StringSplitWhiteSpace(line); if (parts.size() != 2) { OS_LOGE(TAG, "Invalid hashes entry: %.*s", line.size(), line.data()); return false; } - auto hash = parts[0].trim(); - auto file = parts[1].trim(); + auto hash = OpenShock::StringTrim(parts[0]); + auto file = OpenShock::StringTrim(parts[1]); - if (file.startsWith("./"_sv)) { + if (OpenShock::StringStartsWith(file, "./"sv)) { file = file.substr(2); } diff --git a/src/SemVer.cpp b/src/SemVer.cpp index 35fa0609..4d9d544d 100644 --- a/src/SemVer.cpp +++ b/src/SemVer.cpp @@ -3,6 +3,7 @@ const char* const TAG = "SemVer"; #include "Logging.h" +#include "util/StringUtils.h" using namespace OpenShock; @@ -15,8 +16,8 @@ constexpr bool _semverIsPositiveDigit(char c) { constexpr bool _semverIsDigit(char c) { return c == '0' || _semverIsPositiveDigit(c); } -constexpr bool _semverIsDigits(StringView str) { - if (str.isNullOrEmpty()) { +constexpr bool _semverIsDigits(std::string_view str) { + if (str.empty()) { return false; } @@ -34,8 +35,8 @@ constexpr bool _semverIsNonDigit(char c) { constexpr bool _semverIsIdentifierChararacter(char c) { return _semverIsDigit(c) || _semverIsNonDigit(c); } -constexpr bool _semverIsIdentifierChararacters(StringView str) { - if (str.isNullOrEmpty()) { +constexpr bool _semverIsIdentifierChararacters(std::string_view str) { + if (str.empty()) { return false; } @@ -47,8 +48,8 @@ constexpr bool _semverIsIdentifierChararacters(StringView str) { return true; } -constexpr bool _semverIsNumericIdentifier(StringView str) { - if (str.isNullOrEmpty()) { +constexpr bool _semverIsNumericIdentifier(std::string_view str) { + if (str.empty()) { return false; } @@ -58,8 +59,8 @@ constexpr bool _semverIsNumericIdentifier(StringView str) { return _semverIsPositiveDigit(str[0]) && _semverIsDigits(str.substr(1)); } -constexpr bool _semverIsAlphanumericIdentifier(StringView str) { - if (str.isNullOrEmpty()) { +constexpr bool _semverIsAlphanumericIdentifier(std::string_view str) { + if (str.empty()) { return false; } @@ -67,7 +68,7 @@ constexpr bool _semverIsAlphanumericIdentifier(StringView str) { return _semverIsNonDigit(str[0]); } - std::size_t nonDigitPos = StringView::npos; + std::size_t nonDigitPos = std::string_view::npos; for (std::size_t i = 0; i < str.length(); ++i) { if (_semverIsNonDigit(str[i])) { nonDigitPos = i; @@ -75,7 +76,7 @@ constexpr bool _semverIsAlphanumericIdentifier(StringView str) { } } - if (nonDigitPos == StringView::npos) { + if (nonDigitPos == std::string_view::npos) { return false; } @@ -93,19 +94,19 @@ constexpr bool _semverIsAlphanumericIdentifier(StringView str) { return _semverIsIdentifierChararacters(before) && _semverIsIdentifierChararacters(after); } -constexpr bool _semverIsBuildIdentifier(StringView str) { +constexpr bool _semverIsBuildIdentifier(std::string_view str) { return _semverIsAlphanumericIdentifier(str) || _semverIsDigits(str); } -constexpr bool _semverIsPrereleaseIdentifier(StringView str) { +constexpr bool _semverIsPrereleaseIdentifier(std::string_view str) { return _semverIsAlphanumericIdentifier(str) || _semverIsNumericIdentifier(str); } -constexpr bool _semverIsDotSeperatedBuildIdentifiers(StringView str) { - if (str.isNullOrEmpty()) { +constexpr bool _semverIsDotSeperatedBuildIdentifiers(std::string_view str) { + if (str.empty()) { return false; } auto dotIdx = str.find('.'); - while (dotIdx != StringView::npos) { + while (dotIdx != std::string_view::npos) { auto part = str.substr(0, dotIdx); if (!_semverIsBuildIdentifier(part)) { return false; @@ -117,13 +118,13 @@ constexpr bool _semverIsDotSeperatedBuildIdentifiers(StringView str) { return _semverIsBuildIdentifier(str); } -constexpr bool _semverIsDotSeperatedPreleaseIdentifiers(StringView str) { - if (str.isNullOrEmpty()) { +constexpr bool _semverIsDotSeperatedPreleaseIdentifiers(std::string_view str) { + if (str.empty()) { return false; } auto dotIdx = str.find('.'); - while (dotIdx != StringView::npos) { + while (dotIdx != std::string_view::npos) { auto part = str.substr(0, dotIdx); if (!_semverIsPrereleaseIdentifier(part)) { return false; @@ -139,52 +140,52 @@ const auto _semverIsPatch = _semverIsNumericIdentifier; const auto _semverIsMinor = _semverIsNumericIdentifier; const auto _semverIsMajor = _semverIsNumericIdentifier; const auto _semverIsPrerelease = _semverIsDotSeperatedPreleaseIdentifiers; -const auto _semverIsBuild = _semverIsDotSeperatedBuildIdentifiers; -bool _semverIsVersionCore(StringView str) { - if (str.isNullOrEmpty()) { +const auto _semverIsBuild = _semverIsDotSeperatedBuildIdentifiers; +bool _semverIsVersionCore(std::string_view str) { + if (str.empty()) { return false; } - auto parts = str.split('.'); - if (parts.size() != 3) { + std::string_view parts[3]; + if (!OpenShock::TryStringSplit(str, '.', parts)) { return false; } return _semverIsMajor(parts[0]) && _semverIsMinor(parts[1]) && _semverIsPatch(parts[2]); } -bool _semverIsSemver(StringView str) { - if (str.isNullOrEmpty()) { +bool _semverIsSemver(std::string_view str) { + if (str.empty()) { return false; } auto dashPos = str.find('-'); auto plusPos = str.find('+'); - if (dashPos == StringView::npos && plusPos == StringView::npos) { + if (dashPos == std::string_view::npos && plusPos == std::string_view::npos) { return _semverIsVersionCore(str); } - if (dashPos != StringView::npos && plusPos != StringView::npos) { + if (dashPos != std::string_view::npos && plusPos != std::string_view::npos) { if (dashPos > plusPos) { return false; } - auto core = str.substr(0, dashPos); + auto core = str.substr(0, dashPos); auto prerelease = str.substr(dashPos + 1, plusPos - dashPos - 1); - auto build = str.substr(plusPos + 1); + auto build = str.substr(plusPos + 1); return _semverIsVersionCore(core) && _semverIsPrerelease(prerelease) && _semverIsBuild(build); } - if (dashPos != StringView::npos) { - auto core = str.substr(0, dashPos); + if (dashPos != std::string_view::npos) { + auto core = str.substr(0, dashPos); auto prerelease = str.substr(dashPos + 1); return _semverIsVersionCore(core) && _semverIsPrerelease(prerelease); } - if (plusPos != StringView::npos) { - auto core = str.substr(0, plusPos); + if (plusPos != std::string_view::npos) { + auto core = str.substr(0, plusPos); auto build = str.substr(plusPos + 1); return _semverIsVersionCore(core) && _semverIsBuild(build); @@ -193,8 +194,8 @@ bool _semverIsSemver(StringView str) { return false; } -bool _tryParseU16(OpenShock::StringView str, uint16_t& out) { - if (str.isNullOrEmpty()) { +bool _tryParseU16(std::string_view str, uint16_t& out) { + if (str.empty()) { return false; } @@ -252,24 +253,24 @@ std::string SemVer::toString() const { return str; } -bool OpenShock::TryParseSemVer(StringView semverStr, SemVer& semver) { - auto parts = semverStr.split('.'); - if (parts.size() < 3) { - OS_LOGE(TAG, "Must have at least 3 parts: %.*s", semverStr.length(), semverStr.data()); +bool OpenShock::TryParseSemVer(std::string_view semverStr, SemVer& semver) { + std::string_view parts[3]; + if (!OpenShock::TryStringSplit(semverStr, '.', parts)) { + OS_LOGE(TAG, "Failed to split version string: %.*s", semverStr.length(), semverStr.data()); return false; } - StringView majorStr = parts[0], minorStr = parts[1], patchStr = parts[2]; + std::string_view majorStr = parts[0], minorStr = parts[1], patchStr = parts[2]; auto dashIdx = patchStr.find('-'); - if (dashIdx != StringView::npos) { + if (dashIdx != std::string_view::npos) { semver.prerelease = patchStr.substr(dashIdx + 1); patchStr = patchStr.substr(0, dashIdx); } auto plusIdx = semver.prerelease.find('+'); - if (plusIdx != StringView::npos) { - semver.build = semver.prerelease.substr(plusIdx + 1); + if (plusIdx != std::string_view::npos) { + semver.build = semver.prerelease.substr(plusIdx + 1); semver.prerelease = semver.prerelease.substr(0, plusIdx); } diff --git a/src/config/BackendConfig.cpp b/src/config/BackendConfig.cpp index e004f2a2..0527d750 100644 --- a/src/config/BackendConfig.cpp +++ b/src/config/BackendConfig.cpp @@ -9,7 +9,7 @@ using namespace OpenShock::Config; BackendConfig::BackendConfig() : domain(OPENSHOCK_API_DOMAIN), authToken(), lcgOverride() { } -BackendConfig::BackendConfig(StringView domain, StringView authToken, StringView lcgOverride) : domain(domain.toString()), authToken(authToken.toString()), lcgOverride(lcgOverride.toString()) { } +BackendConfig::BackendConfig(std::string_view domain, std::string_view authToken, std::string_view lcgOverride) : domain(std::string(domain)), authToken(std::string(authToken)), lcgOverride(std::string(lcgOverride)) { } void BackendConfig::ToDefault() { domain = OPENSHOCK_API_DOMAIN; diff --git a/src/config/Config.cpp b/src/config/Config.cpp index c2a2f544..e52ee480 100644 --- a/src/config/Config.cpp +++ b/src/config/Config.cpp @@ -169,7 +169,7 @@ std::string Config::GetAsJSON(bool withSensitiveData) { return result; } -bool Config::SaveFromJSON(StringView json) { +bool Config::SaveFromJSON(std::string_view json) { cJSON* root = cJSON_ParseWithLength(json.data(), json.size()); if (root == nullptr) { OS_LOGE(TAG, "Failed to parse JSON: %s", cJSON_GetErrorPtr()); @@ -385,7 +385,7 @@ bool Config::AnyWiFiCredentials(std::function& credentialsList) : accessPointSSID(accessPointSSID.toString()), hostname(hostname.toString()), credentialsList(credentialsList) { } +WiFiConfig::WiFiConfig(std::string_view accessPointSSID, std::string_view hostname, const std::vector& credentialsList) : accessPointSSID(std::string(accessPointSSID)), hostname(std::string(hostname)), credentialsList(credentialsList) { } void WiFiConfig::ToDefault() { accessPointSSID = OPENSHOCK_FW_AP_PREFIX; diff --git a/src/config/WiFiCredentials.cpp b/src/config/WiFiCredentials.cpp index 836c6afb..30ce6a31 100644 --- a/src/config/WiFiCredentials.cpp +++ b/src/config/WiFiCredentials.cpp @@ -10,7 +10,7 @@ using namespace OpenShock::Config; WiFiCredentials::WiFiCredentials() : id(0), ssid(), password() { } -WiFiCredentials::WiFiCredentials(uint8_t id, StringView ssid, StringView password) : id(id), ssid(ssid.toString()), password(password.toString()) { } +WiFiCredentials::WiFiCredentials(uint8_t id, std::string_view ssid, std::string_view password) : id(id), ssid(std::string(ssid)), password(std::string(password)) { } void WiFiCredentials::ToDefault() { id = 0; diff --git a/src/config/internal/utils.cpp b/src/config/internal/utils.cpp index 69d3f916..bfde56e2 100644 --- a/src/config/internal/utils.cpp +++ b/src/config/internal/utils.cpp @@ -53,7 +53,7 @@ bool Config::Internal::Utils::FromFbsIPAddress(IPAddress& ip, const flatbuffers: return false; } - StringView view(*fbsIP); + std::string_view view(*fbsIP); if (!OpenShock::IPV4AddressFromStringView(ip, view)) { OS_LOGE(TAG, "failed to parse IP address"); @@ -121,7 +121,7 @@ bool Config::Internal::Utils::FromJsonIPAddress(IPAddress& ip, const cJSON* json return false; } - StringView view(jsonVal->valuestring); + std::string_view view(jsonVal->valuestring); if (!OpenShock::IPV4AddressFromStringView(ip, view)) { OS_LOGE(TAG, "failed to parse IP address at '%s'", name); diff --git a/src/event_handlers/websocket/gateway/OtaInstall.cpp b/src/event_handlers/websocket/gateway/OtaInstall.cpp index 175ec29b..55812ce1 100644 --- a/src/event_handlers/websocket/gateway/OtaInstall.cpp +++ b/src/event_handlers/websocket/gateway/OtaInstall.cpp @@ -23,12 +23,12 @@ void _Private::HandleOtaInstall(const OpenShock::Serialization::Gateway::Gateway return; } - StringView prerelease, build; + std::string_view prerelease, build; if (semver->prerelease() != nullptr) { - prerelease = StringView(semver->prerelease()->c_str(), semver->prerelease()->size()); + prerelease = std::string_view(semver->prerelease()->c_str(), semver->prerelease()->size()); } if (semver->build() != nullptr) { - build = StringView(semver->build()->c_str(), semver->build()->size()); + build = std::string_view(semver->build()->c_str(), semver->build()->size()); } OpenShock::SemVer version(semver->major(), semver->minor(), semver->patch(), prerelease, build); diff --git a/src/http/HTTPRequestManager.cpp b/src/http/HTTPRequestManager.cpp index ebcd9619..751a36fc 100644 --- a/src/http/HTTPRequestManager.cpp +++ b/src/http/HTTPRequestManager.cpp @@ -5,15 +5,19 @@ const char* const TAG = "HTTPRequestManager"; #include "Common.h" #include "Logging.h" #include "Time.h" +#include "util/StringUtils.h" #include #include #include #include +#include #include #include +using namespace std::string_view_literals; + const std::size_t HTTP_BUFFER_SIZE = 4096LLU; const int HTTP_DOWNLOAD_SIZE_LIMIT = 200 * 1024 * 1024; // 200 MB @@ -102,28 +106,43 @@ std::unordered_map> s_rateLimits; using namespace OpenShock; -StringView _getDomain(StringView url) { - if (url.isNullOrEmpty()) { - return StringView::Null(); +std::string_view _getDomain(std::string_view url) { + if (url.empty()) { + return {}; + } + + // Remove the protocol eg. "https://api.example.com:443/path" -> "api.example.com:443/path" + auto seperator = url.find("://"); + if (seperator != std::string_view::npos) { + url.substr(seperator + 3); } - // Remove the protocol, port, and path eg. "https://api.example.com:443/path" -> "api.example.com" - url = url.afterDelimiter("://"_sv).beforeDelimiter('/').beforeDelimiter(':'); + // Remove the path eg. "api.example.com:443/path" -> "api.example.com:443" + seperator = url.find('/'); + if (seperator != std::string_view::npos) { + url = url.substr(0, seperator); + } + + // Remove the port eg. "api.example.com:443" -> "api.example.com" + seperator = url.rfind(':'); + if (seperator != std::string_view::npos) { + url = url.substr(0, seperator); + } // Remove all subdomains eg. "api.example.com" -> "example.com" - auto domainSep = url.rfind('.'); - if (domainSep == StringView::npos) { + seperator = url.rfind('.'); + if (seperator == std::string_view::npos) { return url; // E.g. "localhost" } - domainSep = url.rfind('.', domainSep - 1); - if (domainSep != StringView::npos) { - url = url.substr(domainSep + 1); + seperator = url.rfind('.', seperator - 1); + if (seperator != std::string_view::npos) { + url = url.substr(seperator + 1); } return url; } -std::shared_ptr _rateLimitFactory(StringView domain) { +std::shared_ptr _rateLimitFactory(std::string_view domain) { auto rateLimit = std::make_shared(); // Add default limits @@ -139,8 +158,8 @@ std::shared_ptr _rateLimitFactory(StringView domain) { return rateLimit; } -std::shared_ptr _getRateLimiter(StringView url) { - auto domain = _getDomain(url).toString(); +std::shared_ptr _getRateLimiter(std::string_view url) { + auto domain = std::string(_getDomain(url)); if (domain.empty()) { return nullptr; } @@ -159,7 +178,7 @@ std::shared_ptr _getRateLimiter(StringView url) { } void _setupClient(HTTPClient& client) { - client.setUserAgent(OpenShock::Constants::FW_USERAGENT_sv.toArduinoString()); + client.setUserAgent(OpenShock::Constants::FW_USERAGENT); } struct StreamReaderResult { @@ -185,8 +204,8 @@ constexpr bool _tryFindCRLF(std::size_t& pos, const uint8_t* buffer, std::size_t return false; } -constexpr bool _tryParseHexSizeT(std::size_t& result, StringView str) { - if (str.isNullOrEmpty() || str.size() > sizeof(std::size_t) * 2) { +constexpr bool _tryParseHexSizeT(std::size_t& result, std::string_view str) { + if (str.empty() || str.size() > sizeof(std::size_t) * 2) { return false; } @@ -244,7 +263,7 @@ ParserState _parseChunkHeader(const uint8_t* buffer, std::size_t bufferLen, std: return ParserState::Invalid; } - StringView sizeField(reinterpret_cast(buffer), sizeFieldEnd); + std::string_view sizeField(reinterpret_cast(buffer), sizeFieldEnd); // Parse the chunk size if (!_tryParseHexSizeT(payloadLen, sizeField)) { @@ -422,7 +441,7 @@ StreamReaderResult _readStreamData(HTTPClient& client, WiFiClient* stream, std:: HTTP::Response _doGetStream( HTTPClient& client, - StringView url, + std::string_view url, const std::map& headers, const std::vector& acceptedCodes, std::shared_ptr rateLimiter, @@ -431,7 +450,7 @@ HTTP::Response _doGetStream( uint32_t timeoutMs ) { int64_t begin = OpenShock::millis(); - if (!client.begin(url.toArduinoString())) { + if (!client.begin(OpenShock::StringToArduinoString(url))) { OS_LOGE(TAG, "Failed to begin HTTP request"); return {HTTP::RequestResult::RequestFailed, 0}; } @@ -516,7 +535,7 @@ HTTP::Response _doGetStream( } HTTP::Response - HTTP::Download(StringView url, const std::map& headers, HTTP::GotContentLengthCallback contentLengthCallback, HTTP::DownloadCallback downloadCallback, const std::vector& acceptedCodes, uint32_t timeoutMs) { + HTTP::Download(std::string_view url, const std::map& headers, HTTP::GotContentLengthCallback contentLengthCallback, HTTP::DownloadCallback downloadCallback, const std::vector& acceptedCodes, uint32_t timeoutMs) { std::shared_ptr rateLimiter = _getRateLimiter(url); if (rateLimiter == nullptr) { return {RequestResult::InvalidURL, 0, 0}; @@ -532,7 +551,7 @@ HTTP::Response return _doGetStream(client, url, headers, acceptedCodes, rateLimiter, contentLengthCallback, downloadCallback, timeoutMs); } -HTTP::Response HTTP::GetString(StringView url, const std::map& headers, const std::vector& acceptedCodes, uint32_t timeoutMs) { +HTTP::Response HTTP::GetString(std::string_view url, const std::map& headers, const std::vector& acceptedCodes, uint32_t timeoutMs) { std::string result; auto allocator = [&result](std::size_t contentLength) { diff --git a/src/http/JsonAPI.cpp b/src/http/JsonAPI.cpp index fd6e2c83..f5d4af18 100644 --- a/src/http/JsonAPI.cpp +++ b/src/http/JsonAPI.cpp @@ -2,17 +2,18 @@ #include "Common.h" #include "config/Config.h" +#include "util/StringUtils.h" using namespace OpenShock; -HTTP::Response HTTP::JsonAPI::LinkAccount(const char* accountLinkCode) { +HTTP::Response HTTP::JsonAPI::LinkAccount(std::string_view accountLinkCode) { std::string domain; if (!Config::GetBackendDomain(domain)) { return {HTTP::RequestResult::InternalError, 0, {}}; } char uri[OPENSHOCK_URI_BUFFER_SIZE]; - sprintf(uri, "https://%s/1/device/pair/%s", domain.c_str(), accountLinkCode); + sprintf(uri, "https://%s/1/device/pair/%.*s", domain.c_str(), accountLinkCode.length(), accountLinkCode.data()); return HTTP::GetJSON( uri, @@ -24,7 +25,7 @@ HTTP::Response HTTP::JsonAPI::LinkA ); } -HTTP::Response HTTP::JsonAPI::GetDeviceInfo(StringView deviceToken) { +HTTP::Response HTTP::JsonAPI::GetDeviceInfo(std::string_view deviceToken) { std::string domain; if (!Config::GetBackendDomain(domain)) { return {HTTP::RequestResult::InternalError, 0, {}}; @@ -37,14 +38,14 @@ HTTP::Response HTTP::JsonAPI::GetDev uri, { { "Accept", "application/json"}, - {"DeviceToken", deviceToken.toArduinoString()} + {"DeviceToken", OpenShock::StringToArduinoString(deviceToken)} }, Serialization::JsonAPI::ParseDeviceInfoJsonResponse, {200, 401} ); } -HTTP::Response HTTP::JsonAPI::AssignLcg(StringView deviceToken) { +HTTP::Response HTTP::JsonAPI::AssignLcg(std::string_view deviceToken) { std::string domain; if (!Config::GetBackendDomain(domain)) { return {HTTP::RequestResult::InternalError, 0, {}}; @@ -57,7 +58,7 @@ HTTP::Response HTTP::JsonAPI::AssignL uri, { { "Accept", "application/json"}, - {"DeviceToken", deviceToken.toArduinoString()} + {"DeviceToken", OpenShock::StringToArduinoString(deviceToken)} }, Serialization::JsonAPI::ParseAssignLcgJsonResponse, {200, 401} diff --git a/src/intconv.cpp b/src/intconv.cpp index 3859b77f..caa64410 100644 --- a/src/intconv.cpp +++ b/src/intconv.cpp @@ -2,8 +2,11 @@ #include #include +#include #include +using namespace std::string_view_literals; + template constexpr unsigned int NumDigits() { static_assert(std::is_integral::value); @@ -20,7 +23,7 @@ constexpr unsigned int NumDigits() { // Base converter template -constexpr bool spanToT(OpenShock::StringView str, T& val) { +constexpr bool spanToT(std::string_view str, T& val) { static_assert(std::is_integral::value); const T Threshold = std::numeric_limits::max() / 10; @@ -55,10 +58,10 @@ constexpr bool spanToT(OpenShock::StringView str, T& val) { // Unsigned converter template -constexpr bool spanToUT(OpenShock::StringView str, T& val) { +constexpr bool spanToUT(std::string_view str, T& val) { static_assert(std::is_unsigned::value); - if (str.isNullOrEmpty() || str.length() > NumDigits()) { + if (str.empty() || str.length() > NumDigits()) { return false; } @@ -67,17 +70,17 @@ constexpr bool spanToUT(OpenShock::StringView str, T& val) { // Signed converter template -constexpr bool spanToST(OpenShock::StringView str, T& val) { +constexpr bool spanToST(std::string_view str, T& val) { static_assert(std::is_signed::value); - if (str.isNullOrEmpty() || str.length() > NumDigits()) { + if (str.empty() || str.length() > NumDigits()) { return false; } bool negative = str.front() == '-'; if (negative) { str = str.substr(1); - if (str.isNullOrEmpty()) { + if (str.empty()) { return false; } } @@ -99,28 +102,28 @@ constexpr bool spanToST(OpenShock::StringView str, T& val) { using namespace OpenShock; // Specific converters -bool IntConv::stoi8(OpenShock::StringView str, int8_t& val) { +bool IntConv::stoi8(std::string_view str, int8_t& val) { return spanToST(str, val); } -bool IntConv::stou8(OpenShock::StringView str, uint8_t& val) { +bool IntConv::stou8(std::string_view str, uint8_t& val) { return spanToUT(str, val); } -bool IntConv::stoi16(OpenShock::StringView str, int16_t& val) { +bool IntConv::stoi16(std::string_view str, int16_t& val) { return spanToST(str, val); } -bool IntConv::stou16(OpenShock::StringView str, uint16_t& val) { +bool IntConv::stou16(std::string_view str, uint16_t& val) { return spanToUT(str, val); } -bool IntConv::stoi32(OpenShock::StringView str, int32_t& val) { +bool IntConv::stoi32(std::string_view str, int32_t& val) { return spanToST(str, val); } -bool IntConv::stou32(OpenShock::StringView str, uint32_t& val) { +bool IntConv::stou32(std::string_view str, uint32_t& val) { return spanToUT(str, val); } -bool IntConv::stoi64(OpenShock::StringView str, int64_t& val) { +bool IntConv::stoi64(std::string_view str, int64_t& val) { return spanToST(str, val); } -bool IntConv::stou64(OpenShock::StringView str, uint64_t& val) { +bool IntConv::stou64(std::string_view str, uint64_t& val) { return spanToUT(str, val); } @@ -136,189 +139,189 @@ static_assert(NumDigits() == 20, "NumDigits test for int64_t failed"); constexpr bool test_spanToUT8() { uint8_t u8 = 0; - return spanToUT("255"_sv, u8) && u8 == 255; + return spanToUT("255"sv, u8) && u8 == 255; } static_assert(test_spanToUT8(), "test_spanToUT8 failed"); constexpr bool test_spanToUT16() { uint16_t u16 = 0; - return spanToUT("65535"_sv, u16) && u16 == 65'535; + return spanToUT("65535"sv, u16) && u16 == 65'535; } static_assert(test_spanToUT16(), "test_spanToUT16 failed"); constexpr bool test_spanToUT32() { uint32_t u32 = 0; - return spanToUT("4294967295"_sv, u32) && u32 == 4'294'967'295U; + return spanToUT("4294967295"sv, u32) && u32 == 4'294'967'295U; } static_assert(test_spanToUT32(), "test_spanToUT32 failed"); constexpr bool test_spanToUT64() { uint64_t u64 = 0; - return spanToUT("18446744073709551615"_sv, u64) && u64 == 18'446'744'073'709'551'615ULL; + return spanToUT("18446744073709551615"sv, u64) && u64 == 18'446'744'073'709'551'615ULL; } static_assert(test_spanToUT64(), "test_spanToUT64 failed"); constexpr bool test_spanToUT8Overflow() { uint8_t u8 = 0; - return !spanToUT("256"_sv, u8); // Overflow + return !spanToUT("256"sv, u8); // Overflow } static_assert(test_spanToUT8Overflow(), "test_spanToUT8Overflow failed"); constexpr bool test_spanToUT16Overflow() { uint16_t u16 = 0; - return !spanToUT("70000"_sv, u16); // Overflow + return !spanToUT("70000"sv, u16); // Overflow } static_assert(test_spanToUT16Overflow(), "test_spanToUT16Overflow failed"); constexpr bool test_spanToUT32Overflow() { uint32_t u32 = 0; - return !spanToUT("4294967296"_sv, u32); // Overflow + return !spanToUT("4294967296"sv, u32); // Overflow } static_assert(test_spanToUT32Overflow(), "test_spanToUT32Overflow failed"); constexpr bool test_spanToUT64Overflow() { uint64_t u64 = 0; - return !spanToUT("18446744073709551616"_sv, u64); // Overflow + return !spanToUT("18446744073709551616"sv, u64); // Overflow } static_assert(test_spanToUT64Overflow(), "test_spanToUT64Overflow failed"); constexpr bool test_spanToST8() { int8_t i8 = 0; - return spanToST("-127"_sv, i8) && i8 == -127; + return spanToST("-127"sv, i8) && i8 == -127; } static_assert(test_spanToST8(), "test_spanToST8 failed"); constexpr bool test_spanToST16() { int16_t i16 = 0; - return spanToST("32767"_sv, i16) && i16 == 32'767; + return spanToST("32767"sv, i16) && i16 == 32'767; } static_assert(test_spanToST16(), "test_spanToST16 failed"); constexpr bool test_spanToST32() { int32_t i32 = 0; - return spanToST("-2147483647"_sv, i32) && i32 == -2'147'483'647; + return spanToST("-2147483647"sv, i32) && i32 == -2'147'483'647; } static_assert(test_spanToST32(), "test_spanToST32 failed"); constexpr bool test_spanToST64() { int64_t i64 = 0; - return spanToST("9223372036854775807"_sv, i64) && i64 == 9'223'372'036'854'775'807LL; + return spanToST("9223372036854775807"sv, i64) && i64 == 9'223'372'036'854'775'807LL; } static_assert(test_spanToST64(), "test_spanToST64 failed"); constexpr bool test_spanToST8Underflow() { int8_t i8 = 0; - return !spanToST("-128"_sv, i8); // Underflow + return !spanToST("-128"sv, i8); // Underflow } static_assert(test_spanToST8Underflow(), "test_spanToST8Underflow failed"); constexpr bool test_spanToST8Overflow() { int8_t i8 = 0; - return !spanToST("128"_sv, i8); // Overflow + return !spanToST("128"sv, i8); // Overflow } static_assert(test_spanToST8Overflow(), "test_spanToST8Overflow failed"); constexpr bool test_spanToST16Underflow() { int16_t i16 = 0; - return !spanToST("-32769"_sv, i16); // Underflow + return !spanToST("-32769"sv, i16); // Underflow } static_assert(test_spanToST16Underflow(), "test_spanToST16Underflow failed"); constexpr bool test_spanToST16Overflow() { int16_t i16 = 0; - return !spanToST("32768"_sv, i16); // Overflow + return !spanToST("32768"sv, i16); // Overflow } static_assert(test_spanToST16Overflow(), "test_spanToST16Overflow failed"); constexpr bool test_spanToST32Underflow() { int32_t i32 = 0; - return !spanToST("-2147483649"_sv, i32); // Underflow + return !spanToST("-2147483649"sv, i32); // Underflow } static_assert(test_spanToST32Underflow(), "test_spanToST32Underflow failed"); constexpr bool test_spanToST32Overflow() { int32_t i32 = 0; - return !spanToST("2147483648"_sv, i32); // Overflow + return !spanToST("2147483648"sv, i32); // Overflow } static_assert(test_spanToST32Overflow(), "test_spanToST32Overflow failed"); constexpr bool test_spanToST64Underflow() { int64_t i64 = 0; - return !spanToST("-9223372036854775809"_sv, i64); // Underflow + return !spanToST("-9223372036854775809"sv, i64); // Underflow } static_assert(test_spanToST64Underflow(), "test_spanToST64Underflow failed"); constexpr bool test_spanToST64Overflow() { int64_t i64 = 0; - return !spanToST("9223372036854775808"_sv, i64); // Overflow + return !spanToST("9223372036854775808"sv, i64); // Overflow } static_assert(test_spanToST64Overflow(), "test_spanToST64Overflow failed"); constexpr bool test_spanToSTEmptyString() { int8_t i8 = 0; - return !spanToST(""_sv, i8); // Empty string + return !spanToST(""sv, i8); // Empty string } static_assert(test_spanToSTEmptyString(), "test_spanToSTEmptyString failed"); constexpr bool test_spanToSTJustNegativeSign() { int16_t i16 = 0; - return !spanToST("-"_sv, i16); // Just a negative sign + return !spanToST("-"sv, i16); // Just a negative sign } static_assert(test_spanToSTJustNegativeSign(), "test_spanToSTJustNegativeSign failed"); constexpr bool test_spanToSTNegativeZero() { int32_t i32 = 0; - return !spanToST("-0"_sv, i32); // Negative zero + return !spanToST("-0"sv, i32); // Negative zero } static_assert(test_spanToSTNegativeZero(), "test_spanToSTNegativeZero failed"); constexpr bool test_spanToSTInvalidCharacter() { int32_t i32 = 0; - return !spanToST("+123"_sv, i32); // Invalid character + return !spanToST("+123"sv, i32); // Invalid character } static_assert(test_spanToSTInvalidCharacter(), "test_spanToSTInvalidCharacter failed"); constexpr bool test_spanToSTLeadingSpace() { int64_t i64 = 0; - return !spanToST(" 123"_sv, i64); // Leading space + return !spanToST(" 123"sv, i64); // Leading space } static_assert(test_spanToSTLeadingSpace(), "test_spanToSTLeadingSpace failed"); constexpr bool test_spanToSTTrailingSpace() { int64_t i64 = 0; - return !spanToST("123 "_sv, i64); // Trailing space + return !spanToST("123 "sv, i64); // Trailing space } static_assert(test_spanToSTTrailingSpace(), "test_spanToSTTrailingSpace failed"); constexpr bool test_spanToSTLeadingZero() { int64_t i64 = 0; - return !spanToST("0123"_sv, i64); // Leading zero + return !spanToST("0123"sv, i64); // Leading zero } static_assert(test_spanToSTLeadingZero(), "test_spanToSTLeadingZero failed"); diff --git a/src/serial/SerialInputHandler.cpp b/src/serial/SerialInputHandler.cpp index 0e8eb6c7..4d6bdaec 100644 --- a/src/serial/SerialInputHandler.cpp +++ b/src/serial/SerialInputHandler.cpp @@ -12,17 +12,42 @@ const char* const TAG = "SerialInputHandler"; #include "Logging.h" #include "serialization/JsonAPI.h" #include "serialization/JsonSerial.h" -#include "StringView.h" #include "Time.h" #include "util/Base64Utils.h" +#include "util/StringUtils.h" #include "wifi/WiFiManager.h" #include #include +#include +#include #include -#include +namespace std { + struct hash_ci { + std::size_t operator()(std::string_view str) const { + std::size_t hash = 7; + + for (int i = 0; i < str.size(); ++i) { + hash = hash * 31 + tolower(str[i]); + } + + return hash; + } + }; + + template<> + struct less { + bool operator()(std::string_view a, std::string_view b) const { return a < b; } + }; + + struct equals_ci { + bool operator()(std::string_view a, std::string_view b) const { return strncasecmp(a.data(), b.data(), std::max(a.size(), b.size())) == 0; } + }; +} // namespace std + +using namespace std::string_view_literals; #define SERPR_SYS(format, ...) Serial.printf("$SYS$|" format "\n", ##__VA_ARGS__) #define SERPR_RESPONSE(format, ...) SERPR_SYS("Response|" format, ##__VA_ARGS__) @@ -31,29 +56,29 @@ const char* const TAG = "SerialInputHandler"; using namespace OpenShock; -const int64_t PASTE_INTERVAL_THRESHOLD_MS = 20; +const int64_t PASTE_INTERVAL_THRESHOLD_MS = 20; const std::size_t SERIAL_BUFFER_CLEAR_THRESHOLD = 512; struct SerialCmdHandler { - StringView cmd; + std::string_view cmd; const char* helpResponse; - void (*commandHandler)(StringView); + void (*commandHandler)(std::string_view); }; static bool s_echoEnabled = true; -static std::unordered_map s_commandHandlers; +static std::unordered_map s_commandHandlers; /// @brief Tries to parse a boolean from a string (case-insensitive) /// @param str Input string /// @param strLen Length of input string /// @param out Output boolean /// @return True if the argument is a boolean, false otherwise -bool _tryParseBool(StringView str, bool& out) { - if (str.isNullOrEmpty()) { +bool _tryParseBool(std::string_view str, bool& out) { + if (str.empty()) { return false; } - str = str.trim(); + str = OpenShock::StringTrim(str); if (str.length() > 5) { return false; @@ -72,21 +97,21 @@ bool _tryParseBool(StringView str, bool& out) { return false; } -void _handleVersionCommand(StringView arg) { +void _handleVersionCommand(std::string_view arg) { (void)arg; Serial.print("\n"); SerialInputHandler::PrintVersionInfo(); } -void _handleRestartCommand(StringView arg) { +void _handleRestartCommand(std::string_view arg) { (void)arg; Serial.println("Restarting ESP..."); ESP.restart(); } -void _handleFactoryResetCommand(StringView arg) { +void _handleFactoryResetCommand(std::string_view arg) { (void)arg; Serial.println("Resetting to factory defaults..."); @@ -95,8 +120,8 @@ void _handleFactoryResetCommand(StringView arg) { ESP.restart(); } -void _handleRfTxPinCommand(StringView arg) { - if (arg.isNullOrEmpty()) { +void _handleRfTxPinCommand(std::string_view arg) { + if (arg.empty()) { uint8_t txPin; if (!Config::GetRFConfigTxPin(txPin)) { SERPR_ERROR("Failed to get RF TX pin from config"); @@ -134,8 +159,8 @@ void _handleRfTxPinCommand(StringView arg) { } } -void _handleDomainCommand(StringView arg) { - if (arg.isNullOrEmpty()) { +void _handleDomainCommand(std::string_view arg) { + if (arg.empty()) { std::string domain; if (!Config::GetBackendDomain(domain)) { SERPR_ERROR("Failed to get domain from config"); @@ -171,15 +196,7 @@ void _handleDomainCommand(StringView arg) { return; } - OS_LOGI( - TAG, - "Successfully connected to \"%.*s\", version: %s, commit: %s, current time: %s", - arg.length(), - arg.data(), - resp.data.version.c_str(), - resp.data.commit.c_str(), - resp.data.currentTime.c_str() - ); + OS_LOGI(TAG, "Successfully connected to \"%.*s\", version: %s, commit: %s, current time: %s", arg.length(), arg.data(), resp.data.version.c_str(), resp.data.commit.c_str(), resp.data.currentTime.c_str()); bool result = OpenShock::Config::SetBackendDomain(arg); @@ -194,8 +211,8 @@ void _handleDomainCommand(StringView arg) { ESP.restart(); } -void _handleAuthtokenCommand(StringView arg) { - if (arg.isNullOrEmpty()) { +void _handleAuthtokenCommand(std::string_view arg) { + if (arg.empty()) { std::string authToken; if (!Config::GetBackendAuthToken(authToken)) { SERPR_ERROR("Failed to get auth token from config"); @@ -216,8 +233,8 @@ void _handleAuthtokenCommand(StringView arg) { } } -void _handleLcgOverrideCommand(StringView arg) { - if (arg.isNullOrEmpty()) { +void _handleLcgOverrideCommand(std::string_view arg) { + if (arg.empty()) { std::string lcgOverride; if (!Config::GetBackendLCGOverride(lcgOverride)) { SERPR_ERROR("Failed to get LCG override from config"); @@ -229,7 +246,7 @@ void _handleLcgOverrideCommand(StringView arg) { return; } - if (arg.startsWith("clear")) { + if (OpenShock::StringStartsWith(arg, "clear"sv)) { if (arg.size() != 5) { SERPR_ERROR("Invalid command (clear command should not have any arguments)"); return; @@ -244,13 +261,13 @@ void _handleLcgOverrideCommand(StringView arg) { return; } - if (arg.startsWith("set ")) { + if (OpenShock::StringStartsWith(arg, "set "sv)) { if (arg.size() <= 4) { SERPR_ERROR("Invalid command (set command should have an argument)"); return; } - StringView domain = arg.substr(4); + std::string_view domain = arg.substr(4); if (domain.size() + 40 >= OPENSHOCK_URI_BUFFER_SIZE) { SERPR_ERROR("Domain name too long, please try increasing the \"OPENSHOCK_URI_BUFFER_SIZE\" constant in source code"); @@ -299,10 +316,10 @@ void _handleLcgOverrideCommand(StringView arg) { SERPR_ERROR("Invalid subcommand"); } -void _handleNetworksCommand(StringView arg) { +void _handleNetworksCommand(std::string_view arg) { cJSON* root; - if (arg.isNullOrEmpty()) { + if (arg.empty()) { root = cJSON_CreateArray(); if (root == nullptr) { SERPR_ERROR("Failed to create JSON array"); @@ -339,8 +356,8 @@ void _handleNetworksCommand(StringView arg) { std::vector creds; - uint8_t id = 1; - cJSON* network = nullptr; + uint8_t id = 1; + cJSON* network = nullptr; cJSON_ArrayForEach(network, root) { Config::WiFiCredentials cred; @@ -368,10 +385,10 @@ void _handleNetworksCommand(StringView arg) { OpenShock::WiFiManager::RefreshNetworkCredentials(); } -void _handleKeepAliveCommand(StringView arg) { +void _handleKeepAliveCommand(std::string_view arg) { bool keepAliveEnabled; - if (arg.isNullOrEmpty()) { + if (arg.empty()) { // Get keep alive status if (!Config::GetRFConfigKeepAliveEnabled(keepAliveEnabled)) { SERPR_ERROR("Failed to get keep-alive status from config"); @@ -396,8 +413,8 @@ void _handleKeepAliveCommand(StringView arg) { } } -void _handleSerialEchoCommand(StringView arg) { - if (arg.isNullOrEmpty()) { +void _handleSerialEchoCommand(std::string_view arg) { + if (arg.empty()) { // Get current serial echo status SERPR_RESPONSE("SerialEcho|%s", s_echoEnabled ? "true" : "false"); return; @@ -419,8 +436,8 @@ void _handleSerialEchoCommand(StringView arg) { } } -void _handleValidGpiosCommand(StringView arg) { - if (!arg.isNullOrEmpty()) { +void _handleValidGpiosCommand(std::string_view arg) { + if (!arg.empty()) { SERPR_ERROR("Invalid argument (too many arguments)"); return; } @@ -444,8 +461,8 @@ void _handleValidGpiosCommand(StringView arg) { SERPR_RESPONSE("ValidGPIOs|%s", buffer.c_str()); } -void _handleJsonConfigCommand(StringView arg) { - if (arg.isNullOrEmpty()) { +void _handleJsonConfigCommand(std::string_view arg) { + if (arg.empty()) { // Get raw config std::string json = Config::GetAsJSON(true); @@ -463,8 +480,8 @@ void _handleJsonConfigCommand(StringView arg) { ESP.restart(); } -void _handleRawConfigCommand(StringView arg) { - if (arg.isNullOrEmpty()) { +void _handleRawConfigCommand(std::string_view arg) { + if (arg.empty()) { std::vector buffer; // Get raw config @@ -499,7 +516,7 @@ void _handleRawConfigCommand(StringView arg) { ESP.restart(); } -void _handleDebugInfoCommand(StringView arg) { +void _handleDebugInfoCommand(std::string_view arg) { (void)arg; SERPR_RESPONSE("RTOSInfo|Free Heap|%u", xPortGetFreeHeapSize()); @@ -529,8 +546,8 @@ void _handleDebugInfoCommand(StringView arg) { } } -void _handleRFTransmitCommand(StringView arg) { - if (arg.isNullOrEmpty()) { +void _handleRFTransmitCommand(std::string_view arg) { + if (arg.empty()) { SERPR_ERROR("No command"); return; } @@ -558,9 +575,9 @@ void _handleRFTransmitCommand(StringView arg) { SERPR_SUCCESS("Command sent"); } -void _handleHelpCommand(StringView arg) { - arg = arg.trim(); - if (arg.isNullOrEmpty()) { +void _handleHelpCommand(std::string_view arg) { + arg = OpenShock::StringTrim(arg); + if (arg.empty()) { SerialInputHandler::PrintWelcomeHeader(); // Raw string literal (1+ to remove the first newline) @@ -604,7 +621,7 @@ factoryreset reset device to factory defaults and restart } static const SerialCmdHandler kVersionCmdHandler = { - "version"_sv, + "version"sv, R"(version Print version information Example: @@ -613,7 +630,7 @@ static const SerialCmdHandler kVersionCmdHandler = { _handleVersionCommand, }; static const SerialCmdHandler kRestartCmdHandler = { - "restart"_sv, + "restart"sv, R"(restart Restart the board Example: @@ -622,7 +639,7 @@ static const SerialCmdHandler kRestartCmdHandler = { _handleRestartCommand, }; static const SerialCmdHandler kSystemInfoCmdHandler = { - "sysinfo"_sv, + "sysinfo"sv, R"(sysinfo Get system information from RTOS, WiFi, etc. Example: @@ -631,7 +648,7 @@ static const SerialCmdHandler kSystemInfoCmdHandler = { _handleDebugInfoCommand, }; static const SerialCmdHandler kSerialEchoCmdHandler = { - "echo"_sv, + "echo"sv, R"(echo Get the serial echo status. If enabled, typed characters are echoed back to the serial port. @@ -646,7 +663,7 @@ echo [] _handleSerialEchoCommand, }; static const SerialCmdHandler kValidGpiosCmdHandler = { - "validgpios"_sv, + "validgpios"sv, R"(validgpios List all valid GPIO pins Example: @@ -655,7 +672,7 @@ static const SerialCmdHandler kValidGpiosCmdHandler = { _handleValidGpiosCommand, }; static const SerialCmdHandler kRfTxPinCmdHandler = { - "rftxpin"_sv, + "rftxpin"sv, R"(rftxpin Get the GPIO pin used for the radio transmitter. @@ -669,7 +686,7 @@ rftxpin [] _handleRfTxPinCommand, }; static const SerialCmdHandler kDomainCmdHandler = { - "domain"_sv, + "domain"sv, R"(domain Get the backend domain. @@ -683,7 +700,7 @@ domain [] _handleDomainCommand, }; static const SerialCmdHandler kAuthTokenCmdHandler = { - "authtoken"_sv, + "authtoken"sv, R"(authtoken Get the backend auth token. @@ -716,7 +733,7 @@ lcgoverride clear _handleLcgOverrideCommand, }; static const SerialCmdHandler kNetworksCmdHandler = { - "networks"_sv, + "networks"sv, R"(networks Get all saved networks. @@ -733,7 +750,7 @@ networks [] _handleNetworksCommand, }; static const SerialCmdHandler kKeepAliveCmdHandler = { - "keepalive"_sv, + "keepalive"sv, R"(keepalive Get the shocker keep-alive status. @@ -747,7 +764,7 @@ keepalive [] _handleKeepAliveCommand, }; static const SerialCmdHandler kJsonConfigCmdHandler = { - "jsonconfig"_sv, + "jsonconfig"sv, R"(jsonconfig Get the configuration as JSON Example: @@ -763,7 +780,7 @@ jsonconfig _handleJsonConfigCommand, }; static const SerialCmdHandler kRawConfigCmdHandler = { - "rawconfig"_sv, + "rawconfig"sv, R"(rawconfig Get the raw binary config Example: @@ -779,7 +796,7 @@ rawconfig _handleRawConfigCommand, }; static const SerialCmdHandler kRfTransmitCmdHandler = { - "rftransmit"_sv, + "rftransmit"sv, R"(rftransmit Transmit a RF command Arguments: @@ -795,7 +812,7 @@ static const SerialCmdHandler kRfTransmitCmdHandler = { _handleRFTransmitCommand, }; static const SerialCmdHandler kFactoryResetCmdHandler = { - "factoryreset"_sv, + "factoryreset"sv, R"(factoryreset Reset the device to factory defaults and restart Example: @@ -804,7 +821,7 @@ static const SerialCmdHandler kFactoryResetCmdHandler = { _handleFactoryResetCommand, }; static const SerialCmdHandler khelpCmdHandler = { - "help"_sv, + "help"sv, R"(help [] Print help information Arguments: @@ -853,16 +870,16 @@ int findLineStart(const char* buffer, int bufferSize, int lineEnd) { return -1; } -void processSerialLine(StringView line) { - line = line.trim(); - if (line.isNullOrEmpty()) { +void processSerialLine(std::string_view line) { + line = OpenShock::StringTrim(line); + if (line.empty()) { SERPR_ERROR("No command"); return; } - auto parts = line.split(' ', 1); - StringView command = parts[0]; - StringView arguments = parts.size() > 1 ? parts[1] : StringView(); + auto parts = OpenShock::StringSplit(line, ' ', 1); + std::string_view command = parts[0]; + std::string_view arguments = parts.size() > 1 ? parts[1] : std::string_view(); auto it = s_commandHandlers.find(command); if (it == s_commandHandlers.end()) { @@ -915,7 +932,7 @@ void SerialInputHandler::Update() { static char* buffer = nullptr; // TODO: Clean up this buffer every once in a while static std::size_t bufferSize = 0; static std::size_t bufferIndex = 0; - static int64_t lastEcho = 0; + static int64_t lastEcho = 0; static bool suppressingPaste = false; while (true) { @@ -981,7 +998,7 @@ void SerialInputHandler::Update() { break; } - StringView line = StringView(buffer, lineEnd).trim(); + std::string_view line = OpenShock::StringTrim(std::string_view(buffer, lineEnd)); Serial.printf("\r> %.*s\n", line.size(), line.data()); diff --git a/src/serialization/WSGateway.cpp b/src/serialization/WSGateway.cpp index d0fb56de..0242bb2b 100644 --- a/src/serialization/WSGateway.cpp +++ b/src/serialization/WSGateway.cpp @@ -75,7 +75,7 @@ bool Gateway::SerializeOtaInstallProgressMessage(int32_t updateId, Gateway::OtaI return callback(span.data(), span.size()); } -bool Gateway::SerializeOtaInstallFailedMessage(int32_t updateId, StringView message, bool fatal, Common::SerializationCallbackFn callback) { +bool Gateway::SerializeOtaInstallFailedMessage(int32_t updateId, std::string_view message, bool fatal, Common::SerializationCallbackFn callback) { flatbuffers::FlatBufferBuilder builder(256); // TODO: Profile this and adjust the size accordingly auto messageOffset = builder.CreateString(message.data(), message.size()); diff --git a/src/util/IPAddressUtils.cpp b/src/util/IPAddressUtils.cpp index a6dbc5c3..61023d37 100644 --- a/src/util/IPAddressUtils.cpp +++ b/src/util/IPAddressUtils.cpp @@ -1,16 +1,17 @@ #include "util/IPAddressUtils.h" #include "intconv.h" +#include "util/StringUtils.h" const char* const TAG = "Util::IPAddressUtils"; -bool OpenShock::IPV4AddressFromStringView(IPAddress& ip, StringView sv) { - if (sv.isNullOrEmpty()) { +bool OpenShock::IPV4AddressFromStringView(IPAddress& ip, std::string_view sv) { + if (sv.empty()) { return false; } - auto parts = sv.split('.'); - if (parts.size() != 4) { + std::string_view parts[4]; + if (!OpenShock::TryStringSplit(sv, '.', parts)) { return false; // Must have 4 octets } diff --git a/src/util/ParitionUtils.cpp b/src/util/ParitionUtils.cpp index dd219cbf..3764879a 100644 --- a/src/util/ParitionUtils.cpp +++ b/src/util/ParitionUtils.cpp @@ -22,7 +22,7 @@ bool OpenShock::TryGetPartitionHash(const esp_partition_t* partition, char (&has return true; } -bool OpenShock::FlashPartitionFromUrl(const esp_partition_t* partition, StringView remoteUrl, const uint8_t (&remoteHash)[32], std::function progressCallback) { +bool OpenShock::FlashPartitionFromUrl(const esp_partition_t* partition, std::string_view remoteUrl, const uint8_t (&remoteHash)[32], std::function progressCallback) { OpenShock::SHA256 sha256; if (!sha256.begin()) { OS_LOGE(TAG, "Failed to initialize SHA256 hash"); diff --git a/src/util/StringUtils.cpp b/src/util/StringUtils.cpp index 6e331c06..80e74146 100644 --- a/src/util/StringUtils.cpp +++ b/src/util/StringUtils.cpp @@ -57,3 +57,72 @@ bool OpenShock::FormatToString(std::string& out, const char* format, ...) { return true; } + +std::vector OpenShock::StringSplit(const std::string_view view, char delimiter, std::size_t maxSplits) { + if (view.empty()) { + return {}; + } + + std::vector result = {}; + + std::size_t pos = 0; + std::size_t splits = 0; + while (pos < view.size() && splits < maxSplits) { + std::size_t nextPos = view.find(delimiter, pos); + if (nextPos == std::string_view::npos) { + nextPos = view.size(); + } + + result.push_back(view.substr(pos, nextPos - pos)); + pos = nextPos + 1; + ++splits; + } + + if (pos < view.size()) { + result.push_back(view.substr(pos)); + } + + return result; +} + +std::vector OpenShock::StringSplit(const std::string_view view, bool (*predicate)(char delimiter), std::size_t maxSplits) { + if (view.empty()) { + return {}; + } + + std::vector result = {}; + + const char* start = nullptr; + for (const char* ptr = view.begin(); ptr < view.end(); ++ptr) { + if (predicate(*ptr)) { + if (start != nullptr) { + result.emplace_back(std::string_view(start, ptr - start)); + start = nullptr; + } + } else if (start == nullptr) { + start = ptr; + } + } + + if (start != nullptr) { + result.emplace_back(std::string_view(start, view.end() - start)); + } + + return result; +} + +std::vector OpenShock::StringSplitNewLines(const std::string_view view, std::size_t maxSplits) { + return StringSplit( + view, [](char c) { return c == '\r' || c == '\n'; }, maxSplits + ); +} + +std::vector OpenShock::StringSplitWhiteSpace(const std::string_view view, std::size_t maxSplits) { + return StringSplit( + view, [](char c) { return isspace(c) != 0; }, maxSplits + ); +} + +String OpenShock::StringToArduinoString(std::string_view view) { + return String(view.data(), view.size()); +} diff --git a/src/wifi/WiFiManager.cpp b/src/wifi/WiFiManager.cpp index 787f8b7a..32e1374a 100644 --- a/src/wifi/WiFiManager.cpp +++ b/src/wifi/WiFiManager.cpp @@ -171,7 +171,7 @@ bool _connect(const uint8_t (&bssid)[6], const std::string& password) { return _connectImpl(it->ssid, password.c_str(), bssid); } -bool _authenticate(const WiFiNetwork& net, StringView password) { +bool _authenticate(const WiFiNetwork& net, std::string_view password) { uint8_t id = Config::AddWiFiCredentials(net.ssid, password); if (id == 0) { Serialization::Local::SerializeErrorMessage("too_many_credentials", CaptivePortal::BroadcastMessageBIN); @@ -180,7 +180,7 @@ bool _authenticate(const WiFiNetwork& net, StringView password) { Serialization::Local::SerializeWiFiNetworkEvent(Serialization::Types::WifiNetworkEventType::Saved, net, CaptivePortal::BroadcastMessageBIN); - return _connect(net.ssid, password.toString()); + return _connect(net.ssid, std::string(password)); } void _evWiFiConnected(arduino_event_t* event) { @@ -342,7 +342,7 @@ bool WiFiManager::Init() { return true; } -bool WiFiManager::Save(const char* ssid, StringView password) { +bool WiFiManager::Save(const char* ssid, std::string_view password) { OS_LOGV(TAG, "Authenticating to network %s", ssid); auto it = _findNetworkBySSID(ssid); From 4e1e963a1ff36c09432ee35bab8edfcee268b15f Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 6 Sep 2024 20:35:06 +0200 Subject: [PATCH 25/41] Remove log spam --- src/GatewayClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GatewayClient.cpp b/src/GatewayClient.cpp index 876642ae..3bd2d0b0 100644 --- a/src/GatewayClient.cpp +++ b/src/GatewayClient.cpp @@ -194,7 +194,7 @@ void GatewayClient::_handleEvent(WStype_t type, uint8_t* payload, std::size_t le OS_LOGD(TAG, "Received ping from API"); break; case WStype_PONG: - OS_LOGD(TAG, "Received pong from API"); + OS_LOGV(TAG, "Received pong from API"); break; case WStype_BIN: EventHandlers::WebSocket::HandleGatewayBinary(payload, length); From 20bbc25b8afe819dc5b3e08b38c24bb86d7bede1 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 6 Sep 2024 20:45:39 +0200 Subject: [PATCH 26/41] Move and rename IntConv --- include/Convert.h | 16 ++++++++++++++ include/intconv.h | 15 ------------- src/{intconv.cpp => Convert.cpp} | 36 +++++++++++++++++++++++-------- src/serial/SerialInputHandler.cpp | 26 +++------------------- src/util/IPAddressUtils.cpp | 4 ++-- 5 files changed, 48 insertions(+), 49 deletions(-) create mode 100644 include/Convert.h delete mode 100644 include/intconv.h rename src/{intconv.cpp => Convert.cpp} (90%) diff --git a/include/Convert.h b/include/Convert.h new file mode 100644 index 00000000..e3defdb5 --- /dev/null +++ b/include/Convert.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +namespace OpenShock::Convert { + bool ToInt8(std::string_view str, int8_t& val); + bool ToUInt8(std::string_view str, uint8_t& val); + bool ToInt16(std::string_view str, int16_t& val); + bool ToUInt16(std::string_view str, uint16_t& val); + bool ToInt32(std::string_view str, int32_t& val); + bool ToUInt32(std::string_view str, uint32_t& val); + bool ToInt64(std::string_view str, int64_t& val); + bool ToUInt64(std::string_view str, uint64_t& val); + bool ToBool(std::string_view str, bool& val); +} // namespace OpenShock::Convert diff --git a/include/intconv.h b/include/intconv.h deleted file mode 100644 index f0074383..00000000 --- a/include/intconv.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include -#include - -namespace OpenShock::IntConv { - bool stoi8(std::string_view str, int8_t& val); - bool stou8(std::string_view str, uint8_t& val); - bool stoi16(std::string_view str, int16_t& val); - bool stou16(std::string_view str, uint16_t& val); - bool stoi32(std::string_view str, int32_t& val); - bool stou32(std::string_view str, uint32_t& val); - bool stoi64(std::string_view str, int64_t& val); - bool stou64(std::string_view str, uint64_t& val); -} // namespace OpenShock::IntConv diff --git a/src/intconv.cpp b/src/Convert.cpp similarity index 90% rename from src/intconv.cpp rename to src/Convert.cpp index caa64410..85dd2a28 100644 --- a/src/intconv.cpp +++ b/src/Convert.cpp @@ -1,6 +1,7 @@ -#include "intconv.h" +#include "Convert.h" #include +#include #include #include #include @@ -102,30 +103,47 @@ constexpr bool spanToST(std::string_view str, T& val) { using namespace OpenShock; // Specific converters -bool IntConv::stoi8(std::string_view str, int8_t& val) { +bool Convert::ToInt8(std::string_view str, int8_t& val) { return spanToST(str, val); } -bool IntConv::stou8(std::string_view str, uint8_t& val) { +bool Convert::ToUInt8(std::string_view str, uint8_t& val) { return spanToUT(str, val); } -bool IntConv::stoi16(std::string_view str, int16_t& val) { +bool Convert::ToInt16(std::string_view str, int16_t& val) { return spanToST(str, val); } -bool IntConv::stou16(std::string_view str, uint16_t& val) { +bool Convert::ToUInt16(std::string_view str, uint16_t& val) { return spanToUT(str, val); } -bool IntConv::stoi32(std::string_view str, int32_t& val) { +bool Convert::ToInt32(std::string_view str, int32_t& val) { return spanToST(str, val); } -bool IntConv::stou32(std::string_view str, uint32_t& val) { +bool Convert::ToUInt32(std::string_view str, uint32_t& val) { return spanToUT(str, val); } -bool IntConv::stoi64(std::string_view str, int64_t& val) { +bool Convert::ToInt64(std::string_view str, int64_t& val) { return spanToST(str, val); } -bool IntConv::stou64(std::string_view str, uint64_t& val) { +bool Convert::ToUInt64(std::string_view str, uint64_t& val) { return spanToUT(str, val); } +bool Convert::ToBool(std::string_view str, bool& val) { + if (str.length() > 5) { + return false; + } + + if (strncasecmp(str.data(), "true", str.length()) == 0) { + val = true; + return true; + } + + if (strncasecmp(str.data(), "false", str.length()) == 0) { + val = false; + return true; + } + + return false; +} static_assert(NumDigits() == 3, "NumDigits test for uint8_t failed"); static_assert(NumDigits() == 5, "NumDigits test for uint16_t failed"); diff --git a/src/serial/SerialInputHandler.cpp b/src/serial/SerialInputHandler.cpp index 4d6bdaec..173a7512 100644 --- a/src/serial/SerialInputHandler.cpp +++ b/src/serial/SerialInputHandler.cpp @@ -8,7 +8,7 @@ const char* const TAG = "SerialInputHandler"; #include "config/SerialInputConfig.h" #include "FormatHelpers.h" #include "http/HTTPRequestManager.h" -#include "intconv.h" +#include "Convert.h" #include "Logging.h" #include "serialization/JsonAPI.h" #include "serialization/JsonSerial.h" @@ -74,27 +74,7 @@ static std::unordered_map 5) { - return false; - } - - if (strncasecmp(str.data(), "true", str.length()) == 0) { - out = true; - return true; - } - - if (strncasecmp(str.data(), "false", str.length()) == 0) { - out = false; - return true; - } - - return false; + return OpenShock::Convert::ToBool(OpenShock::StringTrim(str), out); } void _handleVersionCommand(std::string_view arg) { @@ -134,7 +114,7 @@ void _handleRfTxPinCommand(std::string_view arg) { } uint8_t pin; - if (!OpenShock::IntConv::stou8(arg, pin)) { + if (!OpenShock::Convert::ToUInt8(arg, pin)) { SERPR_ERROR("Invalid argument (number invalid or out of range)"); } diff --git a/src/util/IPAddressUtils.cpp b/src/util/IPAddressUtils.cpp index 61023d37..f5d0801d 100644 --- a/src/util/IPAddressUtils.cpp +++ b/src/util/IPAddressUtils.cpp @@ -1,6 +1,6 @@ #include "util/IPAddressUtils.h" -#include "intconv.h" +#include "Convert.h" #include "util/StringUtils.h" const char* const TAG = "Util::IPAddressUtils"; @@ -16,7 +16,7 @@ bool OpenShock::IPV4AddressFromStringView(IPAddress& ip, std::string_view sv) { } std::uint8_t octets[4]; - if (!IntConv::stou8(parts[0], octets[0]) || !IntConv::stou8(parts[1], octets[1]) || !IntConv::stou8(parts[2], octets[2]) || !IntConv::stou8(parts[3], octets[3])) { + if (!Convert::ToUInt8(parts[0], octets[0]) || !Convert::ToUInt8(parts[1], octets[1]) || !Convert::ToUInt8(parts[2], octets[2]) || !Convert::ToUInt8(parts[3], octets[3])) { return false; } From ffc3d93ca71806f06bf2e17e3cd1fe27c530ed49 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 6 Sep 2024 20:49:38 +0200 Subject: [PATCH 27/41] Fix typo --- include/Convert.h | 8 ++++---- src/Convert.cpp | 8 ++++---- src/serial/SerialInputHandler.cpp | 2 +- src/util/IPAddressUtils.cpp | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/Convert.h b/include/Convert.h index e3defdb5..325f7eb2 100644 --- a/include/Convert.h +++ b/include/Convert.h @@ -5,12 +5,12 @@ namespace OpenShock::Convert { bool ToInt8(std::string_view str, int8_t& val); - bool ToUInt8(std::string_view str, uint8_t& val); + bool ToUint8(std::string_view str, uint8_t& val); bool ToInt16(std::string_view str, int16_t& val); - bool ToUInt16(std::string_view str, uint16_t& val); + bool ToUint16(std::string_view str, uint16_t& val); bool ToInt32(std::string_view str, int32_t& val); - bool ToUInt32(std::string_view str, uint32_t& val); + bool ToUint32(std::string_view str, uint32_t& val); bool ToInt64(std::string_view str, int64_t& val); - bool ToUInt64(std::string_view str, uint64_t& val); + bool ToUint64(std::string_view str, uint64_t& val); bool ToBool(std::string_view str, bool& val); } // namespace OpenShock::Convert diff --git a/src/Convert.cpp b/src/Convert.cpp index 85dd2a28..95f08ee1 100644 --- a/src/Convert.cpp +++ b/src/Convert.cpp @@ -106,25 +106,25 @@ using namespace OpenShock; bool Convert::ToInt8(std::string_view str, int8_t& val) { return spanToST(str, val); } -bool Convert::ToUInt8(std::string_view str, uint8_t& val) { +bool Convert::ToUint8(std::string_view str, uint8_t& val) { return spanToUT(str, val); } bool Convert::ToInt16(std::string_view str, int16_t& val) { return spanToST(str, val); } -bool Convert::ToUInt16(std::string_view str, uint16_t& val) { +bool Convert::ToUint16(std::string_view str, uint16_t& val) { return spanToUT(str, val); } bool Convert::ToInt32(std::string_view str, int32_t& val) { return spanToST(str, val); } -bool Convert::ToUInt32(std::string_view str, uint32_t& val) { +bool Convert::ToUint32(std::string_view str, uint32_t& val) { return spanToUT(str, val); } bool Convert::ToInt64(std::string_view str, int64_t& val) { return spanToST(str, val); } -bool Convert::ToUInt64(std::string_view str, uint64_t& val) { +bool Convert::ToUint64(std::string_view str, uint64_t& val) { return spanToUT(str, val); } bool Convert::ToBool(std::string_view str, bool& val) { diff --git a/src/serial/SerialInputHandler.cpp b/src/serial/SerialInputHandler.cpp index 173a7512..cd36ab37 100644 --- a/src/serial/SerialInputHandler.cpp +++ b/src/serial/SerialInputHandler.cpp @@ -114,7 +114,7 @@ void _handleRfTxPinCommand(std::string_view arg) { } uint8_t pin; - if (!OpenShock::Convert::ToUInt8(arg, pin)) { + if (!OpenShock::Convert::ToUint8(arg, pin)) { SERPR_ERROR("Invalid argument (number invalid or out of range)"); } diff --git a/src/util/IPAddressUtils.cpp b/src/util/IPAddressUtils.cpp index f5d0801d..15661641 100644 --- a/src/util/IPAddressUtils.cpp +++ b/src/util/IPAddressUtils.cpp @@ -16,7 +16,7 @@ bool OpenShock::IPV4AddressFromStringView(IPAddress& ip, std::string_view sv) { } std::uint8_t octets[4]; - if (!Convert::ToUInt8(parts[0], octets[0]) || !Convert::ToUInt8(parts[1], octets[1]) || !Convert::ToUInt8(parts[2], octets[2]) || !Convert::ToUInt8(parts[3], octets[3])) { + if (!Convert::ToUint8(parts[0], octets[0]) || !Convert::ToUint8(parts[1], octets[1]) || !Convert::ToUint8(parts[2], octets[2]) || !Convert::ToUint8(parts[3], octets[3])) { return false; } From 33b618a97e450c4e0e571b8a3f6e6105616ff766 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 09:07:26 +0200 Subject: [PATCH 28/41] build(deps-dev): Bump the frontend group in /frontend with 8 updates (#284) Bumps the frontend group in /frontend with 8 updates: | Package | From | To | | --- | --- | --- | | [@playwright/test](https://github.com/microsoft/playwright) | `1.46.1` | `1.47.0` | | [@sveltejs/kit](https://github.com/sveltejs/kit/tree/HEAD/packages/kit) | `2.5.25` | `2.5.26` | | [@tailwindcss/forms](https://github.com/tailwindlabs/tailwindcss-forms) | `0.5.8` | `0.5.9` | | [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) | `22.5.2` | `22.5.4` | | [eslint](https://github.com/eslint/eslint) | `9.9.1` | `9.10.0` | | [postcss](https://github.com/postcss/postcss) | `8.4.43` | `8.4.45` | | [svelte-check](https://github.com/sveltejs/language-tools) | `3.8.6` | `4.0.1` | | [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) | `5.4.2` | `5.4.3` | Updates `@playwright/test` from 1.46.1 to 1.47.0 - [Release notes](https://github.com/microsoft/playwright/releases) - [Commits](https://github.com/microsoft/playwright/compare/v1.46.1...v1.47.0) Updates `@sveltejs/kit` from 2.5.25 to 2.5.26 - [Release notes](https://github.com/sveltejs/kit/releases) - [Changelog](https://github.com/sveltejs/kit/blob/main/packages/kit/CHANGELOG.md) - [Commits](https://github.com/sveltejs/kit/commits/@sveltejs/kit@2.5.26/packages/kit) Updates `@tailwindcss/forms` from 0.5.8 to 0.5.9 - [Release notes](https://github.com/tailwindlabs/tailwindcss-forms/releases) - [Changelog](https://github.com/tailwindlabs/tailwindcss-forms/blob/main/CHANGELOG.md) - [Commits](https://github.com/tailwindlabs/tailwindcss-forms/compare/v0.5.8...v0.5.9) Updates `@types/node` from 22.5.2 to 22.5.4 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Updates `eslint` from 9.9.1 to 9.10.0 - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md) - [Commits](https://github.com/eslint/eslint/compare/v9.9.1...v9.10.0) Updates `postcss` from 8.4.43 to 8.4.45 - [Release notes](https://github.com/postcss/postcss/releases) - [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md) - [Commits](https://github.com/postcss/postcss/compare/8.4.43...8.4.45) Updates `svelte-check` from 3.8.6 to 4.0.1 - [Release notes](https://github.com/sveltejs/language-tools/releases) - [Commits](https://github.com/sveltejs/language-tools/compare/svelte-check-3.8.6...svelte-check-4.0.1) Updates `vite` from 5.4.2 to 5.4.3 - [Release notes](https://github.com/vitejs/vite/releases) - [Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite/commits/v5.4.3/packages/vite) --- updated-dependencies: - dependency-name: "@playwright/test" dependency-type: direct:development update-type: version-update:semver-minor dependency-group: frontend - dependency-name: "@sveltejs/kit" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: "@tailwindcss/forms" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: eslint dependency-type: direct:development update-type: version-update:semver-minor dependency-group: frontend - dependency-name: postcss dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: svelte-check dependency-type: direct:development update-type: version-update:semver-major dependency-group: frontend - dependency-name: vite dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- frontend/package-lock.json | 345 ++++++++++--------------------------- frontend/package.json | 16 +- 2 files changed, 102 insertions(+), 259 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 52286af6..88c5c484 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -11,29 +11,29 @@ "@floating-ui/dom": "1.6.10" }, "devDependencies": { - "@playwright/test": "1.46.1", + "@playwright/test": "1.47.0", "@skeletonlabs/skeleton": "2.10.2", "@skeletonlabs/tw-plugin": "0.4.0", "@sveltejs/adapter-static": "^3.0.4", - "@sveltejs/kit": "2.5.25", + "@sveltejs/kit": "2.5.26", "@sveltejs/vite-plugin-svelte": "^3.1.2", - "@tailwindcss/forms": "0.5.8", + "@tailwindcss/forms": "0.5.9", "@tailwindcss/typography": "0.5.15", - "@types/node": "22.5.2", + "@types/node": "22.5.4", "autoprefixer": "10.4.20", - "eslint": "^9.9.1", + "eslint": "^9.10.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-svelte": "2.43.0", "flatbuffers": "24.3.25", - "postcss": "8.4.43", + "postcss": "8.4.45", "prettier": "3.3.3", "prettier-plugin-svelte": "3.2.6", "svelte": "4.2.19", - "svelte-check": "3.8.6", + "svelte-check": "4.0.1", "tailwindcss": "3.4.10", "tslib": "2.7.0", "typescript": "5.5.4", - "vite": "^5.4.2", + "vite": "^5.4.3", "vite-plugin-tailwind-purgecss": "^0.3.3", "vitest": "2.0.5" } @@ -531,9 +531,9 @@ } }, "node_modules/@eslint/js": { - "version": "9.9.1", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.9.1.tgz", - "integrity": "sha512-xIDQRsfg5hNBqHz04H1R3scSVwmI+KUbqjsQKHKQ1DAUSaUjYPReZZmS/5PNiKu1fUvzDd6H7DEDKACSEhu+TQ==", + "version": "9.10.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.10.0.tgz", + "integrity": "sha512-fuXtbiP5GWIn8Fz+LWoOMVf/Jxm+aajZYkhi6CuEm4SxymFM+eUWzbO9qXT+L0iCkL5+KGYMCSGxo686H19S1g==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -548,6 +548,18 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@eslint/plugin-kit": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.1.0.tgz", + "integrity": "sha512-autAXT203ixhqei9xt+qkYOvY8l6LAFIdT2UXc/RPNeUVfqRF1BV94GTJyVPFKT8nFM6MyVJhjLj9E8JWvf5zQ==", + "dev": true, + "dependencies": { + "levn": "^0.4.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@floating-ui/core": { "version": "1.6.4", "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.6.4.tgz", @@ -734,12 +746,12 @@ } }, "node_modules/@playwright/test": { - "version": "1.46.1", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.46.1.tgz", - "integrity": "sha512-Fq6SwLujA/DOIvNC2EL/SojJnkKf/rAwJ//APpJJHRyMi1PdKrY3Az+4XNQ51N4RTbItbIByQ0jgd1tayq1aeA==", + "version": "1.47.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.47.0.tgz", + "integrity": "sha512-SgAdlSwYVpToI4e/IH19IHHWvoijAYH5hu2MWSXptRypLSnzj51PcGD+rsOXFayde4P9ZLi+loXVwArg6IUkCA==", "dev": true, "dependencies": { - "playwright": "1.46.1" + "playwright": "1.47.0" }, "bin": { "playwright": "cli.js" @@ -993,9 +1005,9 @@ } }, "node_modules/@sveltejs/kit": { - "version": "2.5.25", - "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.5.25.tgz", - "integrity": "sha512-5hBSEN8XEjDZ5+2bHkFh8Z0QyOk0C187cyb12aANe1c8aeKbfu5ZD5XaC2vEH4h0alJFDXPdUkXQBmeeXeMr1A==", + "version": "2.5.26", + "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.5.26.tgz", + "integrity": "sha512-8l1JTIM2L+bS8ebq1E+nGjv/YSKSnD9Q19bYIUkc41vaEG2JjVUx6ikvPIJv2hkQAuqJLzoPrXlKk4KcyWOv3Q==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -1064,9 +1076,9 @@ } }, "node_modules/@tailwindcss/forms": { - "version": "0.5.8", - "resolved": "https://registry.npmjs.org/@tailwindcss/forms/-/forms-0.5.8.tgz", - "integrity": "sha512-DJs7B7NPD0JH7BVvdHWNviWmunlFhuEkz7FyFxE4japOWYMLl9b1D6+Z9mivJJPWr6AEbmlPqgiFRyLwFB1SgQ==", + "version": "0.5.9", + "resolved": "https://registry.npmjs.org/@tailwindcss/forms/-/forms-0.5.9.tgz", + "integrity": "sha512-tM4XVr2+UVTxXJzey9Twx48c1gcxFStqn1pQz0tRsX8o3DvxhN5oY5pvyAbUx7VTaZxpej4Zzvc6h+1RJBzpIg==", "dev": true, "dependencies": { "mini-svg-data-uri": "^1.2.3" @@ -1103,20 +1115,14 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.5.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.2.tgz", - "integrity": "sha512-acJsPTEqYqulZS/Yp/S3GgeE6GZ0qYODUR8aVr/DkhHQ8l9nd4j5x1/ZJy9/gHrRlFMqkO6i0I3E27Alu4jjPg==", + "version": "22.5.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.4.tgz", + "integrity": "sha512-FDuKUJQm/ju9fT/SeX/6+gBzoPzlVCzfzmGkwKvRHQVxi4BntVbyIwf6a4Xn62mrvndLiml6z/UBXIdEVjQLXg==", "dev": true, "dependencies": { "undici-types": "~6.19.2" } }, - "node_modules/@types/pug": { - "version": "2.0.10", - "resolved": "https://registry.npmjs.org/@types/pug/-/pug-2.0.10.tgz", - "integrity": "sha512-Sk/uYFOBAB7mb74XcpizmH0KOR2Pv3D2Hmrh1Dmy5BmK3MpdSa5kqZcg6EKBdklU0bFXX9gCfzvpnyUehrPIuA==", - "dev": true - }, "node_modules/@vitest/expect": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-2.0.5.tgz", @@ -1423,15 +1429,6 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, - "node_modules/buffer-crc32": { - "version": "0.2.13", - "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", - "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==", - "dev": true, - "engines": { - "node": "*" - } - }, "node_modules/cac": { "version": "6.7.14", "resolved": "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz", @@ -1703,15 +1700,6 @@ "node": ">=6" } }, - "node_modules/detect-indent": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.1.0.tgz", - "integrity": "sha512-reYkTUJAZb9gUuZ2RvVCNhVHdg62RHnJ7WJl8ftMi4diZ6NWlciOzQN88pUhSELEwflJht4oQDv0F0BMlwaYtA==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/devalue": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/devalue/-/devalue-5.0.0.tgz", @@ -1787,12 +1775,6 @@ "url": "https://github.com/fb55/entities?sponsor=1" } }, - "node_modules/es6-promise": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.3.1.tgz", - "integrity": "sha512-SOp9Phqvqn7jtEUxPWdWfWoLmyt2VaJ6MpvP9Comy1MceMXqE6bxvaTu4iaxpYYPzhny28Lc+M87/c2cPK6lDg==", - "dev": true - }, "node_modules/esbuild": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.21.5.tgz", @@ -1853,16 +1835,17 @@ } }, "node_modules/eslint": { - "version": "9.9.1", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.9.1.tgz", - "integrity": "sha512-dHvhrbfr4xFQ9/dq+jcVneZMyRYLjggWjk6RVsIiHsP8Rz6yZ8LvZ//iU4TrZF+SXWG+JkNF2OyiZRvzgRDqMg==", + "version": "9.10.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.10.0.tgz", + "integrity": "sha512-Y4D0IgtBZfOcOUAIQTSXBKoNGfY0REGqHJG6+Q81vNippW5YlKjHFj4soMxamKK1NXHUWuBZTLdU3Km+L/pcHw==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.11.0", "@eslint/config-array": "^0.18.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.9.1", + "@eslint/js": "9.10.0", + "@eslint/plugin-kit": "^0.1.0", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.3.0", "@nodelib/fs.walk": "^1.2.8", @@ -1885,7 +1868,6 @@ "is-glob": "^4.0.0", "is-path-inside": "^3.0.3", "json-stable-stringify-without-jsonify": "^1.0.1", - "levn": "^0.4.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", @@ -2354,26 +2336,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "dev": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/glob-parent": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", @@ -2410,12 +2372,6 @@ "integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==", "dev": true }, - "node_modules/graceful-fs": { - "version": "4.2.11", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", - "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", - "dev": true - }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -2817,15 +2773,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/min-indent": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz", - "integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==", - "dev": true, - "engines": { - "node": ">=4" - } - }, "node_modules/mini-svg-data-uri": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/mini-svg-data-uri/-/mini-svg-data-uri-1.4.4.tgz", @@ -2847,15 +2794,6 @@ "node": "*" } }, - "node_modules/minimist": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", - "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", - "dev": true, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/minipass": { "version": "7.0.4", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.4.tgz", @@ -2865,18 +2803,6 @@ "node": ">=16 || 14 >=14.17" } }, - "node_modules/mkdirp": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", - "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", - "dev": true, - "dependencies": { - "minimist": "^1.2.6" - }, - "bin": { - "mkdirp": "bin/cmd.js" - } - }, "node_modules/mri": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz", @@ -3234,12 +3160,12 @@ } }, "node_modules/playwright": { - "version": "1.46.1", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.46.1.tgz", - "integrity": "sha512-oPcr1yqoXLCkgKtD5eNUPLiN40rYEM39odNpIb6VE6S7/15gJmA1NzVv6zJYusV0e7tzvkU/utBFNa/Kpxmwng==", + "version": "1.47.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.47.0.tgz", + "integrity": "sha512-jOWiRq2pdNAX/mwLiwFYnPHpEZ4rM+fRSQpRHwEwZlP2PUANvL3+aJOF/bvISMhFD30rqMxUB4RJx9aQbfh4Ww==", "dev": true, "dependencies": { - "playwright-core": "1.46.1" + "playwright-core": "1.47.0" }, "bin": { "playwright": "cli.js" @@ -3252,9 +3178,9 @@ } }, "node_modules/playwright-core": { - "version": "1.46.1", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.46.1.tgz", - "integrity": "sha512-h9LqIQaAv+CYvWzsZ+h3RsrqCStkBHlgo6/TJlFst3cOTlLghBQlJwPOZKQJTKNaD3QIB7aAVQ+gfWbN3NXB7A==", + "version": "1.47.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.47.0.tgz", + "integrity": "sha512-1DyHT8OqkcfCkYUD9zzUTfg7EfTd+6a8MkD/NWOvjo0u/SCNd5YmY/lJwFvUZOxJbWNds+ei7ic2+R/cRz/PDg==", "dev": true, "bin": { "playwright-core": "cli.js" @@ -3264,9 +3190,9 @@ } }, "node_modules/postcss": { - "version": "8.4.43", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.43.tgz", - "integrity": "sha512-gJAQVYbh5R3gYm33FijzCZj7CHyQ3hWMgJMprLUlIYqCwTeZhBQ19wp0e9mA25BUbEvY5+EXuuaAjqQsrBxQBQ==", + "version": "8.4.45", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.45.tgz", + "integrity": "sha512-7KTLTdzdZZYscUc65XmjFiB73vBhBfbPztCYdUNvlaso9PrzjzcmjqBPR0lNGkcVlcO4BjiO5rK/qNz+XAen1Q==", "dev": true, "funding": [ { @@ -3719,30 +3645,6 @@ "node": ">=6" } }, - "node_modules/sander": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/sander/-/sander-0.5.1.tgz", - "integrity": "sha512-3lVqBir7WuKDHGrKRDn/1Ye3kwpXaDOMsiRP1wd6wpZW56gJhsbp5RqQpA6JG/P+pkXizygnr1dKR8vzWaVsfA==", - "dev": true, - "dependencies": { - "es6-promise": "^3.1.2", - "graceful-fs": "^4.1.3", - "mkdirp": "^0.5.1", - "rimraf": "^2.5.2" - } - }, - "node_modules/sander/node_modules/rimraf": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", - "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", - "dev": true, - "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" - } - }, "node_modules/semver": { "version": "7.6.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", @@ -3814,21 +3716,6 @@ "node": ">= 10" } }, - "node_modules/sorcery": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/sorcery/-/sorcery-0.11.0.tgz", - "integrity": "sha512-J69LQ22xrQB1cIFJhPfgtLuI6BpWRiWu1Y3vSsIwK/eAScqJxd/+CJlUuHQRdX2C9NGFamq+KqNywGgaThwfHw==", - "dev": true, - "dependencies": { - "@jridgewell/sourcemap-codec": "^1.4.14", - "buffer-crc32": "^0.2.5", - "minimist": "^1.2.0", - "sander": "^0.5.0" - }, - "bin": { - "sorcery": "bin/sorcery" - } - }, "node_modules/source-map-js": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz", @@ -3952,18 +3839,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/strip-indent": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz", - "integrity": "sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==", - "dev": true, - "dependencies": { - "min-indent": "^1.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -4068,23 +3943,54 @@ } }, "node_modules/svelte-check": { - "version": "3.8.6", - "resolved": "https://registry.npmjs.org/svelte-check/-/svelte-check-3.8.6.tgz", - "integrity": "sha512-ij0u4Lw/sOTREP13BdWZjiXD/BlHE6/e2e34XzmVmsp5IN4kVa3PWP65NM32JAgwjZlwBg/+JtiNV1MM8khu0Q==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/svelte-check/-/svelte-check-4.0.1.tgz", + "integrity": "sha512-AuWnCZdREoOzMhoptHPUUPYUxLNdXSkoZnPnlv19SZJJimRzLmjjZLKsOiRB4AnhgX+56/WSEdvkWXI/q2BSsA==", "dev": true, "dependencies": { - "@jridgewell/trace-mapping": "^0.3.17", + "@jridgewell/trace-mapping": "^0.3.25", "chokidar": "^3.4.1", + "fdir": "^6.2.0", "picocolors": "^1.0.0", - "sade": "^1.7.4", - "svelte-preprocess": "^5.1.3", - "typescript": "^5.0.3" + "sade": "^1.7.4" }, "bin": { "svelte-check": "bin/svelte-check" }, + "engines": { + "node": ">= 18.0.0" + }, + "peerDependencies": { + "svelte": "^4.0.0 || ^5.0.0-next.0", + "typescript": ">=5.0.0" + } + }, + "node_modules/svelte-check/node_modules/fdir": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.3.0.tgz", + "integrity": "sha512-QOnuT+BOtivR77wYvCWHfGt9s4Pz1VIMbD463vegT5MLqNXy8rYFT/lPVEqf/bhYeT6qmqrNHhsX+rWwe3rOCQ==", + "dev": true, "peerDependencies": { - "svelte": "^3.55.0 || ^4.0.0-next.0 || ^4.0.0 || ^5.0.0-next.0" + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/svelte-check/node_modules/picomatch": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", + "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", + "dev": true, + "optional": true, + "peer": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" } }, "node_modules/svelte-eslint-parser": { @@ -4126,69 +4032,6 @@ "svelte": "^3.19.0 || ^4.0.0" } }, - "node_modules/svelte-preprocess": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/svelte-preprocess/-/svelte-preprocess-5.1.3.tgz", - "integrity": "sha512-xxAkmxGHT+J/GourS5mVJeOXZzne1FR5ljeOUAMXUkfEhkLEllRreXpbl3dIYJlcJRfL1LO1uIAPpBpBfiqGPw==", - "dev": true, - "hasInstallScript": true, - "dependencies": { - "@types/pug": "^2.0.6", - "detect-indent": "^6.1.0", - "magic-string": "^0.30.5", - "sorcery": "^0.11.0", - "strip-indent": "^3.0.0" - }, - "engines": { - "node": ">= 16.0.0", - "pnpm": "^8.0.0" - }, - "peerDependencies": { - "@babel/core": "^7.10.2", - "coffeescript": "^2.5.1", - "less": "^3.11.3 || ^4.0.0", - "postcss": "^7 || ^8", - "postcss-load-config": "^2.1.0 || ^3.0.0 || ^4.0.0 || ^5.0.0", - "pug": "^3.0.0", - "sass": "^1.26.8", - "stylus": "^0.55.0", - "sugarss": "^2.0.0 || ^3.0.0 || ^4.0.0", - "svelte": "^3.23.0 || ^4.0.0-next.0 || ^4.0.0 || ^5.0.0-next.0", - "typescript": ">=3.9.5 || ^4.0.0 || ^5.0.0" - }, - "peerDependenciesMeta": { - "@babel/core": { - "optional": true - }, - "coffeescript": { - "optional": true - }, - "less": { - "optional": true - }, - "postcss": { - "optional": true - }, - "postcss-load-config": { - "optional": true - }, - "pug": { - "optional": true - }, - "sass": { - "optional": true - }, - "stylus": { - "optional": true - }, - "sugarss": { - "optional": true - }, - "typescript": { - "optional": true - } - } - }, "node_modules/tailwindcss": { "version": "3.4.10", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.10.tgz", @@ -4472,13 +4315,13 @@ "dev": true }, "node_modules/vite": { - "version": "5.4.2", - "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.2.tgz", - "integrity": "sha512-dDrQTRHp5C1fTFzcSaMxjk6vdpKvT+2/mIdE07Gw2ykehT49O0z/VHS3zZ8iV/Gh8BJJKHWOe5RjaNrW5xf/GA==", + "version": "5.4.3", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.3.tgz", + "integrity": "sha512-IH+nl64eq9lJjFqU+/yrRnrHPVTlgy42/+IzbOdaFDVlyLgI/wDlf+FCobXLX1cT0X5+7LMyH1mIy2xJdLfo8Q==", "dev": true, "dependencies": { "esbuild": "^0.21.3", - "postcss": "^8.4.41", + "postcss": "^8.4.43", "rollup": "^4.20.0" }, "bin": { diff --git a/frontend/package.json b/frontend/package.json index 993b88a0..8eb07573 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -15,29 +15,29 @@ "test:unit": "vitest" }, "devDependencies": { - "@playwright/test": "1.46.1", + "@playwright/test": "1.47.0", "@skeletonlabs/skeleton": "2.10.2", "@skeletonlabs/tw-plugin": "0.4.0", "@sveltejs/adapter-static": "^3.0.4", - "@sveltejs/kit": "2.5.25", + "@sveltejs/kit": "2.5.26", "@sveltejs/vite-plugin-svelte": "^3.1.2", - "@tailwindcss/forms": "0.5.8", + "@tailwindcss/forms": "0.5.9", "@tailwindcss/typography": "0.5.15", - "@types/node": "22.5.2", + "@types/node": "22.5.4", "autoprefixer": "10.4.20", - "eslint": "^9.9.1", + "eslint": "^9.10.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-svelte": "2.43.0", "flatbuffers": "24.3.25", - "postcss": "8.4.43", + "postcss": "8.4.45", "prettier": "3.3.3", "prettier-plugin-svelte": "3.2.6", "svelte": "4.2.19", - "svelte-check": "3.8.6", + "svelte-check": "4.0.1", "tailwindcss": "3.4.10", "tslib": "2.7.0", "typescript": "5.5.4", - "vite": "^5.4.2", + "vite": "^5.4.3", "vite-plugin-tailwind-purgecss": "^0.3.3", "vitest": "2.0.5" }, From b25e1b8762b6607ec9319825447667fb6d4523ff Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 09:08:32 +0200 Subject: [PATCH 29/41] build(deps): Bump ini in /.github/scripts in the ci-cd group (#283) Bumps the ci-cd group in /.github/scripts with 1 update: [ini](https://github.com/npm/ini). Updates `ini` from 4.1.3 to 5.0.0 - [Release notes](https://github.com/npm/ini/releases) - [Changelog](https://github.com/npm/ini/blob/main/CHANGELOG.md) - [Commits](https://github.com/npm/ini/compare/v4.1.3...v5.0.0) --- updated-dependencies: - dependency-name: ini dependency-type: direct:production update-type: version-update:semver-major dependency-group: ci-cd ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: HeavenVR --- .github/scripts/package-lock.json | 10 +++++----- .github/scripts/package.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/scripts/package-lock.json b/.github/scripts/package-lock.json index a24853e1..b2264153 100644 --- a/.github/scripts/package-lock.json +++ b/.github/scripts/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@actions/core": "^1.10.1", "@actions/github": "^6.0.0", - "ini": "^4.1.2", + "ini": "^5.0.0", "semver": "^7.6.0" } }, @@ -181,11 +181,11 @@ "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==" }, "node_modules/ini": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/ini/-/ini-4.1.3.tgz", - "integrity": "sha512-X7rqawQBvfdjS10YU1y1YVreA3SsLrW9dX2CewP2EbBJM4ypVNLDkO5y04gejPwKIY9lR+7r9gn3rFPt/kmWFg==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ini/-/ini-5.0.0.tgz", + "integrity": "sha512-+N0ngpO3e7cRUWOJAS7qw0IZIVc6XPrW4MlFBdD066F2L4k1L6ker3hLqSq7iXxU5tgS4WGkIUElWn5vogAEnw==", "engines": { - "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + "node": "^18.17.0 || >=20.5.0" } }, "node_modules/once": { diff --git a/.github/scripts/package.json b/.github/scripts/package.json index 6d654add..094d60a9 100644 --- a/.github/scripts/package.json +++ b/.github/scripts/package.json @@ -11,7 +11,7 @@ "dependencies": { "@actions/core": "^1.10.1", "@actions/github": "^6.0.0", - "ini": "^4.1.2", + "ini": "^5.0.0", "semver": "^7.6.0" } } From e5fddcbab68df639e91b2b97558200d1cbff6dfd Mon Sep 17 00:00:00 2001 From: hhvrc Date: Mon, 9 Sep 2024 09:53:05 +0200 Subject: [PATCH 30/41] Python versions fix --- .github/actions/build-firmware/action.yml | 4 ---- .github/actions/build-staticfs/action.yml | 4 ---- .github/actions/merge-partitions/action.yml | 6 +----- .github/workflows/ci-build.yml | 3 --- .github/workflows/codeql.yml | 1 - .python-version | 1 + requirements.txt | Bin 112 -> 112 bytes 7 files changed, 2 insertions(+), 17 deletions(-) create mode 100644 .python-version diff --git a/.github/actions/build-firmware/action.yml b/.github/actions/build-firmware/action.yml index 2a257723..64c484d4 100644 --- a/.github/actions/build-firmware/action.yml +++ b/.github/actions/build-firmware/action.yml @@ -1,9 +1,6 @@ name: build-firmware description: Builds the firmware partitions and uploads them as an artifact inputs: - python-version: - required: true - description: 'Python version to use' board: required: true description: 'Board name to build' @@ -31,7 +28,6 @@ runs: - uses: actions/setup-python@v5 with: - python-version: ${{ inputs.python-version }} cache: 'pip' - name: Install python dependencies diff --git a/.github/actions/build-staticfs/action.yml b/.github/actions/build-staticfs/action.yml index a0c97c0c..3a6231e9 100644 --- a/.github/actions/build-staticfs/action.yml +++ b/.github/actions/build-staticfs/action.yml @@ -1,9 +1,6 @@ name: build-staticfs description: Builds the static filesystem partition and uploads it as an artifact inputs: - python-version: - description: 'Python version to use' - required: true skip-checkout: description: 'If true, skips checkout' required: false @@ -25,7 +22,6 @@ runs: - uses: actions/setup-python@v5 with: - python-version: ${{ inputs.python-version }} cache: 'pip' - name: Install dependencies diff --git a/.github/actions/merge-partitions/action.yml b/.github/actions/merge-partitions/action.yml index 3a25eefa..34a1399b 100644 --- a/.github/actions/merge-partitions/action.yml +++ b/.github/actions/merge-partitions/action.yml @@ -1,9 +1,6 @@ name: merge-partitions description: Merges multiple partitions into a single flashable binary inputs: - python-version: - description: 'Python version to use' - required: true version: description: 'Version of the firmware' required: true @@ -28,12 +25,11 @@ runs: - uses: actions/setup-python@v5 with: - python-version: ${{ inputs.python-version }} cache: 'pip' - name: Install dependencies shell: bash - run: pip install esptool + run: pip install -r requirements.txt - name: Download static filesystem partition uses: actions/download-artifact@v4 diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 9ce50ff6..c3c943d7 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -47,7 +47,6 @@ jobs: - uses: actions/checkout@v4 - uses: ./.github/actions/build-staticfs with: - python-version: ${{ env.PYTHON_VERSION }} skip-checkout: true build-firmware: @@ -62,7 +61,6 @@ jobs: - uses: ./.github/actions/build-firmware with: - python-version: ${{ env.PYTHON_VERSION }} board: ${{ matrix.board }} version: ${{ needs.getvars.outputs.version }} skip-checkout: true @@ -85,7 +83,6 @@ jobs: - uses: ./.github/actions/merge-partitions with: - python-version: ${{ env.PYTHON_VERSION }} version: ${{ needs.getvars.outputs.version }} board: ${{ matrix.board }} skip-checkout: true diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index dccdd083..432ddc63 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -86,7 +86,6 @@ jobs: - uses: ./.github/actions/build-firmware with: - python-version: 3.12 board: ${{ matrix.board }} skip-checkout: true diff --git a/.python-version b/.python-version new file mode 100644 index 00000000..d9506ceb --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.12.5 diff --git a/requirements.txt b/requirements.txt index 7b1fa11b58018cb5465c31651148df1c54297484..d3f30e7f5897025e2c5c78d1371a251513649c82 100644 GIT binary patch delta 17 WcmXRYn2^F_%%I0$0K|q2Tnqptp#s|g delta 17 WcmXRYn2^F_#GuDu0K^syTnqptu>#=$ From 3a954e3781709ad9c80e00e32e67eb37eec26319 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Mon, 9 Sep 2024 10:06:29 +0200 Subject: [PATCH 31/41] shocklink -> openshock --- .env | 2 +- .github/workflows/codeql.yml | 2 +- src/serial/SerialInputHandler.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.env b/.env index 29f0d4cc..dcd59971 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -OPENSHOCK_API_DOMAIN=api.shocklink.net +OPENSHOCK_API_DOMAIN=api.openshock.app OPENSHOCK_FW_CDN_DOMAIN=firmware.openshock.org OPENSHOCK_FW_VERSION=0.0.0-unknown OPENSHOCK_FW_HOSTNAME=OpenShock diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 432ddc63..b10d714b 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -9,7 +9,7 @@ on: - cron: '0 6 * * 1' env: - OPENSHOCK_API_DOMAIN: api.shocklink.net + OPENSHOCK_API_DOMAIN: api.openshock.app OPENSHOCK_FW_GIT_REF: ${{ github.ref }} OPENSHOCK_FW_GIT_COMMIT: ${{ github.sha }} OPENSHOCK_FW_BUILD_DATE: ${{ github.event.head_commit.timestamp }} diff --git a/src/serial/SerialInputHandler.cpp b/src/serial/SerialInputHandler.cpp index cd36ab37..f891c2d0 100644 --- a/src/serial/SerialInputHandler.cpp +++ b/src/serial/SerialInputHandler.cpp @@ -675,7 +675,7 @@ domain [] Arguments: must be a string. Example: - domain api.shocklink.net + domain api.openshock.app )", _handleDomainCommand, }; @@ -703,7 +703,7 @@ lcgoverride set Arguments: must be a string. Example: - lcgoverride set eu1-gateway.shocklink.net + lcgoverride set eu1-gateway.openshock.app lcgoverride clear Clear the overridden LCG endpoint. From b3b4bb8b297bfc40bc96d126f327deb533d94b68 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Mon, 9 Sep 2024 10:12:18 +0200 Subject: [PATCH 32/41] Remove short commit hash to prevent version collisions --- .github/scripts/get-vars.js | 4 +--- scripts/embed_env_vars.py | 4 ---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/scripts/get-vars.js b/.github/scripts/get-vars.js index 90cb22f2..b03b8eb5 100644 --- a/.github/scripts/get-vars.js +++ b/.github/scripts/get-vars.js @@ -21,8 +21,6 @@ if (!isGitTag && !isGitBranch && !isGitPullRequest) { } const gitCommitHash = process.env.GITHUB_SHA; -const gitShortCommitHash = child_process.execSync('git rev-parse --short HEAD').toString().trim(); - if (gitCommitHash === undefined) { core.setFailed('Environment variable "GITHUB_SHA" not found'); process.exit(); @@ -85,7 +83,7 @@ if (!isGitTag) { } // Add the git commit hash to the version string - currentVersion += `+${gitShortCommitHash}`; + currentVersion += `+${gitCommitHash}`; } else { if (latestRelease.prerelease.length > 0) { currentVersion += `-${latestRelease.prerelease.join('.')}`; diff --git a/scripts/embed_env_vars.py b/scripts/embed_env_vars.py index 49bc04a5..6ca70337 100644 --- a/scripts/embed_env_vars.py +++ b/scripts/embed_env_vars.py @@ -95,10 +95,6 @@ def transform_cpp_define_string(k: str, v: str) -> str: if v.startswith('"') and v.endswith('"'): v = v[1:-1] - # Special case for OPENSHOCK_FW_GIT_COMMIT. - if k == 'OPENSHOCK_FW_GIT_COMMIT' and len(v) > 7: - v = v[0:7] - return env.StringifyMacro(v) From f4c809253f0b2c172de59fafb0cc1e766267d1b3 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Mon, 9 Sep 2024 23:15:42 +0200 Subject: [PATCH 33/41] Partially revert "Remove short commit hash to prevent version collisions" This reverts commit b3b4bb8b297bfc40bc96d126f327deb533d94b68. --- .github/scripts/get-vars.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/scripts/get-vars.js b/.github/scripts/get-vars.js index b03b8eb5..27309db4 100644 --- a/.github/scripts/get-vars.js +++ b/.github/scripts/get-vars.js @@ -21,6 +21,8 @@ if (!isGitTag && !isGitBranch && !isGitPullRequest) { } const gitCommitHash = process.env.GITHUB_SHA; +const gitShortCommitHash = gitCommitHash.substring(0, 8); + if (gitCommitHash === undefined) { core.setFailed('Environment variable "GITHUB_SHA" not found'); process.exit(); @@ -83,7 +85,7 @@ if (!isGitTag) { } // Add the git commit hash to the version string - currentVersion += `+${gitCommitHash}`; + currentVersion += `+${gitShortCommitHash}`; } else { if (latestRelease.prerelease.length > 0) { currentVersion += `-${latestRelease.prerelease.join('.')}`; From 3cd8afdcf3f08baeee7bb574ed9f521017417e94 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Sep 2024 09:31:17 +0200 Subject: [PATCH 34/41] build(deps): Bump the frontend group in /frontend with 11 updates (#285) Bumps the frontend group in /frontend with 11 updates: | Package | From | To | | --- | --- | --- | | [@floating-ui/dom](https://github.com/floating-ui/floating-ui/tree/HEAD/packages/dom) | `1.6.10` | `1.6.11` | | [@playwright/test](https://github.com/microsoft/playwright) | `1.47.0` | `1.47.1` | | [@sveltejs/kit](https://github.com/sveltejs/kit/tree/HEAD/packages/kit) | `2.5.26` | `2.5.27` | | [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) | `22.5.4` | `22.5.5` | | [eslint-plugin-svelte](https://github.com/sveltejs/eslint-plugin-svelte) | `2.43.0` | `2.44.0` | | [postcss](https://github.com/postcss/postcss) | `8.4.45` | `8.4.47` | | [svelte-check](https://github.com/sveltejs/language-tools) | `4.0.1` | `4.0.2` | | [tailwindcss](https://github.com/tailwindlabs/tailwindcss) | `3.4.10` | `3.4.11` | | [typescript](https://github.com/microsoft/TypeScript) | `5.5.4` | `5.6.2` | | [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) | `5.4.3` | `5.4.5` | | [vitest](https://github.com/vitest-dev/vitest/tree/HEAD/packages/vitest) | `2.0.5` | `2.1.1` | Updates `@floating-ui/dom` from 1.6.10 to 1.6.11 - [Release notes](https://github.com/floating-ui/floating-ui/releases) - [Changelog](https://github.com/floating-ui/floating-ui/blob/master/packages/dom/CHANGELOG.md) - [Commits](https://github.com/floating-ui/floating-ui/commits/@floating-ui/dom@1.6.11/packages/dom) Updates `@playwright/test` from 1.47.0 to 1.47.1 - [Release notes](https://github.com/microsoft/playwright/releases) - [Commits](https://github.com/microsoft/playwright/compare/v1.47.0...v1.47.1) Updates `@sveltejs/kit` from 2.5.26 to 2.5.27 - [Release notes](https://github.com/sveltejs/kit/releases) - [Changelog](https://github.com/sveltejs/kit/blob/main/packages/kit/CHANGELOG.md) - [Commits](https://github.com/sveltejs/kit/commits/@sveltejs/kit@2.5.27/packages/kit) Updates `@types/node` from 22.5.4 to 22.5.5 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Updates `eslint-plugin-svelte` from 2.43.0 to 2.44.0 - [Release notes](https://github.com/sveltejs/eslint-plugin-svelte/releases) - [Commits](https://github.com/sveltejs/eslint-plugin-svelte/compare/eslint-plugin-svelte@2.43.0...eslint-plugin-svelte@2.44.0) Updates `postcss` from 8.4.45 to 8.4.47 - [Release notes](https://github.com/postcss/postcss/releases) - [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md) - [Commits](https://github.com/postcss/postcss/compare/8.4.45...8.4.47) Updates `svelte-check` from 4.0.1 to 4.0.2 - [Release notes](https://github.com/sveltejs/language-tools/releases) - [Commits](https://github.com/sveltejs/language-tools/compare/svelte-check-4.0.1...svelte-check-4.0.2) Updates `tailwindcss` from 3.4.10 to 3.4.11 - [Release notes](https://github.com/tailwindlabs/tailwindcss/releases) - [Changelog](https://github.com/tailwindlabs/tailwindcss/blob/v3.4.11/CHANGELOG.md) - [Commits](https://github.com/tailwindlabs/tailwindcss/compare/v3.4.10...v3.4.11) Updates `typescript` from 5.5.4 to 5.6.2 - [Release notes](https://github.com/microsoft/TypeScript/releases) - [Changelog](https://github.com/microsoft/TypeScript/blob/main/azure-pipelines.release.yml) - [Commits](https://github.com/microsoft/TypeScript/compare/v5.5.4...v5.6.2) Updates `vite` from 5.4.3 to 5.4.5 - [Release notes](https://github.com/vitejs/vite/releases) - [Changelog](https://github.com/vitejs/vite/blob/v5.4.5/packages/vite/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite/commits/v5.4.5/packages/vite) Updates `vitest` from 2.0.5 to 2.1.1 - [Release notes](https://github.com/vitest-dev/vitest/releases) - [Commits](https://github.com/vitest-dev/vitest/commits/v2.1.1/packages/vitest) --- updated-dependencies: - dependency-name: "@floating-ui/dom" dependency-type: direct:production update-type: version-update:semver-patch dependency-group: frontend - dependency-name: "@playwright/test" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: "@sveltejs/kit" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: eslint-plugin-svelte dependency-type: direct:development update-type: version-update:semver-minor dependency-group: frontend - dependency-name: postcss dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: svelte-check dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: tailwindcss dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: typescript dependency-type: direct:development update-type: version-update:semver-minor dependency-group: frontend - dependency-name: vite dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: vitest dependency-type: direct:development update-type: version-update:semver-minor dependency-group: frontend ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- frontend/package-lock.json | 423 ++++++++++++++----------------------- frontend/package.json | 22 +- 2 files changed, 174 insertions(+), 271 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 88c5c484..161ae1d3 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -8,34 +8,34 @@ "name": "frontend", "version": "0.0.1", "dependencies": { - "@floating-ui/dom": "1.6.10" + "@floating-ui/dom": "1.6.11" }, "devDependencies": { - "@playwright/test": "1.47.0", + "@playwright/test": "1.47.1", "@skeletonlabs/skeleton": "2.10.2", "@skeletonlabs/tw-plugin": "0.4.0", "@sveltejs/adapter-static": "^3.0.4", - "@sveltejs/kit": "2.5.26", + "@sveltejs/kit": "2.5.27", "@sveltejs/vite-plugin-svelte": "^3.1.2", "@tailwindcss/forms": "0.5.9", "@tailwindcss/typography": "0.5.15", - "@types/node": "22.5.4", + "@types/node": "22.5.5", "autoprefixer": "10.4.20", "eslint": "^9.10.0", "eslint-config-prettier": "9.1.0", - "eslint-plugin-svelte": "2.43.0", + "eslint-plugin-svelte": "2.44.0", "flatbuffers": "24.3.25", - "postcss": "8.4.45", + "postcss": "8.4.47", "prettier": "3.3.3", "prettier-plugin-svelte": "3.2.6", "svelte": "4.2.19", - "svelte-check": "4.0.1", - "tailwindcss": "3.4.10", + "svelte-check": "4.0.2", + "tailwindcss": "3.4.11", "tslib": "2.7.0", - "typescript": "5.5.4", - "vite": "^5.4.3", + "typescript": "5.6.2", + "vite": "^5.4.5", "vite-plugin-tailwind-purgecss": "^0.3.3", - "vitest": "2.0.5" + "vitest": "2.1.1" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -569,18 +569,18 @@ } }, "node_modules/@floating-ui/dom": { - "version": "1.6.10", - "resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.6.10.tgz", - "integrity": "sha512-fskgCFv8J8OamCmyun8MfjB1Olfn+uZKjOKZ0vhYF3gRmEUXcGOjxWL8bBr7i4kIuPZ2KD2S3EUIOxnjC8kl2A==", + "version": "1.6.11", + "resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.6.11.tgz", + "integrity": "sha512-qkMCxSR24v2vGkhYDo/UzxfJN3D4syqSjyuTFz6C7XcpU1pASPRieNI0Kj5VP3/503mOfYiGY891ugBX1GlABQ==", "dependencies": { "@floating-ui/core": "^1.6.0", - "@floating-ui/utils": "^0.2.7" + "@floating-ui/utils": "^0.2.8" } }, "node_modules/@floating-ui/utils": { - "version": "0.2.7", - "resolved": "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.7.tgz", - "integrity": "sha512-X8R8Oj771YRl/w+c1HqAC1szL8zWQRwFvgDwT129k9ACdBoud/+/rX9V0qiMl6LWUdP9voC2nDVZYPMQQsb6eA==" + "version": "0.2.8", + "resolved": "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.8.tgz", + "integrity": "sha512-kym7SodPp8/wloecOpcmSnWJsK7M0E5Wg8UcFA+uO4B9s5d0ywXOEro/8HM9x0rW+TljRzul/14UYz3TleT3ig==" }, "node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", @@ -685,9 +685,9 @@ } }, "node_modules/@jridgewell/sourcemap-codec": { - "version": "1.4.15", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", - "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==", + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", + "integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==", "dev": true }, "node_modules/@jridgewell/trace-mapping": { @@ -746,12 +746,12 @@ } }, "node_modules/@playwright/test": { - "version": "1.47.0", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.47.0.tgz", - "integrity": "sha512-SgAdlSwYVpToI4e/IH19IHHWvoijAYH5hu2MWSXptRypLSnzj51PcGD+rsOXFayde4P9ZLi+loXVwArg6IUkCA==", + "version": "1.47.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.47.1.tgz", + "integrity": "sha512-dbWpcNQZ5nj16m+A5UNScYx7HX5trIy7g4phrcitn+Nk83S32EBX/CLU4hiF4RGKX/yRc93AAqtfaXB7JWBd4Q==", "dev": true, "dependencies": { - "playwright": "1.47.0" + "playwright": "1.47.1" }, "bin": { "playwright": "cli.js" @@ -1005,9 +1005,9 @@ } }, "node_modules/@sveltejs/kit": { - "version": "2.5.26", - "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.5.26.tgz", - "integrity": "sha512-8l1JTIM2L+bS8ebq1E+nGjv/YSKSnD9Q19bYIUkc41vaEG2JjVUx6ikvPIJv2hkQAuqJLzoPrXlKk4KcyWOv3Q==", + "version": "2.5.27", + "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.5.27.tgz", + "integrity": "sha512-CcbRTzl+65oWljAASL6UlxM4x3NWwd0fjq5fQOfP243vs50myFQ8lil0fr3Im6HeeQqYUCtnv8HjO8REWVPjTw==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -1115,22 +1115,22 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.5.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.4.tgz", - "integrity": "sha512-FDuKUJQm/ju9fT/SeX/6+gBzoPzlVCzfzmGkwKvRHQVxi4BntVbyIwf6a4Xn62mrvndLiml6z/UBXIdEVjQLXg==", + "version": "22.5.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.5.tgz", + "integrity": "sha512-Xjs4y5UPO/CLdzpgR6GirZJx36yScjh73+2NlLlkFRSoQN8B0DpfXPdZGnvVmLRLOsqDpOfTNv7D9trgGhmOIA==", "dev": true, "dependencies": { "undici-types": "~6.19.2" } }, "node_modules/@vitest/expect": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-2.0.5.tgz", - "integrity": "sha512-yHZtwuP7JZivj65Gxoi8upUN2OzHTi3zVfjwdpu2WrvCZPLwsJ2Ey5ILIPccoW23dd/zQBlJ4/dhi7DWNyXCpA==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-2.1.1.tgz", + "integrity": "sha512-YeueunS0HiHiQxk+KEOnq/QMzlUuOzbU1Go+PgAsHvvv3tUkJPm9xWt+6ITNTlzsMXUjmgm5T+U7KBPK2qQV6w==", "dev": true, "dependencies": { - "@vitest/spy": "2.0.5", - "@vitest/utils": "2.0.5", + "@vitest/spy": "2.1.1", + "@vitest/utils": "2.1.1", "chai": "^5.1.1", "tinyrainbow": "^1.2.0" }, @@ -1138,10 +1138,37 @@ "url": "https://opencollective.com/vitest" } }, + "node_modules/@vitest/mocker": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-2.1.1.tgz", + "integrity": "sha512-LNN5VwOEdJqCmJ/2XJBywB11DLlkbY0ooDJW3uRX5cZyYCrc4PI/ePX0iQhE3BiEGiQmK4GE7Q/PqCkkaiPnrA==", + "dev": true, + "dependencies": { + "@vitest/spy": "^2.1.0-beta.1", + "estree-walker": "^3.0.3", + "magic-string": "^0.30.11" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@vitest/spy": "2.1.1", + "msw": "^2.3.5", + "vite": "^5.0.0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, "node_modules/@vitest/pretty-format": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-2.0.5.tgz", - "integrity": "sha512-h8k+1oWHfwTkyTkb9egzwNMfJAEx4veaPSnMeKbVSjp4euqGSbQlm5+6VHwTr7u4FJslVVsUG5nopCaAYdOmSQ==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-2.1.1.tgz", + "integrity": "sha512-SjxPFOtuINDUW8/UkElJYQSFtnWX7tMksSGW0vfjxMneFqxVr8YJ979QpMbDW7g+BIiq88RAGDjf7en6rvLPPQ==", "dev": true, "dependencies": { "tinyrainbow": "^1.2.0" @@ -1151,12 +1178,12 @@ } }, "node_modules/@vitest/runner": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-2.0.5.tgz", - "integrity": "sha512-TfRfZa6Bkk9ky4tW0z20WKXFEwwvWhRY+84CnSEtq4+3ZvDlJyY32oNTJtM7AW9ihW90tX/1Q78cb6FjoAs+ig==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-2.1.1.tgz", + "integrity": "sha512-uTPuY6PWOYitIkLPidaY5L3t0JJITdGTSwBtwMjKzo5O6RCOEncz9PUN+0pDidX8kTHYjO0EwUIvhlGpnGpxmA==", "dev": true, "dependencies": { - "@vitest/utils": "2.0.5", + "@vitest/utils": "2.1.1", "pathe": "^1.1.2" }, "funding": { @@ -1164,13 +1191,13 @@ } }, "node_modules/@vitest/snapshot": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-2.0.5.tgz", - "integrity": "sha512-SgCPUeDFLaM0mIUHfaArq8fD2WbaXG/zVXjRupthYfYGzc8ztbFbu6dUNOblBG7XLMR1kEhS/DNnfCZ2IhdDew==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-2.1.1.tgz", + "integrity": "sha512-BnSku1WFy7r4mm96ha2FzN99AZJgpZOWrAhtQfoxjUU5YMRpq1zmHRq7a5K9/NjqonebO7iVDla+VvZS8BOWMw==", "dev": true, "dependencies": { - "@vitest/pretty-format": "2.0.5", - "magic-string": "^0.30.10", + "@vitest/pretty-format": "2.1.1", + "magic-string": "^0.30.11", "pathe": "^1.1.2" }, "funding": { @@ -1178,9 +1205,9 @@ } }, "node_modules/@vitest/spy": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-2.0.5.tgz", - "integrity": "sha512-c/jdthAhvJdpfVuaexSrnawxZz6pywlTPe84LUB2m/4t3rl2fTo9NFGBG4oWgaD+FTgDDV8hJ/nibT7IfH3JfA==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-2.1.1.tgz", + "integrity": "sha512-ZM39BnZ9t/xZ/nF4UwRH5il0Sw93QnZXd9NAZGRpIgj0yvVwPpLd702s/Cx955rGaMlyBQkZJ2Ir7qyY48VZ+g==", "dev": true, "dependencies": { "tinyspy": "^3.0.0" @@ -1190,13 +1217,12 @@ } }, "node_modules/@vitest/utils": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-2.0.5.tgz", - "integrity": "sha512-d8HKbqIcya+GR67mkZbrzhS5kKhtp8dQLcmRZLGTscGVg7yImT82cIrhtn2L8+VujWcy6KZweApgNmPsTAO/UQ==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-2.1.1.tgz", + "integrity": "sha512-Y6Q9TsI+qJ2CC0ZKj6VBb+T8UPz593N113nnUykqwANqhgf3QkZeHFlusgKLTqrnVHbj/XDKZcDHol+dxVT+rQ==", "dev": true, "dependencies": { - "@vitest/pretty-format": "2.0.5", - "estree-walker": "^3.0.3", + "@vitest/pretty-format": "2.1.1", "loupe": "^3.1.1", "tinyrainbow": "^1.2.0" }, @@ -1651,12 +1677,12 @@ } }, "node_modules/debug": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.5.tgz", - "integrity": "sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==", + "version": "4.3.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", + "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", "dev": true, "dependencies": { - "ms": "2.1.2" + "ms": "^2.1.3" }, "engines": { "node": ">=6.0" @@ -1921,9 +1947,9 @@ } }, "node_modules/eslint-plugin-svelte": { - "version": "2.43.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-svelte/-/eslint-plugin-svelte-2.43.0.tgz", - "integrity": "sha512-REkxQWvg2pp7QVLxQNa+dJ97xUqRe7Y2JJbSWkHSuszu0VcblZtXkPBPckkivk99y5CdLw4slqfPylL2d/X4jQ==", + "version": "2.44.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-svelte/-/eslint-plugin-svelte-2.44.0.tgz", + "integrity": "sha512-wav4MOs02vBb1WjvTCYItwJCxMkuk2Z4p+K/eyjL0N/z7ahXLP+0LtQQjiKc2ezuif7GnZLbD1F3o1VHzSvdVg==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", @@ -1936,7 +1962,7 @@ "postcss-safe-parser": "^6.0.0", "postcss-selector-parser": "^6.1.0", "semver": "^7.6.2", - "svelte-eslint-parser": "^0.41.0" + "svelte-eslint-parser": "^0.41.1" }, "engines": { "node": "^14.17.0 || >=16.0.0" @@ -2114,29 +2140,6 @@ "node": ">=0.10.0" } }, - "node_modules/execa": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/execa/-/execa-8.0.1.tgz", - "integrity": "sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==", - "dev": true, - "dependencies": { - "cross-spawn": "^7.0.3", - "get-stream": "^8.0.1", - "human-signals": "^5.0.0", - "is-stream": "^3.0.0", - "merge-stream": "^2.0.0", - "npm-run-path": "^5.1.0", - "onetime": "^6.0.0", - "signal-exit": "^4.1.0", - "strip-final-newline": "^3.0.0" - }, - "engines": { - "node": ">=16.17" - }, - "funding": { - "url": "https://github.com/sindresorhus/execa?sponsor=1" - } - }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -2324,18 +2327,6 @@ "node": "*" } }, - "node_modules/get-stream": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-8.0.1.tgz", - "integrity": "sha512-VaUJspBffn/LMCJVoMvSAdmscJyS1auj5Zulnn5UoYcY531UWmdwhRWkcGKnGU93m5HSXP9LP2usOryrBtQowA==", - "dev": true, - "engines": { - "node": ">=16" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/glob-parent": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", @@ -2393,15 +2384,6 @@ "node": ">= 0.4" } }, - "node_modules/human-signals": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-5.0.0.tgz", - "integrity": "sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==", - "dev": true, - "engines": { - "node": ">=16.17.0" - } - }, "node_modules/ignore": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz", @@ -2543,18 +2525,6 @@ "@types/estree": "*" } }, - "node_modules/is-stream": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-3.0.0.tgz", - "integrity": "sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==", - "dev": true, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -2719,12 +2689,12 @@ } }, "node_modules/magic-string": { - "version": "0.30.10", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.10.tgz", - "integrity": "sha512-iIRwTIf0QKV3UAnYK4PU8uiEc4SRh5jX0mwpIwETPpHdhVM4f53RSwS/vXvN1JhGX+Cs7B8qIq3d6AH49O5fAQ==", + "version": "0.30.11", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.11.tgz", + "integrity": "sha512-+Wri9p0QHMy+545hKww7YAu5NyzF8iomPL/RQazugQ9+Ez4Ic3mERMd8ZTX5rfK944j+560ZJi8iAwgak1Ac7A==", "dev": true, "dependencies": { - "@jridgewell/sourcemap-codec": "^1.4.15" + "@jridgewell/sourcemap-codec": "^1.5.0" } }, "node_modules/mdn-data": { @@ -2733,12 +2703,6 @@ "integrity": "sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==", "dev": true }, - "node_modules/merge-stream": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", - "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", - "dev": true - }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -2761,18 +2725,6 @@ "node": ">=8.6" } }, - "node_modules/mimic-fn": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", - "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/mini-svg-data-uri": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/mini-svg-data-uri/-/mini-svg-data-uri-1.4.4.tgz", @@ -2822,9 +2774,9 @@ } }, "node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "dev": true }, "node_modules/mz": { @@ -2886,33 +2838,6 @@ "node": ">=0.10.0" } }, - "node_modules/npm-run-path": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.1.0.tgz", - "integrity": "sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==", - "dev": true, - "dependencies": { - "path-key": "^4.0.0" - }, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/npm-run-path/node_modules/path-key": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-key/-/path-key-4.0.0.tgz", - "integrity": "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -2940,21 +2865,6 @@ "wrappy": "1" } }, - "node_modules/onetime": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-6.0.0.tgz", - "integrity": "sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==", - "dev": true, - "dependencies": { - "mimic-fn": "^4.0.0" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/optionator": { "version": "0.9.3", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz", @@ -3124,9 +3034,9 @@ } }, "node_modules/picocolors": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.1.tgz", - "integrity": "sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.0.tgz", + "integrity": "sha512-TQ92mBOW0l3LeMeyLV6mzy/kWr8lkd/hp3mTg7wYK7zJhuBStmGMBG0BdeDZS/dZx1IukaX6Bk11zcln25o1Aw==", "dev": true }, "node_modules/picomatch": { @@ -3160,12 +3070,12 @@ } }, "node_modules/playwright": { - "version": "1.47.0", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.47.0.tgz", - "integrity": "sha512-jOWiRq2pdNAX/mwLiwFYnPHpEZ4rM+fRSQpRHwEwZlP2PUANvL3+aJOF/bvISMhFD30rqMxUB4RJx9aQbfh4Ww==", + "version": "1.47.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.47.1.tgz", + "integrity": "sha512-SUEKi6947IqYbKxRiqnbUobVZY4bF1uu+ZnZNJX9DfU1tlf2UhWfvVjLf01pQx9URsOr18bFVUKXmanYWhbfkw==", "dev": true, "dependencies": { - "playwright-core": "1.47.0" + "playwright-core": "1.47.1" }, "bin": { "playwright": "cli.js" @@ -3178,9 +3088,9 @@ } }, "node_modules/playwright-core": { - "version": "1.47.0", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.47.0.tgz", - "integrity": "sha512-1DyHT8OqkcfCkYUD9zzUTfg7EfTd+6a8MkD/NWOvjo0u/SCNd5YmY/lJwFvUZOxJbWNds+ei7ic2+R/cRz/PDg==", + "version": "1.47.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.47.1.tgz", + "integrity": "sha512-i1iyJdLftqtt51mEk6AhYFaAJCDx0xQ/O5NU8EKaWFgMjItPVma542Nh/Aq8aLCjIJSzjaiEQGW/nyqLkGF1OQ==", "dev": true, "bin": { "playwright-core": "cli.js" @@ -3190,9 +3100,9 @@ } }, "node_modules/postcss": { - "version": "8.4.45", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.45.tgz", - "integrity": "sha512-7KTLTdzdZZYscUc65XmjFiB73vBhBfbPztCYdUNvlaso9PrzjzcmjqBPR0lNGkcVlcO4BjiO5rK/qNz+XAen1Q==", + "version": "8.4.47", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.47.tgz", + "integrity": "sha512-56rxCq7G/XfB4EkXq9Egn5GCqugWvDFjafDOThIdMBsI15iqPqR5r15TfSr1YPYeEI19YeaXMCbY6u88Y76GLQ==", "dev": true, "funding": [ { @@ -3210,8 +3120,8 @@ ], "dependencies": { "nanoid": "^3.3.7", - "picocolors": "^1.0.1", - "source-map-js": "^1.2.0" + "picocolors": "^1.1.0", + "source-map-js": "^1.2.1" }, "engines": { "node": "^10 || ^12 || >=14" @@ -3717,9 +3627,9 @@ } }, "node_modules/source-map-js": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz", - "integrity": "sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", + "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==", "dev": true, "engines": { "node": ">=0.10.0" @@ -3827,18 +3737,6 @@ "node": ">=8" } }, - "node_modules/strip-final-newline": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-3.0.0.tgz", - "integrity": "sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -3943,9 +3841,9 @@ } }, "node_modules/svelte-check": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/svelte-check/-/svelte-check-4.0.1.tgz", - "integrity": "sha512-AuWnCZdREoOzMhoptHPUUPYUxLNdXSkoZnPnlv19SZJJimRzLmjjZLKsOiRB4AnhgX+56/WSEdvkWXI/q2BSsA==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/svelte-check/-/svelte-check-4.0.2.tgz", + "integrity": "sha512-w2yqcG9ELJe2RJCnAvB7v0OgkHhL3czzz/tVoxGFfO6y4mOrF6QHCDhXijeXzsU7LVKEwWS3Qd9tza4JBuDxqA==", "dev": true, "dependencies": { "@jridgewell/trace-mapping": "^0.3.25", @@ -3994,9 +3892,9 @@ } }, "node_modules/svelte-eslint-parser": { - "version": "0.41.0", - "resolved": "https://registry.npmjs.org/svelte-eslint-parser/-/svelte-eslint-parser-0.41.0.tgz", - "integrity": "sha512-L6f4hOL+AbgfBIB52Z310pg1d2QjRqm7wy3kI1W6hhdhX5bvu7+f0R6w4ykp5HoDdzq+vGhIJmsisaiJDGmVfA==", + "version": "0.41.1", + "resolved": "https://registry.npmjs.org/svelte-eslint-parser/-/svelte-eslint-parser-0.41.1.tgz", + "integrity": "sha512-08ndI6zTghzI8SuJAFpvMbA/haPSGn3xz19pjre19yYMw8Nw/wQJ2PrZBI/L8ijGTgtkWCQQiLLy+Z1tfaCwNA==", "dev": true, "dependencies": { "eslint-scope": "^7.2.2", @@ -4033,9 +3931,9 @@ } }, "node_modules/tailwindcss": { - "version": "3.4.10", - "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.10.tgz", - "integrity": "sha512-KWZkVPm7yJRhdu4SRSl9d4AK2wM3a50UsvgHZO7xY77NQr2V+fIrEuoDGQcbvswWvFGbS2f6e+jC/6WJm1Dl0w==", + "version": "3.4.11", + "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.11.tgz", + "integrity": "sha512-qhEuBcLemjSJk5ajccN9xJFtM/h0AVCPaA6C92jNP+M2J8kX+eMJHI7R2HFKUvvAsMpcfLILMCFYSeDwpMmlUg==", "dev": true, "dependencies": { "@alloc/quick-lru": "^5.2.0", @@ -4173,9 +4071,15 @@ } }, "node_modules/tinybench": { - "version": "2.8.0", - "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.8.0.tgz", - "integrity": "sha512-1/eK7zUnIklz4JUUlL+658n58XO2hHLQfSk1Zf2LKieUjxidN16eKFEoDEfjHc3ohofSSqK3X5yO6VGb6iW8Lw==", + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", + "integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==", + "dev": true + }, + "node_modules/tinyexec": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-0.3.0.tgz", + "integrity": "sha512-tVGE0mVJPGb0chKhqmsoosjsS+qUnJVGJpZgsHYQcGoPlG3B51R3PouqTgEGH2Dc9jjFyOqOpix6ZHNMXp1FZg==", "dev": true }, "node_modules/tinypool": { @@ -4197,9 +4101,9 @@ } }, "node_modules/tinyspy": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-3.0.0.tgz", - "integrity": "sha512-q5nmENpTHgiPVd1cJDDc9cVoYN5x4vCvwT3FMilvKPKneCBZAxn2YWQjDF0UMcE9k0Cay1gBiDfTMU0g+mPMQA==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-3.0.2.tgz", + "integrity": "sha512-n1cw8k1k0x4pgA2+9XrOkFydTerNcJ1zWCO5Nn9scWHTD+5tp8dghT2x1uduQePZTZgd3Tupf+x9BxJjeJi77Q==", "dev": true, "engines": { "node": ">=14.0.0" @@ -4251,9 +4155,9 @@ } }, "node_modules/typescript": { - "version": "5.5.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", - "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz", + "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -4315,9 +4219,9 @@ "dev": true }, "node_modules/vite": { - "version": "5.4.3", - "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.3.tgz", - "integrity": "sha512-IH+nl64eq9lJjFqU+/yrRnrHPVTlgy42/+IzbOdaFDVlyLgI/wDlf+FCobXLX1cT0X5+7LMyH1mIy2xJdLfo8Q==", + "version": "5.4.5", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.5.tgz", + "integrity": "sha512-pXqR0qtb2bTwLkev4SE3r4abCNioP3GkjvIDLlzziPpXtHgiJIjuKl+1GN6ESOT3wMjG3JTeARopj2SwYaHTOA==", "dev": true, "dependencies": { "esbuild": "^0.21.3", @@ -4374,15 +4278,14 @@ } }, "node_modules/vite-node": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/vite-node/-/vite-node-2.0.5.tgz", - "integrity": "sha512-LdsW4pxj0Ot69FAoXZ1yTnA9bjGohr2yNBU7QKRxpz8ITSkhuDl6h3zS/tvgz4qrNjeRnvrWeXQ8ZF7Um4W00Q==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/vite-node/-/vite-node-2.1.1.tgz", + "integrity": "sha512-N/mGckI1suG/5wQI35XeR9rsMsPqKXzq1CdUndzVstBj/HvyxxGctwnK6WX43NGt5L3Z5tcRf83g4TITKJhPrA==", "dev": true, "dependencies": { "cac": "^6.7.14", - "debug": "^4.3.5", + "debug": "^4.3.6", "pathe": "^1.1.2", - "tinyrainbow": "^1.2.0", "vite": "^5.0.0" }, "bin": { @@ -4453,29 +4356,29 @@ } }, "node_modules/vitest": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/vitest/-/vitest-2.0.5.tgz", - "integrity": "sha512-8GUxONfauuIdeSl5f9GTgVEpg5BTOlplET4WEDaeY2QBiN8wSm68vxN/tb5z405OwppfoCavnwXafiaYBC/xOA==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/vitest/-/vitest-2.1.1.tgz", + "integrity": "sha512-97We7/VC0e9X5zBVkvt7SGQMGrRtn3KtySFQG5fpaMlS+l62eeXRQO633AYhSTC3z7IMebnPPNjGXVGNRFlxBA==", "dev": true, "dependencies": { - "@ampproject/remapping": "^2.3.0", - "@vitest/expect": "2.0.5", - "@vitest/pretty-format": "^2.0.5", - "@vitest/runner": "2.0.5", - "@vitest/snapshot": "2.0.5", - "@vitest/spy": "2.0.5", - "@vitest/utils": "2.0.5", + "@vitest/expect": "2.1.1", + "@vitest/mocker": "2.1.1", + "@vitest/pretty-format": "^2.1.1", + "@vitest/runner": "2.1.1", + "@vitest/snapshot": "2.1.1", + "@vitest/spy": "2.1.1", + "@vitest/utils": "2.1.1", "chai": "^5.1.1", - "debug": "^4.3.5", - "execa": "^8.0.1", - "magic-string": "^0.30.10", + "debug": "^4.3.6", + "magic-string": "^0.30.11", "pathe": "^1.1.2", "std-env": "^3.7.0", - "tinybench": "^2.8.0", + "tinybench": "^2.9.0", + "tinyexec": "^0.3.0", "tinypool": "^1.0.0", "tinyrainbow": "^1.2.0", "vite": "^5.0.0", - "vite-node": "2.0.5", + "vite-node": "2.1.1", "why-is-node-running": "^2.3.0" }, "bin": { @@ -4490,8 +4393,8 @@ "peerDependencies": { "@edge-runtime/vm": "*", "@types/node": "^18.0.0 || >=20.0.0", - "@vitest/browser": "2.0.5", - "@vitest/ui": "2.0.5", + "@vitest/browser": "2.1.1", + "@vitest/ui": "2.1.1", "happy-dom": "*", "jsdom": "*" }, diff --git a/frontend/package.json b/frontend/package.json index 8eb07573..2c4bd11d 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -15,34 +15,34 @@ "test:unit": "vitest" }, "devDependencies": { - "@playwright/test": "1.47.0", + "@playwright/test": "1.47.1", "@skeletonlabs/skeleton": "2.10.2", "@skeletonlabs/tw-plugin": "0.4.0", "@sveltejs/adapter-static": "^3.0.4", - "@sveltejs/kit": "2.5.26", + "@sveltejs/kit": "2.5.27", "@sveltejs/vite-plugin-svelte": "^3.1.2", "@tailwindcss/forms": "0.5.9", "@tailwindcss/typography": "0.5.15", - "@types/node": "22.5.4", + "@types/node": "22.5.5", "autoprefixer": "10.4.20", "eslint": "^9.10.0", "eslint-config-prettier": "9.1.0", - "eslint-plugin-svelte": "2.43.0", + "eslint-plugin-svelte": "2.44.0", "flatbuffers": "24.3.25", - "postcss": "8.4.45", + "postcss": "8.4.47", "prettier": "3.3.3", "prettier-plugin-svelte": "3.2.6", "svelte": "4.2.19", - "svelte-check": "4.0.1", - "tailwindcss": "3.4.10", + "svelte-check": "4.0.2", + "tailwindcss": "3.4.11", "tslib": "2.7.0", - "typescript": "5.5.4", - "vite": "^5.4.3", + "typescript": "5.6.2", + "vite": "^5.4.5", "vite-plugin-tailwind-purgecss": "^0.3.3", - "vitest": "2.0.5" + "vitest": "2.1.1" }, "type": "module", "dependencies": { - "@floating-ui/dom": "1.6.10" + "@floating-ui/dom": "1.6.11" } } From aa3aab71dd7468af198992f92fc508a7fb75c42b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 20 Sep 2024 10:30:47 +0200 Subject: [PATCH 35/41] build(deps-dev): Bump vite in /frontend in the npm_and_yarn group (#286) Bumps the npm_and_yarn group in /frontend with 1 update: [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite). Updates `vite` from 5.4.5 to 5.4.6 - [Release notes](https://github.com/vitejs/vite/releases) - [Changelog](https://github.com/vitejs/vite/blob/v5.4.6/packages/vite/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite/commits/v5.4.6/packages/vite) --- updated-dependencies: - dependency-name: vite dependency-type: direct:development dependency-group: npm_and_yarn ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- frontend/package-lock.json | 8 ++++---- frontend/package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 161ae1d3..c75bde85 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -33,7 +33,7 @@ "tailwindcss": "3.4.11", "tslib": "2.7.0", "typescript": "5.6.2", - "vite": "^5.4.5", + "vite": "^5.4.6", "vite-plugin-tailwind-purgecss": "^0.3.3", "vitest": "2.1.1" } @@ -4219,9 +4219,9 @@ "dev": true }, "node_modules/vite": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.5.tgz", - "integrity": "sha512-pXqR0qtb2bTwLkev4SE3r4abCNioP3GkjvIDLlzziPpXtHgiJIjuKl+1GN6ESOT3wMjG3JTeARopj2SwYaHTOA==", + "version": "5.4.6", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.6.tgz", + "integrity": "sha512-IeL5f8OO5nylsgzd9tq4qD2QqI0k2CQLGrWD0rCN0EQJZpBK5vJAx0I+GDkMOXxQX/OfFHMuLIx6ddAxGX/k+Q==", "dev": true, "dependencies": { "esbuild": "^0.21.3", diff --git a/frontend/package.json b/frontend/package.json index 2c4bd11d..3dff24bd 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -37,7 +37,7 @@ "tailwindcss": "3.4.11", "tslib": "2.7.0", "typescript": "5.6.2", - "vite": "^5.4.5", + "vite": "^5.4.6", "vite-plugin-tailwind-purgecss": "^0.3.3", "vitest": "2.1.1" }, From 7b64d7e8c2e5ae9fed67a66bff3b790bf8c62c52 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 09:09:39 +0200 Subject: [PATCH 36/41] build(deps-dev): Bump the frontend group in /frontend with 6 updates (#288) Bumps the frontend group in /frontend with 6 updates: | Package | From | To | | --- | --- | --- | | [@playwright/test](https://github.com/microsoft/playwright) | `1.47.1` | `1.47.2` | | [@sveltejs/adapter-static](https://github.com/sveltejs/kit/tree/HEAD/packages/adapter-static) | `3.0.4` | `3.0.5` | | [@sveltejs/kit](https://github.com/sveltejs/kit/tree/HEAD/packages/kit) | `2.5.27` | `2.5.28` | | [eslint](https://github.com/eslint/eslint) | `9.10.0` | `9.11.0` | | [tailwindcss](https://github.com/tailwindlabs/tailwindcss) | `3.4.11` | `3.4.12` | | [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) | `5.4.6` | `5.4.7` | Updates `@playwright/test` from 1.47.1 to 1.47.2 - [Release notes](https://github.com/microsoft/playwright/releases) - [Commits](https://github.com/microsoft/playwright/compare/v1.47.1...v1.47.2) Updates `@sveltejs/adapter-static` from 3.0.4 to 3.0.5 - [Release notes](https://github.com/sveltejs/kit/releases) - [Changelog](https://github.com/sveltejs/kit/blob/main/packages/adapter-static/CHANGELOG.md) - [Commits](https://github.com/sveltejs/kit/commits/@sveltejs/adapter-static@3.0.5/packages/adapter-static) Updates `@sveltejs/kit` from 2.5.27 to 2.5.28 - [Release notes](https://github.com/sveltejs/kit/releases) - [Changelog](https://github.com/sveltejs/kit/blob/main/packages/kit/CHANGELOG.md) - [Commits](https://github.com/sveltejs/kit/commits/@sveltejs/kit@2.5.28/packages/kit) Updates `eslint` from 9.10.0 to 9.11.0 - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md) - [Commits](https://github.com/eslint/eslint/compare/v9.10.0...v9.11.0) Updates `tailwindcss` from 3.4.11 to 3.4.12 - [Release notes](https://github.com/tailwindlabs/tailwindcss/releases) - [Changelog](https://github.com/tailwindlabs/tailwindcss/blob/v3.4.12/CHANGELOG.md) - [Commits](https://github.com/tailwindlabs/tailwindcss/compare/v3.4.11...v3.4.12) Updates `vite` from 5.4.6 to 5.4.7 - [Release notes](https://github.com/vitejs/vite/releases) - [Changelog](https://github.com/vitejs/vite/blob/v5.4.7/packages/vite/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite/commits/v5.4.7/packages/vite) --- updated-dependencies: - dependency-name: "@playwright/test" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: "@sveltejs/adapter-static" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: "@sveltejs/kit" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: eslint dependency-type: direct:development update-type: version-update:semver-minor dependency-group: frontend - dependency-name: tailwindcss dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend - dependency-name: vite dependency-type: direct:development update-type: version-update:semver-patch dependency-group: frontend ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- frontend/package-lock.json | 80 +++++++++++++++++++------------------- frontend/package.json | 12 +++--- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index c75bde85..b694e20e 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -11,17 +11,17 @@ "@floating-ui/dom": "1.6.11" }, "devDependencies": { - "@playwright/test": "1.47.1", + "@playwright/test": "1.47.2", "@skeletonlabs/skeleton": "2.10.2", "@skeletonlabs/tw-plugin": "0.4.0", - "@sveltejs/adapter-static": "^3.0.4", - "@sveltejs/kit": "2.5.27", + "@sveltejs/adapter-static": "^3.0.5", + "@sveltejs/kit": "2.5.28", "@sveltejs/vite-plugin-svelte": "^3.1.2", "@tailwindcss/forms": "0.5.9", "@tailwindcss/typography": "0.5.15", "@types/node": "22.5.5", "autoprefixer": "10.4.20", - "eslint": "^9.10.0", + "eslint": "^9.11.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-svelte": "2.44.0", "flatbuffers": "24.3.25", @@ -30,10 +30,10 @@ "prettier-plugin-svelte": "3.2.6", "svelte": "4.2.19", "svelte-check": "4.0.2", - "tailwindcss": "3.4.11", + "tailwindcss": "3.4.12", "tslib": "2.7.0", "typescript": "5.6.2", - "vite": "^5.4.6", + "vite": "^5.4.7", "vite-plugin-tailwind-purgecss": "^0.3.3", "vitest": "2.1.1" } @@ -531,9 +531,9 @@ } }, "node_modules/@eslint/js": { - "version": "9.10.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.10.0.tgz", - "integrity": "sha512-fuXtbiP5GWIn8Fz+LWoOMVf/Jxm+aajZYkhi6CuEm4SxymFM+eUWzbO9qXT+L0iCkL5+KGYMCSGxo686H19S1g==", + "version": "9.11.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.11.0.tgz", + "integrity": "sha512-LPkkenkDqyzTFauZLLAPhIb48fj6drrfMvRGSL9tS3AcZBSVTllemLSNyCvHNNL2t797S/6DJNSIwRwXgMO/eQ==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -549,9 +549,9 @@ } }, "node_modules/@eslint/plugin-kit": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.1.0.tgz", - "integrity": "sha512-autAXT203ixhqei9xt+qkYOvY8l6LAFIdT2UXc/RPNeUVfqRF1BV94GTJyVPFKT8nFM6MyVJhjLj9E8JWvf5zQ==", + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.2.0.tgz", + "integrity": "sha512-vH9PiIMMwvhCx31Af3HiGzsVNULDbyVkHXwlemn/B0TFj/00ho3y55efXrUZTfQipxoHC5u4xq6zblww1zm1Ig==", "dev": true, "dependencies": { "levn": "^0.4.1" @@ -746,12 +746,12 @@ } }, "node_modules/@playwright/test": { - "version": "1.47.1", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.47.1.tgz", - "integrity": "sha512-dbWpcNQZ5nj16m+A5UNScYx7HX5trIy7g4phrcitn+Nk83S32EBX/CLU4hiF4RGKX/yRc93AAqtfaXB7JWBd4Q==", + "version": "1.47.2", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.47.2.tgz", + "integrity": "sha512-jTXRsoSPONAs8Za9QEQdyjFn+0ZQFjCiIztAIF6bi1HqhBzG9Ma7g1WotyiGqFSBRZjIEqMdT8RUlbk1QVhzCQ==", "dev": true, "dependencies": { - "playwright": "1.47.1" + "playwright": "1.47.2" }, "bin": { "playwright": "cli.js" @@ -996,18 +996,18 @@ } }, "node_modules/@sveltejs/adapter-static": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/@sveltejs/adapter-static/-/adapter-static-3.0.4.tgz", - "integrity": "sha512-Qm4GAHCnRXwfWG9/AtnQ7mqjyjTs7i0Opyb8H2KH9rMR7fLxqiPx/tXeoE6HHo66+72CjyOb4nFH3lrejY4vzA==", + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@sveltejs/adapter-static/-/adapter-static-3.0.5.tgz", + "integrity": "sha512-kFJR7RxeB6FBvrKZWAEzIALatgy11ISaaZbcPup8JdWUdrmmfUHHTJ738YHJTEfnCiiXi6aX8Q6ePY7tnSMD6Q==", "dev": true, "peerDependencies": { "@sveltejs/kit": "^2.0.0" } }, "node_modules/@sveltejs/kit": { - "version": "2.5.27", - "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.5.27.tgz", - "integrity": "sha512-CcbRTzl+65oWljAASL6UlxM4x3NWwd0fjq5fQOfP243vs50myFQ8lil0fr3Im6HeeQqYUCtnv8HjO8REWVPjTw==", + "version": "2.5.28", + "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.5.28.tgz", + "integrity": "sha512-/O7pvFGBsQPcFa9UrW8eUC5uHTOXLsUp3SN0dY6YmRAL9nfPSrJsSJk//j5vMpinSshzUjteAFcfQTU+04Ka1w==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -1861,17 +1861,17 @@ } }, "node_modules/eslint": { - "version": "9.10.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.10.0.tgz", - "integrity": "sha512-Y4D0IgtBZfOcOUAIQTSXBKoNGfY0REGqHJG6+Q81vNippW5YlKjHFj4soMxamKK1NXHUWuBZTLdU3Km+L/pcHw==", + "version": "9.11.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.11.0.tgz", + "integrity": "sha512-yVS6XODx+tMFMDFcG4+Hlh+qG7RM6cCJXtQhCKLSsr3XkLvWggHjCqjfh0XsPPnt1c56oaT6PMgW9XWQQjdHXA==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.11.0", "@eslint/config-array": "^0.18.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.10.0", - "@eslint/plugin-kit": "^0.1.0", + "@eslint/js": "9.11.0", + "@eslint/plugin-kit": "^0.2.0", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.3.0", "@nodelib/fs.walk": "^1.2.8", @@ -3070,12 +3070,12 @@ } }, "node_modules/playwright": { - "version": "1.47.1", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.47.1.tgz", - "integrity": "sha512-SUEKi6947IqYbKxRiqnbUobVZY4bF1uu+ZnZNJX9DfU1tlf2UhWfvVjLf01pQx9URsOr18bFVUKXmanYWhbfkw==", + "version": "1.47.2", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.47.2.tgz", + "integrity": "sha512-nx1cLMmQWqmA3UsnjaaokyoUpdVaaDhJhMoxX2qj3McpjnsqFHs516QAKYhqHAgOP+oCFTEOCOAaD1RgD/RQfA==", "dev": true, "dependencies": { - "playwright-core": "1.47.1" + "playwright-core": "1.47.2" }, "bin": { "playwright": "cli.js" @@ -3088,9 +3088,9 @@ } }, "node_modules/playwright-core": { - "version": "1.47.1", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.47.1.tgz", - "integrity": "sha512-i1iyJdLftqtt51mEk6AhYFaAJCDx0xQ/O5NU8EKaWFgMjItPVma542Nh/Aq8aLCjIJSzjaiEQGW/nyqLkGF1OQ==", + "version": "1.47.2", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.47.2.tgz", + "integrity": "sha512-3JvMfF+9LJfe16l7AbSmU555PaTl2tPyQsVInqm3id16pdDfvZ8TTZ/pyzmkbDrZTQefyzU7AIHlZqQnxpqHVQ==", "dev": true, "bin": { "playwright-core": "cli.js" @@ -3931,9 +3931,9 @@ } }, "node_modules/tailwindcss": { - "version": "3.4.11", - "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.11.tgz", - "integrity": "sha512-qhEuBcLemjSJk5ajccN9xJFtM/h0AVCPaA6C92jNP+M2J8kX+eMJHI7R2HFKUvvAsMpcfLILMCFYSeDwpMmlUg==", + "version": "3.4.12", + "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.12.tgz", + "integrity": "sha512-Htf/gHj2+soPb9UayUNci/Ja3d8pTmu9ONTfh4QY8r3MATTZOzmv6UYWF7ZwikEIC8okpfqmGqrmDehua8mF8w==", "dev": true, "dependencies": { "@alloc/quick-lru": "^5.2.0", @@ -4219,9 +4219,9 @@ "dev": true }, "node_modules/vite": { - "version": "5.4.6", - "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.6.tgz", - "integrity": "sha512-IeL5f8OO5nylsgzd9tq4qD2QqI0k2CQLGrWD0rCN0EQJZpBK5vJAx0I+GDkMOXxQX/OfFHMuLIx6ddAxGX/k+Q==", + "version": "5.4.7", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.7.tgz", + "integrity": "sha512-5l2zxqMEPVENgvzTuBpHer2awaetimj2BGkhBPdnwKbPNOlHsODU+oiazEZzLK7KhAnOrO+XGYJYn4ZlUhDtDQ==", "dev": true, "dependencies": { "esbuild": "^0.21.3", diff --git a/frontend/package.json b/frontend/package.json index 3dff24bd..444d36a7 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -15,17 +15,17 @@ "test:unit": "vitest" }, "devDependencies": { - "@playwright/test": "1.47.1", + "@playwright/test": "1.47.2", "@skeletonlabs/skeleton": "2.10.2", "@skeletonlabs/tw-plugin": "0.4.0", - "@sveltejs/adapter-static": "^3.0.4", - "@sveltejs/kit": "2.5.27", + "@sveltejs/adapter-static": "^3.0.5", + "@sveltejs/kit": "2.5.28", "@sveltejs/vite-plugin-svelte": "^3.1.2", "@tailwindcss/forms": "0.5.9", "@tailwindcss/typography": "0.5.15", "@types/node": "22.5.5", "autoprefixer": "10.4.20", - "eslint": "^9.10.0", + "eslint": "^9.11.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-svelte": "2.44.0", "flatbuffers": "24.3.25", @@ -34,10 +34,10 @@ "prettier-plugin-svelte": "3.2.6", "svelte": "4.2.19", "svelte-check": "4.0.2", - "tailwindcss": "3.4.11", + "tailwindcss": "3.4.12", "tslib": "2.7.0", "typescript": "5.6.2", - "vite": "^5.4.6", + "vite": "^5.4.7", "vite-plugin-tailwind-purgecss": "^0.3.3", "vitest": "2.1.1" }, From bcfaec7028439a506cf52ecbcc589c3677e07cb6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:34:16 +0200 Subject: [PATCH 37/41] build(deps-dev): Bump rollup in /frontend in the npm_and_yarn group (#289) Bumps the npm_and_yarn group in /frontend with 1 update: [rollup](https://github.com/rollup/rollup). Updates `rollup` from 4.21.0 to 4.22.4 - [Release notes](https://github.com/rollup/rollup/releases) - [Changelog](https://github.com/rollup/rollup/blob/master/CHANGELOG.md) - [Commits](https://github.com/rollup/rollup/compare/v4.21.0...v4.22.4) --- updated-dependencies: - dependency-name: rollup dependency-type: indirect dependency-group: npm_and_yarn ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- frontend/package-lock.json | 134 ++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index b694e20e..d041377f 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -767,9 +767,9 @@ "dev": true }, "node_modules/@rollup/rollup-android-arm-eabi": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.21.0.tgz", - "integrity": "sha512-WTWD8PfoSAJ+qL87lE7votj3syLavxunWhzCnx3XFxFiI/BA/r3X7MUM8dVrH8rb2r4AiO8jJsr3ZjdaftmnfA==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.22.4.tgz", + "integrity": "sha512-Fxamp4aEZnfPOcGA8KSNEohV8hX7zVHOemC8jVBoBUHu5zpJK/Eu3uJwt6BMgy9fkvzxDaurgj96F/NiLukF2w==", "cpu": [ "arm" ], @@ -780,9 +780,9 @@ ] }, "node_modules/@rollup/rollup-android-arm64": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.21.0.tgz", - "integrity": "sha512-a1sR2zSK1B4eYkiZu17ZUZhmUQcKjk2/j9Me2IDjk1GHW7LB5Z35LEzj9iJch6gtUfsnvZs1ZNyDW2oZSThrkA==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.22.4.tgz", + "integrity": "sha512-VXoK5UMrgECLYaMuGuVTOx5kcuap1Jm8g/M83RnCHBKOqvPPmROFJGQaZhGccnsFtfXQ3XYa4/jMCJvZnbJBdA==", "cpu": [ "arm64" ], @@ -793,9 +793,9 @@ ] }, "node_modules/@rollup/rollup-darwin-arm64": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.21.0.tgz", - "integrity": "sha512-zOnKWLgDld/svhKO5PD9ozmL6roy5OQ5T4ThvdYZLpiOhEGY+dp2NwUmxK0Ld91LrbjrvtNAE0ERBwjqhZTRAA==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.22.4.tgz", + "integrity": "sha512-xMM9ORBqu81jyMKCDP+SZDhnX2QEVQzTcC6G18KlTQEzWK8r/oNZtKuZaCcHhnsa6fEeOBionoyl5JsAbE/36Q==", "cpu": [ "arm64" ], @@ -806,9 +806,9 @@ ] }, "node_modules/@rollup/rollup-darwin-x64": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.21.0.tgz", - "integrity": "sha512-7doS8br0xAkg48SKE2QNtMSFPFUlRdw9+votl27MvT46vo44ATBmdZdGysOevNELmZlfd+NEa0UYOA8f01WSrg==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.22.4.tgz", + "integrity": "sha512-aJJyYKQwbHuhTUrjWjxEvGnNNBCnmpHDvrb8JFDbeSH3m2XdHcxDd3jthAzvmoI8w/kSjd2y0udT+4okADsZIw==", "cpu": [ "x64" ], @@ -819,9 +819,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.21.0.tgz", - "integrity": "sha512-pWJsfQjNWNGsoCq53KjMtwdJDmh/6NubwQcz52aEwLEuvx08bzcy6tOUuawAOncPnxz/3siRtd8hiQ32G1y8VA==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.22.4.tgz", + "integrity": "sha512-j63YtCIRAzbO+gC2L9dWXRh5BFetsv0j0va0Wi9epXDgU/XUi5dJKo4USTttVyK7fGw2nPWK0PbAvyliz50SCQ==", "cpu": [ "arm" ], @@ -832,9 +832,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-musleabihf": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.21.0.tgz", - "integrity": "sha512-efRIANsz3UHZrnZXuEvxS9LoCOWMGD1rweciD6uJQIx2myN3a8Im1FafZBzh7zk1RJ6oKcR16dU3UPldaKd83w==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.22.4.tgz", + "integrity": "sha512-dJnWUgwWBX1YBRsuKKMOlXCzh2Wu1mlHzv20TpqEsfdZLb3WoJW2kIEsGwLkroYf24IrPAvOT/ZQ2OYMV6vlrg==", "cpu": [ "arm" ], @@ -845,9 +845,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-gnu": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.21.0.tgz", - "integrity": "sha512-ZrPhydkTVhyeGTW94WJ8pnl1uroqVHM3j3hjdquwAcWnmivjAwOYjTEAuEDeJvGX7xv3Z9GAvrBkEzCgHq9U1w==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.22.4.tgz", + "integrity": "sha512-AdPRoNi3NKVLolCN/Sp4F4N1d98c4SBnHMKoLuiG6RXgoZ4sllseuGioszumnPGmPM2O7qaAX/IJdeDU8f26Aw==", "cpu": [ "arm64" ], @@ -858,9 +858,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-musl": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.21.0.tgz", - "integrity": "sha512-cfaupqd+UEFeURmqNP2eEvXqgbSox/LHOyN9/d2pSdV8xTrjdg3NgOFJCtc1vQ/jEke1qD0IejbBfxleBPHnPw==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.22.4.tgz", + "integrity": "sha512-Gl0AxBtDg8uoAn5CCqQDMqAx22Wx22pjDOjBdmG0VIWX3qUBHzYmOKh8KXHL4UpogfJ14G4wk16EQogF+v8hmA==", "cpu": [ "arm64" ], @@ -871,9 +871,9 @@ ] }, "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.21.0.tgz", - "integrity": "sha512-ZKPan1/RvAhrUylwBXC9t7B2hXdpb/ufeu22pG2psV7RN8roOfGurEghw1ySmX/CmDDHNTDDjY3lo9hRlgtaHg==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.22.4.tgz", + "integrity": "sha512-3aVCK9xfWW1oGQpTsYJJPF6bfpWfhbRnhdlyhak2ZiyFLDaayz0EP5j9V1RVLAAxlmWKTDfS9wyRyY3hvhPoOg==", "cpu": [ "ppc64" ], @@ -884,9 +884,9 @@ ] }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.21.0.tgz", - "integrity": "sha512-H1eRaCwd5E8eS8leiS+o/NqMdljkcb1d6r2h4fKSsCXQilLKArq6WS7XBLDu80Yz+nMqHVFDquwcVrQmGr28rg==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.22.4.tgz", + "integrity": "sha512-ePYIir6VYnhgv2C5Xe9u+ico4t8sZWXschR6fMgoPUK31yQu7hTEJb7bCqivHECwIClJfKgE7zYsh1qTP3WHUA==", "cpu": [ "riscv64" ], @@ -897,9 +897,9 @@ ] }, "node_modules/@rollup/rollup-linux-s390x-gnu": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.21.0.tgz", - "integrity": "sha512-zJ4hA+3b5tu8u7L58CCSI0A9N1vkfwPhWd/puGXwtZlsB5bTkwDNW/+JCU84+3QYmKpLi+XvHdmrlwUwDA6kqw==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.22.4.tgz", + "integrity": "sha512-GqFJ9wLlbB9daxhVlrTe61vJtEY99/xB3C8e4ULVsVfflcpmR6c8UZXjtkMA6FhNONhj2eA5Tk9uAVw5orEs4Q==", "cpu": [ "s390x" ], @@ -910,9 +910,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-gnu": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.21.0.tgz", - "integrity": "sha512-e2hrvElFIh6kW/UNBQK/kzqMNY5mO+67YtEh9OA65RM5IJXYTWiXjX6fjIiPaqOkBthYF1EqgiZ6OXKcQsM0hg==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.22.4.tgz", + "integrity": "sha512-87v0ol2sH9GE3cLQLNEy0K/R0pz1nvg76o8M5nhMR0+Q+BBGLnb35P0fVz4CQxHYXaAOhE8HhlkaZfsdUOlHwg==", "cpu": [ "x64" ], @@ -923,9 +923,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-musl": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.21.0.tgz", - "integrity": "sha512-1vvmgDdUSebVGXWX2lIcgRebqfQSff0hMEkLJyakQ9JQUbLDkEaMsPTLOmyccyC6IJ/l3FZuJbmrBw/u0A0uCQ==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.22.4.tgz", + "integrity": "sha512-UV6FZMUgePDZrFjrNGIWzDo/vABebuXBhJEqrHxrGiU6HikPy0Z3LfdtciIttEUQfuDdCn8fqh7wiFJjCNwO+g==", "cpu": [ "x64" ], @@ -936,9 +936,9 @@ ] }, "node_modules/@rollup/rollup-win32-arm64-msvc": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.21.0.tgz", - "integrity": "sha512-s5oFkZ/hFcrlAyBTONFY1TWndfyre1wOMwU+6KCpm/iatybvrRgmZVM+vCFwxmC5ZhdlgfE0N4XorsDpi7/4XQ==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.22.4.tgz", + "integrity": "sha512-BjI+NVVEGAXjGWYHz/vv0pBqfGoUH0IGZ0cICTn7kB9PyjrATSkX+8WkguNjWoj2qSr1im/+tTGRaY+4/PdcQw==", "cpu": [ "arm64" ], @@ -949,9 +949,9 @@ ] }, "node_modules/@rollup/rollup-win32-ia32-msvc": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.21.0.tgz", - "integrity": "sha512-G9+TEqRnAA6nbpqyUqgTiopmnfgnMkR3kMukFBDsiyy23LZvUCpiUwjTRx6ezYCjJODXrh52rBR9oXvm+Fp5wg==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.22.4.tgz", + "integrity": "sha512-SiWG/1TuUdPvYmzmYnmd3IEifzR61Tragkbx9D3+R8mzQqDBz8v+BvZNDlkiTtI9T15KYZhP0ehn3Dld4n9J5g==", "cpu": [ "ia32" ], @@ -962,9 +962,9 @@ ] }, "node_modules/@rollup/rollup-win32-x64-msvc": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.21.0.tgz", - "integrity": "sha512-2jsCDZwtQvRhejHLfZ1JY6w6kEuEtfF9nzYsZxzSlNVKDX+DpsDJ+Rbjkm74nvg2rdx0gwBS+IMdvwJuq3S9pQ==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.22.4.tgz", + "integrity": "sha512-j8pPKp53/lq9lMXN57S8cFz0MynJk8OWNuUnXct/9KCpKU7DgU3bYMJhwWmcqC0UU29p8Lr0/7KEVcaM6bf47Q==", "cpu": [ "x64" ], @@ -3486,9 +3486,9 @@ } }, "node_modules/rollup": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.21.0.tgz", - "integrity": "sha512-vo+S/lfA2lMS7rZ2Qoubi6I5hwZwzXeUIctILZLbHI+laNtvhhOIon2S1JksA5UEDQ7l3vberd0fxK44lTYjbQ==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.22.4.tgz", + "integrity": "sha512-vD8HJ5raRcWOyymsR6Z3o6+RzfEPCnVLMFJ6vRslO1jt4LO6dUo5Qnpg7y4RkZFM2DMe3WUirkI5c16onjrc6A==", "dev": true, "dependencies": { "@types/estree": "1.0.5" @@ -3501,22 +3501,22 @@ "npm": ">=8.0.0" }, "optionalDependencies": { - "@rollup/rollup-android-arm-eabi": "4.21.0", - "@rollup/rollup-android-arm64": "4.21.0", - "@rollup/rollup-darwin-arm64": "4.21.0", - "@rollup/rollup-darwin-x64": "4.21.0", - "@rollup/rollup-linux-arm-gnueabihf": "4.21.0", - "@rollup/rollup-linux-arm-musleabihf": "4.21.0", - "@rollup/rollup-linux-arm64-gnu": "4.21.0", - "@rollup/rollup-linux-arm64-musl": "4.21.0", - "@rollup/rollup-linux-powerpc64le-gnu": "4.21.0", - "@rollup/rollup-linux-riscv64-gnu": "4.21.0", - "@rollup/rollup-linux-s390x-gnu": "4.21.0", - "@rollup/rollup-linux-x64-gnu": "4.21.0", - "@rollup/rollup-linux-x64-musl": "4.21.0", - "@rollup/rollup-win32-arm64-msvc": "4.21.0", - "@rollup/rollup-win32-ia32-msvc": "4.21.0", - "@rollup/rollup-win32-x64-msvc": "4.21.0", + "@rollup/rollup-android-arm-eabi": "4.22.4", + "@rollup/rollup-android-arm64": "4.22.4", + "@rollup/rollup-darwin-arm64": "4.22.4", + "@rollup/rollup-darwin-x64": "4.22.4", + "@rollup/rollup-linux-arm-gnueabihf": "4.22.4", + "@rollup/rollup-linux-arm-musleabihf": "4.22.4", + "@rollup/rollup-linux-arm64-gnu": "4.22.4", + "@rollup/rollup-linux-arm64-musl": "4.22.4", + "@rollup/rollup-linux-powerpc64le-gnu": "4.22.4", + "@rollup/rollup-linux-riscv64-gnu": "4.22.4", + "@rollup/rollup-linux-s390x-gnu": "4.22.4", + "@rollup/rollup-linux-x64-gnu": "4.22.4", + "@rollup/rollup-linux-x64-musl": "4.22.4", + "@rollup/rollup-win32-arm64-msvc": "4.22.4", + "@rollup/rollup-win32-ia32-msvc": "4.22.4", + "@rollup/rollup-win32-x64-msvc": "4.22.4", "fsevents": "~2.3.2" } }, From 325ac874effaa681ae71f1045288ad1f99a19eb9 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 27 Sep 2024 20:28:02 +0200 Subject: [PATCH 38/41] Bump platform-espressif32 to 6.9 --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 12c2d5f1..efdb324b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [env] -platform = espressif32 @ 6.8.1 +platform = espressif32 @ 6.9.0 board = az-delivery-devkit-v4 ; Overridden per board framework = arduino build_flags = From 20f8e604fcaa6e090c3801ab96f44a64accbde48 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 27 Sep 2024 20:31:12 +0200 Subject: [PATCH 39/41] Get rid of redifinition warnings --- include/CaptivePortal.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/CaptivePortal.h b/include/CaptivePortal.h index 80d412ba..c31a2f02 100644 --- a/include/CaptivePortal.h +++ b/include/CaptivePortal.h @@ -1,7 +1,5 @@ #pragma once -#include - #include #include From fc34709f958de475db52600579bf74d3185eb885 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 27 Sep 2024 21:58:34 +0200 Subject: [PATCH 40/41] Improve local build version deduction --- .env | 1 - .env.development | 1 - scripts/embed_env_vars.py | 57 ++++++++++++++++++++++++++++++++----- scripts/utils/shorthands.py | 4 +++ 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/.env b/.env index dcd59971..b9c8220a 100644 --- a/.env +++ b/.env @@ -1,6 +1,5 @@ OPENSHOCK_API_DOMAIN=api.openshock.app OPENSHOCK_FW_CDN_DOMAIN=firmware.openshock.org -OPENSHOCK_FW_VERSION=0.0.0-unknown OPENSHOCK_FW_HOSTNAME=OpenShock OPENSHOCK_FW_AP_PREFIX=OpenShock- OPENSHOCK_URI_BUFFER_SIZE=256 diff --git a/.env.development b/.env.development index 1cd46e41..2048dfea 100644 --- a/.env.development +++ b/.env.development @@ -1,4 +1,3 @@ # Included by frontend/ (DO NOT RENAME THIS FILE!) # Intended for development builds (locally). LOG_LEVEL=VERBOSE -OPENSHOCK_FW_VERSION=0.0.0-local diff --git a/scripts/embed_env_vars.py b/scripts/embed_env_vars.py index 6ca70337..4ad67351 100644 --- a/scripts/embed_env_vars.py +++ b/scripts/embed_env_vars.py @@ -35,16 +35,45 @@ # Read the correct .env file. dot = dotenv.DotEnv(project_dir, dotenv_type) - -# Get the current git commit hash. -def get_git_commit() -> str | None: +def get_git_repo(): try: - # Get the current git repository. - repo = git.Repo(search_parent_directories=True) - return repo.head.object.hexsha + return git.Repo(search_parent_directories=True) except git.exc.InvalidGitRepositoryError: return None +import re + +def sort_semver(versions): + def parse_semver(v): + # Split version into main, prerelease, and build metadata parts + match = re.match(r'^v?(\d+\.\d+\.\d+)(?:-([0-9A-Za-z-.]+))?(?:\+([0-9A-Za-z-.]+))?$', v) + if not match: + raise ValueError(f"Invalid version: {v}") + main_version, prerelease, build = match.groups() + + return (main_version, prerelease, build) + + def has_suffix(version): + return + + def version_key(version): + main_version, _, _ = parse_semver(version) + + # Convert the main version into a tuple of integers for natural sorting + main_version_tuple = tuple(map(int, main_version.split('.'))) + + return main_version_tuple + + # Remove versions with prerelease/build suffixes + clean_only = [v for v in versions if not ('-' in v or '+' in v)] + + # Sort by version key + return sorted(clean_only, key=lambda v: version_key(v)) + +git_repo = get_git_repo() +git_commit = git_repo.head.object.hexsha if git_repo is not None else None +git_tags = [tag.name for tag in git_repo.tags] if git_repo is not None else [] +latest_git_tag = sort_semver(git_tags)[-1] if len(git_tags) > 0 else None # Find env variables based on only the pioenv and sysenv. def get_pio_firmware_vars() -> dict[str, str | int | bool]: @@ -60,7 +89,6 @@ def macroify(s: str) -> str: vars['OPENSHOCK_FW_CHIP'] = fw_chip.upper() vars['OPENSHOCK_FW_CHIP_' + macroify(fw_chip)] = True # Used for conditional compilation. vars['OPENSHOCK_FW_MODE'] = pio_build_type - git_commit = get_git_commit() if git_commit is not None: vars['OPENSHOCK_FW_GIT_COMMIT'] = git_commit return vars @@ -157,6 +185,21 @@ def print_dump(name: str, map: Mapping[str, str | int | bool]) -> None: merge_missing_keys(cpp_defines, pio_openshock_vars) merge_missing_keys(cpp_defines, dot_openshock_vars) +# Check if OPENSHOCK_FW_VERSION is set. +if 'OPENSHOCK_FW_VERSION' not in cpp_defines: + if is_ci: + raise ValueError('OPENSHOCK_FW_VERSION must be set in environment variables for CI builds.') + + # If latest_git_tag is set, use it, else use 0.0.0, assign to variable. + version = (latest_git_tag if latest_git_tag is not None else '0.0.0') + '-local' + + # If git_commit is set, append it to the version. + if git_commit is not None: + version += '+' + git_commit[0:7] + + # If not set, get the latest tag. + cpp_defines['OPENSHOCK_FW_VERSION'] = version + # Gets the log level from environment variables. # TODO: Delete get_loglevel and use... something more generic. log_level_int = dot.get_loglevel('LOG_LEVEL') diff --git a/scripts/utils/shorthands.py b/scripts/utils/shorthands.py index 2df2c576..841b8b8a 100644 --- a/scripts/utils/shorthands.py +++ b/scripts/utils/shorthands.py @@ -38,3 +38,7 @@ def is_github_pr_into(branch: str) -> bool: # Checks if the run was triggered by a tag. def is_github_tag() -> bool: return sysenv.get_string('GITHUB_REF_TYPE', 'branch') == 'tag' + +def get_latest_tag(): + # Use git to get the latest tag. + return os.popen('git describe --tags --abbrev=0').read().strip() \ No newline at end of file From 8662723b141e51e16eaa1ca7e1279a0cbcf75204 Mon Sep 17 00:00:00 2001 From: hhvrc Date: Fri, 27 Sep 2024 22:11:34 +0200 Subject: [PATCH 41/41] Feed version info to staticfs build --- .github/actions/build-staticfs/action.yml | 8 ++++++++ .github/workflows/ci-build.yml | 1 + 2 files changed, 9 insertions(+) diff --git a/.github/actions/build-staticfs/action.yml b/.github/actions/build-staticfs/action.yml index 3a6231e9..6b6febca 100644 --- a/.github/actions/build-staticfs/action.yml +++ b/.github/actions/build-staticfs/action.yml @@ -1,6 +1,9 @@ name: build-staticfs description: Builds the static filesystem partition and uploads it as an artifact inputs: + version: + required: true + description: 'Current firmware version' skip-checkout: description: 'If true, skips checkout' required: false @@ -37,6 +40,11 @@ runs: - name: Build filesystem partition shell: bash run: pio run --target buildfs -e fs + env: + OPENSHOCK_FW_VERSION: ${{ inputs.version }} + OPENSHOCK_FW_GIT_REF: ${{ github.ref }} + OPENSHOCK_FW_GIT_COMMIT: ${{ github.sha }} + OPENSHOCK_FW_BUILD_DATE: ${{ github.event.head_commit.timestamp }} - name: Rename partition binary shell: bash diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index c3c943d7..06e5d12f 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -47,6 +47,7 @@ jobs: - uses: actions/checkout@v4 - uses: ./.github/actions/build-staticfs with: + version: ${{ needs.getvars.outputs.version }} skip-checkout: true build-firmware: