Skip to content
Snippets Groups Projects
Commit 7a986c30 authored by Stephen D's avatar Stephen D
Browse files

callsign in text messages

parent ff0bf543
No related branches found
No related tags found
No related merge requests found
......@@ -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()?
......
......@@ -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);
......
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment