Skip to content
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
2 changes: 1 addition & 1 deletion Firmware/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ RUN arduino-cli lib install "SparkFun MAX1704x Fuel Gauge Arduino Library"@1.0.4
RUN arduino-cli lib install "SparkFun u-blox GNSS v3"@3.1.10
RUN arduino-cli lib install "SparkFun Qwiic OLED Arduino Library"@1.0.13
RUN arduino-cli lib install [email protected]
RUN arduino-cli lib install "SparkFun Extensible Message Parser"@1.0.4
RUN arduino-cli lib install "SparkFun Extensible Message Parser"@1.0.6
RUN arduino-cli lib install "SparkFun BQ40Z50 Battery Manager Arduino Library"@1.0.0
RUN arduino-cli lib install "ArduinoMqttClient"@0.1.8
RUN arduino-cli lib install "SparkFun u-blox PointPerfect Library"@1.11.4
Expand Down
96 changes: 86 additions & 10 deletions Firmware/RTK_Everywhere/Base.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,97 @@
Base.ino
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

// This function gets called when an RTCM packet passes parser check in processUart1Message() task
// Pass data along to NTRIP Server, or ESP-NOW radio
void processRTCM(uint8_t *rtcmData, uint16_t dataLength)
// Enough storage for two rounds of RTCM 1074,1084,1094,1124,1005
// To help prevent the "no increase in file size" and "due to lack of RTCM" glitch:
// RTCM is stored in PSRAM by the processUart1Message task and written by sendRTCMToConsumers
const uint8_t rtcmConsumerBufferEntries = 16;
const uint16_t rtcmConsumerBufferEntrySize = 1032; // RTCM can be up to 1024 + 6 bytes
uint16_t rtcmConsumerBufferLengths[rtcmConsumerBufferEntries];
uint8_t rtcmConsumerBufferHead;
uint8_t rtcmConsumerBufferTail;
uint8_t *rtcmConsumerBufferPtr = nullptr;

// Allocate and initialize the rtcmConsumerBuffer
bool rtcmConsumerBufferAllocated()
{
// Give this byte to the various possible transmission methods
for (int x = 0; x < dataLength; x++)
if (rtcmConsumerBufferPtr == nullptr)
{
for (int serverIndex = 0; serverIndex < NTRIP_SERVER_MAX; serverIndex++)
ntripServerProcessRTCM(serverIndex, rtcmData[x]);
rtcmConsumerBufferPtr = (uint8_t *)rtkMalloc(
(size_t)rtcmConsumerBufferEntrySize * (size_t)rtcmConsumerBufferEntries,
"ntripBuffer");
for (uint8_t i = 0; i < rtcmConsumerBufferEntries; i++)
rtcmConsumerBufferLengths[i] = 0;
rtcmConsumerBufferHead = 0;
rtcmConsumerBufferTail = 0;
}
if (rtcmConsumerBufferPtr == nullptr)
{
systemPrintln("rtcmConsumerBuffer malloc failed!");
return false;
}

return true;
}

// Store each RTCM message in a PSRAM buffer
// The messages are written to the servers by sendRTCMToConsumers
void storeRTCMForConsumers(uint8_t *rtcmData, uint16_t dataLength)
{
if (!rtcmConsumerBufferAllocated())
return;

// Check if a buffer is available
uint8_t buffersInUse = rtcmConsumerBufferHead - rtcmConsumerBufferTail;
if (buffersInUse >= rtcmConsumerBufferEntries) // Wrap if Tail is > Head
buffersInUse += rtcmConsumerBufferEntries;
if (buffersInUse < (rtcmConsumerBufferEntries - 1))
{
uint8_t *dest = rtcmConsumerBufferPtr;
dest += (size_t)rtcmConsumerBufferEntrySize * (size_t)rtcmConsumerBufferHead;
memcpy(dest, rtcmData, dataLength); // Store the RTCM
rtcmConsumerBufferLengths[rtcmConsumerBufferHead] = dataLength; // Store the length
rtcmConsumerBufferHead++; // Increment the Head
rtcmConsumerBufferHead %= rtcmConsumerBufferEntries; // Wrap
}
else
{
if (settings.debugNtripServerRtcm && (!inMainMenu))
systemPrintln("rtcmConsumerBuffer full. RTCM lost");
}
}

