doris_rs/header/
antenna.rs1use crate::{fmt_doris, prelude::FormattingError};
2
3use std::io::{BufWriter, Write};
4
5#[cfg(feature = "serde")]
6use serde::{Deserialize, Serialize};
7
8#[derive(Default, Clone, Debug, PartialEq)]
10#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11pub struct Antenna {
12 pub model: String,
14
15 pub serial_number: String,
17
18 pub approx_coordinates: Option<(f64, f64, f64)>,
20
21 pub height: Option<f64>,
24
25 pub eastern: Option<f64>,
28
29 pub northern: Option<f64>,
32}
33
34impl Antenna {
35 pub(crate) fn format<W: Write>(&self, w: &mut BufWriter<W>) -> Result<(), FormattingError> {
37 writeln!(
38 w,
39 "{}",
40 fmt_doris(
41 &format!("{:<20}{}", self.serial_number, self.model),
42 "ANT # / TYPE"
43 )
44 )?;
45
46 if let Some(coords) = &self.approx_coordinates {
47 writeln!(
48 w,
49 "{}",
50 fmt_doris(
51 &format!("{:14.4}{:14.4}{:14.4}", coords.0, coords.1, coords.2),
52 "APPROX POSITION XYZ"
53 )
54 )?;
55 }
56
57 writeln!(
58 w,
59 "{}",
60 fmt_doris(
61 &format!(
62 "{:14.4}{:14.4}{:14.4}",
63 self.height.unwrap_or(0.0),
64 self.eastern.unwrap_or(0.0),
65 self.northern.unwrap_or(0.0)
66 ),
67 "ANTENNA: DELTA H/E/N"
68 )
69 )?;
70
71 Ok(())
72 }
73
74 pub fn with_model(&self, m: &str) -> Self {
76 let mut s = self.clone();
77 s.model = m.to_string();
78 s
79 }
80
81 pub fn with_serial_number(&self, serial_number: &str) -> Self {
83 let mut s = self.clone();
84 s.serial_number = serial_number.to_string();
85 s
86 }
87
88 pub fn with_base_coordinates(&self, coords: (f64, f64, f64)) -> Self {
90 let mut s = self.clone();
91 s.approx_coordinates = Some(coords);
92 s
93 }
94
95 pub fn with_height(&self, h: f64) -> Self {
97 let mut s = self.clone();
98 s.height = Some(h);
99 s
100 }
101
102 pub fn with_eastern_component(&self, e: f64) -> Self {
104 let mut s = self.clone();
105 s.eastern = Some(e);
106 s
107 }
108
109 pub fn with_northern_component(&self, n: f64) -> Self {
111 let mut s = self.clone();
112 s.northern = Some(n);
113 s
114 }
115}