Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gps_ubx.h
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 
27 #ifndef GPS_UBX_H
28 #define GPS_UBX_H
29 
30 #ifdef GPS_CONFIGURE
31 #warning "Please use gps_ubx_ucenter.xml module instead of GPS_CONFIGURE"
32 #endif
33 
34 #include "mcu_periph/uart.h"
35 
36 #define GPS_NB_CHANNELS 16
37 
38 #define GPS_UBX_MAX_PAYLOAD 255
39 struct GpsUbx {
40  bool_t msg_available;
41  uint8_t msg_buf[GPS_UBX_MAX_PAYLOAD] __attribute__((aligned));
44 
52 
56 
57 };
58 
59 extern struct GpsUbx gps_ubx;
60 
61 #if USE_GPS_UBX_RXM_RAW
62 struct GpsUbxRawMes {
63  double cpMes;
64  double prMes;
65  float doMes;
66  uint8_t sv;
67  int8_t mesQI;
68  int8_t cno;
69  uint8_t lli;
70 };
71 
72 struct GpsUbxRaw {
73  int32_t iTOW;
74  int16_t week;
75  uint8_t numSV;
76  struct GpsUbxRawMes measures[GPS_NB_CHANNELS];
77 };
78 
79 extern struct GpsUbxRaw gps_ubx_raw;
80 #endif
81 
82 /*
83  * This part is used by the autopilot to read data from a uart
84  */
85 #include "mcu_periph/link_device.h"
86 
87 extern void ubx_header(struct link_device *dev, uint8_t nav_id, uint8_t msg_id, uint16_t len);
88 extern void ubx_trailer(struct link_device *dev);
89 extern void ubx_send_bytes(struct link_device *dev, uint8_t len, uint8_t *bytes);
90 extern void ubx_send_cfg_rst(struct link_device *dev, uint16_t bbr, uint8_t reset_mode);
91 
92 extern void gps_ubx_read_message(void);
93 extern void gps_ubx_parse(uint8_t c);
94 extern void gps_ubx_msg(void);
95 
96 
97 /* Gps callback is called when receiving a VELNED or a SOL message
98  * All position/speed messages are sent in one shot and VELNED is the last one on fixedwing
99  * For rotorcraft, only SOL message is needed for pos/speed data
100  */
101 static inline void GpsEvent(void)
102 {
103  struct link_device *dev = &((GPS_LINK).device);
104 
105  while (dev->char_available(dev->periph)) {
106  gps_ubx_parse(dev->get_byte(dev->periph));
107  if (gps_ubx.msg_available) {
108  gps_ubx_msg();
109  }
110  }
111 }
112 
113 
114 /*
115  * GPS Reset
116  */
117 
118 #define CFG_RST_Reset_Hardware 0x00
119 #define CFG_RST_Reset_Controlled 0x01
120 #define CFG_RST_Reset_Controlled_GPS_only 0x02
121 #define CFG_RST_Reset_Controlled_GPS_stop 0x08
122 #define CFG_RST_Reset_Controlled_GPS_start 0x09
123 
124 #define CFG_RST_BBR_Hotstart 0x0000
125 #define CFG_RST_BBR_Warmstart 0x0001
126 #define CFG_RST_BBR_Coldstart 0xffff
127 
128 #define gps_ubx_Reset(_val) { \
129  gps_ubx.reset = _val; \
130  if (gps_ubx.reset > CFG_RST_BBR_Warmstart) \
131  gps_ubx.reset = CFG_RST_BBR_Coldstart; \
132  ubx_send_cfg_rst(&(GPS_LINK).device, gps_ubx.reset, CFG_RST_Reset_Controlled); \
133  }
134 
135 #endif /* GPS_UBX_H */
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void ubx_send_cfg_rst(struct link_device *dev, uint16_t bbr, uint8_t reset_mode)
Definition: gps_ubx.c:310
uint8_t sol_flags
Definition: gps_ubx.h:54
Definition: gps_ubx.h:39
uint16_t len
Definition: gps_ubx.h:46
uint8_t msg_buf[GPS_UBX_MAX_PAYLOAD]
Definition: gps_ubx.h:41
uint8_t msg_id
Definition: gps_ubx.h:42
uint8_t error_cnt
Definition: gps_ubx.h:50
#define GPS_UBX_MAX_PAYLOAD
Definition: gps_ubx.h:38
void gps_ubx_read_message(void)
Definition: gps_ubx.c:74
void gps_ubx_msg(void)
Definition: gps_ubx.c:323
uint8_t ck_b
Definition: gps_ubx.h:48
void ubx_send_bytes(struct link_device *dev, uint8_t len, uint8_t *bytes)
Definition: gps_ubx.c:302
uint8_t ck_a
Definition: gps_ubx.h:48
signed short int16_t
Definition: types.h:17
bool_t msg_available
Definition: gps_ubx.h:40
uint8_t msg_idx
Definition: gps_ubx.h:47
void gps_ubx_parse(uint8_t c)
Definition: gps_ubx.c:192
static void GpsEvent(void)
Definition: gps_ubx.h:101
uint8_t send_ck_b
Definition: gps_ubx.h:49
signed long int32_t
Definition: types.h:19
uint8_t status
Definition: gps_ubx.h:45
struct GpsUbx gps_ubx
Definition: gps_ubx.c:58
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:69
uint8_t status_flags
Definition: gps_ubx.h:53
void ubx_trailer(struct link_device *dev)
Definition: gps_ubx.c:295
unsigned char uint8_t
Definition: types.h:14
uint8_t send_ck_a
Definition: gps_ubx.h:49
uint8_t have_velned
Definition: gps_ubx.h:55
signed char int8_t
Definition: types.h:15
uint8_t error_last
Definition: gps_ubx.h:51
void ubx_header(struct link_device *dev, uint8_t nav_id, uint8_t msg_id, uint16_t len)
Definition: gps_ubx.c:283
uint8_t msg_class
Definition: gps_ubx.h:43
#define GPS_NB_CHANNELS
Definition: gps_ubx.h:36