mirror of
https://github.com/valmojr/armatak.git
synced 2026-06-13 11:53:28 +00:00
formatted some rust files for linting porpuses
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use uuid::Uuid;
|
||||
use chrono::{Duration, SecondsFormat, Utc};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub struct CursorOverTime {
|
||||
pub uuid: Option<String>,
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
use arma_rs::{FromArma, FromArmaError};
|
||||
use super::cot::CursorOverTime;
|
||||
use arma_rs::{FromArma, FromArmaError};
|
||||
|
||||
pub struct DigitalPointerPayload {
|
||||
pub link_uid: String,
|
||||
pub contact_callsign: String,
|
||||
pub point_lat: f64,
|
||||
pub point_lon: f64,
|
||||
pub point_hae: f32,
|
||||
pub link_uid: String,
|
||||
pub contact_callsign: String,
|
||||
pub point_lat: f64,
|
||||
pub point_lon: f64,
|
||||
pub point_hae: f32,
|
||||
}
|
||||
|
||||
impl FromArma for DigitalPointerPayload {
|
||||
fn from_arma(data: String) -> Result<DigitalPointerPayload, FromArmaError> {
|
||||
let (link_uid, contact_callsign, point_lat, point_lon, point_hae) =
|
||||
<(String, String, f64, f64, f32)>::from_arma(data)?;
|
||||
Ok(Self {
|
||||
link_uid,
|
||||
contact_callsign,
|
||||
point_lat,
|
||||
point_lon,
|
||||
point_hae,
|
||||
})
|
||||
}
|
||||
fn from_arma(data: String) -> Result<DigitalPointerPayload, FromArmaError> {
|
||||
let (link_uid, contact_callsign, point_lat, point_lon, point_hae) =
|
||||
<(String, String, f64, f64, f32)>::from_arma(data)?;
|
||||
Ok(Self {
|
||||
link_uid,
|
||||
contact_callsign,
|
||||
point_lat,
|
||||
point_lon,
|
||||
point_hae,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl DigitalPointerPayload {
|
||||
pub fn to_cot(&self) -> CursorOverTime {
|
||||
CursorOverTime {
|
||||
uuid: Some(format!("{}{}", self.link_uid.clone(), ".SPI1")),
|
||||
r#type: Some("b-m-p-s-p-i".to_string()),
|
||||
point_lat: self.point_lat,
|
||||
point_lon: self.point_lon,
|
||||
point_hae: self.point_hae,
|
||||
point_ce: None,
|
||||
point_le: None,
|
||||
contact_callsign: self.contact_callsign.clone(),
|
||||
group_name: None,
|
||||
group_role: None,
|
||||
track_course: None,
|
||||
track_speed: None,
|
||||
link_uid: Some(self.link_uid.clone()),
|
||||
remarker: None,
|
||||
}
|
||||
}
|
||||
pub fn to_cot(&self) -> CursorOverTime {
|
||||
CursorOverTime {
|
||||
uuid: Some(format!("{}{}", self.link_uid.clone(), ".SPI1")),
|
||||
r#type: Some("b-m-p-s-p-i".to_string()),
|
||||
point_lat: self.point_lat,
|
||||
point_lon: self.point_lon,
|
||||
point_hae: self.point_hae,
|
||||
point_ce: None,
|
||||
point_le: None,
|
||||
contact_callsign: self.contact_callsign.clone(),
|
||||
group_name: None,
|
||||
group_role: None,
|
||||
track_course: None,
|
||||
track_speed: None,
|
||||
link_uid: Some(self.link_uid.clone()),
|
||||
remarker: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
pub mod circle;
|
||||
pub mod circle;
|
||||
|
||||
104
src/cot/eud.rs
104
src/cot/eud.rs
@@ -1,62 +1,62 @@
|
||||
use arma_rs::{FromArma, FromArmaError};
|
||||
use super::cot::CursorOverTime;
|
||||
use arma_rs::{FromArma, FromArmaError};
|
||||
|
||||
pub struct EudCoTPayload {
|
||||
pub uuid: String,
|
||||
pub point_lat: f64,
|
||||
pub point_lon: f64,
|
||||
pub point_hae: f32,
|
||||
pub contact_callsign: String,
|
||||
pub group_name: String,
|
||||
pub group_role: String,
|
||||
pub track_course: i32,
|
||||
pub track_speed: f32,
|
||||
pub uuid: String,
|
||||
pub point_lat: f64,
|
||||
pub point_lon: f64,
|
||||
pub point_hae: f32,
|
||||
pub contact_callsign: String,
|
||||
pub group_name: String,
|
||||
pub group_role: String,
|
||||
pub track_course: i32,
|
||||
pub track_speed: f32,
|
||||
}
|
||||
|
||||
impl FromArma for EudCoTPayload {
|
||||
fn from_arma(data: String) -> Result<EudCoTPayload, FromArmaError> {
|
||||
let (
|
||||
uuid,
|
||||
point_lat,
|
||||
point_lon,
|
||||
point_hae,
|
||||
contact_callsign,
|
||||
group_name,
|
||||
group_role,
|
||||
track_course,
|
||||
track_speed,
|
||||
) = <(String, f64, f64, f32, String, String, String, i32, f32)>::from_arma(data)?;
|
||||
Ok(Self {
|
||||
uuid,
|
||||
point_lat,
|
||||
point_lon,
|
||||
point_hae,
|
||||
contact_callsign,
|
||||
group_name,
|
||||
group_role,
|
||||
track_course,
|
||||
track_speed,
|
||||
})
|
||||
}
|
||||
fn from_arma(data: String) -> Result<EudCoTPayload, FromArmaError> {
|
||||
let (
|
||||
uuid,
|
||||
point_lat,
|
||||
point_lon,
|
||||
point_hae,
|
||||
contact_callsign,
|
||||
group_name,
|
||||
group_role,
|
||||
track_course,
|
||||
track_speed,
|
||||
) = <(String, f64, f64, f32, String, String, String, i32, f32)>::from_arma(data)?;
|
||||
Ok(Self {
|
||||
uuid,
|
||||
point_lat,
|
||||
point_lon,
|
||||
point_hae,
|
||||
contact_callsign,
|
||||
group_name,
|
||||
group_role,
|
||||
track_course,
|
||||
track_speed,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl EudCoTPayload {
|
||||
pub fn to_cot(&self) -> CursorOverTime {
|
||||
CursorOverTime {
|
||||
uuid: Some(self.uuid.clone()),
|
||||
r#type: None,
|
||||
point_lat: self.point_lat,
|
||||
point_lon: self.point_lon,
|
||||
point_hae: self.point_hae,
|
||||
point_ce: None,
|
||||
point_le: None,
|
||||
contact_callsign: self.contact_callsign.clone(),
|
||||
group_name: Some(self.group_name.clone()),
|
||||
group_role: Some(self.group_role.clone()),
|
||||
track_course: Some(self.track_course),
|
||||
track_speed: Some(self.track_speed),
|
||||
link_uid: None,
|
||||
remarker: None,
|
||||
}
|
||||
}
|
||||
pub fn to_cot(&self) -> CursorOverTime {
|
||||
CursorOverTime {
|
||||
uuid: Some(self.uuid.clone()),
|
||||
r#type: None,
|
||||
point_lat: self.point_lat,
|
||||
point_lon: self.point_lon,
|
||||
point_hae: self.point_hae,
|
||||
point_ce: None,
|
||||
point_le: None,
|
||||
contact_callsign: self.contact_callsign.clone(),
|
||||
group_name: Some(self.group_name.clone()),
|
||||
group_role: Some(self.group_role.clone()),
|
||||
track_course: Some(self.track_course),
|
||||
track_speed: Some(self.track_speed),
|
||||
link_uid: None,
|
||||
remarker: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use arma_rs::{FromArma, FromArmaError};
|
||||
use super::cot::CursorOverTime;
|
||||
use arma_rs::{FromArma, FromArmaError};
|
||||
|
||||
pub struct ExternalPositionPayload {
|
||||
pub uuid: String,
|
||||
@@ -13,47 +13,47 @@ pub struct ExternalPositionPayload {
|
||||
}
|
||||
|
||||
impl FromArma for ExternalPositionPayload {
|
||||
fn from_arma(data: String) -> Result<ExternalPositionPayload, FromArmaError> {
|
||||
let (
|
||||
uuid,
|
||||
point_lat,
|
||||
point_lon,
|
||||
point_hae,
|
||||
contact_callsign,
|
||||
track_course,
|
||||
track_speed,
|
||||
remarker,
|
||||
) = <(String, f64, f64, f32, String, i32, f32, String)>::from_arma(data)?;
|
||||
Ok(Self {
|
||||
uuid,
|
||||
point_lat,
|
||||
point_lon,
|
||||
point_hae,
|
||||
contact_callsign,
|
||||
track_course,
|
||||
track_speed,
|
||||
remarker,
|
||||
})
|
||||
}
|
||||
fn from_arma(data: String) -> Result<ExternalPositionPayload, FromArmaError> {
|
||||
let (
|
||||
uuid,
|
||||
point_lat,
|
||||
point_lon,
|
||||
point_hae,
|
||||
contact_callsign,
|
||||
track_course,
|
||||
track_speed,
|
||||
remarker,
|
||||
) = <(String, f64, f64, f32, String, i32, f32, String)>::from_arma(data)?;
|
||||
Ok(Self {
|
||||
uuid,
|
||||
point_lat,
|
||||
point_lon,
|
||||
point_hae,
|
||||
contact_callsign,
|
||||
track_course,
|
||||
track_speed,
|
||||
remarker,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ExternalPositionPayload {
|
||||
pub fn to_cot(&self) -> CursorOverTime {
|
||||
CursorOverTime {
|
||||
uuid: Some(self.uuid.clone()),
|
||||
r#type: None,
|
||||
point_lat: self.point_lat,
|
||||
point_lon: self.point_lon,
|
||||
point_hae: self.point_hae,
|
||||
point_ce: None,
|
||||
point_le: None,
|
||||
contact_callsign: self.contact_callsign.clone(),
|
||||
group_name: None,
|
||||
group_role: None,
|
||||
track_course: Some(self.track_course),
|
||||
track_speed: Some(self.track_speed),
|
||||
link_uid: None,
|
||||
remarker: Some(self.remarker.clone()),
|
||||
}
|
||||
}
|
||||
pub fn to_cot(&self) -> CursorOverTime {
|
||||
CursorOverTime {
|
||||
uuid: Some(self.uuid.clone()),
|
||||
r#type: None,
|
||||
point_lat: self.point_lat,
|
||||
point_lon: self.point_lon,
|
||||
point_hae: self.point_hae,
|
||||
point_ce: None,
|
||||
point_le: None,
|
||||
contact_callsign: self.contact_callsign.clone(),
|
||||
group_name: None,
|
||||
group_role: None,
|
||||
track_course: Some(self.track_course),
|
||||
track_speed: Some(self.track_speed),
|
||||
link_uid: None,
|
||||
remarker: Some(self.remarker.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use arma_rs::{FromArma, FromArmaError};
|
||||
use chrono::{Utc, Duration, SecondsFormat};
|
||||
use chrono::{Duration, SecondsFormat, Utc};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub struct MessagePayload {
|
||||
@@ -14,8 +14,7 @@ pub struct MessagePayload {
|
||||
|
||||
impl FromArma for MessagePayload {
|
||||
fn from_arma(data: String) -> Result<Self, FromArmaError> {
|
||||
let (sender_callsign, chatroom, message_text,
|
||||
point_lat, point_lon, point_hae, sender_uid) =
|
||||
let (sender_callsign, chatroom, message_text, point_lat, point_lon, point_hae, sender_uid) =
|
||||
<(String, String, String, f64, f64, f32, String)>::from_arma(data)?;
|
||||
|
||||
Ok(Self {
|
||||
@@ -55,8 +54,8 @@ impl MessageCot {
|
||||
|
||||
pub fn to_xml(&self) -> String {
|
||||
let created_time = Utc::now().to_rfc3339_opts(SecondsFormat::Millis, true);
|
||||
let stale_time = (Utc::now() + Duration::days(1))
|
||||
.to_rfc3339_opts(SecondsFormat::Millis, true);
|
||||
let stale_time =
|
||||
(Utc::now() + Duration::days(1)).to_rfc3339_opts(SecondsFormat::Millis, true);
|
||||
|
||||
// MESSAGE ID (random UUID)
|
||||
let message_uuid = Uuid::new_v4().to_string();
|
||||
@@ -98,10 +97,7 @@ impl MessageCot {
|
||||
format!(
|
||||
"<__chat parent=\"RootContactGroup\" groupOwner=\"false\" \
|
||||
messageId=\"{}\" chatroom=\"{}\" id=\"{}\" senderCallsign=\"{}\">",
|
||||
message_uuid,
|
||||
self.chatroom,
|
||||
self.chatroom,
|
||||
self.sender_callsign,
|
||||
message_uuid, self.chatroom, self.chatroom, self.sender_callsign,
|
||||
)
|
||||
.as_str(),
|
||||
);
|
||||
@@ -109,9 +105,7 @@ impl MessageCot {
|
||||
xml.push_str(
|
||||
format!(
|
||||
"<chatgrp uid0=\"{}\" uid1=\"{}\" id=\"{}\" />",
|
||||
self.sender_uid,
|
||||
self.chatroom,
|
||||
self.chatroom
|
||||
self.sender_uid, self.chatroom, self.chatroom
|
||||
)
|
||||
.as_str(),
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
pub mod draws;
|
||||
pub mod cot;
|
||||
pub mod digital_pointer;
|
||||
pub mod draws;
|
||||
pub mod eud;
|
||||
pub mod gps;
|
||||
pub mod message;
|
||||
pub mod nato;
|
||||
pub mod nato;
|
||||
|
||||
@@ -10,9 +10,6 @@ pub struct LogPayload {
|
||||
impl FromArma for LogPayload {
|
||||
fn from_arma(data: String) -> Result<LogPayload, FromArmaError> {
|
||||
let (status, message) = <(String, String)>::from_arma(data)?;
|
||||
Ok(Self {
|
||||
status,
|
||||
message
|
||||
})
|
||||
Ok(Self { status, message })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,21 +9,30 @@ pub fn send_eud_cot(ctx: Context, cursor_over_time: cot::eud::EudCoTPayload) ->
|
||||
"Sending End User Device Cursor Over Time to TCP server"
|
||||
}
|
||||
|
||||
pub fn send_marker_cot(ctx: Context, cursor_over_time: cot::nato::MarkerCoTPayload) -> &'static str {
|
||||
pub fn send_marker_cot(
|
||||
ctx: Context,
|
||||
cursor_over_time: cot::nato::MarkerCoTPayload,
|
||||
) -> &'static str {
|
||||
let payload = cursor_over_time.to_cot().convert_to_xml();
|
||||
send_payload(ctx, payload);
|
||||
|
||||
"Sending Marker Cursor Over Time to TCP server"
|
||||
}
|
||||
|
||||
pub fn send_digital_pointer_cot(ctx: Context, cursor_over_time: cot::digital_pointer::DigitalPointerPayload) -> &'static str {
|
||||
pub fn send_digital_pointer_cot(
|
||||
ctx: Context,
|
||||
cursor_over_time: cot::digital_pointer::DigitalPointerPayload,
|
||||
) -> &'static str {
|
||||
let payload = cursor_over_time.to_cot().convert_to_xml();
|
||||
send_payload(ctx, payload);
|
||||
|
||||
"Sending Digital Pointer Cursor Over Time to TCP server"
|
||||
}
|
||||
|
||||
pub fn send_message_cot(ctx: Context, message_payload: cot::message::MessagePayload) -> &'static str {
|
||||
pub fn send_message_cot(
|
||||
ctx: Context,
|
||||
message_payload: cot::message::MessagePayload,
|
||||
) -> &'static str {
|
||||
let message_cot = cot::message::MessageCot::from_payload(message_payload);
|
||||
let payload = message_cot.to_xml();
|
||||
send_payload(ctx, payload);
|
||||
|
||||
@@ -2,7 +2,10 @@ use arma_rs::Context;
|
||||
|
||||
use crate::{cot, tcp::send_payload};
|
||||
|
||||
pub fn send_circle_cot(ctx: Context, circle_payload: cot::draws::circle::CircleCoTPayload) -> &'static str {
|
||||
pub fn send_circle_cot(
|
||||
ctx: Context,
|
||||
circle_payload: cot::draws::circle::CircleCoTPayload,
|
||||
) -> &'static str {
|
||||
let shape_circle_cot = circle_payload.to_cot();
|
||||
let now = chrono::Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Millis, true);
|
||||
let stale = (chrono::Utc::now() + chrono::Duration::days(1))
|
||||
@@ -14,21 +17,21 @@ pub fn send_circle_cot(ctx: Context, circle_payload: cot::draws::circle::CircleC
|
||||
}
|
||||
|
||||
pub fn send_ellipse_cot(ctx: Context) -> &'static str {
|
||||
let _ = ctx;
|
||||
"Not implemented: send_ellipse_cot"
|
||||
let _ = ctx;
|
||||
"Not implemented: send_ellipse_cot"
|
||||
}
|
||||
|
||||
pub fn send_rectangle_cot(ctx: Context) -> &'static str {
|
||||
let _ = ctx;
|
||||
"Not implemented: send_ellipse_cot"
|
||||
let _ = ctx;
|
||||
"Not implemented: send_ellipse_cot"
|
||||
}
|
||||
|
||||
pub fn send_freedraw_cot(ctx: Context) -> &'static str {
|
||||
let _ = ctx;
|
||||
"Not implemented: send_ellipse_cot"
|
||||
let _ = ctx;
|
||||
"Not implemented: send_ellipse_cot"
|
||||
}
|
||||
|
||||
pub fn send_vectordraw_cot(ctx: Context) -> &'static str {
|
||||
let _ = ctx;
|
||||
"Not implemented: send_ellipse_cot"
|
||||
}
|
||||
let _ = ctx;
|
||||
"Not implemented: send_ellipse_cot"
|
||||
}
|
||||
|
||||
34
src/tests.rs
34
src/tests.rs
@@ -1,25 +1,25 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::init;
|
||||
use uuid::Uuid;
|
||||
use std::vec;
|
||||
use crate::init;
|
||||
use std::vec;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[test]
|
||||
fn uuid_output_is_uuid4_identifier() {
|
||||
let extension = init().testing();
|
||||
let (output, _) = extension.call("uuid", None);
|
||||
#[test]
|
||||
fn uuid_output_is_uuid4_identifier() {
|
||||
let extension = init().testing();
|
||||
let (output, _) = extension.call("uuid", None);
|
||||
|
||||
let validation = Uuid::parse_str(&output);
|
||||
let validation = Uuid::parse_str(&output);
|
||||
|
||||
assert!(validation.is_ok())
|
||||
}
|
||||
assert!(validation.is_ok())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uuid_output_throws_if_passed_args() {
|
||||
let extension = init().testing();
|
||||
let args: Vec<String> = vec![1.to_string(),2.to_string()];
|
||||
let (output, _) = extension.call("uuid", Some(args));
|
||||
#[test]
|
||||
fn uuid_output_throws_if_passed_args() {
|
||||
let extension = init().testing();
|
||||
let args: Vec<String> = vec![1.to_string(), 2.to_string()];
|
||||
let (output, _) = extension.call("uuid", Some(args));
|
||||
|
||||
assert_eq!(output,"")
|
||||
}
|
||||
assert_eq!(output, "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,116 +9,119 @@ use std::thread;
|
||||
use crate::cot;
|
||||
|
||||
pub enum UdpCommand {
|
||||
SendMessage(String, Context),
|
||||
Stop,
|
||||
SendMessage(String, Context),
|
||||
Stop,
|
||||
}
|
||||
|
||||
pub struct UdpClient {
|
||||
pub(crate) tx: Sender<UdpCommand>,
|
||||
pub(crate) tx: Sender<UdpCommand>,
|
||||
}
|
||||
|
||||
impl UdpClient {
|
||||
pub fn start(&self, address: String, rx: Receiver<UdpCommand>, ctx: Context) {
|
||||
if let Some(ref client) = *UDP_CLIENT.lock().unwrap() {
|
||||
client.stop();
|
||||
pub fn start(&self, address: String, rx: Receiver<UdpCommand>, ctx: Context) {
|
||||
if let Some(ref client) = *UDP_CLIENT.lock().unwrap() {
|
||||
client.stop();
|
||||
}
|
||||
|
||||
thread::spawn(move || {
|
||||
let socket = match UdpSocket::bind("0.0.0.0:0") {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
let _ = ctx.callback_data(
|
||||
"UDP SOCKET ERROR",
|
||||
"Failed to bind UDP socket",
|
||||
e.to_string(),
|
||||
);
|
||||
info!("Failed to bind UDP socket: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let _ = ctx.callback_data("UDP SOCKET", "EUD Connected", address.clone());
|
||||
|
||||
let mut running = true;
|
||||
while running {
|
||||
match rx.recv() {
|
||||
Ok(UdpCommand::SendMessage(message, context)) => {
|
||||
if let Err(e) = socket.send_to(message.as_bytes(), &address) {
|
||||
info!("Failed to send UDP message: {}", e);
|
||||
let _ = context.callback_data(
|
||||
"UDP SOCKET ERROR",
|
||||
"Failed to send UDP message",
|
||||
e.to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(UdpCommand::Stop) => {
|
||||
running = false;
|
||||
info!("Stopping UDP client.");
|
||||
}
|
||||
Err(error) => {
|
||||
info!("Error receiving command: {}", error.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
thread::spawn(move || {
|
||||
let socket = match UdpSocket::bind("0.0.0.0:0") {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
let _ = ctx.callback_data(
|
||||
"UDP SOCKET ERROR",
|
||||
"Failed to bind UDP socket",
|
||||
e.to_string(),
|
||||
);
|
||||
info!("Failed to bind UDP socket: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
pub fn send_payload(&self, context: Context, payload: String) {
|
||||
let tx = self.tx.clone();
|
||||
thread::spawn(move || {
|
||||
tx.send(UdpCommand::SendMessage(payload, context)).unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
let _ = ctx.callback_data("UDP SOCKET", "EUD Connected", address.clone());
|
||||
|
||||
let mut running = true;
|
||||
while running {
|
||||
match rx.recv() {
|
||||
Ok(UdpCommand::SendMessage(message, context)) => {
|
||||
if let Err(e) = socket.send_to(message.as_bytes(), &address) {
|
||||
info!("Failed to send UDP message: {}", e);
|
||||
let _ = context.callback_data(
|
||||
"UDP SOCKET ERROR",
|
||||
"Failed to send UDP message",
|
||||
e.to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(UdpCommand::Stop) => {
|
||||
running = false;
|
||||
info!("Stopping UDP client.");
|
||||
}
|
||||
Err(error) => {
|
||||
info!("Error receiving command: {}", error.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub fn send_payload(&self, context: Context, payload: String) {
|
||||
let tx = self.tx.clone();
|
||||
thread::spawn(move || {
|
||||
tx.send(UdpCommand::SendMessage(payload, context)).unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
pub fn stop(&self) {
|
||||
let tx = self.tx.clone();
|
||||
thread::spawn(move || {
|
||||
tx.send(UdpCommand::Stop).unwrap();
|
||||
});
|
||||
}
|
||||
pub fn stop(&self) {
|
||||
let tx = self.tx.clone();
|
||||
thread::spawn(move || {
|
||||
tx.send(UdpCommand::Stop).unwrap();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref UDP_CLIENT: Arc<Mutex<Option<UdpClient>>> = Arc::new(Mutex::new(None));
|
||||
static ref UDP_CLIENT: Arc<Mutex<Option<UdpClient>>> = Arc::new(Mutex::new(None));
|
||||
}
|
||||
|
||||
pub fn start(ctx: Context, address: String) -> &'static str {
|
||||
let (tx, rx): (Sender<UdpCommand>, Receiver<UdpCommand>) = mpsc::channel();
|
||||
let (tx, rx): (Sender<UdpCommand>, Receiver<UdpCommand>) = mpsc::channel();
|
||||
|
||||
let client = UdpClient { tx };
|
||||
client.start(address, rx, ctx);
|
||||
let client = UdpClient { tx };
|
||||
client.start(address, rx, ctx);
|
||||
|
||||
let mut client_guard = UDP_CLIENT.lock().unwrap();
|
||||
*client_guard = Some(client);
|
||||
let mut client_guard = UDP_CLIENT.lock().unwrap();
|
||||
*client_guard = Some(client);
|
||||
|
||||
"Starting UDP Client"
|
||||
"Starting UDP Client"
|
||||
}
|
||||
|
||||
pub fn send_payload(ctx: Context, payload: String) -> &'static str {
|
||||
if let Some(ref client) = *UDP_CLIENT.lock().unwrap() {
|
||||
client.send_payload(ctx, payload);
|
||||
} else {
|
||||
let _ = ctx.callback_null("UDP SOCKET ERROR", "UDP Socket is not running");
|
||||
}
|
||||
if let Some(ref client) = *UDP_CLIENT.lock().unwrap() {
|
||||
client.send_payload(ctx, payload);
|
||||
} else {
|
||||
let _ = ctx.callback_null("UDP SOCKET ERROR", "UDP Socket is not running");
|
||||
}
|
||||
|
||||
"Sending payload to UDP server"
|
||||
"Sending payload to UDP server"
|
||||
}
|
||||
|
||||
pub fn send_gps_cot(ctx: Context, cursor_over_time: cot::gps::ExternalPositionPayload) -> &'static str {
|
||||
let payload = cursor_over_time.to_cot().convert_to_xml();
|
||||
send_payload(ctx, payload);
|
||||
pub fn send_gps_cot(
|
||||
ctx: Context,
|
||||
cursor_over_time: cot::gps::ExternalPositionPayload,
|
||||
) -> &'static str {
|
||||
let payload = cursor_over_time.to_cot().convert_to_xml();
|
||||
send_payload(ctx, payload);
|
||||
|
||||
"Sending GPS Cursor Over Time to UDP server"
|
||||
"Sending GPS Cursor Over Time to UDP server"
|
||||
}
|
||||
|
||||
pub fn stop(ctx: Context) -> &'static str {
|
||||
if let Some(ref client) = *UDP_CLIENT.lock().unwrap() {
|
||||
client.stop();
|
||||
let _ = ctx.callback_null("UDP SOCKET", "EUD Disconnected");
|
||||
} else {
|
||||
let _ = ctx.callback_null("UDP SOCKET ERROR", "UDP Socket is not running");
|
||||
}
|
||||
if let Some(ref client) = *UDP_CLIENT.lock().unwrap() {
|
||||
client.stop();
|
||||
let _ = ctx.callback_null("UDP SOCKET", "EUD Disconnected");
|
||||
} else {
|
||||
let _ = ctx.callback_null("UDP SOCKET ERROR", "UDP Socket is not running");
|
||||
}
|
||||
|
||||
"Stopping UDP Client"
|
||||
"Stopping UDP Client"
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
use std::net::{IpAddr, UdpSocket};
|
||||
|
||||
pub fn get_local_address() -> String {
|
||||
fn get_local_ip() -> Result<IpAddr, String> {
|
||||
let socket = UdpSocket::bind("0.0.0.0:0").map_err(|e| e.to_string())?;
|
||||
socket.connect("8.8.8.8:80").map_err(|e| e.to_string())?;
|
||||
socket
|
||||
.local_addr()
|
||||
.map(|addr| addr.ip())
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
fn get_local_ip() -> Result<IpAddr, String> {
|
||||
let socket = UdpSocket::bind("0.0.0.0:0").map_err(|e| e.to_string())?;
|
||||
socket.connect("8.8.8.8:80").map_err(|e| e.to_string())?;
|
||||
socket
|
||||
.local_addr()
|
||||
.map(|addr| addr.ip())
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
let parsed_data = get_local_ip();
|
||||
let parsed_data = get_local_ip();
|
||||
|
||||
match parsed_data {
|
||||
Ok(ip) => {
|
||||
return format!("ws://{}:4152", ip.to_string());
|
||||
}
|
||||
Err(_) => {
|
||||
return "not provided".to_string();
|
||||
}
|
||||
}
|
||||
match parsed_data {
|
||||
Ok(ip) => {
|
||||
return format!("ws://{}:4152", ip.to_string());
|
||||
}
|
||||
Err(_) => {
|
||||
return "not provided".to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ use crate::structs::LogPayload;
|
||||
use log::{error, info, warn};
|
||||
|
||||
pub fn log_info(data: LogPayload) -> String {
|
||||
match data.status.as_str() {
|
||||
"info" => info!("{}", data.message),
|
||||
"warn" => warn!("{}", data.message),
|
||||
"error" => error!("{}", data.message),
|
||||
_ => error!("{}", "Wrong log call"),
|
||||
}
|
||||
"logged".to_string()
|
||||
}
|
||||
match data.status.as_str() {
|
||||
"info" => info!("{}", data.message),
|
||||
"warn" => warn!("{}", data.message),
|
||||
"error" => error!("{}", data.message),
|
||||
_ => error!("{}", "Wrong log call"),
|
||||
}
|
||||
"logged".to_string()
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
pub mod uuid;
|
||||
pub mod address;
|
||||
pub mod log;
|
||||
pub mod log;
|
||||
pub mod uuid;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
pub fn get_uuid() -> String {
|
||||
use uuid::Uuid;
|
||||
use uuid::Uuid;
|
||||
|
||||
let id = Uuid::new_v4().to_string();
|
||||
let id = Uuid::new_v4().to_string();
|
||||
|
||||
return id;
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,13 @@ lazy_static! {
|
||||
#[cfg(target_os = "windows")]
|
||||
const CREATE_NO_WINDOW: u32 = 0x08000000;
|
||||
|
||||
fn build_rtsp_url(address: &str, port: &str, stream_path: &str, username: &str, password: &str) -> String {
|
||||
fn build_rtsp_url(
|
||||
address: &str,
|
||||
port: &str,
|
||||
stream_path: &str,
|
||||
username: &str,
|
||||
password: &str,
|
||||
) -> String {
|
||||
if username.is_empty() || password.is_empty() {
|
||||
format!("rtsp://{}:{}/{}", address, port, stream_path)
|
||||
} else {
|
||||
@@ -28,20 +34,22 @@ fn build_rtsp_url(address: &str, port: &str, stream_path: &str, username: &str,
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||
fn spawn_ffmpeg(
|
||||
rtsp_url: String,
|
||||
stop_rx: Receiver<()>,
|
||||
status_tx: Sender<Result<(), String>>,
|
||||
) {
|
||||
fn spawn_ffmpeg(rtsp_url: String, stop_rx: Receiver<()>, status_tx: Sender<Result<(), String>>) {
|
||||
thread::spawn(move || {
|
||||
let mut cmd = Command::new("ffmpeg");
|
||||
cmd.args(&[
|
||||
"-f","x11grab",
|
||||
"-framerate","30",
|
||||
"-video_size","1920x1080",
|
||||
"-i" ,":0",
|
||||
"-f","rtsp",
|
||||
"-rtsp_transport","tcp",
|
||||
"-f",
|
||||
"x11grab",
|
||||
"-framerate",
|
||||
"30",
|
||||
"-video_size",
|
||||
"1920x1080",
|
||||
"-i",
|
||||
":0",
|
||||
"-f",
|
||||
"rtsp",
|
||||
"-rtsp_transport",
|
||||
"tcp",
|
||||
&rtsp_url,
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user