Skip to content

Commit f14b777

Browse files
authored
Merge pull request #674 from sparkfun/PMP_Prioritization
Turn off L-Band if RTCM is received
2 parents ae04fbe + c60b0f1 commit f14b777

File tree

8 files changed

+177
-32
lines changed

8 files changed

+177
-32
lines changed

Firmware/RTK_Surveyor/NVM.ino

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@ void recordSystemSettingsToFile(File *settingsFile)
430430
settingsFile->printf("%s=%d\r\n", "gnssUartInterruptsCore", settings.gnssUartInterruptsCore);
431431
settingsFile->printf("%s=%d\r\n", "bluetoothInterruptsCore", settings.bluetoothInterruptsCore);
432432
settingsFile->printf("%s=%d\r\n", "i2cInterruptsCore", settings.i2cInterruptsCore);
433+
settingsFile->printf("%s=%d\r\n", "rtcmTimeoutBeforeUsingLBand_s", settings.rtcmTimeoutBeforeUsingLBand_s);
434+
435+
//Add new settings above
436+
//<------------------------------------------------------------>
433437
}
434438

435439
// Given a fileName, parse the file and load the given settings struct
@@ -1328,6 +1332,11 @@ bool parseLine(char *str, Settings *settings)
13281332
settings->enableNetworkFailover = d;
13291333
else if (strcmp(settingName, "printNetworkStatus") == 0)
13301334
settings->printNetworkStatus = d;
1335+
else if (strcmp(settingName, "rtcmTimeoutBeforeUsingLBand_s") == 0)
1336+
settings->rtcmTimeoutBeforeUsingLBand_s = d;
1337+
1338+
//Add new settings above
1339+
//<------------------------------------------------------------>
13311340

13321341
// Check for bulk settings (WiFi credentials, constellations, message rates, ESPNOW Peers)
13331342
// Must be last on else list

Firmware/RTK_Surveyor/NtripClient.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,9 @@ void ntripClientUpdate()
840840
// Restart the NTRIP receive data timer
841841
ntripClientTimer = millis();
842842

843+
// Record the arrival of RTCM from the WiFi connection. This resets the RTCM timeout used on the L-Band.
844+
rtcmLastPacketReceived = millis();
845+
843846
// Push RTCM to GNSS module over I2C / SPI
844847
theGNSS.pushRawData(rtcmData, rtcmCount);
845848
netIncomingRTCM = true;

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,12 @@ class SFE_UBLOX_GNSS_SUPER_DERIVED : public SFE_UBLOX_GNSS_SUPER
316316

317317
SFE_UBLOX_GNSS_SUPER_DERIVED theGNSS;
318318

319+
#ifdef COMPILE_L_BAND
320+
static SFE_UBLOX_GNSS_SUPER i2cLBand; // NEO-D9S
321+
322+
void checkRXMCOR(UBX_RXM_COR_data_t *ubxDataStruct);
323+
#endif
324+
319325
volatile struct timeval
320326
gnssSyncTv; // This holds the time the RTC was sync'd to GNSS time via Time Pulse interrupt - used by NTP
321327
struct timeval previousGnssSyncTv; // This holds the time of the previous RTC sync
@@ -360,6 +366,8 @@ int64_t ARPECEFZ = 0;
360366
uint16_t ARPECEFH = 0;
361367

362368
const byte haeNumberOfDecimals = 8; // Used for printing and transmitting lat/lon
369+
bool lBandCommunicationEnabled = false;
370+
unsigned long rtcmLastPacketReceived = 0; //Monitors the last time we received RTCM. Proctors PMP vs RTCM prioritization.
363371
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
364372

365373
// Battery fuel gauge and PWM LEDs

Firmware/RTK_Surveyor/Tasks.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ void btReadTask(void *e)
180180
btEscapeCharsReceived = 0; // Update timeout check for escape char and partial frame
181181

182182
bluetoothIncomingRTCM = true;
183+
184+
// Record the arrival of RTCM from the Bluetooth connection (a phone or tablet is providing the RTCM
185+
// via NTRIP). This resets the RTCM timeout used on the L-Band.
186+
rtcmLastPacketReceived = millis();
187+
183188
} // End just a character in the stream
184189

185190
} // End btPrintEcho == false && bluetoothRxDataAvailable()

