Skip to content

Commit a1814e3

Browse files
committed
Add setMainTalkerID and setHighPrecisionMode
1 parent 34b9828 commit a1814e3

File tree

5 files changed

+115
-34
lines changed

5 files changed

+115
-34
lines changed

examples/Automatic_NMEA/Example1_getLatestNMEAGPGGA/Example1_getLatestNMEAGPGGA.ino

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
1 if the data is valid but is stale (you have read it before)
1515
2 if the data is valid and fresh
1616
17+
If the module is using multiple GNSS constellations, the GGA message will be prefixed with Talker ID "GN" instead of "GP".
18+
The library includes a getLatestNMEAGNGGA function too.
19+
This example shows how to use both functions - and how to change the Talker ID so the GNGGA messages become GPGGA.
20+
1721
This example turns off all sentences except for GPGGA.
1822
1923
Feel like supporting open source hardware?
@@ -59,7 +63,13 @@ void setup()
5963
myGNSS.disableNMEAMessage(UBX_NMEA_VTG, COM_PORT_I2C);
6064
myGNSS.enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_I2C); // Leave only GGA enabled at current navigation rate
6165

62-
//myGNSS.saveConfiguration(); //Optional: Save these settings to NVM
66+
// Set the Main Talker ID to "GP". The NMEA GGA messages will be GPGGA instead of GNGGA
67+
myGNSS.setMainTalkerID(SFE_UBLOX_MAIN_TALKER_ID_GP);
68+
//myGNSS.setMainTalkerID(SFE_UBLOX_MAIN_TALKER_ID_DEFAULT); // Uncomment this line to restore the default main talker ID
69+
70+
myGNSS.setHighPrecisionMode(true); // Enable High Precision Mode - include extra decimal places in the GGA messages
71+
72+
//myGNSS.saveConfiguration(VAL_CFG_SUBSEC_IOPORT | VAL_CFG_SUBSEC_MSGCONF); //Optional: Save only the ioPort and message settings to NVM
6373

6474
Serial.println(F("Messages configured"));
6575

@@ -81,20 +91,14 @@ void loop()
8191
{
8292
Serial.println(F("GPGGA data is available but is stale"));
8393
}
84-
else if (result == 2)
94+
else // if (result == 2)
8595
{
8696
// Data contains .length and .nmea
87-
Serial.print(F("NMEA: Length: "));
97+
Serial.print(F("Latest GPGGA: Length: "));
8898
Serial.print(data.length);
8999
Serial.print(F("\tData: "));
90100
Serial.println((const char *)data.nmea); // .nmea is printable (NULL-terminated)
91101
}
92-
else
93-
{
94-
Serial.print(F("result == "));
95-
Serial.print(result);
96-
Serial.println(F(". This should be impossible!"));
97-
}
98102

99103
result = myGNSS.getLatestNMEAGNGGA(&data); // Get the latest GNGGA data (if any)
100104

@@ -106,20 +110,14 @@ void loop()
106110
{
107111
Serial.println(F("GNGGA data is available but is stale"));
108112
}
109-
else if (result == 2)
113+
else // if (result == 2)
110114
{
111115
// Data contains .length and .nmea
112-
Serial.print(F("NMEA: Length: "));
116+
Serial.print(F("Latest GNGGA: Length: "));
113117
Serial.print(data.length);
114118
Serial.print(F("\tData: "));
115119
Serial.println((const char *)data.nmea); // .nmea is printable (NULL-terminated)
116120
}
117-
else
118-
{
119-
Serial.print(F("result == "));
120-
Serial.print(result);
121-
Serial.println(F(". This should be impossible!"));
122-
}
123121

124122
delay(250);
125123
}

keywords.txt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,6 @@ initPacketUBXHNRPVT KEYWORD2
446446
flushHNRPVT KEYWORD2
447447
logHNRPVT KEYWORD2
448448

449-
setNMEALoggingMask KEYWORD2
450-
getNMEALoggingMask KEYWORD2
451-
setProcessNMEAMask KEYWORD2
452-
getProcessNMEAMask KEYWORD2
453-
454449
setNavigationFrequency KEYWORD2
455450
getNavigationFrequency KEYWORD2
456451
setMeasurementRate KEYWORD2
@@ -559,6 +554,19 @@ getHNRroll KEYWORD2
559554
getHNRpitch KEYWORD2
560555
getHNRheading KEYWORD2
561556

