use crate::messages::digital_radar_data::DataBlockId;
use crate::messages::primitive_aliases::{Integer2, Real4, ScaledInteger2};
use serde::Deserialize;
use std::fmt::Debug;
#[cfg(feature = "uom")]
use uom::si::f64::{Information, Length, Velocity};
#[derive(Clone, PartialEq, Deserialize)]
pub struct RadialDataBlock {
pub data_block_id: DataBlockId,
pub lrtup: Integer2,
pub unambiguous_range: ScaledInteger2,
pub horizontal_channel_noise_level: Real4,
pub vertical_channel_noise_level: Real4,
pub nyquist_velocity: ScaledInteger2,
pub radial_flags: Integer2,
pub horizontal_channel_calibration_constant: Real4,
pub vertical_channel_calibration_constant: Real4,
}
impl RadialDataBlock {
#[cfg(feature = "uom")]
pub fn lrtup(&self) -> Information {
Information::new::<uom::si::information::byte>(self.lrtup as f64)
}
#[cfg(feature = "uom")]
pub fn unambiguous_range(&self) -> Length {
Length::new::<uom::si::length::kilometer>(self.unambiguous_range as f64)
}
#[cfg(feature = "uom")]
pub fn nyquist_velocity(&self) -> Velocity {
Velocity::new::<uom::si::velocity::meter_per_second>(self.nyquist_velocity as f64 * 0.01)
}
}
#[cfg(not(feature = "uom"))]
impl Debug for RadialDataBlock {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("RadialDataBlock")
.field("data_block_id", &self.data_block_id)
.field("lrtup", &self.lrtup)
.field("unambiguous_range", &self.unambiguous_range)
.field(
"horizontal_channel_noise_level",
&self.horizontal_channel_noise_level,
)
.field(
"vertical_channel_noise_level",
&self.vertical_channel_noise_level,
)
.field("nyquist_velocity", &self.nyquist_velocity)
.field("radial_flags", &self.radial_flags)
.field(
"horizontal_channel_calibration_constant",
&self.horizontal_channel_calibration_constant,
)
.field(
"vertical_channel_calibration_constant",
&self.vertical_channel_calibration_constant,
)
.finish()
}
}
#[cfg(feature = "uom")]
impl Debug for RadialDataBlock {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("RadialDataBlock")
.field("data_block_id", &self.data_block_id)
.field("lrtup", &self.lrtup())
.field("unambiguous_range", &self.unambiguous_range())
.field(
"horizontal_channel_noise_level",
&self.horizontal_channel_noise_level,
)
.field(
"vertical_channel_noise_level",
&self.vertical_channel_noise_level,
)
.field("nyquist_velocity", &self.nyquist_velocity())
.field("radial_flags", &self.radial_flags)
.field(
"horizontal_channel_calibration_constant",
&self.horizontal_channel_calibration_constant,
)
.field(
"vertical_channel_calibration_constant",
&self.vertical_channel_calibration_constant,
)
.finish()
}
}