|
|
|
@ -20,6 +20,14 @@
@@ -20,6 +20,14 @@
|
|
|
|
|
#include <AP_HAL/AP_HAL.h> |
|
|
|
|
#include <ctype.h> |
|
|
|
|
|
|
|
|
|
#define BOAT_DEBUG 0 |
|
|
|
|
#if BOAT_DEBUG |
|
|
|
|
#include <GCS_MAVLink/GCS.h> |
|
|
|
|
# define Debug(fmt, args ...) gcs().send_text(MAV_SEVERITY_INFO, "Sonar: " fmt "\n", ## args) |
|
|
|
|
#else |
|
|
|
|
# define Debug(fmt, args ...) |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
extern const AP_HAL::HAL& hal; |
|
|
|
|
|
|
|
|
|
// return last value measured by sensor
|
|
|
|
@ -90,6 +98,7 @@ bool AP_RangeFinder_NMEA::decode(char c)
@@ -90,6 +98,7 @@ bool AP_RangeFinder_NMEA::decode(char c)
|
|
|
|
|
return valid_sentence; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case '@': // sentence begin
|
|
|
|
|
case '$': // sentence begin
|
|
|
|
|
_sentence_type = SONAR_UNKNOWN; |
|
|
|
|
_term_number = 0; |
|
|
|
@ -119,6 +128,9 @@ bool AP_RangeFinder_NMEA::decode_latest_term()
@@ -119,6 +128,9 @@ bool AP_RangeFinder_NMEA::decode_latest_term()
|
|
|
|
|
// handle the last term in a message
|
|
|
|
|
if (_term_is_checksum) { |
|
|
|
|
_sentence_done = true; |
|
|
|
|
if(_sentence_type == SONAR_EDEP){ // EDEP没有CRC
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
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)) { |
|
|
|
@ -151,6 +163,7 @@ bool AP_RangeFinder_NMEA::decode_latest_term()
@@ -151,6 +163,7 @@ bool AP_RangeFinder_NMEA::decode_latest_term()
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
const char *term_type = &_term[2]; |
|
|
|
|
const char *term_sic = &_term[0]; |
|
|
|
|
if (strcmp(term_type, "DBT") == 0) { |
|
|
|
|
_sentence_type = SONAR_DBT; |
|
|
|
|
} else if (strcmp(term_type, "DPT") == 0) { |
|
|
|
@ -159,6 +172,10 @@ bool AP_RangeFinder_NMEA::decode_latest_term()
@@ -159,6 +172,10 @@ bool AP_RangeFinder_NMEA::decode_latest_term()
|
|
|
|
|
_sentence_type = SONAR_MTW; |
|
|
|
|
} else if (strcmp(term_type, "ED") == 0) { |
|
|
|
|
_sentence_type = SONAR_HDED; |
|
|
|
|
}else if (strcmp(term_sic, "SIC") == 0) { |
|
|
|
|
_sentence_type = SONAR_SIC; |
|
|
|
|
}else if (strcmp(term_sic, "EDEP") == 0) { |
|
|
|
|
_sentence_type = SONAR_EDEP; |
|
|
|
|
} else { |
|
|
|
|
_sentence_type = SONAR_UNKNOWN; |
|
|
|
|
} |
|
|
|
@ -185,6 +202,30 @@ bool AP_RangeFinder_NMEA::decode_latest_term()
@@ -185,6 +202,30 @@ bool AP_RangeFinder_NMEA::decode_latest_term()
|
|
|
|
|
if (_term_number == 4) { |
|
|
|
|
_distance_m = strtof(_term, NULL); |
|
|
|
|
} |
|
|
|
|
}else if ((_sentence_type == SONAR_SIC )) { |
|
|
|
|
|
|
|
|
|
if (_term_number == 5) { |
|
|
|
|
_distance_m = atof(_term); |
|
|
|
|
Debug("dist:%.2f",_distance_m); |
|
|
|
|
} |
|
|
|
|
}else if (_sentence_type == SONAR_EDEP) { |
|
|
|
|
// parse DBT messages
|
|
|
|
|
switch (_sentence_type + _term_number) { |
|
|
|
|
case SONAR_EDEP + 1: |
|
|
|
|
_distance_m = atof(_term); |
|
|
|
|
// Debug("distance:%.2f",_distance_m);
|
|
|
|
|
Debug("%.2f,%.2f,%d",_distance_m,delt_dist,sound_speed); |
|
|
|
|
break; |
|
|
|
|
case SONAR_EDEP + 2: |
|
|
|
|
delt_dist = atof(_term); |
|
|
|
|
Debug("delt distance:%.2f",delt_dist); |
|
|
|
|
break; |
|
|
|
|
case SONAR_EDEP + 3: |
|
|
|
|
sound_speed = atoi(_term); |
|
|
|
|
Debug("sound speed:%d",sound_speed); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|