Firmware/RTK_Surveyor/ZED.ino

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Enable data output from the NEO
2+
bool zedEnableLBandCommunication()
3+
{
4+
bool response = true;
5+
6+
#ifdef COMPILE_L_BAND
7+
8+
response &= theGNSS.setRXMCORcallbackPtr(&checkRXMCOR); // Enable callback to check if the PMP data is being decrypted successfully
9+
10+
if (productVariant == RTK_FACET_LBAND_DIRECT)
11+
{
12+
// Setup for ZED to NEO serial communication
13+
response &= theGNSS.setVal32(UBLOX_CFG_UART2INPROT_UBX, true); // Configure ZED for UBX input on UART2
14+
15+
// Disable PMP callback over I2C. Enable UARTs.
16+
response &= i2cLBand.setRXMPMPmessageCallbackPtr(nullptr); // Disable PMP callback to push raw PMP over I2C
17+
18+
response &= i2cLBand.newCfgValset();
19+
response &= i2cLBand.addCfgValset(UBLOX_CFG_MSGOUT_UBX_RXM_PMP_I2C, 0); // Disable UBX-RXM-PMP on NEO's I2C port
20+
21+
response &= i2cLBand.addCfgValset(UBLOX_CFG_UART2OUTPROT_UBX, 1); // Enable UBX output on NEO's UART2
22+
response &= i2cLBand.addCfgValset(UBLOX_CFG_MSGOUT_UBX_RXM_PMP_UART2, 1); // Output UBX-RXM-PMP on NEO's UART2
23+
response &= i2cLBand.addCfgValset(UBLOX_CFG_UART2_BAUDRATE, settings.radioPortBaud); // Match baudrate with ZED
24+
}
25+
else if (productVariant == RTK_FACET_LBAND)
26+
{
27+
// Older versions of the Facet L-Band had solder jumpers that could be closed to directly connect the NEO
28+
// to the ZED. If the user has explicitly disabled I2C corrections, enable a UART connection.
29+
if (settings.useI2cForLbandCorrections == true)
30+
{
31+
response &= theGNSS.setVal32(UBLOX_CFG_UART2INPROT_UBX, settings.enableUART2UBXIn);
32+
33+
i2cLBand.setRXMPMPmessageCallbackPtr(&pushRXMPMP); // Enable PMP callback to push raw PMP over I2C
34+
35+
response &= i2cLBand.newCfgValset();
36+
response &= i2cLBand.addCfgValset(UBLOX_CFG_MSGOUT_UBX_RXM_PMP_I2C, 1); // Enable UBX-RXM-PMP on NEO's I2C port
37+
38+
response &= i2cLBand.addCfgValset(UBLOX_CFG_UART2OUTPROT_UBX, 0); // Disable UBX output on NEO's UART2
39+
response &= i2cLBand.addCfgValset(UBLOX_CFG_MSGOUT_UBX_RXM_PMP_UART2, 0); // Disable UBX-RXM-PMP on NEO's UART2
40+
}
41+
else // Setup ZED to NEO serial communication
42+
{
43+
response &= theGNSS.setVal32(UBLOX_CFG_UART2INPROT_UBX, true); // Configure ZED for UBX input on UART2
44+
45+
i2cLBand.setRXMPMPmessageCallbackPtr(nullptr); // Disable PMP callback to push raw PMP over I2C
46+
47+
response &= i2cLBand.newCfgValset();
48+
response &= i2cLBand.addCfgValset(UBLOX_CFG_MSGOUT_UBX_RXM_PMP_I2C, 0); // Disable UBX-RXM-PMP on NEO's I2C port
49+
50+
response &= i2cLBand.addCfgValset(UBLOX_CFG_UART2OUTPROT_UBX, 1); // Enable UBX output on UART2
51+
response &= i2cLBand.addCfgValset(UBLOX_CFG_MSGOUT_UBX_RXM_PMP_UART2, 1); // Output UBX-RXM-PMP on UART2
52+
response &=
53+
i2cLBand.addCfgValset(UBLOX_CFG_UART2_BAUDRATE, settings.radioPortBaud); // Match baudrate with ZED
54+
}
55+
}
56+
else
57+
{
58+
systemPrintln("zedEnableLBandCorrections: Unknown platform");
59+
return (false);
60+
}
61+
62+
response &= i2cLBand.sendCfgValset();
63+
64+
#endif
65+
66+
return (response);
67+
}
68+
69+
// Disable data output from the NEO
70+
bool zedDisableLBandCommunication()
71+
{
72+
bool response = true;
73+
74+
#ifdef COMPILE_L_BAND
75+
response &= i2cLBand.setRXMPMPmessageCallbackPtr(nullptr); // Disable PMP callback no matter the platform
76+
response &= theGNSS.setRXMCORcallbackPtr(nullptr); // Disable callback to check if the PMP data is being decrypted successfully
77+
78+
if (productVariant == RTK_FACET_LBAND_DIRECT)
79+
{
80+
response &= i2cLBand.newCfgValset();
81+
response &= i2cLBand.addCfgValset(UBLOX_CFG_UART2OUTPROT_UBX, 0); // Disable UBX output from NEO's UART2
82+
}
83+
else if (productVariant == RTK_FACET_LBAND)
84+
{
85+
// Older versions of the Facet L-Band had solder jumpers that could be closed to directly connect the NEO
86+
// to the ZED. Check if the user has explicitly set I2C corrections.
87+
if (settings.useI2cForLbandCorrections == true)
88+
{
89+
response &= i2cLBand.newCfgValset();
90+
response &= i2cLBand.addCfgValset(UBLOX_CFG_MSGOUT_UBX_RXM_PMP_I2C, 0); // Disable UBX-RXM-PMP from NEO's I2C port
91+
}
92+
else // Setup ZED to NEO serial communication
93+
{
94+
response &= i2cLBand.newCfgValset();
95+
response &= i2cLBand.addCfgValset(UBLOX_CFG_UART2OUTPROT_UBX, 0); // Disable UBX output from NEO's UART2
96+
}
97+
}
98+
else
99+
{
100+
systemPrintln("zedEnableLBandCorrections: Unknown platform");
101+
return (false);
102+
}
103+
104+
response &= i2cLBand.sendCfgValset();
105+
106+
#endif
107+
108+
return (response);
109+
}

Firmware/RTK_Surveyor/menuPP.ino

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
#define MQTT_CERT_SIZE 2000
1010

11-
static SFE_UBLOX_GNSS_SUPER i2cLBand; // NEO-D9S
12-
1311
// The PointPerfect token is provided at compile time via build flags
1412
#ifndef POINTPERFECT_TOKEN
1513
#define POINTPERFECT_TOKEN \
@@ -1031,38 +1029,9 @@ void beginLBand()
10311029
response &=
10321030
i2cLBand.addCfgValset(UBLOX_CFG_MSGOUT_UBX_RXM_PMP_UART1, 0); // Diasable UBX-RXM-PMP on UART1. Not used.
10331031

1034-
// Determine if we should use callback to harvest/sent encrypted messages over I2C
1035-
// If not, it is assumed the ZED UART2 is directly connected to NEO UART2
1036-
if (settings.useI2cForLbandCorrections == true)
1037-
{
1038-
// Enable PMP over I2C. Disable UARTs
1039-
response &= theGNSS.setVal32(UBLOX_CFG_UART2INPROT_UBX, settings.enableUART2UBXIn);
1040-
1041-
i2cLBand.setRXMPMPmessageCallbackPtr(&pushRXMPMP); // Enable PMP callback
1042-
1043-
response &=
1044-
i2cLBand.addCfgValset(UBLOX_CFG_MSGOUT_UBX_RXM_PMP_I2C, 1); // Ensure UBX-RXM-PMP is enabled on I2C port
1045-
1046-
response &= i2cLBand.addCfgValset(UBLOX_CFG_UART2OUTPROT_UBX, 0); // Disable UBX output on UART2
1047-
response &= i2cLBand.addCfgValset(UBLOX_CFG_MSGOUT_UBX_RXM_PMP_UART2, 0); // Disable UBX-RXM-PMP on UART2
1048-
response &= i2cLBand.addCfgValset(UBLOX_CFG_UART2_BAUDRATE, settings.radioPortBaud); // match baudrate with ZED
1049-
}
1050-
else // Setup for ZED to NEO serial communication
1051-
{
1052-
response &= theGNSS.setVal32(UBLOX_CFG_UART2INPROT_UBX, true); // Configure ZED for UBX input on UART2
1053-
1054-
// Disable PMP callback over I2C. Enable UARTs.
1055-
i2cLBand.setRXMPMPmessageCallbackPtr(nullptr); // Enable PMP callback
1056-
response &= i2cLBand.addCfgValset(UBLOX_CFG_MSGOUT_UBX_RXM_PMP_I2C, 0); // Disable UBX-RXM-PMP on I2C port
1057-
1058-
response &= i2cLBand.addCfgValset(UBLOX_CFG_UART2OUTPROT_UBX, 1); // Enable UBX output on UART2
1059-
response &= i2cLBand.addCfgValset(UBLOX_CFG_MSGOUT_UBX_RXM_PMP_UART2, 1); // Output UBX-RXM-PMP on UART2
1060-
response &= i2cLBand.addCfgValset(UBLOX_CFG_UART2_BAUDRATE, settings.radioPortBaud); // match baudrate with ZED
1061-
}
1062-
10631032
response &= i2cLBand.sendCfgValset();
10641033

