Update oXs_out_frsky.cpp
[openXsensor.git] / openXsensor / oXs_gps.h
blob9af48b918f0c8c456210281e6f859bd6d53eabad
1 #ifndef OXS_GPS_h
2 #define OXS_GPS_h
4 #include <Arduino.h>
5 #include "oXs_config_basic.h"
6 #include "oXs_config_advanced.h"
7 #include "oXs_config_macros.h"
11 // from the UBlox6 document, the largest payout we receive i the NAV-SVINFO and the payload size
12 // is calculated as 8 + 12*numCh. numCh in the case of a Glonass receiver is 28.
13 #define UBLOX_PAYLOAD_SIZE 344 // 344 is the absolute max size
14 #define UBLOX_BUFFER_SIZE 50 // but the message that we read should not exceed about 50 bytes
16 // UBX support
17 //typedef struct { // not used I think
18 // uint8_t preamble1;
19 // uint8_t preamble2;
20 // uint8_t msg_class;
21 // uint8_t msg_id;
22 // uint16_t length;
23 //} ubx_header;
25 typedef struct {
26 uint32_t time; // GPS msToW
27 int32_t longitude; // in degree with 7 decimals
28 int32_t latitude; // in degree with 7 decimals
29 int32_t altitude_ellipsoid; // in mm
30 int32_t altitude_msl; // in mm
31 uint32_t horizontal_accuracy;
32 uint32_t vertical_accuracy; // in mm
33 } ubx_nav_posllh;
35 typedef struct {
36 uint32_t time; // GPS msToW
37 uint8_t fix_type;
38 uint8_t fix_status;
39 uint8_t differential_status;
40 uint8_t res;
41 uint32_t time_to_first_fix;
42 uint32_t uptime; // milliseconds
43 } ubx_nav_status;
45 typedef struct {
46 uint32_t time;
47 int32_t time_nsec;
48 int16_t week;
49 uint8_t fix_type;
50 uint8_t fix_status;
51 int32_t ecef_x;
52 int32_t ecef_y;
53 int32_t ecef_z;
54 uint32_t position_accuracy_3d;
55 int32_t ecef_x_velocity;
56 int32_t ecef_y_velocity;
57 int32_t ecef_z_velocity;
58 uint32_t speed_accuracy;
59 uint16_t position_DOP;
60 uint8_t res;
61 uint8_t satellites;
62 uint32_t res2;
63 } ubx_nav_solution;
65 typedef struct {
66 uint32_t time; // GPS msToW
67 int32_t ned_north;
68 int32_t ned_east;
69 int32_t ned_down;
70 uint32_t speed_3d;
71 uint32_t speed_2d;
72 int32_t heading_2d;
73 uint32_t speed_accuracy;
74 uint32_t heading_accuracy;
75 } ubx_nav_velned;
77 typedef struct {
78 uint8_t chn; // Channel number, 255 for SVx not assigned to channel
79 uint8_t svid; // Satellite ID
80 uint8_t flags; // Bitmask
81 uint8_t quality; // Bitfield
82 uint8_t cno; // Carrier to Noise Ratio (Signal Strength) // dbHz, 0-55.
83 uint8_t elev; // Elevation in integer degrees
84 int16_t azim; // Azimuth in integer degrees
85 int32_t prRes; // Pseudo range residual in centimetres
86 } ubx_nav_svinfo_channel;
88 typedef struct {
89 uint32_t time; // GPS Millisecond time of week
90 uint8_t numCh; // Number of channels
91 uint8_t globalFlags; // Bitmask, Chip hardware generation 0:Antaris, 1:u-blox 5, 2:u-blox 6
92 uint16_t reserved2; // Reserved
93 ubx_nav_svinfo_channel channel[16]; // 16 satellites * 12 byte
94 } ubx_nav_svinfo;
96 #if defined(GPS_TRANSMIT_TIME)
97 typedef struct {
98 uint32_t time; // GPS msToW
99 uint32_t time_acc;
100 int32_t nanoseconds;
101 uint16_t year;
102 uint8_t month;
103 uint8_t day;
104 uint8_t hour;
105 uint8_t min;
106 uint8_t sec;
107 uint8_t flag;
108 } ubx_nav_timeutc;
109 #endif
111 // GPS codes that could be used
112 #define PREAMBLE1 0xb5
113 #define PREAMBLE2 0x62
114 #define CLASS_NAV 0x01
115 #define CLASS_ACK 0x05
116 #define CLASS_CFG 0x06
117 #define MSG_ACK_NACK 0x00
118 #define MSG_ACK_ACK 0x01
119 #define MSG_POSLLH 0x2
120 #define MSG_STATUS 0x3
121 #define MSG_SOL 0x6
122 #define MSG_VELNED 0x12
123 #if defined GPS_TRANSMIT_TIME
124 #define MSG_TIMEUTC 0x21
125 #endif
126 #define MSG_SVINFO 0x30
127 #define MSG_CFG_PRT 0x00
128 #define MSG_CFG_RATE 0x08
129 #define MSG_CFG_SET_RATE 0x01
130 #define MSG_CFG_NAV_SETTINGS 0x24
132 #define FIX_NONE 0
133 #define FIX_DEAD_RECKONING 1
134 #define FIX_2D 2
135 #define FIX_3D 3
136 #define FIX_GPS_DEAD_RECKONING 4
137 #define FIX_TIME 5
139 #define NAV_STATUS_FIX_VALID 1
144 class OXS_GPS {
145 public:
146 #ifdef DEBUG
147 OXS_GPS( HardwareSerial &print);
148 #else
149 OXS_GPS( uint8_t x );
150 #endif
151 void setupGps() ;
152 void readGps();
153 // void OXS_GPS::_update_checksum(uint8_t *data, uint8_t len, uint8_t *ck_a, uint8_t *ck_b) ;
154 bool UBLOX_parse_gps(void) ;
155 bool gpsNewFrameUBLOX(uint8_t data) ;
158 private:
159 #ifdef DEBUG
160 HardwareSerial* printer;
161 #endif
168 #endif // OXS_GPS_h