From 1af5601d633cdd37b9eb89d2cacec13502b58416 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 15 Sep 2023 19:22:12 +0200 Subject: [PATCH] looking good --- satrs-core/src/hal/host/mod.rs | 2 +- satrs-core/src/hal/host/tcp_server.rs | 14 ++++++++------ satrs-core/src/hal/host/tcp_with_cobs_server.rs | 15 ++++++++++++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/satrs-core/src/hal/host/mod.rs b/satrs-core/src/hal/host/mod.rs index dfd02c1..5e98061 100644 --- a/satrs-core/src/hal/host/mod.rs +++ b/satrs-core/src/hal/host/mod.rs @@ -1,4 +1,4 @@ //! Helper modules intended to be used on hosts with a full [std] runtime -mod tcp_with_cobs_server; pub mod tcp_server; +mod tcp_with_cobs_server; pub mod udp_server; diff --git a/satrs-core/src/hal/host/tcp_server.rs b/satrs-core/src/hal/host/tcp_server.rs index 16bcce4..c518bad 100644 --- a/satrs-core/src/hal/host/tcp_server.rs +++ b/satrs-core/src/hal/host/tcp_server.rs @@ -8,7 +8,9 @@ use core::fmt::Display; use thiserror::Error; // Re-export the TMTC in COBS server. -pub use crate::hal::host::tcp_with_cobs_server::TcpTmtcInCobsServer; +pub use crate::hal::host::tcp_with_cobs_server::{ + parse_buffer_for_cobs_encoded_packets, TcpTmtcInCobsServer, +}; #[derive(Error, Debug)] pub enum TcpTmtcError { @@ -30,11 +32,11 @@ pub struct ConnectionResult { } pub(crate) struct TcpTmtcServerBase { - pub (crate) listener: TcpListener, - pub (crate) tm_source: Box>, - pub (crate) tm_buffer: Vec, - pub (crate) tc_receiver: Box>, - pub (crate) tc_buffer: Vec, + pub(crate) listener: TcpListener, + pub(crate) tm_source: Box>, + pub(crate) tm_buffer: Vec, + pub(crate) tc_receiver: Box>, + pub(crate) tc_buffer: Vec, } impl TcpTmtcServerBase { diff --git a/satrs-core/src/hal/host/tcp_with_cobs_server.rs b/satrs-core/src/hal/host/tcp_with_cobs_server.rs index 6c72254..359eec3 100644 --- a/satrs-core/src/hal/host/tcp_with_cobs_server.rs +++ b/satrs-core/src/hal/host/tcp_with_cobs_server.rs @@ -9,9 +9,9 @@ use std::io::Write; use std::net::ToSocketAddrs; use std::vec::Vec; +use crate::hal::host::tcp_server::TcpTmtcServerBase; use crate::tmtc::ReceivesTc; use crate::tmtc::TmPacketSource; -use crate::hal::host::tcp_server::TcpTmtcServerBase; use super::tcp_server::ConnectionResult; use super::tcp_server::TcpTmtcError; @@ -22,6 +22,9 @@ use super::tcp_server::TcpTmtcError; /// Using a framing protocol like COBS imposes minimal restrictions on the type of TMTC data /// exchanged while also allowing packets with flexible size and a reliable way to reconstruct full /// packets even from a data stream which is split up. +/// +/// The server wil use the [parse_buffer_for_cobs_encoded_packets] function to parse for packets +/// and pass them to a generic TC receiver. pub struct TcpTmtcInCobsServer { base: TcpTmtcServerBase, tm_encoding_buffer: Vec, @@ -112,6 +115,16 @@ impl TcpTmtcInCobsServer } } +/// This function parses a given buffer for COBS encoded packets. The packet structure is +/// expected to be like this, assuming a sentinel value of 0 as the packet delimiter. +/// +/// 0 | ... Packet Data ... | 0 | 0 | ... Packet Data ... | 0 +/// +/// This function is also able to deal with broken tail packets at the end. If broken tail +/// packets are detected, they are moved to the front of the buffer, and the write index for +/// future write operations will be written to the `next_write_idx` argument. +/// +/// The parser will write all packets which were decoded successfully to the given `tc_receiver`. pub fn parse_buffer_for_cobs_encoded_packets( buf: &mut [u8], tc_receiver: &mut dyn ReceivesTc,