Enable the usb interface during when creating the GPS.
[ruwai.git] / software / arduino / libraries / gps_ublox / ubx_protocol.h
blobb4f6ec37bf026a004cb2a4e62794a4d7789b49bd
1 // -*- coding: utf-8 -*-
2 // LICENSE
3 //
4 // This file is part of ruwai.
5 //
6 // If you use ruwai in any program or publication, please inform and
7 // acknowledge its author Stefan Mertl (stefan@mertl-research.at).
8 //
9 // pSysmon 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 3 of the License, or
12 // (at your option) any later version.
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.
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/>.
22 #ifndef ubloxprotocol_h
23 #define ubloxprotocol_h
25 #include <Arduino.h>
27 // Used to pack the structures to remove eventual byte overhead.
28 #ifndef PACKED
29 #define PACKED __attribute__((packed))
30 #endif
33 #define SYNC_CHAR_1 0xB5
34 #define SYNC_CHAR_2 0x62
36 #define TIMEPULSE 0
37 #define TIMEPULSE2 1
39 #define UBX_CFG_TP5_SCALING 4294967296
42 /*! Compute the checksum values of a UBX paket. */
43 void update_ubx_checksum(uint8_t* payload, uint8_t length, uint8_t &ck_a, uint8_t &ck_b);
46 //! The UBX class IDs.
47 typedef enum ubx_msg_class_e {
48 UBX_CLASS_NAV = 0x01,
49 UBX_CLASS_RXM = 0x02,
50 UBX_CLASS_INF = 0x04,
51 UBX_CLASS_ACK = 0x05,
52 UBX_CLASS_CFG = 0x06,
53 UBX_CLASS_MON = 0x0A,
54 UBX_CLASSS_AID = 0x0B,
55 UBX_CLASS_TIM = 0x0D,
56 UBX_CLASS_ESF = 0x10
57 } ubx_msg_class_t;
59 //! The UBX CFG class message IDs.
60 typedef enum cfg_msg_id_e {
61 UBX_CFG_ID_PRT = 0x00,
62 UBX_CFG_ID_MSG = 0x01,
63 UBX_CFG_ID_INF = 0x02,
64 UBX_CFG_ID_TP5 = 0x31
65 } cfg_msg_id_t;
67 //! The UBX NAV class message IDs.
68 typedef enum nav_msg_id_e {
69 UBX_NAV_ID_POSLLH = 0x02,
70 UBX_NAV_ID_STATUS = 0x03,
71 UBX_NAV_ID_TIMEUTC = 0x21
72 } nav_msg_id_t;
74 //! The UBX ACK class message IDs.
75 typedef enum ack_msg_id_e {
76 UBX_ACK_ID_NAK = 0x00,
77 UBX_ACK_ID_ACK = 0x01
78 } ack_msg_id_t;
80 //! The UBX TIM class message IDs.
81 typedef enum tim_msg_id_e {
82 UBX_TIM_ID_TP = 0x01
83 } tim_msg_id_t;
85 //! The NMEA class IDs.
86 typedef enum nmea_msg_class_e {
87 NMEA_CLASS_STD = 0xF0,
88 NMEA_CLASS_UBX = 0xF1
89 } nmea_msg_class_t;
91 //! The NMEA message IDs.
92 typedef enum nmea_std_msg_id_e {
93 NMEA_STD_ID_DTM = 0x0A,
94 NMEA_STD_ID_GBS = 0x09,
95 NMEA_STD_ID_GGA = 0x00,
96 NMEA_STD_ID_GLL = 0x01,
97 NMEA_STD_ID_GPQ = 0x40,
98 NMEA_STD_ID_GRS = 0x06,
99 NMEA_STD_ID_GSA = 0x02,
100 NMEA_STD_ID_GST = 0x07,
101 NMEA_STD_ID_GSV = 0x03,
102 NMEA_STD_ID_RMC = 0x04,
103 NMEA_STD_ID_THS = 0x0E,
104 NMEA_STD_ID_TXT = 0x41,
105 NMEA_STD_ID_VTG = 0x05,
106 NMEA_STD_ID_ZDA = 0x08
107 } nmea_std_msg_id_t;
109 //! The UBX paket header.
110 typedef struct PACKED ubx_header_s {
111 uint8_t sync_char1;
112 uint8_t sync_char2;
113 uint8_t msg_class;
114 uint8_t msg_id;
115 uint16_t payload_length;
116 } ubx_header_t;
118 //! The UBX CFG-MSG poll message.
119 typedef struct PACKED ubx_cfg_msg_rate_poll_s {
120 uint8_t msg_class;
121 uint8_t msg_id;
122 } ubx_cfg_msg_rate_poll_t;
124 //! The UBX CFG-MSG set current target message.
125 typedef struct PACKED ubx_cfg_msg_rate_s {
126 uint8_t msg_class;
127 uint8_t msg_id;
128 uint8_t rate;
129 } ubx_cfg_msg_rate_t;
131 //! The UBX CFG-TP5 poll message.
132 typedef struct PACKED ubx_cfg_tp5_poll_s {
133 uint8_t tp_idx;
134 } ubx_cfg_tp5_poll_t;
137 // The UBX CFG-TP5 flags bitfield.
138 typedef struct PACKED ubx_cfg_tp5_flags_s {
139 uint8_t active : 1;
140 uint8_t lock_gps_freq : 1;
141 uint8_t locked_other_set : 1;
142 uint8_t is_freq : 1;
143 uint8_t is_length : 1;
144 uint8_t align_to_tow : 1;
145 uint8_t polarity : 1;
146 uint8_t grid_utc_gps : 1;
147 uint32_t reserved : 24;
148 } ubx_cfg_tp5_flags_t;
151 //! The UBX CFG-TP5 message.
152 typedef struct PACKED ubx_cfg_tp5_s {
153 uint8_t tp_idx;
154 uint8_t reserved0;
155 uint16_t reserved1;
156 int16_t ant_cable_delay;
157 int16_t rf_group_delay;
158 uint32_t freq_period;
159 uint32_t freq_period_lock;
160 uint32_t pulse_len_ratio;
161 uint32_t pulse_len_ratio_lock;
162 int32_t user_config_delay;
163 ubx_cfg_tp5_flags_t flags;
164 } ubx_cfg_tp5_t;
167 //! The UBX CFG-PRT txready bitfield.
168 typedef struct PACKED ubx_cfg_prt_txready_s {
169 uint8_t en : 1;
170 uint8_t pol : 1;
171 uint8_t pin : 5;
172 uint16_t thres : 9;
173 } ubx_cfg_prt_txready_t;
175 //! The UBX CFG-PRT mode bitfield.
176 typedef struct PACKED ubx_cfg_prt_mode_s {
177 uint8_t unused0 : 4;
178 uint8_t reserved1 : 1;
179 uint8_t unused1 : 1;
180 uint8_t charlen : 2;
181 uint8_t unused2 : 1;
182 uint8_t parity : 3;
183 uint8_t nstopbits : 2;
184 uint32_t unused3 : 18;
185 } ubx_cfg_prt_mode_t;
187 //! The UBX CFG-PRT inProtoMask bitfield.
188 typedef struct PACKED ubx_cfg_prt_inprotomask_s {
189 uint8_t ubx : 1;
190 uint8_t nmea : 1;
191 uint8_t rtcm : 1;
192 uint16_t unused0 : 13;
193 } ubx_cfg_prt_inprotomask_t;
195 //! The UBX CFG-PRT outProtoMask bitfield.
196 typedef struct PACKED ubx_cfg_prt_outprotomask_s {
197 uint8_t ubx : 1;
198 uint8_t nmea : 1;
199 uint8_t rtcm : 1;
200 uint16_t unused0 : 13;
201 } ubx_cfg_prt_outprotomask_t;
203 //! The UBX CFG-PRT message.
204 typedef struct PACKED ubx_cfg_prt_uart_s {
205 uint8_t prt_id;
206 uint8_t reserved0;
207 ubx_cfg_prt_txready_t tx_ready;
208 ubx_cfg_prt_mode_t mode;
209 uint32_t baud_rate;
210 ubx_cfg_prt_inprotomask_t in_proto_mask;
211 ubx_cfg_prt_outprotomask_t out_proto_mask;
212 uint16_t reserved4;
213 uint16_t reserved5;
214 } ubx_cfg_prt_uart_t;
217 //! The UBX NAV-STATUS flags bitfield.
218 typedef struct PACKED ubx_nav_status_flags_s {
219 uint8_t gps_fix_ok : 1;
220 uint8_t diff_so_in : 1;
221 uint8_t wkn_set : 1;
222 uint8_t tow_set : 1;
223 uint8_t reserved : 4;
224 } ubx_nav_status_flags_t;
226 //! THE UBX NAV-STATUS fixStat bitfield.
227 typedef struct PACKED ubx_nav_status_fixstat_s {
228 uint8_t dgps_i_stat : 1;
229 uint8_t reserved : 5;
230 uint8_t map_matching : 2;
231 } ubx_nav_status_fixstat_t;
233 //! The UBX NAV-STATUS flags2 bitfield.
234 typedef struct PACKED ubx_nav_status_flags2_s {
235 uint8_t psm_state : 2;
236 uint8_t reserved : 6;
237 } ubx_nav_status_flags2_t;
239 //! The UBX NAV-STATUS message.
240 typedef struct PACKED ubx_nav_status_s {
241 uint32_t i_tow;
242 uint8_t gps_fix;
243 ubx_nav_status_flags_t flags;
244 ubx_nav_status_fixstat_t fix_stat;
245 ubx_nav_status_flags2_t flags2;
246 uint32_t ttff;
247 uint32_t msss;
248 } ubx_nav_status_t;
250 //! The UBX NAV-TIMEUTC valid bitfield.
251 typedef struct PACKED ubx_nav_timeutc_valid_s {
252 uint8_t validtow : 1;
253 uint8_t validwkn : 1;
254 uint8_t validutc : 1;
255 } ubx_nav_timeutc_valid_t;
258 //! The UBX NAV-TIMEUTC message.
259 typedef struct PACKED ubx_nav_timeutc_s {
260 uint32_t i_tow;
261 uint32_t t_acc;
262 int32_t nano;
263 uint16_t year;
264 uint8_t month;
265 uint8_t day;
266 uint8_t hour;
267 uint8_t min;
268 uint8_t sec;
269 ubx_nav_timeutc_valid_t valid;
270 } ubx_nav_timeutc_t;
273 //! The UBX NAV-POSLLH message.
274 typedef struct PACKED ubx_nav_posllh_s {
275 uint32_t i_tow;
276 int32_t lon;
277 int32_t lat;
278 int32_t height;
279 int32_t h_msl;
280 uint32_t h_acc;
281 uint32_t v_acc;
282 } ubx_nav_posllh_t;
285 //! The UBX TIM-TP flags bitfield.
286 typedef struct PACKED ubx_tim_tp_flags_s {
287 uint8_t time_base : 1;
288 uint8_t utc : 1;
289 uint8_t reserved : 6;
290 } ubx_tim_tp_flags_t;
292 //! The UBX TIM-TP message.
293 typedef struct PACKED ubx_tim_tp_s {
294 uint32_t tow_ms;
295 uint32_t tow_sub_ms;
296 int32_t q_err;
297 uint16_t week;
298 ubx_tim_tp_flags_t flags;
299 uint8_t reserved1;
300 } ubx_tim_tp_t;
303 //! The UBX MON-HW flags bitfield.
304 typedef struct PACKED ubx_mon_hw_flags_s {
305 uint8_t rtccalib : 1;
306 uint8_t safeboot : 1;
307 uint8_t jamming_state: 2;
308 uint8_t reserved : 4;
309 } ubx_mon_hw_flags_t;
312 //! The UBX MON-HW message.
313 typedef struct PACKED ubx_mon_hw_s {
314 uint32_t pin_sel;
315 uint32_t pin_bank;
316 uint32_t pin_dir;
317 uint32_t pin_val;
318 uint16_t noise_per_ms;
319 uint16_t agc_cnt;
320 uint8_t a_status;
321 uint8_t a_power;
322 ubx_mon_hw_flags_t flags;
323 uint8_t reserved1;
324 uint32_t used_mask;
325 uint8_t vp[25];
326 uint8_t jam_ind;
327 uint16_t reserved3;
328 uint32_t pin_irq;
329 uint32_t pull_h;
330 uint32_t pull_l;
331 } ubx_mon_hw_t;
334 //! The UBX ACK-ACK message.
335 typedef struct PACKED ubx_ack_ack_s {
336 uint8_t cls_id;
337 uint8_t msg_id;
338 } ubx_ack_ack_t;
341 // The UBX CFG-INF target_mask bitfiedl.
342 typedef struct PACKED ubx_cfg_inf_target_mask_s {
343 uint8_t error : 1;
344 uint8_t warning : 1;
345 uint8_t notice : 1;
346 uint8_t debug : 1;
347 uint8_t test : 1;
348 uint8_t reserved : 3;
349 } ubx_cfg_inf_target_mask_t;
351 // The UBX CFG-INF inf_msg_mask bitfield.
352 typedef struct PACKED ubx_cfg_inf_inf_msg_mask_s {
353 ubx_cfg_inf_target_mask_t ddc;
354 ubx_cfg_inf_target_mask_t serial_1;
355 ubx_cfg_inf_target_mask_t serial_2;
356 ubx_cfg_inf_target_mask_t usb;
357 ubx_cfg_inf_target_mask_t spi;
358 ubx_cfg_inf_target_mask_t reserved;
359 } ubx_cfg_inf_inf_msg_mask_t;
361 //! The UBX CFG-INF message.
362 typedef struct PACKED ubx_cfg_inf_s {
363 uint8_t protocol_id;
364 uint8_t reserved_0;
365 uint8_t reserved_1;
366 ubx_cfg_inf_inf_msg_mask_t inf_msg_mask;
368 } ubx_cfg_inf_t;
369 #endif