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_skytraq.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Antoine Drouin <poinix@gmail.com>
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 #ifndef GPS_SKYTRAQ_H
23 #define GPS_SKYTRAQ_H
24 
25 #include "mcu_periph/uart.h"
26 
27 #define SKYTRAQ_SYNC1 0xA0
28 #define SKYTRAQ_SYNC2 0xA1
29 
30 #define SKYTRAQ_SYNC3 0x0D
31 #define SKYTRAQ_SYNC4 0x0A
32 
33 
34 #define SKYTRAQ_ID_NAVIGATION_DATA 0XA8
35 
36 #define SKYTRAQ_NAVIGATION_DATA_FixMode(_payload) (uint8_t) (*((uint8_t*)_payload+2-2))
37 #define SKYTRAQ_NAVIGATION_DATA_NumSV(_payload) (uint8_t) (*((uint8_t*)_payload+3-2))
38 
39 //#define SKYTRAQ_NAVIGATION_DATA_TOW(_payload) (uint32_t)(_payload[7] + (((uint32_t)_payload[6])<<8) + (((uint32_t)_payload[5])<<16) + (((uint32_t)_payload[4])<<24))
40 #define SKYTRAQ_NAVIGATION_DATA_TOW(_payload) __builtin_bswap32(*(uint32_t*)&_payload[ 6-2])
41 #define SKYTRAQ_NAVIGATION_DATA_LAT(_payload) __builtin_bswap32(*( int32_t*)&_payload[10-2])
42 #define SKYTRAQ_NAVIGATION_DATA_LON(_payload) __builtin_bswap32(*( int32_t*)&_payload[14-2])
43 #define SKYTRAQ_NAVIGATION_DATA_AEL(_payload) __builtin_bswap32(*(uint32_t*)&_payload[18-2])
44 #define SKYTRAQ_NAVIGATION_DATA_ASL(_payload) __builtin_bswap32(*(uint32_t*)&_payload[22-2])
45 //#define SKYTRAQ_NAVIGATION_DATA_GDOP(_payload) __builtin_bswap16(*(uint16_t*)&_payload[26-2])
46 //#define SKYTRAQ_NAVIGATION_DATA_PDOP(_payload) __builtin_bswap(*(uint16_t*)&_payload[28-2])
47 
48 #define SKYTRAQ_NAVIGATION_DATA_ECEFX(_payload) __builtin_bswap32(*( int32_t*)&_payload[36-2])
49 #define SKYTRAQ_NAVIGATION_DATA_ECEFY(_payload) __builtin_bswap32(*( int32_t*)&_payload[40-2])
50 #define SKYTRAQ_NAVIGATION_DATA_ECEFZ(_payload) __builtin_bswap32(*( int32_t*)&_payload[44-2])
51 #define SKYTRAQ_NAVIGATION_DATA_ECEFVX(_payload) __builtin_bswap32(*( int32_t*)&_payload[48-2])
52 #define SKYTRAQ_NAVIGATION_DATA_ECEFVY(_payload) __builtin_bswap32(*( int32_t*)&_payload[52-2])
53 #define SKYTRAQ_NAVIGATION_DATA_ECEFVZ(_payload) __builtin_bswap32(*( int32_t*)&_payload[56-2])
54 
55 
56 
57 /* last error type */
58 #define GPS_SKYTRAQ_ERR_NONE 0
59 #define GPS_SKYTRAQ_ERR_OVERRUN 1
60 #define GPS_SKYTRAQ_ERR_MSG_TOO_LONG 2
61 #define GPS_SKYTRAQ_ERR_CHECKSUM 3
62 #define GPS_SKYTRAQ_ERR_OUT_OF_SYNC 4
63 #define GPS_SKYTRAQ_ERR_UNEXPECTED 5
64 
65 #define GPS_SKYTRAQ_MAX_PAYLOAD 255
66 struct GpsSkytraq {
67  uint8_t msg_buf[GPS_SKYTRAQ_MAX_PAYLOAD] __attribute__ ((aligned));
68  bool_t msg_available;
70 
77 };
78 
79 extern struct GpsSkytraq gps_skytraq;
80 
81 
82 /*
83  * This part is used by the autopilot to read data from a uart
84  */
85 #define __GpsLink(dev, _x) dev##_x
86 #define _GpsLink(dev, _x) __GpsLink(dev, _x)
87 #define GpsLink(_x) _GpsLink(GPS_LINK, _x)
88 
89 #define GpsBuffer() GpsLink(ChAvailable())
90 
91 #define GpsEvent(_sol_available_callback) { \
92  if (GpsBuffer()) { \
93  ReadGpsBuffer(); \
94  } \
95  if (gps_skytraq.msg_available) { \
96  gps_skytraq_read_message(); \
97  if (gps_skytraq.msg_id == SKYTRAQ_ID_NAVIGATION_DATA) { \
98  if (gps.fix == GPS_FIX_3D) { \
99  gps.last_fix_ticks = sys_time.nb_sec_rem; \
100  gps.last_fix_time = sys_time.nb_sec; \
101  } \
102  _sol_available_callback(); \
103  } \
104  gps_skytraq.msg_available = FALSE; \
105  } \
106  }
107 
108 #define ReadGpsBuffer() { \
109  while (GpsLink(ChAvailable())&&!gps_skytraq.msg_available) \
110  gps_skytraq_parse(GpsLink(Getch())); \
111  }
112 
113 
114 extern void gps_skytraq_read_message(void);
115 extern void gps_skytraq_parse(uint8_t c);
116 
117 #endif /* GPS_SKYTRAQ_H */
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint8_t error_last
Definition: gps_skytraq.h:76
uint8_t msg_id
Definition: gps_skytraq.h:69
void gps_skytraq_read_message(void)
Definition: gps_skytraq.c:61
uint8_t status
Definition: gps_skytraq.h:71
uint8_t msg_idx
Definition: gps_skytraq.h:73
uint8_t error_cnt
Definition: gps_skytraq.h:75
#define GPS_SKYTRAQ_MAX_PAYLOAD
Definition: gps_skytraq.h:65
bool_t msg_available
Definition: gps_skytraq.h:68
uint8_t checksum
Definition: gps_skytraq.h:74
uint16_t len
Definition: gps_skytraq.h:72
unsigned char uint8_t
Definition: types.h:14
struct GpsSkytraq gps_skytraq
Definition: gps_skytraq.c:31
uint8_t msg_buf[GPS_SKYTRAQ_MAX_PAYLOAD] __attribute__((aligned))
void gps_skytraq_parse(uint8_t c)
Definition: gps_skytraq.c:125
static struct point c
Definition: discsurvey.c:13