From 19fd6789d5f7f411bb99cd8a103a19e4f7940a74 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 3 May 2019 01:59:25 +0000 Subject: [PATCH] GPX out read logged alt in dm for Betaflight 4 Code formatted Two spaces added Auto-formatted changes using coding standards --- src/blackbox_decode.c | 21 ++++++++++++++++++--- src/parser.c | 10 ++++++++++ src/parser.h | 2 ++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/blackbox_decode.c b/src/blackbox_decode.c index b93a755..4554a99 100644 --- a/src/blackbox_decode.c +++ b/src/blackbox_decode.c @@ -454,11 +454,26 @@ void outputGPSFields(flightLog_t *log, FILE *file, int64_t *frame) } } +int getMajorVersion(flightLog_t *log) +{ + if (!log->private->fcVersion[0]) { + return -1; //Unknown version + } + char fcVersion[30]; + strcpy(fcVersion, log->private->fcVersion); + return atoi(strtok(fcVersion, ".")); +} + /** - * Get altitude in [m] from betaflight logged [cm], including optional user altitude offset. + * Get altitude in [m] including optional user altitude offset. + * Note: Betaflight before version 4 logged altitude in [cm], since Betaflight 4 it use [dm]. */ -float getAltitude(flightLog_t *log, int64_t *frame) { - return frame[log->gpsFieldIndexes.GPS_altitude] / 100.0 + options.altOffset; //Change [cm] to [m] for gpx format +float getAltitude(flightLog_t *log, int64_t *frame) +{ + int majorFcVersion = getMajorVersion(log); + float unitFactor = majorFcVersion < 4 ? 0.01 : 0.1; //The logged altitude was changed from centimeter to decimeter since Betaflight 4.0.0.RC1 + return frame[log->gpsFieldIndexes.GPS_altitude] * unitFactor + + options.altOffset; //Change [cm] to [m] for gpx format } void outputGPSFrame(flightLog_t *log, int64_t *frame) diff --git a/src/parser.c b/src/parser.c index 432ceb0..81e51ca 100644 --- a/src/parser.c +++ b/src/parser.c @@ -392,6 +392,16 @@ static size_t parseHeaderLine(flightLog_t *log, mmapStream_t *stream, ParserStat log->sysConfig.firmwareType = FIRMWARE_TYPE_CLEANFLIGHT; else log->sysConfig.firmwareType = FIRMWARE_TYPE_BASEFLIGHT; + } else if (strcmp(fieldName, "Firmware revision") == 0) { + char fieldCopy[200]; + strcpy(fieldCopy, fieldValue); + char* fcName = strtok(fieldCopy, " "); //Read firmware name + if (!strcmp(fcName, "Betaflight")) { //Version text location known for Betaflight firmware + char* fcVersion = strtok(NULL, " "); //Firmware version text + strcpy(log->private->fcVersion, fcVersion); + } else { + log->private->fcVersion[0] = 0; //Indicate that firmware version unknown + } } else if (strcmp(fieldName, "minthrottle") == 0) { log->sysConfig.minthrottle = atoi(fieldValue); diff --git a/src/parser.h b/src/parser.h index a53da62..8cdd112 100644 --- a/src/parser.h +++ b/src/parser.h @@ -177,6 +177,8 @@ typedef struct flightLogPrivate_t { int dataVersion; + char fcVersion[30]; + // Blackbox state: int64_t blackboxHistoryRing[3][FLIGHT_LOG_MAX_FIELDS];