beast: constrain position messages by time interval
This commit is contained in:
parent
c9e3581fe2
commit
f56244b7ef
|
@ -6,13 +6,15 @@ use tokio::sync::mpsc::channel;
|
|||
use adsb::ICAOAddress;
|
||||
use super::beast;
|
||||
|
||||
const MAX_CPR_INTERVAL: u64 = 2;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Entry {
|
||||
pub emitter_category: Option<u8>,
|
||||
pub callsign: Option<String>,
|
||||
pub altitude: Option<u16>,
|
||||
cpr1: Option<adsb::CPRFrame>,
|
||||
cpr2: Option<adsb::CPRFrame>,
|
||||
cpr1: Option<(Instant, adsb::CPRFrame)>,
|
||||
cpr2: Option<(Instant, adsb::CPRFrame)>,
|
||||
pub heading: Option<f64>,
|
||||
pub ground_speed: Option<f64>,
|
||||
pub vertical_rate: Option<i16>,
|
||||
|
@ -29,10 +31,10 @@ impl Entry {
|
|||
altitude, cpr_frame
|
||||
} => {
|
||||
self.altitude = Some(altitude);
|
||||
if self.cpr2.as_ref().map(|cpr2| cpr2.parity != cpr_frame.parity).unwrap_or(false) {
|
||||
if self.cpr2.as_ref().map(|(_, cpr2)| cpr2.parity != cpr_frame.parity).unwrap_or(false) {
|
||||
self.cpr1 = self.cpr2.take();
|
||||
}
|
||||
self.cpr2 = Some(cpr_frame);
|
||||
self.cpr2 = Some((Instant::now(), cpr_frame));
|
||||
}
|
||||
adsb::ADSBMessageKind::AirborneVelocity {
|
||||
heading, ground_speed,
|
||||
|
@ -56,7 +58,9 @@ impl Entry {
|
|||
|
||||
pub fn position(&self) -> Option<adsb::Position> {
|
||||
match (&self.cpr1, &self.cpr2) {
|
||||
(Some(cpr1), Some(cpr2)) => {
|
||||
(Some((time1, cpr1)), Some((time2, cpr2)))
|
||||
if time2.duration_since(*time1) <= Duration::from_secs(MAX_CPR_INTERVAL) =>
|
||||
{
|
||||
let pos = adsb::cpr::get_position((cpr1, cpr2))?;
|
||||
if pos.latitude >= -90.0 && pos.latitude <= 90.0 &&
|
||||
pos.longitude >= -180.0 && pos.longitude <= 180.0
|
||||
|
|
Loading…
Reference in New Issue