basic TMTC interaction established

This commit is contained in:
Robin Müller 2022-08-29 00:44:34 +02:00
parent 9b791b1de1
commit cc21785687
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
3 changed files with 53 additions and 36 deletions

View File

@ -42,10 +42,10 @@ impl<E> UdpTcServer<E> {
let res = match self.socket.recv_from(&mut self.recv_buf) { let res = match self.socket.recv_from(&mut self.recv_buf) {
Ok(res) => res, Ok(res) => res,
Err(e) => { Err(e) => {
if e.kind() != ErrorKind::WouldBlock { return if e.kind() == ErrorKind::WouldBlock {
return Err(ReceiveResult::WouldBlock); Err(ReceiveResult::WouldBlock)
} else { } else {
return Err(ReceiveResult::OtherIoError(e)); Err(ReceiveResult::OtherIoError(e))
} }
} }
}; };

View File

@ -2,6 +2,7 @@ use fsrc_example::{OBSW_SERVER_ADDR, SERVER_PORT};
use spacepackets::tc::PusTc; use spacepackets::tc::PusTc;
use spacepackets::SpHeader; use spacepackets::SpHeader;
use std::net::{IpAddr, SocketAddr, UdpSocket}; use std::net::{IpAddr, SocketAddr, UdpSocket};
use std::time::Duration;
fn main() { fn main() {
let mut buf = [0; 32]; let mut buf = [0; 32];
@ -13,4 +14,12 @@ fn main() {
client client
.send_to(&buf[0..size], &addr) .send_to(&buf[0..size], &addr)
.expect(&*format!("Sending to {:?} failed", addr)); .expect(&*format!("Sending to {:?} failed", addr));
client
.set_read_timeout(Some(Duration::from_secs(2)))
.expect("Setting read timeout failed");
if let Ok(len) = client.recv(&mut buf) {
println!("Received TM with {} bytes", len);
} else {
println!("No reply received for 2 seconds or timeout");
}
} }

View File

@ -11,8 +11,8 @@ use spacepackets::tm::{PusTm, PusTmSecondaryHeader};
use spacepackets::{CcsdsPacket, SpHeader}; use spacepackets::{CcsdsPacket, SpHeader};
use std::net::{IpAddr, SocketAddr}; use std::net::{IpAddr, SocketAddr};
use std::sync::{mpsc, Arc, Mutex}; use std::sync::{mpsc, Arc, Mutex};
use std::sync::mpsc::TryRecvError;
use std::thread; use std::thread;
use std::time::Duration;
const PUS_APID: u16 = 0x02; const PUS_APID: u16 = 0x02;
@ -96,12 +96,12 @@ struct TmStore {
impl TmStore { impl TmStore {
fn add_pus_tm(&mut self, pus_tm: &PusTm) -> StoreAddr { fn add_pus_tm(&mut self, pus_tm: &PusTm) -> StoreAddr {
let (addr, mut buf) = self let (addr, buf) = self
.pool .pool
.free_element(pus_tm.len_packed()) .free_element(pus_tm.len_packed())
.expect("Store error"); .expect("Store error");
pus_tm pus_tm
.write_to(&mut buf) .write_to(buf)
.expect("Writing PUS TM to store failed"); .expect("Writing PUS TM to store failed");
addr addr
} }
@ -144,11 +144,11 @@ fn main() {
let mut udp_tmtc_server = UdpTmtcServer { let mut udp_tmtc_server = UdpTmtcServer {
udp_tc_server, udp_tc_server,
tm_rx: tm_server_rx, tm_rx: tm_server_rx,
tm_store: tm_store.clone(), tm_store
}; };
loop { loop {
let res = udp_tmtc_server.udp_tc_server.try_recv_tc(); loop {
match res { match udp_tmtc_server.udp_tc_server.try_recv_tc() {
Ok(_) => (), Ok(_) => (),
Err(e) => match e { Err(e) => match e {
ReceiveResult::ReceiverError(e) => match e { ReceiveResult::ReceiverError(e) => match e {
@ -161,23 +161,33 @@ fn main() {
}, },
ReceiveResult::OtherIoError(e) => { ReceiveResult::OtherIoError(e) => {
println!("IO error {e}"); println!("IO error {e}");
break;
} }
ReceiveResult::WouldBlock => { ReceiveResult::WouldBlock => {
if let Some(recv_addr) = udp_tmtc_server.udp_tc_server.last_sender() { if let Some(recv_addr) = udp_tmtc_server.udp_tc_server.last_sender() {
// TODO: Send TM Here // TODO: Send TM Here
match udp_tmtc_server.tm_rx.try_recv() { while let Ok(addr) = udp_tmtc_server.tm_rx.try_recv() {
Ok(addr) => { let mut store_lock = udp_tmtc_server
udp_tmtc_server.tm_store.lock().expect("Locking TM store failed").pool.read() .tm_store
udp_tmtc_server.udp_tc_server.socket.send_to() .lock()
} .expect("Locking TM store failed");
Err(_) => {} let pg = store_lock.pool.read_with_guard(addr);
let buf = pg.read().expect("Error reading TM pool data");
println!("Sending TM");
udp_tmtc_server
.udp_tc_server
.socket
.send_to(buf, recv_addr)
.expect("Sending TM failed");
} }
} }
break;
} }
}, },
} }
} }
thread::sleep(Duration::from_millis(400));
}
}); });
let jh1 = thread::spawn(move || { let jh1 = thread::spawn(move || {
let tm_funnel = TmFunnel { let tm_funnel = TmFunnel {
@ -185,9 +195,7 @@ fn main() {
tm_funnel_rx, tm_funnel_rx,
}; };
loop { loop {
let res = tm_funnel.tm_funnel_rx.recv(); if let Ok(addr) = tm_funnel.tm_funnel_rx.recv() {
if res.is_ok() {
let addr = res.unwrap();
tm_funnel tm_funnel
.tm_server_tx .tm_server_tx
.send(addr) .send(addr)