25 #include "pprzlink/dl_protocol.h"
28 #ifndef USE_GPS_UBX_RTCM
29 #define USE_GPS_UBX_RTCM 0
35 #define RTCM3_PREAMBLE 0xD3
36 #define RTCM3_MSG_1005 0x69
37 #define RTCM3_MSG_1077 0xB1
38 #define RTCM3_MSG_4072 0x72
39 #define RTCM3_MSG_1230 0xE6
40 #define RTCM3_MSG_1087 0xBB
43 #if PRINT_DEBUG_GPS_UBX
44 #define DEBUG_PRINT(...) printf(__VA_ARGS__)
46 #define DEBUG_PRINT(...) {}
50 #include "ubx_protocol.h"
61 #define GOT_CHECKSUM1 8
63 #define RXM_RTCM_VERSION 0x02
64 #define NAV_RELPOSNED_VERSION 0x01
66 #define GPS_UBX_ERR_NONE 0
67 #define GPS_UBX_ERR_OVERRUN 1
68 #define GPS_UBX_ERR_MSG_TOO_LONG 2
69 #define GPS_UBX_ERR_CHECKSUM 3
70 #define GPS_UBX_ERR_UNEXPECTED 4
71 #define GPS_UBX_ERR_OUT_OF_SYNC 5
73 #define UTM_HEM_NORTH 0
74 #define UTM_HEM_SOUTH 1
83 extern struct RtcmMan rtcm_man;
85 #ifndef INJECT_BUFF_SIZE
86 #define INJECT_BUFF_SIZE 1024 + 6
95 struct rtcm_t rtcm = { 0 };
102 #ifndef GPS_UBX_BOOTRESET
103 #define GPS_UBX_BOOTRESET 0
106 #define CFG_RST_Reset_Hardware 0x00
107 #define CFG_RST_Reset_Controlled 0x01
108 #define CFG_RST_Reset_Controlled_GPS_only 0x02
109 #define CFG_RST_Reset_Controlled_GPS_stop 0x08
110 #define CFG_RST_Reset_Controlled_GPS_start 0x09
112 #define CFG_RST_BBR_Hotstart 0x0000
113 #define CFG_RST_BBR_Warmstart 0x0001
114 #define CFG_RST_BBR_Coldstart 0xffff
144 while (
dev->char_available(
dev->periph)) {
146 if (
gps_ubx[i].msg_available) {
168 if (
gps_ubx[0].msg_available) {
174 uint8_t l = DL_HITL_UBX_ubx_payload_length(buf);
175 uint8_t *ubx_payload = DL_HITL_UBX_ubx_payload(buf);
176 memcpy(
gps_ubx[0].msg_buf, ubx_payload, l);
186 uint8_t gnssFixOK = bit_is_set(flags, 0);
187 uint8_t diffSoln = bit_is_set(flags, 1);
188 uint8_t carrSoln = (flags & 0xC0) >> 6;
189 if (diffSoln && carrSoln == 2) {
191 }
else if(diffSoln && carrSoln == 1) {
193 }
else if(gnssFixOK) {
219 gubx->
state.
cacc = (RadOfDeg(UBX_NAV_PVT_headAcc(gubx->
msg_buf) * 10)) * 10;
355 gubx->
state.
cacc = (RadOfDeg(UBX_NAV_VELNED_cAcc(gubx->
msg_buf) * 10)) * 10;
427 if (diffSoln && carrSoln == 2) {
429 }
else if(diffSoln && carrSoln == 1) {
431 }
else if(gnssFixOK) {
470 case UBX_NAV_POSECEF_ID:
473 case UBX_NAV_POSLLH_ID:
476 case UBX_NAV_STATUS_ID:
485 case UBX_NAV_POSUTM_ID:
488 case UBX_NAV_VELECEF_ID:
491 case UBX_NAV_VELNED_ID:
494 case UBX_NAV_SVINFO_ID:
500 case UBX_NAV_RELPOSNED_ID:
507 else if (gubx->
msg_class == UBX_RXM_ID) {
535 if (c == UBX_SYNC1) {
540 if (c != UBX_SYNC2) {
566 gubx->
len |= (c << 8);
582 if (c != gubx->
ck_a) {
589 if (c != gubx->
ck_b) {
610 dev->put_byte(
dev->periph, 0,
byte);
622 dev->put_byte(
dev->periph, 0, UBX_SYNC1);
623 dev->put_byte(
dev->periph, 0, UBX_SYNC2);
646 dev->send_message(
dev->periph, 0);
652 for (i = 0; i < len; i++) {
660 UbxSend_CFG_RST(
dev, bbr, reset_mode, 0x00);
664 #ifndef GPS_UBX_UCENTER
665 #define gps_ubx_ucenter_event() {}
680 (gubx->
msg_id == UBX_NAV_VELNED_ID ||
681 gubx->
msg_id == UBX_NAV_PVT_ID ||
682 (gubx->
msg_id == UBX_NAV_SOL_ID &&
697 gubx->msg_available =
false;
715 for (i = 0; i < n; i++) {
718 dev->send_message(
dev->periph, 0);
735 #ifdef GPS_UBX_UCENTER
743 for (i = 0; i < length; i++) {
744 if (rtcm.nbyte == 0) {
747 rtcm.buff[rtcm.nbyte++] = data[i];
751 if (rtcm.nbyte < INJECT_BUFF_SIZE) {
752 rtcm.buff[rtcm.nbyte++] = data[i];
753 if (rtcm.nbyte == 3) {
758 if (rtcm.nbyte == rtcm.len + 3) {
760 unsigned int crc1 =
crc24q(rtcm.buff, rtcm.len);
761 unsigned int crc2 =
RTCMgetbitu(rtcm.buff, rtcm.len * 8, 24);
774 default:
DEBUG_PRINT(
"Unknown type: %i", packet_id);
break;
777 DEBUG_PRINT(
"Skipping message %i (CRC failed) - %d", packet_id, rtcm.buff[0]);
779 for (j = 1; j < rtcm.len; j++) {
unsigned int RTCMgetbitu(unsigned char *buff, int pos, int lenb)
unsigned int crc24q(const unsigned char *buff, int len)
Main include for ABI (AirBorneInterface).
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
uint16_t gps_week_number(uint16_t year, uint8_t month, uint8_t day)
Number of weeks since navigation epoch (6 January 1980)
void WEAK gps_inject_data(uint8_t packet_id, uint8_t length, uint8_t *data)
Default parser for GPS injected data.
void gps_periodic_check(struct GpsState *gps_s)
Periodic GPS check.
struct GpsRelposNED gps_relposned
int16_t azim
azimuth in deg
uint32_t tow
GPS time of week in ms.
uint8_t qi
quality bitfield (GPS receiver specific)
int32_t hmsl
height above mean sea level (MSL) in mm
int8_t elev
elevation in deg
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
uint32_t sacc
speed accuracy in cm/s
struct UtmCoor_i utm_pos
position in UTM (north,east: cm; alt: mm over MSL)
uint32_t cacc
course accuracy in rad*1e7
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
#define GPS_VALID_VEL_ECEF_BIT
#define GPS_VALID_VEL_NED_BIT
uint8_t cno
Carrier to Noise Ratio (Signal Strength) in dbHz.
struct EcefCoor_i ecef_pos
position in ECEF in cm
uint32_t hacc
horizontal accuracy in cm
#define GPS_VALID_POS_LLA_BIT
uint32_t last_3dfix_ticks
cpu time ticks at last valid 3D fix
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
uint16_t pdop
position dilution of precision scaled by 100
#define GPS_VALID_POS_ECEF_BIT
#define GPS_VALID_HMSL_BIT
struct NedCoor_i ned_vel
speed NED in cm/s
uint32_t last_msg_time
cpu time in sec at last received GPS message
uint8_t svid
Satellite ID.
uint8_t nb_channels
Number of scanned satellites.
uint32_t last_3dfix_time
cpu time in sec at last valid 3D fix
uint32_t pacc
position accuracy in cm
uint16_t gspeed
norm of 2d ground speed in cm/s
uint8_t valid_fields
bitfield indicating valid fields (GPS_VALID_x_BIT)
uint8_t comp_id
id of current gps
uint32_t vacc
vertical accuracy in cm
#define GPS_FIX_3D
3D GPS fix
uint16_t speed_3d
norm of 3d speed in cm/s
struct SVinfo svinfos[GPS_NB_CHANNELS]
holds information from the Space Vehicles (Satellites)
uint8_t flags
bitfield with GPS receiver specific flags
#define GPS_VALID_COURSE_BIT
uint32_t last_msg_ticks
cpu time ticks at last received GPS message
#define GPS_VALID_POS_UTM_BIT
uint8_t num_sv
number of sat in fix
data structures for GPS with RTK capabilities
#define CFG_RST_BBR_Coldstart
static void gps_ubx_parse_nav_sat(struct GpsUbx *gubx)
void gps_ubx_periodic_check(void)
void ubx_trailer(struct link_device *dev)
void gps_ubx_parse_HITL_UBX(uint8_t *buf)
void ubx_header(struct link_device *dev, uint8_t nav_id, uint8_t msg_id, uint16_t len)
#define GPS_UBX_ERR_UNEXPECTED
void gps_ubx_read_message(struct GpsUbx *gubx)
#define GPS_UBX_ERR_OVERRUN
#define GPS_UBX_BOOTRESET
static void gps_ubx_parse_nav_posecef(struct GpsUbx *gubx)
#define NAV_RELPOSNED_VERSION
static void ubx_send_1byte(struct link_device *dev, uint8_t byte)
static void gps_ubx_parse_nav_pvt(struct GpsUbx *gubx)
static void gps_ubx_parse_nav_posutm(struct GpsUbx *gubx)
void gps_ublox_write(struct link_device *dev, uint8_t *buff, uint32_t n)
#define GPS_UBX_ERR_MSG_TOO_LONG
#define UNINIT
Includes macros generated from ubx.xml.
#define CFG_RST_Reset_Controlled
#define CFG_RST_BBR_Hotstart
#define GPS_UBX_ERR_CHECKSUM
void ubx_send_cfg_rst(struct link_device *dev, uint16_t bbr, UNUSED uint8_t reset_mode)
static void gps_ubx_parse_nav_sol(struct GpsUbx *gubx)
void gps_ubx_msg(struct GpsUbx *gubx)
struct GpsUbx gps_ubx[GPS_UBX_NB]
#define gps_ubx_ucenter_event()
static void gps_ubx_parse_nav_posllh(struct GpsUbx *gubx)
#define CFG_RST_BBR_Warmstart
static void gps_ubx_parse_nav_velned(struct GpsUbx *gubx)
static void gps_ubx_parse_velecef(struct GpsUbx *gubx)
static void gps_ubx_parse_nav_svinfo(struct GpsUbx *gubx)
void gps_ubx_parse(struct GpsUbx *gubx, uint8_t c)
void ubx_send_bytes(struct link_device *dev, uint8_t len, uint8_t *bytes)
static void gps_ubx_parse_nav_status(struct GpsUbx *gubx)
static void gps_ubx_parse_nav_relposned(struct GpsUbx *gubx)
#define GPS_UBX_ERR_OUT_OF_SYNC
UBX protocol specific code.
uint8_t msg_buf[GPS_UBX_MAX_PAYLOAD]
#define GPS_UBX_MAX_PAYLOAD
int gps_ubx_ucenter_get_status(void)
int32_t lat
in degrees*1e7
int32_t alt
in millimeters (above WGS84 reference ellipsoid or above MSL)
int32_t alt
in millimeters above WGS84 reference ellipsoid
uint8_t zone
UTM zone number.
int32_t east
in centimeters
int32_t lon
in degrees*1e7
int32_t north
in centimeters
uint8_t buff[25]
Buffer used for general comunication over SPI (in buffer)
arch independent LED (Light Emitting Diodes) API
static const struct usb_device_descriptor dev
volatile uint32_t nb_sec
full seconds since startup
volatile uint32_t nb_sec_rem
remainder of seconds since startup in CPU_TICKS
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.