From 3aa395dc4eb11abc4e2863fad6fa75382cbe2eca Mon Sep 17 00:00:00 2001 From: mattbk Date: Sun, 28 Sep 2025 21:20:46 -0500 Subject: [PATCH 1/5] Rough out sending a basic UDP notification. --- src/main.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main.rs b/src/main.rs index 8ff489b..fc33654 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use std::io::{Read, Write}; use std::net::TcpStream; use std::thread::sleep; use std::time::Duration; +use std::net::UdpSocket; /// Validate that the provided port string can be parsed into a u16 and is nonzero. fn validate_port(port: &str) -> Result { @@ -47,6 +48,18 @@ struct Cli { /// Only monitor UI frames #[arg(short = 'u', long, default_value_t = false)] ui_only: bool, + + // Enable UDP + #[arg(short = 'm', long, default_value_t = false)] + udp: bool, + + // Send UDP to what IP address (e.g. 127.0.0.1) + #[arg(short = 'b', long)] + uip: std::net::IpAddr, + + // Send UDP to what port (e.g. 8000) + #[arg(short = 'k', long, value_parser = validate_port)] + uport: u16, } /// Convert a byte slice into a hex-dump string for debugging purposes. @@ -384,6 +397,12 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) { return; } + // Send UDP + let uaddr = format!("{}:{}", cli.uip, cli.uport); + let socket = UdpSocket::bind("0.0.0.0:0"); + let message = "Packet received"; + socket.expect("REASON").send_to(message.as_bytes(), uaddr); + // In non-debug mode, print the session line and any additional lines. if !cli.debug { print_session_line(×tamp, &source, &final_destination, &summary); @@ -403,7 +422,19 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) { fn main() -> Result<()> { let cli = Cli::parse(); let addr = format!("{}:{}", cli.ip, cli.port); + //let uaddr = format!("{}:{}", cli.uip, cli.uport); let reconnect_delay_ms = 5000; +/* + if cli.udp { + // Bind the client socket to any available address and port + let socket = UdpSocket::bind("0.0.0.0:0")?; + println!("UDP client started"); + // Send a message to the server + let message = "UDP client connected"; + socket.send_to(message.as_bytes(), uaddr)?; + //println!("Sent message to {}: {}", uaddr, message); + } +*/ loop { println!("Connecting to AGWPE server at {addr}"); -- 2.39.5 From 8065fcc24eb39ad20c3a219ef2c33d26752c5bbb Mon Sep 17 00:00:00 2001 From: mattbk Date: Sun, 28 Sep 2025 21:47:26 -0500 Subject: [PATCH 2/5] Pass raw frame text over UDP. --- src/main.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index fc33654..c6df683 100644 --- a/src/main.rs +++ b/src/main.rs @@ -400,8 +400,9 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) { // Send UDP let uaddr = format!("{}:{}", cli.uip, cli.uport); let socket = UdpSocket::bind("0.0.0.0:0"); - let message = "Packet received"; - socket.expect("REASON").send_to(message.as_bytes(), uaddr); + //let message = "Packet received"; + let message = &text; + let _ = socket.expect("REASON").send_to(message.as_bytes(), uaddr); // In non-debug mode, print the session line and any additional lines. if !cli.debug { @@ -422,9 +423,9 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) { fn main() -> Result<()> { let cli = Cli::parse(); let addr = format!("{}:{}", cli.ip, cli.port); - //let uaddr = format!("{}:{}", cli.uip, cli.uport); + let uaddr = format!("{}:{}", cli.uip, cli.uport); let reconnect_delay_ms = 5000; -/* + if cli.udp { // Bind the client socket to any available address and port let socket = UdpSocket::bind("0.0.0.0:0")?; @@ -432,9 +433,7 @@ fn main() -> Result<()> { // Send a message to the server let message = "UDP client connected"; socket.send_to(message.as_bytes(), uaddr)?; - //println!("Sent message to {}: {}", uaddr, message); } -*/ loop { println!("Connecting to AGWPE server at {addr}"); -- 2.39.5 From 6101932b0df5b4c2850cc0169ede035658376ab4 Mon Sep 17 00:00:00 2001 From: mattbk Date: Sat, 4 Oct 2025 22:42:14 -0500 Subject: [PATCH 3/5] Add defaults for UDP arguments to not get in the way. --- src/main.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index c6df683..d005f94 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ use std::net::TcpStream; use std::thread::sleep; use std::time::Duration; use std::net::UdpSocket; +use std::net::Ipv4Addr; /// Validate that the provided port string can be parsed into a u16 and is nonzero. fn validate_port(port: &str) -> Result { @@ -49,16 +50,12 @@ struct Cli { #[arg(short = 'u', long, default_value_t = false)] ui_only: bool, - // Enable UDP - #[arg(short = 'm', long, default_value_t = false)] - udp: bool, - // Send UDP to what IP address (e.g. 127.0.0.1) - #[arg(short = 'b', long)] + #[arg(short = 'b', long, default_value_t = std::net::IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)))] uip: std::net::IpAddr, // Send UDP to what port (e.g. 8000) - #[arg(short = 'k', long, value_parser = validate_port)] + #[arg(short = 'k', long, value_parser = validate_port, default_value_t = 55555)] uport: u16, } @@ -426,10 +423,10 @@ fn main() -> Result<()> { let uaddr = format!("{}:{}", cli.uip, cli.uport); let reconnect_delay_ms = 5000; - if cli.udp { + if cli.uport != 55555 { // Bind the client socket to any available address and port let socket = UdpSocket::bind("0.0.0.0:0")?; - println!("UDP client started"); + println!("UDP client started at {}:{}", cli.uip, cli.uport); // Send a message to the server let message = "UDP client connected"; socket.send_to(message.as_bytes(), uaddr)?; -- 2.39.5 From 7957fa7c2cc541bfa13f6d4e35aa0be50967894c Mon Sep 17 00:00:00 2001 From: mattbk Date: Sun, 5 Oct 2025 18:21:16 -0500 Subject: [PATCH 4/5] Pass data as JSON over UDP. --- Cargo.toml | 1 + src/main.rs | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e99a8b7..8e64aae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ authors = ["Chris, N6CTA "] anyhow = "1.0" chrono = "0.4" clap = { version = "4", features = ["derive"] } +serde_json = "1.0.145" socket2 = "0.5" [profile.release] diff --git a/src/main.rs b/src/main.rs index d005f94..986f45f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,9 +7,10 @@ use std::convert::TryInto; use std::io::{Read, Write}; use std::net::TcpStream; use std::thread::sleep; -use std::time::Duration; +use std::time::{Duration, SystemTime, UNIX_EPOCH}; use std::net::UdpSocket; use std::net::Ipv4Addr; +use serde_json::json; /// Validate that the provided port string can be parsed into a u16 and is nonzero. fn validate_port(port: &str) -> Result { @@ -395,11 +396,19 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) { } // Send UDP - let uaddr = format!("{}:{}", cli.uip, cli.uport); - let socket = UdpSocket::bind("0.0.0.0:0"); - //let message = "Packet received"; - let message = &text; - let _ = socket.expect("REASON").send_to(message.as_bytes(), uaddr); + if cli.uport != 55555 { + let uaddr = format!("{}:{}", cli.uip, cli.uport); + let socket = UdpSocket::bind("0.0.0.0:0"); + + let packet = json!({ + "final_destination": &final_destination, + "source": &source, + "summary": &summary, + "text": &text, + "timestamp": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(), + }); + let _ = socket.expect("REASON").send_to(packet.to_string().as_bytes(), uaddr); + } // In non-debug mode, print the session line and any additional lines. if !cli.debug { -- 2.39.5 From 98da8b95d5e47d6732ea216337c1b7b48ff9537f Mon Sep 17 00:00:00 2001 From: mattbk Date: Sun, 12 Oct 2025 21:06:49 -0500 Subject: [PATCH 5/5] Send a UDP message to the server that says you are connected. --- src/main.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 986f45f..5211c97 100644 --- a/src/main.rs +++ b/src/main.rs @@ -406,6 +406,7 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) { "summary": &summary, "text": &text, "timestamp": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(), + "type": "data" }); let _ = socket.expect("REASON").send_to(packet.to_string().as_bytes(), uaddr); } @@ -437,8 +438,13 @@ fn main() -> Result<()> { let socket = UdpSocket::bind("0.0.0.0:0")?; println!("UDP client started at {}:{}", cli.uip, cli.uport); // Send a message to the server - let message = "UDP client connected"; - socket.send_to(message.as_bytes(), uaddr)?; + let packet = json!({ + "text": "UDP client connected", + "timestamp": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(), + "type": "status" + }); + //let message = "UDP client connected"; + socket.send_to(packet.to_string().as_bytes(), uaddr)?; } loop { -- 2.39.5