Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gps_mtk.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 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 
22 
23 #ifndef MTK_H
24 #define MTK_H
25 
26 #include "mcu_periph/uart.h"
27 
29 #include "mtk_protocol.h"
30 
31 #define GPS_MTK_MAX_PAYLOAD 255
32 
33 struct GpsMtk {
34  bool_t msg_available;
35  uint8_t msg_buf[GPS_MTK_MAX_PAYLOAD] __attribute__ ((aligned));
38 
46 
49 };
50 
51 extern struct GpsMtk gps_mtk;
52 
53 
54 /*
55  * This part is used by the autopilot to read data from a uart
56  */
57 #define __GpsLink(dev, _x) dev##_x
58 #define _GpsLink(dev, _x) __GpsLink(dev, _x)
59 #define GpsLink(_x) _GpsLink(GPS_LINK, _x)
60 
61 #define GpsBuffer() GpsLink(ChAvailable())
62 
63 #ifdef GPS_CONFIGURE
64 extern bool_t gps_configuring;
65 #define GpsConfigure() { \
66  if (gps_configuring) \
67  gps_configure(); \
68  }
69 #else
70 #define GpsConfigure() {}
71 #endif
72 
73 #define GpsEvent(_sol_available_callback) { \
74  if (GpsBuffer()) { \
75  ReadGpsBuffer(); \
76  GpsConfigure(); \
77  } \
78  if (gps_mtk.msg_available) { \
79  gps_mtk_read_message(); \
80  if (gps_mtk.msg_class == MTK_DIY14_ID && \
81  gps_mtk.msg_id == MTK_DIY14_NAV_ID) { \
82  if (gps.fix == GPS_FIX_3D) { \
83  gps.last_fix_time = sys_time.nb_sec; \
84  } \
85  _sol_available_callback(); \
86  } \
87  if (gps_mtk.msg_class == MTK_DIY16_ID && \
88  gps_mtk.msg_id == MTK_DIY16_NAV_ID) { \
89  if (gps.fix == GPS_FIX_3D) { \
90  gps.last_fix_ticks = sys_time.nb_sec_rem; \
91  gps.last_fix_time = sys_time.nb_sec; \
92  } \
93  _sol_available_callback(); \
94  } \
95  gps_mtk.msg_available = FALSE; \
96  } \
97  }
98 
99 #define ReadGpsBuffer() { \
100  while (GpsLink(ChAvailable())&&!gps_mtk.msg_available) \
101  gps_mtk_parse(GpsLink(Getch())); \
102  }
103 
104 
105 extern void gps_mtk_read_message(void);
106 extern void gps_mtk_parse(uint8_t c);
107 
108 /*
109  * dynamic GPS configuration
110  */
111 #ifdef GPS_CONFIGURE
112 extern void gps_configure(void);
113 extern void gps_configure_uart(void);
114 #endif
115 
116 #endif /* MTK_H */
unsigned short uint16_t
Definition: types.h:16
uint16_t len
Definition: gps_mtk.h:40
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
Definition: gps_mtk.h:33
uint8_t ck_a
Definition: gps_mtk.h:42
#define GPS_MTK_MAX_PAYLOAD
Includes macros generated from mtk.xml.
Definition: gps_mtk.h:31
uint8_t sol_flags
Definition: gps_mtk.h:48
void gps_mtk_parse(uint8_t c)
Definition: gps_mtk.c:283
uint8_t send_ck_a
Definition: gps_mtk.h:43
uint8_t status_flags
Definition: gps_mtk.h:47
uint8_t msg_id
Definition: gps_mtk.h:36
uint8_t msg_buf[GPS_MTK_MAX_PAYLOAD]
Definition: gps_mtk.h:35
struct GpsMtk gps_mtk
Definition: gps_mtk.c:82
uint8_t error_cnt
Definition: gps_mtk.h:44
void gps_mtk_read_message(void)
Definition: gps_mtk.c:160
uint8_t status
Definition: gps_mtk.h:39
uint8_t ck_b
Definition: gps_mtk.h:42
bool_t msg_available
Definition: gps_mtk.h:34
unsigned char uint8_t
Definition: types.h:14
uint8_t msg_class
Definition: gps_mtk.h:37
uint8_t error_last
Definition: gps_mtk.h:45
static struct point c
Definition: discsurvey.c:39
uint8_t msg_idx
Definition: gps_mtk.h:41
uint8_t send_ck_b
Definition: gps_mtk.h:43