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

Commit e050707

Browse files
committed
Nearly working version string harvesting
1 parent 447f241 commit e050707

File tree

2 files changed

+54
-24
lines changed

2 files changed

+54
-24
lines changed

src/SparkFun_Ublox_Arduino_Library.cpp

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ void SFE_UBLOX_GPS::process(uint8_t incoming)
145145
//This is the start of a binary sentence. Reset flags.
146146
//We still don't know the response class
147147
ubxFrameCounter = 0;
148+
149+
rollingChecksumA = 0; //Reset our rolling checksums
150+
rollingChecksumB = 0;
151+
148152
currentSentence = UBX;
149153
}
150154
else if (incoming == '$')
@@ -284,6 +288,11 @@ void SFE_UBLOX_GPS::processRTCM(uint8_t incoming)
284288
//interim bytes.
285289
void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
286290
{
291+
//Add all incoming bytes to the rolling checksum
292+
//Stop at len+4 as this is the checksum bytes to that should not be added to the rolling checksum
293+
if(incomingUBX->counter < incomingUBX->len + 4)
294+
addToChecksum(incoming);
295+
287296
if (incomingUBX->counter == 0)
288297
{
289298
incomingUBX->cls = incoming;
@@ -306,19 +315,15 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
306315
}
307316
else if (incomingUBX->counter == incomingUBX->len + 5) //ChecksumB
308317
{
309-
//Validate this sentence
310-
311-
uint8_t tempA = incomingUBX->checksumA;
312-
uint8_t tempB = incoming;
313-
314-
calcChecksum(incomingUBX); //Calc checksum across this message. Results stored in message.
315-
318+
incomingUBX->checksumB = incoming;
319+
316320
currentSentence = NONE; //We're done! Reset the sentence to being looking for a new start char
317321

318-
if (incomingUBX->checksumA == tempA && incomingUBX->checksumB == tempB)
322+
//Validate this sentence
323+
if (incomingUBX->checksumA == rollingChecksumA && incomingUBX->checksumB == rollingChecksumB)
319324
{
320325
#ifdef DEBUG
321-
debug.print("Checksum/Frame Good: ");
326+
debug.println("Checksum/Frame Good");
322327
//printFrame(incomingUBX);
323328
#endif
324329
incomingUBX->valid = true;
@@ -333,11 +338,11 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
333338
else //Load this byte into the payload array
334339
{
335340
//Begin recording if counter goes past startingSpot
336-
if( (incomingUBX->counter - 4) > incomingUBX->startingSpot)
341+
if( (incomingUBX->counter - 4) >= incomingUBX->startingSpot)
337342
{
338343
//Check to see if we have room for this byte
339-
if( (incomingUBX->counter - 4) < MAX_PAYLOAD_SIZE)
340-
incomingUBX->payload[incomingUBX->counter - 4 + incomingUBX->startingSpot] = incoming; //Store this byte into payload array
344+
if( ((incomingUBX->counter - 4) - incomingUBX->startingSpot) < MAX_PAYLOAD_SIZE) //If counter = 208, starting spot = 200, we're good to record.
345+
incomingUBX->payload[incomingUBX->counter - 4 - incomingUBX->startingSpot] = incoming; //Store this byte into payload array
341346
}
342347
}
343348

@@ -449,7 +454,8 @@ boolean SFE_UBLOX_GPS::isConnected()
449454
return (true);
450455
}
451456

452-
//Given a message, calc and store the two byte "8-Bit Fletcher" checksum
457+
//Given a message, calc and store the two byte "8-Bit Fletcher" checksum over the entirety of the message
458+
//This is called before we send a command message
453459
void SFE_UBLOX_GPS::calcChecksum(ubxPacket *msg)
454460
{
455461
msg->checksumA = 0;
@@ -474,6 +480,15 @@ void SFE_UBLOX_GPS::calcChecksum(ubxPacket *msg)
474480
}
475481
}
476482

483+
//Given a message and a byte, add to rolling "8-Bit Fletcher" checksum
484+
//This is used when receiving messages from module
485+
void SFE_UBLOX_GPS::addToChecksum(uint8_t incoming)
486+
{
487+
rollingChecksumA += incoming;
488+
rollingChecksumB += rollingChecksumA;
489+
}
490+
491+
477492
//=-=-=-=-=-=-=-= Specific commands =-=-=-=-=-=-=-=
478493

479494
//Poll the module until and ack is received
@@ -794,27 +809,38 @@ uint8_t SFE_UBLOX_GPS::getProtocolVersionHigh(uint16_t maxWait)
794809
packetCfg.id = UBX_MON_VER;
795810
packetCfg.len = 0;
796811

812+
packetCfg.startingSpot = 0; //Get software version
813+
814+
if(sendCommand(packetCfg, maxWait) == false)
815+
return(0); //If command send fails then bail
816+
817+
Serial.print("Software version: ");
818+
for(int location = 0 ; location < 64 ; location++)
819+
{
820+
Serial.write(payloadCfg[location]);
821+
if(payloadCfg[location] == '\0') break;
822+
}
823+
Serial.println();
824+
825+
//while(1);
826+
797827
//We will send the command repeatedly, increasing the startingSpot as we go
798828
//Then we look at each extension field of 30 bytes
799-
for(uint8_t extensionNumber = 0 ; extensionNumber < 1 ; extensionNumber++)
829+
for(uint8_t extensionNumber = 0 ; extensionNumber < 4 ; extensionNumber++)
800830
{
801-
//packetCfg.startingSpot = 40 + (30*extensionNumber);
802-
packetCfg.startingSpot = 0;
831+
packetCfg.startingSpot = 40 + (30*extensionNumber);
803832

804833
if(sendCommand(packetCfg, maxWait) == false)
805834
return(0); //If command send fails then bail
806835

807836
//Now we need to start looking for "PROTVER" in the incoming byte stream
808837
Serial.print("Extension: ");
809-
for(int location ; location < 64 ; location++)
838+
for(int location = 0 ; location < 64 ; location++)
810839
{
811-
Serial.write(packetCfg.payload[location]);
812-
if(packetCfg.payload[location] == '\0') break;
840+
Serial.write(payloadCfg[location]);
841+
if(payloadCfg[location] == '\0') break;
813842
}
814843
Serial.println();
815-
816-
while(1);
817-
818844
}
819845

820846
return(0);

src/SparkFun_Ublox_Arduino_Library.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ typedef struct
130130
uint8_t cls;
131131
uint8_t id;
132132
uint16_t len; //Length of the payload. Does not include cls, id, or checksum bytes
133-
uint16_t counter; //Keeps track of number of overall bytes received
133+
uint16_t counter; //Keeps track of number of overall bytes received. Some responses are larger than 255 bytes.
134134
uint16_t startingSpot; //The counter value needed to go past before we begin recording into payload array
135135
uint8_t *payload;
136-
uint8_t checksumA;
136+
uint8_t checksumA; //Given to us from module. Checked against the rolling calculated A/B checksums.
137137
uint8_t checksumB;
138138
boolean valid; //Goes true when both checksums pass
139139
} ubxPacket;
@@ -247,6 +247,10 @@ class SFE_UBLOX_GPS
247247
boolean commandAck = false; //This goes true after we send a command and it's ack'd
248248
uint8_t ubxFrameCounter;
249249

250+
uint8_t rollingChecksumA; //Rolls forward as we receive incoming bytes. Checked against the last two A/B checksum bytes
251+
uint8_t rollingChecksumB; //Rolls forward as we receive incoming bytes. Checked against the last two A/B checksum bytes
252+
void addToChecksum(uint8_t incoming); //Given an incoming byte, adjust rollingChecksumA/B
253+
250254
uint16_t rtcmLen = 0;
251255
};
252256

0 commit comments

Comments
 (0)