Skip to content

Commit

Permalink
ubx: added support for ublox M10 (PX4#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
katzfey authored Apr 11, 2023
1 parent c46ef08 commit f0b892f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 25 deletions.
86 changes: 61 additions & 25 deletions src/ubx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,36 +140,23 @@ GPSDriverUBX::configure(unsigned &baudrate, const GPSConfig &config)
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_UART1_DATABITS, 0, cfg_valset_msg_size);
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_UART1_PARITY, 0, cfg_valset_msg_size);
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_UART1INPROT_UBX, 1, cfg_valset_msg_size);
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_UART1INPROT_RTCM3X, _output_mode == OutputMode::RTCM ? 0 : 1,
cfg_valset_msg_size);
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_UART1INPROT_NMEA, 0, cfg_valset_msg_size);
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_UART1OUTPROT_UBX, 1, cfg_valset_msg_size);

if (_output_mode != OutputMode::GPS) {
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_UART1OUTPROT_RTCM3X, 1, cfg_valset_msg_size);
}

cfgValset<uint8_t>(UBX_CFG_KEY_CFG_UART1OUTPROT_NMEA, 0, cfg_valset_msg_size);
// TODO: are we ever connected to UART2?

// USB
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_USBINPROT_UBX, 1, cfg_valset_msg_size);
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_USBINPROT_RTCM3X, _output_mode == OutputMode::RTCM ? 0 : 1,
cfg_valset_msg_size);
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_USBINPROT_NMEA, 0, cfg_valset_msg_size);
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_USBOUTPROT_UBX, 1, cfg_valset_msg_size);

if (_output_mode != OutputMode::GPS) {
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_USBOUTPROT_RTCM3X, 1, cfg_valset_msg_size);
}

cfgValset<uint8_t>(UBX_CFG_KEY_CFG_USBOUTPROT_NMEA, 0, cfg_valset_msg_size);
// Note: USB protocol settings are handled later in the configureDevice function.

bool cfg_valset_success = false;

if (sendMessage(UBX_MSG_CFG_VALSET, (uint8_t *)&_buf, cfg_valset_msg_size)) {

if (waitForAck(UBX_MSG_CFG_VALSET, UBX_CONFIG_TIMEOUT, true) == 0) {
// Note: The M10 comes up sending NMEA sentences at 9600. It can't
// respond with an ACK until the current sentence has completed transmission.
// This can take over a second so need a large timeout on this particular wait.
// Once it has acked this it will turn off the NMEA sentences and all is good
// for future transactions.
if (waitForAck(UBX_MSG_CFG_VALSET, 2000, true) == 0) {
cfg_valset_success = true;
}
}
Expand Down Expand Up @@ -519,6 +506,40 @@ int GPSDriverUBX::configureDevicePreV27(const GNSSSystemsMask &gnssSystems)

int GPSDriverUBX::configureDevice(const GPSConfig &config, const int32_t uart2_baudrate)
{
// There is no RTCM or USB interface on M10
if (_board != Board::u_blox10) {

int cfg_valset_msg_size = initCfgValset();

cfgValset<uint8_t>(UBX_CFG_KEY_CFG_UART1INPROT_RTCM3X, _output_mode == OutputMode::RTCM ? 0 : 1,
cfg_valset_msg_size);

if (_output_mode != OutputMode::GPS) {
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_UART1OUTPROT_RTCM3X, 1, cfg_valset_msg_size);
}

// USB
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_USBINPROT_UBX, 1, cfg_valset_msg_size);
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_USBINPROT_RTCM3X, _output_mode == OutputMode::RTCM ? 0 : 1,
cfg_valset_msg_size);
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_USBINPROT_NMEA, 0, cfg_valset_msg_size);
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_USBOUTPROT_UBX, 1, cfg_valset_msg_size);

if (_output_mode != OutputMode::GPS) {
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_USBOUTPROT_RTCM3X, 1, cfg_valset_msg_size);
}

cfgValset<uint8_t>(UBX_CFG_KEY_CFG_USBOUTPROT_NMEA, 0, cfg_valset_msg_size);

if (!sendMessage(UBX_MSG_CFG_VALSET, (uint8_t *)&_buf, cfg_valset_msg_size)) {
return -1;
}

if (waitForAck(UBX_MSG_CFG_VALSET, UBX_CONFIG_TIMEOUT, true) < 0) {
return -1;
}
}

/* set configuration parameters */
int cfg_valset_msg_size = initCfgValset();
cfgValset<uint8_t>(UBX_CFG_KEY_NAVSPG_FIXMODE, 3 /* Auto 2d/3d */, cfg_valset_msg_size);
Expand Down Expand Up @@ -570,6 +591,10 @@ int GPSDriverUBX::configureDevice(const GPSConfig &config, const int32_t uart2_b
waitForAck(UBX_MSG_CFG_VALSET, UBX_CONFIG_TIMEOUT, false);

// configure active GNSS systems (leave signal bands as is)
// Note: For M10 configuration if changing from default. As per the
// MAX-M10S integration guide UBX-20053088 - R03, see section
// 2.1.1.3 GNSS signal configuration for details on some restrictions.
// Implementing these restrictions are a TODO item for M10.
if (static_cast<int32_t>(config.gnss_systems) != 0) {
cfg_valset_msg_size = initCfgValset();

Expand All @@ -592,7 +617,6 @@ int GPSDriverUBX::configureDevice(const GPSConfig &config, const int32_t uart2_b
cfgValset<uint8_t>(UBX_CFG_KEY_SIGNAL_GAL_ENA, 0, cfg_valset_msg_size);
}


if (config.gnss_systems & GNSSSystemsMask::ENABLE_BEIDOU) {
UBX_DEBUG("GNSS Systems: Use BeiDou");
cfgValset<uint8_t>(UBX_CFG_KEY_SIGNAL_BDS_ENA, 1, cfg_valset_msg_size);
Expand Down Expand Up @@ -663,8 +687,13 @@ int GPSDriverUBX::configureDevice(const GPSConfig &config, const int32_t uart2_b
config.interface_protocols & InterfaceProtocolsMask::I2C_IN_PROT_UBX, cfg_valset_msg_size);
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_I2CINPROT_NMEA,
config.interface_protocols & InterfaceProtocolsMask::I2C_IN_PROT_NMEA, cfg_valset_msg_size);
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_I2CINPROT_RTCM3X,
config.interface_protocols & InterfaceProtocolsMask::I2C_IN_PROT_RTCM3X, cfg_valset_msg_size);

// There is no RTCM on M10
if (_board != Board::u_blox10) {
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_I2CINPROT_RTCM3X,
config.interface_protocols & InterfaceProtocolsMask::I2C_IN_PROT_RTCM3X, cfg_valset_msg_size);
}

cfgValset<uint8_t>(UBX_CFG_KEY_CFG_I2COUTPROT_UBX,
config.interface_protocols & InterfaceProtocolsMask::I2C_OUT_PROT_UBX, cfg_valset_msg_size);
cfgValset<uint8_t>(UBX_CFG_KEY_CFG_I2COUTPROT_NMEA,
Expand Down Expand Up @@ -829,8 +858,11 @@ bool GPSDriverUBX::cfgValsetPort(uint32_t key_id, uint8_t value, int &msg_size)
return false;
}

if (!cfgValset<uint8_t>(key_id + 3, value, msg_size)) {
return false;
// M10 has no USB
if (_board != Board::u_blox10) {
if (!cfgValset<uint8_t>(key_id + 3, value, msg_size)) {
return false;
}
}
}

Expand Down Expand Up @@ -1726,6 +1758,10 @@ GPSDriverUBX::payloadRxAddMonVer(const uint8_t b)
sizeof(_buf.payload_rx_mon_ver_part1.hwVersion)) == 0) {
_board = Board::u_blox9;

} else if (strncmp((const char *)_buf.payload_rx_mon_ver_part1.hwVersion, "000A0000",
sizeof(_buf.payload_rx_mon_ver_part1.hwVersion)) == 0) {
_board = Board::u_blox10;

} else {
UBX_WARN("unknown board hw: %s", _buf.payload_rx_mon_ver_part1.hwVersion);
}
Expand Down
1 change: 1 addition & 0 deletions src/ubx.h
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ class GPSDriverUBX : public GPSBaseStationSupport
u_blox8 = 8, ///< M8N or M8P
u_blox9 = 9, ///< M9N, or any F9*, except F9P
u_blox9_F9P = 10, ///< F9P
u_blox10 = 11,
};

const Board &board() const { return _board; }
Expand Down

0 comments on commit f0b892f

Please sign in to comment.