Skip to content

Commit

Permalink
GPX out read logged alt in dm for Betaflight 4 (#25)
Browse files Browse the repository at this point in the history
GPX out read logged alt in dm for Betaflight 4
  • Loading branch information
mikeller authored May 6, 2019
2 parents 25acb71 + 19fd678 commit 9f6ee40
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/blackbox_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ typedef struct flightLogPrivate_t
{
int dataVersion;

char fcVersion[30];

// Blackbox state:
int64_t blackboxHistoryRing[3][FLIGHT_LOG_MAX_FIELDS];

Expand Down

0 comments on commit 9f6ee40

Please sign in to comment.