diff --git a/satrs-example/src/interface/tcp.rs b/satrs-example/src/interface/tcp.rs index 8eebe34..8690ad6 100644 --- a/satrs-example/src/interface/tcp.rs +++ b/satrs-example/src/interface/tcp.rs @@ -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 } } diff --git a/satrs/src/encoding/ccsds.rs b/satrs/src/encoding/ccsds.rs index 690dc67..c552409 100644 --- a/satrs/src/encoding/ccsds.rs +++ b/satrs/src/encoding/ccsds.rs @@ -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( 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( 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 } } diff --git a/satrs/src/hal/std/tcp_spacepackets_server.rs b/satrs/src/hal/std/tcp_spacepackets_server.rs index 1756d78..b03d522 100644 --- a/satrs/src/hal/std/tcp_spacepackets_server.rs +++ b/satrs/src/hal/std/tcp_spacepackets_server.rs @@ -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); 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 } } diff --git a/satrs/tests/tcp_servers.rs b/satrs/tests/tcp_servers.rs index 227ee68..12e62c7 100644 --- a/satrs/tests/tcp_servers.rs +++ b/satrs/tests/tcp_servers.rs @@ -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 } }