blob: 13ae5fab7939af7fd7e71d82b0d768afa3a9c50f [file] [log] [blame]
Sylvain Munaut341542b2009-12-22 21:53:22 +01001/*
2 * ubx.h
3 *
4 * Header for UBX related stuff
5 *
6 *
7 * Copyright (C) 2009 Sylvain Munaut <tnt@246tNt.com>
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#ifndef __UBX_H__
24#define __UBX_H__
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#include <stdint.h>
31
32/* Constants used in UBX */
33
34 /* Sync bytes (two first bytes of each message) */
35#define UBX_SYNC0 0xb5
36#define UBX_SYNC1 0x62
37
38 /* UBX messages classes */
39#define UBX_CLASS_NAV 0x01
40#define UBX_CLASS_RXM 0x02
41#define UBX_CLASS_INF 0x04
42#define UBX_CLASS_ACK 0x05
43#define UBX_CLASS_CFG 0x06
44#define UBX_CLASS_UPD 0x09
45#define UBX_CLASS_MON 0x0a
46#define UBX_CLASS_AID 0x0b
47#define UBX_CLASS_TIM 0x0d
48
49 /* UBX messages type ID (by class) */
50#define UBX_NAV_POSECEF 0x01
51#define UBX_NAV_POSLLH 0x02
52#define UBX_NAV_STATUS 0x03
53#define UBX_NAV_DOP 0x04
54#define UBX_NAV_SOL 0x06
55#define UBX_NAV_POSUTM 0x08
56#define UBX_NAV_VELECEF 0x11
57#define UBX_NAV_VELNED 0x12
58#define UBX_NAV_TIMEGPS 0x20
59#define UBX_NAV_TIMEUTC 0x21
60#define UBX_NAV_CLOCK 0x22
61#define UBX_NAV_SVINFO 0x30
62#define UBX_NAV_DGPS 0x31
63#define UBX_NAV_SBAS 0x32
64#define UBX_NAV_EKFSTATUS 0x40
65
66#define UBX_RXM_RAW 0x10
67#define UBX_RXM_SFRB 0x11
68#define UBX_RXM_SVSI 0x20
69#define UBX_RXM_SVSI_GPS 0x20
70#define UBX_RXM_ALM 0x30
71#define UBX_RXM_EPH 0x31
72#define UBX_RXM_POSREQ 0x40
73
74#define UBX_INF_ERROR 0x00
75#define UBX_INF_WARNING 0x01
76#define UBX_INF_NOTICE 0x02
77#define UBX_INF_TEST 0x03
78#define UBX_INF_DEBUG 0x04
79#define UBX_INF_USER 0x07
80
81#define UBX_ACK_NAK 0x00
82#define UBX_ACK_ACK 0x01
83
84#define UBX_CFG_PRT 0x00
85#define UBX_CFG_USB 0x1b
86#define UBX_CFG_MSG 0x01
87#define UBX_CFG_NMEA 0x17
88#define UBX_CFG_RATE 0x08
89#define UBX_CFG_CFG 0x09
90#define UBX_CFG_TP 0x07
91#define UBX_CFG_NAV2 0x1a
92#define UBX_CFG_DAT 0x06
93#define UBX_CFG_INF 0x02
94#define UBX_CFG_RST 0x04
95#define UBX_CFG_RXM 0x11
96#define UBX_CFG_ANT 0x13
97#define UBX_CFG_FXN 0x0e
98#define UBX_CFG_SBAS 0x16
99#define UBX_CFG_LIC 0x80
100#define UBX_CFG_TM 0x10
101#define UBX_CFG_TM2 0x19
102#define UBX_CFG_TMODE 0x1d
103#define UBX_CFG_EKF 0x12
104
105#define UBX_UPD_DOWNL 0x01
106#define UBX_UPD_UPLOAD 0x02
107#define UBX_UPD_EXEC 0x03
108#define UBX_UPD_MEMCPY 0x04
109
110#define UBX_MON_SCHD 0x01
111#define UBX_MON_IO 0x02
112#define UBX_MON_IPC 0x03
113#define UBX_MON_VER 0x04
114#define UBX_MON_EXCEPT 0x05
115#define UBX_MON_MSGPP 0x06
116#define UBX_MON_RXBUF 0x07
117#define UBX_MON_TXBUF 0x08
118#define UBX_MON_HW 0x09
119#define UBX_MON_USB 0x0a
120
121#define UBX_AID_REQ 0x00
122#define UBX_AID_INI 0x01
123#define UBX_AID_HUI 0x02
124#define UBX_AID_DATA 0x10
125#define UBX_AID_ALM 0x30
126#define UBX_AID_EPH 0x31
127
128#define UBX_TIM_TP 0x01
129#define UBX_TIM_TM 0x02
130#define UBX_TIM_TM2 0x03
131#define UBX_TIM_SVIN 0x04
132
133
134/* Header */
135struct ubx_hdr {
136 uint8_t sync[2];
137 uint8_t msg_class;
138 uint8_t msg_id;
139 uint16_t payload_len;
140} __attribute__((packed));
141
142
143/* Payload formats (some of them) */
144struct ubx_nav_posllh {
Dieter Spaarca9517f2012-07-18 22:13:17 +0200145 uint32_t itow; /* ms */
Sylvain Munaut341542b2009-12-22 21:53:22 +0100146 int32_t lon; /* scaling 1e-7 */
147 int32_t lat; /* scaling 1e-7 */
148 int32_t height;/* mm */
149 int32_t hsl; /* mm */
150 uint32_t hacc; /* mm */
151 uint32_t vacc; /* mm */
152} __attribute__((packed));
153
154struct ubx_aid_ini {
155 int32_t x;
156 int32_t y;
157 int32_t z;
158 uint32_t posacc;
159 uint16_t tm_cfg;
160 uint16_t wn;
Dieter Spaarca9517f2012-07-18 22:13:17 +0200161 uint32_t tow; /* ms */
Sylvain Munaut341542b2009-12-22 21:53:22 +0100162 int32_t tow_ns;
163 uint32_t tacc_ms;
164 uint32_t tacc_ns;
165 int32_t clkd;
166 uint32_t clkdacc;
167 uint32_t flags;
168} __attribute__((packed));
169
170struct ubx_aid_hui {
171 uint32_t health;
172 double utc_a1;
173 double utc_a0;
174 int32_t utc_tot;
175 int16_t utc_wnt;
176 int16_t utc_ls;
177 int16_t utc_wnf;
178 int16_t utc_dn;
179 int16_t utc_lsf;
180 int16_t utc_spare;
181 float klob_a0;
182 float klob_a1;
183 float klob_a2;
184 float klob_a3;
185 float klob_b0;
186 float klob_b1;
187 float klob_b2;
188 float klob_b3;
189 uint32_t flags;
190} __attribute__((packed));
191
192struct ubx_aid_alm {
193 uint32_t sv_id;
194 uint32_t gps_week;
195 uint32_t alm_words[8]; /* Present only if 'gps_week' != 0 */
196} __attribute__((packed));
197
198struct ubx_aid_eph {
199 uint32_t sv_id;
200 uint32_t present;
201 uint32_t eph_words[24]; /* Present only if 'present' != 0 */
202} __attribute__((packed));
203
Dieter Spaarfa325672012-07-18 22:14:01 +0200204struct ubx_nav_timegps {
205 uint32_t itow; /* ms */
206 int32_t ftow; /* ns */
207 int16_t week;
208 uint8_t leaps;
209 uint8_t valid;
210 uint32_t tacc; /* ns */
211} __attribute__((packed));
Sylvain Munaut341542b2009-12-22 21:53:22 +0100212
213/* Message handler */
214typedef void (*ubx_msg_handler_t)(
215 struct ubx_hdr *hdr, void *payload, int payload_len, void *userdata);
216
217struct ubx_dispatch_entry {
218 uint8_t msg_class;
219 uint8_t msg_id;
220 ubx_msg_handler_t handler;
221};
222
223#define UBX_DISPATCH(kls,id,hdl) { \
224 .msg_class = UBX_CLASS_ ## kls , \
225 .msg_id = UBX_ ## kls ## _ ## id, \
226 .handler = (hdl), \
227}
228
229
230/* Methods */
231int ubx_msg_dispatch(struct ubx_dispatch_entry *dt,
232 void *msg, int len, void *userdata);
233
234
235#ifdef __cplusplus
236}
237#endif
238
239#endif /* __UBX_H__ */
240