improve docs, better naming
All checks were successful
Rust/sat-rs/pipeline/pr-main This commit looks good
All checks were successful
Rust/sat-rs/pipeline/pr-main This commit looks good
This commit is contained in:
parent
29c0961fab
commit
62ebad12fa
@ -32,7 +32,7 @@ impl SpacePacketValidator for SimplePacketValidator {
|
|||||||
log::warn!("ignoring space packet with header {:?}", sp_header);
|
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
|
// We could perform a CRC check.. but lets keep this simple and assume that TCP ensures
|
||||||
// data integrity.
|
// data integrity.
|
||||||
SpValidity::Ignore
|
SpValidity::Skip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,8 +6,8 @@ use crate::{tmtc::PacketSenderRaw, ComponentId};
|
|||||||
pub enum SpValidity {
|
pub enum SpValidity {
|
||||||
Valid,
|
Valid,
|
||||||
/// The space packet can be assumed to have a valid format, but the packet should
|
/// The space packet can be assumed to have a valid format, but the packet should
|
||||||
/// be ignored.
|
/// be skipped.
|
||||||
Ignore,
|
Skip,
|
||||||
/// The space packet or space packet header has an invalid format, for example a CRC check
|
/// 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
|
/// 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
|
/// 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
|
/// 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.
|
/// 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
|
/// The parses will behave differently based on the [SpValidity] returned from the user provided
|
||||||
/// [SpacePacketValidation::Valid] to the given `packet_sender` and return the number of packets
|
/// [SpacePacketValidator]:
|
||||||
/// found. If the [PacketSenderRaw::send_packet] calls fails, the error will be returned.
|
|
||||||
///
|
///
|
||||||
/// If the user provided [SpacePacketValidator] returns [SpacePacketValidation::Invalid], the
|
/// 1. [SpValidity::Valid]: The parser will forward all packets to the given `packet_sender` and
|
||||||
/// parser assumes that the synchronization is lost and tries to find the start of a new space
|
/// return the number of packets found.If the [PacketSenderRaw::send_packet] calls fails, the
|
||||||
/// packet header by scanning all the following bytes.
|
/// 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<SendError>(
|
pub fn parse_buffer_for_ccsds_space_packets<SendError>(
|
||||||
buf: &mut [u8],
|
buf: &mut [u8],
|
||||||
packet_validator: &(impl SpacePacketValidator + ?Sized),
|
packet_validator: &(impl SpacePacketValidator + ?Sized),
|
||||||
@ -71,7 +74,7 @@ pub fn parse_buffer_for_ccsds_space_packets<SendError>(
|
|||||||
current_idx += packet_size;
|
current_idx += packet_size;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SpValidity::Ignore => {
|
SpValidity::Skip => {
|
||||||
current_idx += sp_header.total_len();
|
current_idx += sp_header.total_len();
|
||||||
}
|
}
|
||||||
// We might have lost sync. Try to find the start of a new space packet header.
|
// 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 crate::{encoding::tests::TcCacher, ComponentId};
|
||||||
|
|
||||||
use super::{
|
use super::{parse_buffer_for_ccsds_space_packets, SpValidity, SpacePacketValidator};
|
||||||
parse_buffer_for_ccsds_space_packets, SpValidity, SpacePacketValidator,
|
|
||||||
};
|
|
||||||
|
|
||||||
const PARSER_ID: ComponentId = 0x05;
|
const PARSER_ID: ComponentId = 0x05;
|
||||||
const TEST_APID_0: u16 = 0x02;
|
const TEST_APID_0: u16 = 0x02;
|
||||||
@ -122,7 +123,7 @@ mod tests {
|
|||||||
{
|
{
|
||||||
return SpValidity::Valid;
|
return SpValidity::Valid;
|
||||||
}
|
}
|
||||||
SpValidity::Ignore
|
SpValidity::Skip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ mod tests {
|
|||||||
return SpValidity::Valid;
|
return SpValidity::Valid;
|
||||||
}
|
}
|
||||||
// Simple case: Assume that the interface always contains valid space packets.
|
// Simple case: Assume that the interface always contains valid space packets.
|
||||||
SpValidity::Ignore
|
SpValidity::Skip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ use spacepackets::{
|
|||||||
ecss::{
|
ecss::{
|
||||||
tc::PusTcReader,
|
tc::PusTcReader,
|
||||||
tm::{PusTmCreator, PusTmReader},
|
tm::{PusTmCreator, PusTmReader},
|
||||||
WritablePusPacket,
|
|
||||||
},
|
},
|
||||||
SpHeader,
|
SpHeader,
|
||||||
};
|
};
|
||||||
@ -226,6 +225,7 @@ pub mod std_mod {
|
|||||||
|
|
||||||
#[cfg(feature = "crossbeam")]
|
#[cfg(feature = "crossbeam")]
|
||||||
use crossbeam_channel as cb;
|
use crossbeam_channel as cb;
|
||||||
|
use spacepackets::ecss::WritablePusPacket;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::pool::PoolProvider;
|
use crate::pool::PoolProvider;
|
||||||
|
@ -209,7 +209,7 @@ impl SpacePacketValidator for SimpleVerificator {
|
|||||||
if self.valid_ids.contains(&sp_header.packet_id()) {
|
if self.valid_ids.contains(&sp_header.packet_id()) {
|
||||||
return SpValidity::Valid;
|
return SpValidity::Valid;
|
||||||
}
|
}
|
||||||
SpValidity::Ignore
|
SpValidity::Skip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user