@@ -194,17 +194,6 @@ void SFE_UBLOX_GPS::process(uint8_t incoming)
194
194
processUBX (incoming, &packetAck);
195
195
else if (ubxFrameClass == CLASS_NOT_AN_ACK)
196
196
processUBX (incoming, &packetCfg);
197
- else
198
- {
199
- #ifdef DEBUG
200
- // Print this character
201
- debug.print (F (" No frame class set: " ));
202
- debug.write (incoming);
203
- debug.print (" 0x" );
204
- debug.print (incoming, HEX);
205
- debug.println ();
206
- #endif
207
- }
208
197
}
209
198
else if (currentSentence == NMEA)
210
199
{
@@ -329,18 +318,22 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
329
318
if (incomingUBX->checksumA == tempA && incomingUBX->checksumB == tempB)
330
319
{
331
320
#ifdef DEBUG
332
- debug.print (" Frame cleared : " );
321
+ debug.print (" Checksum/ Frame Good : " );
333
322
// printFrame(incomingUBX);
334
323
#endif
335
-
336
324
incomingUBX->valid = true ;
337
325
processUBXpacket (incomingUBX); // We've got a valid packet, now do something with it
338
326
}
327
+ #ifdef DEBUG
328
+ else
329
+ debug.println (" Checksum failed. Response too big?" );
330
+ #endif
331
+
339
332
}
340
333
else // Load this byte into the payload array
341
334
{
342
335
// Begin recording if counter goes past startingSpot
343
- if (incomingUBX->counter > incomingUBX->startingSpot )
336
+ if ( ( incomingUBX->counter - 4 ) > incomingUBX->startingSpot )
344
337
{
345
338
// Check to see if we have room for this byte
346
339
if ( (incomingUBX->counter - 4 ) < MAX_PAYLOAD_SIZE)
@@ -394,53 +387,46 @@ boolean SFE_UBLOX_GPS::sendCommand(ubxPacket outgoingUBX, uint16_t maxWait)
394
387
395
388
// Write header bytes
396
389
_i2cPort->beginTransmission ((uint8_t )_gpsI2Caddress); // There is no register to write to, we just begin writing data bytes
397
- _i2cPort->write (UBX_SYNCH_1);
398
- _i2cPort->write (UBX_SYNCH_2);
390
+ _i2cPort->write (UBX_SYNCH_1); // μ - oh ublox, you're funny. I will call you micro-blox from now on.
391
+ _i2cPort->write (UBX_SYNCH_2); // b
399
392
_i2cPort->write (outgoingUBX.cls );
400
393
_i2cPort->write (outgoingUBX.id );
401
394
_i2cPort->write (outgoingUBX.len & 0xFF ); // LSB
402
395
_i2cPort->write (outgoingUBX.len >> 8 ); // MSB
403
-
404
- // Normally we would endTransmission() here but instead, we check if there are more bytes to transmit.
396
+ if (_i2cPort-> endTransmission ( false ) != 0 ) // Do not release bus
397
+ return ( false ); // Sensor did not ACK
405
398
406
- // If we are sending just a command, there are no bytes to send so skip sending anything.
407
- if (outgoingUBX.len > 0 )
399
+ // Write payload. Limit the sends into 32 byte chunks
400
+ // This code based on ublox: https://forum.u-blox.com/index.php/20528/how-to-use-i2c-to-get-the-nmea-frames
401
+ uint16_t bytesToSend = outgoingUBX.len ;
402
+
403
+ // "The number of data bytes must be at least 2 to properly distinguish
404
+ // from the write access to set the address counter in random read accesses."
405
+ uint16_t startSpot = 0 ;
406
+ while (bytesToSend > 1 )
408
407
{
409
- if (_i2cPort->endTransmission (false ) != 0 ) // Do not release bus
410
- return (false ); // Sensor did not ACK
411
-
412
- // Write payload. Limit the sends into 32 byte chunks
413
- // This code based on ublox: https://forum.u-blox.com/index.php/20528/how-to-use-i2c-to-get-the-nmea-frames
414
- uint16_t bytesToSend = outgoingUBX.len ;
415
-
416
- // "The number of data bytes must be at least 2 to properly distinguish
417
- // from the write access to set the address counter in random read accesses."
418
- uint16_t startSpot = 0 ;
419
- while (bytesToSend > 1 )
420
- {
421
- uint8_t len = bytesToSend;
422
- if (len > I2C_BUFFER_LENGTH) len = I2C_BUFFER_LENGTH;
423
-
424
- _i2cPort->beginTransmission ((uint8_t )_gpsI2Caddress);
425
- // _i2cPort->write(outgoingUBX.payload, len); //Write a portion of the payload to the bus
426
-
427
- for (uint16_t x = 0 ; x < len ; x++)
428
- _i2cPort->write (outgoingUBX.payload [startSpot + x]); // Write a portion of the payload to the bus
429
-
430
- if (_i2cPort->endTransmission (false ) != 0 ) // Don't release bus
431
- return (false ); // Sensor did not ACK
432
-
433
- // *outgoingUBX.payload += len; //Move the pointer forward
434
- startSpot += len; // Move the pointer forward
435
- bytesToSend -= len;
436
- }
437
-
438
- // Write checksum
439
- _i2cPort->beginTransmission ((uint8_t )_gpsI2Caddress);
440
- if (bytesToSend == 1 ) _i2cPort->write (outgoingUBX.payload , 1 );
441
- _i2cPort->write (outgoingUBX.checksumA );
442
- _i2cPort->write (outgoingUBX.checksumB );
408
+ uint8_t len = bytesToSend;
409
+ if (len > I2C_BUFFER_LENGTH) len = I2C_BUFFER_LENGTH;
410
+
411
+ _i2cPort->beginTransmission ((uint8_t )_gpsI2Caddress);
412
+ // _i2cPort->write(outgoingUBX.payload, len); //Write a portion of the payload to the bus
413
+
414
+ for (uint16_t x = 0 ; x < len ; x++)
415
+ _i2cPort->write (outgoingUBX.payload [startSpot + x]); // Write a portion of the payload to the bus
416
+
417
+ if (_i2cPort->endTransmission (false ) != 0 ) // Don't release bus
418
+ return (false ); // Sensor did not ACK
419
+
420
+ // *outgoingUBX.payload += len; //Move the pointer forward
421
+ startSpot += len; // Move the pointer forward
422
+ bytesToSend -= len;
443
423
}
424
+
425
+ // Write checksum
426
+ _i2cPort->beginTransmission ((uint8_t )_gpsI2Caddress);
427
+ if (bytesToSend == 1 ) _i2cPort->write (outgoingUBX.payload , 1 );
428
+ _i2cPort->write (outgoingUBX.checksumA );
429
+ _i2cPort->write (outgoingUBX.checksumB );
444
430
445
431
// All done transmitting bytes. Release bus.
446
432
if (_i2cPort->endTransmission () != 0 )
@@ -694,9 +680,15 @@ uint32_t SFE_UBLOX_GPS::getPositionAccuracy(uint16_t maxWait)
694
680
tempAccuracy |= payloadCfg[26 ] << 8 *2 ;
695
681
tempAccuracy |= payloadCfg[27 ] << 8 *3 ;
696
682
683
+ Serial.print (" temp: " );
684
+ Serial.println (tempAccuracy, HEX);
685
+
697
686
if ( (tempAccuracy % 10 ) >= 5 ) tempAccuracy += 5 ; // Round fraction of mm up to next mm if .5 or above
698
687
tempAccuracy /= 10 ; // Convert 0.1mm units to mm
699
688
689
+ Serial.print (" temp: " );
690
+ Serial.println (tempAccuracy, HEX);
691
+
700
692
return (tempAccuracy);
701
693
}
702
694
// Get the current latitude in degrees
@@ -709,8 +701,7 @@ int32_t SFE_UBLOX_GPS::getLatitude(uint16_t maxWait)
709
701
packetCfg.len = 0 ;
710
702
packetCfg.startingSpot = 0 ;
711
703
712
- // if(sendCommand(packetCfg, maxWait) == false)
713
- if (sendCommand (packetCfg, 1500 ) == false )
704
+ if (sendCommand (packetCfg, maxWait) == false )
714
705
return (0 ); // If command send fails then bail
715
706
716
707
// We got a response, now parse the byte fields
@@ -807,13 +798,12 @@ uint8_t SFE_UBLOX_GPS::getProtocolVersionHigh(uint16_t maxWait)
807
798
// Then we look at each extension field of 30 bytes
808
799
for (uint8_t extensionNumber = 0 ; extensionNumber < 1 ; extensionNumber++)
809
800
{
810
- packetCfg.startingSpot = 40 + (30 *extensionNumber);
801
+ // packetCfg.startingSpot = 40 + (30*extensionNumber);
802
+ packetCfg.startingSpot = 0 ;
811
803
812
804
if (sendCommand (packetCfg, maxWait) == false )
813
805
return (0 ); // If command send fails then bail
814
806
815
- while (1 );
816
-
817
807
// Now we need to start looking for "PROTVER" in the incoming byte stream
818
808
Serial.print (" Extension: " );
819
809
for (int location ; location < 64 ; location++)
@@ -822,6 +812,9 @@ uint8_t SFE_UBLOX_GPS::getProtocolVersionHigh(uint16_t maxWait)
822
812
if (packetCfg.payload [location] == ' \0 ' ) break ;
823
813
}
824
814
Serial.println ();
815
+
816
+ while (1 );
817
+
825
818
}
826
819
827
820
return (0 );
0 commit comments