aboutsummaryrefslogtreecommitdiffstats
path: root/rrlp-ephemeris/ubx.h
blob: 8264386582288843e92e7f9183dbbcba57e755df (plain)
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
/*
 * ubx.h
 *
 * Header for UBX related stuff
 *
 *
 * Copyright (C) 2009  Sylvain Munaut <tnt@246tNt.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __UBX_H__
#define __UBX_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

/* Constants used in UBX */

	/* Sync bytes (two first bytes of each message) */
#define UBX_SYNC0		0xb5
#define UBX_SYNC1		0x62

	/* UBX messages classes */
#define UBX_CLASS_NAV		0x01
#define UBX_CLASS_RXM		0x02
#define UBX_CLASS_INF		0x04
#define UBX_CLASS_ACK		0x05
#define UBX_CLASS_CFG		0x06
#define UBX_CLASS_UPD		0x09
#define UBX_CLASS_MON		0x0a
#define UBX_CLASS_AID		0x0b
#define UBX_CLASS_TIM		0x0d

	/* UBX messages type ID (by class) */
#define UBX_NAV_POSECEF		0x01
#define UBX_NAV_POSLLH		0x02
#define UBX_NAV_STATUS		0x03
#define UBX_NAV_DOP		0x04
#define UBX_NAV_SOL		0x06
#define UBX_NAV_POSUTM		0x08
#define UBX_NAV_VELECEF		0x11
#define UBX_NAV_VELNED		0x12
#define UBX_NAV_TIMEGPS		0x20
#define UBX_NAV_TIMEUTC		0x21
#define UBX_NAV_CLOCK		0x22
#define UBX_NAV_SVINFO		0x30
#define UBX_NAV_DGPS		0x31
#define UBX_NAV_SBAS		0x32
#define UBX_NAV_EKFSTATUS	0x40

#define UBX_RXM_RAW		0x10
#define UBX_RXM_SFRB		0x11
#define UBX_RXM_SVSI		0x20
#define UBX_RXM_SVSI_GPS	0x20
#define UBX_RXM_ALM		0x30
#define UBX_RXM_EPH		0x31
#define UBX_RXM_POSREQ		0x40

#define UBX_INF_ERROR		0x00
#define UBX_INF_WARNING		0x01
#define UBX_INF_NOTICE		0x02
#define UBX_INF_TEST		0x03
#define UBX_INF_DEBUG		0x04
#define UBX_INF_USER		0x07

#define UBX_ACK_NAK		0x00
#define UBX_ACK_ACK		0x01

#define UBX_CFG_PRT		0x00
#define UBX_CFG_USB		0x1b
#define UBX_CFG_MSG		0x01
#define UBX_CFG_NMEA		0x17
#define UBX_CFG_RATE		0x08
#define UBX_CFG_CFG		0x09
#define UBX_CFG_TP		0x07
#define UBX_CFG_NAV2		0x1a
#define UBX_CFG_DAT		0x06
#define UBX_CFG_INF		0x02
#define UBX_CFG_RST		0x04
#define UBX_CFG_RXM		0x11
#define UBX_CFG_ANT		0x13
#define UBX_CFG_FXN		0x0e
#define UBX_CFG_SBAS		0x16
#define UBX_CFG_LIC		0x80
#define UBX_CFG_TM		0x10
#define UBX_CFG_TM2		0x19
#define UBX_CFG_TMODE		0x1d
#define UBX_CFG_EKF		0x12

#define UBX_UPD_DOWNL		0x01
#define UBX_UPD_UPLOAD		0x02
#define UBX_UPD_EXEC		0x03
#define UBX_UPD_MEMCPY		0x04

#define UBX_MON_SCHD		0x01
#define UBX_MON_IO		0x02
#define UBX_MON_IPC		0x03
#define UBX_MON_VER		0x04
#define UBX_MON_EXCEPT		0x05
#define UBX_MON_MSGPP		0x06
#define UBX_MON_RXBUF		0x07
#define UBX_MON_TXBUF		0x08
#define UBX_MON_HW		0x09
#define UBX_MON_USB		0x0a

#define UBX_AID_REQ		0x00
#define UBX_AID_INI		0x01
#define UBX_AID_HUI		0x02
#define UBX_AID_DATA		0x10
#define UBX_AID_ALM		0x30
#define UBX_AID_EPH		0x31

#define UBX_TIM_TP		0x01
#define UBX_TIM_TM		0x02
#define UBX_TIM_TM2		0x03
#define UBX_TIM_SVIN		0x04


/* Header */
struct ubx_hdr {
        uint8_t  sync[2];
        uint8_t  msg_class;
        uint8_t  msg_id;
        uint16_t payload_len;
} __attribute__((packed));


/* Payload formats (some of them) */
struct ubx_nav_posllh {
	uint32_t itow;
	int32_t  lon;	/* scaling 1e-7 */
	int32_t  lat;	/* scaling 1e-7 */
	int32_t  height;/* mm */
	int32_t  hsl;	/* mm */
	uint32_t hacc;	/* mm */
	uint32_t vacc;	/* mm */
} __attribute__((packed));

struct ubx_aid_ini {
	int32_t  x;
	int32_t  y;
	int32_t  z;
	uint32_t posacc;
	uint16_t tm_cfg;
	uint16_t wn;
	uint32_t tow;
	int32_t  tow_ns;
	uint32_t tacc_ms;
	uint32_t tacc_ns;
	int32_t  clkd;
	uint32_t clkdacc;
	uint32_t flags;
} __attribute__((packed));

struct ubx_aid_hui {
	uint32_t health;
	double   utc_a1;
	double   utc_a0;
	int32_t  utc_tot;
	int16_t  utc_wnt;
	int16_t  utc_ls;
	int16_t  utc_wnf;
	int16_t  utc_dn;
	int16_t  utc_lsf;
	int16_t  utc_spare;
	float    klob_a0;
	float    klob_a1;
	float    klob_a2;
	float    klob_a3;
	float    klob_b0;
	float    klob_b1;
	float    klob_b2;
	float    klob_b3;
	uint32_t flags;
} __attribute__((packed));

struct ubx_aid_alm {
	uint32_t sv_id;
	uint32_t gps_week;
	uint32_t alm_words[8];	/* Present only if 'gps_week' != 0 */
} __attribute__((packed));

struct ubx_aid_eph {
	uint32_t sv_id;
	uint32_t present;
	uint32_t eph_words[24];	/* Present only if 'present' != 0 */
} __attribute__((packed));


/* Message handler */
typedef void (*ubx_msg_handler_t)(
	struct ubx_hdr *hdr, void *payload, int payload_len, void *userdata);

struct ubx_dispatch_entry {
	uint8_t msg_class;
	uint8_t msg_id;
	ubx_msg_handler_t handler;
};

#define UBX_DISPATCH(kls,id,hdl) {		\
	.msg_class = UBX_CLASS_ ## kls ,	\
	.msg_id = UBX_ ## kls ## _ ## id,	\
	.handler = (hdl),			\
}


/* Methods */
int ubx_msg_dispatch(struct ubx_dispatch_entry *dt,
                     void *msg, int len, void *userdata);


#ifdef __cplusplus
}
#endif

#endif /* __UBX_H__ */