Skip to content

Commit b315a73

Browse files
AP_GPS: add UBX_DebugMessages driver option
GPS_DRV_OPTIONS bit 10 enables F9/HPG debug streams (NAV-SAT, NAV-SIG, NAV-CLOCK, MON-RF, MON-HW3, MON-COMMS, MON-SPAN) on UART1. The boot blob switches the receiver to 921600 to fit the extra bandwidth, and the UART RX buffer floors at 4096 to absorb a full nav epoch in one burst. Debug message ids are added to the parser as consume-cases so the unknown-message disable path does not race with the enable list. Also fixes UBLOX_SET_BINARY_921600 NMEA checksum (was 1F, correct 17) and verifies all MSGOUT key IDs against u-blox HPG 2.02.
1 parent fe6d6f6 commit b315a73

4 files changed

Lines changed: 129 additions & 7 deletions

File tree

libraries/AP_GPS/AP_GPS.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
extern const AP_HAL::HAL &hal;
7272

7373
// baudrates to try to detect GPSes with
74-
const uint32_t AP_GPS::_baudrates[] = {9600U, 115200U, 4800U, 19200U, 38400U, 57600U, 230400U, 460800U};
74+
const uint32_t AP_GPS::_baudrates[] = {9600U, 115200U, 4800U, 19200U, 38400U, 57600U, 230400U, 460800U, 921600U};
7575
#ifndef AP_GPS_UBLOX_DEFAULT_BAUDRATE
7676
#define AP_GPS_UBLOX_DEFAULT_BAUDRATE 230400
7777
#endif
@@ -242,7 +242,7 @@ const AP_Param::GroupInfo AP_GPS::var_info[] = {
242242
// @Param: _DRV_OPTIONS
243243
// @DisplayName: driver options
244244
// @Description: Additional backend specific options
245-
// @Bitmask: 0:Use UART2 for moving baseline on ublox,1:Use base station for GPS yaw on SBF,2:Use baudrate 115200,3:Use dedicated CAN port b/w GPSes for moving baseline,4:Use ellipsoid height instead of AMSL, 5:Override GPS satellite health of L5 band from L1 health, 6:Enable RTCM full parse even for a single channel, 7:Disable automatic full RTCM parsing when RTCM seen on more than one channel
245+
// @Bitmask: 0:Use UART2 for moving baseline on ublox,1:Use base station for GPS yaw on SBF,2:Use baudrate 115200,3:Use dedicated CAN port b/w GPSes for moving baseline,4:Use ellipsoid height instead of AMSL, 5:Override GPS satellite health of L5 band from L1 health, 6:Enable RTCM full parse even for a single channel, 7:Disable automatic full RTCM parsing when RTCM seen on more than one channel, 8:HSI trim using PPS (ublox), 9:HSI trim stats, 10:Enable u-blox debug messages on UART1
246246
// @User: Advanced
247247
AP_GROUPINFO("_DRV_OPTIONS", 22, AP_GPS, _driver_options, 0),
248248

@@ -540,6 +540,12 @@ void AP_GPS::send_blob_start(uint8_t instance)
540540
const auto type = params[instance].type;
541541

542542
#if AP_GPS_UBLOX_ENABLED
543+
if (type == GPS_TYPE_UBLOX && option_set(DriverOptions::UBX_DebugMessages)) {
544+
// bump UART1 to 921600 so the extra debug streams fit within nav-rate
545+
static const char blob[] = UBLOX_SET_BINARY_921600;
546+
send_blob_start(instance, blob, sizeof(blob));
547+
return;
548+
}
543549
if (type == GPS_TYPE_UBLOX && option_set(DriverOptions::UBX_Use115200)) {
544550
static const char blob[] = UBLOX_SET_BINARY_115200;
545551
send_blob_start(instance, blob, sizeof(blob));
@@ -718,6 +724,16 @@ AP_GPS_Backend *AP_GPS::_detect_instance(uint8_t instance)
718724
if (type == GPS_TYPE_UBLOX_RTK_BASE) {
719725
rx_size = 2048;
720726
}
727+
#if AP_GPS_UBLOX_ENABLED
728+
if ((type == GPS_TYPE_AUTO || type == GPS_TYPE_UBLOX ||
729+
type == GPS_TYPE_UBLOX_RTK_BASE || type == GPS_TYPE_UBLOX_RTK_ROVER) &&
730+
option_set(DriverOptions::UBX_DebugMessages)) {
731+
// F9 debug streams (NAV-SAT/SIG/CLOCK + MON-RF/HW3/COMMS/SPAN)
732+
// push several KB per nav epoch in a single burst at 921600 -
733+
// give the RX path enough headroom to absorb a full epoch
734+
rx_size = MAX(rx_size, (uint16_t)4096);
735+
}
736+
#endif
721737
_port[instance]->begin(dstate->probe_baud, rx_size, tx_size);
722738
_port[instance]->set_flow_control(AP_HAL::UARTDriver::FLOW_CONTROL_DISABLE);
723739
dstate->last_baud_change_ms = now;
@@ -768,7 +784,10 @@ AP_GPS_Backend *AP_GPS::_detect_instance(uint8_t instance)
768784
type == GPS_TYPE_UBLOX) &&
769785
((!_auto_config && _baudrates[dstate->current_baud] >= 38400) ||
770786
(_baudrates[dstate->current_baud] >= 115200 && option_set(DriverOptions::UBX_Use115200)) ||
771-
_baudrates[dstate->current_baud] == AP_GPS_UBLOX_DEFAULT_BAUDRATE) &&
787+
_baudrates[dstate->current_baud] == AP_GPS_UBLOX_DEFAULT_BAUDRATE ||
788+
// also accept 921600 so we can re-detect a u-blox that was
789+
// previously configured to 921600 by the debug-msgs option
790+
_baudrates[dstate->current_baud] == 921600U) &&
772791
AP_GPS_UBLOX::_detect(dstate->ublox_detect_state, data)) {
773792
return new AP_GPS_UBLOX(*this, params[instance], state[instance], _port[instance], GPS_ROLE_NORMAL);
774793
}

