Skip to content

Commit f6c01a7

Browse files
authored
Merge pull request #416 from sparkfun/Use_GNSS_Logging_Buffer
Use GNSS Library logging buffer to emulate UART1
2 parents 7a84df0 + a4881eb commit f6c01a7

29 files changed

+1426
-856
lines changed

Firmware/RTK_Surveyor/Base.ino

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ bool configureUbloxModuleBase()
1515

1616
theGNSS.checkUblox(); //Regularly poll to get latest data and any RTCM
1717

18-
theGNSS.setNMEAGPGGAcallbackPtr(nullptr); // Disable GPGGA call back that may have been set during Rover NTRIP Client mode
18+
theGNSS.setNMEAGPGGAcallbackPtr(nullptr); //Disable GPGGA call back that may have been set during Rover NTRIP Client mode
1919

2020
bool response = true;
2121

@@ -27,19 +27,31 @@ bool configureUbloxModuleBase()
2727
//Since we are at 1Hz, allow GSV NMEA to be reported at whatever the user has chosen
2828
response &= theGNSS.addCfgValset(settings.ubxMessages[8].msgConfigKey, settings.ubxMessages[8].msgRate); //Update rate on module
2929

30-
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_NMEA_ID_GGA_I2C, 0); // Disable NMEA message that may have been set during Rover NTRIP Client mode
30+
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_NMEA_ID_GGA_I2C, 0); //Disable NMEA message that may have been set during Rover NTRIP Client mode
3131

3232
//Survey mode is only available on ZED-F9P modules
3333
if (zedModuleType == PLATFORM_F9P)
3434
response &= theGNSS.addCfgValset(UBLOX_CFG_TMODE_MODE, 0); //Disable survey-in mode
3535

36-
response &= theGNSS.addCfgValset(UBLOX_CFG_NAVSPG_DYNMODEL, (dynModel)settings.dynamicModel); // Set dynamic model
36+
response &= theGNSS.addCfgValset(UBLOX_CFG_NAVSPG_DYNMODEL, (dynModel)settings.dynamicModel); //Set dynamic model
3737

38+
//RTCM is only available on ZED-F9P modules
39+
//
40+
//For most RTK products, the GNSS is interfaced via both I2C and UART1. Configuration and PVT/HPPOS messages are
41+
//configured over I2C. Any messages that need to be logged are output on UART1, and received by this code using
42+
//serialGNSS.
3843
//In base mode the RTK device should output RTCM over all ports:
3944
//(Primary) UART2 in case the Surveyor is connected via radio to rover
4045
//(Optional) I2C in case user wants base to connect to WiFi and NTRIP Caster
4146
//(Seconday) USB in case the Surveyor is used as an NTRIP caster connected to SBC or other
4247
//(Tertiary) UART1 in case Surveyor is sending RTCM to phone that is then NTRIP Caster
48+
//
49+
//But, on the Reference Station, the GNSS is interfaced via SPI. It has no access to I2C and UART1.
50+
//We use the GNSS library's built-in logging buffer to mimic UART1. The code in Tasks.ino reads
51+
//data from the logging buffer as if it had come from UART1.
52+
//So for that product - in Base mode - we can only output RTCM on SPI, USB and UART2.
53+
//If we want to log the RTCM messages, we need to add them to the logging buffer inside the GNSS library.
54+
//If we want to pass them along to (e.g.) radio, we do that using processRTCM (defined below).
4355

4456
if (USE_I2C_GNSS)
4557
{
@@ -48,7 +60,7 @@ bool configureUbloxModuleBase()
4860
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1084_I2C, 1);
4961
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1094_I2C, 1);
5062
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1124_I2C, 1);
51-
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1230_I2C, 10); //Enable message every 10 seconds
63+
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1230_I2C, 10); //Enable message every 10 cycles - note: this may conflict with settings and setMessages?
5264

5365
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1005_UART1, 1);
5466
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1074_UART1, 1);
@@ -57,14 +69,36 @@ bool configureUbloxModuleBase()
5769
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1124_UART1, 1);
5870
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1230_UART1, 10);
5971
}
60-
else
72+
else //SPI GNSS
6173
{
6274
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1005_SPI, 1);
6375
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1074_SPI, 1);
6476
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1084_SPI, 1);
6577
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1094_SPI, 1);
6678
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1124_SPI, 1);
67-
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1230_SPI, 10); //Enable message every 10 seconds
79+
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1230_SPI, 10); //Enable message every 10 cycles - note: this may conflict with settings and setMessages?
80+
81+
//Enable logging of these messages so the RTCM will be stored automatically in the logging buffer.
82+
//This mimics the data arriving via UART1.
83+
uint32_t logRTCMMessages = theGNSS.getRTCMLoggingMask();
84+
logRTCMMessages |= ( SFE_UBLOX_FILTER_RTCM_TYPE1005 | SFE_UBLOX_FILTER_RTCM_TYPE1074 | SFE_UBLOX_FILTER_RTCM_TYPE1084
85+
| SFE_UBLOX_FILTER_RTCM_TYPE1094 | SFE_UBLOX_FILTER_RTCM_TYPE1124 | SFE_UBLOX_FILTER_RTCM_TYPE1230 );
86+
theGNSS.setRTCMLoggingMask(logRTCMMessages);
87+
log_d("setRTCMLoggingMask 0x%X", logRTCMMessages);
88+
89+
//Update settings, otherwise setMessages could disable these again...
90+
for (int x = 0; x < MAX_UBX_MSG; x++)
91+
{
92+
if (settings.ubxMessages[x].msgClass == UBX_RTCM_MSB) //RTCM messages
93+
{
94+
if (settings.ubxMessages[x].filterMask & //This is quicker than checking the msgID
95+
( SFE_UBLOX_FILTER_RTCM_TYPE1005 | SFE_UBLOX_FILTER_RTCM_TYPE1074 | SFE_UBLOX_FILTER_RTCM_TYPE1084
96+
| SFE_UBLOX_FILTER_RTCM_TYPE1094 | SFE_UBLOX_FILTER_RTCM_TYPE1124))
97+
settings.ubxMessages[x].msgRate = 1;
98+
if (settings.ubxMessages[x].filterMask & SFE_UBLOX_FILTER_RTCM_TYPE1230)
99+
settings.ubxMessages[x].msgRate = 10;
100+
}
101+
}
68102
}
69103

70104
response &= theGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1005_USB, 1);

0 commit comments

Comments
 (0)