diff --git a/libraries/AP_Common/AP_Common.cpp b/libraries/AP_Common/AP_Common.cpp index 4c7c3af0ce..8acdc2a76a 100644 --- a/libraries/AP_Common/AP_Common.cpp +++ b/libraries/AP_Common/AP_Common.cpp @@ -93,9 +93,9 @@ size_t strncpy_noterm(char *dest, const char *src, size_t n) * return the numeric value of an ascii hex character * * @param[in] a Hexadecimal character - * @return Returns a binary value + * @return Returns a binary value. If 'a' is not a valid hex character 255 (AKA -1) is returned */ -int16_t char_to_hex(char a) +uint8_t char_to_hex(char a) { if (a >= 'A' && a <= 'F') { return a - 'A' + 10; @@ -104,5 +104,5 @@ int16_t char_to_hex(char a) } else if (a >= '0' && a <= '9') { return a - '0'; } - return 0; + return 255; } diff --git a/libraries/AP_Common/AP_Common.h b/libraries/AP_Common/AP_Common.h index d51e888e53..177a24c0fc 100644 --- a/libraries/AP_Common/AP_Common.h +++ b/libraries/AP_Common/AP_Common.h @@ -169,7 +169,7 @@ bool hex_to_uint8(uint8_t a, uint8_t &res); // return the uint8 value of an asc size_t strncpy_noterm(char *dest, const char *src, size_t n); // return the numeric value of an ascii hex character -int16_t char_to_hex(char a); +uint8_t char_to_hex(char a); /* Bit manipulation