sct_reader/loaders/vnas_crc/
mod.rs1use std::{fs::File, path::Path};
2
3use anyhow::Context;
4use aviation_calc_util::geo::GeoPoint;
5use facility::CrcFacility;
6use serde::{Deserialize, Serialize};
7
8pub mod facility;
9pub mod eram;
10pub mod stars;
11pub mod tower;
12
13#[derive(Debug, Clone, Default, Serialize, Deserialize)]
14#[serde(rename_all = "camelCase")]
15pub struct CrcVideoMapRef {
16 pub id: String,
17 pub name: String,
18 pub tags: Vec<String>,
19 pub short_name: Option<String>,
20 pub source_file_name: String,
21 pub stars_brightness_category: String,
22 pub stars_id: Option<i32>,
23 pub stars_always_visible: bool,
24 pub tdm_only: bool
25}
26
27#[derive(Debug, Clone, Default, Serialize, Deserialize)]
28#[serde(rename_all = "camelCase")]
29pub struct CrcTranceiver {
30 pub id: String,
31 pub name: String,
32 pub location: GeoPoint,
33 pub height_msl_meters: f64,
34 pub height_agl_meters: f64
35}
36
37#[derive(Debug, Clone, Default, Serialize, Deserialize)]
38#[serde(rename_all = "camelCase")]
39pub struct CrcPackage {
40 pub id: String,
41 #[serde(skip)]
42 pub file_path: String,
43 pub video_maps: Vec<CrcVideoMapRef>,
44 pub transceivers: Vec<CrcTranceiver>,
45 pub visibility_centers: Vec<GeoPoint>,
46 pub facility: CrcFacility
47}
48
49impl CrcPackage {
50 pub fn try_new_from_file(file: impl AsRef<Path>) -> anyhow::Result<Self> {
51 let mut package: CrcPackage = serde_json::from_reader::<File, CrcPackage>(File::open(&file)?).context("Invalid CRC Json")?;
52
53 package.file_path = file.as_ref().canonicalize()?.to_str().context("Could not convert CRC File Path to String")?.to_string();
54
55 Ok(package)
56 }
57}