summaryrefslogtreecommitdiff
path: root/src/main/java/com/benburwell/planes/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/benburwell/planes/data')
-rw-r--r--src/main/java/com/benburwell/planes/data/Aircraft.java90
-rw-r--r--src/main/java/com/benburwell/planes/data/AircraftStore.java34
-rw-r--r--src/main/java/com/benburwell/planes/data/AircraftStoreListener.java9
-rw-r--r--src/main/java/com/benburwell/planes/data/NavigationAid.java187
-rw-r--r--src/main/java/com/benburwell/planes/data/Position.java46
5 files changed, 366 insertions, 0 deletions
diff --git a/src/main/java/com/benburwell/planes/data/Aircraft.java b/src/main/java/com/benburwell/planes/data/Aircraft.java
new file mode 100644
index 0000000..66a7a46
--- /dev/null
+++ b/src/main/java/com/benburwell/planes/data/Aircraft.java
@@ -0,0 +1,90 @@
+package com.benburwell.planes.data;
+
+import com.benburwell.planes.sbs.SBSPacket;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * Created by ben on 11/15/16.
+ */
+public class Aircraft implements Comparable<Aircraft> {
+ private final String hexIdent;
+ private Position currentPosition = new Position();
+ private List<Position> positionHistory = new ArrayList<>();
+ private String callsign = "";
+ private String squawk = "";
+ private long packetCount = 0;
+ private double track;
+ private double groundSpeed;
+ private double verticalRate;
+
+ public Aircraft(String hexIdent) {
+ this.hexIdent = hexIdent;
+ }
+
+ public void handleUpdate(SBSPacket packet) {
+ this.packetCount++;
+ if (packet.getAltitude() != null) {
+ this.currentPosition.setAltitude(packet.getAltitude());
+ }
+ if (packet.getLatitude() != null) {
+ this.currentPosition.setLatitude(packet.getLatitude());
+ }
+ if (packet.getLongitude() != null) {
+ this.currentPosition.setLongitude(packet.getLongitude());
+ }
+ if (packet.getCallsign() != null && !packet.getCallsign().isEmpty()) {
+ this.callsign = packet.getCallsign();
+ }
+ if (packet.getSquawk() != null && !packet.getSquawk().isEmpty()) {
+ this.callsign = packet.getSquawk();
+ }
+ if (packet.getTrack() != null) {
+ this.track = packet.getTrack();
+ }
+ if (packet.getGroundSpeed() != null) {
+ this.groundSpeed = packet.getGroundSpeed();
+ }
+ if (packet.getVerticalRate() != null) {
+ this.verticalRate = packet.getVerticalRate();
+ }
+ }
+
+ public Position getCurrentPosition() {
+ return currentPosition;
+ }
+
+ public String getCallsign() {
+ return callsign;
+ }
+
+ public String getSquawk() {
+ return squawk;
+ }
+
+ public Long getPacketCount() {
+ return packetCount;
+ }
+
+ public String getHexIdent() {
+ return this.hexIdent;
+ }
+
+ public double getTrack() {
+ return this.track;
+ }
+
+ public double getGroundSpeed() {
+ return this.groundSpeed;
+ }
+
+ public double getVerticalRate() {
+ return this.verticalRate;
+ }
+
+ @Override
+ public int compareTo(Aircraft that) {
+ return this.getHexIdent().compareTo(that.getHexIdent());
+ }
+}
diff --git a/src/main/java/com/benburwell/planes/data/AircraftStore.java b/src/main/java/com/benburwell/planes/data/AircraftStore.java
new file mode 100644
index 0000000..076701d
--- /dev/null
+++ b/src/main/java/com/benburwell/planes/data/AircraftStore.java
@@ -0,0 +1,34 @@
+package com.benburwell.planes.data;
+
+import com.benburwell.planes.sbs.SBSPacket;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * Created by ben on 11/17/16.
+ */
+public class AircraftStore {
+ private Map<String,Aircraft> aircraftMap = new HashMap<>();
+ private List<AircraftStoreListener> aircraftListeners = new ArrayList<>();
+
+ public Map<String,Aircraft> getAircraft() {
+ return this.aircraftMap;
+ }
+
+ public void addPacket(SBSPacket packet) {
+ if (!this.aircraftMap.containsKey(packet.getHexIdent())) {
+ this.aircraftMap.put(packet.getHexIdent(), new Aircraft(packet.getHexIdent()));
+ }
+ this.aircraftMap.get(packet.getHexIdent()).handleUpdate(packet);
+ this.aircraftListeners.stream()
+ .filter(listener -> listener.respondTo(packet.getHexIdent()))
+ .forEach(AircraftStoreListener::aircraftStoreChanged);
+ }
+
+ public void subscribe(AircraftStoreListener listener) {
+ this.aircraftListeners.add(listener);
+ }
+}
diff --git a/src/main/java/com/benburwell/planes/data/AircraftStoreListener.java b/src/main/java/com/benburwell/planes/data/AircraftStoreListener.java
new file mode 100644
index 0000000..2ef635f
--- /dev/null
+++ b/src/main/java/com/benburwell/planes/data/AircraftStoreListener.java
@@ -0,0 +1,9 @@
+package com.benburwell.planes.data;
+
+/**
+ * Created by ben on 11/17/16.
+ */
+public interface AircraftStoreListener {
+ void aircraftStoreChanged();
+ boolean respondTo(String aircraftId);
+}
diff --git a/src/main/java/com/benburwell/planes/data/NavigationAid.java b/src/main/java/com/benburwell/planes/data/NavigationAid.java
new file mode 100644
index 0000000..09521a0
--- /dev/null
+++ b/src/main/java/com/benburwell/planes/data/NavigationAid.java
@@ -0,0 +1,187 @@
+package com.benburwell.planes.data;
+
+/**
+ * Frequencies in kHz, elevations in ft
+ *
+ * Created by ben on 11/19/16.
+ */
+public class NavigationAid {
+ private int id;
+ private String filename;
+ private String ident;
+ private String type;
+ private int frequency;
+ private double latitude;
+ private double longitude;
+ private int elevation;
+ private String isoCountry;
+ private double dmeFrequency;
+ private String dmeChannel;
+ private double dmeLatitude;
+ private double dmeLongitude;
+ private int dmeElevation;
+ private double slavedVariation;
+ private double magneticVariation;
+ private String usageType;
+ private String power;
+ private String associatedAirport;
+
+ public NavigationAid() {}
+
+ public static NavigationAid fromCSV(String row) {
+ NavigationAid aid = new NavigationAid();
+ return aid;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getFilename() {
+ return filename;
+ }
+
+ public void setFilename(String filename) {
+ this.filename = filename;
+ }
+
+ public String getIdent() {
+ return ident;
+ }
+
+ public void setIdent(String ident) {
+ this.ident = ident;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public int getFrequency() {
+ return frequency;
+ }
+
+ public void setFrequency(int frequency) {
+ this.frequency = frequency;
+ }
+
+ public double getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(double latitude) {
+ this.latitude = latitude;
+ }
+
+ public double getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(double longitude) {
+ this.longitude = longitude;
+ }
+
+ public int getElevation() {
+ return elevation;
+ }
+
+ public void setElevation(int elevation) {
+ this.elevation = elevation;
+ }
+
+ public String getIsoCountry() {
+ return isoCountry;
+ }
+
+ public void setIsoCountry(String isoCountry) {
+ this.isoCountry = isoCountry;
+ }
+
+ public double getDmeFrequency() {
+ return dmeFrequency;
+ }
+
+ public void setDmeFrequency(double dmeFrequency) {
+ this.dmeFrequency = dmeFrequency;
+ }
+
+ public String getDmeChannel() {
+ return dmeChannel;
+ }
+
+ public void setDmeChannel(String dmeChannel) {
+ this.dmeChannel = dmeChannel;
+ }
+
+ public double getDmeLatitude() {
+ return dmeLatitude;
+ }
+
+ public void setDmeLatitude(double dmeLatitude) {
+ this.dmeLatitude = dmeLatitude;
+ }
+
+ public double getDmeLongitude() {
+ return dmeLongitude;
+ }
+
+ public void setDmeLongitude(double dmeLongitude) {
+ this.dmeLongitude = dmeLongitude;
+ }
+
+ public int getDmeElevation() {
+ return dmeElevation;
+ }
+
+ public void setDmeElevation(int dmeElevation) {
+ this.dmeElevation = dmeElevation;
+ }
+
+ public double getSlavedVariation() {
+ return slavedVariation;
+ }
+
+ public void setSlavedVariation(double slavedVariation) {
+ this.slavedVariation = slavedVariation;
+ }
+
+ public double getMagneticVariation() {
+ return magneticVariation;
+ }
+
+ public void setMagneticVariation(double magneticVariation) {
+ this.magneticVariation = magneticVariation;
+ }
+
+ public String getUsageType() {
+ return usageType;
+ }
+
+ public void setUsageType(String usageType) {
+ this.usageType = usageType;
+ }
+
+ public String getPower() {
+ return power;
+ }
+
+ public void setPower(String power) {
+ this.power = power;
+ }
+
+ public String getAssociatedAirport() {
+ return associatedAirport;
+ }
+
+ public void setAssociatedAirport(String associatedAirport) {
+ this.associatedAirport = associatedAirport;
+ }
+}
diff --git a/src/main/java/com/benburwell/planes/data/Position.java b/src/main/java/com/benburwell/planes/data/Position.java
new file mode 100644
index 0000000..4b37235
--- /dev/null
+++ b/src/main/java/com/benburwell/planes/data/Position.java
@@ -0,0 +1,46 @@
+package com.benburwell.planes.data;
+
+import java.util.Date;
+
+/**
+ * Created by ben on 11/15/16.
+ */
+public class Position {
+ private Date timestamp = new Date(System.currentTimeMillis());
+ private Double latitude = 0.0;
+ private Double longitude = 0.0;
+
+ public Date getTimestamp() {
+ return timestamp;
+ }
+
+ public void setTimestamp(Date timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ public double getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(double latitude) {
+ this.latitude = latitude;
+ }
+
+ public double getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(double longitude) {
+ this.longitude = longitude;
+ }
+
+ public double getAltitude() {
+ return altitude;
+ }
+
+ public void setAltitude(double altitude) {
+ this.altitude = altitude;
+ }
+
+ private double altitude = 0;
+}