Skip to content

Commit

Permalink
only generate derived GPS data when we have a valid fix
Browse files Browse the repository at this point in the history
  • Loading branch information
stronnag committed Dec 28, 2020
1 parent bac08a5 commit 78c5c94
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/blackbox_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,10 @@ void flightModeName(FILE *file) {
/**
* Print the GPS fields from the given GPS frame as comma-separated values (the GPS frame time is not printed).
*/

static double range, bearing;
static int32_t relbearing;

void outputGPSFields(flightLog_t *log, FILE *file, int64_t *frame)
{
int i;
Expand Down Expand Up @@ -629,14 +633,15 @@ void outputGPSFields(flightLog_t *log, FILE *file, int64_t *frame)

// Adding information overlay fields
if (options.mergeGPS) {
double range = 0, bearing = 0;
int32_t relbearing = 0;

if (log->sysConfig.gpsHomeLatitude != 0 && log->sysConfig.gpsHomeLongitude != 0) {
double gpsHomeLat = log->sysConfig.gpsHomeLatitude / 10000000.0;
double gpsHomeLon = log->sysConfig.gpsHomeLongitude / 10000000.0;
uint8_t fix_type = 0;

if (log->gpsFieldIndexes.GPS_fixType != -1)
fix_type = frame[log->gpsFieldIndexes.GPS_fixType];

if(currentLat != 0 && currentLon != 0) {
if(currentLat != 0 && currentLon != 0 && fix_type == 2) {
// vehichle relative makes rel bearing easier ...
bearing_distance(currentLat, currentLon, gpsHomeLat, gpsHomeLon, &range, &bearing);
relbearing = lrint(bearing) - currentCourse;
Expand Down
2 changes: 2 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ static void identifyGPSFields(flightLog_t *log, flightLogFrameDef_t *frameDef)

if (strcmp(fieldName, "time") == 0) {
log->gpsFieldIndexes.time = i;
} else if (strcmp(fieldName, "GPS_fixType") == 0) {
log->gpsFieldIndexes.GPS_fixType = i;
} else if (strcmp(fieldName, "GPS_numSat") == 0) {
log->gpsFieldIndexes.GPS_numSat = i;
} else if (strcmp(fieldName, "GPS_altitude") == 0) {
Expand Down
1 change: 1 addition & 0 deletions src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ struct flightLogPrivate_t;
*/
typedef struct gpsGFieldIndexes_t {
int time;
int GPS_fixType;
int GPS_numSat;
int GPS_coord[2];
int GPS_altitude;
Expand Down

0 comments on commit 78c5c94

Please sign in to comment.