Skip to content

Commit

Permalink
Improve BDS40 detection by allowing empty FMS altitude if status is a…
Browse files Browse the repository at this point in the history
…vailable
  • Loading branch information
Douglasdc3 committed Oct 12, 2022
1 parent c6daacd commit 83bd0c2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/aero/t2s/modes/decoder/df/bds/Bds40.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Bds40(short[] data) {

fmsAltitude = (((data[5] & 0x3) << 10) | (data[6] << 2) | ((data[7] >>> 6) & 0x3)) * 16;
if (statusFms) {
if (fmsAltitude <= 0 || fmsAltitude > 52000) {
if (fmsAltitude < 0 || fmsAltitude > 52000) {
invalidate();
return;
}
Expand Down
27 changes: 27 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 @@ -192,6 +192,33 @@ public void test_df21_bds50_44CD73() throws UnknownDownlinkFormatException {
assertEquals(214.2, bds.getTrueTrack(), 0.1);
}

@Test
public void test_df21_bds40_407776() throws UnknownDownlinkFormatException {
DownlinkFormat df = testMessage("A000169EB2CC0030A80106C25083");

assertInstanceOf(DF20.class, df);
DF20 df20 = (DF20) df;
assertEquals("407776", df.getIcao()); // Military / corrupt transponder
assertEquals(35350, df20.getAltitude().getAltitude());

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

Bds40 bds = (Bds40) df20.getBds();
assertTrue(bds.isStatusMcp());
assertEquals(26000, bds.getSelectedAltitude(), 0.1);
assertTrue(bds.isStatusFms());
assertEquals(0, bds.getFmsAltitude(), 0.1);
assertTrue(bds.isStatusBaro());
assertEquals(1013.2, bds.getBaro(), 0.1);
assertTrue(bds.isStatusTargetSource());
assertEquals(SelectedAltitudeSource.MCP, bds.getSelectedAltitudeSource());
assertTrue(bds.isStatusMcpMode());
assertFalse(bds.isAutopilotVnav());
assertFalse(bds.isAutopilotAltitudeHold());
assertFalse(bds.isAutopilotApproach());
}

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

Expand Down

0 comments on commit 83bd0c2

Please sign in to comment.