@@ -162,7 +162,6 @@ boolean SFE_UBLOX_GPS::checkUblox()
162
162
}
163
163
164
164
// Polls I2C for data, passing any new bytes to process()
165
- // Times out after given amount of time
166
165
boolean SFE_UBLOX_GPS::checkUbloxI2C ()
167
166
{
168
167
if (millis () - lastCheck >= I2C_POLLING_WAIT_MS)
@@ -215,7 +214,7 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
215
214
216
215
bytesAvailable -= bytesToRead;
217
216
}
218
- } // end timed read
217
+ }
219
218
220
219
return (true );
221
220
@@ -441,12 +440,16 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
441
440
}
442
441
else // Load this byte into the payload array
443
442
{
443
+ // If a UBX_NAV_PVT packet comes in asynchronously, we need to fudge the startingSpot
444
+ uint16_t startingSpot = incomingUBX->startingSpot ;
445
+ if (autoPVT && incomingUBX->cls == UBX_CLASS_NAV && incomingUBX->id == UBX_NAV_PVT)
446
+ startingSpot = 20 ;
444
447
// Begin recording if counter goes past startingSpot
445
- if ( (incomingUBX->counter - 4 ) >= incomingUBX-> startingSpot )
448
+ if ( (incomingUBX->counter - 4 ) >= startingSpot)
446
449
{
447
450
// Check to see if we have room for this byte
448
- if ( ((incomingUBX->counter - 4 ) - incomingUBX-> startingSpot ) < MAX_PAYLOAD_SIZE) // If counter = 208, starting spot = 200, we're good to record.
449
- incomingUBX->payload [incomingUBX->counter - 4 - incomingUBX-> startingSpot ] = incoming; // Store this byte into payload array
451
+ if ( ((incomingUBX->counter - 4 ) - startingSpot) < MAX_PAYLOAD_SIZE) // If counter = 208, starting spot = 200, we're good to record.
452
+ incomingUBX->payload [incomingUBX->counter - 4 - startingSpot] = incoming; // Store this byte into payload array
450
453
}
451
454
}
452
455
@@ -473,16 +476,17 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
473
476
if (msg->id == UBX_NAV_PVT && msg->len == 92 )
474
477
{
475
478
// Parse various byte fields into global vars
476
- fixType = extractByte (20 - packetCfg.startingSpot );
477
- carrierSolution = extractByte (21 - packetCfg.startingSpot ) >> 6 ; // Get 6th&7th bits of this byte
478
- SIV = extractByte (23 - packetCfg.startingSpot );
479
- longitude = extractLong (24 - packetCfg.startingSpot );
480
- latitude = extractLong (28 - packetCfg.startingSpot );
481
- altitude = extractLong (32 - packetCfg.startingSpot );
482
- altitudeMSL = extractLong (36 - packetCfg.startingSpot );
483
- groundSpeed = extractLong (60 - packetCfg.startingSpot );
484
- headingOfMotion = extractLong (64 - packetCfg.startingSpot );
485
- pDOP = extractLong (76 - packetCfg.startingSpot );
479
+ constexpr int startingSpot = 20 ; // fixed value used in processUBX
480
+ fixType = extractByte (20 - startingSpot);
481
+ carrierSolution = extractByte (21 - startingSpot) >> 6 ; // Get 6th&7th bits of this byte
482
+ SIV = extractByte (23 - startingSpot);
483
+ longitude = extractLong (24 - startingSpot);
484
+ latitude = extractLong (28 - startingSpot);
485
+ altitude = extractLong (32 - startingSpot);
486
+ altitudeMSL = extractLong (36 - startingSpot);
487
+ groundSpeed = extractLong (60 - startingSpot);
488
+ headingOfMotion = extractLong (64 - startingSpot);
489
+ pDOP = extractLong (76 - startingSpot);
486
490
487
491
// Mark all datums as fresh (not read before)
488
492
moduleQueried.all = true ;
@@ -1114,7 +1118,7 @@ boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait)
1114
1118
packetCfg.cls = UBX_CLASS_NAV;
1115
1119
packetCfg.id = UBX_NAV_PVT;
1116
1120
packetCfg.len = 0 ;
1117
- packetCfg.startingSpot = 20 ; // Begin listening at spot 20 so we can record up to 20+MAX_PAYLOAD_SIZE = 84 bytes
1121
+ // packetCfg.startingSpot = 20; //Begin listening at spot 20 so we can record up to 20+MAX_PAYLOAD_SIZE = 84 bytes Note:now hard-coded in processUBX
1118
1122
1119
1123
// The data is parsed as part of processing the response
1120
1124
return sendCommand (packetCfg, maxWait);
0 commit comments