From 7957fa7c2cc541bfa13f6d4e35aa0be50967894c Mon Sep 17 00:00:00 2001 From: mattbk Date: Sun, 5 Oct 2025 18:21:16 -0500 Subject: [PATCH] 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 {