Skip to content

Commit 85848d7

Browse files
committed
Add true heading when available to track on surface position
1 parent b23f132 commit 85848d7

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/main/java/aero/t2s/modes/decoder/df/df17/SurfacePosition.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ public class SurfacePosition extends ExtendedSquitter {
88
private int velocityEncoded = 0;
99
private double velocity = 0;
1010

11-
private boolean trackValid = false;
11+
private boolean trackAvailable = false;
1212
private int trackEncoded = 0;
13+
private double track = 0;
1314

1415
private double lat;
1516
private double lon;
@@ -27,8 +28,9 @@ public SurfacePosition decode() {
2728
velocityAvailable = velocityEncoded != 0;
2829
velocity = decodeEncodedVelocity();
2930

30-
trackValid = ((data[5] >>> 3) & 0x1) == 0x1;
31+
trackAvailable = ((data[5] >>> 3) & 0x1) == 0x1;
3132
trackEncoded = ((data[5] & 0x7) << 4) | (data[6] >>> 4);
33+
track = trackEncoded * 360.0 / 128.0;
3234

3335
// Decode position
3436
int time = (data[6] >>> 3) & 0x1;
@@ -65,6 +67,10 @@ public void apply(Track track) {
6567
if (velocityAvailable) {
6668
track.setGs(velocity);
6769
}
70+
71+
if (trackAvailable) {
72+
track.setTrueHeading(this.track);
73+
}
6874
}
6975

7076
public boolean isPositionAvailable() {
@@ -75,6 +81,10 @@ public boolean isVelocityAvailable() {
7581
return this.velocityAvailable;
7682
}
7783

84+
public boolean isTrackAvailable() {
85+
return trackAvailable;
86+
}
87+
7888
public double getLat() {
7989
return lat;
8090
}
@@ -95,16 +105,12 @@ public double getVelocity() {
95105
return this.velocity;
96106
}
97107

98-
public boolean isTrackValid() {
99-
return trackValid;
100-
}
101-
102108
public int getTrackEncoded() {
103109
return trackEncoded;
104110
}
105111

106112
public double getTrack() {
107-
return trackEncoded * 360.0 / 128.0;
113+
return track;
108114
}
109115

110116
private double decodeEncodedVelocity() {

src/test/java/aero/t2s/modes/decoder/df/df17/SurfacePositionTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void test_surface_position_aircraft() throws UnknownDownlinkFormatExcepti
2727
SurfacePosition positionA = (SurfacePosition) exSqA;
2828
assertEquals(13, positionA.getVelocityEncoded());
2929
assertEquals(2.0, positionA.getVelocity());
30-
assertTrue(positionA.isTrackValid());
30+
assertTrue(positionA.isTrackAvailable());
3131
assertEquals(82, positionA.getTrackEncoded());
3232
assertEquals(230.625, positionA.getTrack(), 0.001);
3333
// We should NOT have a valid position after only one frame
@@ -48,7 +48,10 @@ public void test_surface_position_aircraft() throws UnknownDownlinkFormatExcepti
4848
assertEquals(-2.2671, positionB.getLon(), 0.001);
4949

5050
assertTrue(positionB.isVelocityAvailable());
51-
assertEquals(1.75, positionB.getVelocity());
51+
assertEquals(1.75, positionB.getVelocity(), 0.1);
52+
53+
assertTrue(positionB.isTrackAvailable());
54+
assertEquals(230.625, positionB.getTrack(), 0.1);
5255
}
5356

5457
@Test
@@ -63,7 +66,7 @@ public void test_surface_position_vehicle() throws UnknownDownlinkFormatExceptio
6366
SurfacePosition position = (SurfacePosition) exSq;
6467
assertEquals(1, position.getVelocityEncoded());
6568
assertEquals(0.0, position.getVelocity());
66-
assertFalse(position.isTrackValid());
69+
assertFalse(position.isTrackAvailable());
6770
}
6871

6972
private DownlinkFormat testMessage(String message) throws UnknownDownlinkFormatException {

0 commit comments

Comments
 (0)