Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPX out read logged alt in dm for Betaflight 4 #25

Merged
merged 1 commit into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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