Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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 
37 #include "ubx_protocol.h"
38 
39 #define GPS_NB_CHANNELS 16
40 
41 #define GPS_UBX_MAX_PAYLOAD 255
42 struct GpsUbx {
43  bool_t msg_available;
44  uint8_t msg_buf[GPS_UBX_MAX_PAYLOAD] __attribute__ ((aligned));
47 
55 
59 
60 };
61 
62 extern struct GpsUbx gps_ubx;
63 
64 #if USE_GPS_UBX_RXM_RAW
65 struct GpsUbxRawMes {
66  double cpMes;
67  double prMes;
68  float doMes;
69  uint8_t sv;
70  int8_t mesQI;
71  int8_t cno;
72  uint8_t lli;
73 };
74 
75 struct GpsUbxRaw {
76  int32_t iTOW;
77  int16_t week;
78  uint8_t numSV;
79  struct GpsUbxRawMes measures[GPS_NB_CHANNELS];
80 };
81 
82 extern struct GpsUbxRaw gps_ubx_raw;
83 #endif
84 
85 /*
86  * This part is used by the autopilot to read data from a uart
87  */
88 #define __GpsLink(dev, _x) dev##_x
89 #define _GpsLink(dev, _x) __GpsLink(dev, _x)
90 #define GpsLink(_x) _GpsLink(GPS_LINK, _x)
91 
92 #define GpsBuffer() GpsLink(ChAvailable())
93 
94 #ifndef GPS_UBX_UCENTER
95 #define gps_ubx_ucenter_event() {}
96 #endif
97 
98 
99 /* Gps callback is called when receiving a VELNED or a SOL message
100  * All position/speed messages are sent in one shot and VELNED is the last one on fixedwing
101  * For rotorcraft, only SOL message is needed for pos/speed data
102  */
103 #define GpsEvent(_sol_available_callback) { \
104  if (GpsBuffer()) { \
105  ReadGpsBuffer(); \
106  } \
107  if (gps_ubx.msg_available) { \
108  gps.last_msg_ticks = sys_time.nb_sec_rem; \
109  gps.last_msg_time = sys_time.nb_sec; \
110  gps_ubx_read_message(); \
111  gps_ubx_ucenter_event(); \
112  if (gps_ubx.msg_class == UBX_NAV_ID && \
113  (gps_ubx.msg_id == UBX_NAV_VELNED_ID || \
114  (gps_ubx.msg_id == UBX_NAV_SOL_ID && \
115  gps_ubx.have_velned == 0))) { \
116  if (gps.fix == GPS_FIX_3D) { \
117  gps.last_3dfix_ticks = sys_time.nb_sec_rem; \
118  gps.last_3dfix_time = sys_time.nb_sec; \
119  } \
120  _sol_available_callback(); \
121  } \
122  gps_ubx.msg_available = FALSE; \
123  } \
124  }
125 
126 #define ReadGpsBuffer() { \
127  while (GpsLink(ChAvailable())&&!gps_ubx.msg_available) \
128  gps_ubx_parse(GpsLink(Getch())); \
129  }
130 
131 
132 extern void gps_ubx_read_message(void);
133 extern void gps_ubx_parse(uint8_t c);
134 
135 
136 
137 /*
138  * GPS Reset
139  */
140 
141 #define CFG_RST_Reset_Hardware 0x00
142 #define CFG_RST_Reset_Controlled 0x01
143 #define CFG_RST_Reset_Controlled_GPS_only 0x02
144 #define CFG_RST_Reset_Controlled_GPS_stop 0x08
145 #define CFG_RST_Reset_Controlled_GPS_start 0x09
146 
147 #define CFG_RST_BBR_Hotstart 0x0000
148 #define CFG_RST_BBR_Warmstart 0x0001
149 #define CFG_RST_BBR_Coldstart 0xffff
150 
151 extern void ubxsend_cfg_rst(uint16_t, uint8_t);
152 
153 #define gps_ubx_Reset(_val) { \
154  gps_ubx.reset = _val; \
155  if (gps_ubx.reset > CFG_RST_BBR_Warmstart) \
156  gps_ubx.reset = CFG_RST_BBR_Coldstart; \
157  ubxsend_cfg_rst(gps_ubx.reset, CFG_RST_Reset_Controlled); \
158  }
159 
160 #define GpsUartSendMessage GpsLink(SendMessage)
161 
162 #define GpsUartSend1(c) GpsLink(Transmit(c))
163 #define UbxInitCheksum() { gps_ubx.send_ck_a = gps_ubx.send_ck_b = 0; }
164 #define UpdateChecksum(c) { gps_ubx.send_ck_a += c; gps_ubx.send_ck_b += gps_ubx.send_ck_a; }
165 #define UbxSend1(c) { uint8_t i8=c; GpsUartSend1(i8); UpdateChecksum(i8); }
166 #define UbxSend2(c) { uint16_t i16=c; UbxSend1(i16&0xff); UbxSend1(i16 >> 8); }
167 #define UbxSend1ByAddr(x) { UbxSend1(*x); }
168 #define UbxSend2ByAddr(x) { UbxSend1(*x); UbxSend1(*(x+1)); }
169 #define UbxSend4ByAddr(x) { UbxSend1(*x); UbxSend1(*(x+1)); UbxSend1(*(x+2)); UbxSend1(*(x+3)); }
170 #define GpsUartSetBaudrate(_a) GpsLink(SetBaudrate(_a))
171 
172 #define UbxHeader(nav_id, msg_id, len) { \
173  GpsUartSend1(UBX_SYNC1); \
174  GpsUartSend1(UBX_SYNC2); \
175  UbxInitCheksum(); \
176  UbxSend1(nav_id); \
177  UbxSend1(msg_id); \
178  UbxSend2(len); \
179  }
180 
181 #define UbxTrailer() { GpsUartSend1(gps_ubx.send_ck_a); GpsUartSend1(gps_ubx.send_ck_b); GpsUartSendMessage(); }
182 
183 #endif /* GPS_UBX_H */
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
Definition: gps_ubx.h:42
uint8_t msg_buf[GPS_UBX_MAX_PAYLOAD]
Definition: gps_ubx.h:44
bool_t msg_available
Definition: gps_ubx.h:43
uint8_t ck_a
Definition: gps_ubx.h:51
uint8_t send_ck_b
Definition: gps_ubx.h:52
#define GPS_UBX_MAX_PAYLOAD
Definition: gps_ubx.h:41
void ubxsend_cfg_rst(uint16_t, uint8_t)
Definition: jsbsim_gps.c:66
uint8_t status_flags
Definition: gps_ubx.h:56
void gps_ubx_read_message(void)
Definition: gps_ubx.c:73
uint8_t msg_class
Definition: gps_ubx.h:46
uint8_t send_ck_a
Definition: gps_ubx.h:52
uint8_t error_cnt
Definition: gps_ubx.h:53
signed short int16_t
Definition: types.h:17
uint8_t msg_idx
Definition: gps_ubx.h:50
uint8_t ck_b
Definition: gps_ubx.h:51
uint8_t error_last
Definition: gps_ubx.h:54
void gps_ubx_parse(uint8_t c)
Definition: gps_ubx.c:194
signed long int32_t
Definition: types.h:19
struct GpsUbx gps_ubx
Definition: gps_ubx.c:58
uint8_t have_velned
Definition: gps_ubx.h:58
unsigned char uint8_t
Definition: types.h:14
uint8_t sol_flags
Definition: gps_ubx.h:57
uint8_t status
Definition: gps_ubx.h:48
uint16_t len
Definition: gps_ubx.h:49
signed char int8_t
Definition: types.h:15
uint8_t msg_id
Definition: gps_ubx.h:45
#define GPS_NB_CHANNELS
Includes macros generated from ubx.xml.
Definition: gps_ubx.h:39