Skip to content

Commit f4c646e

Browse files
committed
Add priority control to LoRa RTCM
1 parent 1a7941c commit f4c646e

File tree

1 file changed

+44
-24
lines changed

1 file changed

+44
-24
lines changed

Firmware/RTK_Everywhere/LoRa.ino

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ void updateLora()
135135
loraState = LORA_TX;
136136
}
137137

138+
if (inBaseMode() == false)
139+
loraState = LORA_NOT_STARTED; // Force restart to move to other modes
140+
138141
break;
139142

140143
case (LORA_TX):
@@ -151,6 +154,9 @@ void updateLora()
151154
loraBytesSent = 0;
152155
}
153156
}
157+
158+
if (inBaseMode() == false)
159+
loraState = LORA_NOT_STARTED; // Force restart to move to other modes
154160
}
155161

156162
break;
@@ -163,30 +169,37 @@ void updateLora()
163169

164170
rtcmCount = Serial.readBytes(rtcmData, sizeof(rtcmData));
165171

166-
gnssPushRawData(rtcmData, rtcmCount); // Push RTCM to GNSS module
172+
// We've just received data. We assume this is RTCM and push it directly to the GNSS.
173+
// BUT we need to consider the Corrections Priorities.
174+
// Step 1: check if CORR_RADIO_LORA is registered as a correction source. If not, register it.
175+
// Step 2: check if CORR_RADIO_LORA is the highest - actually LOWEST - registered correction source.
176+
// If it is, push the data. If not, discard the data.
167177

168-
if (settings.debugLora == true)
169-
{
170-
static unsigned long lastReport = 0;
171-
static int loraRtcmCount = 0;
178+
// Step 1
179+
updateCorrectionsLastSeen(CORR_RADIO_LORA); // This will (re)register the correction source if needed
172180

173-
loraRtcmCount += rtcmCount;
181+
// Step 2
182+
if (isHighestRegisteredCorrectionsSource(CORR_RADIO_LORA))
183+
{
184+
// Pass RTCM bytes (presumably) from LoRa out ESP32-UART to GNSS
185+
gnssPushRawData(rtcmData, rtcmCount); // Push RTCM to GNSS module
174186

175-
if (millis() - lastReport > 3000)
187+
if (((settings.debugCorrections == true) || (settings.debugLora == true)) && !inMainMenu)
176188
{
177-
lastReport = millis();
178-
179189
systemFlush(); // Complete prints
180190
muxSelectUsb(); // Connect USB
181191

182-
systemPrintf("Bytes received from LoRa: %d\r\n", loraRtcmCount);
192+
systemPrintf("LoRa received %d RTCM bytes, pushed to GNSS\r\n", rtcmCount);
183193
systemFlush(); // Allow print to complete
184194

185195
muxSelectLoRa(); // Disconnect from USB
186-
187-
loraRtcmCount = 0;
188196
}
189197
}
198+
else
199+
{
200+
if ((settings.debugCorrections == true) && !inMainMenu)
201+
systemPrintf("LoRa received %d RTCM bytes, NOT pushed due to priority\r\n", rtcmCount);
202+
}
190203
}
191204

192205
if (isUsbAttached() == true) // USB cable attached, share the ESP32 UART0 connection between USB And LoRa
@@ -236,30 +249,37 @@ void updateLora()
236249

237250
rtcmCount = Serial.readBytes(rtcmData, sizeof(rtcmData));
238251

239-
gnssPushRawData(rtcmData, rtcmCount); // Push RTCM to GNSS module
252+
// We've just received data. We assume this is RTCM and push it directly to the GNSS.
253+
// BUT we need to consider the Corrections Priorities.
254+
// Step 1: check if CORR_RADIO_LORA is registered as a correction source. If not, register it.
255+
// Step 2: check if CORR_RADIO_LORA is the highest - actually LOWEST - registered correction source.
256+
// If it is, push the data. If not, discard the data.
240257

241-
if (settings.debugLora == true)
242-
{
243-
static unsigned long lastReport = 0;
244-
static int loraRtcmCount = 0;
258+
// Step 1
259+
updateCorrectionsLastSeen(CORR_RADIO_LORA); // This will (re)register the correction source if needed
245260

246-
loraRtcmCount += rtcmCount;
261+
// Step 2
262+
if (isHighestRegisteredCorrectionsSource(CORR_RADIO_LORA))
263+
{
264+
// Pass RTCM bytes (presumably) from LoRa out ESP32-UART to GNSS
265+
gnssPushRawData(rtcmData, rtcmCount); // Push RTCM to GNSS module
247266

248-
if (millis() - lastReport > 3000)
267+
if (((settings.debugCorrections == true) || (settings.debugLora == true)) && !inMainMenu)
249268
{
250-
lastReport = millis();
251-
252269
systemFlush(); // Complete prints
253270
muxSelectUsb(); // Connect USB
254271

255-
systemPrintf("Bytes received from LoRa: %d\r\n", loraRtcmCount);
272+
systemPrintf("LoRa received %d RTCM bytes, pushed to GNSS\r\n", rtcmCount);
256273
systemFlush(); // Allow print to complete
257274

258275
muxSelectLoRa(); // Disconnect from USB
259-
260-
loraRtcmCount = 0;
261276
}
262277
}
278+
else
279+
{
280+
if ((settings.debugCorrections == true) && !inMainMenu)
281+
systemPrintf("LoRa received %d RTCM bytes, NOT pushed due to priority\r\n", rtcmCount);
282+
}
263283
}
264284

265285
if (isUsbAttached() == false) // USB cable detached

0 commit comments

Comments
 (0)