Skip to main content

nyx_space/od/ground_station/
doppler_config.rs

1/*
2    Nyx, blazing fast astrodynamics
3    Copyright (C) 2018-onwards Christopher Rabotin <christopher.rabotin@gmail.com>
4
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU Affero General Public License as published
7    by the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU Affero General Public License for more details.
14
15    You should have received a copy of the GNU Affero General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.
17*/
18
19use crate::od::msr::IntegrationRef;
20use der::{Decode, Encode, Reader};
21use hifitime::{Duration, Unit};
22use serde::{Deserialize, Serialize};
23
24#[cfg(feature = "python")]
25use pyo3::prelude::*;
26
27#[cfg_attr(feature = "python", pyclass(from_py_object, get_all, set_all))]
28#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
29pub struct DopplerConfig {
30    /// Duration needed to generate a measurement (if unset, it is assumed to be instantaneous)
31    pub integration_time: Duration,
32    #[serde(default)]
33    /// The integration reference flag as per CCSDS TDM, i.e. if the time tag of the data is
34    pub integration_ref: IntegrationRef,
35}
36
37impl Default for DopplerConfig {
38    fn default() -> Self {
39        Self {
40            integration_time: 1 * Unit::Second,
41            integration_ref: IntegrationRef::End,
42        }
43    }
44}
45
46impl<'a> Decode<'a> for DopplerConfig {
47    fn decode<R: Reader<'a>>(decoder: &mut R) -> der::Result<Self> {
48        let integration_time_ns = decoder.decode()?;
49        let integration_time = Duration::from_total_nanoseconds(integration_time_ns);
50        let integration_ref = decoder.decode()?;
51
52        Ok(DopplerConfig {
53            integration_time,
54            integration_ref,
55        })
56    }
57}
58
59impl Encode for DopplerConfig {
60    fn encoded_len(&self) -> der::Result<der::Length> {
61        self.integration_time.total_nanoseconds().encoded_len()?
62            + self.integration_ref.encoded_len()?
63    }
64
65    fn encode(&self, encoder: &mut impl der::Writer) -> der::Result<()> {
66        let integration_time_ns = self.integration_time.total_nanoseconds();
67        integration_time_ns.encode(encoder)?;
68        self.integration_ref.encode(encoder)?;
69
70        Ok(())
71    }
72}
73
74#[cfg_attr(feature = "python", pymethods)]
75impl DopplerConfig {
76    fn __str__(&self) -> String {
77        format!("{self:?}")
78    }
79
80    fn __repr__(&self) -> String {
81        format!("{self:?} @ {self:p}")
82    }
83
84    fn __eq__(&self, other: &Self) -> bool {
85        self == other
86    }
87}