Add Crossbeam helpers #52

Merged
muellerr merged 2 commits from add-crossbeam-tmtc-helpers into main 2023-07-11 22:53:33 +02:00
2 changed files with 8 additions and 21 deletions
Showing only changes of commit df346467bc - Show all commits

View File

@ -319,6 +319,7 @@ pub mod std_mod {
use crate::ChannelId; use crate::ChannelId;
use alloc::boxed::Box; use alloc::boxed::Box;
use alloc::vec::Vec; use alloc::vec::Vec;
use crossbeam_channel as cb;
use spacepackets::ecss::tm::PusTmCreator; use spacepackets::ecss::tm::PusTmCreator;
use spacepackets::ecss::PusError; use spacepackets::ecss::PusError;
use spacepackets::time::cds::TimeProvider; use spacepackets::time::cds::TimeProvider;
@ -329,7 +330,6 @@ pub mod std_mod {
use std::sync::mpsc; use std::sync::mpsc;
use std::sync::mpsc::TryRecvError; use std::sync::mpsc::TryRecvError;
use thiserror::Error; use thiserror::Error;
use crossbeam_channel as cb;
impl From<mpsc::SendError<StoreAddr>> for EcssTmtcError { impl From<mpsc::SendError<StoreAddr>> for EcssTmtcError {
fn from(_: mpsc::SendError<StoreAddr>) -> Self { fn from(_: mpsc::SendError<StoreAddr>) -> Self {
@ -444,11 +444,7 @@ pub mod std_mod {
name: &'static str, name: &'static str,
receiver: mpsc::Receiver<TcAddrWithToken>, receiver: mpsc::Receiver<TcAddrWithToken>,
) -> Self { ) -> Self {
Self { Self { id, name, receiver }
id,
name,
receiver,
}
} }
} }
@ -504,7 +500,6 @@ pub mod std_mod {
name: &'static str, name: &'static str,
shared_tm_store: SharedTmStore, shared_tm_store: SharedTmStore,
sender: crossbeam_channel::Sender<StoreAddr>, sender: crossbeam_channel::Sender<StoreAddr>,
pub ignore_poison_errors: bool,
} }
impl CrossbeamTmInStoreSender { impl CrossbeamTmInStoreSender {
@ -513,14 +508,12 @@ pub mod std_mod {
name: &'static str, name: &'static str,
shared_tm_store: SharedTmStore, shared_tm_store: SharedTmStore,
sender: crossbeam_channel::Sender<StoreAddr>, sender: crossbeam_channel::Sender<StoreAddr>,
ignore_poison_errors: bool,
) -> Self { ) -> Self {
Self { Self {
id, id,
name, name,
shared_tm_store, shared_tm_store,
sender, sender,
ignore_poison_errors,
} }
} }
} }
@ -558,13 +551,9 @@ pub mod std_mod {
pub fn new( pub fn new(
id: ChannelId, id: ChannelId,
name: &'static str, name: &'static str,
receiver: cb::Receiver<TcAddrWithToken> receiver: cb::Receiver<TcAddrWithToken>,
) -> Self { ) -> Self {
Self { Self { id, name, receiver }
id,
name,
receiver,
}
} }
} }

View File

@ -1,5 +1,3 @@
// TODO: Refactor this to also test the STD impl using mpsc
// TODO: Change back to cross-beam as soon as STD impl was added back for TM.
#[cfg(feature = "crossbeam")] #[cfg(feature = "crossbeam")]
pub mod crossbeam_test { pub mod crossbeam_test {
use hashbrown::HashMap; use hashbrown::HashMap;
@ -7,13 +5,13 @@ pub mod crossbeam_test {
use satrs_core::pus::verification::{ use satrs_core::pus::verification::{
FailParams, RequestId, VerificationReporterCfg, VerificationReporterWithSender, FailParams, RequestId, VerificationReporterCfg, VerificationReporterWithSender,
}; };
use satrs_core::pus::MpscTmInStoreSender; use satrs_core::pus::CrossbeamTmInStoreSender;
use satrs_core::tmtc::tm_helper::SharedTmStore; use satrs_core::tmtc::tm_helper::SharedTmStore;
use spacepackets::ecss::tc::{PusTcCreator, PusTcReader, PusTcSecondaryHeader}; use spacepackets::ecss::tc::{PusTcCreator, PusTcReader, PusTcSecondaryHeader};
use spacepackets::ecss::tm::PusTmReader; use spacepackets::ecss::tm::PusTmReader;
use spacepackets::ecss::{EcssEnumU16, EcssEnumU8, PusPacket, SerializablePusPacket}; use spacepackets::ecss::{EcssEnumU16, EcssEnumU8, PusPacket, SerializablePusPacket};
use spacepackets::SpHeader; use spacepackets::SpHeader;
use std::sync::{mpsc, Arc, RwLock}; use std::sync::{Arc, RwLock};
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
@ -39,9 +37,9 @@ pub mod crossbeam_test {
let shared_tm_store = SharedTmStore::new(Box::new(LocalPool::new(pool_cfg.clone()))); let shared_tm_store = SharedTmStore::new(Box::new(LocalPool::new(pool_cfg.clone())));
let shared_tc_pool_0 = Arc::new(RwLock::new(LocalPool::new(pool_cfg))); let shared_tc_pool_0 = Arc::new(RwLock::new(LocalPool::new(pool_cfg)));
let shared_tc_pool_1 = shared_tc_pool_0.clone(); let shared_tc_pool_1 = shared_tc_pool_0.clone();
let (tx, rx) = mpsc::channel(); let (tx, rx) = crossbeam_channel::bounded(10);
let sender = let sender =
MpscTmInStoreSender::new(0, "verif_sender", shared_tm_store.clone(), tx.clone()); CrossbeamTmInStoreSender::new(0, "verif_sender", shared_tm_store.clone(), tx.clone());
let mut reporter_with_sender_0 = let mut reporter_with_sender_0 =
VerificationReporterWithSender::new(&cfg, Box::new(sender)); VerificationReporterWithSender::new(&cfg, Box::new(sender));
let mut reporter_with_sender_1 = reporter_with_sender_0.clone(); let mut reporter_with_sender_1 = reporter_with_sender_0.clone();