From 7a986c300013231846678f08060640e0ebb7a561 Mon Sep 17 00:00:00 2001 From: Stephen D <webmaster@scd31.com> Date: Fri, 7 Jul 2023 17:32:29 -0300 Subject: [PATCH] callsign in text messages --- src/aprs.rs | 21 ++++++++++++--------- src/control.rs | 12 +++++++++--- src/packet.rs | 9 +++++++-- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/aprs.rs b/src/aprs.rs index 9c6b613..25f8c3a 100644 --- a/src/aprs.rs +++ b/src/aprs.rs @@ -135,16 +135,18 @@ impl CommandHandler { match cmd { Command::ReqImageId(id) => { - let _ = self - .telem_tx - .send(Packet::new_text_message("HQ image request received")); + let _ = self.telem_tx.send(Packet::new_text_message( + &self.callsign, + "HQ image request received", + )); self.img_request.send(id)? } Command::BurstBalloon => { - let _ = self - .telem_tx - .send(Packet::new_text_message("Burst balloon command received")); + let _ = self.telem_tx.send(Packet::new_text_message( + &self.callsign, + "Burst balloon command received", + )); let (_, stderr) = subprocess::Exec::shell(&self.burst_command) .communicate()? @@ -157,9 +159,10 @@ impl CommandHandler { } } Command::CutPayload => { - let _ = self - .telem_tx - .send(Packet::new_text_message("Payload cutdown command received")); + let _ = self.telem_tx.send(Packet::new_text_message( + &self.callsign, + "Payload cutdown command received", + )); let (_, stderr) = subprocess::Exec::shell(&self.cutdown_command) .communicate()? diff --git a/src/control.rs b/src/control.rs index c779c11..761d59f 100644 --- a/src/control.rs +++ b/src/control.rs @@ -34,8 +34,9 @@ impl Controller { let (cmd_tx, cmd_rx) = mpsc::channel(); { + let callsign = self.config.callsign.clone(); let uart = self.config.uart.clone(); - thread::spawn(|| Self::tx_thread(uart, img_rx, telem_rx)); + thread::spawn(|| Self::tx_thread(callsign, uart, img_rx, telem_rx)); } { @@ -85,7 +86,12 @@ impl Controller { } // manages our transceiver - fn tx_thread(uart: String, image_rx: Receiver<FecPacket>, telem_rx: Receiver<Packet>) { + fn tx_thread( + callsign: String, + uart: String, + image_rx: Receiver<FecPacket>, + telem_rx: Receiver<Packet>, + ) { let mut radio = loop { let r = UartRadio::new(&uart); @@ -130,7 +136,7 @@ impl Controller { } }; - let packet = Packet::new_text_message(&format!("Temp: {}", temp)); + let packet = Packet::new_text_message(&callsign, &format!("Temp: {}", temp)); if let Err(e) = radio.send_packet(&packet.into_raw(&mut text_msg_id).into()) { eprintln!("Could not send packet: {}", e); diff --git a/src/packet.rs b/src/packet.rs index 6a40ca3..8bd7b63 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -11,14 +11,19 @@ pub enum Packet { impl Packet { // Cuts off messages that are too long - pub fn new_text_message(msg: &str) -> Self { + pub fn new_text_message(callsign: &str, msg: &str) -> Self { let mut out = [0x55; TEXT_MESSAGE_LEN]; // this technically would allow part of a character to be sent // (unicode multi-byte character that gets cut off at the end) // ideally, we would iterate over characters and add them, so that // we could abort before adding a partial character - for (i, b) in msg.as_bytes().iter().enumerate().take(TEXT_MESSAGE_LEN) { + let iter = callsign + .as_bytes() + .iter() + .chain(b": ".iter()) + .chain(msg.as_bytes().iter()); + for (i, b) in iter.enumerate().take(TEXT_MESSAGE_LEN) { out[i] = *b; } -- GitLab