Skip to content

Commit 3c3d6ca

Browse files
committed
It's got a pulse....!
1 parent 9d0ced9 commit 3c3d6ca

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

Firmware/RTK_Everywhere/AuthCoPro.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ void beginAuthCoPro(TwoWire *i2cBus)
5151
appleAccessory->setProductPlanUID(productPlanUID);
5252

5353
// Pass the pointers for the latest NMEA data into the Accessory driver
54-
latestGPGGA = (char *)rtkMalloc(100, "AuthCoPro");
55-
latestGPRMC = (char *)rtkMalloc(100, "AuthCoPro");
56-
latestGPGST = (char *)rtkMalloc(100, "AuthCoPro");
54+
latestGPGGA = (char *)rtkMalloc(latestNmeaMaxLen, "AuthCoPro");
55+
latestGPRMC = (char *)rtkMalloc(latestNmeaMaxLen, "AuthCoPro");
56+
latestGPGST = (char *)rtkMalloc(latestNmeaMaxLen, "AuthCoPro");
5757
appleAccessory->setNMEApointers(latestGPGGA, latestGPRMC, latestGPGST);
5858

5959
// Pass the transport connected and disconnect methods into the accessory driver

Firmware/RTK_Everywhere/RTK_Everywhere.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,9 @@ static const uint8_t UUID_IAP2[] = {0x00, 0x00, 0x00, 0x00, 0xDE, 0xCA, 0xFA, 0
779779

780780
#endif
781781

782+
// Storage for the latest NMEA GPGGA/GPRMC/GPGST - to be passed to the MFi Apple device
783+
// We should optimse this with a Lee table... TODO
784+
const size_t latestNmeaMaxLen = 100;
782785
char *latestGPGGA;
783786
char *latestGPRMC;
784787
char *latestGPGST;

Firmware/RTK_Everywhere/Tasks.ino

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -623,26 +623,45 @@ void processUart1Message(SEMP_PARSE_STATE *parse, uint16_t type)
623623
}
624624
}
625625

626-
// Save GGA / RMC / GST for the authentication coprocessor
626+
// Save GGA / RMC / GST for the Apple device
627+
// We should optimse this with a Lee table... TODO
627628
if ((online.authenticationCoPro) && (type == RTK_NMEA_PARSER_INDEX))
628629
{
629630
if (strstr(sempNmeaGetSentenceName(parse), "GGA") != nullptr)
630631
{
631-
strncpy(latestGPGGA, (const char *)parse->buffer, sizeof(latestGPGGA));
632-
if ((strlen(latestGPGGA) > 10) && (latestGPGGA[strlen(latestGPGGA) - 2] == '\r'))
633-
latestGPGGA[strlen(latestGPGGA) - 2] = 0; // Truncate the \r\n
632+
if (parse->length < latestNmeaMaxLen)
633+
{
634+
memcpy(latestGPGGA, parse->buffer, parse->length);
635+
latestGPGGA[parse->length] = 0; // NULL terminate
636+
if ((strlen(latestGPGGA) > 10) && (latestGPGGA[strlen(latestGPGGA) - 2] == '\r'))
637+
latestGPGGA[strlen(latestGPGGA) - 2] = 0; // Truncate the \r\n
638+
}
639+
else
640+
systemPrintf("Increase latestNmeaMaxLen to > %d\r\n", parse->length);
634641
}
635642
else if (strstr(sempNmeaGetSentenceName(parse), "RMC") != nullptr)
636643
{
637-
strncpy(latestGPRMC, (const char *)parse->buffer, sizeof(latestGPRMC));
638-
if ((strlen(latestGPRMC) > 10) && (latestGPRMC[strlen(latestGPRMC) - 2] == '\r'))
639-
latestGPRMC[strlen(latestGPRMC) - 2] = 0; // Truncate the \r\n
644+
if (parse->length < latestNmeaMaxLen)
645+
{
646+
memcpy(latestGPRMC, parse->buffer, parse->length);
647+
latestGPRMC[parse->length] = 0; // NULL terminate
648+
if ((strlen(latestGPRMC) > 10) && (latestGPRMC[strlen(latestGPRMC) - 2] == '\r'))
649+
latestGPRMC[strlen(latestGPRMC) - 2] = 0; // Truncate the \r\n
650+
}
651+
else
652+
systemPrintf("Increase latestNmeaMaxLen to > %d\r\n", parse->length);
640653
}
641654
else if (strstr(sempNmeaGetSentenceName(parse), "GST") != nullptr)
642655
{
643-
strncpy(latestGPGST, (const char *)parse->buffer, sizeof(latestGPGST));
644-
if ((strlen(latestGPGST) > 10) && (latestGPGST[strlen(latestGPGST) - 2] == '\r'))
645-
latestGPGST[strlen(latestGPGST) - 2] = 0; // Truncate the \r\n
656+
if (parse->length < latestNmeaMaxLen)
657+
{
658+
memcpy(latestGPGST, parse->buffer, parse->length);
659+
latestGPGST[parse->length] = 0; // NULL terminate
660+
if ((strlen(latestGPGST) > 10) && (latestGPGST[strlen(latestGPGST) - 2] == '\r'))
661+
latestGPGST[strlen(latestGPGST) - 2] = 0; // Truncate the \r\n
662+
}
663+
else
664+
systemPrintf("Increase latestNmeaMaxLen to > %d\r\n", parse->length);
646665
}
647666
}
648667

0 commit comments

Comments
 (0)