From 0b4a88837c92137f78351a0cdb83e251c5b0e26b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 4 Apr 2024 13:26:39 +0200 Subject: [PATCH] split up APID and packet ID validator --- satrs-example/src/ccsds.rs | 10 +++++----- satrs-example/src/config.rs | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/satrs-example/src/ccsds.rs b/satrs-example/src/ccsds.rs index 2373a4d..1841d17 100644 --- a/satrs-example/src/ccsds.rs +++ b/satrs-example/src/ccsds.rs @@ -1,9 +1,9 @@ use satrs::pus::ReceivesEcssPusTc; -use satrs::spacepackets::{CcsdsPacket, PacketId, SpHeader}; +use satrs::spacepackets::{CcsdsPacket, SpHeader}; use satrs::tmtc::{CcsdsPacketHandler, ReceivesCcsdsTc}; use satrs::ValidatorU16Id; use satrs_example::config::components::Apid; -use satrs_example::config::PACKET_ID_VALIDATOR; +use satrs_example::config::APID_VALIDATOR; #[derive(Clone)] pub struct CcsdsReceiver< @@ -18,8 +18,8 @@ impl< E: 'static, > ValidatorU16Id for CcsdsReceiver { - fn validate(&self, packet_id: u16) -> bool { - PACKET_ID_VALIDATOR.contains(&PacketId::from(packet_id)) + fn validate(&self, apid: u16) -> bool { + APID_VALIDATOR.contains(&apid) } } @@ -47,7 +47,7 @@ impl< sp_header: &SpHeader, _tc_raw: &[u8], ) -> Result<(), Self::Error> { - println!("Unknown APID 0x{:x?} detected", sp_header.apid()); + log::warn!("unknown APID 0x{:x?} detected", sp_header.apid()); Ok(()) } } diff --git a/satrs-example/src/config.rs b/satrs-example/src/config.rs index 8f8cd1b..7e474e9 100644 --- a/satrs-example/src/config.rs +++ b/satrs-example/src/config.rs @@ -49,6 +49,13 @@ lazy_static! { } set }; + pub static ref APID_VALIDATOR: HashSet = { + let mut set = HashSet::new(); + for id in components::Apid::iter() { + set.insert(id as u16); + } + set + }; } pub mod tmtc_err {