add Vec test for PUS17 handler

This commit is contained in:
2024-01-31 23:03:57 +01:00
parent 9bea82ff0e
commit 982b1afcb9
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,
name: &'static str,
receiver: mpsc::Receiver<EcssTcAndToken>,
}
impl EcssChannel for MpscTcInStoreReceiver {
impl EcssChannel for MpscTcReceiver {
fn id(&self) -> ChannelId {
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> {
self.receiver.try_recv().map_err(|e| match e {
TryRecvError::Empty => TryRecvTmtcError::Empty,
@ -501,7 +501,7 @@ pub mod std_mod {
}
}
impl MpscTcInStoreReceiver {
impl MpscTcReceiver {
pub fn new(
id: ChannelId,
name: &'static str,
@ -518,8 +518,8 @@ pub mod std_mod {
#[derive(Clone)]
pub struct MpscTmAsVecSender {
id: ChannelId,
sender: mpsc::Sender<Vec<u8>>,
name: &'static str,
sender: mpsc::Sender<Vec<u8>>,
}
impl From<mpsc::SendError<Vec<u8>>> for EcssTmtcError {
@ -604,13 +604,13 @@ pub mod std_mod {
}
}
pub struct CrossbeamTcInStoreReceiver {
pub struct CrossbeamTcReceiver {
id: ChannelId,
name: &'static str,
receiver: cb::Receiver<EcssTcAndToken>,
}
impl CrossbeamTcInStoreReceiver {
impl CrossbeamTcReceiver {
pub fn new(
id: ChannelId,
name: &'static str,
@ -620,7 +620,7 @@ pub mod std_mod {
}
}
impl EcssChannel for CrossbeamTcInStoreReceiver {
impl EcssChannel for CrossbeamTcReceiver {
fn id(&self) -> ChannelId {
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> {
self.receiver.try_recv().map_err(|e| match e {
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.
/// Please note that this structure is not able to convert TCs which are stored inside a
/// [SharedPool].
#[derive(Default, Clone)]
pub struct EcssTcInVecConverter {
pub pus_tc_raw: Option<Vec<u8>>,
}

View File

@ -113,7 +113,7 @@ mod tests {
RequestId, VerificationReporterCfg, VerificationReporterWithSender,
};
use crate::pus::{
EcssTcAndToken, EcssTcInStoreConverter, MpscTcInStoreReceiver, MpscTmInStoreSender,
EcssTcAndToken, EcssTcInStoreConverter, MpscTcReceiver, MpscTmInStoreSender, MpscTmAsVecSender, EcssTcInVecConverter, TcInMemory,
};
use crate::tmtc::tm_helper::SharedTmStore;
use spacepackets::ecss::tc::{PusTcCreator, PusTcSecondaryHeader};
@ -127,7 +127,7 @@ mod tests {
const TEST_APID: u16 = 0x101;
#[test]
fn test_basic_ping_processing() {
fn test_basic_ping_processing_using_store() {
let mut pus_buf: [u8; 64] = [0; 64];
let pool_cfg = PoolCfg::new(vec![(16, 16), (8, 32), (4, 64)]);
let tc_pool = LocalPool::new(pool_cfg.clone());
@ -143,7 +143,7 @@ mod tests {
let mut verification_handler =
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_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 mut pus_17_handler = PusService17TestHandler::new(
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");
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());
}
}