diff --git a/satrs-example/src/interface/tcp.rs b/satrs-example/src/interface/tcp.rs index 8690ad6..cc3f669 100644 --- a/satrs-example/src/interface/tcp.rs +++ b/satrs-example/src/interface/tcp.rs @@ -32,7 +32,7 @@ impl SpacePacketValidator for SimplePacketValidator { log::warn!("ignoring space packet with header {:?}", sp_header); // We could perform a CRC check.. but lets keep this simple and assume that TCP ensures // data integrity. - SpValidity::Ignore + SpValidity::Skip } } diff --git a/satrs/src/encoding/ccsds.rs b/satrs/src/encoding/ccsds.rs index c552409..4e361c9 100644 --- a/satrs/src/encoding/ccsds.rs +++ b/satrs/src/encoding/ccsds.rs @@ -6,8 +6,8 @@ use crate::{tmtc::PacketSenderRaw, ComponentId}; pub enum SpValidity { Valid, /// The space packet can be assumed to have a valid format, but the packet should - /// be ignored. - Ignore, + /// be skipped. + Skip, /// The space packet or space packet header has an invalid format, for example a CRC check /// failed. In that case, the parser loses the packet synchronization and needs to check for /// the start of a new space packet header start again. The space packet header @@ -30,13 +30,16 @@ pub trait SpacePacketValidator { /// 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 forward all packets for which the user provided [SpacePacketValidator] returned -/// [SpacePacketValidation::Valid] to the given `packet_sender` and return the number of packets -/// found. If the [PacketSenderRaw::send_packet] calls fails, the error will be returned. +/// The parses will behave differently based on the [SpValidity] returned from the user provided +/// [SpacePacketValidator]: /// -/// If the user provided [SpacePacketValidator] returns [SpacePacketValidation::Invalid], the -/// parser assumes that the synchronization is lost and tries to find the start of a new space -/// packet header by scanning all the following bytes. +/// 1. [SpValidity::Valid]: The parser will forward all packets to the given `packet_sender` and +/// return the number of packets found.If the [PacketSenderRaw::send_packet] calls fails, the +/// error will be returned. +/// 2. [SpValidity::Invalid]: The parser assumes that the synchronization is lost and tries to +/// find the start of a new space packet header by scanning all the following bytes. +/// 3. [SpValidity::Skip]: The parser skips the packet using the packet length determined from the +/// space packet header. pub fn parse_buffer_for_ccsds_space_packets( buf: &mut [u8], packet_validator: &(impl SpacePacketValidator + ?Sized), @@ -71,7 +74,7 @@ pub fn parse_buffer_for_ccsds_space_packets( current_idx += packet_size; continue; } - SpValidity::Ignore => { + SpValidity::Skip => { current_idx += sp_header.total_len(); } // We might have lost sync. Try to find the start of a new space packet header. @@ -92,9 +95,7 @@ mod tests { use crate::{encoding::tests::TcCacher, ComponentId}; - use super::{ - parse_buffer_for_ccsds_space_packets, SpValidity, SpacePacketValidator, - }; + use super::{parse_buffer_for_ccsds_space_packets, SpValidity, SpacePacketValidator}; const PARSER_ID: ComponentId = 0x05; const TEST_APID_0: u16 = 0x02; @@ -122,7 +123,7 @@ mod tests { { return SpValidity::Valid; } - SpValidity::Ignore + SpValidity::Skip } } diff --git a/satrs/src/hal/std/tcp_spacepackets_server.rs b/satrs/src/hal/std/tcp_spacepackets_server.rs index b03d522..2cbe31f 100644 --- a/satrs/src/hal/std/tcp_spacepackets_server.rs +++ b/satrs/src/hal/std/tcp_spacepackets_server.rs @@ -212,7 +212,7 @@ mod tests { return SpValidity::Valid; } // Simple case: Assume that the interface always contains valid space packets. - SpValidity::Ignore + SpValidity::Skip } } diff --git a/satrs/src/tmtc/mod.rs b/satrs/src/tmtc/mod.rs index 53c6723..f075c42 100644 --- a/satrs/src/tmtc/mod.rs +++ b/satrs/src/tmtc/mod.rs @@ -20,7 +20,6 @@ use spacepackets::{ ecss::{ tc::PusTcReader, tm::{PusTmCreator, PusTmReader}, - WritablePusPacket, }, SpHeader, }; @@ -226,6 +225,7 @@ pub mod std_mod { #[cfg(feature = "crossbeam")] use crossbeam_channel as cb; + use spacepackets::ecss::WritablePusPacket; use thiserror::Error; use crate::pool::PoolProvider; diff --git a/satrs/tests/tcp_servers.rs b/satrs/tests/tcp_servers.rs index 12e62c7..602913e 100644 --- a/satrs/tests/tcp_servers.rs +++ b/satrs/tests/tcp_servers.rs @@ -209,7 +209,7 @@ impl SpacePacketValidator for SimpleVerificator { if self.valid_ids.contains(&sp_header.packet_id()) { return SpValidity::Valid; } - SpValidity::Ignore + SpValidity::Skip } }