looking good
All checks were successful
Rust/sat-rs/pipeline/head This commit looks good
Rust/sat-rs/pipeline/pr-main This commit looks good

This commit is contained in:
Robin Müller 2023-09-15 19:22:12 +02:00
parent 3d6e33bc00
commit 1af5601d63
Signed by: muellerr
GPG Key ID: A649FB78196E3849
3 changed files with 23 additions and 8 deletions

View File

@ -1,4 +1,4 @@
//! Helper modules intended to be used on hosts with a full [std] runtime //! Helper modules intended to be used on hosts with a full [std] runtime
mod tcp_with_cobs_server;
pub mod tcp_server; pub mod tcp_server;
mod tcp_with_cobs_server;
pub mod udp_server; pub mod udp_server;

View File

@ -8,7 +8,9 @@ use core::fmt::Display;
use thiserror::Error; use thiserror::Error;
// Re-export the TMTC in COBS server. // 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)] #[derive(Error, Debug)]
pub enum TcpTmtcError<TmError: Display, TcError: Display> { pub enum TcpTmtcError<TmError: Display, TcError: Display> {
@ -30,11 +32,11 @@ pub struct ConnectionResult {
} }
pub(crate) struct TcpTmtcServerBase<TcError, TmError> { pub(crate) struct TcpTmtcServerBase<TcError, TmError> {
pub (crate) listener: TcpListener, pub(crate) listener: TcpListener,
pub (crate) tm_source: Box<dyn TmPacketSource<Error = TmError>>, pub(crate) tm_source: Box<dyn TmPacketSource<Error = TmError>>,
pub (crate) tm_buffer: Vec<u8>, pub(crate) tm_buffer: Vec<u8>,
pub (crate) tc_receiver: Box<dyn ReceivesTc<Error = TcError>>, pub(crate) tc_receiver: Box<dyn ReceivesTc<Error = TcError>>,
pub (crate) tc_buffer: Vec<u8>, pub(crate) tc_buffer: Vec<u8>,
} }
impl<TcError, TmError> TcpTmtcServerBase<TcError, TmError> { impl<TcError, TmError> TcpTmtcServerBase<TcError, TmError> {

View File

@ -9,9 +9,9 @@ use std::io::Write;
use std::net::ToSocketAddrs; use std::net::ToSocketAddrs;
use std::vec::Vec; use std::vec::Vec;
use crate::hal::host::tcp_server::TcpTmtcServerBase;
use crate::tmtc::ReceivesTc; use crate::tmtc::ReceivesTc;
use crate::tmtc::TmPacketSource; use crate::tmtc::TmPacketSource;
use crate::hal::host::tcp_server::TcpTmtcServerBase;
use super::tcp_server::ConnectionResult; use super::tcp_server::ConnectionResult;
use super::tcp_server::TcpTmtcError; 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 /// 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 /// 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. /// 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<TcError, TmError> { pub struct TcpTmtcInCobsServer<TcError, TmError> {
base: TcpTmtcServerBase<TcError, TmError>, base: TcpTmtcServerBase<TcError, TmError>,
tm_encoding_buffer: Vec<u8>, tm_encoding_buffer: Vec<u8>,
@ -112,6 +115,16 @@ impl<TcError: 'static + Display, TmError: 'static + Display> 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<E>( pub fn parse_buffer_for_cobs_encoded_packets<E>(
buf: &mut [u8], buf: &mut [u8],
tc_receiver: &mut dyn ReceivesTc<Error = E>, tc_receiver: &mut dyn ReceivesTc<Error = E>,