Skip to content

Commit 4ed5f41

Browse files
committed
Added pluggable route decoder and filtering based on flight number
1 parent 476f761 commit 4ed5f41

18 files changed

Lines changed: 482 additions & 156 deletions
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
Collection of drivers for Earthcast/Delta project. Includes separate driver classes for:
2-
- NLDN (lightning)
3-
- MESH (Hail)
4-
- Turbulence (Vertical slices of GTGTURB product)
5-
- FlightAware (Feed for flight plan and location data)
1+
# FlightAware Add-on
2+
3+
Add-on to ingest real-time flight plan and position data from FlightAware Firehose feed

sensors/aviation/sensorhub-driver-fltaware/src/main/java/org/sensorhub/impl/sensor/flightAware/FlightAwareConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ enum Mode {
5757
@DisplayInfo(desc="Airline codes to listen for")
5858
public List<String> airlines = new ArrayList<>();
5959

60+
@DisplayInfo(desc="Flight filter configuration")
61+
public FlightObjectFilterConfig filterConfig;
62+
6063
@DisplayInfo(desc="Pub/sub configuration")
6164
public MessageQueueConfig pubSubConfig;
6265
}

sensors/aviation/sensorhub-driver-fltaware/src/main/java/org/sensorhub/impl/sensor/flightAware/FlightAwareDriver.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public class FlightAwareDriver extends AbstractSensorModule<FlightAwareConfig> i
8686
static final String SENSOR_UID_PREFIX = "urn:osh:sensor:aviation:";
8787
static final String FLIGHT_UID_PREFIX = "urn:osh:aviation:flight:";
8888

89+
IFlightObjectFilter flightFilter;
90+
IFlightRouteDecoder flightRouteDecoder;
8991
Cache<String, String> faIdToDestinationCache;
9092
ScheduledExecutorService watchDogTimer;
9193
FlightAwareClient firehoseClient;
@@ -219,6 +221,13 @@ public void init() throws SensorHubException
219221
addOutput(flightPositionOutput, false);
220222
flightPositionOutput.init();
221223

