Paparazzi UAS v7.0_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 *
4 * This file is part of paparazzi.
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, write to
18 * the Free Software Foundation, 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 *
21 * Initial author: C. De Wagter
22 */
23
31#include "modules/gps/gps_ubx.h"
32#include "ubx_protocol.h"
34
35#if PRINT_DEBUG_GPS_UBX_UCENTER
36#include <stdio.h>
37#define DEBUG_PRINT(...) printf(__VA_ARGS__)
38#else
39#define DEBUG_PRINT(...) {}
40#endif
41
42#if GPS_UBX_NB > 1
43#warning "Only one GPS_UBX is supported for ucenter configuration."
44#endif
45
48//
49// UCENTER: init, periodic and event
50#ifndef GPS_I2C
51static bool gps_ubx_ucenter_autobaud(uint8_t nr);
52#endif
54
55#define GPS_UBX_UCENTER_STATUS_STOPPED 0
56#define GPS_UBX_UCENTER_STATUS_AUTOBAUD 1
57#define GPS_UBX_UCENTER_STATUS_CONFIG 2
58#define GPS_UBX_UCENTER_STATUS_WAITING 3
59
60#define GPS_UBX_UCENTER_REPLY_NONE 0
61#define GPS_UBX_UCENTER_REPLY_ACK 1
62#define GPS_UBX_UCENTER_REPLY_NACK 2
63#define GPS_UBX_UCENTER_REPLY_VERSION 3
64#define GPS_UBX_UCENTER_REPLY_CFG_PRT 4
65
66// Target baudrate for the module
67#define UBX_GPS_BAUD (UBX_GPS_PORT).baudrate
68
69// All U-Center data
71
72
74// Init Function
75
98
99
101// Periodic Function
102// -time-based configuration
103
105{
106 switch (gps_ubx_ucenter.status) {
107 // Save processing time inflight
109 return;
110 break;
111 // Automatically Determine Current Baudrate
113#ifdef GPS_I2C
116#else
120#if PRINT_DEBUG_GPS_UBX_UCENTER
121 if (gps_ubx_ucenter.baud_init > 0) {
122 DEBUG_PRINT("Initial ublox baudrate found: %u\n", gps_ubx_ucenter.baud_init);
123 } else {
124 DEBUG_PRINT("WARNING: Unable to determine the ublox baudrate. Autoconfiguration is unlikely to work.\n");
125 }
126#endif
127 } else {
129 }
130#endif /* GPS_I2C */
131 break;
132 // Send Configuration
136#ifdef GPS_I2C
138#endif
140 } else {
142#ifdef GPS_I2C
144 }
145 break;
147 if (gps_i2c_tx_is_ready()) {
149#endif /*GPS_I2C*/
150 }
151 break;
152 default:
153 // stop this module now...
154 // todo
155 break;
156 }
157}
158
160// Event Function
161// -fetch replies: ACK and VERSION info
162
164{
165 // Save processing time inflight
167 return;
168 }
169
170 // Read Configuration Reply's
171 switch (gps_ubx[0].msg_class) {
172 case UBX_ACK_ID:
173 if (gps_ubx[0].msg_id == UBX_ACK_ACK_ID) {
175 DEBUG_PRINT("ACK\n");
176 } else if (gps_ubx[0].msg_id == UBX_ACK_NAK_ID) {
178 DEBUG_PRINT("NACK\n");
179 }
180 break;
181 case UBX_MON_ID:
182 if (gps_ubx[0].msg_id == UBX_MON_VER_ID) {
184 gps_ubx_ucenter.sw_ver_h = UBX_MON_VER_c(gps_ubx[0].msg_buf, 0) - '0';
185 gps_ubx_ucenter.sw_ver_l = 10 * (UBX_MON_VER_c(gps_ubx[0].msg_buf, 2) - '0');
186 gps_ubx_ucenter.sw_ver_l += UBX_MON_VER_c(gps_ubx[0].msg_buf, 3) - '0';
187 gps_ubx_ucenter.hw_ver_h = UBX_MON_VER_c(gps_ubx[0].msg_buf, 33) - '0';
188 gps_ubx_ucenter.hw_ver_h += 10 * (UBX_MON_VER_c(gps_ubx[0].msg_buf, 32) - '0');
189 gps_ubx_ucenter.hw_ver_l = UBX_MON_VER_c(gps_ubx[0].msg_buf, 37) - '0';
190 gps_ubx_ucenter.hw_ver_l += 10 * (UBX_MON_VER_c(gps_ubx[0].msg_buf, 36) - '0');
191
194 } else if (gps_ubx[0].msg_id == UBX_MON_GNSS_ID) {
196 }
197 break;
198 case UBX_CFG_ID:
199 if (gps_ubx[0].msg_id == UBX_CFG_PRT_ID) {
203
204 DEBUG_PRINT("gps_ubx_ucenter.baud_run: %u\n", gps_ubx_ucenter.baud_run);
205 DEBUG_PRINT("gps_ubx_ucenter.port_id: %u\n", gps_ubx_ucenter.port_id);
206 }
207 break;
208 default:
209 break;
210 }
211}
212
215//
216// UCENTER Configuration Functions
217
228
241static inline void gps_ubx_ucenter_enable_msg(uint8_t class, uint8_t id, uint8_t rate)
242{
243 UbxSend_CFG_MSG(gps_ubx_ucenter.dev, class, id, rate);
244}
245
254#ifndef GPS_I2C
256{
257 switch (nr) {
258 case 0:
259 case 1:
260 // Very important for some modules:
261 // Give the GPS some time to boot (up to 0.75 second)
262 break;
263 case 2:
265 uart_periph_set_baudrate(&(UBX_GPS_PORT), B38400); // Try the most common first?
267 break;
268 case 3:
271 return false;
272 }
274 uart_periph_set_baudrate(&(UBX_GPS_PORT), B9600); // Maybe the factory default?
276 break;
277 case 4:
280 return false;
281 }
283 uart_periph_set_baudrate(&(UBX_GPS_PORT), B57600); // The high-rate default?
285 break;
286 case 5:
289 return false;
290 }
292 uart_periph_set_baudrate(&(UBX_GPS_PORT), B4800); // Default NMEA baudrate?
294 break;
295 case 6:
298 return false;
299 }
301 uart_periph_set_baudrate(&(UBX_GPS_PORT), B115200); // Last possible option for ublox
303 break;
304 case 7:
307 return false;
308 }
310 uart_periph_set_baudrate(&(UBX_GPS_PORT), B230400); // Last possible option for ublox
312 break;
313 case 8:
316 return false;
317 }
318
319 // Autoconfig Failed... let's setup the failsafe baudrate
320 // Should we try even a different baudrate?
321 gps_ubx_ucenter.baud_init = 0; // Set as zero to indicate that we couldn't verify the baudrate
323 return false;
324 default:
325 break;
326 }
327 return true;
328}
329#endif /* GPS_I2C */
331// UBlox internal Navigation Solution
332
333#define NAV_DYN_STATIONARY 1
334#define NAV_DYN_PEDESTRIAN 2
335#define NAV_DYN_AUTOMOTIVE 3
336#define NAV_DYN_SEA 4
337#define NAV_DYN_AIRBORNE_1G 5
338#define NAV_DYN_AIRBORNE_2G 6 // paparazzi default
339#define NAV_DYN_AIRBORNE_4G 7
340
341#define NAV5_DYN_PORTABLE 0 // ublox default
342#define NAV5_DYN_FIXED 1
343#define NAV5_DYN_STATIONARY 2
344#define NAV5_DYN_PEDESTRIAN 3
345#define NAV5_DYN_AUTOMOTIVE 4
346#define NAV5_DYN_SEA 5
347#define NAV5_DYN_AIRBORNE_1G 6
348#define NAV5_DYN_AIRBORNE_2G 7 // paparazzi default
349#define NAV5_DYN_AIRBORNE_4G 8
350
351#ifndef GPS_UBX_NAV5_DYNAMICS
352#define GPS_UBX_NAV5_DYNAMICS NAV5_DYN_AIRBORNE_2G
353#endif
354
355#if GPS_UBX_UCENTER_ENABLE_NMEA
356#define GPS_UBX_ENABLE_NMEA_DATA_MASK 0xff
357#else
358#define GPS_UBX_ENABLE_NMEA_DATA_MASK 0x00
359#endif
360
361#define NAV5_MASK 0x05 // Apply dynamic model and position fix mode settings
362
363#define NAV5_2D_ONLY 1
364#define NAV5_3D_ONLY 2 // paparazzi default
365#define NAV5_AUTO 3 // ublox default
366
367#define NAV5_DEFAULT_MIN_ELEV 5 // deg
368#define NAV5_DEFAULT_PDOP_MASK 25 // no units
369#define NAV5_DEFAULT_TDOP_MASK 25 // no units
370#define NAV5_DEFAULT_P_ACC 100 // m
371#define NAV5_DEFAULT_T_ACC 300 // m
372#define NAV5_DEFAULT_STATIC_HOLD_THRES 0 // cm/s
373
374#define IGNORED 0
375#define RESERVED 0
376
377static inline void gps_ubx_ucenter_config_nav(void)
378{
379 // New ublox firmware v5 or higher uses CFG_NAV5 message, CFG_NAV is no longer available
380 // If version message couldn't be fetched, default to NAV5
381 DEBUG_PRINT("sw_ver: %i, hw_ver: %i\n", gps_ubx_ucenter.sw_ver_h, gps_ubx_ucenter.hw_ver_h);
385 NAV_DYN_AIRBORNE_2G, 3, 16, 24, 20, 5, 0, 0x3C,
386 0x3C, 0x14, 0x03E8 , 0x0000, 0x0, 0x17, 0x00FA, 0x00FA,
387 0x0064, 0x012C, 0x000F, 0x00, 0x00);
388 } else {
393 }
394}
395
396
397
399// UBlox port and protocol GPS configuration
400
401#ifdef GPS_PORT_ID
402#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."
403#endif
404
405// UART mode: 8N1 with reserved1 set for compatability with A4
406#define UBX_UART_MODE_MASK 0x000008D0
407
408#define UBX_PROTO_MASK 0x0001
409#define NMEA_PROTO_MASK 0x0002
410#define RTCM_PROTO_MASK 0x0004
411#define RTCM3_PROTO_MASK 0x0020
412
413#define GPS_PORT_DDC 0x00
414#define GPS_PORT_UART1 0x01
415#define GPS_PORT_UART2 0x02
416#define GPS_PORT_USB 0x03
417#define GPS_PORT_SPI 0x04
418#define GPS_PORT_RESERVED 0x05
419
420#ifndef GPS_UBX_UCENTER_RATE
421#define GPS_UBX_UCENTER_RATE 0x00FA // In milliseconds. 0x00FA = 250ms = 4Hz
422#endif
423
424#ifndef GPS_UBX_UCENTER_SAVE
425#define GPS_UBX_UCENTER_SAVE TRUE // try to save conf by default
426#endif
427
428static inline void gps_ubx_ucenter_config_port(void)
429{
430 switch (gps_ubx_ucenter.port_id) {
431 // I2C Interface
432 case GPS_PORT_DDC:
433#ifdef GPS_I2C
435 UBX_PROTO_MASK, 0x0, 0x0);
436#else
437 DEBUG_PRINT("WARNING: Please include the gps_i2c module.\n");
438#endif
439 break;
440 // UART Interface
441 case GPS_PORT_UART1:
442 case GPS_PORT_UART2:
447 break;
448 // USB Interface
449 case GPS_PORT_USB:
451 gps_ubx_ucenter.port_id, 0x0, 0x0, 0x0, 0x0,
453 break;
454 case GPS_PORT_SPI:
455 DEBUG_PRINT("WARNING: ublox SPI port is currently not supported.\n");
456 break;
457 default:
458 DEBUG_PRINT("WARNING: Unknown ublox port id: %u\n", gps_ubx_ucenter.port_id);
459 break;
460 }
461}
462
463#define GPS_SBAS_ENABLED 0x01
464
465#define GPS_SBAS_RANGING 0x01
466#define GPS_SBAS_CORRECTIONS 0x02
467#define GPS_SBAS_INTEGRITY 0x04 // If enabled, the receiver will only use GPS satellites for which integrity information is available (not recommended)
468
469#define GPS_SBAS_MAX_SBAS 3 // Default ublox setting uses 3 SBAS channels(?)
470
471#define GPS_SBAS_AUTOSCAN 0x00
472
473static inline void gps_ubx_ucenter_config_sbas(void)
474{
475 // Since March 2nd 2011 EGNOS is released for aviation purposes
479}
480
481// Text Telemetry for Debugging
482#undef GOT_PAYLOAD
483
485{
486 DEBUG_PRINT("gps_ubx_ucenter_configure nr: %u\n", nr);
487
488 // Store the reply of the last configuration step and reset
491 }
492
493 switch (nr) {
494 case 0:
495 // Use old baudrate to issue a baudrate change command
497 break;
498 case 1:
499#ifndef GPS_I2C
500#if PRINT_DEBUG_GPS_UBX_UCENTER
502 DEBUG_PRINT("ublox did not acknowledge port configuration.\n");
503 } else {
504 DEBUG_PRINT("Changed ublox baudrate to: %u\n", UART_SPEED(gps_ubx_ucenter.baud_target));
505 }
506#endif
507 // Now the GPS baudrate should have changed
510#endif /*GPS_I2C*/
512 break;
513 case 2:
514 case 3:
515 case 4:
516 case 5:
517 // UBX_G5010 takes 0.7 seconds to answer a firmware request
518 // Version info is important for proper configuration as different firmwares have different settings
519 break;
520 case 6:
521 // Configure CFG-NAV(5) message
523 break;
524#if GPS_UBX_UCENTER_PVT_ONLY // disable other messages, except SAT
525 case 7:
527 break;
528 case 8:
530 break;
531 case 9:
533 break;
534 case 10:
535 // Satelite information
537 break;
538 case 11:
540 break;
541 case 12:
543 break;
544 case 13:
545 // Enable Position Velocity time solution
547 break;
548#else
549 case 7:
550 // Geodetic Position Solution
552 break;
553 case 8:
554 // Velocity Solution in NED
556 break;
557 case 9:
558 // Receiver Navigation Status
560 break;
561 case 10:
562 // Space Vehicle Information
564 break;
565 case 11:
566 // Navigation Solution Information
567#if GPS_UBX_UCENTER_SLOW_NAV_SOL
569#else
571#endif
572 break;
573 case 12:
574 // Disable UTM on old Lea4P
576 break;
577 case 13:
578 // Enable Position Velocity time solution
580 break;
581#endif // !PVT_ONLY
582 case 14:
583 // SBAS Configuration
585 break;
586 case 15:
587 // Poll Navigation/Measurement Rate Settings
589 break;
590 case 16:
591 // Raw Measurement Data
592#if USE_GPS_UBX_RXM_RAW
594#endif
595 break;
596 case 17:
597 // Subframe Buffer
598#if USE_GPS_UBX_RXM_SFRB
600#endif
601 break;
602#if USE_GPS_UBX_RTCM
603 case 18:
604 DEBUG_PRINT("CFG_DGNSS\n");
606 break;
607 case 19:
608 DEBUG_PRINT("Enable RELPOSNED\n");
610 break;
611 case 20:
612 DEBUG_PRINT("Enable HPPPOSLLH\n");
614 break;
615 case 21:
616 DEBUG_PRINT("Enable RXM_RTCM\n");
618 break;
619#endif
620 case 22:
621#if GPS_UBX_UCENTER_SAVE
622 // Try to save on non-ROM devices...
623 UbxSend_CFG_CFG(gps_ubx_ucenter.dev, 0x00000000, 0xffffffff, 0x00000000);
624#endif
625 break;
626 case 23:
628 break;
629 case 24:
630 break;
631 case 25:
632#if DEBUG_GPS_UBX_UCENTER
633 // Debug Downlink the result of all configuration steps: see messages
634 // To view, enable DEBUG message in your telemetry configuration .xml
636 for (int i = 0; i < GPS_UBX_UCENTER_CONFIG_STEPS; i++) {
638 }
639#endif
640#ifdef DOWNLINK_TRANSPORT
641 {
646 }
647#endif
648 return false;
649 default:
650 break;
651 }
652
654 return true; // Continue, except for the last case
655}
656
658{
659 return gps_ubx_ucenter.status;
660}
#define B4800
Definition uart_arch.h:42
#define B57600
Definition uart_arch.h:46
#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 B115200
Definition uart_arch.h:48
struct GpsUbx gps_ubx[GPS_UBX_NB]
Definition gps_ubx.c:78
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 NAV5_DEFAULT_PDOP_MASK
static void gps_ubx_ucenter_config_nav(void)
#define GPS_UBX_UCENTER_RATE
static void gps_ubx_ucenter_config_port_poll(void)
Polls the u-blox port configuration When the payload is omitted (zero length), the configuration for ...
#define NAV5_DEFAULT_T_ACC
#define GPS_SBAS_ENABLED
#define GPS_PORT_USB
#define GPS_SBAS_CORRECTIONS
#define GPS_UBX_UCENTER_REPLY_NACK
void gps_ubx_ucenter_periodic(void)
#define UBX_GPS_BAUD
#define IGNORED
#define GPS_PORT_DDC
#define GPS_UBX_UCENTER_STATUS_STOPPED
#define RESERVED
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
#define GPS_UBX_UCENTER_STATUS_CONFIG
#define NAV5_DEFAULT_STATIC_HOLD_THRES
void gps_ubx_ucenter_event(void)
static bool gps_ubx_ucenter_autobaud(uint8_t nr)
Automatically determine the baudrate of the u-blox module.
#define NAV5_DEFAULT_TDOP_MASK
#define GPS_UBX_ENABLE_NMEA_DATA_MASK
#define UBX_PROTO_MASK
#define NAV5_DEFAULT_MIN_ELEV
#define DEBUG_PRINT(...)
#define NAV5_MASK
#define NAV5_DEFAULT_P_ACC
#define GPS_SBAS_AUTOSCAN
#define RTCM3_PROTO_MASK
#define GPS_UBX_UCENTER_REPLY_VERSION
#define GPS_UBX_UCENTER_REPLY_NONE
#define GPS_SBAS_MAX_SBAS
void gps_ubx_ucenter_init(void)
#define NMEA_PROTO_MASK
static void gps_ubx_ucenter_config_port(void)
#define GPS_PORT_SPI
#define GPS_SBAS_INTEGRITY
#define GPS_UBX_UCENTER_STATUS_WAITING
#define GPS_PORT_UART1
#define UBX_UART_MODE_MASK
#define GPS_SBAS_RANGING
int gps_ubx_ucenter_get_status(void)
#define GPS_UBX_NAV5_DYNAMICS
#define NAV5_3D_ONLY
static bool gps_ubx_ucenter_configure(uint8_t nr)
#define GPS_UBX_UCENTER_REPLY_CFG_PRT
#define GPS_PORT_UART2
static void gps_ubx_ucenter_config_sbas(void)
Configure Ublox GPS.
#define GPS_UBX_UCENTER_CONFIG_STEPS
U-Center Variables.
struct link_device * dev
char replies[GPS_UBX_UCENTER_CONFIG_STEPS]
uint8_t port_id
Port identifier number.
void uart_periph_set_baudrate(struct uart_periph *periph, uint32_t baud)
Definition uart_arch.c:280
uint16_t foo
Definition main_demo5.c:58
#define FALSE
Definition std.h:5
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.