adsb: emit Action::Ignored
This commit is contained in:
parent
1c6c4f1d9b
commit
f782f1a810
13
src/adsb.rs
13
src/adsb.rs
|
@ -66,6 +66,7 @@ pub enum Action {
|
||||||
Appeared,
|
Appeared,
|
||||||
Disappeared,
|
Disappeared,
|
||||||
Moved,
|
Moved,
|
||||||
|
Ignored,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
|
@ -154,11 +155,18 @@ pub fn run(url: &'static str, locations: Locations) -> Receiver<Event> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let mut events = vec![];
|
||||||
for mut info in infos {
|
for mut info in infos {
|
||||||
if info.altitude > MAX_ALTITUDE {
|
if info.altitude > MAX_ALTITUDE {
|
||||||
if !ignored.contains(&info.hex) {
|
if !ignored.contains(&info.hex) {
|
||||||
states.remove(&info.hex);
|
ignored.insert(info.hex.clone());
|
||||||
ignored.insert(info.hex);
|
if let Some(_) = states.remove(&info.hex) {
|
||||||
|
events.push(Event {
|
||||||
|
action: Action::Ignored,
|
||||||
|
info,
|
||||||
|
location: Arc::new("ignoriert".to_owned()),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -181,7 +189,6 @@ pub fn run(url: &'static str, locations: Locations) -> Receiver<Event> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut events = vec![];
|
|
||||||
states.retain(|_, state| {
|
states.retain(|_, state| {
|
||||||
if state.last + Duration::from_secs(STATE_TIMEOUT) < Instant::now() {
|
if state.last + Duration::from_secs(STATE_TIMEOUT) < Instant::now() {
|
||||||
events.push(Event {
|
events.push(Event {
|
||||||
|
|
46
src/main.rs
46
src/main.rs
|
@ -36,30 +36,42 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
while let Some(event) = events.recv().await {
|
while let Some(event) = events.recv().await {
|
||||||
println!("event: {:?}", event);
|
println!("event: {:?}", event);
|
||||||
|
|
||||||
let mut text;
|
let identifier;
|
||||||
if let Some(aircraft) = aircrafts.find(&event.info.get_hex()) {
|
if let Some(aircraft) = aircrafts.find(&event.info.get_hex()) {
|
||||||
println!("aircraft: {:?}", aircraft);
|
println!("aircraft: {:?}", aircraft);
|
||||||
text = format!("{} {} ({} {})",
|
// TODO: aircraft.model.starts_with(&aircraft.manufacturername)
|
||||||
aircraft.owner, aircraft.registration,
|
identifier = format!(
|
||||||
aircraft.manufacturername, aircraft.model
|
"{} {} ({} {})",
|
||||||
|
aircraft.owner, aircraft.registration,
|
||||||
|
aircraft.manufacturername, aircraft.model
|
||||||
);
|
);
|
||||||
} else if let Some(flight) = event.info.get_flight() {
|
} 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 {
|
} else {
|
||||||
text = format!("[{}]", event.info.get_hex());
|
identifier = format!("[{}]", event.info.get_hex());
|
||||||
}
|
}
|
||||||
|
|
||||||
text = format!("{} {}", text, match event.action {
|
let text = match event.action {
|
||||||
adsb::Action::Appeared => "ist aufgetaucht",
|
adsb::Action::Appeared =>
|
||||||
adsb::Action::Moved => "fliegt jetzt",
|
format!("{} ist {:.0}m über {} aufgetaucht",
|
||||||
adsb::Action::Disappeared => "ist abgetaucht.",
|
identifier,
|
||||||
});
|
event.info.get_altitude_m(),
|
||||||
if event.action != adsb::Action::Disappeared {
|
event.location
|
||||||
text = format!("{} {:.0}m über {}", text,
|
),
|
||||||
event.info.get_altitude_m(),
|
adsb::Action::Moved =>
|
||||||
event.location
|
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);
|
println!(">> {}", text);
|
||||||
jabber.send_message(text).await;
|
jabber.send_message(text).await;
|
||||||
|
|
Loading…
Reference in New Issue