Skip to content

Commit 1455fee

Browse files
committed
Add EA Session support for VTG, GSA & GSV
1 parent eb36c5a commit 1455fee

File tree

4 files changed

+61
-4
lines changed

4 files changed

+61
-4
lines changed

Firmware/RTK_Everywhere/AuthCoPro.ino

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ void beginAuthCoPro(TwoWire *i2cBus)
5555
latestGPGGA = (char *)rtkMalloc(latestNmeaMaxLen, "AuthCoPro");
5656
latestGPRMC = (char *)rtkMalloc(latestNmeaMaxLen, "AuthCoPro");
5757
latestGPGST = (char *)rtkMalloc(latestNmeaMaxLen, "AuthCoPro");
58-
appleAccessory->setNMEApointers(latestGPGGA, latestGPRMC, latestGPGST);
58+
latestGPVTG = (char *)rtkMalloc(latestNmeaMaxLen, "AuthCoPro");
59+
appleAccessory->setNMEApointers(latestGPGGA, latestGPRMC, latestGPGST, latestGPVTG);
60+
61+
// Pass the pointer for additional GSA / GSV EA Session data
62+
latestEASessionData = (char *)rtkMalloc(latestEASessionDataMaxLen, "AuthCoPro");
63+
appleAccessory->setEASessionPointer(latestEASessionData);
5964

6065
// Pass the transport connected and disconnect methods into the accessory driver
6166
appleAccessory->setTransportConnectedMethod(&transportConnected);

Firmware/RTK_Everywhere/Bluetooth.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ TaskHandle_t bluetoothCommandTaskHandle = nullptr; // Task to monitor incoming C
5454
void bluetoothUpdate()
5555
{
5656
#ifdef COMPILE_BT
57-
static uint32_t lastCheck = millis(); // Check if connected every 100ms
58-
if (millis() > (lastCheck + 100))
57+
static uint32_t lastCheck = millis(); // Check if connected every 50ms
58+
if (millis() > (lastCheck + 50))
5959
{
6060
lastCheck = millis();
6161

@@ -530,7 +530,7 @@ void bluetoothStart()
530530
//record.service_name = (char *)sdp_service_name;
531531
record.service_name_length = strlen(deviceName) + 1;
532532
record.service_name = (char *)deviceName;
533-
record.rfcomm_channel_number = 1;
533+
//record.rfcomm_channel_number = 1;
534534
esp_sdp_create_record((esp_bluetooth_sdp_record_t *)&record);
535535
}
536536
}

Firmware/RTK_Everywhere/RTK_Everywhere.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,9 @@ const size_t latestNmeaMaxLen = 100;
825825
char *latestGPGGA;
826826
char *latestGPRMC;
827827
char *latestGPGST;
828+
char *latestGPVTG;
829+
const size_t latestEASessionDataMaxLen = 4001; // 1000 * 4 plus NULL
830+
char *latestEASessionData;
828831

829832
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
830833

Firmware/RTK_Everywhere/Tasks.ino

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,55 @@ void processUart1Message(SEMP_PARSE_STATE *parse, uint16_t type)
813813
else
814814
systemPrintf("Increase latestNmeaMaxLen to > %d\r\n", parse->length);
815815
}
816+
else if (strstr(sempNmeaGetSentenceName(parse), "VTG") != nullptr)
817+
{
818+
if (parse->length < latestNmeaMaxLen)
819+
{
820+
memcpy(latestGPVTG, parse->buffer, parse->length);
821+
latestGPVTG[parse->length] = 0; // NULL terminate
822+
if ((strlen(latestGPVTG) > 10) && (latestGPVTG[strlen(latestGPVTG) - 2] == '\r'))
823+
latestGPVTG[strlen(latestGPVTG) - 2] = 0; // Truncate the \r\n
824+
forceTalkerId("P",latestGPVTG,latestNmeaMaxLen);
825+
}
826+
else
827+
systemPrintf("Increase latestNmeaMaxLen to > %d\r\n", parse->length);
828+
}
829+
else if ((strstr(sempNmeaGetSentenceName(parse), "GSA") != nullptr)
830+
|| (strstr(sempNmeaGetSentenceName(parse), "GSV") != nullptr))
831+
{
832+
// If the Apple Accessory is sending the data to the EA Session,
833+
// discard this GSA / GSV. Bad things would happen if we were to
834+
// manipulate latestEASessionData while appleAccessory is using it.
835+
if (appleAccessory->latestEASessionDataIsBlocking() == false)
836+
{
837+
size_t spaceAvailable = latestEASessionDataMaxLen - strlen(latestEASessionData);
838+
spaceAvailable -= 3; // Leave room for the CR, LF and NULL
839+
while (spaceAvailable < parse->length) // If the buffer is full, delete the oldest message(s)
840+
{
841+
const char *lfPtr = strstr(latestEASessionData, "\n"); // Find the first LF
842+
if (lfPtr == nullptr)
843+
break; // Something has gone badly wrong...
844+
lfPtr++; // Point at the byte after the LF
845+
size_t oldLen = lfPtr - latestEASessionData; // This much data is old
846+
size_t newLen = strlen(latestEASessionData) - oldLen; // This much is new (not old)
847+
for (size_t i = 0; i <= newLen; i++) // Move the new data over the old. Include the NULL
848+
latestEASessionData[i] = latestEASessionData[oldLen + i];
849+
spaceAvailable += oldLen;
850+
}
851+
size_t dataLen = strlen(latestEASessionData);
852+
memcpy(&latestEASessionData[dataLen], parse->buffer, parse->length); // Add the new NMEA data
853+
dataLen += parse->length;
854+
latestEASessionData[dataLen] = 0; // NULL terminate
855+
if (latestEASessionData[dataLen - 1] != '\n')
856+
{
857+
latestEASessionData[dataLen] = '\r'; // Add CR
858+
latestEASessionData[dataLen + 1] = '\n'; // Add LF
859+
latestEASessionData[dataLen + 2] = 0; // NULL terminate
860+
}
861+
}
862+
else if (settings.debugNetworkLayer)
863+
systemPrintf("Discarding %d GSA/GSV bytes - latestEASessionDataIsBlocking\r\n", parse->length);
864+
}
816865
}
817866

818867
// Determine if this message should be processed by the Unicore library

0 commit comments

Comments
 (0)