From 25fe2b3fb07fb88e2c445519006b72c1f5fae958 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 29 Jul 2015 11:07:01 +1000 Subject: [PATCH] AP_GPS: added optional NMEA debug log compile time option for debugging --- libraries/AP_GPS/AP_GPS_NMEA.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libraries/AP_GPS/AP_GPS_NMEA.cpp b/libraries/AP_GPS/AP_GPS_NMEA.cpp index 54854898bf..eb9ccb05f6 100644 --- a/libraries/AP_GPS/AP_GPS_NMEA.cpp +++ b/libraries/AP_GPS/AP_GPS_NMEA.cpp @@ -40,6 +40,13 @@ extern const AP_HAL::HAL& hal; +// optionally log all NMEA data for debug purposes +// #define NMEA_LOG_PATH "nmea.log" + +#ifdef NMEA_LOG_PATH +#include +#endif + // SiRF init messages ////////////////////////////////////////////////////////// // // Note that we will only see a SiRF in NMEA mode if we are explicitly configured @@ -117,7 +124,17 @@ bool AP_GPS_NMEA::read(void) numc = port->available(); while (numc--) { - if (_decode(port->read())) { + char c = port->read(); +#ifdef NMEA_LOG_PATH + static FILE *logf = NULL; + if (logf == NULL) { + logf = fopen(NMEA_LOG_PATH, "wb"); + } + if (c >= 0 && logf != NULL) { + ::fwrite(&c, 1, 1, logf); + } +#endif + if (_decode(c)) { parsed = true; } }