44 #include "generated/settings.h"
49 #error "PRIMARY_GPS not set!"
61 #ifndef GPS_POWER_GPIO_ON
62 #define GPS_POWER_GPIO_ON gpio_set
67 #ifndef GPS_RELPOS_MAX
68 #define GPS_RELPOS_MAX 3
71 #define MSEC_PER_WEEK (1000*60*60*24*7)
72 #define TIME_TO_SWITCH 5000
99 #if PERIODIC_TELEMETRY
106 pprz_msg_send_SVINFO(trans,
dev, AC_ID, &svid,
142 static void send_gps(
struct transport_tx *trans,
struct link_device *
dev)
148 #if PPRZLINK_DEFAULT_VER == 2 && GPS_POS_BROADCAST
150 struct pprzlink_msg
msg;
153 msg.sender_id = AC_ID;
154 msg.receiver_id = PPRZLINK_MSG_BROADCAST;
155 msg.component_id = 0;
156 pprzlink_msg_send_GPS(&
msg,
158 pprz_msg_send_GPS(trans,
dev, AC_ID,
174 pprz_msg_send_GPS_RELPOS(trans,
dev, AC_ID,
192 #if PPRZLINK_DEFAULT_VER == 2 && GPS_POS_BROADCAST
194 struct pprzlink_msg
msg;
197 msg.sender_id = AC_ID;
198 msg.receiver_id = PPRZLINK_MSG_BROADCAST;
199 msg.component_id = 0;
200 pprzlink_msg_send_GPS_INT(&
msg,
202 pprz_msg_send_GPS_INT(trans,
dev, AC_ID,
223 #if PPRZLINK_DEFAULT_VER == 2 && GPS_POS_BROADCAST
225 struct pprzlink_msg
msg;
228 msg.sender_id = AC_ID;
229 msg.receiver_id = PPRZLINK_MSG_BROADCAST;
230 msg.component_id = 0;
231 pprzlink_msg_send_GPS_LLA(&
msg,
233 pprz_msg_send_GPS_LLA(trans,
dev, AC_ID,
251 static uint32_t time_since_last_gps_switch = 0;
256 return GpsId(SECONDARY_GPS);
265 current_gps_id = gps_s->
comp_id;
274 return current_gps_id;
286 current_gps_id = gps_multi_switch(gps_s);
287 if (gps_s->
comp_id == current_gps_id) {
297 bool gps_3d_timeout_valid =
false;
298 #ifdef GPS_FIX_TIMEOUT
300 gps_3d_timeout_valid =
true;
309 uint32_t stamp __attribute__((unused)),
318 current_gps_id = gps_multi_switch(gps_s);
319 if (gps_s->
comp_id == current_gps_id) {
335 uint32_t stamp __attribute__((unused)),
367 #ifdef GPS_POWER_GPIO
378 #if PERIODIC_TELEMETRY
419 uint8_t *data __attribute__((unused)))
427 if (DL_GPS_INJECT_ac_id(buf) != AC_ID) {
return; }
431 DL_GPS_INJECT_packet_id(buf),
432 DL_GPS_INJECT_data_length(buf),
433 DL_GPS_INJECT_data(buf)
441 DL_RTCM_INJECT_data_length(buf),
442 DL_RTCM_INJECT_data(buf));
558 struct NedCoor_i ned_vel_i = { 0, 0, 0 };
593 utm.
alt = gps_s->hmsl / 1000.;
615 utm.
alt = gps_s->hmsl;
632 { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
633 { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
642 uint16_t leap_year = (gps_years % 4 == 0) ? 1 : 0;
646 return gps_years * 365 + ((gps_years - 1) / 4) + 1 + day_of_year - 6;
Main include for ABI (AirBorneInterface).
#define ABI_BROADCAST
Broadcast address.
Event structure to store callbacks in a linked list.
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
Some architecture independent helper functions for GPIOs.
struct UtmCoor_f utm_float_from_gps(struct GpsState *gps_s, uint8_t zone)
Convenience functions to get utm position from GPS state.
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
struct NedCoor_f ned_vel_float_from_gps(struct GpsState *gps_s)
Get GPS ned velocity (float) Converted on the fly if not available.
struct EcefCoor_f ecef_vel_float_from_gps(struct GpsState *gps_s)
Get GPS ecef velocity (float) Converted on the fly if not available.
struct GpsTimeSync gps_time_sync
struct UtmCoor_i utm_int_from_gps(struct GpsState *gps_s, uint8_t zone)
Convenience function to get utm position in int from GPS structure.
static const uint16_t month_days[2][13]
GPS week number roll-over workaround application note.
uint16_t gps_week_number(uint16_t year, uint8_t month, uint8_t day)
Number of weeks since navigation epoch (6 January 1980)
void gps_parse_GPS_INJECT(uint8_t *buf)
struct GpsState gps
global GPS state
struct LlaCoor_i lla_int_from_gps(struct GpsState *gps_s)
Get GPS lla (integer) Converted on the fly if not available.
struct EcefCoor_i ecef_vel_int_from_gps(struct GpsState *gps_s)
Get GPS ecef velocity (integer) Converted on the fly if not available.
static abi_event gps_relpos_ev
struct EcefCoor_f ecef_float_from_gps(struct GpsState *gps_s)
Get GPS ecef pos (float) Converted on the fly if not available.
static void send_gps_int(struct transport_tx *trans, struct link_device *dev)
void gps_parse_RTCM_INJECT(uint8_t *buf)
static void send_gps_lla(struct transport_tx *trans, struct link_device *dev)
static void gps_relpos_cb(uint8_t sender_id, uint32_t stamp, struct RelPosNED *relpos)
static void send_svinfo_available(struct transport_tx *trans, struct link_device *dev)
send SVINFO message if updated.
static void send_svinfo_id(struct transport_tx *trans, struct link_device *dev, uint8_t svid)
void WEAK gps_inject_data(uint8_t packet_id, uint8_t length, uint8_t *data)
Default parser for GPS injected data.
struct EcefCoor_i ecef_int_from_gps(struct GpsState *gps_s)
Get GPS ecef pos (integer) Converted on the fly if not available.
struct NedCoor_i ned_vel_int_from_gps(struct GpsState *gps_s)
Get GPS ned velocity (integer) Converted on the fly if not available.
struct LlaCoor_f lla_float_from_gps(struct GpsState *gps_s)
Get GPS lla (float) Converted on the fly if not available.
void gps_init(void)
initialize the global GPS state
static void send_gps(struct transport_tx *trans, struct link_device *dev)
uint32_t gps_tow_from_sys_ticks(uint32_t sys_ticks)
Convert time in sys_time ticks to GPS time of week.
uint16_t gps_day_number(uint16_t year, uint8_t month, uint8_t day)
Number of days since navigation epoch (6 January 1980)
bool gps_fix_valid(void)
Check if GPS fix is valid.
static void send_svinfo(struct transport_tx *trans, struct link_device *dev)
send SVINFO message (regardless of state)
void gps_periodic_check(struct GpsState *gps_s)
Periodic GPS check.
static void send_gps_relpos(struct transport_tx *trans, struct link_device *dev)
static struct RelPosNED gps_relposned[GPS_RELPOS_MAX]
static void send_gps_sol(struct transport_tx *trans, struct link_device *dev)
Device independent GPS code (interface)
int16_t azim
azimuth in deg
uint32_t tow
GPS time of week in ms.
#define GPS_MODE_SECONDARY
float distance_acc
Distance accuracy in meters.
uint8_t qi
quality bitfield (GPS receiver specific)
int32_t hmsl
height above mean sea level (MSL) in mm
static float gps_time_since_last_3dfix(void)
Returns the time since last 3D fix in seconds (float)
int8_t elev
elevation in deg
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
float heading
Relative heading to the reference station in radians.
uint32_t sacc
speed accuracy in cm/s
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.
float heading_acc
Heading accuracy in radians.
struct EcefCoor_i ecef_pos
position in ECEF in cm
uint32_t hacc
horizontal accuracy in cm
#define GPS_VALID_POS_LLA_BIT
double distance
Relative distance to the reference station in meters.
uint32_t last_3dfix_ticks
cpu time ticks at last valid 3D fix
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
uint32_t t0_ticks
hw clock ticks when GPS message is received
#define GPS_TIMEOUT
GPS timeout in seconds in case of communication loss with GPS module.
uint16_t pdop
position dilution of precision scaled by 100
#define GPS_FIX_NONE
No GPS fix.
#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
uint32_t t0_tow
GPS time of week in ms from last message.
uint8_t svid
Satellite ID.
uint8_t nb_channels
Number of scanned satellites.
struct NedCoor_f pos_acc
Position accuracy in meters.
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
struct NedCoor_d pos
Relative postion to the reference station in meters.
#define GPS_FIX_3D
3D GPS fix
struct SVinfo svinfos[GPS_NB_CHANNELS]
holds information from the Space Vehicles (Satellites)
uint8_t flags
bitfield with GPS receiver specific flags
uint32_t last_msg_ticks
cpu time ticks at last received GPS message
uint16_t reference_id
Reference station identification.
#define GPS_VALID_POS_UTM_BIT
uint8_t num_sv
number of sat in fix
data structure for GPS information
data structure for GPS time sync
#define UTM_COPY(_u1, _u2)
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
#define ECEF_FLOAT_OF_BFP(_o, _i)
void ecef_of_lla_i(struct EcefCoor_i *out, struct LlaCoor_i *in)
Convert a LLA to ECEF.
void ltp_def_from_ecef_i(struct LtpDef_i *def, struct EcefCoor_i *ecef)
void ecef_of_ned_vect_i(struct EcefCoor_i *ecef, struct LtpDef_i *def, struct NedCoor_i *ned)
Rotate a vector from NED to ECEF.
void ned_of_ecef_vect_i(struct NedCoor_i *ned, struct LtpDef_i *def, struct EcefCoor_i *ecef)
Rotate a vector from ECEF to NED.
#define VECT3_FLOAT_OF_CM(_o, _i)
#define LLA_FLOAT_OF_BFP(_o, _i)
void utm_of_lla_i(struct UtmCoor_i *utm, struct LlaCoor_i *lla)
Convert a LLA to UTM.
void lla_of_ecef_i(struct LlaCoor_i *out, struct EcefCoor_i *in)
Convert a ECEF to LLA.
void ltp_def_from_lla_i(struct LtpDef_i *def, struct LlaCoor_i *lla)
#define UTM_FLOAT_OF_BFP(_o, _i)
vector in EarthCenteredEarthFixed coordinates
vector in Latitude, Longitude and Altitude
definition of the local (flat earth) coordinate system
vector in North East Down coordinates
position in UTM coordinates
static int32_t wgs84_ellipsoid_to_geoid_i(int32_t lat, int32_t lon)
Get WGS84 ellipsoid/geoid separation.
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
arch independent LED (Light Emitting Diodes) API
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
Paparazzi generic macros for geodetic calculations.
float alt
in meters (above WGS84 reference ellipsoid or above MSL)
uint8_t zone
UTM zone number.
vector in EarthCenteredEarthFixed coordinates
vector in Latitude, Longitude and Altitude
vector in North East Down coordinates Units: meters
position in UTM coordinates Units: meters
void preflight_error(struct preflight_result_t *result, const char *fmt,...)
Register a preflight error used inside the preflight checking functions.
void preflight_success(struct preflight_result_t *result, const char *fmt,...)
Register a preflight success used inside the preflight checking functions.
void preflight_check_register(struct preflight_check_t *check, preflight_check_f func)
Register a preflight check and add it to the linked list.
Persistent settings interface.
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
volatile uint32_t nb_tick
SYS_TIME_TICKS since startup.
volatile uint32_t nb_sec
full seconds since startup
static uint32_t msec_of_sys_time_ticks(uint32_t ticks)
static float get_sys_time_float(void)
Get the time in seconds since startup.
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.