27 #ifndef USE_GPS_UBX_RTCM
28 #define USE_GPS_UBX_RTCM 0
34 #define RTCM3_PREAMBLE 0xD3
35 #define RTCM3_MSG_1005 0x69
36 #define RTCM3_MSG_1077 0xB1
37 #define RTCM3_MSG_1087 0xBB
40 #if PRINT_DEBUG_GPS_UBX
41 #define DEBUG_PRINT(...) printf(__VA_ARGS__)
43 #define DEBUG_PRINT(...) {}
47 #include "ubx_protocol.h"
58 #define GOT_CHECKSUM1 8
60 #define RXM_RTCM_VERSION 0x02
61 #define NAV_RELPOSNED_VERSION 0x00
63 #define GPS_UBX_ERR_NONE 0
64 #define GPS_UBX_ERR_OVERRUN 1
65 #define GPS_UBX_ERR_MSG_TOO_LONG 2
66 #define GPS_UBX_ERR_CHECKSUM 3
67 #define GPS_UBX_ERR_UNEXPECTED 4
68 #define GPS_UBX_ERR_OUT_OF_SYNC 5
70 #define UTM_HEM_NORTH 0
71 #define UTM_HEM_SOUTH 1
75 #if USE_GPS_UBX_RXM_RAW
76 struct GpsUbxRaw gps_ubx_raw;
83 #ifndef INJECT_BUFF_SIZE
84 #define INJECT_BUFF_SIZE 512
92 struct rtcm_t rtcm = { 0 };
111 struct link_device *
dev = &((UBX_GPS_LINK).device);
113 while (dev->char_available(dev->periph)) {
132 #if ! USE_GPS_UBX_RTCM
201 #if !USE_GPS_UBX_RTCM
242 #endif // USE_GPS_UBX_RTCM
246 #if USE_GPS_UBX_RXM_RAW
252 for (i = 0; i < max_SV; i++) {
253 gps_ubx_raw.measures[i].cpMes = UBX_RXM_RAW_cpMes(
gps_ubx.
msg_buf, i);
254 gps_ubx_raw.measures[i].prMes = UBX_RXM_RAW_prMes(
gps_ubx.
msg_buf, i);
255 gps_ubx_raw.measures[i].doMes = UBX_RXM_RAW_doMes(
gps_ubx.
msg_buf, i);
257 gps_ubx_raw.measures[i].mesQI = UBX_RXM_RAW_mesQI(
gps_ubx.
msg_buf, i);
258 gps_ubx_raw.measures[i].cno = UBX_RXM_RAW_cno(
gps_ubx.
msg_buf, i);
259 gps_ubx_raw.measures[i].lli = UBX_RXM_RAW_lli(
gps_ubx.
msg_buf, i);
261 #endif // USE_GPS_UBX_RXM_RAW
293 DEBUG_PRINT(
"Unknown RXM_RTCM version: %i\n", version);
295 #endif // USE_GPS_UBX_RTCM
316 if (c == UBX_SYNC1) {
321 if (c != UBX_SYNC2) {
391 dev->put_byte(dev->periph, 0, byte);
398 dev->put_byte(dev->periph, 0, UBX_SYNC1);
399 dev->put_byte(dev->periph, 0, UBX_SYNC2);
412 dev->send_message(dev->periph, 0);
418 for (i = 0; i < len; i++) {
426 UbxSend_CFG_RST(dev, bbr, reset_mode, 0x00);
430 #ifndef GPS_UBX_UCENTER
431 #define gps_ubx_ucenter_event() {}
466 for (i = 0; i < n; i++) {
467 dev->put_byte(dev->periph, 0, buff[i]);
469 dev->send_message(dev->periph, 0);
486 #ifdef GPS_UBX_UCENTER
494 for (i = 0; i < length; i++) {
495 if (rtcm.nbyte == 0) {
498 rtcm.buff[rtcm.nbyte++] = data[i];
502 if (rtcm.nbyte < INJECT_BUFF_SIZE) {
503 rtcm.buff[rtcm.nbyte++] = data[i];
504 if (rtcm.nbyte == 3) {
509 if (rtcm.nbyte == rtcm.len + 3) {
511 unsigned int crc1 =
crc24q(rtcm.buff, rtcm.len);
512 unsigned int crc2 =
RTCMgetbitu(rtcm.buff, rtcm.len * 8, 24);
521 default:
DEBUG_PRINT(
"Unknown type: %i", packet_id);
break;
524 DEBUG_PRINT(
"Skipping message %i (CRC failed) - %d", packet_id, rtcm.buff[0]);
526 for (j = 1; j < rtcm.len; j++) {
uint8_t qi
quality bitfield (GPS receiver specific)
unsigned int RTCMgetbitu(unsigned char *buff, int pos, int lenb)
uint32_t t0_tow
GPS time of week in ms from last message.
int32_t north
in centimeters
struct SVinfo svinfos[GPS_NB_CHANNELS]
holds information from the Space Vehicles (Satellites)
int16_t azim
azimuth in deg
uint32_t pacc
position accuracy in cm
void ubx_trailer(struct link_device *dev)
void ubx_send_bytes(struct link_device *dev, uint8_t len, uint8_t *bytes)
#define gps_ubx_ucenter_event()
uint8_t nb_channels
Number of scanned satellites.
uint32_t t0_ticks
hw clock ticks when GPS message is received
#define GPS_VALID_VEL_NED_BIT
uint8_t valid_fields
bitfield indicating valid fields (GPS_VALID_x_BIT)
UBX protocol specific code.
void gps_ubx_parse(uint8_t c)
Main include for ABI (AirBorneInterface).
uint8_t msg_buf[GPS_UBX_MAX_PAYLOAD]
int32_t east
in centimeters
uint8_t svid
Satellite ID.
volatile uint32_t nb_tick
SYS_TIME_TICKS since startup.
uint16_t speed_3d
norm of 3d speed in cm/s
#define GPS_FIX_3D
3D GPS fix
struct UtmCoor_i utm_pos
position in UTM (north,east: cm; alt: mm over MSL)
static void ubx_send_1byte(struct link_device *dev, uint8_t byte)
#define GPS_UBX_ERR_OUT_OF_SYNC
uint32_t last_3dfix_ticks
cpu time ticks at last valid 3D fix
int8_t elev
elevation in deg
int32_t alt
in millimeters above WGS84 reference ellipsoid
#define GPS_UBX_MAX_PAYLOAD
uint32_t sacc
speed accuracy in cm/s
struct GpsTimeSync gps_ubx_time_sync
#define NAV_RELPOSNED_VERSION
uint32_t last_msg_time
cpu time in sec at last received GPS message
uint32_t cacc
course accuracy in rad*1e7
uint8_t zone
UTM zone number.
#define GPS_VALID_COURSE_BIT
#define GPS_UBX_ERR_UNEXPECTED
int32_t hmsl
height above mean sea level (MSL) in mm
uint8_t cno
Carrier to Noise Ratio (Signal Strength) in dbHz.
uint32_t tow
GPS time of week in ms.
unsigned int crc24q(const unsigned char *buff, int len)
void gps_ublox_write(struct link_device *dev, uint8_t *buff, uint32_t n)
uint16_t pdop
position dilution of precision scaled by 100
void ubx_header(struct link_device *dev, uint8_t nav_id, uint8_t msg_id, uint16_t len)
#define GPS_UBX_NB_CHANNELS
struct EcefCoor_i ecef_pos
position in ECEF in cm
void ubx_send_cfg_rst(struct link_device *dev, uint16_t bbr, uint8_t reset_mode)
#define GPS_VALID_HMSL_BIT
int32_t lon
in degrees*1e7
#define GPS_UBX_ERR_MSG_TOO_LONG
volatile uint32_t nb_sec_rem
remainder of seconds since startup in CPU_TICKS
struct GpsRelposNED gps_relposned
static const struct usb_device_descriptor dev
void gps_ubx_read_message(void)
int gps_ubx_ucenter_get_status(void)
uint32_t last_3dfix_time
cpu time in sec at last valid 3D fix
int32_t alt
in millimeters (above WGS84 reference ellipsoid or above MSL)
#define GPS_UBX_ERR_OVERRUN
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
uint8_t comp_id
id of current gps
volatile uint32_t nb_sec
full seconds since startup
int32_t t0_tow_frac
fractional ns remainder of tow [ms], range -500000 .. 500000
#define GPS_VALID_POS_ECEF_BIT
data structures for GPS with RTK capabilities
uint8_t flags
bitfield with GPS receiver specific flags
uint32_t last_msg_ticks
cpu time ticks at last received GPS message
#define GPS_VALID_POS_LLA_BIT
uint8_t num_sv
number of sat in fix
arch independent LED (Light Emitting Diodes) API
#define UNINIT
Includes macros generated from ubx.xml.
uint16_t gspeed
norm of 2d ground speed in cm/s
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
data structure for GPS time sync
#define GPS_VALID_VEL_ECEF_BIT
void gps_inject_data(uint8_t packet_id, uint8_t length, uint8_t *data)
Override the default GPS packet injector to inject the data trough UART.
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
int32_t lat
in degrees*1e7
#define GPS_VALID_POS_UTM_BIT
struct NedCoor_i ned_vel
speed NED in cm/s
uint8_t buff[25]
Buffer used for general comunication over SPI (in buffer)
#define GPS_UBX_ERR_CHECKSUM