Skip to content

Commit

Permalink
Merge pull request #28 from iNavFlight/jh_compiler_warning_fix
Browse files Browse the repository at this point in the history
Fix win32 compiler warnings; only generate derived GPS data when we have a valid fix
  • Loading branch information
stronnag authored Dec 28, 2020
2 parents 630cd3e + 78c5c94 commit 6fbc7ab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 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
13 changes: 7 additions & 6 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 Expand Up @@ -842,16 +844,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 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) (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;
}
}
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 6fbc7ab

Please sign in to comment.