Skip to content

Commit

Permalink
Actually return NMEA string with CRLF
Browse files Browse the repository at this point in the history
  • Loading branch information
makermelissa committed Mar 28, 2024
1 parent b9abc83 commit 792e13d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/NMEA_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,12 @@ char *Adafruit_GPS::build(char *nmea, const char *thisSource,
addChecksum(nmea); // Successful completion
if (!noCRLF) { // Add Carriage Return and Line Feed to comply with NMEA-183
size_t len = strlen(nmea);
char *newStr =
char *nmeaWithCRLF =
(char *)malloc(len + 3); // +2 for \r\n, +1 for null terminator
if (newStr) {
strcpy(newStr, nmea); // Copy original string
strcat(newStr, "\r\n"); // Append \r\n
if (nmeaWithCRLF) {
strcpy(nmeaWithCRLF, nmea); // Copy original string
strcat(nmeaWithCRLF, "\r\n"); // Append \r\n
return nmeaWithCRLF; // return pointer to finished product
}
}
return nmea; // return pointer to finished product
Expand Down

0 comments on commit 792e13d

Please sign in to comment.