libraries/AP_GPS/AP_GPS.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ class AP_GPS
648648
DisableRTCMDecode = (1U << 7),
649649
HSITrimUsingPPS = (1U << 8),
650650
HSITrimStats = (1U << 9),
651+
UBX_DebugMessages = (1U << 10),
651652
};
652653

653654
// check if an option is set

libraries/AP_GPS/AP_GPS_UBLOX.cpp

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,34 @@ const AP_GPS_UBLOX::config_list AP_GPS_UBLOX::config_L5_ovrd_dis[] {
276276
{ConfigKey::CFG_SIGNAL_L5_HEALTH_OVRD, 0},
277277
};
278278

279+
/*
280+
enable F9 debug message outputs on UART1.
281+
NAV-PVT/STATUS/VELNED/DOP/TIMEGPS and RXM-RAWX are excluded - they
282+
are managed by the standard rate-config path (CONFIG_RATE_*) and
283+
would otherwise race with this list.
284+
driven by GPS_DRV_OPTIONS bit 10 (UBX_DebugMessages).
285+
*/
286+
const AP_GPS_UBLOX::config_list AP_GPS_UBLOX::config_F9_debug_uart1[] {
287+
{ ConfigKey::MSGOUT_UBX_NAV_SAT_UART1, 1},
288+
{ ConfigKey::MSGOUT_UBX_NAV_CLOCK_UART1, 1},
289+
{ ConfigKey::MSGOUT_UBX_NAV_SIG_UART1, 1},
290+
{ ConfigKey::MSGOUT_UBX_MON_RF_UART1, 5},
291+
{ ConfigKey::MSGOUT_UBX_MON_HW3_UART1, 5},
292+
{ ConfigKey::MSGOUT_UBX_MON_COMMS_UART1, 5},
293+
{ ConfigKey::MSGOUT_UBX_MON_SPAN_UART1, 5},
294+
};
295+
296+
// disable variant - applied when UBX_DebugMessages is cleared
297+
const AP_GPS_UBLOX::config_list AP_GPS_UBLOX::config_F9_debug_uart1_dis[] {
298+
{ ConfigKey::MSGOUT_UBX_NAV_SAT_UART1, 0},
299+
{ ConfigKey::MSGOUT_UBX_NAV_CLOCK_UART1, 0},
300+
{ ConfigKey::MSGOUT_UBX_NAV_SIG_UART1, 0},
301+
{ ConfigKey::MSGOUT_UBX_MON_RF_UART1, 0},
302+
{ ConfigKey::MSGOUT_UBX_MON_HW3_UART1, 0},
303+
{ ConfigKey::MSGOUT_UBX_MON_COMMS_UART1, 0},
304+
{ ConfigKey::MSGOUT_UBX_MON_SPAN_UART1, 0},
305+
};
306+
279307
void
280308
AP_GPS_UBLOX::_request_next_config(void)
281309
{
@@ -497,6 +525,30 @@ AP_GPS_UBLOX::_request_next_config(void)
497525
break;
498526
}
499527

