Skip to content

Commit

Permalink
BDS60 is invalid if CAS & IAS are too far apart or mach is given when…
Browse files Browse the repository at this point in the history
… status is not set
  • Loading branch information
Douglasdc3 committed Nov 15, 2020
1 parent 450eb9c commit 59be443
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions src/main/java/aero/t2s/modes/decoder/df/bds/Bds60.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aero.t2s.modes.decoder.df.bds;

import aero.t2s.modes.Track;
import aero.t2s.modes.decoder.AltitudeEncoding;

public class Bds60 extends Bds {
private static final double MAG_ACCURACY = 90.0 / 512.0;
Expand Down Expand Up @@ -51,9 +52,16 @@ public Bds60(short[] data) {

mach = ((data[7] << 2) | data[8] >> 6) * MACH_ACCURACY;
mach /= 1000.0;
if (statusMach && (mach <= 0 || mach > 1)) {
invalidate();
return;
if (statusMach) {
if (mach <= 0 || mach > 1) {
invalidate();
return;
}
} else {
if (mach != 0) {
invalidate();
return;
}
}

double baroSign = ((data[8] >>> 4) & 0x1) == 1 ? -512.0 : 0.0;
Expand All @@ -69,6 +77,44 @@ public Bds60(short[] data) {
invalidate();
return;
}

if (statusMach && statusIas && data[0] >>> 3 == 20) {
double altitude = AltitudeEncoding.decode((data[2] & 0x1F) << 8 | data[3]).getAltitude();
if (altitude > 0) {
double cas = machToCas(altitude * 0.3048) / 0.514444;
if (Math.abs(cas - ias) > 20) {
invalidate();
return;
}
}
}
}

private double machToCas(double altitude) {
return tasToCas(machToTas(altitude), altitude);
}

private double tasToCas(double tas, double altitude) {
double rho0 = 1.225;
double T = Math.max(288.15 - 0.0065 * altitude, 216.65);
double rhotrop = 1.225 * Math.pow((T / 288.15), 4.256848030018761);
double dhstrat = Math.max(0.0, altitude - 11000.0);
double rho = rhotrop * Math.exp(-dhstrat / 6341.552161);
double R = 287.05287; // m2/(s2 x K), gas constant, sea level ISA
double p = rho * R * T;
double p0 = 101325.0; // Pa, air pressure, sea level ISA

double qdyn = p * (Math.pow((1.0 + rho * tas * tas / (7.0 * p)), 3.5) - 1.0);
return Math.sqrt(7.0 * p0 / rho0 * (Math.pow((qdyn / p0 + 1.0), (2.0 / 7.0)) - 1.0));
}

private double machToTas(double altitude) {
double T = Math.max(288.15 - 0.0065 * altitude, 216.65);
double R = 287.05287; // m2/(s2 x K), gas constant, sea level ISA
double gamma = 1.40; // cp/cv for air
double a = Math.sqrt(gamma * R * T);

return mach * a;
}


Expand Down

0 comments on commit 59be443

Please sign in to comment.