34#include "ubx_protocol.h"
41#warning "Only one GPS_UBX is supported for ucenter configuration."
45#warning "GPS_PORT_ID is no longer needed by the ublox ucenter for automatically configuration. Please remove this defined variable and double check that autoconfig is working as expected."
53#ifdef GPS_UBX_UCENTER_RATE
54#define GPS_UBX_UCENTER_RATE_LEGACY GPS_UBX_UCENTER_RATE
55#define GPS_UBX_UCENTER_RATE_VALSET GPS_UBX_UCENTER_RATE
57#define GPS_UBX_UCENTER_RATE_LEGACY 200
58#define GPS_UBX_UCENTER_RATE_VALSET 100
60#define GPS_UBX_UCENTER_RATE_LEGACY_FALLBACK 250
61#define GPS_UBX_UCENTER_RATE_VALSET_FALLBACK 200
64#define NAV5_DYN_PORTABLE 0
65#define NAV5_DYN_FIXED 1
66#define NAV5_DYN_STATIONARY 2
67#define NAV5_DYN_PEDESTRIAN 3
68#define NAV5_DYN_AUTOMOTIVE 4
70#define NAV5_DYN_AIRBORNE_1G 6
71#define NAV5_DYN_AIRBORNE_2G 7
72#define NAV5_DYN_AIRBORNE_4G 8
74#ifndef GPS_UBX_NAV5_DYNAMICS
75#define GPS_UBX_NAV5_DYNAMICS NAV5_DYN_AIRBORNE_2G
84#if GPS_UBX_UCENTER_ENABLE_NMEA
85#define GPS_UBX_ENABLE_NMEA_DATA_MASK 0xff
87#define GPS_UBX_ENABLE_NMEA_DATA_MASK 0x00
91#ifndef GPS_UBX_UCENTER_SAVE
92#define GPS_UBX_UCENTER_SAVE TRUE
96#define GPS_PORT_DDC 0x00
97#define GPS_PORT_UART1 0x01
98#define GPS_PORT_UART2 0x02
99#define GPS_PORT_USB 0x03
100#define GPS_PORT_SPI 0x04
111#define GPS_UBX_UCENTER_STATUS_STOPPED 0
112#define GPS_UBX_UCENTER_STATUS_AUTOBAUD 1
113#define GPS_UBX_UCENTER_STATUS_CONFIG 2
114#define GPS_UBX_UCENTER_STATUS_WAITING 3
116#define GPS_UBX_UCENTER_REPLY_NONE 0
117#define GPS_UBX_UCENTER_REPLY_ACK 1
118#define GPS_UBX_UCENTER_REPLY_NACK 2
119#define GPS_UBX_UCENTER_REPLY_VERSION 3
120#define GPS_UBX_UCENTER_REPLY_CFG_PRT 4
123#define UBX_GPS_BAUD (UBX_GPS_PORT).baudrate
138#if PERIODIC_TELEMETRY
181#if PERIODIC_TELEMETRY
183 static bool telemetry_registered =
false;
184 if (!telemetry_registered) {
186 telemetry_registered =
true;
260 for (
uint8_t i = 0; i < 26; i++) {
261 uint8_t c = UBX_MON_VER_c(payload, i);
262 if (c >=
'0' && c <=
'9' && UBX_MON_VER_c(payload, i + 1) ==
'.') {
264 gps_ubx_ucenter.sw_ver_l = 10 * (UBX_MON_VER_c(payload, i + 2) -
'0') + (UBX_MON_VER_c(payload, i + 3) -
'0');
274 static const char protver[] =
"PROTVER";
275 for (
uint16_t ext = 40; ext + 30 <= len; ext += 30) {
277 while (i < 7 && UBX_MON_VER_c(payload, ext + i) ==
protver[i]) {
283 for (i = 8; i < 11; i++) {
284 uint8_t c = UBX_MON_VER_c(payload, ext + i);
285 if (c <
'0' || c >
'9') {
288 major = 10 * major + (c -
'0');
299 if (c >=
'0' && c <=
'9') {
301 }
else if (c >=
'A' && c <=
'F') {
303 }
else if (c >=
'a' && c <=
'f') {
317 switch (
gps_ubx[0].msg_class) {
319 if (
gps_ubx[0].msg_id == UBX_ACK_ACK_ID) {
321 }
else if (
gps_ubx[0].msg_id == UBX_ACK_NAK_ID) {
326 if (
gps_ubx[0].msg_id == UBX_MON_VER_ID) {
336 }
else if (
gps_ubx[0].msg_id == UBX_MON_GNSS_ID) {
338 }
else if (
gps_ubx[0].msg_id == UBX_MON_COMMS_ID) {
340 uint8_t output_port = (UBX_MON_COMMS_txErrors(
gps_ubx[0].msg_buf) >> 2) & 0x07;
341 if (output_port != 0) {
347 if (
gps_ubx[0].msg_id == UBX_CFG_PRT_ID) {
373#define GPS_UBX_UCENTER_NB_BAUDS (sizeof(gps_ubx_ucenter_bauds) / sizeof(gps_ubx_ucenter_bauds[0]))
440#if DEBUG_GPS_UBX_UCENTER
444#ifdef DOWNLINK_TRANSPORT
469#define NAV_DYN_AIRBORNE_2G 6
471#define NAV5_MASK 0x05
473#define NAV5_DEFAULT_MIN_ELEV 5
474#define NAV5_DEFAULT_PDOP_MASK 25
475#define NAV5_DEFAULT_TDOP_MASK 25
476#define NAV5_DEFAULT_P_ACC 100
477#define NAV5_DEFAULT_T_ACC 300
478#define NAV5_DEFAULT_STATIC_HOLD_THRES 0
491 0x3C, 0x14, 0x03E8 , 0x0000, 0x0, 0x17, 0x00FA, 0x00FA,
492 0x0064, 0x012C, 0x000F, 0x00, 0x00);
502#define UBX_UART_MODE_MASK 0x000008D0
504#define UBX_PROTO_MASK 0x0001
505#define NMEA_PROTO_MASK 0x0002
506#define RTCM_PROTO_MASK 0x0004
507#define RTCM3_PROTO_MASK 0x0020
539#define GPS_SBAS_ENABLED 0x01
541#define GPS_SBAS_RANGING 0x01
542#define GPS_SBAS_CORRECTIONS 0x02
543#define GPS_SBAS_INTEGRITY 0x04
545#define GPS_SBAS_MAX_SBAS 3
547#define GPS_SBAS_AUTOSCAN 0x00
591#if GPS_UBX_UCENTER_PVT_ONLY
634#if GPS_UBX_UCENTER_SLOW_NAV_SOL
664#if USE_GPS_UBX_RXM_RAW
670#if USE_GPS_UBX_RXM_SFRB
689#if GPS_UBX_UCENTER_SAVE
691 UbxSend_CFG_CFG(
gps_ubx_ucenter.dev, 0x00000000, 0xffffffff, 0x00000000);
715#define VALSET_LAYER_RAM 0x01
718#define CFG_RATE_MEAS 0x30210001
719#define CFG_RATE_NAV 0x30210002
720#define CFG_NAVSPG_FIXMODE 0x20110011
721#define CFG_NAVSPG_DYNMODEL 0x20110021
722#define CFG_UART1_BAUDRATE 0x40520001
723#define CFG_UART2_BAUDRATE 0x40530001
724#define CFG_UART1INPROT_RTCM3X 0x10730004
725#define CFG_UART2INPROT_RTCM3X 0x10750004
726#define CFG_UART1OUTPROT_NMEA 0x10740002
727#define CFG_UART2OUTPROT_NMEA 0x10760002
730#define CFG_MSGOUT_NAV_PVT 0x20910006
731#define CFG_MSGOUT_NAV_POSLLH 0x20910029
732#define CFG_MSGOUT_NAV_VELNED 0x20910042
733#define CFG_MSGOUT_NAV_STATUS 0x2091001a
734#define CFG_MSGOUT_NAV_SAT 0x20910015
735#define CFG_MSGOUT_NAV_RELPOSNED 0x2091008d
736#define CFG_MSGOUT_NAV_DAHEADING 0x209103df
739#define VALSET_RELPOSNED_RATE 1
741#define VALSET_RELPOSNED_RATE 0
745#define VALSET_RECEIVER 0
747#define VALSET_MSGOUT 2
774#define VALSET_CFG_NB (sizeof(gps_ubx_ucenter_valset_cfg) / sizeof(gps_ubx_ucenter_valset_cfg[0]))
797 switch ((key >> 28) & 0x07) {
825 }
else if (nr == 1) {
845#if GPS_UBX_UCENTER_SAVE
847 UbxSend_CFG_CFG(
gps_ubx_ucenter.dev, 0x00000000, 0xffffffff, 0x00000000);
Common code for AP and FBW telemetry.
static struct uart_periph * dev
struct GpsUbx gps_ubx[GPS_UBX_NB]
UBX protocol specific code.
void gps_i2c_begin(void)
config is done, begin reading messages
bool gps_i2c_tx_is_ready(void)
is driver ready to send a message
#define NAV_DYN_AIRBORNE_2G
struct gps_ubx_ucenter_struct gps_ubx_ucenter
#define CFG_MSGOUT_NAV_PVT
#define NAV5_DEFAULT_PDOP_MASK
static void gps_ubx_ucenter_config_nav(void)
static uint8_t gps_ubx_ucenter_hex(char c)
Value of a hexadecimal character (0 when it isn't one).
#define GPS_UBX_UCENTER_RATE_VALSET_FALLBACK
static bool gps_ubx_ucenter_configure_valset(uint8_t nr)
Configure the receiver with UBX-CFG-VALSET, one step per call (4 Hz).
#define CFG_UART2INPROT_RTCM3X
#define CFG_UART1INPROT_RTCM3X
#define NAV5_DEFAULT_T_ACC
#define CFG_MSGOUT_NAV_VELNED
static void gps_ubx_ucenter_valset(uint32_t key, uint32_t value)
Set one configuration item in RAM.
#define GPS_SBAS_CORRECTIONS
#define GPS_UBX_UCENTER_REPLY_NACK
void gps_ubx_ucenter_periodic(void)
#define CFG_MSGOUT_NAV_POSLLH
#define CFG_MSGOUT_NAV_RELPOSNED
#define GPS_PORT_DDC
Receiver port numbers (UBX-CFG-PRT), also the offset of the CFG-MSGOUT keys.
#define GPS_UBX_UCENTER_STATUS_STOPPED
static const struct @223253254216236134032326377037017164311174362001 gps_ubx_ucenter_valset_cfg[]
Configuration, one item per step: the receiver refuses the whole message when it doesn't know one key...
static void gps_ubx_ucenter_enable_msg(uint8_t class, uint8_t id, uint8_t rate)
Enable u-blox message at desired period.
#define GPS_UBX_UCENTER_REPLY_ACK
#define GPS_UBX_UCENTER_STATUS_AUTOBAUD
static void gps_ubx_ucenter_send_info(uint8_t sbas)
Send the configuration replies (DEBUG message) and the receiver information to the ground.
#define GPS_UBX_UCENTER_STATUS_CONFIG
#define CFG_UART1_BAUDRATE
#define NAV5_DEFAULT_STATIC_HOLD_THRES
void gps_ubx_ucenter_event(void)
#define CFG_NAVSPG_FIXMODE
static bool gps_ubx_ucenter_autobaud(uint8_t nr)
Automatically determine the baudrate of the u-blox module and its configuration interface.
static uint8_t gps_ubx_ucenter_gnss(void)
Satellite systems in use: from the satellites in the solution (UBX-NAV-SAT), else as reported by UBX-...
#define GPS_UBX_UCENTER_RATE_VALSET
#define NAV5_DEFAULT_TDOP_MASK
#define GPS_UBX_ENABLE_NMEA_DATA_MASK
NMEA output next to UBX, disabled by default.
#define GPS_UBX_UCENTER_RATE_LEGACY
Measurement period [ms]: 5 Hz by default, 10 Hz with the configuration interface (X20).
static const uint32_t gps_ubx_ucenter_bauds[]
Baudrates tried, after the target one: the common one, the factory default, the high-rate default,...
#define NAV5_DEFAULT_MIN_ELEV
static void gps_ubx_ucenter_parse_sw_version(uint8_t *payload)
Parse "major.minor" from a version string (e.g.
#define NAV5_DEFAULT_P_ACC
#define GPS_SBAS_AUTOSCAN
#define VALSET_RELPOSNED_RATE
#define GPS_UBX_UCENTER_RATE_LEGACY_FALLBACK
#define GPS_UBX_UCENTER_REPLY_VERSION
#define GPS_UBX_UCENTER_REPLY_NONE
#define CFG_MSGOUT_NAV_SAT
#define GPS_SBAS_MAX_SBAS
void gps_ubx_ucenter_init(void)
#define CFG_NAVSPG_DYNMODEL
#define VALSET_RECEIVER
What a configuration item applies to.
static void gps_ubx_ucenter_config_port(void)
#define CFG_UART1OUTPROT_NMEA
#define GPS_UBX_UCENTER_NB_BAUDS
#define CFG_UART2_BAUDRATE
#define GPS_SBAS_INTEGRITY
static uint8_t gps_ubx_ucenter_parse_protver(uint8_t *payload, uint16_t len)
Parse the protocol version major from the extensions (30 characters each, after the software and hard...
static bool gps_ubx_ucenter_configure_step(uint8_t nr)
One configuration step with the interface the receiver supports, false when done.
#define GPS_UBX_UCENTER_STATUS_WAITING
#define UBX_UART_MODE_MASK
#define CFG_MSGOUT_NAV_STATUS
static void gps_ubx_ucenter_autobaud_poll(void)
Poll the port configuration (legacy UBX-CFG-PRT), the version (UBX-MON-VER, all receivers) and the po...
int gps_ubx_ucenter_get_status(void)
#define VALSET_LAYER_RAM
Written to RAM only, saved afterwards like with the legacy messages (UBX-CFG-CFG): flash is not on ev...
static uint32_t gps_ubx_ucenter_valset_key(uint8_t type, uint32_t key, uint32_t key_uart2)
Key of a configuration item for the port the autopilot is connected to, 0 when it doesn't apply.
static void send_ublox_info(struct transport_tx *trans, struct link_device *dev)
Receiver information, slowly for the GCS and the logs (the configuration itself is only done at start...
#define CFG_MSGOUT_NAV_DAHEADING
#define GPS_UBX_NAV5_DYNAMICS
static bool gps_ubx_ucenter_configure(uint8_t nr)
Configure the receiver with the legacy UBX-CFG messages, one step per call (4 Hz).
#define GPS_UBX_UCENTER_REPLY_CFG_PRT
#define CFG_UART2OUTPROT_NMEA
static void gps_ubx_ucenter_config_sbas(void)
#define GPS_UBX_UCENTER_CONFIG_STEPS
U-Center Variables.
uint8_t protver
Protocol version major (MON-VER extension), 0 when not reported.
void uart_periph_set_baudrate(struct uart_periph *periph, uint32_t baud)
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.