kinda stuck at this point so making a commit

This commit is contained in:
2024-10-31 00:19:02 +01:00
parent cd7d9fa3b7
commit 6d65463286
35 changed files with 44224 additions and 217 deletions

View File

@@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0.90"
bincode = "1.3.3"
derive_more = "1.0.0"
flate2 = { version = "1.0.34", features = ["zlib-rs"] }
serde = { version = "1.0.210", features = ["derive"] }
thiserror = "1.0.64"

View File

@@ -1,18 +1,153 @@
use derive_more::derive::Display;
use serde::{de, Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[derive(Debug, Display, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub enum SystemPacket {
Ping,
Pong,
Close { reason: String },
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[derive(Debug, Display, Clone, Deserialize, Serialize)]
pub enum SimConnectPacket {
// ..
AtcID(String),
Airplane(Airplane),
Fuel(Fuel),
Gps(Gps),
OnGround(OnGround),
IsParked(IsParked),
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[derive(Debug, Clone, Display, Deserialize, Serialize)]
#[display("[{atc_type} - {atc_model}] {title} ({category})")]
pub struct Airplane {
pub atc_type: String,
pub atc_model: String,
pub title: String,
pub category: String,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Fuel {
pub center_quantity: f64,
pub center_capacity: f64,
pub center2_quantity: f64,
pub center2_capacity: f64,
pub center3_quantity: f64,
pub center3_capacity: f64,
pub left_main_quantity: f64,
pub left_main_capacity: f64,
pub left_aux_quantity: f64,
pub left_aux_capacity: f64,
pub left_tip_quantity: f64,
pub left_tip_capacity: f64,
pub right_main_quantity: f64,
pub right_main_capacity: f64,
pub right_aux_quantity: f64,
pub right_aux_capacity: f64,
pub right_tip_quantity: f64,
pub right_tip_capacity: f64,
pub external1_quantity: f64,
pub external1_capacity: f64,
pub external2_quantity: f64,
pub external2_capacity: f64,
pub weight: f64,
}
impl Fuel {
pub fn total_quantity(&self) -> f64 {
self.center_quantity
+ self.center2_quantity
+ self.center3_quantity
+ self.left_main_quantity
+ self.left_aux_quantity
+ self.left_tip_quantity
+ self.right_main_quantity
+ self.right_aux_quantity
+ self.right_tip_quantity
+ self.external1_quantity
+ self.external2_quantity
}
pub fn total_capacity(&self) -> f64 {
self.center_capacity
+ self.center2_capacity
+ self.center3_capacity
+ self.left_main_capacity
+ self.left_aux_capacity
+ self.left_tip_capacity
+ self.right_main_capacity
+ self.right_aux_capacity
+ self.right_tip_capacity
+ self.external1_capacity
+ self.external2_capacity
}
}
impl core::fmt::Display for Fuel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let percent = (100.0 / self.total_capacity()) * self.total_quantity();
write!(
f,
"{}GL/{}GL ({}%)",
self.total_quantity(),
self.total_capacity(),
percent
)
}
}
#[derive(Debug, Clone, Display, Deserialize, Serialize)]
#[display("{lat}, {lon} at {alt}ft")]
pub struct Gps {
pub lat: f64,
pub lon: f64,
pub alt: f64,
}
#[derive(Debug, Clone, Display, Deserialize, Serialize)]
pub struct OnGround {
pub sim_on_ground: bool,
}
#[derive(Debug, Clone, Display, Deserialize, Serialize)]
pub struct IsParked {
pub is_parked: bool,
}
// #[derive(Debug, Display, Clone, Deserialize, Serialize)]
// #[display("[{icao}] {lat} {lon} {alt}")]
// pub struct Airport {
// pub icao: String,
// pub region: String,
// pub lat: f64,
// pub lon: f64,
// pub alt: f64,
// }
impl PartialEq for SimConnectPacket {
fn eq(&self, other: &Self) -> bool {
matches!(
(self, other),
(Self::AtcID(_), Self::AtcID(_)) | (Self::Fuel(_), Self::Fuel(_))
)
}
}
impl Eq for SimConnectPacket {}
#[derive(Debug, Display, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub enum Packets {
System(SystemPacket),
SimConnect(SimConnectPacket),