diff --git a/Firmware/fibre/cpp/include/fibre/cpp_utils.hpp b/Firmware/fibre/cpp/include/fibre/cpp_utils.hpp index af28a07f..6a81858d 100644 --- a/Firmware/fibre/cpp/include/fibre/cpp_utils.hpp +++ b/Firmware/fibre/cpp/include/fibre/cpp_utils.hpp @@ -882,71 +882,6 @@ TRet* dynamic_get(size_t i, const std::tuple& t) { return dynamic_get_impl, TRet, Ts...>::get(i, t); } -/* Hex to numbers ------------------------------------------------------------*/ - -template -constexpr size_t hex_digits() { - return (std::numeric_limits::digits + 3) / 4; -} - -/* @brief Converts a hexadecimal digit to a uint8_t. -* @param output If not null, the digit's value is stored in this output -* Returns true if the char is a valid hex digit, false otherwise -*/ -static bool hex_digit_to_byte(char ch, uint8_t* output) { - uint8_t nil_output = 0; - if (!output) - output = &nil_output; - if (ch >= '0' && ch <= '9') - return (*output) = ch - '0', true; - if (ch >= 'a' && ch <= 'f') - return (*output) = ch - 'a' + 10, true; - if (ch >= 'A' && ch <= 'F') - return (*output) = ch - 'A' + 10, true; - return false; -} - -/* @brief Converts a hex string to an integer -* @param output If not null, the result is stored in this output -* Returns true if the string represents a valid hex value, false otherwise. -*/ -template -bool hex_string_to_int(const char * str, size_t length, TInt* output) { - constexpr size_t N_DIGITS = hex_digits(); - TInt result = 0; - if (length > N_DIGITS) - length = N_DIGITS; - for (size_t i = 0; i < length && str[i]; i++) { - uint8_t digit = 0; - if (!hex_digit_to_byte(str[i], &digit)) - return false; - result <<= 4; - result += digit; - } - if (output) - *output = result; - return true; -} - -template -bool hex_string_to_int(const char * str, TInt* output) { - return hex_string_to_int(str, hex_digits(), output); -} - -template -bool hex_string_to_int_arr(const char * str, size_t length, TInt (&output)[ICount]) { - for (size_t i = 0; i < ICount; i++) { - if (!hex_string_to_int(&str[i * hex_digits()], &output[i])) - return false; - } - return true; -} - -template -bool hex_string_to_int_arr(const char * str, TInt (&output)[ICount]) { - return hex_string_to_int_arr(str, hex_digits() * ICount, output); -} - template class simple_iterator : std::iterator { diff --git a/Firmware/fibre/cpp/include/fibre/protocol.hpp b/Firmware/fibre/cpp/include/fibre/protocol.hpp index a03a596e..09bac8c4 100644 --- a/Firmware/fibre/cpp/include/fibre/protocol.hpp +++ b/Firmware/fibre/cpp/include/fibre/protocol.hpp @@ -386,7 +386,8 @@ template<> struct Codec { return int_val.has_value() ? std::optional(*reinterpret_cast(&int_val.value())) : std::nullopt; } static bool encode(float value, bufptr_t* buffer) { - return Codec::encode(*reinterpret_cast(&value), buffer); + void* ptr = &value; + return Codec::encode(*reinterpret_cast(ptr), buffer); } }; template