From e0d01c64c240a37c6ca95730ba4c2b1c6703d8e3 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 5 Nov 2018 19:55:36 +0000 Subject: [PATCH] Clean up GPS data parsing. --- YSFGateway/APRSWriter.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/YSFGateway/APRSWriter.cpp b/YSFGateway/APRSWriter.cpp index b247e7a..f7b3533 100644 --- a/YSFGateway/APRSWriter.cpp +++ b/YSFGateway/APRSWriter.cpp @@ -276,20 +276,18 @@ void CAPRSWriter::sendIdFrameMobile() buffer[ret] = '\0'; // Parse the GPS data - char* pLatitude = ::strtok((char*)buffer, ","); // Latitude - char* pLongitude = ::strtok(NULL, ","); // Longitude - char* pAltitude = ::strtok(NULL, ","); // Altitude (m) - char* pVelocity = ::strtok(NULL, ","); // Velocity (kms/h) + char* pLatitude = ::strtok((char*)buffer, ",\n"); // Latitude + char* pLongitude = ::strtok(NULL, ",\n"); // Longitude + char* pAltitude = ::strtok(NULL, ",\n"); // Altitude (m) + char* pVelocity = ::strtok(NULL, ",\n"); // Velocity (kms/h) char* pBearing = ::strtok(NULL, "\n"); // Bearing - if (pLatitude == NULL || pLongitude == NULL || pAltitude == NULL || pVelocity == NULL || pBearing == NULL) + if (pLatitude == NULL || pLongitude == NULL || pAltitude == NULL) return; float rawLatitude = ::atof(pLatitude); float rawLongitude = ::atof(pLongitude); float rawAltitude = ::atof(pAltitude); - float rawVelocity = ::atof(pVelocity); - float rawBearing = ::atof(pBearing); char desc[200U]; if (m_txFrequency != 0U) { @@ -342,13 +340,14 @@ void CAPRSWriter::sendIdFrameMobile() lat, (rawLatitude < 0.0F) ? 'S' : 'N', lon, (rawLongitude < 0.0F) ? 'W' : 'E'); - if (::strlen(pBearing) > 0U && ::strlen(pVelocity) > 0U) - ::sprintf(output + ::strlen(output), "%03.0f/%03.0f", rawBearing, rawVelocity * 0.539957F); + if (pBearing != NULL && pVelocity != NULL) { + float rawVelocity = ::atof(pVelocity); + float rawBearing = ::atof(pBearing); - if (::strlen(pAltitude) > 0U) - ::sprintf(output + ::strlen(output), "/A=%06.0f", float(rawAltitude) * 3.28F); + ::sprintf(output + ::strlen(output), "%03.0f/%03.0f", rawBearing, rawVelocity * 0.539957F); + } - ::sprintf(output + ::strlen(output), "%s %s", band, desc); + ::sprintf(output + ::strlen(output), "/A=%06.0f%s %s", float(rawAltitude) * 3.28F, band, desc); m_thread->write(output);