better module name
All checks were successful
Rust/sat-rs/pipeline/pr-main This commit looks good

This commit is contained in:
Robin Müller 2023-09-20 15:18:20 +02:00
parent f314e69ed8
commit 4017b5afc2
Signed by: muellerr
GPG Key ID: FCE0B2BD2195142F
6 changed files with 39 additions and 26 deletions

View File

@ -1,5 +1,17 @@
use crate::tmtc::ReceivesTcCore; use crate::tmtc::ReceivesTcCore;
use cobs::decode_in_place; use cobs::{decode_in_place, encode};
/// This function encodes the given packet with COBS and also wraps the encoded packet with
/// the sentinel value 0. It can be used repeatedly on the same encoded buffer by expecting
/// and incrementing the mutable reference of the current packet index. This is also used
/// to retrieve the total encoded size.
pub fn encode_packet_with_cobs(packet: &[u8], encoded_buf: &mut [u8], current_idx: &mut usize) {
encoded_buf[*current_idx] = 0;
*current_idx += 1;
*current_idx += encode(packet, &mut encoded_buf[*current_idx..]);
encoded_buf[*current_idx] = 0;
*current_idx += 1;
}
/// This function parses a given buffer for COBS encoded packets. The packet structure is /// 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: /// expected to be like this, assuming a sentinel value of 0 as the packet delimiter:
@ -58,7 +70,7 @@ pub(crate) mod tests {
use cobs::encode; use cobs::encode;
use crate::{ use crate::{
parsers::tests::{encode_simple_packet, INVERTED_PACKET, SIMPLE_PACKET}, encoding::tests::{encode_simple_packet, INVERTED_PACKET, SIMPLE_PACKET},
tmtc::ReceivesTcCore, tmtc::ReceivesTcCore,
}; };

View File

@ -0,0 +1,22 @@
pub mod ccsds;
pub mod cobs;
pub use crate::encoding::ccsds::parse_buffer_for_ccsds_space_packets;
pub use crate::encoding::cobs::parse_buffer_for_cobs_encoded_packets;
#[cfg(test)]
pub(crate) mod tests {
use super::cobs::encode_packet_with_cobs;
pub(crate) const SIMPLE_PACKET: [u8; 5] = [1, 2, 3, 4, 5];
pub(crate) const INVERTED_PACKET: [u8; 5] = [5, 4, 3, 2, 1];
pub(crate) fn encode_simple_packet(encoded_buf: &mut [u8], current_idx: &mut usize) {
encode_packet_with_cobs(&SIMPLE_PACKET, encoded_buf, current_idx)
}
#[allow(dead_code)]
pub(crate) fn encode_inverted_packet(encoded_buf: &mut [u8], current_idx: &mut usize) {
encode_packet_with_cobs(&INVERTED_PACKET, encoded_buf, current_idx)
}
}

View File

@ -8,7 +8,7 @@ use std::net::TcpListener;
use std::net::TcpStream; use std::net::TcpStream;
use std::vec::Vec; use std::vec::Vec;
use crate::parsers::parse_buffer_for_cobs_encoded_packets; use crate::encoding::parse_buffer_for_cobs_encoded_packets;
use crate::tmtc::ReceivesTc; use crate::tmtc::ReceivesTc;
use crate::tmtc::TmPacketSource; use crate::tmtc::TmPacketSource;
@ -171,8 +171,8 @@ mod tests {
}; };
use crate::{ use crate::{
encoding::tests::{INVERTED_PACKET, SIMPLE_PACKET},
hal::std::tcp_server::ServerConfig, hal::std::tcp_server::ServerConfig,
parsers::tests::{INVERTED_PACKET, SIMPLE_PACKET},
tmtc::{ReceivesTcCore, TmPacketSourceCore}, tmtc::{ReceivesTcCore, TmPacketSourceCore},
}; };
use alloc::{boxed::Box, collections::VecDeque, sync::Arc, vec::Vec}; use alloc::{boxed::Box, collections::VecDeque, sync::Arc, vec::Vec};

View File

@ -20,6 +20,7 @@ extern crate downcast_rs;
#[cfg(any(feature = "std", test))] #[cfg(any(feature = "std", test))]
extern crate std; extern crate std;
pub mod encoding;
pub mod error; pub mod error;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] #[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
@ -33,7 +34,6 @@ pub mod hk;
pub mod mode; pub mod mode;
pub mod objects; pub mod objects;
pub mod params; pub mod params;
pub mod parsers;
pub mod pool; pub mod pool;
pub mod power; pub mod power;
pub mod pus; pub mod pus;

View File

@ -1,21 +0,0 @@
pub mod ccsds;
pub mod cobs;
pub use crate::parsers::ccsds::parse_buffer_for_ccsds_space_packets;
pub use crate::parsers::cobs::parse_buffer_for_cobs_encoded_packets;
#[cfg(test)]
pub(crate) mod tests {
use cobs::encode;
pub(crate) const SIMPLE_PACKET: [u8; 5] = [1, 2, 3, 4, 5];
pub(crate) const INVERTED_PACKET: [u8; 5] = [5, 4, 3, 2, 1];
pub(crate) fn encode_simple_packet(encoded_buf: &mut [u8], current_idx: &mut usize) {
encoded_buf[*current_idx] = 0;
*current_idx += 1;
*current_idx += encode(&SIMPLE_PACKET, &mut encoded_buf[*current_idx..]);
encoded_buf[*current_idx] = 0;
*current_idx += 1;
}
}