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 infomain
parent
3729fd87f0
commit
b0621b636d
|
@ -61,17 +61,17 @@ where
|
|||
} else if name.local_name.contains("downSignal") {
|
||||
dish = Some(
|
||||
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") {
|
||||
dish = Some(
|
||||
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") {
|
||||
dish = Some(
|
||||
dish.unwrap()
|
||||
.set_target(Target::try_from(attributes).unwrap()),
|
||||
.add_target(Target::try_from(attributes).unwrap()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)]
|
||||
pub struct Signal {
|
||||
pub signal_type: String,
|
||||
pub signal_type: SignalType,
|
||||
pub signal_type_debug: String,
|
||||
pub data_rate: Option<f64>,
|
||||
pub frequency: Option<f64>,
|
||||
|
@ -68,7 +93,7 @@ impl TryFrom<Vec<OwnedAttribute>> for Signal {
|
|||
type Error = ParseError;
|
||||
|
||||
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 data_rate = get_attr(&attrs, "dataRate")?.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)]
|
||||
pub struct Target {
|
||||
name: String,
|
||||
id: u32,
|
||||
pub name: String,
|
||||
pub id: u32,
|
||||
/// Up Leg Range (km)
|
||||
upleg_range: f64,
|
||||
pub upleg_range: f64,
|
||||
/// Down Leg Leg Range (km)
|
||||
downleg_range: f64,
|
||||
pub downleg_range: f64,
|
||||
/// Round trip light time (s)
|
||||
rtlt: f64,
|
||||
pub rtlt: f64,
|
||||
}
|
||||
|
||||
impl TryFrom<Vec<OwnedAttribute>> for Target {
|
||||
|
@ -131,24 +156,24 @@ pub struct Dish {
|
|||
pub is_ddor: bool,
|
||||
pub created: DateTime<Utc>,
|
||||
pub updated: DateTime<Utc>,
|
||||
pub up_signal: Signal,
|
||||
pub down_signal: Signal,
|
||||
pub target: Target,
|
||||
pub up_signal: Vec<Signal>,
|
||||
pub down_signal: Vec<Signal>,
|
||||
pub target: Vec<Target>,
|
||||
}
|
||||
|
||||
impl Dish {
|
||||
pub fn set_up_signal(mut self, signal: Signal) -> Self {
|
||||
self.up_signal = signal;
|
||||
pub fn add_up_signal(mut self, signal: Signal) -> Self {
|
||||
self.up_signal.push(signal);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_down_signal(mut self, signal: Signal) -> Self {
|
||||
self.down_signal = signal;
|
||||
pub fn add_down_signal(mut self, signal: Signal) -> Self {
|
||||
self.down_signal.push(signal);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_target(mut self, target: Target) -> Self {
|
||||
self.target = target;
|
||||
pub fn add_target(mut self, target: Target) -> Self {
|
||||
self.target.push(target);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
@ -177,9 +202,9 @@ impl TryFrom<Vec<OwnedAttribute>> for Dish {
|
|||
is_ddor,
|
||||
created,
|
||||
updated,
|
||||
up_signal: Signal::default(),
|
||||
down_signal: Signal::default(),
|
||||
target: Target::default(),
|
||||
up_signal: Vec::new(),
|
||||
down_signal: Vec::new(),
|
||||
target: Vec::new(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -3,7 +3,7 @@ use reqwest::blocking::Client;
|
|||
use crate::config::VisualizerConfig;
|
||||
use std::sync::mpsc;
|
||||
use std::time::Duration;
|
||||
use crate::dsn::models::Station;
|
||||
use crate::dsn::models::{Station, SignalType};
|
||||
|
||||
mod dsn;
|
||||
mod config;
|
||||
|
@ -38,7 +38,19 @@ fn main() {
|
|||
loop {
|
||||
let stations = rx.recv().unwrap();
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue