Skip to content

Commit

Permalink
Merge pull request #50 from terminal2/EvenOddPositions
Browse files Browse the repository at this point in the history
Move from local position decoding to global unambiguous position decoding when possible
  • Loading branch information
Douglasdc3 committed Feb 21, 2023
2 parents 17aab20 + cca9a63 commit 6e1f401
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 104 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GROUP=aero.t2s
VERSION_NAME=0.2.5-SNAPSHOT
VERSION_NAME=0.2.6-SNAPSHOT

POM_ARTIFACT_ID=mode-s
POM_NAME=Mode-S/ADS-B (1090Mhz)
Expand Down
31 changes: 27 additions & 4 deletions src/main/java/aero/t2s/modes/CprPosition.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
package aero.t2s.modes;

import java.time.Instant;

public class CprPosition {
private double lat;
private double lon;
private int time;
private boolean valid;
private long time;

public CprPosition() {
this.lat = 0.0;
this.lon = 0.0;
this.valid = false;
}
public CprPosition(double lat, double lon) {
setLatLon(lat ,lon);
}

public void setLatLon(double lat, double lon) {
this.lat = lat;
this.lon = lon;
this.time = Instant.now().toEpochMilli();
this.valid = true;
}

public void setLat(double lat) {
this.lat = lat;
Expand All @@ -21,15 +40,19 @@ public double getLon() {
return lon;
}

public void setTime(int time) {
public void setTime(long time) {
this.time = time;
}

public int getTime() {
public long getTime() {
return time;
}

public boolean isValid() {
return lat != 0d && lon != 0;
return valid;
}

public boolean isExpired() {
return time < Instant.now().minusSeconds(10).toEpochMilli();
}
}
5 changes: 3 additions & 2 deletions src/main/java/aero/t2s/modes/ModeSHandler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aero.t2s.modes;

import aero.t2s.modes.decoder.df.DownlinkFormat;
import aero.t2s.modes.decoder.df.df17.AirbornePosition;

import java.util.function.Consumer;

Expand Down Expand Up @@ -42,10 +43,10 @@ protected short[] toData(final String input) throws EmptyMessageException, ModeA
}

public void start() {

AirbornePosition.start();
}

public void stop() {

AirbornePosition.stop();
}
}
10 changes: 9 additions & 1 deletion src/main/java/aero/t2s/modes/Track.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Track {
private Altitude altitude = new Altitude();
private double lat;
private double lon;
private boolean positionAvailable = false;
private int vx;
private int vy;
private double gs;
Expand Down Expand Up @@ -172,7 +173,13 @@ public boolean isGroundBit() {
return groundBit;
}

public void setLatLon(double lat, double lon) {
this.lat = lat;
this.lon = lon;
this.positionAvailable = true;
}
public void setLat(double lat) {
//TODO How do we know if position really is available if we only set the lat? Can we remove this method?
this.lat = lat;
}

Expand All @@ -181,6 +188,7 @@ public double getLat() {
}

public void setLon(double lon) {
//TODO How do we know if position really is available if we only set the lon? Can we remove this method?
this.lon = lon;
}

Expand Down Expand Up @@ -245,7 +253,7 @@ public int getModeA() {
}

public boolean isPositionAvailable() {
return lat != 0 & lon != 0;
return positionAvailable;
}

public void setGeometricHeightOffset(int geometricHeightOffset) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/aero/t2s/modes/decoder/Decoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public DownlinkFormat decode(short[] data) throws UnknownDownlinkFormatException
df = new DF16(data);
break;
case 17:
df = new DF17(data, originLat, originLon);
df = new DF17(data);
break;
case 18:
df = new DF18(data);
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/aero/t2s/modes/decoder/df/DF17.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@
import aero.t2s.modes.decoder.df.df17.*;

public class DF17 extends DownlinkFormat {
private final double originLat;
private final double originLon;

private ExtendedSquitter extendedSquitter;

public DF17(short[] data, double originLat, double originLon) {
public DF17(short[] data) {
super(data, IcaoAddress.FROM_MESSAGE);
this.originLat = originLat;
this.originLon = originLon;
}

@Override
Expand All @@ -34,7 +29,7 @@ public DF17 decode() {
case 20:
case 21:
case 22:
extendedSquitter = new AirbornePosition(data, originLat, originLon);
extendedSquitter = new AirbornePosition(data, getIcao());
break;
case 1:
case 2:
Expand Down

0 comments on commit 6e1f401

Please sign in to comment.