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

Commit b7e7d8a

Browse files
committed
Adding pushRawData:
pushRawData allows (e.g.) RTCM data to be pushed directly to the module Tested with updated versions of the ZED-F9P Example3 (RTCM base) and Example5 (Relative Positioning)
1 parent 864a3a5 commit b7e7d8a

File tree

5 files changed

+108
-3
lines changed

5 files changed

+108
-3
lines changed

Diff for: examples/ZED-F9P/Example3_StartRTCMBase/Example3_StartRTCMBase.ino

+17-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,19 @@
2929
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
3030
SFE_UBLOX_GPS myGPS;
3131

32+
//#define USE_SERIAL1 // Uncomment this line to push the RTCM data to Serial1
33+
3234
void setup()
3335
{
3436
Serial.begin(115200);
3537
while (!Serial); //Wait for user to open terminal
3638
Serial.println("Ublox Base station example");
3739

40+
#ifdef USE_SERIAL1
41+
// If our board supports it, we can output the RTCM data on Serial1
42+
Serial1.begin(115200);
43+
#endif
44+
3845
Wire.begin();
3946
Wire.setClock(400000); //Increase I2C clock speed to 400kHz
4047

@@ -44,8 +51,11 @@ void setup()
4451
while (1);
4552
}
4653

54+
// Uncomment the next line if you want to reset your module back to the default settings with 1Hz navigation rate
55+
//myGPS.factoryDefault(); delay(5000);
56+
4757
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
48-
myGPS.saveConfiguration(); //Save the current settings to flash and BBR
58+
myGPS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save the communications port settings to flash and BBR
4959

5060
while (Serial.available()) Serial.read(); //Clear any latent chars in serial buffer
5161
Serial.println("Press any key to send commands to begin Survey-In");
@@ -153,7 +163,12 @@ void loop()
153163
//Useful for passing the RTCM correction data to a radio, Ntrip broadcaster, etc.
154164
void SFE_UBLOX_GPS::processRTCM(uint8_t incoming)
155165
{
156-
//Let's just pretty-print the HEX values for now
166+
#ifdef USE_SERIAL1
167+
//Push the RTCM data to Serial1
168+
Serial1.write(incoming);
169+
#endif
170+
171+
//Pretty-print the HEX values to Serial
157172
if (myGPS.rtcmFrameCounter % 16 == 0) Serial.println();
158173
Serial.print(" ");
159174
if (incoming < 0x10) Serial.print("0");

Diff for: examples/ZED-F9P/Example5_RelativePositioningInformation/Example5_RelativePositioningInformation.ino

+37-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,21 @@
2626
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
2727
SFE_UBLOX_GPS myGPS;
2828

29+
//#define USE_SERIAL1 // Uncomment this line to push the RTCM data from Serial1 to the module via I2C
30+
31+
size_t numBytes = 0; // Record the number os bytes received from Serial1
32+
2933
void setup()
3034
{
3135
Serial.begin(115200);
3236
while (!Serial); //Wait for user to open terminal
3337
Serial.println("Ublox Base station example");
3438

39+
#ifdef USE_SERIAL1
40+
// If our board supports it, we can receive the RTCM data on Serial1
41+
Serial1.begin(115200);
42+
#endif
43+
3544
Wire.begin();
3645
Wire.setClock(400000); //Increase I2C clock speed to 400kHz
3746

@@ -40,6 +49,15 @@ void setup()
4049
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
4150
while (1);
4251
}
52+
53+
// Uncomment the next line if you want to reset your module back to the default settings with 1Hz navigation rate
54+
//myGPS.factoryDefault(); delay(5000);
55+
56+
#ifdef USE_SERIAL1
57+
Serial.print(F("Enabling UBX and RTCM input on I2C. Result: "));
58+
Serial.print(myGPS.setPortInput(COM_PORT_I2C, COM_TYPE_UBX | COM_TYPE_RTCM3)); //Enable UBX and RTCM input on I2C
59+
myGPS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save the communications port settings to flash and BBR
60+
#endif
4361
}
4462

4563
void loop()
@@ -121,5 +139,23 @@ void loop()
121139
else
122140
Serial.println("RELPOS request failed");
123141

