306 lines
7.9 KiB
C
306 lines
7.9 KiB
C
/****************************************************************************
|
|
*
|
|
* Copy right: 2024-, Copyrigths of EigenComm Ltd.
|
|
* File name: api_gnss.h
|
|
* Description: ec7xx openHAL GNSS entry header file
|
|
* History: Rev1.0 2024-11-27
|
|
*
|
|
****************************************************************************/
|
|
#ifndef MINMEA_H
|
|
#define MINMEA_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
// #include "opensdk_api.h"
|
|
// #include <ctype.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
// #include <time.h>
|
|
// #include <math.h>
|
|
|
|
#ifndef MINMEA_MAX_SENTENCE_LENGTH
|
|
#define MINMEA_MAX_SENTENCE_LENGTH 80
|
|
#endif
|
|
|
|
#define NMEA_ITEMS_MAX (20)
|
|
|
|
typedef struct
|
|
{
|
|
int day;
|
|
int month;
|
|
int year;
|
|
int hours;
|
|
int minutes;
|
|
int seconds;
|
|
} gnss_time_t;
|
|
|
|
typedef struct
|
|
{
|
|
uint8_t valid;
|
|
uint8_t items;
|
|
uint16_t size;
|
|
gnss_time_t time;
|
|
uint32_t latitude;
|
|
uint32_t latitude_scale;
|
|
uint32_t longitude;
|
|
uint32_t longitude_scale;
|
|
uint16_t altitude;
|
|
uint16_t altitude_scale;
|
|
uint16_t speed;
|
|
uint16_t tracked; // 追踪的卫星数量
|
|
uint16_t quality;
|
|
uint16_t hdop; // 水平精度因子
|
|
} gnss_data_t;
|
|
|
|
enum minmea_sentence_id
|
|
{
|
|
MINMEA_INVALID = -1,
|
|
MINMEA_UNKNOWN = 0,
|
|
MINMEA_SENTENCE_GBS,
|
|
MINMEA_SENTENCE_GGA,
|
|
MINMEA_SENTENCE_GLL,
|
|
MINMEA_SENTENCE_GSA,
|
|
MINMEA_SENTENCE_GST,
|
|
MINMEA_SENTENCE_GSV,
|
|
MINMEA_SENTENCE_RMC,
|
|
MINMEA_SENTENCE_VTG,
|
|
MINMEA_SENTENCE_ZDA,
|
|
MINMEA_SENTENCE_TXT,
|
|
};
|
|
|
|
struct minmea_float
|
|
{
|
|
int_least32_t value;
|
|
int_least32_t scale;
|
|
};
|
|
|
|
struct minmea_date
|
|
{
|
|
int day;
|
|
int month;
|
|
int year;
|
|
};
|
|
|
|
struct minmea_time
|
|
{
|
|
int hours;
|
|
int minutes;
|
|
int seconds;
|
|
int microseconds;
|
|
};
|
|
|
|
struct minmea_sentence_gbs
|
|
{
|
|
struct minmea_time time;
|
|
struct minmea_float err_latitude;
|
|
struct minmea_float err_longitude;
|
|
struct minmea_float err_altitude;
|
|
int svid;
|
|
struct minmea_float prob;
|
|
struct minmea_float bias;
|
|
struct minmea_float stddev;
|
|
};
|
|
|
|
struct minmea_sentence_rmc
|
|
{
|
|
char type[6];
|
|
struct minmea_time time;
|
|
bool valid;
|
|
struct minmea_float latitude;
|
|
struct minmea_float longitude;
|
|
struct minmea_float speed;
|
|
struct minmea_float course;
|
|
struct minmea_date date;
|
|
struct minmea_float variation;
|
|
};
|
|
|
|
struct minmea_sentence_gga
|
|
{
|
|
char type[6];
|
|
struct minmea_time time;
|
|
struct minmea_float latitude;
|
|
struct minmea_float longitude;
|
|
int fix_quality;
|
|
int satellites_tracked;
|
|
struct minmea_float hdop;
|
|
struct minmea_float altitude;
|
|
char altitude_units;
|
|
struct minmea_float height;
|
|
char height_units;
|
|
struct minmea_float dgps_age;
|
|
};
|
|
|
|
enum minmea_gll_status
|
|
{
|
|
MINMEA_GLL_STATUS_DATA_VALID = 'A',
|
|
MINMEA_GLL_STATUS_DATA_NOT_VALID = 'V',
|
|
};
|
|
|
|
// FAA mode added to some fields in NMEA 2.3.
|
|
enum minmea_faa_mode
|
|
{
|
|
MINMEA_FAA_MODE_AUTONOMOUS = 'A',
|
|
MINMEA_FAA_MODE_DIFFERENTIAL = 'D',
|
|
MINMEA_FAA_MODE_ESTIMATED = 'E',
|
|
MINMEA_FAA_MODE_MANUAL = 'M',
|
|
MINMEA_FAA_MODE_SIMULATED = 'S',
|
|
MINMEA_FAA_MODE_NOT_VALID = 'N',
|
|
MINMEA_FAA_MODE_PRECISE = 'P',
|
|
};
|
|
|
|
struct minmea_sentence_gll
|
|
{
|
|
char type[6];
|
|
struct minmea_float latitude;
|
|
struct minmea_float longitude;
|
|
struct minmea_time time;
|
|
char status;
|
|
char mode;
|
|
};
|
|
|
|
struct minmea_sentence_gst
|
|
{
|
|
struct minmea_time time;
|
|
struct minmea_float rms_deviation;
|
|
struct minmea_float semi_major_deviation;
|
|
struct minmea_float semi_minor_deviation;
|
|
struct minmea_float semi_major_orientation;
|
|
struct minmea_float latitude_error_deviation;
|
|
struct minmea_float longitude_error_deviation;
|
|
struct minmea_float altitude_error_deviation;
|
|
};
|
|
|
|
enum minmea_gsa_mode
|
|
{
|
|
MINMEA_GPGSA_MODE_AUTO = 'A',
|
|
MINMEA_GPGSA_MODE_FORCED = 'M',
|
|
};
|
|
|
|
enum minmea_gsa_fix_type
|
|
{
|
|
MINMEA_GPGSA_FIX_NONE = 1,
|
|
MINMEA_GPGSA_FIX_2D = 2,
|
|
MINMEA_GPGSA_FIX_3D = 3,
|
|
};
|
|
|
|
struct minmea_sentence_gsa
|
|
{
|
|
char type[6];
|
|
char mode;
|
|
int fix_type;
|
|
int sats[12];
|
|
struct minmea_float pdop;
|
|
struct minmea_float hdop;
|
|
struct minmea_float vdop;
|
|
};
|
|
|
|
struct minmea_sat_info
|
|
{
|
|
int nr;
|
|
int elevation;
|
|
int azimuth;
|
|
int snr;
|
|
};
|
|
|
|
struct minmea_sentence_gsv
|
|
{
|
|
char type[6];
|
|
int total_msgs;
|
|
int msg_nr;
|
|
int total_sats;
|
|
struct minmea_sat_info sats[4];
|
|
};
|
|
|
|
struct minmea_sentence_vtg
|
|
{
|
|
char type[6];
|
|
struct minmea_float true_track_degrees;
|
|
struct minmea_float magnetic_track_degrees;
|
|
struct minmea_float speed_knots;
|
|
struct minmea_float speed_kph;
|
|
enum minmea_faa_mode faa_mode;
|
|
};
|
|
|
|
struct minmea_sentence_zda
|
|
{
|
|
char type[6];
|
|
struct minmea_time time;
|
|
struct minmea_date date;
|
|
int hour_offset;
|
|
int minute_offset;
|
|
};
|
|
|
|
struct minmea_sentence_txt
|
|
{
|
|
char type[6];
|
|
int data1;
|
|
int data2;
|
|
int data3;
|
|
char flag;
|
|
};
|
|
|
|
/**
|
|
* Check sentence validity and checksum. Returns true for valid sentences.
|
|
*/
|
|
bool minmea_check(const char *sentence, bool strict);
|
|
|
|
/**
|
|
* Determine talker identifier.
|
|
*/
|
|
// bool minmea_talker_id(char talker[3], const char *sentence);
|
|
|
|
/**
|
|
* Determine sentence identifier.
|
|
*/
|
|
enum minmea_sentence_id minmea_sentence_id(const char *sentence, bool strict);
|
|
|
|
/**
|
|
* Scanf-like processor for NMEA sentences. Supports the following formats:
|
|
* c - single character (char *)
|
|
* d - direction, returned as 1/-1, default 0 (int *)
|
|
* f - fractional, returned as value + scale (struct minmea_float *)
|
|
* i - decimal, default zero (int *)
|
|
* s - string (char *)
|
|
* t - talker identifier and type (char *)
|
|
* D - date (struct minmea_date *)
|
|
* T - time stamp (struct minmea_time *)
|
|
* _ - ignore this field
|
|
* ; - following fields are optional
|
|
* Returns true on success. See library source code for details.
|
|
*/
|
|
bool minmea_scan(const char *sentence, const char *format, ...);
|
|
|
|
/*
|
|
* Parse a specific type of sentence. Return true on success.
|
|
*/
|
|
bool minmea_parse_gbs(struct minmea_sentence_gbs *frame, const char *sentence);
|
|
bool minmea_parse_rmc(struct minmea_sentence_rmc *frame, const char *sentence);
|
|
bool minmea_parse_gga(struct minmea_sentence_gga *frame, const char *sentence);
|
|
bool minmea_parse_gsa(struct minmea_sentence_gsa *frame, const char *sentence);
|
|
bool minmea_parse_gll(struct minmea_sentence_gll *frame, const char *sentence);
|
|
bool minmea_parse_gst(struct minmea_sentence_gst *frame, const char *sentence);
|
|
bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence);
|
|
bool minmea_parse_vtg(struct minmea_sentence_vtg *frame, const char *sentence);
|
|
bool minmea_parse_zda(struct minmea_sentence_zda *frame, const char *sentence);
|
|
bool minmea_parse_txt(struct minmea_sentence_txt *frame, const char *sentence);
|
|
|
|
/**
|
|
* Check whether a character belongs to the set of characters allowed in a
|
|
* sentence data field.
|
|
*/
|
|
static inline bool minmea_isfield(char c)
|
|
{
|
|
return isprint((unsigned char)c) && c != ',' && c != '*';
|
|
}
|
|
|
|
uint16_t nmea_line_parse(char *line, gnss_data_t *gnss);
|
|
int gnss_parse(char *str, gnss_data_t *data);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|