1 // -*- coding: utf-8 -*-
4 // This file is part of ruwai.
6 // If you use ruwai in any program or publication, please inform and
7 // acknowledge its author Stefan Mertl (stefan@mertl-research.at).
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
27 // Used to pack the structures to remove eventual byte overhead.
29 #define PACKED __attribute__((packed))
33 #define SYNC_CHAR_1 0xB5
34 #define SYNC_CHAR_2 0x62
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
{
54 UBX_CLASSS_AID
= 0x0B,
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,
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
74 //! The UBX ACK class message IDs.
75 typedef enum ack_msg_id_e
{
76 UBX_ACK_ID_NAK
= 0x00,
80 //! The UBX TIM class message IDs.
81 typedef enum tim_msg_id_e
{
85 //! The NMEA class IDs.
86 typedef enum nmea_msg_class_e
{
87 NMEA_CLASS_STD
= 0xF0,
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
109 //! The UBX paket header.
110 typedef struct PACKED ubx_header_s
{
115 uint16_t payload_length
;
118 //! The UBX CFG-MSG poll message.
119 typedef struct PACKED ubx_cfg_msg_rate_poll_s
{
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
{
129 } ubx_cfg_msg_rate_t
;
131 //! The UBX CFG-TP5 poll message.
132 typedef struct PACKED ubx_cfg_tp5_poll_s
{
134 } ubx_cfg_tp5_poll_t
;
137 // The UBX CFG-TP5 flags bitfield.
138 typedef struct PACKED ubx_cfg_tp5_flags_s
{
140 uint8_t lock_gps_freq
: 1;
141 uint8_t locked_other_set
: 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
{
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
;
167 //! The UBX CFG-PRT txready bitfield.
168 typedef struct PACKED ubx_cfg_prt_txready_s
{
173 } ubx_cfg_prt_txready_t
;
175 //! The UBX CFG-PRT mode bitfield.
176 typedef struct PACKED ubx_cfg_prt_mode_s
{
178 uint8_t reserved1
: 1;
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
{
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
{
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
{
207 ubx_cfg_prt_txready_t tx_ready
;
208 ubx_cfg_prt_mode_t mode
;
210 ubx_cfg_prt_inprotomask_t in_proto_mask
;
211 ubx_cfg_prt_outprotomask_t out_proto_mask
;
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;
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
{
243 ubx_nav_status_flags_t flags
;
244 ubx_nav_status_fixstat_t fix_stat
;
245 ubx_nav_status_flags2_t flags2
;
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
{
269 ubx_nav_timeutc_valid_t valid
;
273 //! The UBX NAV-POSLLH message.
274 typedef struct PACKED ubx_nav_posllh_s
{
285 //! The UBX TIM-TP flags bitfield.
286 typedef struct PACKED ubx_tim_tp_flags_s
{
287 uint8_t time_base
: 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
{
298 ubx_tim_tp_flags_t flags
;
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
{
318 uint16_t noise_per_ms
;
322 ubx_mon_hw_flags_t flags
;
334 //! The UBX ACK-ACK message.
335 typedef struct PACKED ubx_ack_ack_s
{
341 // The UBX CFG-INF target_mask bitfiedl.
342 typedef struct PACKED ubx_cfg_inf_target_mask_s
{
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
{
366 ubx_cfg_inf_inf_msg_mask_t inf_msg_mask
;