add Vec test for PUS17 handler

This commit is contained in:
Robin Müller 2024-01-31 23:03:57 +01:00
parent 9bea82ff0e
commit 982b1afcb9
Signed by: muellerr
GPG Key ID: A649FB78196E3849
3 changed files with 66 additions and 18 deletions

View File

@ -474,13 +474,13 @@ pub mod std_mod {
} }
} }
pub struct MpscTcInStoreReceiver { pub struct MpscTcReceiver {
id: ChannelId, id: ChannelId,
name: &'static str, name: &'static str,
receiver: mpsc::Receiver<EcssTcAndToken>, receiver: mpsc::Receiver<EcssTcAndToken>,
} }
impl EcssChannel for MpscTcInStoreReceiver { impl EcssChannel for MpscTcReceiver {
fn id(&self) -> ChannelId { fn id(&self) -> ChannelId {
self.id self.id
} }
@ -490,7 +490,7 @@ pub mod std_mod {
} }
} }
impl EcssTcReceiverCore for MpscTcInStoreReceiver { impl EcssTcReceiverCore for MpscTcReceiver {
fn recv_tc(&self) -> Result<EcssTcAndToken, TryRecvTmtcError> { fn recv_tc(&self) -> Result<EcssTcAndToken, TryRecvTmtcError> {
self.receiver.try_recv().map_err(|e| match e { self.receiver.try_recv().map_err(|e| match e {
TryRecvError::Empty => TryRecvTmtcError::Empty, TryRecvError::Empty => TryRecvTmtcError::Empty,
@ -501,7 +501,7 @@ pub mod std_mod {
} }
} }
impl MpscTcInStoreReceiver { impl MpscTcReceiver {
pub fn new( pub fn new(
id: ChannelId, id: ChannelId,
name: &'static str, name: &'static str,
@ -518,8 +518,8 @@ pub mod std_mod {
#[derive(Clone)] #[derive(Clone)]
pub struct MpscTmAsVecSender { pub struct MpscTmAsVecSender {
id: ChannelId, id: ChannelId,
sender: mpsc::Sender<Vec<u8>>,
name: &'static str, name: &'static str,
sender: mpsc::Sender<Vec<u8>>,
} }
impl From<mpsc::SendError<Vec<u8>>> for EcssTmtcError { impl From<mpsc::SendError<Vec<u8>>> for EcssTmtcError {
@ -604,13 +604,13 @@ pub mod std_mod {
} }
} }
pub struct CrossbeamTcInStoreReceiver { pub struct CrossbeamTcReceiver {
id: ChannelId, id: ChannelId,
name: &'static str, name: &'static str,
receiver: cb::Receiver<EcssTcAndToken>, receiver: cb::Receiver<EcssTcAndToken>,
} }
impl CrossbeamTcInStoreReceiver { impl CrossbeamTcReceiver {
pub fn new( pub fn new(
id: ChannelId, id: ChannelId,
name: &'static str, name: &'static str,
@ -620,7 +620,7 @@ pub mod std_mod {
} }
} }
impl EcssChannel for CrossbeamTcInStoreReceiver { impl EcssChannel for CrossbeamTcReceiver {
fn id(&self) -> ChannelId { fn id(&self) -> ChannelId {
self.id self.id
} }
@ -630,7 +630,7 @@ pub mod std_mod {
} }
} }
impl EcssTcReceiverCore for CrossbeamTcInStoreReceiver { impl EcssTcReceiverCore for CrossbeamTcReceiver {
fn recv_tc(&self) -> Result<EcssTcAndToken, TryRecvTmtcError> { fn recv_tc(&self) -> Result<EcssTcAndToken, TryRecvTmtcError> {
self.receiver.try_recv().map_err(|e| match e { self.receiver.try_recv().map_err(|e| match e {
cb::TryRecvError::Empty => TryRecvTmtcError::Empty, cb::TryRecvError::Empty => TryRecvTmtcError::Empty,
@ -713,6 +713,7 @@ pub mod std_mod {
/// Converter structure for PUS telecommands which are stored inside a `Vec<u8>` structure. /// Converter structure for PUS telecommands which are stored inside a `Vec<u8>` structure.
/// Please note that this structure is not able to convert TCs which are stored inside a /// Please note that this structure is not able to convert TCs which are stored inside a
/// [SharedPool]. /// [SharedPool].
#[derive(Default, Clone)]
pub struct EcssTcInVecConverter { pub struct EcssTcInVecConverter {
pub pus_tc_raw: Option<Vec<u8>>, pub pus_tc_raw: Option<Vec<u8>>,
} }

View File

@ -113,7 +113,7 @@ mod tests {
RequestId, VerificationReporterCfg, VerificationReporterWithSender, RequestId, VerificationReporterCfg, VerificationReporterWithSender,
}; };
use crate::pus::{ use crate::pus::{
EcssTcAndToken, EcssTcInStoreConverter, MpscTcInStoreReceiver, MpscTmInStoreSender, EcssTcAndToken, EcssTcInStoreConverter, MpscTcReceiver, MpscTmInStoreSender, MpscTmAsVecSender, EcssTcInVecConverter, TcInMemory,
}; };
use crate::tmtc::tm_helper::SharedTmStore; use crate::tmtc::tm_helper::SharedTmStore;
use spacepackets::ecss::tc::{PusTcCreator, PusTcSecondaryHeader}; use spacepackets::ecss::tc::{PusTcCreator, PusTcSecondaryHeader};
@ -127,7 +127,7 @@ mod tests {
const TEST_APID: u16 = 0x101; const TEST_APID: u16 = 0x101;
#[test] #[test]
fn test_basic_ping_processing() { fn test_basic_ping_processing_using_store() {
let mut pus_buf: [u8; 64] = [0; 64]; let mut pus_buf: [u8; 64] = [0; 64];
let pool_cfg = PoolCfg::new(vec![(16, 16), (8, 32), (4, 64)]); let pool_cfg = PoolCfg::new(vec![(16, 16), (8, 32), (4, 64)]);
let tc_pool = LocalPool::new(pool_cfg.clone()); let tc_pool = LocalPool::new(pool_cfg.clone());
@ -143,7 +143,7 @@ mod tests {
let mut verification_handler = let mut verification_handler =
VerificationReporterWithSender::new(&verif_cfg, Box::new(verif_sender)); VerificationReporterWithSender::new(&verif_cfg, Box::new(verif_sender));
let test_srv_tm_sender = MpscTmInStoreSender::new(0, "TEST_SENDER", shared_tm_store, tm_tx); let test_srv_tm_sender = MpscTmInStoreSender::new(0, "TEST_SENDER", shared_tm_store, tm_tx);
let test_srv_tc_receiver = MpscTcInStoreReceiver::new(0, "TEST_RECEIVER", test_srv_tc_rx); let test_srv_tc_receiver = MpscTcReceiver::new(0, "TEST_RECEIVER", test_srv_tc_rx);
let in_store_converter = EcssTcInStoreConverter::new(tc_pool_shared.clone(), 2048); let in_store_converter = EcssTcInStoreConverter::new(tc_pool_shared.clone(), 2048);
let mut pus_17_handler = PusService17TestHandler::new( let mut pus_17_handler = PusService17TestHandler::new(
Box::new(test_srv_tc_receiver), Box::new(test_srv_tc_receiver),
@ -218,4 +218,51 @@ mod tests {
let req_id = RequestId::from_bytes(tm.user_data()).expect("generating request ID failed"); let req_id = RequestId::from_bytes(tm.user_data()).expect("generating request ID failed");
assert_eq!(req_id, token.req_id()); assert_eq!(req_id, token.req_id());
} }
#[test]
fn test_basic_ping_processing_using_vec() {
let (test_srv_tc_tx, test_srv_tc_rx) = mpsc::channel();
let (tm_tx, tm_rx) = mpsc::channel();
let verif_sender =
MpscTmAsVecSender::new(0, "verif_sender", tm_tx.clone());
let verif_cfg = VerificationReporterCfg::new(TEST_APID, 1, 2, 8).unwrap();
let mut verification_handler =
VerificationReporterWithSender::new(&verif_cfg, Box::new(verif_sender));
let test_srv_tm_sender = MpscTmAsVecSender::new(0, "TEST_SENDER", tm_tx);
let test_srv_tc_receiver = MpscTcReceiver::new(0, "TEST_RECEIVER", test_srv_tc_rx);
let in_store_converter = EcssTcInVecConverter::default();
let mut pus_17_handler = PusService17TestHandler::new(
Box::new(test_srv_tc_receiver),
Box::new(test_srv_tm_sender),
TEST_APID,
verification_handler.clone(),
in_store_converter,
);
// Create a ping TC, verify acceptance.
let mut sp_header = SpHeader::tc(TEST_APID, SequenceFlags::Unsegmented, 0, 0).unwrap();
let sec_header = PusTcSecondaryHeader::new_simple(17, 1);
let ping_tc = PusTcCreator::new_no_app_data(&mut sp_header, sec_header, true);
let token = verification_handler.add_tc(&ping_tc);
verification_handler.acceptance_success(token, None);
let ping_tc_as_vec = ping_tc.to_vec().unwrap();
let tc_in_memory = TcInMemory::from(ping_tc_as_vec);
test_srv_tc_tx.send(EcssTcAndToken::new(tc_in_memory, token)).unwrap();
let result = pus_17_handler.handle_one_tc();
if let Err(e) = result.as_ref() {
panic!("handling one tc failed with: {:?}", e);
}
// We should see 4 replies in the TM queue now: Acceptance TM, Start TM, ping reply and
// Completion TM
let mut next_msg = tm_rx.try_recv();
assert!(next_msg.is_ok());
let mut tm_raw = next_msg.unwrap();
let (tm, _) = PusTmReader::new(&tm_raw, 0).unwrap();
assert_eq!(tm.service(), 1);
assert_eq!(tm.subservice(), 1);
let req_id = RequestId::from_bytes(tm.user_data()).expect("generating request ID failed");
assert_eq!(req_id, token.req_id());
}
} }

View File

@ -42,7 +42,7 @@ use satrs_core::pus::test::PusService17TestHandler;
use satrs_core::pus::verification::{ use satrs_core::pus::verification::{
TcStateStarted, VerificationReporterCfg, VerificationReporterWithSender, VerificationToken, TcStateStarted, VerificationReporterCfg, VerificationReporterWithSender, VerificationToken,
}; };
use satrs_core::pus::{EcssTcInStoreConverter, MpscTcInStoreReceiver, MpscTmInStoreSender}; use satrs_core::pus::{EcssTcInStoreConverter, MpscTcReceiver, MpscTmInStoreSender};
use satrs_core::seq_count::{CcsdsSimpleSeqCountProvider, SequenceCountProviderCore}; use satrs_core::seq_count::{CcsdsSimpleSeqCountProvider, SequenceCountProviderCore};
use satrs_core::spacepackets::ecss::tm::{PusTmCreator, PusTmZeroCopyWriter}; use satrs_core::spacepackets::ecss::tm::{PusTmCreator, PusTmZeroCopyWriter};
use satrs_core::spacepackets::{ use satrs_core::spacepackets::{
@ -172,7 +172,7 @@ fn main() {
shared_tm_store.clone(), shared_tm_store.clone(),
tm_funnel_tx.clone(), tm_funnel_tx.clone(),
); );
let test_srv_receiver = MpscTcInStoreReceiver::new( let test_srv_receiver = MpscTcReceiver::new(
TcReceiverId::PusTest as ChannelId, TcReceiverId::PusTest as ChannelId,
"PUS_17_TC_RECV", "PUS_17_TC_RECV",
pus_test_rx, pus_test_rx,
@ -195,7 +195,7 @@ fn main() {
shared_tm_store.clone(), shared_tm_store.clone(),
tm_funnel_tx.clone(), tm_funnel_tx.clone(),
); );
let sched_srv_receiver = MpscTcInStoreReceiver::new( let sched_srv_receiver = MpscTcReceiver::new(
TcReceiverId::PusSched as ChannelId, TcReceiverId::PusSched as ChannelId,
"PUS_11_TC_RECV", "PUS_11_TC_RECV",
pus_sched_rx, pus_sched_rx,
@ -222,7 +222,7 @@ fn main() {
shared_tm_store.clone(), shared_tm_store.clone(),
tm_funnel_tx.clone(), tm_funnel_tx.clone(),
); );
let event_srv_receiver = MpscTcInStoreReceiver::new( let event_srv_receiver = MpscTcReceiver::new(
TcReceiverId::PusEvent as ChannelId, TcReceiverId::PusEvent as ChannelId,
"PUS_5_TC_RECV", "PUS_5_TC_RECV",
pus_event_rx, pus_event_rx,
@ -243,7 +243,7 @@ fn main() {
shared_tm_store.clone(), shared_tm_store.clone(),
tm_funnel_tx.clone(), tm_funnel_tx.clone(),
); );
let action_srv_receiver = MpscTcInStoreReceiver::new( let action_srv_receiver = MpscTcReceiver::new(
TcReceiverId::PusAction as ChannelId, TcReceiverId::PusAction as ChannelId,
"PUS_8_TC_RECV", "PUS_8_TC_RECV",
pus_action_rx, pus_action_rx,
@ -265,7 +265,7 @@ fn main() {
tm_funnel_tx.clone(), tm_funnel_tx.clone(),
); );
let hk_srv_receiver = let hk_srv_receiver =
MpscTcInStoreReceiver::new(TcReceiverId::PusHk as ChannelId, "PUS_8_TC_RECV", pus_hk_rx); MpscTcReceiver::new(TcReceiverId::PusHk as ChannelId, "PUS_8_TC_RECV", pus_hk_rx);
let pus_3_handler = PusService3HkHandler::new( let pus_3_handler = PusService3HkHandler::new(
Box::new(hk_srv_receiver), Box::new(hk_srv_receiver),
Box::new(hk_srv_tm_sender), Box::new(hk_srv_tm_sender),