that's a better name
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit
This commit is contained in:
parent
72077505b7
commit
29c0961fab
@ -7,7 +7,7 @@ use std::{
|
|||||||
|
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
use satrs::{
|
use satrs::{
|
||||||
encoding::ccsds::{SpacePacketValidation, SpacePacketValidator},
|
encoding::ccsds::{SpValidity, SpacePacketValidator},
|
||||||
hal::std::tcp_server::{HandledConnectionHandler, ServerConfig, TcpSpacepacketsServer},
|
hal::std::tcp_server::{HandledConnectionHandler, ServerConfig, TcpSpacepacketsServer},
|
||||||
spacepackets::{CcsdsPacket, PacketId},
|
spacepackets::{CcsdsPacket, PacketId},
|
||||||
tmtc::{PacketSenderRaw, PacketSource},
|
tmtc::{PacketSenderRaw, PacketSource},
|
||||||
@ -25,14 +25,14 @@ impl SpacePacketValidator for SimplePacketValidator {
|
|||||||
&self,
|
&self,
|
||||||
sp_header: &satrs::spacepackets::SpHeader,
|
sp_header: &satrs::spacepackets::SpHeader,
|
||||||
_raw_buf: &[u8],
|
_raw_buf: &[u8],
|
||||||
) -> satrs::encoding::ccsds::SpacePacketValidation {
|
) -> satrs::encoding::ccsds::SpValidity {
|
||||||
if self.valid_ids.contains(&sp_header.packet_id()) {
|
if self.valid_ids.contains(&sp_header.packet_id()) {
|
||||||
return SpacePacketValidation::Valid;
|
return SpValidity::Valid;
|
||||||
}
|
}
|
||||||
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.
|
||||||
SpacePacketValidation::Ignore
|
SpValidity::Ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ use spacepackets::{CcsdsPacket, SpHeader};
|
|||||||
use crate::{tmtc::PacketSenderRaw, ComponentId};
|
use crate::{tmtc::PacketSenderRaw, ComponentId};
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
pub enum SpacePacketValidation {
|
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 ignored.
|
||||||
@ -18,7 +18,7 @@ pub enum SpacePacketValidation {
|
|||||||
|
|
||||||
/// Simple trait to allow user code to check the validity of a space packet.
|
/// Simple trait to allow user code to check the validity of a space packet.
|
||||||
pub trait SpacePacketValidator {
|
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
|
/// 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 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());
|
// 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..]) {
|
match packet_validator.validate(&sp_header, &buf[current_idx..]) {
|
||||||
SpacePacketValidation::Valid => {
|
SpValidity::Valid => {
|
||||||
let packet_size = sp_header.total_len();
|
let packet_size = sp_header.total_len();
|
||||||
if (current_idx + packet_size) <= buf_len {
|
if (current_idx + packet_size) <= buf_len {
|
||||||
packet_sender
|
packet_sender
|
||||||
@ -71,11 +71,11 @@ pub fn parse_buffer_for_ccsds_space_packets<SendError>(
|
|||||||
current_idx += packet_size;
|
current_idx += packet_size;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SpacePacketValidation::Ignore => {
|
SpValidity::Ignore => {
|
||||||
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.
|
||||||
SpacePacketValidation::Invalid => {
|
SpValidity::Invalid => {
|
||||||
current_idx += 1;
|
current_idx += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,7 +93,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, SpacePacketValidation, SpacePacketValidator,
|
parse_buffer_for_ccsds_space_packets, SpValidity, SpacePacketValidator,
|
||||||
};
|
};
|
||||||
|
|
||||||
const PARSER_ID: ComponentId = 0x05;
|
const PARSER_ID: ComponentId = 0x05;
|
||||||
@ -116,13 +116,13 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SpacePacketValidator for SimpleVerificator {
|
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
|
if sp_header.packet_id() == TEST_PACKET_ID_0
|
||||||
|| (self.enable_second_id && sp_header.packet_id() == TEST_PACKET_ID_1)
|
|| (self.enable_second_id && sp_header.packet_id() == TEST_PACKET_ID_1)
|
||||||
{
|
{
|
||||||
return SpacePacketValidation::Valid;
|
return SpValidity::Valid;
|
||||||
}
|
}
|
||||||
SpacePacketValidation::Ignore
|
SpValidity::Ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
encoding::ccsds::{SpacePacketValidation, SpacePacketValidator},
|
encoding::ccsds::{SpValidity, SpacePacketValidator},
|
||||||
hal::std::tcp_server::{
|
hal::std::tcp_server::{
|
||||||
tests::{ConnectionFinishedHandler, SyncTmSource},
|
tests::{ConnectionFinishedHandler, SyncTmSource},
|
||||||
ConnectionResult, ServerConfig,
|
ConnectionResult, ServerConfig,
|
||||||
@ -207,12 +207,12 @@ mod tests {
|
|||||||
pub struct SimpleValidator(pub HashSet<PacketId>);
|
pub struct SimpleValidator(pub HashSet<PacketId>);
|
||||||
|
|
||||||
impl SpacePacketValidator for SimpleValidator {
|
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()) {
|
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.
|
// Simple case: Assume that the interface always contains valid space packets.
|
||||||
SpacePacketValidation::Ignore
|
SpValidity::Ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ use std::{
|
|||||||
use hashbrown::HashSet;
|
use hashbrown::HashSet;
|
||||||
use satrs::{
|
use satrs::{
|
||||||
encoding::{
|
encoding::{
|
||||||
ccsds::{SpacePacketValidation, SpacePacketValidator},
|
ccsds::{SpValidity, SpacePacketValidator},
|
||||||
cobs::encode_packet_with_cobs,
|
cobs::encode_packet_with_cobs,
|
||||||
},
|
},
|
||||||
hal::std::tcp_server::{
|
hal::std::tcp_server::{
|
||||||
@ -205,11 +205,11 @@ impl SpacePacketValidator for SimpleVerificator {
|
|||||||
&self,
|
&self,
|
||||||
sp_header: &SpHeader,
|
sp_header: &SpHeader,
|
||||||
_raw_buf: &[u8],
|
_raw_buf: &[u8],
|
||||||
) -> satrs::encoding::ccsds::SpacePacketValidation {
|
) -> satrs::encoding::ccsds::SpValidity {
|
||||||
if self.valid_ids.contains(&sp_header.packet_id()) {
|
if self.valid_ids.contains(&sp_header.packet_id()) {
|
||||||
return SpacePacketValidation::Valid;
|
return SpValidity::Valid;
|
||||||
}
|
}
|
||||||
SpacePacketValidation::Ignore
|
SpValidity::Ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user