UBlox M10 Support
[openXsensor.git] / openXsensor / oXs_gps.h
blobe8820da0bd9c39047382cf50e54261e825ddadcf
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;
67 uint16_t year;
68 uint8_t month;
69 uint8_t day;
70 uint8_t hour;
71 uint8_t min;
72 uint8_t sec;
73 uint8_t valid;
74 uint32_t time_acc;
75 int32_t nano;
76 uint8_t fix_type;
77 uint8_t fix_status;
78 uint8_t additional_flags;
79 uint8_t satellites;
80 uint32_t longitude;
81 uint32_t latitude;
82 int32_t height;
83 int32_t height_above_sea_level;
84 uint32_t hacc; // horizontal accuracy
85 uint32_t vacc; // vertical accuracy
86 int32_t velocity_noord;
87 int32_t velocity_east;
88 int32_t velocity_down;
89 int32_t gspeed_2d_mm; // speed 2D in mm/sec
90 int32_t head_mot_2d;
91 uint32_t speed_accuracy;
92 uint32_t head_accuracy;
93 uint16_t position_DOP;
94 uint16_t flag3;
95 uint32_t res;
96 int32_t head_velocity;
97 int16_t magnetic_declination;
98 uint16_t magnetic_accuracy;
99 } ubx_nav_pvt;
102 typedef struct {
103 uint32_t time; // GPS msToW
104 int32_t ned_north;
105 int32_t ned_east;
106 int32_t ned_down;
107 uint32_t speed_3d;
108 uint32_t speed_2d;
109 int32_t heading_2d;
110 uint32_t speed_accuracy;
111 uint32_t heading_accuracy;
112 } ubx_nav_velned;
114 typedef struct {
115 uint8_t chn; // Channel number, 255 for SVx not assigned to channel
116 uint8_t svid; // Satellite ID
117 uint8_t flags; // Bitmask
118 uint8_t quality; // Bitfield
119 uint8_t cno; // Carrier to Noise Ratio (Signal Strength) // dbHz, 0-55.
120 uint8_t elev; // Elevation in integer degrees
121 int16_t azim; // Azimuth in integer degrees
122 int32_t prRes; // Pseudo range residual in centimetres
123 } ubx_nav_svinfo_channel;
125 typedef struct {
126 uint32_t time; // GPS Millisecond time of week
127 uint8_t numCh; // Number of channels
128 uint8_t globalFlags; // Bitmask, Chip hardware generation 0:Antaris, 1:u-blox 5, 2:u-blox 6
129 uint16_t reserved2; // Reserved
130 ubx_nav_svinfo_channel channel[16]; // 16 satellites * 12 byte
131 } ubx_nav_svinfo;
133 #if defined(GPS_TRANSMIT_TIME)
134 typedef struct {
135 uint32_t time; // GPS msToW
136 uint32_t time_acc;
137 int32_t nanoseconds;
138 uint16_t year;
139 uint8_t month;
140 uint8_t day;
141 uint8_t hour;
142 uint8_t min;
143 uint8_t sec;
144 uint8_t flag;
145 } ubx_nav_timeutc;
146 #endif
148 // GPS codes that could be used
149 #define PREAMBLE1 0xb5
150 #define PREAMBLE2 0x62
151 #define CLASS_NAV 0x01
152 #define CLASS_ACK 0x05
153 #define CLASS_CFG 0x06
154 #define MSG_ACK_NACK 0x00
155 #define MSG_ACK_ACK 0x01
156 #define MSG_POSLLH 0x2
157 #define MSG_STATUS 0x3
158 #define MSG_SOL 0x6 // not supported in ublox10
159 #define MSG_PVT 0x7 // not supported in ublox6
160 #define MSG_VELNED 0x12
161 #if defined GPS_TRANSMIT_TIME
162 #define MSG_TIMEUTC 0x21
163 #endif
164 #define MSG_SVINFO 0x30
165 #define MSG_CFG_PRT 0x00
166 #define MSG_CFG_RATE 0x08
167 #define MSG_CFG_SET_RATE 0x01
168 #define MSG_CFG_NAV_SETTINGS 0x24
170 #define FIX_NONE 0
171 #define FIX_DEAD_RECKONING 1
172 #define FIX_2D 2
173 #define FIX_3D 3
174 #define FIX_GPS_DEAD_RECKONING 4
175 #define FIX_TIME 5
177 #define NAV_STATUS_FIX_VALID 1
182 class OXS_GPS {
183 public:
184 #ifdef DEBUG
185 OXS_GPS( HardwareSerial &print);
186 #else
187 OXS_GPS( uint8_t x );
188 #endif
189 void setupGps() ;
190 void readGps();
191 // void OXS_GPS::_update_checksum(uint8_t *data, uint8_t len, uint8_t *ck_a, uint8_t *ck_b) ;
192 bool UBLOX_parse_gps(void) ;
193 bool gpsNewFrameUBLOX(uint8_t data) ;
196 private:
197 #ifdef DEBUG
198 HardwareSerial* printer;
199 #endif
206 #endif // OXS_GPS_h