AP_RangeFinder: Use common hexadecimal to character number conversion method
This commit is contained in:
parent
e4455491aa
commit
0b1987ae36
@ -134,7 +134,12 @@ bool AP_RangeFinder_NMEA::decode_latest_term()
|
||||
{
|
||||
// handle the last term in a message
|
||||
if (_term_is_checksum) {
|
||||
uint8_t checksum = 16 * char_to_hex(_term[0]) + char_to_hex(_term[1]);
|
||||
uint8_t nibble_high = 0;
|
||||
uint8_t nibble_low = 0;
|
||||
if (!hex_to_uint8(_term[0], nibble_high) || !hex_to_uint8(_term[1], nibble_low)) {
|
||||
return false;
|
||||
}
|
||||
const uint8_t checksum = (nibble_high << 4u) | nibble_low;
|
||||
return ((checksum == _checksum) &&
|
||||
!is_negative(_distance_m) &&
|
||||
(_sentence_type == SONAR_DBT || _sentence_type == SONAR_DPT));
|
||||
@ -174,14 +179,3 @@ bool AP_RangeFinder_NMEA::decode_latest_term()
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// return the numeric value of an ascii hex character
|
||||
int16_t AP_RangeFinder_NMEA::char_to_hex(char a)
|
||||
{
|
||||
if (a >= 'A' && a <= 'F')
|
||||
return a - 'A' + 10;
|
||||
else if (a >= 'a' && a <= 'f')
|
||||
return a - 'a' + 10;
|
||||
else
|
||||
return a - '0';
|
||||
}
|
||||
|
@ -60,9 +60,6 @@ private:
|
||||
// returns true if new sentence has just passed checksum test and is validated
|
||||
bool decode_latest_term();
|
||||
|
||||
// return the numeric value of an ascii hex character
|
||||
static int16_t char_to_hex(char a);
|
||||
|
||||
AP_HAL::UARTDriver *uart = nullptr; // pointer to serial uart
|
||||
|
||||
// message decoding related members
|
||||
|
Loading…
Reference in New Issue
Block a user