From 4ddbd34f9b0a041d9cb0fa4e47d2d46c7de505da Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 2 Nov 2018 10:51:17 +0000 Subject: [PATCH] Intelligently add the velocity/speed/bearing data to the APRS message. --- YSFGateway/APRSWriter.cpp | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/YSFGateway/APRSWriter.cpp b/YSFGateway/APRSWriter.cpp index ba1551b..b247e7a 100644 --- a/YSFGateway/APRSWriter.cpp +++ b/YSFGateway/APRSWriter.cpp @@ -276,20 +276,20 @@ void CAPRSWriter::sendIdFrameMobile() buffer[ret] = '\0'; // Parse the GPS data - char* p1 = ::strtok((char*)buffer, ","); // Latitude - char* p2 = ::strtok(NULL, ","); // Longitude - char* p3 = ::strtok(NULL, ","); // Altitude (m) - char* p4 = ::strtok(NULL, ","); // Speed (kms/h) - char* p5 = ::strtok(NULL, "\n"); // Bearing + 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* pBearing = ::strtok(NULL, "\n"); // Bearing - if (p1 == NULL || p2 == NULL || p3 == NULL || p4 == NULL || p5 == NULL) + if (pLatitude == NULL || pLongitude == NULL || pAltitude == NULL || pVelocity == NULL || pBearing == NULL) return; - float rawLatitude = ::atof(p1); - float rawLongitude = ::atof(p2); - float rawAltitude = ::atof(p3); - float rawSpeed = ::atof(p4); - float rawBearing = ::atof(p5); + 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) { @@ -337,12 +337,18 @@ void CAPRSWriter::sendIdFrameMobile() server.append("S"); char output[500U]; - ::sprintf(output, "%s>APDG03,TCPIP*,qAC,%s:!%s%cD%s%c&%03.0f/%03.0f/A=%06.0f%s %s", + ::sprintf(output, "%s>APDG03,TCPIP*,qAC,%s:!%s%cD%s%c&", m_callsign.c_str(), server.c_str(), lat, (rawLatitude < 0.0F) ? 'S' : 'N', - lon, (rawLongitude < 0.0F) ? 'W' : 'E', - rawBearing, rawSpeed * 0.539957F, - float(rawAltitude) * 3.28F, band, desc); + 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 (::strlen(pAltitude) > 0U) + ::sprintf(output + ::strlen(output), "/A=%06.0f", float(rawAltitude) * 3.28F); + + ::sprintf(output + ::strlen(output), "%s %s", band, desc); m_thread->write(output);