// Send the stored RTCM to consumers: ntripServer, LoRa and ESP-NOW
void sendRTCMToConsumers()
{
if (!rtcmConsumerBufferAllocated())
return;

while (rtcmConsumerBufferHead != rtcmConsumerBufferTail)
{
uint8_t *dest = rtcmConsumerBufferPtr;
dest += (size_t)rtcmConsumerBufferEntrySize * (size_t)rtcmConsumerBufferTail;

// NTRIP Server
for (int serverIndex = 0; serverIndex < NTRIP_SERVER_MAX; serverIndex++)
ntripServerSendRTCM(serverIndex, dest, rtcmConsumerBufferLengths[rtcmConsumerBufferTail]);

for (int x = 0; x < dataLength; x++)
espNowProcessRTCM(rtcmData[x]);
// LoRa
loraProcessRTCM(dest, rtcmConsumerBufferLengths[rtcmConsumerBufferTail]);

loraProcessRTCM(rtcmData, dataLength);
// ESP-NOW
for (uint16_t x = 0; x < rtcmConsumerBufferLengths[rtcmConsumerBufferTail]; x++)
espNowProcessRTCM(dest[x]);

rtcmConsumerBufferTail++; // Increment the Tail
rtcmConsumerBufferTail %= rtcmConsumerBufferEntries; // Wrap
}
}

// This function gets called when an RTCM packet passes parser check in processUart1Message() task
// Store data ready to be passed along to NTRIP Server, or ESP-NOW radio
void processRTCM(uint8_t *rtcmData, uint16_t dataLength)
{
storeRTCMForConsumers(rtcmData, dataLength);

rtcmLastPacketSent = millis();
rtcmPacketsSent++;
Expand Down
5 changes: 5 additions & 0 deletions Firmware/RTK_Everywhere/Begin.ino
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ void beginBoard()
pin_modeButton = 0;
// 24, D2 : Status LED
pin_baseStatusLED = 2;
//pin_debug = 2; // On EVK we can use the Status LED for debug
// 29, D5 : GNSS TP via 74LVC4066 switch
pin_GNSS_TimePulse = 5;
// 14, D12 : I2C1 SDA via 74LVC4066 switch
Expand Down Expand Up @@ -421,6 +422,10 @@ void beginBoard()
pinMode(pin_baseStatusLED, OUTPUT);
baseStatusLedOff();

DMW_if systemPrintf("pin_debug: %d\r\n", pin_debug);
pinMode(pin_debug, OUTPUT);
pinDebugOff();

DMW_if systemPrintf("pin_Cellular_Network_Indicator: %d\r\n", pin_Cellular_Network_Indicator);
pinMode(pin_Cellular_Network_Indicator, INPUT);

Expand Down
3 changes: 2 additions & 1 deletion Firmware/RTK_Everywhere/Developer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ void ntripClientSettingsChanged() {}
#ifndef COMPILE_NTRIP_SERVER
bool ntripServerIsCasting(int serverIndex) {return false;}
void ntripServerPrintStatus(int serverIndex) {systemPrintf("**NTRIP Server %d not compiled**\r\n", serverIndex);}
void ntripServerProcessRTCM(int serverIndex, uint8_t incoming) {}
void ntripServerProcessRTCM(uint8_t *rtcmData, uint16_t dataLength) {}
void ntripServerSendRTCM(int serverIndex, uint8_t *rtcmData, uint16_t dataLength) {}
void ntripServerStop(int serverIndex, bool shutdown) {online.ntripServer[serverIndex] = false;}
void ntripServerUpdate() {}
void ntripServerValidateTables() {}
Expand Down
12 changes: 12 additions & 0 deletions Firmware/RTK_Everywhere/LED.ino
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ void baseStatusLedOff()
digitalWrite(pin_baseStatusLED, LOW);
}

void pinDebugOn()
{
if (pin_debug != PIN_UNDEFINED)
digitalWrite(pin_debug, HIGH);
}

void pinDebugOff()
{
if (pin_debug != PIN_UNDEFINED)
digitalWrite(pin_debug, LOW);
}

void baseStatusLedBlink()
{
if (pin_baseStatusLED != PIN_UNDEFINED)
Expand Down
Loading