58 lines
1.9 KiB
Rust
58 lines
1.9 KiB
Rust
use crate::dsn::dsn_request;
|
|
use reqwest::blocking::Client;
|
|
use crate::config::VisualizerConfig;
|
|
use std::sync::mpsc;
|
|
use std::time::Duration;
|
|
use crate::dsn::models::{Station, SignalType};
|
|
|
|
mod dsn;
|
|
mod config;
|
|
|
|
fn dsn_thread(config: VisualizerConfig, tx: mpsc::Sender<Vec<Station>>) {
|
|
let client = Client::new();
|
|
let sleep_duration = Duration::from_secs(config.polling_rate);
|
|
|
|
loop {
|
|
match dsn_request(&client, &config.dsn_address) {
|
|
Ok(stations) => {
|
|
if tx.send(stations).is_err() {
|
|
break;
|
|
}
|
|
}
|
|
Err(e) => {
|
|
println!("Unable to fetch DSN status: {}", e)
|
|
}
|
|
}
|
|
|
|
std::thread::sleep(sleep_duration);
|
|
}
|
|
}
|
|
|
|
|
|
fn main() {
|
|
let (tx,rx) = mpsc::channel::<Vec<Station>>();
|
|
let config = VisualizerConfig::new("config.toml").unwrap();
|
|
|
|
std::thread::spawn(move || dsn_thread(config, tx));
|
|
|
|
loop {
|
|
let stations = rx.recv().unwrap();
|
|
for station in stations {
|
|
for dish in station.dishes {
|
|
for target in dish.target {
|
|
let up_signal = dish.up_signal.iter().find(|s| s.spacecraft_id == Some(target.id) && SignalType::Data == s.signal_type);
|
|
let down_signal = dish.down_signal.iter().find(|s| s.spacecraft_id == Some(target.id) && SignalType::Data == s.signal_type);
|
|
|
|
if let Some(up_signal) = up_signal {
|
|
println!("{}: Uplink Rate: {}, Up leg Distance: {}", target.name, up_signal.data_rate.unwrap_or(0.0), target.upleg_range)
|
|
}
|
|
else if let Some(down_signal) = down_signal {
|
|
println!("{}: Downlink Rate: {}, Down leg Distance: {}", target.name, down_signal.data_rate.unwrap_or(0.0), target.downleg_range)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|