From 3000e645a26ab4149158d195e0d6b07da385fac8 Mon Sep 17 00:00:00 2001 From: Walt Johnson Date: Fri, 26 May 2023 16:22:30 -0600 Subject: [PATCH] SN-3703 standard NMEA use gn (#400) * Switch NMEA messages to start with * Add comment * Added GNSS ID --- src/data_sets.h | 33 +++++++++++++++++++-------------- src/protocol_nmea.cpp | 27 +++++++++++++++++---------- src/protocol_nmea.h | 1 + 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/data_sets.h b/src/data_sets.h index 9d0125187..a3f6e0204 100644 --- a/src/data_sets.h +++ b/src/data_sets.h @@ -891,15 +891,16 @@ typedef struct PACKED /** Sat SV - GNSS System ID */ enum eSatSvGnssId { - SAT_SV_GNSS_ID_UNKNOWN = 0, - SAT_SV_GNSS_ID_GPS = 1, // GPS (USA) - SAT_SV_GNSS_ID_SBS = 2, // SBAS (multiple regional systems, see flash config for selection) - SAT_SV_GNSS_ID_GAL = 3, // Galileo (European Union) - SAT_SV_GNSS_ID_BEI = 4, // BeiDou (China) - SAT_SV_GNSS_ID_QZS = 5, // QZSS (Japan) - SAT_SV_GNSS_ID_GLO = 6, // GLONASS (Russia) - SAT_SV_GNSS_ID_IRN = 7, // IRNSS / NavIC (India) - SAT_SV_GNSS_ID_IME = 8, // IMES (Japan's Indoor Messaging System) + SAT_SV_GNSS_ID_UNKNOWN = 0, + SAT_SV_GNSS_ID_GNSS = 0, // (multi-constellation) + SAT_SV_GNSS_ID_GPS = 1, // GPS (USA) + SAT_SV_GNSS_ID_SBS = 2, // SBAS (multiple regional systems, see flash config for selection) + SAT_SV_GNSS_ID_GAL = 3, // Galileo (European Union) + SAT_SV_GNSS_ID_BEI = 4, // BeiDou (China) + SAT_SV_GNSS_ID_QZS = 5, // QZSS (Japan) + SAT_SV_GNSS_ID_GLO = 6, // GLONASS (Russia) + SAT_SV_GNSS_ID_IRN = 7, // IRNSS / NavIC (India) + SAT_SV_GNSS_ID_IME = 8, // IMES (Japan's Indoor Messaging System) }; /** GPS Sat Status */ @@ -2050,7 +2051,7 @@ enum eGnssSatSigConst /*! GPS */ GNSS_SAT_SIG_CONST_GPS = (uint16_t)0x0003, /*! QZSS */ - GNSS_SAT_SIG_CONST_QZSS = (uint16_t)0x000C, + GNSS_SAT_SIG_CONST_QZS = (uint16_t)0x000C, /*! Galileo */ GNSS_SAT_SIG_CONST_GAL = (uint16_t)0x0030, /*! BeiDou */ @@ -2058,13 +2059,17 @@ enum eGnssSatSigConst /*! GLONASS */ GNSS_SAT_SIG_CONST_GLO = (uint16_t)0x0300, /*! SBAS */ - GNSS_SAT_SIG_CONST_SBAS = (uint16_t)0x1000, - + GNSS_SAT_SIG_CONST_SBS = (uint16_t)0x1000, + /*! IRNSS / NavIC */ + GNSS_SAT_SIG_CONST_IRN = (uint16_t)0x2000, + /*! IMES */ + GNSS_SAT_SIG_CONST_IME = (uint16_t)0x4000, + /*! GNSS default */ GNSS_SAT_SIG_CONST_DEFAULT = \ GNSS_SAT_SIG_CONST_GPS | \ - GNSS_SAT_SIG_CONST_SBAS | \ - GNSS_SAT_SIG_CONST_QZSS | \ + GNSS_SAT_SIG_CONST_SBS | \ + GNSS_SAT_SIG_CONST_QZS | \ GNSS_SAT_SIG_CONST_GAL | \ GNSS_SAT_SIG_CONST_GLO | \ GNSS_SAT_SIG_CONST_BDS diff --git a/src/protocol_nmea.cpp b/src/protocol_nmea.cpp index 192c44b30..af3455fdc 100644 --- a/src/protocol_nmea.cpp +++ b/src/protocol_nmea.cpp @@ -7,11 +7,11 @@ static int s_protocol_version = 0; +static uint8_t s_gnssId = SAT_SV_GNSS_ID_GNSS; uint8_t nmea2p3_svid_to_sigId(uint8_t gnssId, uint16_t svId); - ////////////////////////////////////////////////////////////////////////// // Utility functions ////////////////////////////////////////////////////////////////////////// @@ -21,6 +21,11 @@ void nema_set_protocol_version(int protocol_version) s_protocol_version = protocol_version; } +void nmea_set_gnss_id(int gnssId) +{ + s_gnssId = gnssId; +} + // Safe snprintf that prevents use of invalid size. // snprintf size (size_t) is unsigned and can wrap very large. int ssnprintf(char buf[], int bufSize, const char *fmt, ...) @@ -152,7 +157,7 @@ void talkerId_to_gnssId(const char a[], uint8_t &gnssId, uint16_t &svId, uint8_t sigId = nmea2p3_svid_to_sigId(gnssId, svIdLast); } -static int nmea_talker(char* a, int aSize, uint8_t gnssId=0) +static int nmea_talker(char* a, int aSize, uint8_t gnssId=s_gnssId) { a[0] = '$'; return gnssId_to_talkerId(a+1, gnssId) + 1; @@ -694,7 +699,8 @@ int nmea_gll(char a[], const int aSize, gps_pos_t &pos) *iD checksum data */ - int n = ssnprintf(a, aSize, "$GPGLL"); + int n = nmea_talker(a, aSize); + nmea_sprint(a, aSize, n, "GLL"); nmea_latToDegMin(a, aSize, n, pos.lla[0]); // 1,2 nmea_lonToDegMin(a, aSize, n, pos.lla[1]); // 3,4 nmea_GPSTimeOfLastFixMilliseconds(a, aSize, n, pos.timeOfWeekMs - pos.leapS*1000); // 5 @@ -739,12 +745,11 @@ int nmea_gsa(char a[], const int aSize, gps_pos_t &pos, gps_sat_t &sat) 17 = VDOP */ - int n = ssnprintf(a, aSize, "$GPGSA" - ",A" // 1 - ",%02u", // 2 - (unsigned int)fixQuality); // 1,2 + int n = nmea_talker(a, aSize); + nmea_sprint(a, aSize, n, "GSA"); + nmea_sprint(a, aSize, n, ",A,%02u", (unsigned int)fixQuality); // 1,2 - for (uint32_t i = 0; i < 12; i++) // 3-14 + for (uint32_t i = 0; i < 12; i++) // 3-14 { if(sat.sat[i].svId) { @@ -774,7 +779,8 @@ int nmea_rmc(char a[], const int aSize, gps_pos_t &pos, gps_vel_t &vel, float ma quat_ecef2ned((float)pos.lla[0], (float)pos.lla[1], qe2n); quatConjRot(vel_ned_, qe2n, vel.vel); - int n = ssnprintf(a, aSize, "$GPRMC"); + int n = nmea_talker(a, aSize); + nmea_sprint(a, aSize, n, "RMC"); nmea_GPSTimeOfLastFix(a, aSize, n, pos.timeOfWeekMs - (pos.leapS*1000)); // 1 - UTC time of last fix if((pos.status&GPS_STATUS_FIX_MASK)!=GPS_STATUS_FIX_NONE) { @@ -822,7 +828,8 @@ int nmea_zda(char a[], const int aSize, gps_pos_t &pos) *CC checksum */ - int n = ssnprintf(a, aSize, "$GPZDA"); + int n = nmea_talker(a, aSize); + nmea_sprint(a, aSize, n, "ZDA"); nmea_GPSTimeOfLastFix(a, aSize, n, pos.timeOfWeekMs - pos.leapS*1000); // 1 nmea_GPSDateOfLastFixCSV(a, aSize, n, pos); // 2,3,4 nmea_sprint(a, aSize, n, ",00,00"); // 5,6 diff --git a/src/protocol_nmea.h b/src/protocol_nmea.h index 402b997ec..8b7b0f36f 100644 --- a/src/protocol_nmea.h +++ b/src/protocol_nmea.h @@ -42,6 +42,7 @@ enum eNmeaProtocolVersion // Utility functions ////////////////////////////////////////////////////////////////////////// void nema_set_protocol_version(int protocol_version); +void nmea_set_gnss_id(int gnssId); void nmea_sprint(char buf[], int bufSize, int &offset, const char *fmt, ...); int nmea_sprint_footer(char* a, int aSize, int &n); char *ASCII_find_next_field(char *str);