31#include "generated/airframe.h"
50static void nmea_send(
const char *payload,
int payload_length);
84#if GPS_NMEA_SEND_USE_STATE_DATA
108 char lat_buf[16], lon_buf[16], gga[120], rmc[120], date_sys[6], time_sys[6];
117 for (
int i = 0; i < 120; i++) { gga[i] =
'\0'; rmc[i] =
'\0'; }
126 "$GPGGA,%s,%s,%c,%s,%c,1,%02u,%04u,%09.3f,M,0,M,,",
127 time_sys, lat_buf, lat_hemi, lon_buf, lon_hemi,
146 sprintf(gga + len_gga,
"*%02X\r\n", cs);
155 "$GPRMC,%s,A,%s,%c,%s,%c,%05.1f,%05.1f,%s,000.0,W",
156 time_sys, lat_buf, lat_hemi, lon_buf, lon_hemi,
171 sprintf(rmc + len_rmc,
"*%02X\r\n", cs);
178 sprintf(gga,
"$GPGGA,,,,,,0,00,99.99,,,,,,*68\r\n");
182 sprintf(rmc,
"$GPRMC,,V,,,,,,,,,,*53\r\n");
193 for (
int i = 0; i < length; i++) {
205 double abs_deg = fabs(deg);
206 int d = (int)abs_deg;
207 double minutes = (abs_deg - d) * 60.0;
211 sprintf(buf,
"%02d%07.4f", d, minutes);
214 sprintf(buf,
"%03d%07.4f", d, minutes);
224 const int64_t gps_epoch_days = 3657;
228 int64_t days = gps_epoch_days + gps_sec / 86400;
234 int64_t era = (days >= 0 ? days : days - 146096) / 146097;
238 uint64_t yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365;
240 int64_t y = (int64_t)yoe + era * 400;
242 uint64_t doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
246 uint64_t d = doy - (153 * mp + 2) / 5 + 1;
248 uint64_t m = mp + (mp < 10 ? 3 : -9);
252 uint32_t sec_of_day = gps_sec % 86400;
253 uint8_t hour = sec_of_day / 3600;
254 uint8_t min = (sec_of_day % 3600) / 60;
258 snprintf(buf_date, buf_date_size,
"%02d%02d%02d",
264 snprintf(buf_time, buf_time_size,
"%02d%02d%02d",
struct GpsState gps
global GPS state
Device independent GPS code (interface).
#define GPS_FIX_3D
3D GPS fix
static uint8_t nmea_checksum(const char *sentence, int length)
Function to calculate checksum.
static void recover_gps_data(void)
Function to recover data available onboard from GPS.
static void gps_nmea_get_system_date_str(char *buf_date, size_t buf_date_size, char *buf_time, size_t buf_time_size)
Get Date from system.
struct Gps_Nmea_Send gps_nmea_send
static void nmea_send(const char *payload, int payload_length)
Function to send payload to UART.
void gps_nmea_send_init(void)
Initialization function.
static void nmea_convert_deg_to_DDMM(double deg, char *buf, int is_lat)
Function to convert lat long in DDLL.MMMM Format Lat and long don't have the same length.
static void build_nmea_sentence(void)
Function to build sentence for NMEA Protocol.
void gps_nmea_send_periodic(void)
Periodic function to send data.
module used to send GPS data over a Tawaki UART for extern instrument using NMEA protocol Exemple of ...
static struct LlaCoor_f * stateGetPositionLla_f(void)
Get position in LLA coordinates (float).
float stateGetHmslOrigin_f(void)
Get the HMSL of the frame origin (float).
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
static float stateGetHorizontalSpeedNorm_f(void)
Get norm of horizontal ground speed (float).
static float stateGetHorizontalSpeedDir_f(void)
Get dir of horizontal ground speed (float).
vector in Latitude, Longitude and Altitude
#define NormCourseRad(x)
Normalize a rad angle between 0 and 2*PI.
API to get/set the generic vehicle states.
void WEAK uart_put_buffer(struct uart_periph *p, long fd, const uint8_t *data, uint16_t len)
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned long long uint64_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.