528+
case STEP_F9_DEBUG: {
529+
if (supports_F9_config()) {
530+
const config_list *list;
531+
uint8_t list_length;
532+
if (option_set(AP_GPS::DriverOptions::UBX_DebugMessages)) {
533+
list = config_F9_debug_uart1;
534+
list_length = ARRAY_SIZE(config_F9_debug_uart1);
535+
Debug("Enabling F9 debug messages on UART1");
536+
} else {
537+
list = config_F9_debug_uart1_dis;
538+
list_length = ARRAY_SIZE(config_F9_debug_uart1_dis);
539+
}
540+
// baud switch is handled by AP_GPS::send_blob_start() during
541+
// detection - it picks UBLOX_SET_BINARY_921600 when this
542+
// option is set, mirroring the moving-baseline 460800 path
543+
if (!_configure_config_set(list, list_length, CONFIG_F9_DEBUG, UBX_VALSET_LAYER_RAM | UBX_VALSET_LAYER_BBR)) {
544+
_next_message--;
545+
}
546+
} else {
547+
_unconfigured_messages &= ~CONFIG_F9_DEBUG;
548+
}
549+
break;
550+
}
551+
500552
default:
501553
// this case should never be reached, do a full reset if it is hit
502554
_next_message = STEP_PVT;
@@ -1409,9 +1461,17 @@ AP_GPS_UBLOX::_parse_gps(void)
14091461
break;
14101462
case MSG_MON_HW2:
14111463
if (_payload_length == 28) {
1412-
log_mon_hw2();
1464+
log_mon_hw2();
14131465
}
14141466
break;
1467+
// F9 debug streams (enabled via CONFIG_F9_DEBUG). We don't decode
1468+
// them but must consume them so the unknown-message default path
1469+
// does not auto-disable them.
1470+
case MSG_MON_RF:
1471+
case MSG_MON_HW3:
1472+
case MSG_MON_COMMS:
1473+
case MSG_MON_SPAN:
1474+
break;
14151475
case MSG_MON_VER: {
14161476
bool check_L1L5 = false;
14171477
_have_version = true;
@@ -1430,6 +1490,8 @@ AP_GPS_UBLOX::_parse_gps(void)
14301490
if (_hardware_generation != UBLOX_F9) {
14311491
// need to ensure time mode is correctly setup on F9
14321492
_unconfigured_messages |= CONFIG_TMODE_MODE;
1493+
// F9 supports MSGOUT MSGOUT_UBX_* keys for debug streams
1494+
_unconfigured_messages |= CONFIG_F9_DEBUG;
14331495
}
14341496
_hardware_generation = UBLOX_F9;
14351497
}
@@ -1862,6 +1924,13 @@ AP_GPS_UBLOX::_parse_gps(void)
18621924
_configure_message_rate(CLASS_NAV, MSG_NAV_SVINFO, 0);
18631925
break;
18641926
}
1927+
// F9 debug streams (enabled via CONFIG_F9_DEBUG). We don't decode
1928+
// them but must consume them so the default path below does not
1929+
// auto-disable them when the option is on.
1930+
case MSG_NAV_SAT:
1931+
case MSG_NAV_SIG:
1932+
case MSG_NAV_CLOCK:
1933+
break;
18651934
default:
18661935
Debug("Unexpected NAV message 0x%02x", (unsigned)_msg_id);
18671936
if (++_disable_counter == 0) {
@@ -2231,7 +2300,8 @@ static const char *reasons[] = {"navigation rate",
22312300
"RTK MB",
22322301
"TIM TM2",
22332302
"M10",
2234-
"L5 Enable Disable"};
2303+
"L5 Enable Disable",
2304+
"F9 debug messages"};
22352305

22362306
static_assert((1 << ARRAY_SIZE(reasons)) == CONFIG_LAST, "UBLOX: Missing configuration description");
22372307

libraries/AP_GPS/AP_GPS_UBLOX.h

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
// a variant with 460800 baudrate
5656
#define UBLOX_SET_BINARY_460800 "\265\142\006\001\003\000\001\006\001\022\117$PUBX,41,1,0023,0001,460800,0*11\r\n"
5757

