Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros 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 extern struct GpsUbx gps_ubx;
62 
63 
64 /*
65  * This part is used by the autopilot to read data from a uart
66  */
67 #define __GpsLink(dev, _x) dev##_x
68 #define _GpsLink(dev, _x) __GpsLink(dev, _x)
69 #define GpsLink(_x) _GpsLink(GPS_LINK, _x)
70 
71 #define GpsBuffer() GpsLink(ChAvailable())
72 
73 #ifndef GPS_UBX_UCENTER
74 #define gps_ubx_ucenter_event() {}
75 #endif
76 
77 
78 /* Gps callback is called when receiving a VELNED or a SOL message
79  * All position/speed messages are sent in one shot and VELNED is the last one on fixedwing
80  * For rotorcraft, only SOL message is needed for pos/speed data
81  */
82 #define GpsEvent(_sol_available_callback) { \
83  if (GpsBuffer()) { \
84  ReadGpsBuffer(); \
85  } \
86  if (gps_ubx.msg_available) { \
87  gps_ubx_read_message(); \
88  gps_ubx_ucenter_event(); \
89  if (gps_ubx.msg_class == UBX_NAV_ID && \
90  (gps_ubx.msg_id == UBX_NAV_VELNED_ID || \
91  (gps_ubx.msg_id == UBX_NAV_SOL_ID && \
92  gps_ubx.have_velned == 0))) { \
93  if (gps.fix == GPS_FIX_3D) { \
94  gps.last_fix_ticks = sys_time.nb_sec_rem; \
95  gps.last_fix_time = sys_time.nb_sec; \
96  } \
97  _sol_available_callback(); \
98  } \
99  gps_ubx.msg_available = FALSE; \
100  } \
101  }
102 
103 #define ReadGpsBuffer() { \
104  while (GpsLink(ChAvailable())&&!gps_ubx.msg_available) \
105  gps_ubx_parse(GpsLink(Getch())); \
106  }
107 
108 
109 extern void gps_ubx_read_message(void);
110 extern void gps_ubx_parse(uint8_t c);
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 extern void ubxsend_cfg_rst(uint16_t, uint8_t);
125 
126 #define gps_ubx_Reset(_val) { \
127  gps_ubx.reset = _val; \
128  if (gps_ubx.reset > CFG_RST_BBR_Warmstart) \
129  gps_ubx.reset = CFG_RST_BBR_Coldstart; \
130  ubxsend_cfg_rst(gps_ubx.reset, CFG_RST_Reset_Controlled); \
131  }
132 
133 
134 #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
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
uint8_t msg_buf[GPS_UBX_MAX_PAYLOAD] __attribute__((aligned))
#define GPS_UBX_MAX_PAYLOAD
Definition: gps_ubx.h:41
void ubxsend_cfg_rst(uint16_t, uint8_t)
Definition: gps_ubx.c:277
uint8_t status_flags
Definition: gps_ubx.h:56
void gps_ubx_read_message(void)
Definition: gps_ubx.c:92
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
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:193
struct GpsUbx gps_ubx
Definition: gps_ubx.c:81
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
static struct point c
Definition: discsurvey.c:13
uint8_t msg_id
Definition: gps_ubx.h:45