Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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#ifndef GPS_UBX_ENABLE_NMEA_DATA_MASK
356#define GPS_UBX_ENABLE_NMEA_DATA_MASK 0x00
357#endif
358
359#define NAV5_MASK 0x05 // Apply dynamic model and position fix mode settings
360
361#define NAV5_2D_ONLY 1
362#define NAV5_3D_ONLY 2 // paparazzi default
363#define NAV5_AUTO 3 // ublox default
364
365#define NAV5_DEFAULT_MIN_ELEV 5 // deg
366#define NAV5_DEFAULT_PDOP_MASK 25 // no units
367#define NAV5_DEFAULT_TDOP_MASK 25 // no units
368#define NAV5_DEFAULT_P_ACC 100 // m
369#define NAV5_DEFAULT_T_ACC 300 // m
370#define NAV5_DEFAULT_STATIC_HOLD_THRES 0 // cm/s
371
372#define IGNORED 0
373#define RESERVED 0
374
375static inline void gps_ubx_ucenter_config_nav(void)
376{
377 // New ublox firmware v5 or higher uses CFG_NAV5 message, CFG_NAV is no longer available
378 // If version message couldn't be fetched, default to NAV5
379 DEBUG_PRINT("sw_ver: %i, hw_ver: %i\n", gps_ubx_ucenter.sw_ver_h, gps_ubx_ucenter.hw_ver_h);
383 NAV_DYN_AIRBORNE_2G, 3, 16, 24, 20, 5, 0, 0x3C,
384 0x3C, 0x14, 0x03E8 , 0x0000, 0x0, 0x17, 0x00FA, 0x00FA,
385 0x0064, 0x012C, 0x000F, 0x00, 0x00);
386 } else {
391 }
392}
393
394
395
397// UBlox port and protocol GPS configuration
398
399#ifdef GPS_PORT_ID
400#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."
401#endif
402
403// UART mode: 8N1 with reserved1 set for compatability with A4
404#define UBX_UART_MODE_MASK 0x000008D0
405
406#define UBX_PROTO_MASK 0x0001
407#define NMEA_PROTO_MASK 0x0002
408#define RTCM_PROTO_MASK 0x0004
409#define RTCM3_PROTO_MASK 0x0020
410
411#define GPS_PORT_DDC 0x00
412#define GPS_PORT_UART1 0x01
413#define GPS_PORT_UART2 0x02
414#define GPS_PORT_USB 0x03
415#define GPS_PORT_SPI 0x04
416#define GPS_PORT_RESERVED 0x05
417
418#ifndef GPS_UBX_UCENTER_RATE
419#define GPS_UBX_UCENTER_RATE 0x00FA // In milliseconds. 0x00FA = 250ms = 4Hz
420#endif
421
422static inline void gps_ubx_ucenter_config_port(void)
423{
424 switch (gps_ubx_ucenter.port_id) {
425 // I2C Interface
426 case GPS_PORT_DDC:
427#ifdef GPS_I2C
429 UBX_PROTO_MASK, 0x0, 0x0);
430#else
431 DEBUG_PRINT("WARNING: Please include the gps_i2c module.\n");
432#endif
433 break;
434 // UART Interface
435 case GPS_PORT_UART1:
436 case GPS_PORT_UART2:
441 break;
442 // USB Interface
443 case GPS_PORT_USB:
445 gps_ubx_ucenter.port_id, 0x0, 0x0, 0x0, 0x0,
447 break;
448 case GPS_PORT_SPI:
449 DEBUG_PRINT("WARNING: ublox SPI port is currently not supported.\n");
450 break;
451 default:
452 DEBUG_PRINT("WARNING: Unknown ublox port id: %u\n", gps_ubx_ucenter.port_id);
453 break;
454 }
455}
456
457#define GPS_SBAS_ENABLED 0x01
458
459#define GPS_SBAS_RANGING 0x01
460#define GPS_SBAS_CORRECTIONS 0x02
461#define GPS_SBAS_INTEGRITY 0x04
462
463#define GPS_SBAS_MAX_SBAS 3 // Default ublox setting uses 3 SBAS channels(?)
464
465#define GPS_SBAS_AUTOSCAN 0x00
466
467static inline void gps_ubx_ucenter_config_sbas(void)
468{
469 // Since March 2nd 2011 EGNOS is released for aviation purposes
473}
474
475// Text Telemetry for Debugging
476#undef GOT_PAYLOAD
477
479{
480 DEBUG_PRINT("gps_ubx_ucenter_configure nr: %u\n", nr);
481
482 // Store the reply of the last configuration step and reset
485 }
486
487 switch (nr) {
488 case 0:
489 // Use old baudrate to issue a baudrate change command
491 break;
492 case 1:
493#ifndef GPS_I2C
494#if PRINT_DEBUG_GPS_UBX_UCENTER
496 DEBUG_PRINT("ublox did not acknowledge port configuration.\n");
497 } else {
498 DEBUG_PRINT("Changed ublox baudrate to: %u\n", UART_SPEED(gps_ubx_ucenter.baud_target));
499 }
500#endif
501 // Now the GPS baudrate should have changed
504#endif /*GPS_I2C*/
506 break;
507 case 2:
508 case 3:
509 case 4:
510 case 5:
511 // UBX_G5010 takes 0.7 seconds to answer a firmware request
512 // Version info is important for proper configuration as different firmwares have different settings
513 break;
514 case 6:
515 // Configure CFG-NAV(5) message
517 break;
518 case 7:
519 // Geodetic Position Solution
521 break;
522 case 8:
523 // Velocity Solution in NED
525 break;
526 case 9:
527 // Receiver Navigation Status
529 break;
530 case 10:
531 // Space Vehicle Information
533 break;
534 case 11:
535 // Navigation Solution Information
536#if GPS_UBX_UCENTER_SLOW_NAV_SOL
538#else
540#endif
541 break;
542 case 12:
543 // Disable UTM on old Lea4P
545 break;
546 case 13:
547 // Enable Position Velocity time solution
549 break;
550 case 14:
551 // SBAS Configuration
553 break;
554 case 15:
555 // Poll Navigation/Measurement Rate Settings
557 break;
558 case 16:
559 // Raw Measurement Data
560#if USE_GPS_UBX_RXM_RAW
562#endif
563 break;
564 case 17:
565 // Subframe Buffer
566#if USE_GPS_UBX_RXM_SFRB
568#endif
569 break;
570#if USE_GPS_UBX_RTCM
571 case 18:
572 DEBUG_PRINT("CFG_DGNSS\n");
574 break;
575 case 19:
576 DEBUG_PRINT("Enable RELPOSNED\n");
578 break;
579 case 20:
580 DEBUG_PRINT("Enable HPPPOSLLH\n");
582 break;
583 case 21:
584 DEBUG_PRINT("Enable RXM_RTCM\n");
586 break;
587#endif
588 case 22:
589 // Try to save on non-ROM devices...
590 UbxSend_CFG_CFG(gps_ubx_ucenter.dev, 0x00000000, 0xffffffff, 0x00000000);
591 break;
592 case 23:
594 break;
595 case 24:
596 break;
597 case 25:
598#if DEBUG_GPS_UBX_UCENTER
599 // Debug Downlink the result of all configuration steps: see messages
600 // To view, enable DEBUG message in your telemetry configuration .xml
602 for (int i = 0; i < GPS_UBX_UCENTER_CONFIG_STEPS; i++) {
604 }
605#endif
606#ifdef DOWNLINK_TRANSPORT
607 {
612 }
613#endif
614 return false;
615 default:
616 break;
617 }
618
620 return true; // Continue, except for the last case
621}
622
624{
625 return gps_ubx_ucenter.status;
626}
#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:76
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.