commit
f7bff30a01
|
|
@ -1,5 +1,5 @@
|
||||||
name=Adafruit GPS Library
|
name=Adafruit GPS Library
|
||||||
version=1.7.4
|
version=1.7.5
|
||||||
author=Adafruit
|
author=Adafruit
|
||||||
maintainer=Adafruit <info@adafruit.com>
|
maintainer=Adafruit <info@adafruit.com>
|
||||||
sentence=An interrupt-based GPS library for no-parsing-required use
|
sentence=An interrupt-based GPS library for no-parsing-required use
|
||||||
|
|
|
||||||
|
|
@ -351,7 +351,8 @@ char Adafruit_GPS::read(void) {
|
||||||
}
|
}
|
||||||
// Serial.print(c);
|
// Serial.print(c);
|
||||||
|
|
||||||
currentline[lineidx++] = c;
|
currentline[lineidx] = c;
|
||||||
|
lineidx = lineidx + 1;
|
||||||
if (lineidx >= MAXLINELENGTH)
|
if (lineidx >= MAXLINELENGTH)
|
||||||
lineidx = MAXLINELENGTH -
|
lineidx = MAXLINELENGTH -
|
||||||
1; // ensure there is someplace to put the next received character
|
1; // ensure there is someplace to put the next received character
|
||||||
|
|
|
||||||
|
|
@ -565,7 +565,15 @@ 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
|
||||||
sprintf(nmea, "%s\r\n", nmea);
|
size_t len = strlen(nmea);
|
||||||
|
char *nmeaWithCRLF =
|
||||||
|
(char *)malloc(len + 3); // +2 for \r\n, +1 for null terminator
|
||||||
|
if (nmeaWithCRLF) {
|
||||||
|
strcpy(nmeaWithCRLF, nmea); // Copy original string
|
||||||
|
strcat(nmeaWithCRLF, "\r\n"); // Append \r\n
|
||||||
|
strcpy(nmea, nmeaWithCRLF); // Copy back to original buffer
|
||||||
|
free(nmeaWithCRLF); // Free the allocated memory
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nmea; // return pointer to finished product
|
return nmea; // return pointer to finished product
|
||||||
}
|
}
|
||||||
|
|
@ -590,5 +598,22 @@ void Adafruit_GPS::addChecksum(char *buff) {
|
||||||
cs ^= buff[i];
|
cs ^= buff[i];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
sprintf(buff, "%s*%02X", buff, cs);
|
|
||||||
|
// Calculate the needed buffer size: original length + 3 (*XX) + 1 (null
|
||||||
|
// terminator)
|
||||||
|
int neededSize = strlen(buff) + 4;
|
||||||
|
char *tempBuffer = (char *)malloc(neededSize);
|
||||||
|
|
||||||
|
if (tempBuffer != NULL) {
|
||||||
|
// Use snprintf to safely format the string with the checksum
|
||||||
|
snprintf(tempBuffer, neededSize, "%s*%02X", buff, cs);
|
||||||
|
|
||||||
|
// Copy the formatted string back to the original buffer
|
||||||
|
// Note: Make sure the original buffer is large enough to hold the new
|
||||||
|
// string.
|
||||||
|
strcpy(buff, tempBuffer);
|
||||||
|
|
||||||
|
// Free the allocated memory to avoid memory leaks
|
||||||
|
free(tempBuffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue