From f77a85e8b8c96a38665f221cd7289f340d6442be Mon Sep 17 00:00:00 2001 From: Malcolm Robb Date: Fri, 26 Apr 2013 09:49:53 +0100 Subject: [PATCH] VK1ET : Additions to check fflags Implement changes suggested by John/VK1ET Changes to cprNFunction to ensure fflag {was 'isodd'} is used as a flag. Fix to decodeCPRrelative to pass 'surface' flag. --- dump1090.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dump1090.c b/dump1090.c index 2a32ea0..9244024 100644 --- a/dump1090.c +++ b/dump1090.c @@ -2338,14 +2338,14 @@ int cprNLFunction(double lat) { else return 1; } -int cprNFunction(double lat, int isodd) { - int nl = cprNLFunction(lat) - isodd; +int cprNFunction(double lat, int fflag) { + int nl = cprNLFunction(lat) - (fflag ? 1 : 0); if (nl < 1) nl = 1; return nl; } -double cprDlonFunction(double lat, int isodd, int surface) { - return (surface ? 90.0 : 360.0) / cprNFunction(lat, isodd); +double cprDlonFunction(double lat, int fflag, int surface) { + return (surface ? 90.0 : 360.0) / cprNFunction(lat, fflag); } /* This algorithm comes from: @@ -2381,7 +2381,7 @@ void decodeCPR(struct aircraft *a, int fflag, int surface) { int ni = cprNFunction(rlat1,1); int m = (int) floor((((lon0 * (cprNLFunction(rlat1)-1)) - (lon1 * cprNLFunction(rlat1))) / 131072.0) + 0.5); - a->lon = cprDlonFunction(rlat1,1,surface) * (cprModFunction(m,ni)+lon1/131072); + a->lon = cprDlonFunction(rlat1, 1, surface) * (cprModFunction(m, ni)+lon1/131072); a->lat = rlat1; } else { // Use even packet. int ni = cprNFunction(rlat0,0); @@ -2444,7 +2444,7 @@ int decodeCPRrelative(struct aircraft *a, int fflag, int surface, double latr, d } // Compute the Longitude Index "m" - AirDlon = cprDlonFunction(rlat, fflag, 0); + AirDlon = cprDlonFunction(rlat, fflag, surface); m = (int) (floor(lonr/AirDlon) + trunc(0.5 + cprModFunction((int)lonr, (int)AirDlon)/AirDlon - lon/131072)); rlon = AirDlon * (m + lon/131072);