rework TCP spacepackets validation process
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:
@ -23,7 +23,10 @@ use std::{
|
||||
|
||||
use hashbrown::HashSet;
|
||||
use satrs::{
|
||||
encoding::cobs::encode_packet_with_cobs,
|
||||
encoding::{
|
||||
ccsds::{SpacePacketValidation, SpacePacketValidator},
|
||||
cobs::encode_packet_with_cobs,
|
||||
},
|
||||
hal::std::tcp_server::{
|
||||
ConnectionResult, HandledConnectionHandler, HandledConnectionInfo, ServerConfig,
|
||||
TcpSpacepacketsServer, TcpTmtcInCobsServer,
|
||||
@ -33,7 +36,7 @@ use satrs::{
|
||||
};
|
||||
use spacepackets::{
|
||||
ecss::{tc::PusTcCreator, WritablePusPacket},
|
||||
PacketId, SpHeader,
|
||||
CcsdsPacket, PacketId, SpHeader,
|
||||
};
|
||||
use std::{collections::VecDeque, sync::Arc, vec::Vec};
|
||||
|
||||
@ -130,7 +133,7 @@ fn test_cobs_server() {
|
||||
|
||||
// Call the connection handler in separate thread, does block.
|
||||
thread::spawn(move || {
|
||||
let result = tcp_server.handle_next_connection(Some(Duration::from_millis(400)));
|
||||
let result = tcp_server.handle_all_connections(Some(Duration::from_millis(400)));
|
||||
if result.is_err() {
|
||||
panic!("handling connection failed: {:?}", result.unwrap_err());
|
||||
}
|
||||
@ -192,6 +195,24 @@ fn test_cobs_server() {
|
||||
const TEST_APID_0: u16 = 0x02;
|
||||
const TEST_PACKET_ID_0: PacketId = PacketId::new_for_tc(true, TEST_APID_0);
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct SimpleVerificator {
|
||||
pub valid_ids: HashSet<PacketId>,
|
||||
}
|
||||
|
||||
impl SpacePacketValidator for SimpleVerificator {
|
||||
fn validate(
|
||||
&self,
|
||||
sp_header: &SpHeader,
|
||||
_raw_buf: &[u8],
|
||||
) -> satrs::encoding::ccsds::SpacePacketValidation {
|
||||
if self.valid_ids.contains(&sp_header.packet_id()) {
|
||||
return SpacePacketValidation::Valid;
|
||||
}
|
||||
SpacePacketValidation::Ignore
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ccsds_server() {
|
||||
let (tc_sender, tc_receiver) = mpsc::channel();
|
||||
@ -200,8 +221,8 @@ fn test_ccsds_server() {
|
||||
let verif_tm = PusTcCreator::new_simple(sph, 1, 1, &[], true);
|
||||
let tm_0 = verif_tm.to_vec().expect("tm generation failed");
|
||||
tm_source.add_tm(&tm_0);
|
||||
let mut packet_id_lookup = HashSet::new();
|
||||
packet_id_lookup.insert(TEST_PACKET_ID_0);
|
||||
let mut packet_id_lookup = SimpleVerificator::default();
|
||||
packet_id_lookup.valid_ids.insert(TEST_PACKET_ID_0);
|
||||
let mut tcp_server = TcpSpacepacketsServer::new(
|
||||
ServerConfig::new(
|
||||
TCP_SERVER_ID,
|
||||
@ -224,7 +245,7 @@ fn test_ccsds_server() {
|
||||
let set_if_done = conn_handled.clone();
|
||||
// Call the connection handler in separate thread, does block.
|
||||
thread::spawn(move || {
|
||||
let result = tcp_server.handle_next_connection(Some(Duration::from_millis(500)));
|
||||
let result = tcp_server.handle_all_connections(Some(Duration::from_millis(500)));
|
||||
if result.is_err() {
|
||||
panic!("handling connection failed: {:?}", result.unwrap_err());
|
||||
}
|
||||
|
Reference in New Issue
Block a user