Skip to content

Commit

Permalink
Merge pull request #44 from terminal2/fix-bds40-decoding-high-alt-fli…
Browse files Browse the repository at this point in the history
…ghts

Improves high altitude flight detection of BDS40 data
  • Loading branch information
Douglasdc3 committed Oct 6, 2022
2 parents ddbff38 + 518dd6b commit df9c40d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/aero/t2s/modes/decoder/df/bds/Bds40.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public Bds40(short[] data) {

selectedAltitude = (((data[4] & 0b01111111) << 5) | (data[5] & 0b11111000) >>> 3) * 16;
if (statusMcp) {
if (selectedAltitude > 50000) {
if (selectedAltitude > 52000) {
invalidate();
return;
}
Expand All @@ -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 > 50000) {
if (fmsAltitude <= 0 || fmsAltitude > 52000) {
invalidate();
return;
}
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/aero/t2s/modes/decoder/df/DfRealMessageTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package aero.t2s.modes.decoder.df;

import aero.t2s.modes.BinaryHelper;
import aero.t2s.modes.constants.SelectedAltitudeSource;
import aero.t2s.modes.database.ModeSDatabase;
import aero.t2s.modes.decoder.Decoder;
import aero.t2s.modes.decoder.UnknownDownlinkFormatException;
import aero.t2s.modes.decoder.df.bds.Bds40;
import aero.t2s.modes.decoder.df.bds.Bds50;
import aero.t2s.modes.decoder.df.bds.Bds60;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -35,6 +38,34 @@ public void test_bds60() throws UnknownDownlinkFormatException {
assertEquals(32, bds.getIrsRocd());
}

@Test
public void test() throws UnknownDownlinkFormatException {
// DownlinkFormat df = testMessage("5D4CA64");
DownlinkFormat df = testMessage("A00006A1E3A71D30AA014672C8DF");

assertInstanceOf(DF20.class, df);
DF20 df20 = (DF20) df;
assertEquals("A48E35", df.getIcao());
assertEquals(51000, df20.getAltitude().getAltitude());

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

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

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

Expand Down

2 comments on commit df9c40d

@filipjonckers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surveillance is done until FL600 - I would put the filter at FL610 to allow for private jets and military traffic above FL500

@Douglasdc3
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It first was checking up to FL650 as is allowed by the data packet.
When trying to determine which BDS is used you want to filter on the 99% of traffic. The likelihood of a FL600 being a normal flight are low compared to it not being BDS44.

currently removing errors through real recorded data, this value may go bit higher if I find more examples.

I'll try run the dataset through my test script using FL610 see if I get the same amount of multiple matches / invalid data as I get now.

Please sign in to comment.