39 #include "pprzlink/pprzlink_device.h"
42 #error "MTK_GPS_LINK not set"
45 #define MTK_DIY_OUTPUT_RATE MTK_DIY_OUTPUT_4HZ
50 #define GOT_SYNC1_14 1
51 #define GOT_SYNC2_14 2
52 #define GOT_CLASS_14 3
53 #define GOT_SYNC1_16 4
54 #define GOT_SYNC2_16 5
57 #define GOT_CHECKSUM1 8
60 #define GPS_MTK_ERR_NONE 0
61 #define GPS_MTK_ERR_OVERRUN 1
62 #define GPS_MTK_ERR_MSG_TOO_LONG 2
63 #define GPS_MTK_ERR_CHECKSUM 3
64 #define GPS_MTK_ERR_UNEXPECTED 4
65 #define GPS_MTK_ERR_OUT_OF_SYNC 5
68 #define MTK_DIY_FIX_3D 3
69 #define MTK_DIY_FIX_2D 2
70 #define MTK_DIY_FIX_NONE 1
74 #define SECS_MINUTE (60)
75 #define SECS_HOUR (60*60)
76 #define SECS_DAY (60*60*24)
77 #define SECS_WEEK (60*60*24*7)
79 #define isleap(x) ((((x)%400)==0) || (!(((x)%100)==0) && (((x)%4)==0)))
81 const int8_t DAYS_MONTH[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
86 #define MTK_DIY_SET_BINARY "$PGCMD,16,0,0,0,0,0*6A\r\n"
87 #define MTK_DIY_SET_NMEA "$PGCMD,16,1,1,1,1,1*6B\r\n"
89 #define MTK_DIY_OUTPUT_1HZ "$PMTK220,1000*1F\r\n"
90 #define MTK_DIY_OUTPUT_2HZ "$PMTK220,500*2B\r\n"
91 #define MTK_DIY_OUTPUT_4HZ "$PMTK220,250*29\r\n"
92 #define MTK_DIY_OTUPUT_5HZ "$PMTK220,200*2C\r\n"
93 #define MTK_DIY_OUTPUT_10HZ "$PMTK220,100*2F\r\n"
95 #define MTK_BAUD_RATE_38400 "$PMTK251,38400*27\r\n"
97 #define MTK_DIY_SBAS_ON "$PMTK313,1*2E\r\n"
98 #define MTK_DIY_SBAS_OFF "$PMTK313,0*2F\r\n"
100 #define MTK_DIY_WAAS_ON "$PSRF151,1*3F\r\n"
101 #define MTK_DIY_WAAS_OFF "$PSRF151,0*3E\r\n"
103 bool gps_configuring;
104 static uint8_t gps_status_config;
118 gps_status_config = 0;
119 gps_configuring =
true;
125 struct link_device *
dev = &((MTK_GPS_LINK).device);
127 while (
dev->char_available(
dev->periph)) {
168 uint16_t gps_msecond = gps_time % 1000;
169 uint8_t gps_second = (gps_time / 1000) % 100;
170 uint8_t gps_minute = (gps_time / 100000) % 100;
171 uint8_t gps_hour = (gps_time / 10000000) % 100;
172 uint16_t gps_year = 2000 + (gps_date % 100);
173 uint8_t gps_month = (gps_date / 100) % 100;
174 uint8_t gps_day = (gps_date / 10000) % 100;
181 if (gps_month > 12) {
return; }
183 ((gps_month == 1) ?
isleap(gps_year) : 0))) {
return; }
184 if (gps_hour > 23) {
return; }
185 if (gps_minute > 59) {
return; }
186 if (gps_second > 59) {
return; }
190 for (i = 1980; i < gps_year; i++) { days += (365 +
isleap(i)); }
193 for (i = 0; i < gps_month - 1; i++) {
200 *gps_itow = ((days % 7) *
SECS_DAY +
313 if (c == MTK_DIY14_SYNC1) {
316 if (c == MTK_DIY16_ID) {
323 if (c != MTK_DIY14_SYNC2) {
338 if (c != MTK_DIY14_ID) {
347 if (c != MTK_DIY14_NAV_ID) {
356 if (c != MTK_DIY16_NAV_ID) {
419 #include "pprzlink/pprzlink_device.h"
421 static void MtkSend_CFG(
char *dat)
423 struct link_device *
dev = &((MTK_GPS_LINK).device);
424 while (*dat != 0) {
dev->put_byte(
dev->periph, 0, *dat++); }
427 void gps_configure_uart(
void)
431 #ifdef USER_GPS_CONFIGURE
432 #include USER_GPS_CONFIGURE
434 static bool user_gps_configure(
bool cpt)
438 MtkSend_CFG(MTK_DIY_SET_BINARY);
450 void gps_configure(
void)
455 gps_configuring = user_gps_configure(gps_status_config++);
Main include for ABI (AirBorneInterface).
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
uint32_t tow
GPS time of week in ms.
int32_t hmsl
height above mean sea level (MSL) in mm
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
#define GPS_VALID_POS_LLA_BIT
uint32_t last_3dfix_ticks
cpu time ticks at last valid 3D fix
#define GPS_FIX_NONE
No GPS fix.
#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 last_3dfix_time
cpu time in sec at last valid 3D fix
uint16_t gspeed
norm of 2d ground speed in cm/s
uint8_t valid_fields
bitfield indicating valid fields (GPS_VALID_x_BIT)
#define GPS_FIX_2D
2D GPS fix
#define GPS_FIX_3D
3D GPS fix
uint16_t speed_3d
norm of 3d speed in cm/s
#define GPS_VALID_COURSE_BIT
uint32_t last_msg_ticks
cpu time ticks at last received GPS message
uint8_t num_sv
number of sat in fix
void gps_mtk_read_message(void)
#define GPS_MTK_ERR_OUT_OF_SYNC
#define GPS_MTK_ERR_UNEXPECTED
#define GPS_MTK_ERR_CHECKSUM
const int8_t DAYS_MONTH[12]
void gps_mtk_parse(uint8_t c)
#define MTK_DIY_OUTPUT_RATE
#define GPS_MTK_ERR_OVERRUN
static void gps_mtk_time2itow(uint32_t gps_date, uint32_t gps_time, uint16_t *gps_week, uint32_t *gps_itow)
Mediatek MT3329 specific code.
uint8_t msg_buf[GPS_MTK_MAX_PAYLOAD]
int32_t lat
in degrees*1e7
int32_t alt
in millimeters above WGS84 reference ellipsoid
int32_t lon
in degrees*1e7
arch independent LED (Light Emitting Diodes) API
static const struct usb_device_descriptor dev
Architecture independent timing functions.
#define SysTimeTimerStart(_t)
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.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.