58+
// a variant with 921600 baudrate
59+
#define UBLOX_SET_BINARY_921600 "\265\142\006\001\003\000\001\006\001\022\117$PUBX,41,1,0023,0001,921600,0*17\r\n"
60+
5861
#define UBLOX_RXM_RAW_LOGGING 1
5962
#define UBLOX_MAX_RXM_RAW_SATS 22
6063
#define UBLOX_MAX_RXM_RAWX_SATS 80
@@ -101,7 +104,8 @@
101104
#define CONFIG_TIM_TM2 (1<<18)
102105
#define CONFIG_M10 (1<<19)
103106
#define CONFIG_L5 (1<<20)
104-
#define CONFIG_LAST (1<<21) // this must always be the last bit
107+
#define CONFIG_F9_DEBUG (1<<21)
108+
#define CONFIG_LAST (1<<22) // this must always be the last bit
105109

106110
#define CONFIG_REQUIRED_INITIAL (CONFIG_RATE_NAV | CONFIG_RATE_POSLLH | CONFIG_RATE_STATUS | CONFIG_RATE_VELNED)
107111

@@ -296,6 +300,18 @@ class AP_GPS_UBLOX : public AP_GPS_Backend
296300
MSGOUT_RTCM_3X_TYPE1230_UART2 = 0x20910305,
297301
MSGOUT_UBX_NAV_RELPOSNED_UART2 = 0x2091008f,
298302

303+
// F9 debug message outputs on UART1 (used by CONFIG_F9_DEBUG).
304+
// NAV-PVT/STATUS/VELNED/DOP/TIMEGPS and RXM-RAWX are intentionally
305+
// omitted - they are owned by the standard rate-config path.
306+
// Values cross-checked against u-blox HPG 2.02 interface description.
307+
MSGOUT_UBX_NAV_SAT_UART1 = 0x20910016,
308+
MSGOUT_UBX_NAV_CLOCK_UART1 = 0x20910066,
309+
MSGOUT_UBX_NAV_SIG_UART1 = 0x20910346,
310+
MSGOUT_UBX_MON_COMMS_UART1 = 0x20910350,
311+
MSGOUT_UBX_MON_HW3_UART1 = 0x20910355,
312+
MSGOUT_UBX_MON_RF_UART1 = 0x2091035a,
313+
MSGOUT_UBX_MON_SPAN_UART1 = 0x2091038c,
314+
299315
// enable specific signals and constellations
300316
CFG_SIGNAL_GPS_ENA = 0x1031001f,
301317
CFG_SIGNAL_GPS_L1CA_ENA = 0x10310001,
@@ -701,7 +717,18 @@ class AP_GPS_UBLOX : public AP_GPS_Backend
701717
MSG_MON_HW = 0x09,
702718
MSG_MON_HW2 = 0x0B,
703719
MSG_MON_VER = 0x04,
720+
// CLASS_MON debug message ids (consumed silently when GPS_DRV_OPTIONS
721+
// bit 10 has them enabled so the unknown-message disable counter
722+
// does not race with the F9 debug VALSET path)
723+
MSG_MON_SPAN = 0x31,
724+
MSG_MON_COMMS = 0x36,
725+
MSG_MON_HW3 = 0x37,
726+
MSG_MON_RF = 0x38,
704727
MSG_NAV_SVINFO = 0x30,
728+
// CLASS_NAV debug message ids (same rationale as the MON_* group)
729+
MSG_NAV_CLOCK = 0x22,
730+
MSG_NAV_SAT = 0x35,
731+
MSG_NAV_SIG = 0x43,
705732
MSG_RXM_RAW = 0x10,
706733
MSG_RXM_RAWX = 0x15,
707734
MSG_TIM_TM2 = 0x03
@@ -765,6 +792,7 @@ class AP_GPS_UBLOX : public AP_GPS_Backend
765792
STEP_TIM_TM2,
766793
STEP_M10,
767794
STEP_L5,
795+
STEP_F9_DEBUG,
768796
STEP_LAST
769797
};
770798

@@ -816,7 +844,7 @@ class AP_GPS_UBLOX : public AP_GPS_Backend
816844
bool _cfg_needs_save;
817845

818846
bool noReceivedHdop;
819-
847+
820848
bool havePvtMsg;
821849

822850
bool _configure_message_rate(uint8_t msg_class, uint8_t msg_id, uint8_t rate);
@@ -925,6 +953,10 @@ class AP_GPS_UBLOX : public AP_GPS_Backend
925953
static const config_list config_M10[];
926954
static const config_list config_L5_ovrd_ena[];
927955
static const config_list config_L5_ovrd_dis[];
956+
957+
// F9 debug message MSGOUT enable/disable on UART1
958+
static const config_list config_F9_debug_uart1[];
959+
static const config_list config_F9_debug_uart1_dis[];
928960
bool in_safeboot_mode;
929961
};
930962

0 commit comments

Comments
 (0)