Skip to content

Commit b23f132

Browse files
committed
Add velocity information to track when available
1 parent e1dc7f0 commit b23f132

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

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

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
public class SurfacePosition extends ExtendedSquitter {
77
private final String address;
88
private int velocityEncoded = 0;
9+
private double velocity = 0;
910

1011
private boolean trackValid = false;
1112
private int trackEncoded = 0;
1213

1314
private double lat;
1415
private double lon;
1516
private boolean positionAvailable = false;
17+
private boolean velocityAvailable = false;
1618

1719
public SurfacePosition(short[] data, String address) {
1820
super(data);
@@ -22,6 +24,8 @@ public SurfacePosition(short[] data, String address) {
2224
@Override
2325
public SurfacePosition decode() {
2426
velocityEncoded = ((data[4] & 0x7) << 4) | (data[5] >>> 4);
27+
velocityAvailable = velocityEncoded != 0;
28+
velocity = decodeEncodedVelocity();
2529

2630
trackValid = ((data[5] >>> 3) & 0x1) == 0x1;
2731
trackEncoded = ((data[5] & 0x7) << 4) | (data[6] >>> 4);
@@ -46,20 +50,31 @@ public SurfacePosition decode() {
4650
} else {
4751
this.positionAvailable = false;
4852
}
49-
return this; }
53+
54+
return this;
55+
}
5056

5157
@Override
5258
public void apply(Track track) {
5359
track.setGroundBit(true);
60+
5461
if (positionAvailable) {
5562
track.setLatLon(lat, lon);
5663
}
64+
65+
if (velocityAvailable) {
66+
track.setGs(velocity);
67+
}
5768
}
5869

5970
public boolean isPositionAvailable() {
6071
return positionAvailable;
6172
}
6273

74+
public boolean isVelocityAvailable() {
75+
return this.velocityAvailable;
76+
}
77+
6378
public double getLat() {
6479
return lat;
6580
}
@@ -77,6 +92,22 @@ public int getVelocityEncoded() {
7792
}
7893

7994
public double getVelocity() {
95+
return this.velocity;
96+
}
97+
98+
public boolean isTrackValid() {
99+
return trackValid;
100+
}
101+
102+
public int getTrackEncoded() {
103+
return trackEncoded;
104+
}
105+
106+
public double getTrack() {
107+
return trackEncoded * 360.0 / 128.0;
108+
}
109+
110+
private double decodeEncodedVelocity() {
80111
if (this.velocityEncoded == 1) {
81112
return 0;
82113
}
@@ -104,18 +135,7 @@ public double getVelocity() {
104135
if (this.velocityEncoded == 124) {
105136
return 175.0;
106137
}
107-
return 0; // Could be either "not available" or "reserved"... just assume zero speed for now
108-
}
109138

110-
public boolean isTrackValid() {
111-
return trackValid;
112-
}
113-
114-
public int getTrackEncoded() {
115-
return trackEncoded;
116-
}
117-
118-
public double getTrack() {
119-
return trackEncoded * 360.0 / 128.0;
139+
return 0; // Could be either "not available" or "reserved"... just assume zero speed for now
120140
}
121141
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public void test_surface_position_aircraft() throws UnknownDownlinkFormatExcepti
4646
assertTrue(positionB.isPositionAvailable());
4747
assertEquals(53.3604, positionB.getLat(), 0.001);
4848
assertEquals(-2.2671, positionB.getLon(), 0.001);
49+
50+
assertTrue(positionB.isVelocityAvailable());
51+
assertEquals(1.75, positionB.getVelocity());
4952
}
5053

5154
@Test

0 commit comments

Comments
 (0)