44 #define MTK_DIY_OUTPUT_RATE MTK_DIY_OUTPUT_4HZ
49 #define GOT_SYNC1_14 1
50 #define GOT_SYNC2_14 2
51 #define GOT_CLASS_14 3
52 #define GOT_SYNC1_16 4
53 #define GOT_SYNC2_16 5
56 #define GOT_CHECKSUM1 8
59 #define GPS_MTK_ERR_NONE 0
60 #define GPS_MTK_ERR_OVERRUN 1
61 #define GPS_MTK_ERR_MSG_TOO_LONG 2
62 #define GPS_MTK_ERR_CHECKSUM 3
63 #define GPS_MTK_ERR_UNEXPECTED 4
64 #define GPS_MTK_ERR_OUT_OF_SYNC 5
67 #define MTK_DIY_FIX_3D 3
68 #define MTK_DIY_FIX_2D 2
69 #define MTK_DIY_FIX_NONE 1
73 #define SECS_MINUTE (60)
74 #define SECS_HOUR (60*60)
75 #define SECS_DAY (60*60*24)
76 #define SECS_WEEK (60*60*24*7)
78 #define isleap(x) ((((x)%400)==0) || (!(((x)%100)==0) && (((x)%4)==0)))
80 const int8_t DAYS_MONTH[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
85 #define MTK_DIY_SET_BINARY "$PGCMD,16,0,0,0,0,0*6A\r\n"
86 #define MTK_DIY_SET_NMEA "$PGCMD,16,1,1,1,1,1*6B\r\n"
88 #define MTK_DIY_OUTPUT_1HZ "$PMTK220,1000*1F\r\n"
89 #define MTK_DIY_OUTPUT_2HZ "$PMTK220,500*2B\r\n"
90 #define MTK_DIY_OUTPUT_4HZ "$PMTK220,250*29\r\n"
91 #define MTK_DIY_OTUPUT_5HZ "$PMTK220,200*2C\r\n"
92 #define MTK_DIY_OUTPUT_10HZ "$PMTK220,100*2F\r\n"
94 #define MTK_BAUD_RATE_38400 "$PMTK251,38400*27\r\n"
96 #define MTK_DIY_SBAS_ON "$PMTK313,1*2E\r\n"
97 #define MTK_DIY_SBAS_OFF "$PMTK313,0*2F\r\n"
99 #define MTK_DIY_WAAS_ON "$PSRF151,1*3F\r\n"
100 #define MTK_DIY_WAAS_OFF "$PSRF151,0*3E\r\n"
102 bool_t gps_configuring;
103 static uint8_t gps_status_config;
113 gps_status_config = 0;
114 gps_configuring =
TRUE;
150 uint16_t gps_msecond = gps_time % 1000;
151 uint8_t gps_second = (gps_time / 1000) % 100;
152 uint8_t gps_minute = (gps_time / 100000) % 100;
153 uint8_t gps_hour = (gps_time / 10000000) % 100;
154 uint16_t gps_year = 2000 + (gps_date % 100);
155 uint8_t gps_month = (gps_date / 100) % 100;
156 uint8_t gps_day = (gps_date / 10000) % 100;
163 if (gps_month > 12) {
return; }
165 ((gps_month == 1) ?
isleap(gps_year) : 0))) {
return; }
166 if (gps_hour > 23) {
return; }
167 if (gps_minute > 59) {
return; }
168 if (gps_second > 59) {
return; }
172 for (i = 1980; i < gps_year; i++) { days += (365 +
isleap(i)); }
175 for (i = 0; i < gps_month - 1; i++) {
182 *gps_itow = ((days % 7) *
SECS_DAY +
317 if (c == MTK_DIY14_SYNC1) {
320 if (c == MTK_DIY16_ID) {
327 if (c != MTK_DIY14_SYNC2) {
342 if (c != MTK_DIY14_ID) {
351 if (c != MTK_DIY14_NAV_ID) {
360 if (c != MTK_DIY16_NAV_ID) {
425 static void MtkSend_CFG(
char *dat)
431 void gps_configure_uart(
void)
435 #ifdef USER_GPS_CONFIGURE
436 #include USER_GPS_CONFIGURE
438 static bool_t user_gps_configure(bool_t cpt)
442 MtkSend_CFG(MTK_DIY_SET_BINARY);
452 #endif // ! USER_GPS_CONFIGURE
454 void gps_configure(
void)
459 gps_configuring = user_gps_configure(gps_status_config++);
put_byte_t put_byte
put one byte
uint32_t t0_tow
GPS time of week in ms from last message.
int32_t north
in centimeters
void gps_mtk_read_message(void)
uint32_t t0_ticks
hw clock ticks when GPS message is received
Main include for ABI (AirBorneInterface).
#define MTK_DIY_OUTPUT_RATE
position in UTM coordinates Units: meters
int32_t east
in centimeters
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 ellipsoid)
void * periph
pointer to parent implementation
uint32_t last_3dfix_ticks
cpu time ticks at last valid 3D fix
int32_t alt
in millimeters above WGS84 reference ellipsoid
static uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
uint32_t last_msg_time
cpu time in sec at last received GPS message
uint8_t zone
UTM zone number.
Paparazzi floating point math for geodetic calculations.
static void gps_mtk_time2itow(uint32_t gps_date, uint32_t gps_time, int16_t *gps_week, uint32_t *gps_itow)
#define GPS_MTK_ERR_CHECKSUM
vector in Latitude, Longitude and Altitude
uint8_t msg_buf[GPS_MTK_MAX_PAYLOAD]
int32_t hmsl
height above mean sea level in mm
void gps_mtk_parse(uint8_t c)
Architecture independent timing functions.
uint32_t tow
GPS time of week in ms.
#define GPS_FIX_NONE
No GPS fix.
#define GPS_FIX_2D
2D GPS fix
Device independent GPS code (interface)
int32_t lon
in degrees*1e7
#define GPS_MTK_ERR_UNEXPECTED
uint8_t zone
UTM zone number.
volatile uint32_t nb_sec_rem
remainder of seconds since startup in CPU_TICKS
#define GPS_MTK_ERR_OUT_OF_SYNC
static const struct usb_device_descriptor dev
void gps_impl_init(void)
GPS initialization.
uint32_t last_3dfix_time
cpu time in sec at last valid 3D fix
int32_t alt
in millimeters above WGS84 reference ellipsoid
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
volatile uint32_t nb_sec
full seconds since startup
int32_t t0_tow_frac
fractional ns remainder of tow [ms], range -500000 .. 500000
struct GpsTimeSync gps_time_sync
uint32_t last_msg_ticks
cpu time ticks at last received GPS message
uint8_t num_sv
number of sat in fix
arch independent LED (Light Emitting Diodes) API
uint16_t gspeed
norm of 2d ground speed in cm/s
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
#define SysTimeTimerStart(_t)
const int8_t DAYS_MONTH[12]
int32_t lat
in degrees*1e7
struct NedCoor_i ned_vel
speed NED in cm/s
#define GPS_MTK_ERR_OVERRUN
struct GpsState gps
global GPS state
#define LLA_FLOAT_OF_BFP(_o, _i)
void utm_of_lla_f(struct UtmCoor_f *utm, struct LlaCoor_f *lla)