Skip to content

Commit

Permalink
[radar] Add --filter_time to reduce mis-decode
Browse files Browse the repository at this point in the history
Add --filter_time for removing airplanes after the the specified time.
This is down to 2 seconds in the ICAO document, but I see 10 seconds as
being pretty good for reducing the amount of mis-decodes greatly.

This was previosuly 60 seconds, which was giving very bad lat/long if a
long period of time was between both messages odd/even.

See #21
  • Loading branch information
wcampbell0x2a committed Dec 2, 2021
1 parent f5ca3c6 commit d46b246
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
24 changes: 13 additions & 11 deletions apps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@ USAGE:
radar [OPTIONS] --lat <LAT> --long <LONG>
OPTIONS:
--cities <CITIES>... Vector of cities [(name, lat, long),..]
--disable-lat-long Disable output of latitude and longitude on display
--gpsd Enable automatic updating of lat/lon from gpsd
--gpsd-ip <GPSD_IP> Ip address of gpsd [default: localhost]
-h, --help Print help information
--host <HOST> [default: localhost]
--lat <LAT> Antenna location latitude
--long <LONG> Antenna location longitude
--port <PORT> [default: 30002]
--scale <SCALE> Zoom level of Radar and Coverage [default: 1.2]
-V, --version Print version information
--cities <CITIES>... Vector of cities [(name, lat, long),..]
--disable-lat-long Disable output of latitude and longitude on display
--filter-time <FILTER_TIME> Seconds since last message from airplane, triggers removal of
airplane after time is up [default: 10]
--gpsd Enable automatic updating of lat/lon from gpsd
--gpsd-ip <GPSD_IP> Ip address of gpsd [default: localhost]
-h, --help Print help information
--host <HOST> [default: localhost]
--lat <LAT> Antenna location latitude
--long <LONG> Antenna location longitude
--port <PORT> [default: 30002]
--scale <SCALE> Zoom level of Radar and Coverage [default: 1.2]
-V, --version Print version information
```

### Key Bindings
Expand Down
13 changes: 4 additions & 9 deletions apps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@ impl Default for AirplaneState {
pub struct AirplaneCoor {
/// [odd, even]
pub altitudes: [Option<Altitude>; 2],
/// last time of frame Rx
pub last_time: SystemTime,
}

impl Default for AirplaneCoor {
fn default() -> Self {
Self {
altitudes: [None, None],
last_time: SystemTime::now(),
}
}
}
Expand Down Expand Up @@ -96,18 +93,15 @@ impl Airplanes {
/// Add `Altitude` from adsb frame
pub fn add_altitude(&mut self, icao: ICAO, altitude: &Altitude) {
let state = self.0.entry(icao).or_insert_with(AirplaneState::default);
let now = SystemTime::now();
match altitude.odd_flag {
CPRFormat::Odd => {
state.coords = AirplaneCoor {
altitudes: [state.coords.altitudes[0], Some(*altitude)],
last_time: now,
};
},
CPRFormat::Even => {
state.coords = AirplaneCoor {
altitudes: [Some(*altitude), state.coords.altitudes[1]],
last_time: now,
};
},
}
Expand Down Expand Up @@ -149,8 +143,9 @@ impl Airplanes {
}

/// Remove airplane after not active for a time
pub fn prune(&mut self) {
self.0
.retain(|_, v| v.last_time.elapsed().unwrap() < std::time::Duration::from_secs(60));
pub fn prune(&mut self, filter_time: u64) {
self.0.retain(|_, v| {
v.last_time.elapsed().unwrap() < std::time::Duration::from_secs(filter_time)
});
}
}
6 changes: 5 additions & 1 deletion apps/src/radar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ struct Opts {
/// Ip address of gpsd
#[clap(long, default_value = "localhost")]
gpsd_ip: String,
/// Seconds since last message from airplane, triggers removal of airplane after time is up
#[clap(long, default_value = "10")]
filter_time: u64,
}

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -197,6 +200,7 @@ fn main() {
let mut quit = None;
let original_scale = opts.scale;
let mut airplanes_state = TableState::default();
let filter_time = opts.filter_time;

let mut settings = Settings {
scale: opts.scale,
Expand Down Expand Up @@ -277,7 +281,7 @@ fn main() {

input.clear();
// remove airplanes that timed-out
adsb_airplanes.prune();
adsb_airplanes.prune(filter_time);

// tui drawing
terminal
Expand Down

0 comments on commit d46b246

Please sign in to comment.