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_4072 0x72
38 #define RTCM3_MSG_1230 0xE6
39 #define RTCM3_MSG_1087 0xBB
42 #if PRINT_DEBUG_GPS_UBX
43 #define DEBUG_PRINT(...) printf(__VA_ARGS__)
45 #define DEBUG_PRINT(...) {}
49 #include "ubx_protocol.h"
60 #define GOT_CHECKSUM1 8
62 #define RXM_RTCM_VERSION 0x02
63 #define NAV_RELPOSNED_VERSION 0x00
65 #define GPS_UBX_ERR_NONE 0
66 #define GPS_UBX_ERR_OVERRUN 1
67 #define GPS_UBX_ERR_MSG_TOO_LONG 2
68 #define GPS_UBX_ERR_CHECKSUM 3
69 #define GPS_UBX_ERR_UNEXPECTED 4
70 #define GPS_UBX_ERR_OUT_OF_SYNC 5
72 #define UTM_HEM_NORTH 0
73 #define UTM_HEM_SOUTH 1
77 #if USE_GPS_UBX_RXM_RAW
78 struct GpsUbxRaw gps_ubx_raw;
85 #ifndef INJECT_BUFF_SIZE
86 #define INJECT_BUFF_SIZE 512
94 struct rtcm_t rtcm = { 0 };
110 struct link_device *
dev = &((UBX_GPS_LINK).device);
112 while (dev->char_available(dev->periph)) {
125 uint8_t gnssFixOK = bit_is_set(flags, 0);
126 uint8_t diffSoln = bit_is_set(flags, 1);
127 uint8_t carrSoln = (flags & 0xC0) >> 6;
157 uint8_t headVehValid = bit_is_set(flags, 5);
189 #if !USE_GPS_UBX_RTCM
341 #if !USE_GPS_UBX_RTCM
388 #if USE_GPS_UBX_RXM_RAW
394 for (i = 0; i < max_SV; i++) {
395 gps_ubx_raw.measures[i].cpMes = UBX_RXM_RAW_cpMes(
gps_ubx.
msg_buf, i);
396 gps_ubx_raw.measures[i].prMes = UBX_RXM_RAW_prMes(
gps_ubx.
msg_buf, i);
397 gps_ubx_raw.measures[i].doMes = UBX_RXM_RAW_doMes(
gps_ubx.
msg_buf, i);
399 gps_ubx_raw.measures[i].mesQI = UBX_RXM_RAW_mesQI(
gps_ubx.
msg_buf, i);
400 gps_ubx_raw.measures[i].cno = UBX_RXM_RAW_cno(
gps_ubx.
msg_buf, i);
401 gps_ubx_raw.measures[i].lli = UBX_RXM_RAW_lli(
gps_ubx.
msg_buf, i);
403 #endif // USE_GPS_UBX_RXM_RAW
438 DEBUG_PRINT(
"Unknown RXM_RTCM version: %i\n", version);
440 #endif // USE_GPS_UBX_RTCM
448 case UBX_NAV_POSECEF_ID:
451 case UBX_NAV_POSLLH_ID:
454 case UBX_NAV_STATUS_ID:
463 case UBX_NAV_POSUTM_ID:
466 case UBX_NAV_VELECEF_ID:
469 case UBX_NAV_VELNED_ID:
472 case UBX_NAV_SVINFO_ID:
478 case UBX_NAV_RELPOSNED_ID:
490 case UBX_RXM_RTCM_ID:
516 if (c == UBX_SYNC1) {
521 if (c != UBX_SYNC2) {
591 dev->put_byte(dev->periph, 0, byte);
598 dev->put_byte(dev->periph, 0, UBX_SYNC1);
599 dev->put_byte(dev->periph, 0, UBX_SYNC2);
612 dev->send_message(dev->periph, 0);
618 for (i = 0; i < len; i++) {
626 UbxSend_CFG_RST(dev, bbr, reset_mode, 0x00);
630 #ifndef GPS_UBX_UCENTER
631 #define gps_ubx_ucenter_event() {}
674 for (i = 0; i < n; i++) {
675 dev->put_byte(dev->periph, 0, buff[i]);
677 dev->send_message(dev->periph, 0);
694 #ifdef GPS_UBX_UCENTER
702 for (i = 0; i < length; i++) {
703 if (rtcm.nbyte == 0) {
706 rtcm.buff[rtcm.nbyte++] = data[i];
710 if (rtcm.nbyte < INJECT_BUFF_SIZE) {
711 rtcm.buff[rtcm.nbyte++] = data[i];
712 if (rtcm.nbyte == 3) {
717 if (rtcm.nbyte == rtcm.len + 3) {
719 unsigned int crc1 =
crc24q(rtcm.buff, rtcm.len);
720 unsigned int crc2 =
RTCMgetbitu(rtcm.buff, rtcm.len * 8, 24);
731 default:
DEBUG_PRINT(
"Unknown type: %i", packet_id);
break;
734 DEBUG_PRINT(
"Skipping message %i (CRC failed) - %d", packet_id, rtcm.buff[0]);
736 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)
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)
static void gps_ubx_parse_nav_svinfo(void)
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.
#define GPS_VALID_VEL_NED_BIT
static void gps_ubx_parse_rxm_raw(void)
uint8_t valid_fields
bitfield indicating valid fields (GPS_VALID_x_BIT)
uint32_t hacc
horizontal accuracy in cm
UBX protocol specific code.
void gps_ubx_parse(uint8_t c)
Main include for ABI (AirBorneInterface).
uint32_t vacc
vertical accuracy in cm
static void gps_ubx_parse_nav_velned(void)
static void gps_ubx_parse_nav_relposned(void)
uint8_t msg_buf[GPS_UBX_MAX_PAYLOAD]
static void gps_ubx_parse_velecef(void)
int32_t east
in centimeters
static void gps_ubx_parse_nav_pvt(void)
uint8_t svid
Satellite ID.
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
static void gps_ubx_parse_nav_sat(void)
#define GPS_UBX_MAX_PAYLOAD
uint32_t sacc
speed accuracy in cm/s
#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.
static void gps_ubx_parse_nav_sol(void)
#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)
static void gps_ubx_parse_nav_status(void)
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
uint16_t gps_week_number(uint16_t year, uint8_t month, uint8_t day)
Number of weeks since navigation epoch (6 January 1980)
static void gps_ubx_parse_nav_posutm(void)
#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
static void gps_ubx_parse_nav_posllh(void)
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
static void gps_ubx_parse_rxm_rtcm(void)
#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
#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)
static void gps_ubx_parse_nav_posecef(void)
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