2 * This file is part of INAV
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
23 #include "common/time.h"
29 #define GPS_CFG_CMD_TIMEOUT_MS 500
30 #define GPS_VERSION_RETRY_TIMES 3
31 #define MAX_UBLOX_PAYLOAD_SIZE 256
32 #define UBLOX_BUFFER_SIZE MAX_UBLOX_PAYLOAD_SIZE
33 #define UBLOX_SBAS_MESSAGE_LENGTH 16
34 #define GPS_CAPA_INTERVAL 5000
36 #define UBX_DYNMODEL_PEDESTRIAN 3
37 #define UBX_DYNMODEL_AUTOMOVITE 4
38 #define UBX_DYNMODEL_AIR_1G 6
39 #define UBX_DYNMODEL_AIR_2G 7
40 #define UBX_DYNMODEL_AIR_4G 8
42 #define UBX_FIXMODE_2D_ONLY 1
43 #define UBX_FIXMODE_3D_ONLY 2
44 #define UBX_FIXMODE_AUTO 3
46 #define UBX_VALID_GPS_DATE(valid) (valid & 1 << 0)
47 #define UBX_VALID_GPS_TIME(valid) (valid & 1 << 1)
48 #define UBX_VALID_GPS_DATE_TIME(valid) (UBX_VALID_GPS_DATE(valid) && UBX_VALID_GPS_TIME(valid))
50 #define UBX_HW_VERSION_UNKNOWN 0
51 #define UBX_HW_VERSION_UBLOX5 500
52 #define UBX_HW_VERSION_UBLOX6 600
53 #define UBX_HW_VERSION_UBLOX7 700
54 #define UBX_HW_VERSION_UBLOX8 800
55 #define UBX_HW_VERSION_UBLOX9 900
56 #define UBX_HW_VERSION_UBLOX10 1000
59 #define UBLOX_CFG_SIGNAL_SBAS_ENA 0x10310020 // U1
60 #define UBLOX_CFG_SIGNAL_SBAS_L1CA_ENA 0x10310005 // U1
62 #define UBLOX_CFG_SIGNAL_GAL_ENA 0x10310021 // U1
63 #define UBLOX_CFG_SIGNAL_GAL_E1_ENA 0x10310007 // U1
65 #define UBLOX_CFG_SIGNAL_BDS_ENA 0x10310022 // U1
66 #define UBLOX_CFG_SIGNAL_BDS_B1_ENA 0x1031000d // U1
67 #define UBLOX_CFG_SIGNAL_BDS_B1C_ENA 0x1031000f // U1 default off
69 #define UBLOX_CFG_QZSS_ENA 0x10310024 // U1
70 #define UBLOX_CFG_QZSS_L1CA_ENA 0x10310012 // U1
71 #define UBLOX_CFG_QZSS_L1S_ENA 0x10310014 // U1
73 #define UBLOX_CFG_GLO_ENA 0x10310025 // U1 default off - may conflict with other constelations
74 #define UBLOX_CFG_GLO_L1_ENA 0x10310018 // U1 default off
76 #define UBLOX_CFG_SBAS_PRNSCANMASK 0x50360006 // 0 = auto // X8
77 #define UBLOX_SBAS_ALL 0x0000000000000000 //Enable search for all SBAS PRNs
78 #define UBLOX_SBAS_PRN120 0x0000000000000001 //Enable search for SBAS PRN120
79 #define UBLOX_SBAS_PRN121 0x0000000000000002 //Enable search for SBAS PRN121
80 #define UBLOX_SBAS_PRN122 0x0000000000000004 //Enable search for SBAS PRN122
81 #define UBLOX_SBAS_PRN123 0x0000000000000008 //Enable search for SBAS PRN123
82 #define UBLOX_SBAS_PRN124 0x0000000000000010 //Enable search for SBAS PRN124
83 #define UBLOX_SBAS_PRN125 0x0000000000000020 //Enable search for SBAS PRN125
84 #define UBLOX_SBAS_PRN126 0x0000000000000040 //Enable search for SBAS PRN126
85 #define UBLOX_SBAS_PRN127 0x0000000000000080 //Enable search for SBAS PRN127
86 #define UBLOX_SBAS_PRN128 0x0000000000000100 //Enable search for SBAS PRN128
87 #define UBLOX_SBAS_PRN129 0x0000000000000200 //Enable search for SBAS PRN129
88 #define UBLOX_SBAS_PRN130 0x0000000000000400 //Enable search for SBAS PRN130
89 #define UBLOX_SBAS_PRN131 0x0000000000000800 //Enable search for SBAS PRN131
90 #define UBLOX_SBAS_PRN132 0x0000000000001000 //Enable search for SBAS PRN132
91 #define UBLOX_SBAS_PRN133 0x0000000000002000 //Enable search for SBAS PRN133
92 #define UBLOX_SBAS_PRN134 0x0000000000004000 //Enable search for SBAS PRN134
93 #define UBLOX_SBAS_PRN135 0x0000000000008000 //Enable search for SBAS PRN135
94 #define UBLOX_SBAS_PRN136 0x0000000000010000 //Enable search for SBAS PRN136
95 #define UBLOX_SBAS_PRN137 0x0000000000020000 //Enable search for SBAS PRN137
96 #define UBLOX_SBAS_PRN138 0x0000000000040000 //Enable search for SBAS PRN138
97 #define UBLOX_SBAS_PRN139 0x0000000000080000 //Enable search for SBAS PRN139
98 #define UBLOX_SBAS_PRN140 0x0000000000100000 //Enable search for SBAS PRN140
99 #define UBLOX_SBAS_PRN141 0x0000000000200000 //Enable search for SBAS PRN141
100 #define UBLOX_SBAS_PRN142 0x0000000000400000 //Enable search for SBAS PRN142
101 #define UBLOX_SBAS_PRN143 0x0000000000800000 //Enable search for SBAS PRN143
102 #define UBLOX_SBAS_PRN144 0x0000000001000000 //Enable search for SBAS PRN144
103 #define UBLOX_SBAS_PRN145 0x0000000002000000 //Enable search for SBAS PRN145
104 #define UBLOX_SBAS_PRN146 0x0000000004000000 //Enable search for SBAS PRN146
105 #define UBLOX_SBAS_PRN147 0x0000000008000000 //Enable search for SBAS PRN147
106 #define UBLOX_SBAS_PRN148 0x0000000010000000 //Enable search for SBAS PRN148
107 #define UBLOX_SBAS_PRN149 0x0000000020000000 //Enable search for SBAS PRN149
108 #define UBLOX_SBAS_PRN150 0x0000000040000000 //Enable search for SBAS PRN150
109 #define UBLOX_SBAS_PRN151 0x0000000080000000 //Enable search for SBAS PRN151
110 #define UBLOX_SBAS_PRN152 0x0000000100000000 //Enable search for SBAS PRN152
111 #define UBLOX_SBAS_PRN153 0x0000000200000000 //Enable search for SBAS PRN153
112 #define UBLOX_SBAS_PRN154 0x0000000400000000 //Enable search for SBAS PRN154
113 #define UBLOX_SBAS_PRN155 0x0000000800000000 //Enable search for SBAS PRN155
114 #define UBLOX_SBAS_PRN156 0x0000001000000000 //Enable search for SBAS PRN156
115 #define UBLOX_SBAS_PRN157 0x0000002000000000 //Enable search for SBAS PRN157
116 #define UBLOX_SBAS_PRN158 0x0000004000000000 //Enable search for SBAS PRN158
149 } ubx_gnss_element_t
;
155 uint8_t numConfigBlocks
;
156 ubx_gnss_element_t config
[0];
163 } __attribute__((packed
)) ubx_config_data_header_v0_t
;
170 } __attribute__((packed
)) ubx_config_data_header_v1_t
;
174 #define MAX_GNSS_SIZE_BYTES (sizeof(ubx_gnss_msg_t) + sizeof(ubx_gnss_element_t)*MAX_GNSS)
177 uint8_t bytes
[MAX_GNSS_SIZE_BYTES
]; // placeholder
196 } __attribute__((packed
)) ubx_config_data8_payload_t
;
199 #define MAX_CONFIG_SET_VAL_VALUES 32
203 ubx_config_data_header_v1_t configHeader
;
205 ubx_config_data8_payload_t payload
[0];
206 uint8_t buffer
[(MAX_CONFIG_SET_VAL_VALUES
* sizeof(ubx_config_data8_payload_t
)) + 2]; // 12 key/value pairs + 2 checksum bytes
208 } __attribute__((packed
)) ubx_config_data8_t
;
213 } __attribute__((packed
)) ubx_message
;
216 char swVersion
[30]; // Zero-terminated Software Version String
217 char hwVersion
[10]; // Zero-terminated Hardware Version String
221 uint32_t time
; // GPS msToW
224 int32_t altitude_ellipsoid
;
225 int32_t altitude_msl
;
226 uint32_t horizontal_accuracy
;
227 uint32_t vertical_accuracy
;
231 uint32_t time
; // GPS msToW
234 uint8_t differential_status
;
236 uint32_t time_to_first_fix
;
237 uint32_t uptime
; // milliseconds
249 uint32_t position_accuracy_3d
;
250 int32_t ecef_x_velocity
;
251 int32_t ecef_y_velocity
;
252 int32_t ecef_z_velocity
;
253 uint32_t speed_accuracy
;
254 uint16_t position_DOP
;
261 uint32_t time
; // GPS msToW
268 uint32_t speed_accuracy
;
269 uint32_t heading_accuracy
;
273 uint8_t chn
; // Channel number, 255 for SVx not assigned to channel
274 uint8_t svid
; // Satellite ID
275 uint8_t flags
; // Bitmask
276 uint8_t quality
; // Bitfield
277 uint8_t cno
; // Carrier to Noise Ratio (Signal Strength) // dbHz, 0-55.
278 uint8_t elev
; // Elevation in integer degrees
279 int16_t azim
; // Azimuth in integer degrees
280 int32_t prRes
; // Pseudo range residual in centimetres
281 } ubx_nav_svinfo_channel
;
284 uint32_t time
; // GPS Millisecond time of week
285 uint8_t numCh
; // Number of channels
286 uint8_t globalFlags
; // Bitmask, Chip hardware generation 0:Antaris, 1:u-blox 5, 2:u-blox 6
287 uint16_t reserved2
; // Reserved
288 ubx_nav_svinfo_channel channel
[16]; // 16 satellites * 12 byte
292 uint32_t time
; // GPS msToW
305 uint32_t time
; // GPS msToW
321 int32_t altitude_ellipsoid
;
322 int32_t altitude_msl
;
323 uint32_t horizontal_accuracy
;
324 uint32_t vertical_accuracy
;
330 uint32_t speed_accuracy
;
331 uint32_t heading_accuracy
;
332 uint16_t position_DOP
;
337 #define UBX_MON_GNSS_GPS_MASK (1 << 0)
338 #define UBX_MON_GNSS_GLONASS_MASK (1 << 1)
339 #define UBX_MON_GNSS_BEIDOU_MASK (1 << 2)
340 #define UBX_MON_GNSS_GALILEO_MASK (1 << 3)
344 uint8_t supported
; // bitfield for GNSS types: 0:GPS, 1:Glonass, 2:Beidou, 3:Galileo
345 uint8_t defaultGnss
; // bitfield for GNSS types: 0:GPS, 1:Glonass, 2:Beidou, 3:Galileo
346 uint8_t enabled
; // bitfield for GNSS types: 0:GPS, 1:Glonass, 2:Beidou, 3:Galileo
347 uint8_t maxConcurrent
;
371 MSG_CLASS_UBX
= 0x01,
372 MSG_CLASS_NMEA
= 0xF0,
393 MSG_CFG_SET_RATE
= 0x01,
394 MSG_CFG_NAV_SETTINGS
= 0x24,
398 } ubx_protocol_bytes_t
;
402 FIX_DEAD_RECKONING
= 1,
405 FIX_GPS_DEAD_RECKONING
= 4,
407 } ubs_nav_fix_type_t
;
410 NAV_STATUS_FIX_VALID
= 1
411 } ubx_nav_status_bits_t
;
413 uint8_t gpsUbloxMaxGnss(void);
414 timeMs_t
gpsUbloxCapLastUpdate(void);
416 bool gpsUbloxHasGalileo(void);
417 bool gpsUbloxHasBeidou(void);
418 bool gpsUbloxHasGlonass(void);
420 bool gpsUbloxGalileoDefault(void);
421 bool gpsUbloxBeidouDefault(void);
422 bool gpsUbloxGlonassDefault(void);
424 bool gpsUbloxGalileoEnabled(void);
425 bool gpsUbloxBeidouEnabled(void);
426 bool gpsUbloxGlonassEnabled(void);