Skip to content

Commit 4b582c8

Browse files
committed
Add _signsOfLife and isNMEAHeaderValid
1 parent 0ecec8b commit 4b582c8

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

src/SparkFun_u-blox_GNSS_Arduino_Library.cpp

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ bool SFE_UBLOX_GNSS::begin(TwoWire &wirePort, uint8_t deviceAddress, uint16_t ma
442442
{
443443
commType = COMM_TYPE_I2C;
444444
_i2cPort = &wirePort; //Grab which port the user wants us to use
445+
_signsOfLife = false; //Clear the _signsOfLife flag. It will be set true if valid traffic is seen.
445446

446447
//We expect caller to begin their I2C port, with the speed of their choice external to the library
447448
//But if they forget, we start the hardware here.
@@ -485,7 +486,7 @@ bool SFE_UBLOX_GNSS::begin(TwoWire &wirePort, uint8_t deviceAddress, uint16_t ma
485486
connected = isConnected(maxWait);
486487
}
487488

488-
if ((!connected ) && assumeSuccess) // Advanced users can assume success if required. Useful if the port is outputting messages at high navigation rate.
489+
if ((!connected ) && assumeSuccess && _signsOfLife) // Advanced users can assume success if required. Useful if the port is outputting messages at high navigation rate.
489490
{
490491
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
491492
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
@@ -504,6 +505,7 @@ bool SFE_UBLOX_GNSS::begin(Stream &serialPort, uint16_t maxWait, bool assumeSucc
504505
{
505506
commType = COMM_TYPE_SERIAL;
506507
_serialPort = &serialPort; //Grab which port the user wants us to use
508+
_signsOfLife = false; //Clear the _signsOfLife flag. It will be set true if valid traffic is seen.
507509

508510
//New in v2.0: allocate memory for the packetCfg payload here - if required. (The user may have called setPacketCfgPayloadSize already)
509511
if (packetCfgPayloadSize == 0)
@@ -537,7 +539,7 @@ bool SFE_UBLOX_GNSS::begin(Stream &serialPort, uint16_t maxWait, bool assumeSucc
537539
connected = isConnected(maxWait);
538540
}
539541

540-
if ((!connected ) && assumeSuccess) // Advanced users can assume success if required. Useful if the port is outputting messages at high navigation rate.
542+
if ((!connected ) && assumeSuccess && _signsOfLife) // Advanced users can assume success if required. Useful if the port is outputting messages at high navigation rate.
541543
{
542544
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
543545
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
@@ -558,6 +560,7 @@ bool SFE_UBLOX_GNSS::begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpeed,
558560
_spiPort = &spiPort;
559561
_csPin = csPin;
560562
_spiSpeed = spiSpeed;
563+
_signsOfLife = false; //Clear the _signsOfLife flag. It will be set true if valid traffic is seen.
561564

562565
// Initialize the chip select pin
563566
pinMode(_csPin, OUTPUT);
@@ -617,7 +620,7 @@ bool SFE_UBLOX_GNSS::begin(SPIClass &spiPort, uint8_t csPin, uint32_t spiSpeed,
617620
connected = isConnected(maxWait);
618621
}
619622

620-
if ((!connected ) && assumeSuccess) // Advanced users can assume success if required. Useful if the port is outputting messages at high navigation rate.
623+
if ((!connected ) && assumeSuccess && _signsOfLife) // Advanced users can assume success if required. Useful if the port is outputting messages at high navigation rate.
621624
{
622625
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
623626
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
@@ -1637,6 +1640,11 @@ void SFE_UBLOX_GNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t r
16371640

16381641
if (nmeaByteCounter == 5)
16391642
{
1643+
if (!_signsOfLife) // If _signsOfLife is not already true, set _signsOfLife to true if the NMEA header is valid
1644+
{
1645+
_signsOfLife = isNMEAHeaderValid();
1646+
}
1647+
16401648
// We've just received the end of the address field. Check if it is selected for logging
16411649
if (logThisNMEA())
16421650
{
@@ -1710,6 +1718,38 @@ bool SFE_UBLOX_GNSS::logThisNMEA()
17101718
return (false);
17111719
}
17121720

1721+
// PRIVATE: Return true if the NMEA header is valid
1722+
bool SFE_UBLOX_GNSS::isNMEAHeaderValid()
1723+
{
1724+
if (nmeaAddressField[0] != '*') return (false);
1725+
if (nmeaAddressField[1] != 'G') return (false);
1726+
if ((nmeaAddressField[3] == 'D') && (nmeaAddressField[4] == 'T') && (nmeaAddressField[5] == 'M')) return (true);
1727+
if (nmeaAddressField[3] == 'G')
1728+
{
1729+
if ((nmeaAddressField[4] == 'A') && (nmeaAddressField[5] == 'Q')) return (true);
1730+
if ((nmeaAddressField[4] == 'B') && (nmeaAddressField[5] == 'Q')) return (true);
1731+
if ((nmeaAddressField[4] == 'B') && (nmeaAddressField[5] == 'S')) return (true);
1732+
if ((nmeaAddressField[4] == 'G') && (nmeaAddressField[5] == 'A')) return (true);
1733+
if ((nmeaAddressField[4] == 'L') && (nmeaAddressField[5] == 'L')) return (true);
1734+
if ((nmeaAddressField[4] == 'L') && (nmeaAddressField[5] == 'Q')) return (true);
1735+
if ((nmeaAddressField[4] == 'N') && (nmeaAddressField[5] == 'Q')) return (true);
1736+
if ((nmeaAddressField[4] == 'N') && (nmeaAddressField[5] == 'S')) return (true);
1737+
if ((nmeaAddressField[4] == 'P') && (nmeaAddressField[5] == 'Q')) return (true);
1738+
if ((nmeaAddressField[4] == 'Q') && (nmeaAddressField[5] == 'Q')) return (true);
1739+
if ((nmeaAddressField[4] == 'R') && (nmeaAddressField[5] == 'S')) return (true);
1740+
if ((nmeaAddressField[4] == 'S') && (nmeaAddressField[5] == 'A')) return (true);
1741+
if ((nmeaAddressField[4] == 'S') && (nmeaAddressField[5] == 'T')) return (true);
1742+
if ((nmeaAddressField[4] == 'S') && (nmeaAddressField[5] == 'V')) return (true);
1743+
}
1744+
if ((nmeaAddressField[3] == 'R') && (nmeaAddressField[4] == 'L') && (nmeaAddressField[5] == 'M')) return (true);
1745+
if ((nmeaAddressField[3] == 'R') && (nmeaAddressField[4] == 'M') && (nmeaAddressField[5] == 'C')) return (true);
1746+
if ((nmeaAddressField[3] == 'T') && (nmeaAddressField[4] == 'X') && (nmeaAddressField[5] == 'T')) return (true);
1747+
if ((nmeaAddressField[3] == 'V') && (nmeaAddressField[4] == 'L') && (nmeaAddressField[5] == 'W')) return (true);
1748+
if ((nmeaAddressField[3] == 'V') && (nmeaAddressField[4] == 'T') && (nmeaAddressField[5] == 'G')) return (true);
1749+
if ((nmeaAddressField[3] == 'Z') && (nmeaAddressField[4] == 'D') && (nmeaAddressField[5] == 'A')) return (true);
1750+
return (false);
1751+
}
1752+
17131753
// PRIVATE: Return true if we should pass this NMEA message to processNMEA
17141754
bool SFE_UBLOX_GNSS::processThisNMEA()
17151755
{
@@ -1887,6 +1927,7 @@ void SFE_UBLOX_GNSS::processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_
18871927
if ((incomingUBX->checksumA == rollingChecksumA) && (incomingUBX->checksumB == rollingChecksumB))
18881928
{
18891929
incomingUBX->valid = SFE_UBLOX_PACKET_VALIDITY_VALID; // Flag the packet as valid
1930+
_signsOfLife = true; //The checksum is valid, so set the _signsOfLife flag
18901931

18911932
// Let's check if the class and ID match the requestedClass and requestedID
18921933
// Remember - this could be a data packet or an ACK packet

src/SparkFun_u-blox_GNSS_Arduino_Library.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,7 @@ class SFE_UBLOX_GNSS
14981498
uint8_t nmeaAddressField[6]; // NMEA Address Field - includes the start character (*)
14991499
bool logThisNMEA(); // Return true if we should log this NMEA message
15001500
bool processThisNMEA(); // Return true if we should pass this NMEA message to processNMEA
1501+
bool isNMEAHeaderValid(); // Return true if the six byte NMEA header appears valid. Used to set _signsOfLife
15011502

15021503
uint16_t rtcmLen = 0;
15031504

@@ -1527,6 +1528,10 @@ class SFE_UBLOX_GNSS
15271528
bool _pushSingleByte = false;
15281529
uint8_t _pushThisSingleByte;
15291530

1531+
// .begin will return true if the assumeSuccess parameter is true and if _signsOfLife is true
1532+
// _signsOfLife is set to true when: a valid UBX message is seen; a valig NMEA header is seen.
1533+
bool _signsOfLife;
1534+
15301535
};
15311536

15321537
#endif

0 commit comments

Comments
 (0)