forked from df8oe/RS41HUP
-
Notifications
You must be signed in to change notification settings - Fork 9
/
ublox.h
242 lines (217 loc) · 9.26 KB
/
ublox.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
//
// Created by SQ5RWU on 2016-12-27.
//
#ifndef RS41HUP_UBLOX_H
#define RS41HUP_UBLOX_H
#include <stdint.h>
typedef struct {
int32_t lat_raw;
int32_t lon_raw;
int32_t alt_raw;
int32_t speed_raw;
uint8_t sats_raw;
uint8_t seconds;
uint8_t minutes;
uint8_t hours;
uint8_t fix;
uint8_t gpsFixOK;
uint8_t psmState;
uint16_t pDOP;
uint16_t ok_packets;
uint16_t bad_packets;
} GPSEntry;
typedef struct __attribute__((packed)){
uint8_t sc1; // 0xB5
uint8_t sc2; // 0x62
uint8_t messageClass;
uint8_t messageId;
uint16_t payloadSize;
} uBloxHeader;
typedef struct {
uint8_t ck_a;
uint8_t ck_b;
} uBloxChecksum;
typedef struct {
uint32_t iTOW; //GPS time of week of the navigation epoch. [- ms]
uint16_t year; //Year (UTC) [- y]
uint8_t month; //Month, range 1..12 (UTC) [- month]
uint8_t day; //Day of month, range 1..31 (UTC) [- d]
uint8_t hour; //Hour of day, range 0..23 (UTC) [- h]
uint8_t min; //Minute of hour, range 0..59 (UTC) [- min]
uint8_t sec; //Seconds of minute, range 0..60 (UTC) [- s]
uint8_t valid; //Validity flags (see graphic below) [- -]
uint32_t tAcc; //Time accuracy estimate (UTC) [- ns]
int32_t nano; //Fraction of second, range -1e9 .. 1e9 (UTC) [- ns]
uint8_t fixType; //GNSSfix Type: [- -]
uint8_t flags; //Fix status flags (see graphic below) [- -]
uint8_t flags2; //Additional flags (see graphic below) [- -]
uint8_t numSV; //Number of satellites used in Nav Solution [- -]
int32_t lon; //Longitude [1e-7 deg]
int32_t lat; //Latitude [1e-7 deg]
int32_t height; //Height above ellipsoid [- mm]
int32_t hMSL; //Height above mean sea level [- mm]
uint32_t hAcc; //Horizontal accuracy estimate [- mm]
uint32_t vAcc; //Vertical accuracy estimate [- mm]
int32_t velN; //NED north velocity [- mm/s]
int32_t velE; //NED east velocity [- mm/s]
int32_t velD; //NED down velocity [- mm/s]
int32_t gSpeed; //Ground Speed (2-D) [- mm/s]
int32_t headMot; //Heading of motion (2-D) [1e-5 deg]
uint32_t sAcc; //Speed accuracy estimate [- mm/s]
uint32_t headAcc; //Heading accuracy estimate (both motion and vehicle) [1e-5 deg]
uint16_t pDOP; //Position DOP [0.01 -]
uint8_t reserved1[6]; //Reserved [- -]
int32_t headVeh; //Heading of vehicle (2-D) [1e-5 deg]
uint8_t reserved2[4]; //Reserved [- -]
} uBloxNAVPVTPayload;
typedef struct {
uint32_t iTOW; //GPS Millisecond Time of Week [- ms]
int32_t lon; //Longitude [1e-7 deg]
int32_t lat; //Latitude [1e-7 deg]
int32_t height; //Height above Ellipsoid [- mm]
int32_t hMSL; //Height above mean sea level [- mm]
uint32_t hAcc; //Horizontal Accuracy Estimate [- mm]
uint32_t vAcc; //Vertical Accuracy Estimate [- mm]
} uBloxNAVPOSLLHPayload;
typedef struct {
uint32_t iTOW; //GPS Millisecond Time of Week [- ms]
int32_t fTOW; //Fractional Nanoseconds remainder of rounded ms above, range -500000 .. 500000 [- ns]
int16_t week; //GPS week (GPS time) [- -]
uint8_t gpsFix; //GPSfix Type, range 0..5 0x00 = No Fix 0x01 = Dead Reckoning only 0x02 = 2D-Fix 0x03 = 3D-Fix 0x04 = GPS + dead reckoning combined 0x05 = Time only fix 0x06..0xff: reserved [- -]
uint8_t flags; //Fix Status Flags (see graphic below) [- -]
int32_t ecefX; //ECEF X coordinate [- cm]
int32_t ecefY; //ECEF Y coordinate [- cm]
int32_t ecefZ; //ECEF Z coordinate [- cm]
uint32_t pAcc; //3D Position Accuracy Estimate [- cm]
int32_t ecefVX; //ECEF X velocity [- cm/s]
int32_t ecefVY; //ECEF Y velocity [- cm/s]
int32_t ecefVZ; //ECEF Z velocity [- cm/s]
uint32_t sAcc; //Speed Accuracy Estimate [- cm/s]
uint16_t pDOP; //Position DOP [0.01 -]
uint8_t reserved1; //Reserved [- -]
uint8_t numSV; //Number of SVs used in Nav Solution [- -]
uint32_t reserved2; //Reserved [- -]
} uBloxNAVSOLPayload;
typedef struct {
uint32_t iTOW; //GPS Millisecond Time of Week [- ms]
int32_t velN; // NED north velocity (cm/s)
int32_t velE; // NED east velocity (cm/s)
int32_t velD; // NED down velocity (cm/s)
uint32_t speed; // Speed (3-D) (cm/s)
uint32_t gSpeed; // Ground Speed (3-D) (cm/s)
int32_t heading; // Heading of motion 2-D
uint32_t sAcc; // Speed Accuracy Estimate (cm/s)
uint32_t cAcc; // Course Accuracy Estimate (degrees)
} uBloxNAVVELNEDPayload;
typedef struct {
uint32_t iTOW; //GPS Millisecond Time of Week [- ms]
uint32_t tAcc; //Time Accuracy Estimate [- ns]
int32_t nano; //Nanoseconds of second, range -1e9 .. 1e9 (UTC) [- ns]
uint16_t year; //Year, range 1999..2099 (UTC) [- y]
uint8_t month; //Month, range 1..12 (UTC) [- month]
uint8_t day; //Day of Month, range 1..31 (UTC) [- d]
uint8_t hour; //Hour of Day, range 0..23 (UTC) [- h]
uint8_t min; //Minute of Hour, range 0..59 (UTC) [- min]
uint8_t sec; //Seconds of Minute, range 0..59 (UTC) [- s]
uint8_t valid; //Validity Flags (see graphic below) [- -]
} uBloxNAVTIMEUTCPayload;
typedef struct {
uint32_t iTOW; //GPS Millisecond Time of Week [- ms]
uint8_t gpsFix; //GPS Fix State
uint8_t flags; // LSB = gpsFixOK - the only valid way of determining if a fix is actually OK.
uint8_t fixStat;
uint8_t flags2; // Power Save Mode State
uint32_t ttff;
uint32_t msss;
} uBloxNAVSTATUSPayload;
typedef struct {
uint8_t portID; //Port Identifier Number (see Serial [- -]
uint8_t reserved1; //Reserved [- -]
uint16_t txReady; //TX ready PIN configuration [- -]
uint32_t mode; //A bit mask describing the UART mode [- -]
uint32_t baudRate; //Baud rate in bits/second [- Bits/s]
uint16_t inProtoMask; //A mask describing which input protocols are active. [- -]
uint16_t outProtoMask; //A mask describing which output protocols are active. [- -]
uint16_t flags; //Flags bit mask (see graphic below) [- -]
uint8_t reserved2[2]; //Reserved [- -]
} uBloxCFGPRTPayload;
typedef struct {
uint8_t clsID; //Message Class [- -]
uint8_t msgID; //Message Identifier [- -]
uint8_t ck_a;
uint8_t ck_b;
} uBloxACKACKayload;
typedef struct {
uint8_t msgClass; //Message Class [- -]
uint8_t msgID; //Message Identifier [- -]
uint8_t rate; //Send rate on current Port [- -]
} uBloxCFGMSGPayload;
typedef struct {
uint16_t navBbrMask; //BBR Sections to clear. The following Special Sets apply:
// 0x0000 Hotstart
// 0x0001 Warmstart
// 0xFFFF Coldstart [- -]
uint8_t resetMode; //Reset Type
// - 0x00 - Hardware reset (Watchdog) immediately
// - 0x01 - Controlled Software reset
// - 0x02 - Controlled Software reset (GPS only)
// - 0x04 - Hardware reset (Watchdog) after shutdown (>=FW6.0)
// - 0x08 - Controlled GPS stop
// - 0x09 - Controlled GPS start [- -]
// - 0x09 - Controlled GPS start [- -]
uint8_t reserved1; //Reserved [- -]
} uBloxCFGRSTPayload;
typedef struct {
uint16_t mask; //Parameters Bitmask. Only the masked parameters will be applied. (see graphic below) [- -]
uint8_t dynModel; //Dynamic Platform model: - 0 Portable - 2 Stationary - 3 Pedestrian - 4 Automotive - 5 Sea - 6 Airborne with <1g Acceleration - 7 Airborne with <2g Acceleration - 8 Airborne with <4g Acceleration [- -]
uint8_t fixMode; //Position Fixing Mode. - 1: 2D only - 2: 3D only - 3: Auto 2D/3D [- -]
int32_t fixedAlt; //Fixed altitude (mean sea level) for 2D fix mode. [0.01 m]
uint32_t fixedAltVar; //Fixed altitude variance for 2D mode. [0.0001 m^2]
int8_t minElev; //Minimum Elevation for a GNSS satellite to be used in NAV [- deg]
uint8_t drLimit; //Maximum time to perform dead reckoning (linear extrapolation) in case of GPS signal loss [- s]
uint16_t pDop; //Position DOP Mask to use [0.1 -]
uint16_t tDop; //Time DOP Mask to use [0.1 -]
uint16_t pAcc; //Position Accuracy Mask [- m]
uint16_t tAcc; //Time Accuracy Mask [- m]
uint8_t staticHoldThresh; //Static hold threshold [- cm/s]
uint8_t dgpsTimeOut; //DGPS timeout, firmware 7 and newer only [- s]
uint32_t reserved2; //Always set to zero [- -]
uint32_t reserved3; //Always set to zero [- -]
uint32_t reserved4; //Always set to zero [- -]
} uBloxCFGNAV5Payload;
typedef struct {
uint8_t reserved1; //Always set to 8 [- -]
uint8_t lpMode; //Low Power Mode 0: Max. performance mode 1: Power Save Mode (>= FW 6.00 only) 2-3: reserved 4: Eco mode 5-255: reserved [- -]
} uBloxCFGRXMPayload;
typedef union {
uBloxNAVPVTPayload navpvt;
uBloxCFGPRTPayload cfgprt;
uBloxCFGMSGPayload cfgmsg;
uBloxCFGNAV5Payload cfgnav5;
uBloxNAVPOSLLHPayload navposllh;
uBloxNAVSOLPayload navsol;
uBloxNAVTIMEUTCPayload navtimeutc;
uBloxNAVVELNEDPayload navvelned;
uBloxNAVSTATUSPayload navstatus;
uBloxACKACKayload ackack;
uBloxCFGRSTPayload cfgrst;
uBloxCFGRXMPayload cfgrxm;
} ubloxPacketData;
typedef struct __attribute__((packed)){
uBloxHeader header;
ubloxPacketData data;
} uBloxPacket;
void ublox_init();
void send_ublox(uint8_t msgClass, uint8_t msgId, uint8_t *payload, uint16_t payloadSize);
void send_ublox_packet(uBloxPacket * packet);
void ublox_get_last_data(GPSEntry * gpsEntry);
uBloxChecksum ublox_calc_checksum(const uint8_t msgClass, const uint8_t msgId, const uint8_t *message, uint16_t size);
void ublox_handle_incoming_byte(uint8_t data);
void ublox_handle_packet(uBloxPacket *pkt);
uint8_t ublox_wait_for_ack();
void ubx_config_gps();
void ubx_powersave();
void ubx_eco_mode();
void ublox_gps_stop();
void ublox_gps_start();
#endif //RS41HUP_UBLOX_H