Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit fd347ce

Browse files
committed
fix startingSpot issue
1 parent 0659ea9 commit fd347ce

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/SparkFun_Ublox_Arduino_Library.cpp

+20-16
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ boolean SFE_UBLOX_GPS::checkUblox()
162162
}
163163

164164
//Polls I2C for data, passing any new bytes to process()
165-
//Times out after given amount of time
166165
boolean SFE_UBLOX_GPS::checkUbloxI2C()
167166
{
168167
if (millis() - lastCheck >= I2C_POLLING_WAIT_MS)
@@ -215,7 +214,7 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
215214

216215
bytesAvailable -= bytesToRead;
217216
}
218-
} //end timed read
217+
}
219218

220219
return (true);
221220

@@ -441,12 +440,16 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
441440
}
442441
else //Load this byte into the payload array
443442
{
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;
444447
//Begin recording if counter goes past startingSpot
445-
if( (incomingUBX->counter - 4) >= incomingUBX->startingSpot)
448+
if( (incomingUBX->counter - 4) >= startingSpot)
446449
{
447450
//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
450453
}
451454
}
452455

@@ -473,16 +476,17 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
473476
if (msg->id == UBX_NAV_PVT && msg->len == 92)
474477
{
475478
//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);
486490

487491
//Mark all datums as fresh (not read before)
488492
moduleQueried.all = true;
@@ -1114,7 +1118,7 @@ boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait)
11141118
packetCfg.cls = UBX_CLASS_NAV;
11151119
packetCfg.id = UBX_NAV_PVT;
11161120
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
11181122

11191123
//The data is parsed as part of processing the response
11201124
return sendCommand(packetCfg, maxWait);

0 commit comments

Comments
 (0)