mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-08-21 15:47:40 +08:00
resolve compile issues
This commit is contained in:
@@ -882,71 +882,6 @@ TRet* dynamic_get(size_t i, const std::tuple<Ts...>& t) {
|
||||
return dynamic_get_impl<std::integral_constant<size_t, 0>, TRet, Ts...>::get(i, t);
|
||||
}
|
||||
|
||||
/* Hex to numbers ------------------------------------------------------------*/
|
||||
|
||||
template<typename T>
|
||||
constexpr size_t hex_digits() {
|
||||
return (std::numeric_limits<T>::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<typename TInt>
|
||||
bool hex_string_to_int(const char * str, size_t length, TInt* output) {
|
||||
constexpr size_t N_DIGITS = hex_digits<TInt>();
|
||||
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<typename TInt>
|
||||
bool hex_string_to_int(const char * str, TInt* output) {
|
||||
return hex_string_to_int<TInt>(str, hex_digits<TInt>(), output);
|
||||
}
|
||||
|
||||
template<typename TInt, size_t ICount>
|
||||
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<TInt>(&str[i * hex_digits<TInt>()], &output[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename TInt, size_t ICount>
|
||||
bool hex_string_to_int_arr(const char * str, TInt (&output)[ICount]) {
|
||||
return hex_string_to_int_arr(str, hex_digits<TInt>() * ICount, output);
|
||||
}
|
||||
|
||||
|
||||
template<typename TDereferenceable, typename TResult>
|
||||
class simple_iterator : std::iterator<std::random_access_iterator_tag, TResult> {
|
||||
|
||||
@@ -386,7 +386,8 @@ template<> struct Codec<float> {
|
||||
return int_val.has_value() ? std::optional<float>(*reinterpret_cast<float*>(&int_val.value())) : std::nullopt;
|
||||
}
|
||||
static bool encode(float value, bufptr_t* buffer) {
|
||||
return Codec<uint32_t>::encode(*reinterpret_cast<uint32_t*>(&value), buffer);
|
||||
void* ptr = &value;
|
||||
return Codec<uint32_t>::encode(*reinterpret_cast<uint32_t*>(ptr), buffer);
|
||||
}
|
||||
};
|
||||
template<typename T>
|
||||
|
||||
Reference in New Issue
Block a user