1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-13 05:06:30 +04:00

Merge branch 'fz-dev' into dev

This commit is contained in:
MX
2022-08-30 11:42:39 +03:00
84 changed files with 1392 additions and 47 deletions

View File

@@ -15,7 +15,7 @@ bool hex_char_to_hex_nibble(char c, uint8_t* nibble) {
}
}
bool hex_chars_to_uint8(char hi, char low, uint8_t* value) {
bool hex_char_to_uint8(char hi, char low, uint8_t* value) {
uint8_t hi_nibble_value, low_nibble_value;
if(hex_char_to_hex_nibble(hi, &hi_nibble_value) &&
@@ -27,13 +27,29 @@ bool hex_chars_to_uint8(char hi, char low, uint8_t* value) {
}
}
bool hex_chars_to_uint8(const char* value_str, uint8_t* value) {
bool parse_success = false;
while(*value_str && value_str[1]) {
parse_success = hex_char_to_uint8(*value_str, value_str[1], value++);
if(!parse_success) break;
value_str += 2;
}
return parse_success;
}
bool hex_chars_to_uint64(const char* value_str, uint64_t* value) {
uint8_t* _value = (uint8_t*)value;
bool parse_success = false;
for(uint8_t i = 0; i < 8; i++) {
parse_success = hex_chars_to_uint8(value_str[i * 2], value_str[i * 2 + 1], &_value[7 - i]);
parse_success = hex_char_to_uint8(value_str[i * 2], value_str[i * 2 + 1], &_value[7 - i]);
if(!parse_success) break;
}
return parse_success;
}
void uint8_to_hex_chars(const uint8_t* src, uint8_t* target, int length) {
const char chars[] = "0123456789ABCDEF";
while(--length >= 0)
target[length] = chars[(src[length >> 1] >> ((1 - (length & 1)) << 2)) & 0xF];
}

View File

@@ -14,14 +14,22 @@ extern "C" {
*/
bool hex_char_to_hex_nibble(char c, uint8_t* nibble);
/** Convert ASCII hex values to byte
/** Convert ASCII hex value to byte
* @param hi hi nibble text
* @param low low nibble text
* @param value output value
*
* @return bool conversion status
*/
bool hex_chars_to_uint8(char hi, char low, uint8_t* value);
bool hex_char_to_uint8(char hi, char low, uint8_t* value);
/** Convert ASCII hex values to uint8_t
* @param value_str ASCII data
* @param value output value
*
* @return bool conversion status
*/
bool hex_chars_to_uint8(const char* value_str, uint8_t* value);
/** Convert ASCII hex values to uint64_t
* @param value_str ASCII 64 bi data
@@ -31,6 +39,14 @@ bool hex_chars_to_uint8(char hi, char low, uint8_t* value);
*/
bool hex_chars_to_uint64(const char* value_str, uint64_t* value);
/** Convert uint8_t to ASCII hex values
* @param src source data
* @param target output value
* @param length data length
*
*/
void uint8_to_hex_chars(const uint8_t* src, uint8_t* target, int length);
#ifdef __cplusplus
}
#endif