Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
gps_ubx_ucenter.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008-2011 The Paparazzi Team
3 * 2026 Freek van Tienen <freek.v.tienen@gmail.com>
4 *
5 * This file is part of paparazzi.
6 *
7 * paparazzi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * paparazzi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with paparazzi; see the file COPYING. If not, see
19 * <http://www.gnu.org/licenses/>.
20 *
21 * Initial author: C. De Wagter
22 */
23
31
33#include "modules/gps/gps_ubx.h"
34#include "ubx_protocol.h"
36#if PERIODIC_TELEMETRY
38#endif
39
40#if GPS_UBX_NB > 1
41#warning "Only one GPS_UBX is supported for ucenter configuration."
42#endif
43
44#ifdef GPS_PORT_ID
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."
46#endif
47
49// Configuration, the same for both interfaces where possible
50
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
56#else
57#define GPS_UBX_UCENTER_RATE_LEGACY 200
58#define GPS_UBX_UCENTER_RATE_VALSET 100
59#endif
60#define GPS_UBX_UCENTER_RATE_LEGACY_FALLBACK 250
61#define GPS_UBX_UCENTER_RATE_VALSET_FALLBACK 200
62
64#define NAV5_DYN_PORTABLE 0 // ublox default
65#define NAV5_DYN_FIXED 1
66#define NAV5_DYN_STATIONARY 2
67#define NAV5_DYN_PEDESTRIAN 3
68#define NAV5_DYN_AUTOMOTIVE 4
69#define NAV5_DYN_SEA 5
70#define NAV5_DYN_AIRBORNE_1G 6
71#define NAV5_DYN_AIRBORNE_2G 7 // paparazzi default
72#define NAV5_DYN_AIRBORNE_4G 8
73
74#ifndef GPS_UBX_NAV5_DYNAMICS
75#define GPS_UBX_NAV5_DYNAMICS NAV5_DYN_AIRBORNE_2G
76#endif
77
79#define NAV5_2D_ONLY 1
80#define NAV5_3D_ONLY 2 // paparazzi default
81#define NAV5_AUTO 3 // ublox default
82
84#if GPS_UBX_UCENTER_ENABLE_NMEA
85#define GPS_UBX_ENABLE_NMEA_DATA_MASK 0xff
86#else
87#define GPS_UBX_ENABLE_NMEA_DATA_MASK 0x00
88#endif
89
91#ifndef GPS_UBX_UCENTER_SAVE
92#define GPS_UBX_UCENTER_SAVE TRUE
93#endif
94
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
101
103// UCENTER: init, periodic and event
104
105#ifndef GPS_I2C
106static bool gps_ubx_ucenter_autobaud(uint8_t nr);
107#endif
108static bool gps_ubx_ucenter_configure(uint8_t nr);
110
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
115
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
121
122// Target baudrate for the module
123#define UBX_GPS_BAUD (UBX_GPS_PORT).baudrate
124
125// All U-Center data
127
128
133static inline uint8_t gps_ubx_ucenter_gnss(void)
134{
135 return (gps_ubx[0].gnss_in_use != 0) ? gps_ubx[0].gnss_in_use : gps_ubx_ucenter.gnss_in_use;
136}
137
138#if PERIODIC_TELEMETRY
140static void send_ublox_info(struct transport_tx *trans, struct link_device *dev)
141{
143 pprz_msg_send_UBLOX_INFO(trans, dev, AC_ID, &gps_ubx_ucenter.baud_run, &gps_ubx_ucenter.sw_ver_h,
144 &gps_ubx_ucenter.sw_ver_l, &gps_ubx_ucenter.hw_ver_h, &gps_ubx_ucenter.hw_ver_l,
145 &gps_ubx_ucenter.sbas_in_use, &gnss);
146}
147#endif
148
150// Init Function
151
153{
154 // Start UCenter
157 gps_ubx_ucenter.cnt = 0;
158
159 gps_ubx_ucenter.baud_init = 0;
160 gps_ubx_ucenter.baud_run = 0;
161 gps_ubx_ucenter.baud_target = UBX_GPS_BAUD;
162
163 gps_ubx_ucenter.sw_ver_h = 0;
164 gps_ubx_ucenter.sw_ver_l = 0;
165 gps_ubx_ucenter.hw_ver_h = 0;
166 gps_ubx_ucenter.hw_ver_l = 0;
167 gps_ubx_ucenter.sbas_in_use = 0;
168 gps_ubx_ucenter.gnss_in_use = 0;
169
170 gps_ubx_ucenter.cfg_prt_reply = false;
171 gps_ubx_ucenter.version_reply = false;
172 gps_ubx_ucenter.protver = 0;
173 gps_ubx_ucenter.valset = false;
174
175 for (int i = 0; i < GPS_UBX_UCENTER_CONFIG_STEPS; i++) {
176 gps_ubx_ucenter.replies[i] = 0;
177 }
178
179 gps_ubx_ucenter.dev = &(UBX_GPS_PORT).device;
180
181#if PERIODIC_TELEMETRY
182 // The init also runs again when the configuration is restarted from the settings
183 static bool telemetry_registered = false;
184 if (!telemetry_registered) {
186 telemetry_registered = true;
187 }
188#endif
189}
190
191
193// Periodic Function
194// -time-based configuration
195
198{
199 if (gps_ubx_ucenter.valset) {
201 }
202 return gps_ubx_ucenter_configure(nr);
203}
204
206{
207 switch (gps_ubx_ucenter.status) {
208 // Save processing time inflight
210 return;
211 // Automatically Determine Current Baudrate
213#ifdef GPS_I2C
214 gps_ubx_ucenter.cnt = 0;
216#else
219 gps_ubx_ucenter.cnt = 0;
220 } else {
221 gps_ubx_ucenter.cnt++;
222 }
223#endif /* GPS_I2C */
224 break;
225 // Send Configuration
229#ifdef GPS_I2C
231#endif
232 gps_ubx_ucenter.cnt = 0;
233 } else {
234 gps_ubx_ucenter.cnt++;
235#ifdef GPS_I2C
237#endif
238 }
239 break;
240#ifdef GPS_I2C
242 if (gps_i2c_tx_is_ready()) {
244 }
245 break;
246#endif /* GPS_I2C */
247 default:
248 break;
249 }
250}
251
253// Event Function
254// -fetch replies: ACK and VERSION info
255
258{
259 // swVersion: 30 characters, the version is the first number
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) == '.') {
263 gps_ubx_ucenter.sw_ver_h = c - '0';
264 gps_ubx_ucenter.sw_ver_l = 10 * (UBX_MON_VER_c(payload, i + 2) - '0') + (UBX_MON_VER_c(payload, i + 3) - '0');
265 return;
266 }
267 }
268}
269
273{
274 static const char protver[] = "PROTVER";
275 for (uint16_t ext = 40; ext + 30 <= len; ext += 30) {
276 uint8_t i = 0;
277 while (i < 7 && UBX_MON_VER_c(payload, ext + i) == protver[i]) {
278 i++;
279 }
280 if (i == 7) {
281 // "PROTVER=" or "PROTVER " followed by the major
282 uint8_t major = 0;
283 for (i = 8; i < 11; i++) {
284 uint8_t c = UBX_MON_VER_c(payload, ext + i);
285 if (c < '0' || c > '9') {
286 break;
287 }
288 major = 10 * major + (c - '0');
289 }
290 return major;
291 }
292 }
293 return 0;
294}
295
298{
299 if (c >= '0' && c <= '9') {
300 return c - '0';
301 } else if (c >= 'A' && c <= 'F') {
302 return c - 'A' + 10;
303 } else if (c >= 'a' && c <= 'f') {
304 return c - 'a' + 10;
305 }
306 return 0;
307}
308
310{
311 // Save processing time inflight
313 return;
314 }
315
316 // Read Configuration Reply's
317 switch (gps_ubx[0].msg_class) {
318 case UBX_ACK_ID:
319 if (gps_ubx[0].msg_id == UBX_ACK_ACK_ID) {
321 } else if (gps_ubx[0].msg_id == UBX_ACK_NAK_ID) {
323 }
324 break;
325 case UBX_MON_ID:
326 if (gps_ubx[0].msg_id == UBX_MON_VER_ID) {
328 gps_ubx_ucenter.version_reply = true;
330 gps_ubx_ucenter.protver = gps_ubx_ucenter_parse_protver(gps_ubx[0].msg_buf, gps_ubx[0].len);
331 // hwVersion: 10 hexadecimal characters at 30, e.g. "00190000" (generation 9), "000B0000" (X20)
332 gps_ubx_ucenter.hw_ver_h = 16 * gps_ubx_ucenter_hex(UBX_MON_VER_c(gps_ubx[0].msg_buf, 32)) +
333 gps_ubx_ucenter_hex(UBX_MON_VER_c(gps_ubx[0].msg_buf, 33));
334 gps_ubx_ucenter.hw_ver_l = 16 * gps_ubx_ucenter_hex(UBX_MON_VER_c(gps_ubx[0].msg_buf, 36)) +
335 gps_ubx_ucenter_hex(UBX_MON_VER_c(gps_ubx[0].msg_buf, 37));
336 } else if (gps_ubx[0].msg_id == UBX_MON_GNSS_ID) {
337 gps_ubx_ucenter.gnss_in_use = UBX_MON_GNSS_enabled(gps_ubx[0].msg_buf);
338 } else if (gps_ubx[0].msg_id == UBX_MON_COMMS_ID) {
339 // Port this reply is output on (X20, 0 when not reported): 1 I2C, 2 UART1, 3 UART2, 4 USB, 5 SPI
340 uint8_t output_port = (UBX_MON_COMMS_txErrors(gps_ubx[0].msg_buf) >> 2) & 0x07;
341 if (output_port != 0) {
342 gps_ubx_ucenter.port_id = output_port - 1;
343 }
344 }
345 break;
346 case UBX_CFG_ID:
347 if (gps_ubx[0].msg_id == UBX_CFG_PRT_ID) {
349 gps_ubx_ucenter.cfg_prt_reply = true;
350 gps_ubx_ucenter.port_id = UBX_CFG_PRT_PortId(gps_ubx[0].msg_buf, 0);
351 gps_ubx_ucenter.baud_run = UBX_CFG_PRT_Baudrate(gps_ubx[0].msg_buf, 0);
352 }
353 break;
354 default:
355 break;
356 }
357}
358
360// Autobaud
361
362#ifndef GPS_I2C
366#ifdef B460800
367 B460800,
368#endif
369#ifdef B921600
370 B921600,
371#endif
372 };
373#define GPS_UBX_UCENTER_NB_BAUDS (sizeof(gps_ubx_ucenter_bauds) / sizeof(gps_ubx_ucenter_bauds[0]))
374
382{
383 gps_ubx_ucenter.cfg_prt_reply = false;
384 gps_ubx_ucenter.version_reply = false;
385 UbxSend_CFG_PRT_POLL(gps_ubx_ucenter.dev);
386 UbxSend_MON_GET_VER(gps_ubx_ucenter.dev);
387 UbxSend_MON_GET_COMMS(gps_ubx_ucenter.dev);
388}
389
399{
400 // Very important for some modules: give the GPS some time to boot (up to 0.75 second)
401 if (nr < 2) {
402 return true;
403 }
404
405 // The polls of the previous step were answered at that baudrate
406 if (nr > 2 && (gps_ubx_ucenter.cfg_prt_reply || gps_ubx_ucenter.version_reply)) {
407 gps_ubx_ucenter.baud_init = gps_ubx_ucenter.baud_run;
408 // The legacy UBX-CFG messages are gone from protocol version 40 (e.g. X20). The configuration
409 // interface exists from 27 (generation 9, F9 HPG 1.00): also used then when the CFG-PRT poll isn't answered.
410 gps_ubx_ucenter.valset = gps_ubx_ucenter.protver >= 40 ||
411 (gps_ubx_ucenter.protver >= 27 && !gps_ubx_ucenter.cfg_prt_reply);
412 // Not over I2C: when the receiver didn't report the port (still the I2C/DDC default), assume UART1
413 if (gps_ubx_ucenter.port_id == GPS_PORT_DDC) {
415 }
416 return false;
417 }
418
419 // Try the target baudrate first (often already configured), then the others
420 uint8_t i = nr - 2;
421 if (i <= GPS_UBX_UCENTER_NB_BAUDS) {
422 uint32_t baud = (i == 0) ? gps_ubx_ucenter.baud_target : gps_ubx_ucenter_bauds[i - 1];
423 gps_ubx_ucenter.baud_run = UART_SPEED(baud); // the CFG-PRT reply overwrites it with the reported one
424 uart_periph_set_baudrate(&(UBX_GPS_PORT), baud);
426 return true;
427 }
428
429 // Autoconfig failed... set the failsafe baudrate
430 gps_ubx_ucenter.baud_init = 0; // Set as zero to indicate that we couldn't verify the baudrate
431 uart_periph_set_baudrate(&(UBX_GPS_PORT), B9600);
432 return false;
433}
434#endif /* GPS_I2C */
435
438{
439 gps_ubx_ucenter.sbas_in_use = sbas;
440#if DEBUG_GPS_UBX_UCENTER
441 // To view, enable the DEBUG message in your telemetry configuration
443#endif
444#ifdef DOWNLINK_TRANSPORT
446 DOWNLINK_SEND_UBLOX_INFO(DefaultChannel, DefaultDevice, &gps_ubx_ucenter.baud_run, &gps_ubx_ucenter.sw_ver_h,
447 &gps_ubx_ucenter.sw_ver_l, &gps_ubx_ucenter.hw_ver_h, &gps_ubx_ucenter.hw_ver_l,
448 &gps_ubx_ucenter.sbas_in_use, &gnss);
449#endif
450}
451
453// Legacy UBX-CFG messages
454
464static inline void gps_ubx_ucenter_enable_msg(uint8_t class, uint8_t id, uint8_t rate)
465{
466 UbxSend_CFG_MSG(gps_ubx_ucenter.dev, class, id, rate);
467}
468
469#define NAV_DYN_AIRBORNE_2G 6 // CFG-NAV (firmware before 5)
470
471#define NAV5_MASK 0x05 // Apply dynamic model and position fix mode settings
472
473#define NAV5_DEFAULT_MIN_ELEV 5 // deg
474#define NAV5_DEFAULT_PDOP_MASK 25 // no units
475#define NAV5_DEFAULT_TDOP_MASK 25 // no units
476#define NAV5_DEFAULT_P_ACC 100 // m
477#define NAV5_DEFAULT_T_ACC 300 // m
478#define NAV5_DEFAULT_STATIC_HOLD_THRES 0 // cm/s
479
480#define IGNORED 0
481#define RESERVED 0
482
483static inline void gps_ubx_ucenter_config_nav(void)
484{
485 // New ublox firmware v5 or higher uses CFG_NAV5 message, CFG_NAV is no longer available
486 // If version message couldn't be fetched, default to NAV5
487 if (gps_ubx_ucenter.sw_ver_h < 5 && gps_ubx_ucenter.hw_ver_h < 6 &&
488 gps_ubx_ucenter.sw_ver_h != 0 && gps_ubx_ucenter.hw_ver_h != 0) {
489 UbxSend_CFG_NAV(gps_ubx_ucenter.dev,
490 NAV_DYN_AIRBORNE_2G, 3, 16, 24, 20, 5, 0, 0x3C,
491 0x3C, 0x14, 0x03E8 , 0x0000, 0x0, 0x17, 0x00FA, 0x00FA,
492 0x0064, 0x012C, 0x000F, 0x00, 0x00);
493 } else {
494 UbxSend_CFG_NAV5(gps_ubx_ucenter.dev,
498 }
499}
500
501// UART mode: 8N1 with reserved1 set for compatability with A4
502#define UBX_UART_MODE_MASK 0x000008D0
503
504#define UBX_PROTO_MASK 0x0001
505#define NMEA_PROTO_MASK 0x0002
506#define RTCM_PROTO_MASK 0x0004
507#define RTCM3_PROTO_MASK 0x0020
508
509static inline void gps_ubx_ucenter_config_port(void)
510{
511 switch (gps_ubx_ucenter.port_id) {
512 // I2C Interface
513 case GPS_PORT_DDC:
514#ifdef GPS_I2C
515 UbxSend_CFG_PRT(gps_ubx_ucenter.dev, gps_ubx_ucenter.port_id, 0x0, 0x0, (0x42 << 1), 0x0, UBX_PROTO_MASK,
516 UBX_PROTO_MASK, 0x0, 0x0);
517#endif
518 break;
519 // UART Interface
520 case GPS_PORT_UART1:
521 case GPS_PORT_UART2:
522 UbxSend_CFG_PRT(gps_ubx_ucenter.dev,
526 break;
527 // USB Interface
528 case GPS_PORT_USB:
529 UbxSend_CFG_PRT(gps_ubx_ucenter.dev,
530 gps_ubx_ucenter.port_id, 0x0, 0x0, 0x0, 0x0,
532 break;
533 default:
534 // SPI is not supported
535 break;
536 }
537}
538
539#define GPS_SBAS_ENABLED 0x01
540
541#define GPS_SBAS_RANGING 0x01
542#define GPS_SBAS_CORRECTIONS 0x02
543#define GPS_SBAS_INTEGRITY 0x04 // If enabled, the receiver will only use GPS satellites for which integrity information is available (not recommended)
544
545#define GPS_SBAS_MAX_SBAS 3 // Default ublox setting uses 3 SBAS channels(?)
546
547#define GPS_SBAS_AUTOSCAN 0x00
548
549static inline void gps_ubx_ucenter_config_sbas(void)
550{
551 // Since March 2nd 2011 EGNOS is released for aviation purposes
555}
556
559{
560 // Store the reply of the last configuration step and reset
562 gps_ubx_ucenter.replies[nr] = gps_ubx_ucenter.reply;
563 }
564
565 switch (nr) {
566 case 0:
567 // Use old baudrate to issue a baudrate change command
569 break;
570 case 1:
571#ifndef GPS_I2C
572 // Now the GPS baudrate should have changed, unless the receiver refused it
574 uart_periph_set_baudrate(&(UBX_GPS_PORT), gps_ubx_ucenter.baud_target);
575 gps_ubx_ucenter.baud_run = UART_SPEED(gps_ubx_ucenter.baud_target);
576 }
577#endif /*GPS_I2C*/
578 UbxSend_MON_GET_VER(gps_ubx_ucenter.dev);
579 break;
580 case 2:
581 case 3:
582 case 4:
583 case 5:
584 // UBX_G5010 takes 0.7 seconds to answer a firmware request
585 // Version info is important for proper configuration as different firmwares have different settings
586 break;
587 case 6:
588 // Configure CFG-NAV(5) message
590 break;
591#if GPS_UBX_UCENTER_PVT_ONLY // disable other messages, except SAT
592 case 7:
593 gps_ubx_ucenter_enable_msg(UBX_NAV_ID, UBX_NAV_POSLLH_ID, 0);
594 break;
595 case 8:
596 gps_ubx_ucenter_enable_msg(UBX_NAV_ID, UBX_NAV_VELNED_ID, 0);
597 break;
598 case 9:
599 gps_ubx_ucenter_enable_msg(UBX_NAV_ID, UBX_NAV_STATUS_ID, 0);
600 break;
601 case 10:
602 // Satelite information
603 gps_ubx_ucenter_enable_msg(UBX_NAV_ID, UBX_NAV_SAT_ID, 10);
604 break;
605 case 11:
606 gps_ubx_ucenter_enable_msg(UBX_NAV_ID, UBX_NAV_SOL_ID, 0);
607 break;
608 case 12:
609 gps_ubx_ucenter_enable_msg(UBX_NAV_ID, UBX_NAV_SVINFO_ID, 0);
610 break;
611 case 13:
612 // Enable Position Velocity time solution
613 gps_ubx_ucenter_enable_msg(UBX_NAV_ID, UBX_NAV_PVT_ID, 1);
614 break;
615#else
616 case 7:
617 // Geodetic Position Solution
618 gps_ubx_ucenter_enable_msg(UBX_NAV_ID, UBX_NAV_POSLLH_ID, 1);
619 break;
620 case 8:
621 // Velocity Solution in NED
622 gps_ubx_ucenter_enable_msg(UBX_NAV_ID, UBX_NAV_VELNED_ID, 1);
623 break;
624 case 9:
625 // Receiver Navigation Status
626 gps_ubx_ucenter_enable_msg(UBX_NAV_ID, UBX_NAV_STATUS_ID, 1);
627 break;
628 case 10:
629 // Space Vehicle Information
630 gps_ubx_ucenter_enable_msg(UBX_NAV_ID, UBX_NAV_SVINFO_ID, 10);
631 break;
632 case 11:
633 // Navigation Solution Information
634#if GPS_UBX_UCENTER_SLOW_NAV_SOL
635 gps_ubx_ucenter_enable_msg(UBX_NAV_ID, UBX_NAV_SOL_ID, 8);
636#else
637 gps_ubx_ucenter_enable_msg(UBX_NAV_ID, UBX_NAV_SOL_ID, 1);
638#endif
639 break;
640 case 12:
641 // Disable UTM on old Lea4P
642 gps_ubx_ucenter_enable_msg(UBX_NAV_ID, UBX_NAV_POSUTM_ID, 0);
643 break;
644 case 13:
645 // Enable Position Velocity time solution
646 gps_ubx_ucenter_enable_msg(UBX_NAV_ID, UBX_NAV_PVT_ID, 1);
647 break;
648#endif // !PVT_ONLY
649 case 14:
650 // SBAS Configuration
652 break;
653 case 15:
654 // Navigation/Measurement Rate Settings
655 UbxSend_CFG_RATE(gps_ubx_ucenter.dev, GPS_UBX_UCENTER_RATE_LEGACY, 0x0001, 0x0000);
656 break;
657 case 16:
658 // A slower measurement rate when it is refused (NAK, e.g. the LEA-4 up to 4 Hz)
661 UbxSend_CFG_RATE(gps_ubx_ucenter.dev, GPS_UBX_UCENTER_RATE_LEGACY_FALLBACK, 0x0001, 0x0000);
662 }
663 // Raw Measurement Data
664#if USE_GPS_UBX_RXM_RAW
665 gps_ubx_ucenter_enable_msg(UBX_RXM_ID, UBX_RXM_RAW_ID, 1);
666#endif
667 break;
668 case 17:
669 // Subframe Buffer
670#if USE_GPS_UBX_RXM_SFRB
671 gps_ubx_ucenter_enable_msg(UBX_RXM_ID, UBX_RXM_SFRB_ID, 1);
672#endif
673 break;
674#if USE_GPS_UBX_RTCM
675 case 18:
676 UbxSend_CFG_DGNSS(gps_ubx_ucenter.dev, 0x03, RESERVED, RESERVED);
677 break;
678 case 19:
679 gps_ubx_ucenter_enable_msg(UBX_NAV_ID, UBX_NAV_RELPOSNED_ID, 1);
680 break;
681 case 20:
682 gps_ubx_ucenter_enable_msg(UBX_NAV_ID, UBX_NAV_HPPOSLLH_ID, 1);
683 break;
684 case 21:
685 gps_ubx_ucenter_enable_msg(UBX_RXM_ID, UBX_RXM_RTCM_ID, 1);
686 break;
687#endif
688 case 22:
689#if GPS_UBX_UCENTER_SAVE
690 // Try to save on non-ROM devices...
691 UbxSend_CFG_CFG(gps_ubx_ucenter.dev, 0x00000000, 0xffffffff, 0x00000000);
692#endif
693 break;
694 case 23:
695 UbxSend_MON_GET_GNSS(gps_ubx_ucenter.dev);
696 break;
697 case 24:
698 break;
699 case 25:
701 return false;
702 default:
703 break;
704 }
705
707 return true; // Continue, except for the last case
708}
709
711// Configuration interface (UBX-CFG-VALSET), u-blox generation 9 and later
712
715#define VALSET_LAYER_RAM 0x01
716
717/* Configuration keys (u-blox interface description), the value size is in bits 28-30 of the key */
718#define CFG_RATE_MEAS 0x30210001 // U2 measurement period [ms]
719#define CFG_RATE_NAV 0x30210002 // U2 measurements per navigation solution
720#define CFG_NAVSPG_FIXMODE 0x20110011 // E1 position fix mode
721#define CFG_NAVSPG_DYNMODEL 0x20110021 // E1 dynamic platform model
722#define CFG_UART1_BAUDRATE 0x40520001 // U4
723#define CFG_UART2_BAUDRATE 0x40530001
724#define CFG_UART1INPROT_RTCM3X 0x10730004 // L RTCM3 corrections in
725#define CFG_UART2INPROT_RTCM3X 0x10750004
726#define CFG_UART1OUTPROT_NMEA 0x10740002 // L NMEA out
727#define CFG_UART2OUTPROT_NMEA 0x10760002
728/* Message output rate keys (per navigation solution) for the I2C port, the key for the other ports is
729 * the port number (CFG-PRT) higher: UART1 +1, UART2 +2, USB +3, SPI +4 */
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 // X20D
737
738#if USE_GPS_UBX_RTCM
739#define VALSET_RELPOSNED_RATE 1
740#else
741#define VALSET_RELPOSNED_RATE 0
742#endif
743
745#define VALSET_RECEIVER 0 // the receiver
746#define VALSET_UART 1 // the UART the autopilot is connected to: key for UART1, key_uart2 for UART2
747#define VALSET_MSGOUT 2 // a message output on the port the autopilot is connected to
748
750static const struct {
751 uint8_t type;
752 uint32_t key;
753 uint32_t key_uart2;
754 uint32_t value;
761 { VALSET_RECEIVER, CFG_RATE_NAV, 0, 1 },
762 // Position, velocity and time in one message, the others are not needed
767 // Satellite information, every 10th solution
769 // Relative position (RTK base or dual antenna heading)
771 // Dual antenna heading (X20D, off by default), the other receivers refuse it
774#define VALSET_CFG_NB (sizeof(gps_ubx_ucenter_valset_cfg) / sizeof(gps_ubx_ucenter_valset_cfg[0]))
775
778{
779 switch (type) {
780 case VALSET_UART:
781 if (gps_ubx_ucenter.port_id == GPS_PORT_UART1) {
782 return key;
783 } else if (gps_ubx_ucenter.port_id == GPS_PORT_UART2) {
784 return key_uart2;
785 }
786 return 0;
787 case VALSET_MSGOUT:
788 return key + gps_ubx_ucenter.port_id;
789 default:
790 return key;
791 }
792}
793
796{
797 switch ((key >> 28) & 0x07) {
798 case 0: // no key
799 break;
800 case 1: // one bit
801 case 2: // one byte
802 UbxSend_CFG_VALSET_U1(gps_ubx_ucenter.dev, 0, VALSET_LAYER_RAM, RESERVED, key, value);
803 break;
804 case 3: // two bytes
805 UbxSend_CFG_VALSET_U2(gps_ubx_ucenter.dev, 0, VALSET_LAYER_RAM, RESERVED, key, value);
806 break;
807 default: // four bytes
808 UbxSend_CFG_VALSET_U4(gps_ubx_ucenter.dev, 0, VALSET_LAYER_RAM, RESERVED, key, value);
809 break;
810 }
811}
812
815{
816 // Store the reply of the last configuration step and reset
818 gps_ubx_ucenter.replies[nr] = gps_ubx_ucenter.reply;
819 }
820
821 if (nr == 0) {
822 // Use the found baudrate to change it to the target one
824 UART_SPEED(gps_ubx_ucenter.baud_target));
825 } else if (nr == 1) {
826#ifndef GPS_I2C
827 // Now the receiver baudrate should have changed, unless the receiver refused it
829 uart_periph_set_baudrate(&(UBX_GPS_PORT), gps_ubx_ucenter.baud_target);
830 gps_ubx_ucenter.baud_run = UART_SPEED(gps_ubx_ucenter.baud_target);
831 }
832#endif
833 } else if (nr < 2 + VALSET_CFG_NB) {
834 uint8_t i = nr - 2;
835 // A slower measurement rate when it is refused (NAK, e.g. in moving base heading mode)
836 if (i > 0 && gps_ubx_ucenter_valset_cfg[i - 1].key == CFG_RATE_MEAS &&
840 }
844 } else if (nr == 2 + VALSET_CFG_NB) {
845#if GPS_UBX_UCENTER_SAVE
846 // Save the configuration in RAM to battery backed RAM and flash
847 UbxSend_CFG_CFG(gps_ubx_ucenter.dev, 0x00000000, 0xffffffff, 0x00000000);
848#endif
849 } else if (nr == 3 + VALSET_CFG_NB) {
850 UbxSend_MON_GET_GNSS(gps_ubx_ucenter.dev);
851 } else if (nr == 4 + VALSET_CFG_NB) {
852 // Wait for the GNSS reply
853 } else {
855 return false;
856 }
857
859 return true; // Continue, except for the last step
860}
861
863{
864 return gps_ubx_ucenter.status;
865}
#define B4800
Definition uart_arch.h:42
#define B57600
Definition uart_arch.h:46
#define B460800
Definition uart_arch.h:50
#define B230400
Definition uart_arch.h:49
#define B38400
Definition uart_arch.h:45
#define UART_SPEED(_def)
Definition uart_arch.h:55
#define B9600
Definition uart_arch.h:43
#define B921600
Definition uart_arch.h:51
#define B115200
Definition uart_arch.h:48
static struct uart_periph * dev
struct GpsUbx gps_ubx[GPS_UBX_NB]
Definition gps_ubx.c:97
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 GPS_SBAS_ENABLED
#define CFG_MSGOUT_NAV_VELNED
#define GPS_PORT_USB
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 UBX_GPS_BAUD
#define IGNORED
#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
#define RESERVED
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 CFG_RATE_NAV
#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 UBX_PROTO_MASK
#define NAV5_DEFAULT_MIN_ELEV
#define NAV5_MASK
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 RTCM3_PROTO_MASK
#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 VALSET_CFG_NB
#define CFG_NAVSPG_DYNMODEL
#define CFG_RATE_MEAS
#define VALSET_RECEIVER
What a configuration item applies to.
#define NMEA_PROTO_MASK
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 GPS_PORT_UART1
#define UBX_UART_MODE_MASK
#define GPS_SBAS_RANGING
#define CFG_MSGOUT_NAV_STATUS
#define VALSET_MSGOUT
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.
#define VALSET_UART
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
#define NAV5_3D_ONLY
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
#define GPS_PORT_UART2
static void gps_ubx_ucenter_config_sbas(void)
Configure Ublox GPS.
#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)
Definition uart_arch.c:280
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition telemetry.h:66
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.