Basic parsing of spacecraft

+ This API is kinda wonky
+ Added signal type parsing
+ It might be good to add parsing of the `debugSignal` field as it contains good info
main
Joey Hines 2021-06-13 15:38:04 -06:00
parent 3729fd87f0
commit b0621b636d
No known key found for this signature in database
GPG Key ID: 80F567B5C968F91B
3 changed files with 61 additions and 24 deletions

View File

@ -61,17 +61,17 @@ where
} else if name.local_name.contains("downSignal") { } else if name.local_name.contains("downSignal") {
dish = Some( dish = Some(
dish.unwrap() dish.unwrap()
.set_down_signal(Signal::try_from(attributes).unwrap()), .add_down_signal(Signal::try_from(attributes).unwrap()),
); );
} else if name.local_name.contains("upSignal") { } else if name.local_name.contains("upSignal") {
dish = Some( dish = Some(
dish.unwrap() dish.unwrap()
.set_up_signal(Signal::try_from(attributes).unwrap()), .add_up_signal(Signal::try_from(attributes).unwrap()),
); );
} else if name.local_name.contains("target") { } else if name.local_name.contains("target") {
dish = Some( dish = Some(
dish.unwrap() dish.unwrap()
.set_target(Target::try_from(attributes).unwrap()), .add_target(Target::try_from(attributes).unwrap()),
); );
} }
} }

View File

@ -53,9 +53,34 @@ impl TryFrom<Vec<OwnedAttribute>> for Station {
} }
} }
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum SignalType {
Data,
Carrier,
None,
Unkown(String)
}
impl From<String> for SignalType {
fn from(s: String) -> Self {
match s.to_lowercase().as_str() {
"data" => SignalType::Data,
"carrier" => SignalType::Carrier,
"none" => SignalType::None,
_ => SignalType::Unkown(s)
}
}
}
impl Default for SignalType {
fn default() -> Self {
SignalType::None
}
}
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
pub struct Signal { pub struct Signal {
pub signal_type: String, pub signal_type: SignalType,
pub signal_type_debug: String, pub signal_type_debug: String,
pub data_rate: Option<f64>, pub data_rate: Option<f64>,
pub frequency: Option<f64>, pub frequency: Option<f64>,
@ -68,7 +93,7 @@ impl TryFrom<Vec<OwnedAttribute>> for Signal {
type Error = ParseError; type Error = ParseError;
fn try_from(attrs: Vec<OwnedAttribute>) -> Result<Self, Self::Error> { fn try_from(attrs: Vec<OwnedAttribute>) -> Result<Self, Self::Error> {
let signal_type = get_attr(&attrs, "signalType")?; let signal_type = SignalType::from(get_attr(&attrs, "signalType")?);
let signal_type_debug = get_attr(&attrs, "signalTypeDebug")?; let signal_type_debug = get_attr(&attrs, "signalTypeDebug")?;
let data_rate = get_attr(&attrs, "dataRate")?.parse::<f64>().ok(); let data_rate = get_attr(&attrs, "dataRate")?.parse::<f64>().ok();
let frequency = get_attr(&attrs, "frequency")?.parse::<f64>().ok(); let frequency = get_attr(&attrs, "frequency")?.parse::<f64>().ok();
@ -90,14 +115,14 @@ impl TryFrom<Vec<OwnedAttribute>> for Signal {
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
pub struct Target { pub struct Target {
name: String, pub name: String,
id: u32, pub id: u32,
/// Up Leg Range (km) /// Up Leg Range (km)
upleg_range: f64, pub upleg_range: f64,
/// Down Leg Leg Range (km) /// Down Leg Leg Range (km)
downleg_range: f64, pub downleg_range: f64,
/// Round trip light time (s) /// Round trip light time (s)
rtlt: f64, pub rtlt: f64,
} }
impl TryFrom<Vec<OwnedAttribute>> for Target { impl TryFrom<Vec<OwnedAttribute>> for Target {
@ -131,24 +156,24 @@ pub struct Dish {
pub is_ddor: bool, pub is_ddor: bool,
pub created: DateTime<Utc>, pub created: DateTime<Utc>,
pub updated: DateTime<Utc>, pub updated: DateTime<Utc>,
pub up_signal: Signal, pub up_signal: Vec<Signal>,
pub down_signal: Signal, pub down_signal: Vec<Signal>,
pub target: Target, pub target: Vec<Target>,
} }
impl Dish { impl Dish {
pub fn set_up_signal(mut self, signal: Signal) -> Self { pub fn add_up_signal(mut self, signal: Signal) -> Self {
self.up_signal = signal; self.up_signal.push(signal);
self self
} }
pub fn set_down_signal(mut self, signal: Signal) -> Self { pub fn add_down_signal(mut self, signal: Signal) -> Self {
self.down_signal = signal; self.down_signal.push(signal);
self self
} }
pub fn set_target(mut self, target: Target) -> Self { pub fn add_target(mut self, target: Target) -> Self {
self.target = target; self.target.push(target);
self self
} }
} }
@ -177,9 +202,9 @@ impl TryFrom<Vec<OwnedAttribute>> for Dish {
is_ddor, is_ddor,
created, created,
updated, updated,
up_signal: Signal::default(), up_signal: Vec::new(),
down_signal: Signal::default(), down_signal: Vec::new(),
target: Target::default(), target: Vec::new(),
}) })
} }
} }

View File

@ -3,7 +3,7 @@ use reqwest::blocking::Client;
use crate::config::VisualizerConfig; use crate::config::VisualizerConfig;
use std::sync::mpsc; use std::sync::mpsc;
use std::time::Duration; use std::time::Duration;
use crate::dsn::models::Station; use crate::dsn::models::{Station, SignalType};
mod dsn; mod dsn;
mod config; mod config;
@ -38,7 +38,19 @@ fn main() {
loop { loop {
let stations = rx.recv().unwrap(); let stations = rx.recv().unwrap();
for station in stations { for station in stations {
println!("Station: {:?}\n Dishes: {:?}", station.name, station.dishes) 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)
}
}
}
} }
} }