adsb: emit Action::Ignored

This commit is contained in:
Astro 2021-10-30 18:34:56 +02:00
parent 1c6c4f1d9b
commit f782f1a810
2 changed files with 39 additions and 20 deletions

View File

@ -66,6 +66,7 @@ pub enum Action {
Appeared,
Disappeared,
Moved,
Ignored,
}
struct State {
@ -154,11 +155,18 @@ pub fn run(url: &'static str, locations: Locations) -> Receiver<Event> {
continue;
}
};
let mut events = vec![];
for mut info in infos {
if info.altitude > MAX_ALTITUDE {
if !ignored.contains(&info.hex) {
states.remove(&info.hex);
ignored.insert(info.hex);
ignored.insert(info.hex.clone());
if let Some(_) = states.remove(&info.hex) {
events.push(Event {
action: Action::Ignored,
info,
location: Arc::new("ignoriert".to_owned()),
});
}
}
continue;
}
@ -181,7 +189,6 @@ pub fn run(url: &'static str, locations: Locations) -> Receiver<Event> {
}
}
let mut events = vec![];
states.retain(|_, state| {
if state.last + Duration::from_secs(STATE_TIMEOUT) < Instant::now() {
events.push(Event {

View File

@ -36,30 +36,42 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
while let Some(event) = events.recv().await {
println!("event: {:?}", event);
let mut text;
let identifier;
if let Some(aircraft) = aircrafts.find(&event.info.get_hex()) {
println!("aircraft: {:?}", aircraft);
text = format!("{} {} ({} {})",
aircraft.owner, aircraft.registration,
aircraft.manufacturername, aircraft.model
// TODO: aircraft.model.starts_with(&aircraft.manufacturername)
identifier = format!(
"{} {} ({} {})",
aircraft.owner, aircraft.registration,
aircraft.manufacturername, aircraft.model
);
} else if let Some(flight) = event.info.get_flight() {
text = format!("Flug {} [{}]", flight, event.info.get_hex());
identifier = format!("Flug {} [{}]", flight, event.info.get_hex());
} else {
text = format!("[{}]", event.info.get_hex());
identifier = format!("[{}]", event.info.get_hex());
}
text = format!("{} {}", text, match event.action {
adsb::Action::Appeared => "ist aufgetaucht",
adsb::Action::Moved => "fliegt jetzt",
adsb::Action::Disappeared => "ist abgetaucht.",
});
if event.action != adsb::Action::Disappeared {
text = format!("{} {:.0}m über {}", text,
event.info.get_altitude_m(),
event.location
);
}
let text = match event.action {
adsb::Action::Appeared =>
format!("{} ist {:.0}m über {} aufgetaucht",
identifier,
event.info.get_altitude_m(),
event.location
),
adsb::Action::Moved =>
format!("{} ist fliegt jetzt {:.0}m über {}",
identifier,
event.info.get_altitude_m(),
event.location
),
adsb::Action::Disappeared =>
format!("{} ist abgetaucht", identifier),
adsb::Action::Ignored =>
format!("{} wird ab {:.0}m ignoriert",
identifier,
event.info.get_altitude_m()
),
};
println!(">> {}", text);
jabber.send_message(text).await;