1065-
theGNSS.setRXMCORcallbackPtr(&checkRXMCOR); // Callback to check if the PMP data is being decrypted successfully
1034+
lBandCommunicationEnabled = zedEnableLBandCommunication();
10661035

10671036
if (response == false)
10681037
systemPrintln("L-Band failed to configure");
@@ -1277,6 +1246,28 @@ void updateLBand()
12771246
lbandTimeToFix = millis();
12781247
log_d("Time to first L-Band fix: %ds", lbandTimeToFix / 1000);
12791248
}
1249+
1250+
if ((millis() - rtcmLastPacketReceived) / 1000 > settings.rtcmTimeoutBeforeUsingLBand_s)
1251+
{
1252+
// If we have not received RTCM in a certain amount of time,
1253+
// and if communication was disabled because RTCM was being received at some point,
1254+
// re-enableL-Band communcation
1255+
if (lBandCommunicationEnabled == false)
1256+
{
1257+
log_d("Enabling L-Band communication due to RTCM timeout");
1258+
lBandCommunicationEnabled = zedEnableLBandCommunication();
1259+
}
1260+
}
1261+
else
1262+
{
1263+
// If we *have* recently received RTCM then disable corrections from then NEO-D9S L-Band receiver
1264+
if (lBandCommunicationEnabled == true)
1265+
{
1266+
log_d("Disabling L-Band communication due to RTCM reception");
1267+
lBandCommunicationEnabled = !zedDisableLBandCommunication(); //zedDisableLBandCommunication() returns true if we successfully disabled
1268+
}
1269+
}
12801270
}
1271+
12811272
#endif // COMPILE_L_BAND
12821273
}

Firmware/RTK_Surveyor/menuSystem.ino

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,8 @@ void menuOperation()
778778
systemPrint("11) Use I2C for L-Band Corrections: ");
779779
systemPrintf("%s\r\n", settings.useI2cForLbandCorrections ? "Enabled" : "Disabled");
780780

781+
systemPrintf("12) RTCM timeout before L-Band override (seconds): %d\r\n", settings.rtcmTimeoutBeforeUsingLBand_s);
782+
781783
systemPrintln("---- Interrupts ----");
782784
systemPrint("30) Bluetooth Interrupts Core: ");
783785
systemPrintln(settings.bluetoothInterruptsCore);
@@ -948,6 +950,18 @@ void menuOperation()
948950
settings.useI2cForLbandCorrectionsConfigured = true; //Record that the user has manually modified the settings.
949951
settings.useI2cForLbandCorrections ^= 1;
950952
}
953+
else if (incoming == 12)
954+
{
955+
systemPrint("Enter the number of seconds before L-Band is used once RTCM is absent (1 to 255): ");
956+
int rtcmTimeoutBeforeUsingLBand_s = getNumber(); // Returns EXIT, TIMEOUT, or long
957+
if ((rtcmTimeoutBeforeUsingLBand_s != INPUT_RESPONSE_GETNUMBER_EXIT) && (rtcmTimeoutBeforeUsingLBand_s != INPUT_RESPONSE_GETNUMBER_TIMEOUT))
958+
{
959+
if (rtcmTimeoutBeforeUsingLBand_s < 1 || rtcmTimeoutBeforeUsingLBand_s > 255)
960+
systemPrintln("Error: RTCM timeout out of range");
961+
else
962+
settings.rtcmTimeoutBeforeUsingLBand_s = rtcmTimeoutBeforeUsingLBand_s; // Recorded to NVM and file
963+
}
964+
}
951965

952966
else if (incoming == 30)
953967
{

Firmware/RTK_Surveyor/settings.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,12 @@ typedef struct
10601060
bool debugPvtServer = false;
10611061
bool enablePvtServer = false;
10621062
uint16_t pvtServerPort = 2948; // PVT server port, 2948 is GPS Daemon: http://tcp-udp-ports.com/port-2948.htm
1063+
1064+
uint8_t rtcmTimeoutBeforeUsingLBand_s = 10; //If 10s have passed without RTCM, enable PMP corrections over L-Band if available
1065+
1066+
//Add new settings above
1067+
//<------------------------------------------------------------>
1068+
10631069
} Settings;
10641070
Settings settings;
10651071

0 commit comments

Comments
 (0)