Skip to content

Commit 0333236

Browse files
committed
Check BDS50 on out of range values
1 parent f87ebbd commit 0333236

File tree

2 files changed

+57
-16
lines changed

2 files changed

+57
-16
lines changed

src/main/java/aero/t2s/modes/decoder/df/bds/Bds50.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -204,22 +204,13 @@ public Bds50(short[] data) {
204204
return;
205205
}
206206

207-
// If known check if roll angle & track angle rate matches expected / value
208-
// Formula from SkyBrary TurnRate (1) = (TAS / 10) => Roll Angle
209-
// Which we can rewrite to Roll Angle * 10 * Turn Rate = TAS
210-
// When TAS is not known we can use GS instead allow for bigger margin
211-
if (statusTrackAngle && statusRollAngle && trackAngleRate != 0) {
212-
double expectedTAS = Math.abs(rollAngle * 10d * (trackAngleRate / 3d));
213-
if (statusTas) {
214-
if (Math.abs(expectedTAS - tas) > 50) {
215-
invalidate();
216-
return;
217-
}
218-
} else if (statusGs) {
219-
if (Math.abs(expectedTAS - gs) > 150) {
220-
invalidate();
221-
return;
222-
}
207+
// Check if values are way off th scale.
208+
// We can only check large values
209+
if ((statusTas || statusGs) && statusTrackAngle && statusRollAngle && Math.abs(trackAngleRate) > 0.25 && Math.abs(rollAngle) > 5) {
210+
// We cannot have a rate one turn at 180 knots or greater at less than 30 degrees of bank
211+
if ((gs > 180 || tas > 180) && rollAngle < 30 && trackAngleRate > 3) {
212+
invalidate();
213+
return;
223214
}
224215
}
225216
}

src/test/java/aero/t2s/modes/decoder/df/DfRealMessageTest.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,56 @@ public void test_df21_bds50_485209() throws UnknownDownlinkFormatException {
289289
assertEquals(31.8, bds.getTrueTrack(), 0.1);
290290
}
291291

292+
@Test
293+
public void test_df21_bds50_484FDF() throws UnknownDownlinkFormatException {
294+
DownlinkFormat df = testMessage("A800080080502D2A600CA9DF5877");
295+
296+
assertInstanceOf(DF21.class, df);
297+
DF21 df21 = (DF21) df;
298+
assertEquals("484FDF", df.getIcao()); // Military / corrupt transponder
299+
assertEquals(1000, df21.getModeA());
300+
301+
assertTrue(df21.isValid());
302+
assertInstanceOf(Bds50.class, df21.getBds());
303+
304+
Bds50 bds = (Bds50) df21.getBds();
305+
assertTrue(bds.isStatusGs());
306+
assertEquals(338, bds.getGs(), 0.1);
307+
assertTrue(bds.isStatusTas());
308+
assertEquals(338, bds.getTas(), 0.1);
309+
assertTrue(bds.isStatusRollAngle());
310+
assertEquals(0.35, bds.getRollAngle(), 0.1);
311+
assertTrue(bds.isStatusTrueAngleRate());
312+
assertEquals(0, bds.getTrackAngleRate(), 0.1);
313+
assertTrue(bds.isStatusTrackAngle());
314+
assertEquals(3.8, bds.getTrueTrack(), 0.1);
315+
}
316+
317+
@Test
318+
public void test_df20_bds50_48418A() throws UnknownDownlinkFormatException {
319+
DownlinkFormat df = testMessage("A0000E978F1FBD316114BDA0FFBF");
320+
321+
assertInstanceOf(DF20.class, df);
322+
DF20 df20 = (DF20) df;
323+
assertEquals("48418A", df.getIcao()); // Military / corrupt transponder
324+
assertEquals(22375, df20.getAltitude().getAltitude());
325+
326+
assertTrue(df20.isValid());
327+
assertInstanceOf(Bds50.class, df20.getBds());
328+
329+
Bds50 bds = (Bds50) df20.getBds();
330+
assertTrue(bds.isStatusGs());
331+
assertEquals(394, bds.getGs(), 0.1);
332+
assertTrue(bds.isStatusTas());
333+
assertEquals(378, bds.getTas(), 0.1);
334+
assertTrue(bds.isStatusRollAngle());
335+
assertEquals(21, bds.getRollAngle(), 0.1);
336+
assertTrue(bds.isStatusTrueAngleRate());
337+
assertEquals(1, bds.getTrackAngleRate(), 0.1);
338+
assertTrue(bds.isStatusTrackAngle());
339+
assertEquals(354, bds.getTrueTrack(), 0.1);
340+
}
341+
292342

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

0 commit comments

Comments
 (0)