Actually return NMEA string with CRLF

This commit is contained in:
Melissa LeBlanc-Williams 2024-03-28 08:25:16 -07:00
parent b9abc83581
commit 792e13d2b2
1 changed files with 5 additions and 4 deletions

View File

@ -566,11 +566,12 @@ char *Adafruit_GPS::build(char *nmea, const char *thisSource,
addChecksum(nmea); // Successful completion addChecksum(nmea); // Successful completion
if (!noCRLF) { // Add Carriage Return and Line Feed to comply with NMEA-183 if (!noCRLF) { // Add Carriage Return and Line Feed to comply with NMEA-183
size_t len = strlen(nmea); size_t len = strlen(nmea);
char *newStr = char *nmeaWithCRLF =
(char *)malloc(len + 3); // +2 for \r\n, +1 for null terminator (char *)malloc(len + 3); // +2 for \r\n, +1 for null terminator
if (newStr) { if (nmeaWithCRLF) {
strcpy(newStr, nmea); // Copy original string strcpy(nmeaWithCRLF, nmea); // Copy original string
strcat(newStr, "\r\n"); // Append \r\n strcat(nmeaWithCRLF, "\r\n"); // Append \r\n
return nmeaWithCRLF; // return pointer to finished product
} }
} }
return nmea; // return pointer to finished product return nmea; // return pointer to finished product