557+
setNMEALoggingMask KEYWORD2
558+
getNMEALoggingMask KEYWORD2
559+
setProcessNMEAMask KEYWORD2
560+
getProcessNMEAMask KEYWORD2
561+
562+
setMainTalkerID KEYWORD2
563+
setHighPrecisionMode KEYWORD2
564+
565+
getLatestNMEAGPGGA KEYWORD2
566+
setNMEAGPGGAcallback KEYWORD2
567+
getLatestNMEAGNGGA KEYWORD2
568+
setNMEAGNGGAcallback KEYWORD2
569+
562570
extractLong KEYWORD2
563571
extractSignedLong KEYWORD2
564572
extractInt KEYWORD2
@@ -745,3 +753,11 @@ SFE_UBLOX_MGA_ACK_INFOCODE_SIZE_MISMATCH LITERAL1
745753
SFE_UBLOX_MGA_ACK_INFOCODE_NOT_STORED LITERAL1
746754
SFE_UBLOX_MGA_ACK_INFOCODE_NOT_READY LITERAL1
747755
SFE_UBLOX_MGA_ACK_INFOCODE_TYPE_UNKNOWN LITERAL1
756+
757+
SFE_UBLOX_MAIN_TALKER_ID_DEFAULT LITERAL1
758+
SFE_UBLOX_MAIN_TALKER_ID_GP LITERAL1
759+
SFE_UBLOX_MAIN_TALKER_ID_GL LITERAL1
760+
SFE_UBLOX_MAIN_TALKER_ID_GN LITERAL1
761+
SFE_UBLOX_MAIN_TALKER_ID_GA LITERAL1
762+
SFE_UBLOX_MAIN_TALKER_ID_GB LITERAL1
763+
SFE_UBLOX_MAIN_TALKER_ID_GQ LITERAL1

src/SparkFun_u-blox_GNSS_Arduino_Library.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,9 @@ void SFE_UBLOX_GNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t r
17071707
{
17081708
uint8_t *lengthPtr = getNMEAWorkingLengthPtr(); // Get a pointer to the working copy length
17091709
uint8_t *nmeaPtr = getNMEAWorkingNMEAPtr(); // Get a pointer to the working copy NMEA data
1710+
uint8_t nmeaMaxLength = getNMEAMaxLength();
17101711
*lengthPtr = 6; // Set the working copy length
1712+
memset(nmeaPtr, 0, nmeaMaxLength); // Clear the working copy
17111713
memcpy(nmeaPtr, &nmeaAddressField[0], 6); // Copy the start character and address field into the working copy
17121714
}
17131715

@@ -12020,6 +12022,54 @@ void SFE_UBLOX_GNSS::logHNRPVT(bool enabled)
1202012022

1202112023
// ***** Helper Functions for NMEA Logging / Processing
1202212024