224+
// init flight filter
225+
if (config.filterConfig != null)
226+
this.flightFilter = config.filterConfig.getFilter();
227+
228+
// init flight route decoder
229+
this.flightRouteDecoder = new FlightRouteDecoderFlightXML(this);
230+
222231
// init ID cache
223232
this.faIdToDestinationCache = CacheBuilder.newBuilder()
224233
.maximumSize(MAX_ID_CACHE_SIZE)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/***************************** BEGIN LICENSE BLOCK ***************************
2+
3+
The contents of this file are subject to the Mozilla Public License, v. 2.0.
4+
If a copy of the MPL was not distributed with this file, You can obtain one
5+
at http://mozilla.org/MPL/2.0/.
6+
7+
Software distributed under the License is distributed on an "AS IS" basis,
8+
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
9+
for the specific language governing rights and limitations under the License.
10+
11+
Copyright (C) 2019 Delta Air Lines, Inc. All Rights Reserved.
12+
13+
******************************* END LICENSE BLOCK ***************************/
14+
15+
package org.sensorhub.impl.sensor.flightAware;
16+
17+
import java.io.BufferedReader;
18+
import java.io.FileReader;
19+
import java.util.Arrays;
20+
import java.util.HashMap;
21+
import java.util.List;
22+
import java.util.Map;
23+
import com.google.common.collect.Range;
24+
25+
26+
/**
27+
* Implementation of flight object filter using lists of flight number
28+
* ranges for one or more airlines.
29+
* @author Alex Robin
30+
* @since Nov 26, 2019
31+
*/
32+
public class FlightNumberRangeFilter implements IFlightObjectFilter
33+
{
34+
Map<String, List<Range<Integer>>> fltNumRanges = new HashMap<>();
35+
36+
37+
protected FlightNumberRangeFilter(FlightNumberRangeFilterConfig config)
38+
{
39+
try (BufferedReader reader = new BufferedReader(new FileReader(config.dataFile)))
40+
{
41+
reader.lines().forEach(l -> {
42+
if (!l.trim().isEmpty())
43+
{
44+
String[] cols = l.split(",");
45+
String airline = cols[0].trim();
46+
int low = Integer.parseInt(cols[1]);
47+
int high = Integer.parseInt(cols[2]);
48+
fltNumRanges.put(airline, Arrays.asList(Range.closed(low, high)));
49+
}
50+
});
51+
}
52+
catch (Exception e)
53+
{
54+
throw new IllegalStateException("Error parsing flight number ranges file", e);
55+
}
56+
}
57+
58+
59+
@Override
60+
public boolean test(FlightObject fltObj)
61+
{
62+
try
63+
{
64+
String airline = fltObj.ident.substring(0, 3);
65+
int fltNum = Integer.parseInt(fltObj.ident.substring(3));
66+
67+
List<Range<Integer>> rangeList = fltNumRanges.get(airline);
68+
if (rangeList == null)
69+
return false;
70+
71+
for (Range<Integer> range: rangeList)
72+
{
73+
if (range.contains(fltNum))
74+
return true;
75+
}
76+
77+
//System.err.println("Filter out " + fltObj.ident);
78+
return false;
79+
}
80+
catch (NumberFormatException e)
81+
{
82+
return false;
83+
}
84+
}
85+
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/***************************** BEGIN LICENSE BLOCK ***************************
2+
3+
The contents of this file are subject to the Mozilla Public License, v. 2.0.
4+
If a copy of the MPL was not distributed with this file, You can obtain one
5+
at http://mozilla.org/MPL/2.0/.
6+
7+
Software distributed under the License is distributed on an "AS IS" basis,
8+
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
9+
for the specific language governing rights and limitations under the License.
10+
11+
Copyright (C) 2019 Delta Air Lines, Inc. All Rights Reserved.
12+
13+
******************************* END LICENSE BLOCK ***************************/
14+
15+
package org.sensorhub.impl.sensor.flightAware;
16+
17+
import org.sensorhub.api.config.DisplayInfo;
18+
19+
20+
/**
21+
* Configuration class for flight number range filter
22+
* @author Alex Robin
23+
* @since Nov 26, 2019
24+
*/
25+
public class FlightNumberRangeFilterConfig extends FlightObjectFilterConfig
26+
{
27+
28+
@DisplayInfo(desc="Path of CSV file containing the ranges of accepted flight numbers.\n"
29+
+ "Each row must have the format: {airline ICAO code},{begin number},{end number}")
30+
public String dataFile;
31+
32+
33+
public IFlightObjectFilter getFilter()
34+
{
35+
return new FlightNumberRangeFilter(this);
36+
}
37+
}

sensors/aviation/sensorhub-driver-fltaware/src/main/java/org/sensorhub/impl/sensor/flightAware/FlightObject.java

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.time.ZonedDateTime;
1919
import java.util.ArrayList;
2020
import java.util.List;
21+
import org.sensorhub.impl.sensor.flightAware.FlightPlan.Waypoint;
2122

2223
/**
2324
*
@@ -82,10 +83,6 @@
8283
8384
*
8485
*/
85-
86-
87-
88-
8986
public class FlightObject
9087
{
9188
public String type; // pos or fp
@@ -98,14 +95,14 @@ public class FlightObject
9895

9996

10097
public String clock; // posix epoch timestamp
101-
public String id = ""; // faFlightId
98+
public String id; // faFlightId
10299
public String gs; // ground speed knots
103100
public String speed; // fixed cruising speed in knots
104101
public String heading;
105102
public String lat;
106103
public String lon;
107-
public String orig = ""; // ICAO airport code, waypoint, or latitude/longitude pair
108-
public String dest = ""; // ICAO airport code, waypoint, or latitude/longitude pair
104+
public String orig; // ICAO airport code, waypoint, or latitude/longitude pair
105+
public String dest; // ICAO airport code, waypoint, or latitude/longitude pair
109106
public String reg;
110107
public String squawk;
111108
public String updateType;
@@ -114,34 +111,22 @@ public class FlightObject
114111
public String eat;
115112
public String ete;
116113
public String fdt;
117-
List<Waypoint> waypoints = new ArrayList<>();
114+
public String route;
115+
public String facility_name;
116+
List<Waypoint> decodedRoute;
117+
118118

119119
// Adding for LawBox support
120120
public double verticalChange; //feet per mminute
121121

122122
public Long getDepartureTime() {
123-
if(edt != null)
124-
return Long.parseLong(edt);
123+
/*if(edt != null)
124+
return Long.parseLong(edt);*/
125125
if(fdt != null)
126126
return Long.parseLong(fdt);
127127

128128
return null;
129129
}
130-
131-
class Waypoint {
132-
public Waypoint(float lat, float lon) {
133-
this.lat = lat;
134-
this.lon = lon;
135-
}
136-
137-
float lat;
138-
float lon;
139-
float alt;
140-
}
141-
142-
public void addWaypoints(double lat, double lon) {
143-
waypoints.add(new Waypoint((float)lat, (float)lon));
144-
}
145130

146131

147132
@Override
@@ -181,24 +166,6 @@ public String toString() {
181166

182167
return b.toString();
183168
}
184-
185-
public float [] getLats() {
186-
float[] lats = new float[waypoints.size()];
187-
int i=0;
188-
for (Waypoint wp : waypoints) {
189-
lats[i++] = wp.lat;
190-
}
191-
return lats;
192-
}
193-
194-
public float[] getLons() {
195-
float [] lons = new float[waypoints.size()];
196-
int i=0;
197-
for (Waypoint wp : waypoints) {
198-
lons[i++] = wp.lon;
199-
}
200-
return lons;
201-
}
202169

203170
public long getClock() {
204171
return Long.parseLong(clock);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/***************************** BEGIN LICENSE BLOCK ***************************
2+
3+
The contents of this file are subject to the Mozilla Public License, v. 2.0.
4+
If a copy of the MPL was not distributed with this file, You can obtain one
5+
at http://mozilla.org/MPL/2.0/.
6+
7+
Software distributed under the License is distributed on an "AS IS" basis,
8+
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
9+
for the specific language governing rights and limitations under the License.
10+
11+
Copyright (C) 2019 Delta Air Lines, Inc. All Rights Reserved.
12+
13+
******************************* END LICENSE BLOCK ***************************/
14+
15+
package org.sensorhub.impl.sensor.flightAware;
16+
17+
18+
public abstract class FlightObjectFilterConfig
19+
{
20+
21+
/**
22+
* @return new filter instance based in this config
23+
*/
24+
public abstract IFlightObjectFilter getFilter();
25+
}

0 commit comments

Comments
 (0)