From b5e048a13b511782ec00df051aae0bc4f2bbdc8a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 16 Apr 2024 10:05:27 +0200 Subject: [PATCH] start TM handling for TCP client --- src/interface/tcp_spp_client.rs | 3 +++ src/main.rs | 11 ++++++++--- src/tmtc/tm_sink.rs | 20 ++++++++++++++------ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/interface/tcp_spp_client.rs b/src/interface/tcp_spp_client.rs index 24bedb2..894c693 100644 --- a/src/interface/tcp_spp_client.rs +++ b/src/interface/tcp_spp_client.rs @@ -30,6 +30,7 @@ pub struct TcpSppClient { events: Events, client: TcpStream, read_buf: [u8; 4096], + tm_tcp_client_rx: mpsc::Receiver, tc_source_tx: mpsc::Sender, validator: SimpleSpValidator, } @@ -38,6 +39,7 @@ impl TcpSppClient { pub fn new( id: ComponentId, tc_source_tx: mpsc::Sender, + tm_tcp_client_rx: mpsc::Receiver, valid_ids: &'static [PacketId], ) -> io::Result { let poll = Poll::new()?; @@ -55,6 +57,7 @@ impl TcpSppClient { events, client, read_buf: [0; 4096], + tm_tcp_client_rx, tc_source_tx, validator: SimpleSpValidator::new(TcpComponent::Client, valid_ids.to_vec()), }) diff --git a/src/main.rs b/src/main.rs index fb7bfc4..038cc4e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,6 +47,7 @@ fn main() { let (tc_source_tx, tc_source_rx) = mpsc::channel(); let (tm_funnel_tx, tm_funnel_rx) = mpsc::channel(); let (tm_server_tx, tm_server_rx) = mpsc::channel(); + let (tm_tcp_client_tx, tm_tcp_client_rx) = mpsc::channel(); let (pus_test_tx, pus_test_rx) = mpsc::channel(); // let (pus_event_tx, pus_event_rx) = mpsc::channel(); @@ -162,9 +163,13 @@ fn main() { stop_signal.clone(), ); - let mut tcp_spp_client = - TcpSppClient::new(TCP_SPP_CLIENT.id(), tc_source_tx, VALID_PACKET_ID_LIST) - .expect("creating TCP SPP client failed"); + let mut tcp_spp_client = TcpSppClient::new( + TCP_SPP_CLIENT.id(), + tc_source_tx, + tm_tcp_client_rx, + VALID_PACKET_ID_LIST, + ) + .expect("creating TCP SPP client failed"); info!("Starting CTRL task"); let ctrl_stop_signal = stop_signal.clone(); diff --git a/src/tmtc/tm_sink.rs b/src/tmtc/tm_sink.rs index 9dfac6f..642b106 100644 --- a/src/tmtc/tm_sink.rs +++ b/src/tmtc/tm_sink.rs @@ -77,7 +77,8 @@ impl TmFunnelCommon { pub struct TmFunnelDynamic { common: TmFunnelCommon, tm_funnel_rx: mpsc::Receiver, - tm_server_tx: mpsc::Sender, + tm_udp_server_tx: mpsc::Sender, + tm_tcp_client_tx: mpsc::Sender, stop_signal: Arc, } @@ -85,13 +86,15 @@ impl TmFunnelDynamic { pub fn new( sync_tm_tcp_source: SyncTcpTmSource, tm_funnel_rx: mpsc::Receiver, - tm_server_tx: mpsc::Sender, + tm_udp_server_tx: mpsc::Sender, + tm_tcp_client_tx: mpsc::Sender, stop_signal: Arc, ) -> Self { Self { common: TmFunnelCommon::new(sync_tm_tcp_source), tm_funnel_rx, - tm_server_tx, + tm_udp_server_tx, + tm_tcp_client_tx, stop_signal, } } @@ -110,9 +113,14 @@ impl TmFunnelDynamic { .expect("Creating TM zero copy writer failed"); self.common.apply_packet_processing(zero_copy_writer); self.common.sync_tm_tcp_source.add_tm(&tm.packet); - self.tm_server_tx - .send(tm) - .expect("Sending TM to server failed"); + let result = self.tm_udp_server_tx.send(tm); + if result.is_err() { + log::error!("TM UDP server has disconnected"); + } + let result = self.tm_tcp_client_tx.send(tm); + if result.is_err() { + log::error!("TM TCP client has disconnected"); + } if self.stop_signal.load(std::sync::atomic::Ordering::Relaxed) { break; }