Skip to content

Commit 6e1f401

Browse files
authored
Merge pull request #50 from terminal2/EvenOddPositions
Move from local position decoding to global unambiguous position decoding when possible
2 parents 17aab20 + cca9a63 commit 6e1f401

File tree

7 files changed

+208
-104
lines changed

7 files changed

+208
-104
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
GROUP=aero.t2s
2-
VERSION_NAME=0.2.5-SNAPSHOT
2+
VERSION_NAME=0.2.6-SNAPSHOT
33

44
POM_ARTIFACT_ID=mode-s
55
POM_NAME=Mode-S/ADS-B (1090Mhz)

src/main/java/aero/t2s/modes/CprPosition.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
package aero.t2s.modes;
22

3+
import java.time.Instant;
4+
35
public class CprPosition {
46
private double lat;
57
private double lon;
6-
private int time;
8+
private boolean valid;
9+
private long time;
10+
11+
public CprPosition() {
12+
this.lat = 0.0;
13+
this.lon = 0.0;
14+
this.valid = false;
15+
}
16+
public CprPosition(double lat, double lon) {
17+
setLatLon(lat ,lon);
18+
}
19+
20+
public void setLatLon(double lat, double lon) {
21+
this.lat = lat;
22+
this.lon = lon;
23+
this.time = Instant.now().toEpochMilli();
24+
this.valid = true;
25+
}
726

827
public void setLat(double lat) {
928
this.lat = lat;
@@ -21,15 +40,19 @@ public double getLon() {
2140
return lon;
2241
}
2342

24-
public void setTime(int time) {
43+
public void setTime(long time) {
2544
this.time = time;
2645
}
2746

28-
public int getTime() {
47+
public long getTime() {
2948
return time;
3049
}
3150

3251
public boolean isValid() {
33-
return lat != 0d && lon != 0;
52+
return valid;
53+
}
54+
55+
public boolean isExpired() {
56+
return time < Instant.now().minusSeconds(10).toEpochMilli();
3457
}
3558
}

src/main/java/aero/t2s/modes/ModeSHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package aero.t2s.modes;
22

33
import aero.t2s.modes.decoder.df.DownlinkFormat;
4+
import aero.t2s.modes.decoder.df.df17.AirbornePosition;
45

56
import java.util.function.Consumer;
67

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

4445
public void start() {
45-
46+
AirbornePosition.start();
4647
}
4748

4849
public void stop() {
49-
50+
AirbornePosition.stop();
5051
}
5152
}

src/main/java/aero/t2s/modes/Track.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class Track {
1111
private Altitude altitude = new Altitude();
1212
private double lat;
1313
private double lon;
14+
private boolean positionAvailable = false;
1415
private int vx;
1516
private int vy;
1617
private double gs;
@@ -172,7 +173,13 @@ public boolean isGroundBit() {
172173
return groundBit;
173174
}
174175

176+
public void setLatLon(double lat, double lon) {
177+
this.lat = lat;
178+
this.lon = lon;
179+
this.positionAvailable = true;
180+
}
175181
public void setLat(double lat) {
182+
//TODO How do we know if position really is available if we only set the lat? Can we remove this method?
176183
this.lat = lat;
177184
}
178185

@@ -181,6 +188,7 @@ public double getLat() {
181188
}
182189

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

@@ -245,7 +253,7 @@ public int getModeA() {
245253
}
246254

247255
public boolean isPositionAvailable() {
248-
return lat != 0 & lon != 0;
256+
return positionAvailable;
249257
}
250258

251259
public void setGeometricHeightOffset(int geometricHeightOffset) {

src/main/java/aero/t2s/modes/decoder/Decoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public DownlinkFormat decode(short[] data) throws UnknownDownlinkFormatException
5050
df = new DF16(data);
5151
break;
5252
case 17:
53-
df = new DF17(data, originLat, originLon);
53+
df = new DF17(data);
5454
break;
5555
case 18:
5656
df = new DF18(data);

src/main/java/aero/t2s/modes/decoder/df/DF17.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44
import aero.t2s.modes.decoder.df.df17.*;
55

66
public class DF17 extends DownlinkFormat {
7-
private final double originLat;
8-
private final double originLon;
9-
107
private ExtendedSquitter extendedSquitter;
118

12-
public DF17(short[] data, double originLat, double originLon) {
9+
public DF17(short[] data) {
1310
super(data, IcaoAddress.FROM_MESSAGE);
14-
this.originLat = originLat;
15-
this.originLon = originLon;
1611
}
1712

1813
@Override
@@ -34,7 +29,7 @@ public DF17 decode() {
3429
case 20:
3530
case 21:
3631
case 22:
37-
extendedSquitter = new AirbornePosition(data, originLat, originLon);
32+
extendedSquitter = new AirbornePosition(data, getIcao());
3833
break;
3934
case 1:
4035
case 2:

0 commit comments

Comments
 (0)