introduce crossbeam module
This commit is contained in:
parent
75c687feed
commit
85b9f6a002
@ -379,7 +379,6 @@ pub mod std_mod {
|
||||
use crate::{ChannelId, TargetId};
|
||||
use alloc::boxed::Box;
|
||||
use alloc::vec::Vec;
|
||||
use crossbeam_channel as cb;
|
||||
use spacepackets::ecss::tc::PusTcReader;
|
||||
use spacepackets::ecss::tm::PusTmCreator;
|
||||
use spacepackets::ecss::{PusError, WritablePusPacket};
|
||||
@ -391,6 +390,9 @@ pub mod std_mod {
|
||||
use std::sync::mpsc::TryRecvError;
|
||||
use thiserror::Error;
|
||||
|
||||
#[cfg(feature = "crossbeam")]
|
||||
pub use cb_mod::*;
|
||||
|
||||
use super::verification::VerificationReportingProvider;
|
||||
use super::{AcceptedEcssTcAndToken, TcInMemory};
|
||||
|
||||
@ -400,21 +402,6 @@ pub mod std_mod {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<cb::SendError<StoreAddr>> for EcssTmtcError {
|
||||
fn from(_: cb::SendError<StoreAddr>) -> Self {
|
||||
Self::Send(GenericSendError::RxDisconnected)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<cb::TrySendError<StoreAddr>> for EcssTmtcError {
|
||||
fn from(value: cb::TrySendError<StoreAddr>) -> Self {
|
||||
match value {
|
||||
cb::TrySendError::Full(_) => Self::Send(GenericSendError::QueueFull(None)),
|
||||
cb::TrySendError::Disconnected(_) => Self::Send(GenericSendError::RxDisconnected),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EcssTmSenderCore for mpsc::Sender<StoreAddr> {
|
||||
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcError> {
|
||||
match tm {
|
||||
@ -439,19 +426,6 @@ pub mod std_mod {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "crossbeam")]
|
||||
impl EcssTmSenderCore for crossbeam_channel::Sender<StoreAddr> {
|
||||
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcError> {
|
||||
match tm {
|
||||
PusTmWrapper::InStore(addr) => self
|
||||
.try_send(addr)
|
||||
.map_err(|e| EcssTmtcError::Send(e.into()))?,
|
||||
PusTmWrapper::Direct(_) => return Err(EcssTmtcError::CantSendDirectTm),
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl EcssTmSenderCore for mpsc::Sender<Vec<u8>> {
|
||||
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcError> {
|
||||
match tm {
|
||||
@ -476,19 +450,6 @@ pub mod std_mod {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "crossbeam")]
|
||||
impl EcssTmSenderCore for crossbeam_channel::Sender<Vec<u8>> {
|
||||
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcError> {
|
||||
match tm {
|
||||
PusTmWrapper::InStore(addr) => return Err(EcssTmtcError::CantSendAddr(addr)),
|
||||
PusTmWrapper::Direct(tm) => self
|
||||
.send(tm.to_vec()?)
|
||||
.map_err(|e| EcssTmtcError::Send(e.into()))?,
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TmInSharedPoolSenderWithId<Sender: EcssTmSenderCore> {
|
||||
channel_id: ChannelId,
|
||||
@ -542,9 +503,6 @@ pub mod std_mod {
|
||||
pub type TmInSharedPoolSenderWithMpsc = TmInSharedPoolSenderWithId<mpsc::Sender<StoreAddr>>;
|
||||
pub type TmInSharedPoolSenderWithBoundedMpsc =
|
||||
TmInSharedPoolSenderWithId<mpsc::SyncSender<StoreAddr>>;
|
||||
#[cfg(feature = "crossbeam")]
|
||||
pub type TmInSharedPoolSenderWithCrossbeam =
|
||||
TmInSharedPoolSenderWithId<crossbeam_channel::Sender<StoreAddr>>;
|
||||
|
||||
/// This class can be used if frequent heap allocations during run-time are not an issue.
|
||||
/// PUS TM packets will be sent around as [Vec]s. Please note that the current implementation
|
||||
@ -624,6 +582,53 @@ pub mod std_mod {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "crossbeam")]
|
||||
pub mod cb_mod {
|
||||
use super::*;
|
||||
|
||||
pub type TmInSharedPoolSenderWithCrossbeam =
|
||||
TmInSharedPoolSenderWithId<cb::Sender<StoreAddr>>;
|
||||
|
||||
impl From<cb::SendError<StoreAddr>> for EcssTmtcError {
|
||||
fn from(_: cb::SendError<StoreAddr>) -> Self {
|
||||
Self::Send(GenericSendError::RxDisconnected)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<cb::TrySendError<StoreAddr>> for EcssTmtcError {
|
||||
fn from(value: cb::TrySendError<StoreAddr>) -> Self {
|
||||
match value {
|
||||
cb::TrySendError::Full(_) => Self::Send(GenericSendError::QueueFull(None)),
|
||||
cb::TrySendError::Disconnected(_) => {
|
||||
Self::Send(GenericSendError::RxDisconnected)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EcssTmSenderCore for cb::Sender<StoreAddr> {
|
||||
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcError> {
|
||||
match tm {
|
||||
PusTmWrapper::InStore(addr) => self
|
||||
.try_send(addr)
|
||||
.map_err(|e| EcssTmtcError::Send(e.into()))?,
|
||||
PusTmWrapper::Direct(_) => return Err(EcssTmtcError::CantSendDirectTm),
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
impl EcssTmSenderCore for cb::Sender<Vec<u8>> {
|
||||
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcError> {
|
||||
match tm {
|
||||
PusTmWrapper::InStore(addr) => return Err(EcssTmtcError::CantSendAddr(addr)),
|
||||
PusTmWrapper::Direct(tm) => self
|
||||
.send(tm.to_vec()?)
|
||||
.map_err(|e| EcssTmtcError::Send(e.into()))?,
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CrossbeamTcReceiver {
|
||||
id: ChannelId,
|
||||
name: &'static str,
|
||||
@ -654,12 +659,13 @@ pub mod std_mod {
|
||||
fn recv_tc(&self) -> Result<EcssTcAndToken, TryRecvTmtcError> {
|
||||
self.receiver.try_recv().map_err(|e| match e {
|
||||
cb::TryRecvError::Empty => TryRecvTmtcError::Empty,
|
||||
cb::TryRecvError::Disconnected => {
|
||||
TryRecvTmtcError::Tmtc(EcssTmtcError::from(GenericRecvError::TxDisconnected))
|
||||
}
|
||||
cb::TryRecvError::Disconnected => TryRecvTmtcError::Tmtc(EcssTmtcError::from(
|
||||
GenericRecvError::TxDisconnected,
|
||||
)),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: All these types could probably be no_std if we implemented error handling ourselves..
|
||||
// but thiserror is really nice, so keep it like this for simplicity for now. Maybe thiserror
|
||||
|
Loading…
Reference in New Issue
Block a user