Skip to content

Commit

Permalink
Add velocity information to track when available
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglasdc3 committed Mar 12, 2023
1 parent e1dc7f0 commit b23f132
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
46 changes: 33 additions & 13 deletions src/main/java/aero/t2s/modes/decoder/df/df17/SurfacePosition.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
public class SurfacePosition extends ExtendedSquitter {
private final String address;
private int velocityEncoded = 0;
private double velocity = 0;

private boolean trackValid = false;
private int trackEncoded = 0;

private double lat;
private double lon;
private boolean positionAvailable = false;
private boolean velocityAvailable = false;

public SurfacePosition(short[] data, String address) {
super(data);
Expand All @@ -22,6 +24,8 @@ public SurfacePosition(short[] data, String address) {
@Override
public SurfacePosition decode() {
velocityEncoded = ((data[4] & 0x7) << 4) | (data[5] >>> 4);
velocityAvailable = velocityEncoded != 0;
velocity = decodeEncodedVelocity();

trackValid = ((data[5] >>> 3) & 0x1) == 0x1;
trackEncoded = ((data[5] & 0x7) << 4) | (data[6] >>> 4);
Expand All @@ -46,20 +50,31 @@ public SurfacePosition decode() {
} else {
this.positionAvailable = false;
}
return this; }

return this;
}

@Override
public void apply(Track track) {
track.setGroundBit(true);

if (positionAvailable) {
track.setLatLon(lat, lon);
}

if (velocityAvailable) {
track.setGs(velocity);
}
}

public boolean isPositionAvailable() {
return positionAvailable;
}

public boolean isVelocityAvailable() {
return this.velocityAvailable;
}

public double getLat() {
return lat;
}
Expand All @@ -77,6 +92,22 @@ public int getVelocityEncoded() {
}

public double getVelocity() {
return this.velocity;
}

public boolean isTrackValid() {
return trackValid;
}

public int getTrackEncoded() {
return trackEncoded;
}

public double getTrack() {
return trackEncoded * 360.0 / 128.0;
}

private double decodeEncodedVelocity() {
if (this.velocityEncoded == 1) {
return 0;
}
Expand Down Expand Up @@ -104,18 +135,7 @@ public double getVelocity() {
if (this.velocityEncoded == 124) {
return 175.0;
}
return 0; // Could be either "not available" or "reserved"... just assume zero speed for now
}

public boolean isTrackValid() {
return trackValid;
}

public int getTrackEncoded() {
return trackEncoded;
}

public double getTrack() {
return trackEncoded * 360.0 / 128.0;
return 0; // Could be either "not available" or "reserved"... just assume zero speed for now
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public void test_surface_position_aircraft() throws UnknownDownlinkFormatExcepti
assertTrue(positionB.isPositionAvailable());
assertEquals(53.3604, positionB.getLat(), 0.001);
assertEquals(-2.2671, positionB.getLon(), 0.001);

assertTrue(positionB.isVelocityAvailable());
assertEquals(1.75, positionB.getVelocity());
}

@Test
Expand Down

0 comments on commit b23f132

Please sign in to comment.