@@ -50,6 +50,9 @@ SFE_UBLOX_GNSS::SFE_UBLOX_GNSS(void)
50
50
pinMode((uint8_t)debugPin, OUTPUT);
51
51
digitalWrite((uint8_t)debugPin, HIGH);
52
52
}
53
+
54
+ _logNMEA.all = 0; // Default to passing no NMEA messages to the file buffer
55
+ _processNMEA.all = SFE_UBLOX_FILTER_NMEA_ALL; // Default to passing all NMEA messages to processNMEA
53
56
}
54
57
55
58
//Stop all automatic message processing. Free all used RAM
@@ -1020,6 +1023,7 @@ void SFE_UBLOX_GNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t r
1020
1023
}
1021
1024
else if (incoming == '$')
1022
1025
{
1026
+ nmeaByteCounter = 0; // Reset the NMEA byte counter
1023
1027
currentSentence = NMEA;
1024
1028
}
1025
1029
else if (incoming == 0xD3) //RTCM frames start with 0xD3
@@ -1241,20 +1245,127 @@ void SFE_UBLOX_GNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t r
1241
1245
//Finally, increment the frame counter
1242
1246
ubxFrameCounter++;
1243
1247
}
1244
- else if (currentSentence == NMEA)
1248
+ else if (currentSentence == NMEA) // Process incoming NMEA mesages. Selectively log if desired.
1245
1249
{
1246
- //If _logNMEA is true, attempt to store incoming in the file buffer
1247
- if (_logNMEA)
1248
- storeFileBytes(&incoming, 1);
1250
+ if ((nmeaByteCounter == 0) && (incoming != '$'))
1251
+ {
1252
+ currentSentence = NONE; //Something went wrong. Reset. (Almost certainly redundant!)
1253
+ }
1254
+ else if ((nmeaByteCounter == 1) && (incoming != 'G'))
1255
+ {
1256
+ currentSentence = NONE; //Something went wrong. Reset.
1257
+ }
1258
+ else if ((nmeaByteCounter >= 0) && (nmeaByteCounter <= 5))
1259
+ {
1260
+ nmeaAddressField[nmeaByteCounter] = incoming; // Store the start character and NMEA address field
1261
+ }
1262
+
1263
+ if (nmeaByteCounter == 5)
1264
+ {
1265
+ // We've just received the end of the address field. Check if it is selected for logging
1266
+ if (logThisNMEA())
1267
+ {
1268
+ storeFileBytes(&nmeaAddressField[0], 6); // Add start character and address field to the file buffer
1269
+ }
1270
+ // Check if it should be passed to processNMEA
1271
+ if (processThisNMEA())
1272
+ {
1273
+ processNMEA(nmeaAddressField[0]); //Process the start character and address field
1274
+ processNMEA(nmeaAddressField[1]);
1275
+ processNMEA(nmeaAddressField[2]);
1276
+ processNMEA(nmeaAddressField[3]);
1277
+ processNMEA(nmeaAddressField[4]);
1278
+ processNMEA(nmeaAddressField[5]);
1279
+ }
1280
+ }
1281
+
1282
+ if ((nmeaByteCounter > 5) || (nmeaByteCounter < 0)) // Should we add incoming to the file buffer and/or pass it to processNMEA?
1283
+ {
1284
+ if (logThisNMEA())
1285
+ storeFileBytes(&incoming, 1); // Add incoming to the file buffer
1286
+ if (processThisNMEA())
1287
+ processNMEA(incoming); // Pass incoming to processNMEA
1288
+ }
1249
1289
1250
- processNMEA(incoming); //Process each NMEA character
1290
+ if (incoming == '*')
1291
+ nmeaByteCounter = -5; // We are expecting * plus two checksum bytes plus CR and LF
1292
+
1293
+ nmeaByteCounter++; // Increment the byte counter
1294
+
1295
+ if (nmeaByteCounter == maxNMEAByteCount) // Check if we have processed too many bytes
1296
+ currentSentence = NONE; //Something went wrong. Reset.
1297
+
1298
+ if (nmeaByteCounter == 0) // Check if we are done
1299
+ currentSentence = NONE; // All done!
1251
1300
}
1252
1301
else if (currentSentence == RTCM)
1253
1302
{
1254
1303
processRTCMframe(incoming); //Deal with RTCM bytes
1255
1304
}
1256
1305
}
1257
1306
1307
+ // PRIVATE: Return true if we should add this NMEA message to the file buffer for logging
1308
+ boolean SFE_UBLOX_GNSS::logThisNMEA()
1309
+ {
1310
+ if (_logNMEA.bits.all == 1) return (true);
1311
+ if ((nmeaAddressField[3] == 'D') && (nmeaAddressField[4] == 'T') && (nmeaAddressField[5] == 'M') && (_logNMEA.bits.UBX_NMEA_DTM == 1)) return (true);
1312
+ if (nmeaAddressField[3] == 'G')
1313
+ {
1314
+ if ((nmeaAddressField[4] == 'A') && (nmeaAddressField[5] == 'Q') && (_logNMEA.bits.UBX_NMEA_GAQ == 1)) return (true);
1315
+ if ((nmeaAddressField[4] == 'B') && (nmeaAddressField[5] == 'Q') && (_logNMEA.bits.UBX_NMEA_GBQ == 1)) return (true);
1316
+ if ((nmeaAddressField[4] == 'B') && (nmeaAddressField[5] == 'S') && (_logNMEA.bits.UBX_NMEA_GBS == 1)) return (true);
1317
+ if ((nmeaAddressField[4] == 'G') && (nmeaAddressField[5] == 'A') && (_logNMEA.bits.UBX_NMEA_GGA == 1)) return (true);
1318
+ if ((nmeaAddressField[4] == 'L') && (nmeaAddressField[5] == 'L') && (_logNMEA.bits.UBX_NMEA_GLL == 1)) return (true);
1319
+ if ((nmeaAddressField[4] == 'L') && (nmeaAddressField[5] == 'Q') && (_logNMEA.bits.UBX_NMEA_GLQ == 1)) return (true);
1320
+ if ((nmeaAddressField[4] == 'N') && (nmeaAddressField[5] == 'Q') && (_logNMEA.bits.UBX_NMEA_GNQ == 1)) return (true);
1321
+ if ((nmeaAddressField[4] == 'N') && (nmeaAddressField[5] == 'S') && (_logNMEA.bits.UBX_NMEA_GNS == 1)) return (true);
1322
+ if ((nmeaAddressField[4] == 'P') && (nmeaAddressField[5] == 'Q') && (_logNMEA.bits.UBX_NMEA_GPQ == 1)) return (true);
1323
+ if ((nmeaAddressField[4] == 'Q') && (nmeaAddressField[5] == 'Q') && (_logNMEA.bits.UBX_NMEA_GQQ == 1)) return (true);
1324
+ if ((nmeaAddressField[4] == 'R') && (nmeaAddressField[5] == 'S') && (_logNMEA.bits.UBX_NMEA_GRS == 1)) return (true);
1325
+ if ((nmeaAddressField[4] == 'S') && (nmeaAddressField[5] == 'A') && (_logNMEA.bits.UBX_NMEA_GSA == 1)) return (true);
1326
+ if ((nmeaAddressField[4] == 'S') && (nmeaAddressField[5] == 'T') && (_logNMEA.bits.UBX_NMEA_GST == 1)) return (true);
1327
+ if ((nmeaAddressField[4] == 'S') && (nmeaAddressField[5] == 'V') && (_logNMEA.bits.UBX_NMEA_GSV == 1)) return (true);
1328
+ }
1329
+ if ((nmeaAddressField[3] == 'R') && (nmeaAddressField[4] == 'L') && (nmeaAddressField[5] == 'M') && (_logNMEA.bits.UBX_NMEA_RLM == 1)) return (true);
1330
+ if ((nmeaAddressField[3] == 'R') && (nmeaAddressField[4] == 'M') && (nmeaAddressField[5] == 'C') && (_logNMEA.bits.UBX_NMEA_RMC == 1)) return (true);
1331
+ if ((nmeaAddressField[3] == 'T') && (nmeaAddressField[4] == 'X') && (nmeaAddressField[5] == 'T') && (_logNMEA.bits.UBX_NMEA_TXT == 1)) return (true);
1332
+ if ((nmeaAddressField[3] == 'V') && (nmeaAddressField[4] == 'L') && (nmeaAddressField[5] == 'W') && (_logNMEA.bits.UBX_NMEA_VLW == 1)) return (true);
1333
+ if ((nmeaAddressField[3] == 'V') && (nmeaAddressField[4] == 'T') && (nmeaAddressField[5] == 'G') && (_logNMEA.bits.UBX_NMEA_VTG == 1)) return (true);
1334
+ if ((nmeaAddressField[3] == 'Z') && (nmeaAddressField[4] == 'D') && (nmeaAddressField[5] == 'A') && (_logNMEA.bits.UBX_NMEA_ZDA == 1)) return (true);
1335
+ return (false);
1336
+ }
1337
+
1338
+ // PRIVATE: Return true if we should pass this NMEA message to processNMEA
1339
+ boolean SFE_UBLOX_GNSS::processThisNMEA()
1340
+ {
1341
+ if (_processNMEA.bits.all == 1) return (true);
1342
+ if ((nmeaAddressField[3] == 'D') && (nmeaAddressField[4] == 'T') && (nmeaAddressField[5] == 'M') && (_processNMEA.bits.UBX_NMEA_DTM == 1)) return (true);
1343
+ if (nmeaAddressField[3] == 'G')
1344
+ {
1345
+ if ((nmeaAddressField[4] == 'A') && (nmeaAddressField[5] == 'Q') && (_processNMEA.bits.UBX_NMEA_GAQ == 1)) return (true);
1346
+ if ((nmeaAddressField[4] == 'B') && (nmeaAddressField[5] == 'Q') && (_processNMEA.bits.UBX_NMEA_GBQ == 1)) return (true);
1347
+ if ((nmeaAddressField[4] == 'B') && (nmeaAddressField[5] == 'S') && (_processNMEA.bits.UBX_NMEA_GBS == 1)) return (true);
1348
+ if ((nmeaAddressField[4] == 'G') && (nmeaAddressField[5] == 'A') && (_processNMEA.bits.UBX_NMEA_GGA == 1)) return (true);
1349
+ if ((nmeaAddressField[4] == 'L') && (nmeaAddressField[5] == 'L') && (_processNMEA.bits.UBX_NMEA_GLL == 1)) return (true);
1350
+ if ((nmeaAddressField[4] == 'L') && (nmeaAddressField[5] == 'Q') && (_processNMEA.bits.UBX_NMEA_GLQ == 1)) return (true);
1351
+ if ((nmeaAddressField[4] == 'N') && (nmeaAddressField[5] == 'Q') && (_processNMEA.bits.UBX_NMEA_GNQ == 1)) return (true);
1352
+ if ((nmeaAddressField[4] == 'N') && (nmeaAddressField[5] == 'S') && (_processNMEA.bits.UBX_NMEA_GNS == 1)) return (true);
1353
+ if ((nmeaAddressField[4] == 'P') && (nmeaAddressField[5] == 'Q') && (_processNMEA.bits.UBX_NMEA_GPQ == 1)) return (true);
1354
+ if ((nmeaAddressField[4] == 'Q') && (nmeaAddressField[5] == 'Q') && (_processNMEA.bits.UBX_NMEA_GQQ == 1)) return (true);
1355
+ if ((nmeaAddressField[4] == 'R') && (nmeaAddressField[5] == 'S') && (_processNMEA.bits.UBX_NMEA_GRS == 1)) return (true);
1356
+ if ((nmeaAddressField[4] == 'S') && (nmeaAddressField[5] == 'A') && (_processNMEA.bits.UBX_NMEA_GSA == 1)) return (true);
1357
+ if ((nmeaAddressField[4] == 'S') && (nmeaAddressField[5] == 'T') && (_processNMEA.bits.UBX_NMEA_GST == 1)) return (true);
1358
+ if ((nmeaAddressField[4] == 'S') && (nmeaAddressField[5] == 'V') && (_processNMEA.bits.UBX_NMEA_GSV == 1)) return (true);
1359
+ }
1360
+ if ((nmeaAddressField[3] == 'R') && (nmeaAddressField[4] == 'L') && (nmeaAddressField[5] == 'M') && (_processNMEA.bits.UBX_NMEA_RLM == 1)) return (true);
1361
+ if ((nmeaAddressField[3] == 'R') && (nmeaAddressField[4] == 'M') && (nmeaAddressField[5] == 'C') && (_processNMEA.bits.UBX_NMEA_RMC == 1)) return (true);
1362
+ if ((nmeaAddressField[3] == 'T') && (nmeaAddressField[4] == 'X') && (nmeaAddressField[5] == 'T') && (_processNMEA.bits.UBX_NMEA_TXT == 1)) return (true);
1363
+ if ((nmeaAddressField[3] == 'V') && (nmeaAddressField[4] == 'L') && (nmeaAddressField[5] == 'W') && (_processNMEA.bits.UBX_NMEA_VLW == 1)) return (true);
1364
+ if ((nmeaAddressField[3] == 'V') && (nmeaAddressField[4] == 'T') && (nmeaAddressField[5] == 'G') && (_processNMEA.bits.UBX_NMEA_VTG == 1)) return (true);
1365
+ if ((nmeaAddressField[3] == 'Z') && (nmeaAddressField[4] == 'D') && (nmeaAddressField[5] == 'A') && (_processNMEA.bits.UBX_NMEA_ZDA == 1)) return (true);
1366
+ return (false);
1367
+ }
1368
+
1258
1369
//This is the default or generic NMEA processor. We're only going to pipe the data to serial port so we can see it.
1259
1370
//User could overwrite this function to pipe characters to nmea.process(c) of tinyGPS or MicroNMEA
1260
1371
//Or user could pipe each character to a buffer, radio, etc.
@@ -9077,12 +9188,27 @@ void SFE_UBLOX_GNSS::logHNRPVT(boolean enabled)
9077
9188
packetUBXHNRPVT->automaticFlags.flags.bits.addToFileBuffer = (uint8_t)enabled;
9078
9189
}
9079
9190
9080
- // ***** Helper Functions for NMEA Logging
9191
+ // ***** Helper Functions for NMEA Logging / Processing
9192
+
9193
+ // Log selected NMEA messages to file buffer - if the messages are enabled and if the file buffer exists
9194
+ // User needs to call setFileBufferSize before .begin
9195
+ void SFE_UBLOX_GNSS::setNMEALoggingMask(uint32_t messages)
9196
+ {
9197
+ _logNMEA.all = messages;
9198
+ }
9199
+ uint32_t SFE_UBLOX_GNSS::getNMEALoggingMask()
9200
+ {
9201
+ return (_logNMEA.all);
9202
+ }
9081
9203
9082
- //Log NMEA data in file buffer - if it exists! User needs to call setFileBufferSize before .begin
9083
- void SFE_UBLOX_GNSS::logNMEA(boolean enabled)
9204
+ // Pass selected NMEA messages to processNMEA
9205
+ void SFE_UBLOX_GNSS::setProcessNMEAMask(uint32_t messages)
9206
+ {
9207
+ _processNMEA.all = messages;
9208
+ }
9209
+ uint32_t SFE_UBLOX_GNSS::getProcessNMEAMask()
9084
9210
{
9085
- _logNMEA = enabled ;
9211
+ return (_processNMEA.all) ;
9086
9212
}
9087
9213
9088
9214
// ***** CFG RATE Helper Functions
0 commit comments