Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user context to library #206

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,30 @@
#include <Wire.h> //Needed for I2C to GNSS

#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
SFE_UBLOX_GNSS myGNSS;

class MY_SFE_UBLOX_GNSS : public SFE_UBLOX_GNSS {

friend SFE_UBLOX_GNSS;

public:
MY_SFE_UBLOX_GNSS()
{
setUserContext(this);
}

protected:
void myProcessRTCM(uint8_t incoming)
{
//Let's just pretty-print the HEX values for now
if (rtcmFrameCounter % 16 == 0) Serial.println();
Serial.print(F(" "));
if (incoming < 0x10) Serial.print(F("0"));
Serial.print(incoming, HEX);
}

};

MY_SFE_UBLOX_GNSS myGNSS;

void setup()
{
Expand Down Expand Up @@ -156,9 +179,11 @@ void loop()
//Useful for passing the RTCM correction data to a radio, Ntrip broadcaster, etc.
void SFE_UBLOX_GNSS::processRTCM(uint8_t incoming)
{
//Let's just pretty-print the HEX values for now
if (myGNSS.rtcmFrameCounter % 16 == 0) Serial.println();
Serial.print(F(" "));
if (incoming < 0x10) Serial.print(F("0"));
Serial.print(incoming, HEX);
MY_SFE_UBLOX_GNSS *me;

// jump into our instance
if ((me = static_cast<MY_SFE_UBLOX_GNSS *>(this)) != NULL)
{
me->myProcessRTCM(incoming);
}
}
12 changes: 12 additions & 0 deletions src/SparkFun_u-blox_GNSS_Arduino_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,18 @@ size_t SFE_UBLOX_GNSS::getPacketCfgSpaceRemaining()
return (packetCfgPayloadSize - packetCfg.len);
}

// Sets user context
void SFE_UBLOX_GNSS::setUserContext(void *userContext)
{
_userContext = userContext;
}

// Retrive user context
void *SFE_UBLOX_GNSS::getUserContext(void)
{
return _userContext;
}

// Initialize the I2C port
bool SFE_UBLOX_GNSS::begin(TwoWire &wirePort, uint8_t deviceAddress, uint16_t maxWait, bool assumeSuccess)
{
Expand Down
5 changes: 5 additions & 0 deletions src/SparkFun_u-blox_GNSS_Arduino_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,10 @@ class SFE_UBLOX_GNSS
bool setPacketCfgPayloadSize(size_t payloadSize); // Set packetCfgPayloadSize
size_t getPacketCfgSpaceRemaining(); // Returns the number of free bytes remaining in packetCfgPayload

// User context
void setUserContext(void *userContext); // Sets user context
void *getUserContext(void); // Retrive user context

// Begin communication with the GNSS. Advanced users can assume success if required. Useful if the port is already outputting messages at high navigation rate.
// Begin will then return true if "signs of life" have been seen: reception of _any_ valid UBX packet or _any_ valid NMEA header.
// By default use the default I2C address, and use Wire port
Expand Down Expand Up @@ -1708,6 +1712,7 @@ class SFE_UBLOX_GNSS
SPIClass *_spiPort; // The instance of SPIClass
uint8_t _csPin; // The chip select pin
uint32_t _spiSpeed; // The speed to use for SPI (Hz)
void *_userContext; // Custom user context as callback context

uint8_t _gpsI2Caddress = 0x42; // Default 7-bit unshifted address of the ublox 6/7/8/M8/F9 series
// This can be changed using the ublox configuration software
Expand Down