124-
delay(4000);
142+
for (int i = 0; i < 500; i++)
143+
{
144+
#ifdef USE_SERIAL1
145+
uint8_t store[256];
146+
while ((Serial1.available()) && (numBytes < 256)) // Check if data has been received
147+
{
148+
store[numBytes++] = Serial1.read(); // Read a byte from Serial1 and store it
149+
}
150+
if (numBytes > 0) // Check if data was received
151+
{
152+
//Serial.print("Pushing ");
153+
//Serial.print(numBytes);
154+
//Serial.println(" bytes via I2C");
155+
myGPS.pushRawData(((uint8_t *)&store), numBytes); // Push the RTCM data via I2C
156+
numBytes = 0; // Reset numBytes
157+
}
158+
#endif
159+
delay(10);
160+
}
125161
}

Diff for: keywords.txt

+2
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ getI2CTransactionSize KEYWORD2
173173

174174
setStaticPosition KEYWORD2
175175

176+
pushRawData KEYWORD2
177+
176178
#######################################
177179
# Constants (LITERAL1)
178180
#######################################

Diff for: src/SparkFun_Ublox_Arduino_Library.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -4197,3 +4197,51 @@ bool SFE_UBLOX_GPS::setStaticPosition(int32_t ecefXOrLat, int32_t ecefYOrLon, in
41974197
{
41984198
return (setStaticPosition(ecefXOrLat, 0, ecefYOrLon, 0, ecefZOrAlt, 0, latlong, maxWait));
41994199
}
4200+
4201+
// Push (e.g.) RTCM data directly to the module
4202+
// Returns true if all numDataBytes were pushed successfully
4203+
// Warning: this function does not check that the data is valid. It is the user's responsibility to ensure the data is valid before pushing.
4204+
boolean SFE_UBLOX_GPS::pushRawData(uint8_t *dataBytes, size_t numDataBytes)
4205+
{
4206+
if (commType == COMM_TYPE_SERIAL)
4207+
{
4208+
// Serial: write all the bytes in one go
4209+
size_t bytesWritten = _serialPort->write(dataBytes, numDataBytes);
4210+
return (bytesWritten == numDataBytes);
4211+
}
4212+
else
4213+
{
4214+
// I2C: split the data up into packets of i2cTransactionSize
4215+
size_t bytesLeftToWrite = numDataBytes;
4216+
size_t bytesWrittenTotal = 0;
4217+
4218+
while (bytesLeftToWrite > 0)
4219+
{
4220+
size_t bytesToWrite; // Limit bytesToWrite to i2cTransactionSize
4221+
if (bytesLeftToWrite > i2cTransactionSize)
4222+
bytesToWrite = i2cTransactionSize;
4223+
else
4224+
bytesToWrite = bytesLeftToWrite;
4225+
4226+
_i2cPort->beginTransmission(_gpsI2Caddress);
4227+
size_t bytesWritten = _i2cPort->write(dataBytes, bytesToWrite); // Write the bytes
4228+
4229+
bytesWrittenTotal += bytesWritten; // Update the totals
4230+
bytesLeftToWrite -= bytesToWrite;
4231+
dataBytes += bytesToWrite; // Point to fresh data
4232+
4233+
if (bytesLeftToWrite > 0)
4234+
{
4235+
if (_i2cPort->endTransmission(false) != 0) //Send a restart command. Do not release bus.
4236+
return (false); //Sensor did not ACK
4237+
}
4238+
else
4239+
{
4240+
if (_i2cPort->endTransmission() != 0) //We're done. Release bus.
4241+
return (false); //Sensor did not ACK
4242+
}
4243+
}
4244+
4245+
return (bytesWrittenTotal == numDataBytes);
4246+
}
4247+
}

Diff for: src/SparkFun_Ublox_Arduino_Library.h

+4
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,10 @@ class SFE_UBLOX_GPS
666666
bool setStaticPosition(int32_t ecefXOrLat, int8_t ecefXOrLatHP, int32_t ecefYOrLon, int8_t ecefYOrLonHP, int32_t ecefZOrAlt, int8_t ecefZOrAltHP, bool latLong = false, uint16_t maxWait = 250);
667667
bool setStaticPosition(int32_t ecefXOrLat, int32_t ecefYOrLon, int32_t ecefZOrAlt, bool latLong = false, uint16_t maxWait = 250);
668668

669+
// Push (e.g.) RTCM data directly to the module
670+
// Warning: this function does not check that the data is valid. It is the user's responsibility to ensure the data is valid before pushing.
671+
boolean pushRawData(uint8_t *dataBytes, size_t numDataBytes);
672+
669673
//Survey-in specific controls
670674
struct svinStructure
671675
{

0 commit comments

Comments
 (0)