Skip to content

Commit

Permalink
Check BDS50 on out of range values
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglasdc3 committed Oct 16, 2022
1 parent f87ebbd commit 0333236
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/main/java/aero/t2s/modes/decoder/df/bds/Bds50.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,13 @@ public Bds50(short[] data) {
return;
}

// If known check if roll angle & track angle rate matches expected / value
// Formula from SkyBrary TurnRate (1) = (TAS / 10) => Roll Angle
// Which we can rewrite to Roll Angle * 10 * Turn Rate = TAS
// When TAS is not known we can use GS instead allow for bigger margin
if (statusTrackAngle && statusRollAngle && trackAngleRate != 0) {
double expectedTAS = Math.abs(rollAngle * 10d * (trackAngleRate / 3d));
if (statusTas) {
if (Math.abs(expectedTAS - tas) > 50) {
invalidate();
return;
}
} else if (statusGs) {
if (Math.abs(expectedTAS - gs) > 150) {
invalidate();
return;
}
// Check if values are way off th scale.
// We can only check large values
if ((statusTas || statusGs) && statusTrackAngle && statusRollAngle && Math.abs(trackAngleRate) > 0.25 && Math.abs(rollAngle) > 5) {
// We cannot have a rate one turn at 180 knots or greater at less than 30 degrees of bank
if ((gs > 180 || tas > 180) && rollAngle < 30 && trackAngleRate > 3) {
invalidate();
return;
}
}
}
Expand Down
50 changes: 50 additions & 0 deletions src/test/java/aero/t2s/modes/decoder/df/DfRealMessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,56 @@ public void test_df21_bds50_485209() throws UnknownDownlinkFormatException {
assertEquals(31.8, bds.getTrueTrack(), 0.1);
}

@Test
public void test_df21_bds50_484FDF() throws UnknownDownlinkFormatException {
DownlinkFormat df = testMessage("A800080080502D2A600CA9DF5877");

assertInstanceOf(DF21.class, df);
DF21 df21 = (DF21) df;
assertEquals("484FDF", df.getIcao()); // Military / corrupt transponder
assertEquals(1000, df21.getModeA());

assertTrue(df21.isValid());
assertInstanceOf(Bds50.class, df21.getBds());

Bds50 bds = (Bds50) df21.getBds();
assertTrue(bds.isStatusGs());
assertEquals(338, bds.getGs(), 0.1);
assertTrue(bds.isStatusTas());
assertEquals(338, bds.getTas(), 0.1);
assertTrue(bds.isStatusRollAngle());
assertEquals(0.35, bds.getRollAngle(), 0.1);
assertTrue(bds.isStatusTrueAngleRate());
assertEquals(0, bds.getTrackAngleRate(), 0.1);
assertTrue(bds.isStatusTrackAngle());
assertEquals(3.8, bds.getTrueTrack(), 0.1);
}

@Test
public void test_df20_bds50_48418A() throws UnknownDownlinkFormatException {
DownlinkFormat df = testMessage("A0000E978F1FBD316114BDA0FFBF");

assertInstanceOf(DF20.class, df);
DF20 df20 = (DF20) df;
assertEquals("48418A", df.getIcao()); // Military / corrupt transponder
assertEquals(22375, df20.getAltitude().getAltitude());

assertTrue(df20.isValid());
assertInstanceOf(Bds50.class, df20.getBds());

Bds50 bds = (Bds50) df20.getBds();
assertTrue(bds.isStatusGs());
assertEquals(394, bds.getGs(), 0.1);
assertTrue(bds.isStatusTas());
assertEquals(378, bds.getTas(), 0.1);
assertTrue(bds.isStatusRollAngle());
assertEquals(21, bds.getRollAngle(), 0.1);
assertTrue(bds.isStatusTrueAngleRate());
assertEquals(1, bds.getTrackAngleRate(), 0.1);
assertTrue(bds.isStatusTrackAngle());
assertEquals(354, bds.getTrueTrack(), 0.1);
}


private DownlinkFormat testMessage(String message) throws UnknownDownlinkFormatException {
Decoder decoder = new Decoder(new HashMap<>(), 50, 2, ModeSDatabase.createDatabase());
Expand Down

0 comments on commit 0333236

Please sign in to comment.