Merge pull request #23 from hhm0/decoding
use last recent airplane position to calculate its ground position
This commit is contained in:
commit
a17e5b0f98
24
mode_s.c
24
mode_s.c
|
@ -2022,12 +2022,24 @@ void decodeCPR(struct aircraft *a, int fflag, int surface) {
|
||||||
double rlat0 = AirDlat0 * (cprModFunction(j,60) + lat0 / 131072);
|
double rlat0 = AirDlat0 * (cprModFunction(j,60) + lat0 / 131072);
|
||||||
double rlat1 = AirDlat1 * (cprModFunction(j,59) + lat1 / 131072);
|
double rlat1 = AirDlat1 * (cprModFunction(j,59) + lat1 / 131072);
|
||||||
|
|
||||||
|
time_t now = time(NULL);
|
||||||
|
double surface_rlat = MODES_USER_LATITUDE_DFLT;
|
||||||
|
double surface_rlon = MODES_USER_LONGITUDE_DFLT;
|
||||||
|
|
||||||
if (surface) {
|
if (surface) {
|
||||||
// If we're on the ground, make sure we have our receiver base station Lat/Lon
|
// If we're on the ground, make sure we have a (likely) valid Lat/Lon
|
||||||
if (0 == (Modes.bUserFlags & MODES_USER_LATLON_VALID))
|
if ((a->bFlags & MODES_ACFLAGS_LATLON_VALID) && (((int)(now - a->seenLatLon)) < Modes.interactive_display_ttl)) {
|
||||||
{return;}
|
surface_rlat = a->lat;
|
||||||
rlat0 += floor(Modes.fUserLat / 90.0) * 90.0; // Move from 1st quadrant to our quadrant
|
surface_rlon = a->lon;
|
||||||
rlat1 += floor(Modes.fUserLat / 90.0) * 90.0;
|
} else if (Modes.bUserFlags & MODES_USER_LATLON_VALID) {
|
||||||
|
surface_rlat = Modes.fUserLat;
|
||||||
|
surface_rlon = Modes.fUserLon;
|
||||||
|
} else {
|
||||||
|
surface_rlat = Modes.fUserLat;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rlat0 += floor(surface_rlat / 90.0) * 90.0; // Move from 1st quadrant to our quadrant
|
||||||
|
rlat1 += floor(surface_rlat / 90.0) * 90.0;
|
||||||
} else {
|
} else {
|
||||||
if (rlat0 >= 270) rlat0 -= 360;
|
if (rlat0 >= 270) rlat0 -= 360;
|
||||||
if (rlat1 >= 270) rlat1 -= 360;
|
if (rlat1 >= 270) rlat1 -= 360;
|
||||||
|
@ -2052,7 +2064,7 @@ void decodeCPR(struct aircraft *a, int fflag, int surface) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (surface) {
|
if (surface) {
|
||||||
a->lon += floor(Modes.fUserLon / 90.0) * 90.0; // Move from 1st quadrant to our quadrant
|
a->lon += floor(surface_rlon / 90.0) * 90.0; // Move from 1st quadrant to our quadrant
|
||||||
} else if (a->lon > 180) {
|
} else if (a->lon > 180) {
|
||||||
a->lon -= 360;
|
a->lon -= 360;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue