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_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.last_msg_ticks = sys_time.nb_sec_rem; \
80  gps.last_msg_time = sys_time.nb_sec; \
81  gps_mtk_read_message(); \
82  if (gps_mtk.msg_class == MTK_DIY14_ID && \
83  gps_mtk.msg_id == MTK_DIY14_NAV_ID) { \
84  if (gps.fix == GPS_FIX_3D) { \
85  gps.last_3dfix_ticks = sys_time.nb_sec_rem; \
86  gps.last_3dfix_time = sys_time.nb_sec; \
87  } \
88  _sol_available_callback(); \
89  } \
90  if (gps_mtk.msg_class == MTK_DIY16_ID && \
91  gps_mtk.msg_id == MTK_DIY16_NAV_ID) { \
92  if (gps.fix == GPS_FIX_3D) { \
93  gps.last_3dfix_ticks = sys_time.nb_sec_rem; \
94  gps.last_3dfix_time = sys_time.nb_sec; \
95  } \
96  _sol_available_callback(); \
97  } \
98  gps_mtk.msg_available = FALSE; \
99  } \
100  }
101 
102 #define ReadGpsBuffer() { \
103  while (GpsLink(ChAvailable())&&!gps_mtk.msg_available) \
104  gps_mtk_parse(GpsLink(Getch())); \
105  }
106 
107 
108 extern void gps_mtk_read_message(void);
109 extern void gps_mtk_parse(uint8_t c);
110 
111 /*
112  * dynamic GPS configuration
113  */
114 #ifdef GPS_CONFIGURE
115 extern void gps_configure(void);
116 extern void gps_configure_uart(void);
117 #endif
118 
119 #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:281
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
uint8_t msg_idx
Definition: gps_mtk.h:41
uint8_t send_ck_b
Definition: gps_mtk.h:43