cleanup
This commit is contained in:
parent
44ef27b2b6
commit
6ac760585a
16
src/fps.rs
16
src/fps.rs
|
@ -36,7 +36,7 @@ pub fn print_fps(fp: &VatlinkDataV3FlightPlan, callsign: &str) {
|
|||
let arrival = fp.arrival.clone();
|
||||
let alternate = fp.alternate.clone();
|
||||
|
||||
let MAIN_WRAP = 68;
|
||||
let main_wrap = 68;
|
||||
|
||||
let mut route = fp.route.clone();
|
||||
|
||||
|
@ -45,7 +45,7 @@ pub fn print_fps(fp: &VatlinkDataV3FlightPlan, callsign: &str) {
|
|||
}
|
||||
|
||||
let route_chars: Vec<char> = route.chars().collect();
|
||||
let mut route_split = &mut route_chars.chunks(MAIN_WRAP)
|
||||
let route_split = &mut route_chars.chunks(main_wrap)
|
||||
.map(|chunk| chunk.iter().collect::<String>())
|
||||
.collect::<Vec<_>>();
|
||||
route_split.push("".to_string());
|
||||
|
@ -67,7 +67,7 @@ pub fn print_fps(fp: &VatlinkDataV3FlightPlan, callsign: &str) {
|
|||
}
|
||||
|
||||
let rem_chars: Vec<char> = rem.chars().collect();
|
||||
let mut rem_split = &mut rem_chars.chunks(MAIN_WRAP)
|
||||
let rem_split = &mut rem_chars.chunks(main_wrap)
|
||||
.map(|chunk| chunk.iter().collect::<String>())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
@ -109,11 +109,11 @@ pub fn print_fps(fp: &VatlinkDataV3FlightPlan, callsign: &str) {
|
|||
|
||||
println!("--- FLIGHT PROGRESS STRIP READOUT FOR {} ---", callsign);
|
||||
println!("┌{:─>leftmost_with_padding$}┬{:─>tnd_leftmost_with_padding$}┬──────┬──────────────────────────────────────────────────────────────────────┬──────┬──────┬──────┐", "", "");
|
||||
println!("│ {: >longest_block_leftmost$} │ {: >longest_block_2nd_leftmost$} │ {: >4} │ {: <MAIN_WRAP$} │ │ │ │", callsign, squawk, departure, route_split[0]);
|
||||
println!("│{: >leftmost_with_padding$}├{:─>tnd_leftmost_with_padding$}┤ {: >4} │ {: <MAIN_WRAP$} │──────┼──────┼──────┤", "", "", arrival, route_split[1].to_string()+rem_01.as_str());
|
||||
println!("│ {: >longest_block_leftmost$} │ {: >longest_block_2nd_leftmost$} │ {: >4} │ {: <MAIN_WRAP$} │ │ │ │", ac_type, departure_time, alternate, route_split[2].to_string()+rem_02.as_str());
|
||||
println!("│{: >leftmost_with_padding$}├{:─>tnd_leftmost_with_padding$}┤ │ {: <MAIN_WRAP$} │──────┼──────┼──────┤", "", "", rem_03);
|
||||
println!("│ {:0>3}{: >ft_offset$} │ {: >longest_block_2nd_leftmost$} │ │ {: <MAIN_WRAP$} │ │ │ │", cid, flight_type, cruise_alt, rem_04);
|
||||
println!("│ {: >longest_block_leftmost$} │ {: >longest_block_2nd_leftmost$} │ {: >4} │ {: <main_wrap$} │ │ │ │", callsign, squawk, departure, route_split[0]);
|
||||
println!("│{: >leftmost_with_padding$}├{:─>tnd_leftmost_with_padding$}┤ {: >4} │ {: <main_wrap$} │──────┼──────┼──────┤", "", "", arrival, route_split[1].to_string()+rem_01.as_str());
|
||||
println!("│ {: >longest_block_leftmost$} │ {: >longest_block_2nd_leftmost$} │ {: >4} │ {: <main_wrap$} │ │ │ │", ac_type, departure_time, alternate, route_split[2].to_string()+rem_02.as_str());
|
||||
println!("│{: >leftmost_with_padding$}├{:─>tnd_leftmost_with_padding$}┤ │ {: <main_wrap$} │──────┼──────┼──────┤", "", "", rem_03);
|
||||
println!("│ {:0>3}{: >ft_offset$} │ {: >longest_block_2nd_leftmost$} │ │ {: <main_wrap$} │ │ │ │", cid, flight_type, cruise_alt, rem_04);
|
||||
println!("└{:─>leftmost_with_padding$}┴{:─>tnd_leftmost_with_padding$}┴──────┴──────────────────────────────────────────────────────────────────────┴──────┴──────┴──────┘", "", "");
|
||||
println!("--- END FLIGHT PROGRESS STRIP READOUT FOR {} ---", callsign);
|
||||
}
|
23
src/main.rs
23
src/main.rs
|
@ -1,21 +1,18 @@
|
|||
use std::error::Error;
|
||||
use std::{io, thread};
|
||||
use std::{io};
|
||||
use std::io::Write;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use log::{debug, error, info, Level, warn};
|
||||
use tokio::select;
|
||||
use tokio::sync::mpsc::{Receiver, channel};
|
||||
use tokio::sync::RwLock;
|
||||
use tokio::time::{sleep, sleep_until};
|
||||
use tokio::time::{sleep};
|
||||
use crate::fps::print_fps;
|
||||
|
||||
use crate::vatlink::{vatlink_init, VATLINK_STATUS_URL, VATLINK_VERSION};
|
||||
use crate::vatlink::data_v3::VATLINK_DATAV3_UPDATE_INTERVAL;
|
||||
use crate::vatlink::data_v3_client::DataClientV3;
|
||||
|
||||
|
||||
pub mod vatlink;
|
||||
pub mod fps;
|
||||
|
||||
|
@ -33,8 +30,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
info!("Retrieved vatlink initialization data, connecting to servers...");
|
||||
|
||||
let mut datav3_client = DataClientV3::new(vatlink_init_data.data.v3).await?;
|
||||
let mut client = Arc::new(RwLock::new(datav3_client));
|
||||
let datav3_client = DataClientV3::new(vatlink_init_data.data.v3).await?;
|
||||
let client = Arc::new(RwLock::new(datav3_client));
|
||||
|
||||
{
|
||||
debug!("connected: {} pilots online", client.read().await.last_saved_data().pilots.len());
|
||||
|
@ -45,8 +42,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
let update_task = tokio::spawn(update_main(update_client, update_shutdown_rx));
|
||||
|
||||
let sector_lat: f64 = 0.0;
|
||||
let sector_long: f64 = 0.0;
|
||||
let _sector_lat: f64 = 0.0;
|
||||
let _sector_long: f64 = 0.0;
|
||||
let sector_loaded: bool = false;
|
||||
|
||||
loop {
|
||||
|
@ -66,6 +63,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||
c/lat/long/range/sector - Create and load a sector file
|
||||
l/ - List aircraft in sector
|
||||
h/ - Help
|
||||
q/ - Quit
|
||||
*/
|
||||
|
||||
let _ = io::stdin().read_line(&mut input).is_ok();
|
||||
|
@ -111,6 +109,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||
":" => todo!(),
|
||||
"c" => todo!(),
|
||||
"l" => todo!(),
|
||||
"q" => {
|
||||
break;
|
||||
}
|
||||
"h" => {
|
||||
info!("vfsm: Commands:");
|
||||
info!("s/callsign - Show a flight strip (s/AF1)");
|
||||
|
@ -122,6 +123,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||
info!("c/lat/long/range/sector - Create and load a sector file");
|
||||
info!("l/ - List aircraft in sector");
|
||||
info!("h/ - Help");
|
||||
info!("q/ - Quit");
|
||||
},
|
||||
_unknown => {
|
||||
error!("unknown command '{}'", _unknown);
|
||||
|
@ -135,6 +137,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||
info!("c/lat/long/range/sector - Create and load a sector file");
|
||||
info!("l/ - List aircraft in sector");
|
||||
info!("h/ - Help");
|
||||
info!("q/ - Quit");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +152,7 @@ async fn update_main(datav3_client: Arc<RwLock<DataClientV3>>, mut rx: Receiver<
|
|||
loop {
|
||||
select! {
|
||||
_ = sleep(Duration::from_secs(VATLINK_DATAV3_UPDATE_INTERVAL as u64)) => (),
|
||||
x = rx.recv() => {
|
||||
_ = rx.recv() => {
|
||||
return Ok(()); // if anything happens (channel closed OR we recv a shutdown) we should exit
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@ use std::fmt::{Display, Formatter};
|
|||
use chrono::{DateTime, Duration, Utc};
|
||||
use log::{debug, trace};
|
||||
use reqwest::{Client, ClientBuilder, header};
|
||||
use tokio::sync::oneshot::channel;
|
||||
use tokio::task::JoinHandle;
|
||||
use tokio::time::sleep;
|
||||
use url::Url;
|
||||
use crate::vatlink::data_v3::VatlinkDataV3;
|
||||
|
@ -79,11 +77,6 @@ impl DataClientV3 {
|
|||
}
|
||||
}
|
||||
|
||||
enum DataClientUpdateThreadMsg {
|
||||
Shutdown,
|
||||
UpdateNow
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum DataClientV3Error {
|
||||
NoServerProvided { options: VatlinkServer }
|
||||
|
|
Loading…
Reference in New Issue