12025+
// Set the mainTalkerId used by NMEA messages - allows all NMEA messages except GSV to be prefixed with GP instead of GN
12026+
bool SFE_UBLOX_GNSS::setMainTalkerID(sfe_ublox_talker_ids_e id, uint16_t maxWait)
12027+
{
12028+
//Get the current extended NMEA protocol configuration (V1)
12029+
packetCfg.cls = UBX_CLASS_CFG;
12030+
packetCfg.id = UBX_CFG_NMEA;
12031+
packetCfg.len = 0;
12032+
packetCfg.startingSpot = 0;
12033+
12034+
//Ask module for the current settings. Loads into payloadCfg.
12035+
if (sendCommand(&packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
12036+
return (false);
12037+
12038+
payloadCfg[9] = (uint8_t)id;
12039+
12040+
packetCfg.len = 20;
12041+
packetCfg.startingSpot = 0;
12042+
12043+
return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
12044+
}
12045+
12046+
// Enable/Disable NMEA High Precision Mode - include extra decimal places in the Lat and Lon
12047+
bool SFE_UBLOX_GNSS::setHighPrecisionMode(bool enable, uint16_t maxWait)
12048+
{
12049+
//Get the current extended NMEA protocol configuration (V1)
12050+
packetCfg.cls = UBX_CLASS_CFG;
12051+
packetCfg.id = UBX_CFG_NMEA;
12052+
packetCfg.len = 0;
12053+
packetCfg.startingSpot = 0;
12054+
12055+
//Ask module for the current settings. Loads into payloadCfg.
12056+
if (sendCommand(&packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
12057+
return (false);
12058+
12059+
if (enable)
12060+
{
12061+
payloadCfg[3] |= (1 << 3); // Set the highPrec flag
12062+
payloadCfg[3] &= ~((1 << 0) | (1 << 2)); // Clear the compat and limit82 flags
12063+
}
12064+
else
12065+
payloadCfg[3] &= ~(1 << 3); // Clear the highPrec flag
12066+
12067+
packetCfg.len = 20;
12068+
packetCfg.startingSpot = 0;
12069+
12070+
return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
12071+
}
12072+
1202312073
// Log selected NMEA messages to file buffer - if the messages are enabled and if the file buffer exists
1202412074
// User needs to call setFileBufferSize before .begin
1202512075
void SFE_UBLOX_GNSS::setNMEALoggingMask(uint32_t messages)

src/SparkFun_u-blox_GNSS_Arduino_Library.h

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,18 @@ enum sfe_ublox_mga_ack_infocode_e
522522
SFE_UBLOX_MGA_ACK_INFOCODE_TYPE_UNKNOWN
523523
};
524524

525+
// The mainTalkerId, set by UBX-CFG-NMEA setMainTalkerID
526+
enum sfe_ublox_talker_ids_e
527+
{
528+
SFE_UBLOX_MAIN_TALKER_ID_DEFAULT,
529+
SFE_UBLOX_MAIN_TALKER_ID_GP,
530+
SFE_UBLOX_MAIN_TALKER_ID_GL,
531+
SFE_UBLOX_MAIN_TALKER_ID_GN,
532+
SFE_UBLOX_MAIN_TALKER_ID_GA,
533+
SFE_UBLOX_MAIN_TALKER_ID_GB,
534+
SFE_UBLOX_MAIN_TALKER_ID_GQ
535+
};
536+
525537
//-=-=-=-=-
526538

527539
#ifndef MAX_PAYLOAD_SIZE
@@ -1167,14 +1179,6 @@ class SFE_UBLOX_GNSS
11671179
void flushHNRPVT(); //Mark all the data as read/stale
11681180
void logHNRPVT(bool enabled = true); // Log data to file buffer
11691181

1170-
// Helper functions for NMEA logging
1171-
void setNMEALoggingMask(uint32_t messages = SFE_UBLOX_FILTER_NMEA_ALL); // Add selected NMEA messages to file buffer - if enabled. Default to adding ALL messages to the file buffer
1172-
uint32_t getNMEALoggingMask(); // Return which NMEA messages are selected for logging to the file buffer - if enabled
1173-
1174-
// Helper functions to control which NMEA messages are passed to processNMEA
1175-
void setProcessNMEAMask(uint32_t messages = SFE_UBLOX_FILTER_NMEA_ALL); // Control which NMEA messages are passed to processNMEA. Default to passing ALL messages
1176-
uint32_t getProcessNMEAMask(); // Return which NMEA messages are passed to processNMEA
1177-
11781182
// Helper functions for CFG RATE
11791183

11801184
bool setNavigationFrequency(uint8_t navFreq, uint16_t maxWait = defaultMaxWait); //Set the number of nav solutions sent per second
@@ -1323,8 +1327,21 @@ class SFE_UBLOX_GNSS
13231327
float getHNRpitch(uint16_t maxWait = defaultMaxWait); // Returned as degrees
13241328
float getHNRheading(uint16_t maxWait = defaultMaxWait); // Returned as degrees
13251329

1330+
// Set the mainTalkerId used by NMEA messages - allows all NMEA messages except GSV to be prefixed with GP instead of GN
1331+
bool setMainTalkerID(sfe_ublox_talker_ids_e id = SFE_UBLOX_MAIN_TALKER_ID_DEFAULT, uint16_t maxWait = defaultMaxWait);
1332+
1333+
// Enable/Disable NMEA High Precision Mode - include extra decimal places in the Lat and Lon
1334+
bool setHighPrecisionMode(bool enable = true, uint16_t maxWait = defaultMaxWait);
1335+
1336+
// Helper functions for NMEA logging
1337+
void setNMEALoggingMask(uint32_t messages = SFE_UBLOX_FILTER_NMEA_ALL); // Add selected NMEA messages to file buffer - if enabled. Default to adding ALL messages to the file buffer
1338+
uint32_t getNMEALoggingMask(); // Return which NMEA messages are selected for logging to the file buffer - if enabled
1339+
1340+
// Helper functions to control which NMEA messages are passed to processNMEA
1341+
void setProcessNMEAMask(uint32_t messages = SFE_UBLOX_FILTER_NMEA_ALL); // Control which NMEA messages are passed to processNMEA. Default to passing ALL messages
1342+
uint32_t getProcessNMEAMask(); // Return which NMEA messages are passed to processNMEA
1343+
13261344
// Support for "auto" storage of NMEA messages
1327-
13281345
uint8_t getLatestNMEAGPGGA(NMEA_GGA_data_t *data); // Return the most recent GPGGA: 0 = no data, 1 = stale data, 2 = fresh data
13291346
bool setNMEAGPGGAcallback(void (*callbackPointer)(NMEA_GGA_data_t)); //Enable a callback on the arrival of a GPGGA message
13301347
uint8_t getLatestNMEAGNGGA(NMEA_GGA_data_t *data); // Return the most recent GNGGA: 0 = no data, 1 = stale data, 2 = fresh data

src/u-blox_structs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,11 +2250,11 @@ struct nmeaAutomaticFlags
22502250
};
22512251

22522252
// The max length for NMEA messages should be 82 bytes, but GGA messages can exceed that if they include the
2253-
// extra decimal places for "High Precision".
2253+
// extra decimal places for "High Precision Mode".
22542254
//
2255-
// To be safe, let's allocate 90 bytes to store the GGA message
2255+
// To be safe, let's allocate 100 bytes to store the GGA message
22562256

2257-
const uint8_t NMEA_GGA_MAX_LENGTH = 90;
2257+
const uint8_t NMEA_GGA_MAX_LENGTH = 100;
22582258

22592259
typedef struct
22602260
{

0 commit comments

Comments
 (0)