that's a better name
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit

This commit is contained in:
Robin Müller 2024-04-16 00:39:12 +02:00
parent 72077505b7
commit 29c0961fab
Signed by: muellerr
GPG Key ID: A649FB78196E3849
4 changed files with 21 additions and 21 deletions

View File

@ -7,7 +7,7 @@ use std::{
use log::{info, warn};
use satrs::{
encoding::ccsds::{SpacePacketValidation, SpacePacketValidator},
encoding::ccsds::{SpValidity, SpacePacketValidator},
hal::std::tcp_server::{HandledConnectionHandler, ServerConfig, TcpSpacepacketsServer},
spacepackets::{CcsdsPacket, PacketId},
tmtc::{PacketSenderRaw, PacketSource},
@ -25,14 +25,14 @@ impl SpacePacketValidator for SimplePacketValidator {
&self,
sp_header: &satrs::spacepackets::SpHeader,
_raw_buf: &[u8],
) -> satrs::encoding::ccsds::SpacePacketValidation {
) -> satrs::encoding::ccsds::SpValidity {
if self.valid_ids.contains(&sp_header.packet_id()) {
return SpacePacketValidation::Valid;
return SpValidity::Valid;
}
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.
SpacePacketValidation::Ignore
SpValidity::Ignore
}
}

View File

@ -3,7 +3,7 @@ use spacepackets::{CcsdsPacket, SpHeader};
use crate::{tmtc::PacketSenderRaw, ComponentId};
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum SpacePacketValidation {
pub enum SpValidity {
Valid,
/// The space packet can be assumed to have a valid format, but the packet should
/// be ignored.
@ -18,7 +18,7 @@ pub enum SpacePacketValidation {
/// Simple trait to allow user code to check the validity of a space packet.
pub trait SpacePacketValidator {
fn validate(&self, sp_header: &SpHeader, raw_buf: &[u8]) -> SpacePacketValidation;
fn validate(&self, sp_header: &SpHeader, raw_buf: &[u8]) -> SpValidity;
}
/// This function parses a given buffer for tightly packed CCSDS space packets. It uses the
@ -55,7 +55,7 @@ pub fn parse_buffer_for_ccsds_space_packets<SendError>(
let sp_header = SpHeader::from_be_bytes(&buf[current_idx..]).unwrap().0;
// let packet_id = u16::from_be_bytes(buf[current_idx..current_idx + 2].try_into().unwrap());
match packet_validator.validate(&sp_header, &buf[current_idx..]) {
SpacePacketValidation::Valid => {
SpValidity::Valid => {
let packet_size = sp_header.total_len();
if (current_idx + packet_size) <= buf_len {
packet_sender
@ -71,11 +71,11 @@ pub fn parse_buffer_for_ccsds_space_packets<SendError>(
current_idx += packet_size;
continue;
}
SpacePacketValidation::Ignore => {
SpValidity::Ignore => {
current_idx += sp_header.total_len();
}
// We might have lost sync. Try to find the start of a new space packet header.
SpacePacketValidation::Invalid => {
SpValidity::Invalid => {
current_idx += 1;
}
}
@ -93,7 +93,7 @@ mod tests {
use crate::{encoding::tests::TcCacher, ComponentId};
use super::{
parse_buffer_for_ccsds_space_packets, SpacePacketValidation, SpacePacketValidator,
parse_buffer_for_ccsds_space_packets, SpValidity, SpacePacketValidator,
};
const PARSER_ID: ComponentId = 0x05;
@ -116,13 +116,13 @@ mod tests {
}
impl SpacePacketValidator for SimpleVerificator {
fn validate(&self, sp_header: &SpHeader, _raw_buf: &[u8]) -> super::SpacePacketValidation {
fn validate(&self, sp_header: &SpHeader, _raw_buf: &[u8]) -> super::SpValidity {
if sp_header.packet_id() == TEST_PACKET_ID_0
|| (self.enable_second_id && sp_header.packet_id() == TEST_PACKET_ID_1)
{
return SpacePacketValidation::Valid;
return SpValidity::Valid;
}
SpacePacketValidation::Ignore
SpValidity::Ignore
}
}

View File

@ -185,7 +185,7 @@ mod tests {
};
use crate::{
encoding::ccsds::{SpacePacketValidation, SpacePacketValidator},
encoding::ccsds::{SpValidity, SpacePacketValidator},
hal::std::tcp_server::{
tests::{ConnectionFinishedHandler, SyncTmSource},
ConnectionResult, ServerConfig,
@ -207,12 +207,12 @@ mod tests {
pub struct SimpleValidator(pub HashSet<PacketId>);
impl SpacePacketValidator for SimpleValidator {
fn validate(&self, sp_header: &SpHeader, _raw_buf: &[u8]) -> SpacePacketValidation {
fn validate(&self, sp_header: &SpHeader, _raw_buf: &[u8]) -> SpValidity {
if self.0.contains(&sp_header.packet_id()) {
return SpacePacketValidation::Valid;
return SpValidity::Valid;
}
// Simple case: Assume that the interface always contains valid space packets.
SpacePacketValidation::Ignore
SpValidity::Ignore
}
}

View File

@ -24,7 +24,7 @@ use std::{
use hashbrown::HashSet;
use satrs::{
encoding::{
ccsds::{SpacePacketValidation, SpacePacketValidator},
ccsds::{SpValidity, SpacePacketValidator},
cobs::encode_packet_with_cobs,
},
hal::std::tcp_server::{
@ -205,11 +205,11 @@ impl SpacePacketValidator for SimpleVerificator {
&self,
sp_header: &SpHeader,
_raw_buf: &[u8],
) -> satrs::encoding::ccsds::SpacePacketValidation {
) -> satrs::encoding::ccsds::SpValidity {
if self.valid_ids.contains(&sp_header.packet_id()) {
return SpacePacketValidation::Valid;
return SpValidity::Valid;
}
SpacePacketValidation::Ignore
SpValidity::Ignore
}
}