From 337ddc2b75edc36a5f5abc7210dbb0ac1ffb5c32 Mon Sep 17 00:00:00 2001 From: Jonathan Hudson Date: Mon, 28 Dec 2020 17:22:35 +0000 Subject: [PATCH 1/3] fix win32 compiler warnings --- src/parser.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/parser.c b/src/parser.c index ad53cbe..185b7f4 100644 --- a/src/parser.c +++ b/src/parser.c @@ -842,16 +842,15 @@ static void parseGPSHomeFrame(flightLog_t *log, mmapStream_t *stream, bool raw) { int64_t jmplat; int64_t jmplon; - jmplat = labs(log->private->gpsHomeHistory[0][log->gpsHomeFieldIndexes.GPS_home[0]] - + jmplat = llabs(log->private->gpsHomeHistory[0][log->gpsHomeFieldIndexes.GPS_home[0]] - log->private->gpsHomeHistory[1][log->gpsHomeFieldIndexes.GPS_home[0]]); - jmplon = labs(log->private->gpsHomeHistory[0][log->gpsHomeFieldIndexes.GPS_home[1]] - + jmplon = llabs(log->private->gpsHomeHistory[0][log->gpsHomeFieldIndexes.GPS_home[1]] - log->private->gpsHomeHistory[1][log->gpsHomeFieldIndexes.GPS_home[1]]); - -#define DEGJMP500M 45000 // 1*7 degrees equating to c. 500m latitude (or equator longitude) +#define DEGJMP2M 450000 // 1*7 degrees equating to c. 5000m latitude (or equator longitude) // if you're at at a pole with will divide by 0, possibly the least of your problems. - int64_t jmplonlimit = (int64_t) (45000 / cos((M_PI/180.0) * (log->private->gpsHomeHistory[0][log->gpsHomeFieldIndexes.GPS_home[1]]/ 10000000.0))); - if (jmplat > 45000 || jmplon > jmplonlimit) { + int64_t jmplonlimit = (int64_t) (DEGJMP2M / cos((M_PI/180.0) * (log->private->gpsHomeHistory[0][log->gpsHomeFieldIndexes.GPS_home[1]]/ 10000000.0))); + if (jmplat > DEGJMP2M || jmplon > jmplonlimit) { sethome = false; } } From bac08a5bd185faf1ce2243233074083b7f5695d8 Mon Sep 17 00:00:00 2001 From: Jonathan Hudson Date: Mon, 28 Dec 2020 17:29:07 +0000 Subject: [PATCH 2/3] revert home limit relax else it fails on broken files --- src/parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser.c b/src/parser.c index 185b7f4..7d2a655 100644 --- a/src/parser.c +++ b/src/parser.c @@ -847,7 +847,7 @@ static void parseGPSHomeFrame(flightLog_t *log, mmapStream_t *stream, bool raw) jmplon = llabs(log->private->gpsHomeHistory[0][log->gpsHomeFieldIndexes.GPS_home[1]] - log->private->gpsHomeHistory[1][log->gpsHomeFieldIndexes.GPS_home[1]]); -#define DEGJMP2M 450000 // 1*7 degrees equating to c. 5000m latitude (or equator longitude) +#define DEGJMP2M 45000 // 1*7 degrees equating to c. 500m latitude (or equator longitude) // if you're at at a pole with will divide by 0, possibly the least of your problems. int64_t jmplonlimit = (int64_t) (DEGJMP2M / cos((M_PI/180.0) * (log->private->gpsHomeHistory[0][log->gpsHomeFieldIndexes.GPS_home[1]]/ 10000000.0))); if (jmplat > DEGJMP2M || jmplon > jmplonlimit) { From 78c5c9436cbbe0891ba5955febd1a771deb36949 Mon Sep 17 00:00:00 2001 From: Jonathan Hudson Date: Mon, 28 Dec 2020 18:09:31 +0000 Subject: [PATCH 3/3] only generate derived GPS data when we have a valid fix --- src/blackbox_decode.c | 13 +++++++++---- src/parser.c | 2 ++ src/parser.h | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/blackbox_decode.c b/src/blackbox_decode.c index 81c9cfa..e59a2f2 100644 --- a/src/blackbox_decode.c +++ b/src/blackbox_decode.c @@ -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; @@ -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; diff --git a/src/parser.c b/src/parser.c index 7d2a655..8c1babe 100644 --- a/src/parser.c +++ b/src/parser.c @@ -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) { diff --git a/src/parser.h b/src/parser.h index ca9bf9b..8ab8b03 100644 --- a/src/parser.h +++ b/src/parser.h @@ -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;