use crate::cot_base::{CursorOnTarget, Sendable};
use crate::time::Time;
use std::fmt::{Debug, Formatter, Result as FmtResult};
pub struct Video {
pub protocol: Option<String>,
pub path: Option<String>,
pub address: Option<String>,
pub port: Option<u16>,
pub uid: Option<String>,
pub alias: Option<String>,
pub rover_port: Option<i32>,
pub rtsp_reliable: Option<bool>,
pub ignore_embedded_klv: Option<bool>,
pub network_timeout: Option<i32>,
pub buffer_time: Option<i32>,
}
pub struct Sensor {
pub cot: CursorOnTarget,
uid: String,
video_uid: String,
parent_callsign: String,
callsign: String,
fov: f64,
fov_blue: f64,
display_magnetic_reference: f64,
range: f64,
fov_green: f64,
fov_alpha: f64,
hide_fov: bool,
fov_red: f64,
azimuth: i32,
}
impl Debug for Sensor {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
f.debug_struct("Sensor")
.field("cot", &self.cot)
.field("fov", &self.fov)
.field("fov_blue", &self.fov_blue)
.field(
"display_magnetic_reference",
&self.display_magnetic_reference,
)
.field("range", &self.range)
.field("fov_green", &self.fov_green)
.field("fov_alpha", &self.fov_alpha)
.field("hide_fov", &self.hide_fov)
.field("fov_red", &self.fov_red)
.field("azimuth", &self.azimuth)
.finish()
}
}
impl Sensor {
pub fn new(
cot: CursorOnTarget,
uid: String,
video_uid: String,
parent_callsign: String,
callsign: String,
fov: f64,
fov_blue: f64,
display_magnetic_reference: f64,
range: f64,
fov_green: f64,
fov_alpha: f64,
hide_fov: bool,
fov_red: f64,
azimuth: i32,
) -> Self {
let mut updated_cot = cot;
updated_cot.type_string = Some("b-m-p-s-p-loc".to_string());
let mut new_sensor = Sensor {
cot: updated_cot,
uid: uid.clone(),
video_uid: video_uid.clone(),
callsign: callsign.clone(),
parent_callsign: parent_callsign.clone(),
fov,
fov_blue,
display_magnetic_reference,
range,
fov_green,
fov_alpha,
hide_fov,
fov_red,
azimuth,
};
new_sensor.update_xml();
new_sensor
}
pub fn get_xml(&mut self) -> String {
self.cot.get_xml()
}
pub fn get_xml_bytes(&mut self) -> Vec<u8> {
self.cot.get_xml_bytes()
}
}
impl Sendable for Sensor {
fn update_xml(&mut self) {
let mut detail = String::new();
detail.push_str(&format!(
"<contact callsign=\"{}\" />\n",
self.callsign
));
detail.push_str(&format!(
"<link type=\"a-f-G-U-C-I\" uid=\"{}\" parent_callsign=\"{}\" relation=\"p-p\" production_time=\"{}\" />\n",
self.video_uid,
self.parent_callsign,
Time::now().to_string()
));
detail.push_str("<archive />\n");
detail.push_str(&format!(
"<sensor fov=\"{}\" fovBlue=\"{}\" displayMagneticReference=\"{}\" range=\"{}\" fovGreen=\"{}\" fovAlpha=\"{}\" hideFov=\"{}\" fovRed=\"{}\" azimuth=\"{}\" />\n",
self.fov, self.fov_blue, self.display_magnetic_reference, self.range, self.fov_green, self.fov_alpha, self.hide_fov, self.fov_red, self.azimuth
));
detail.push_str("<remarks />\n");
detail.push_str(&format!(
"<__video uid=\"{}\" />\n",
self.video_uid
));
self.cot.set_xml_detail(detail);
}
fn modify_field(&mut self, field: &str, value: &str) {
match field {
"uid" => {
self.uid = value.to_string();
}
"video_uid" => {
self.video_uid = value.to_string();
}
"parent_callsign" => {
self.parent_callsign = value.to_string();
}
"callsign" => {
self.callsign = value.to_string();
}
"fov" => {
self.fov = value.parse().unwrap();
}
"fov_blue" => {
self.fov_blue = value.parse().unwrap();
}
"display_magnetic_reference" => {
self.display_magnetic_reference = value.parse().unwrap();
}
"range" => {
self.range = value.parse().unwrap();
}
"fov_green" => {
self.fov_green = value.parse().unwrap();
}
"fov_alpha" => {
self.fov_alpha = value.parse().unwrap();
}
"hide_fov" => {
self.hide_fov = value.parse().unwrap();
}
"fov_red" => {
self.fov_red = value.parse().unwrap();
}
"azimuth" => {
self.azimuth = value.parse().unwrap();
}
_ => {}
}
self.update_xml();
}
fn get_cot(&self)-> CursorOnTarget {
self.cot.clone()
}
}