Skip to content

Commit

Permalink
Fix Altitude decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglasdc3 committed Oct 12, 2022
1 parent c54c450 commit c6daacd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/main/java/aero/t2s/modes/decoder/AltitudeEncoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public static Altitude decode(int encoded) {
}

private static Altitude decodeFeet(int encoded) {
int n = ((encoded & 0b1111110000000) >>> 2) | (encoded & 0b11111);
// Remove bits 7 & 8 and stitch the binary message together.
int n = ((encoded & 0b1111110000000) >>> 2) + ((encoded & 0b100000) >>> 1) + (encoded & 0b1111);

int altitude = (25 * n) - 1000;

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/aero/t2s/modes/decoder/df/DF0Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void it_decodes_altitude()
{
df0 = new DF0(BinaryHelper.stringToByteArray("02E1951DE7596A")).decode();

assertEquals(33325, df0.getAltitude().getAltitude(), 0.1);
assertEquals(32925, df0.getAltitude().getAltitude(), 0.1);
assertEquals(25, df0.getAltitude().getStep());
assertFalse(df0.getAltitude().isMetric());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void test_df20_bds60_800736() throws UnknownDownlinkFormatException {
assertInstanceOf(DF20.class, df);
DF20 df20 = (DF20) df;
assertEquals("800736", df.getIcao());
assertEquals(41375, df20.getAltitude().getAltitude());
assertEquals(40975, df20.getAltitude().getAltitude());

assertTrue(df20.isValid());
assertInstanceOf(Bds60.class, df20.getBds());
Expand Down

0 comments on commit c6daacd

Please sign in to comment.