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 crate::{ChannelId, TargetId};
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use crossbeam_channel as cb;
|
|
||||||
use spacepackets::ecss::tc::PusTcReader;
|
use spacepackets::ecss::tc::PusTcReader;
|
||||||
use spacepackets::ecss::tm::PusTmCreator;
|
use spacepackets::ecss::tm::PusTmCreator;
|
||||||
use spacepackets::ecss::{PusError, WritablePusPacket};
|
use spacepackets::ecss::{PusError, WritablePusPacket};
|
||||||
@ -391,6 +390,9 @@ pub mod std_mod {
|
|||||||
use std::sync::mpsc::TryRecvError;
|
use std::sync::mpsc::TryRecvError;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[cfg(feature = "crossbeam")]
|
||||||
|
pub use cb_mod::*;
|
||||||
|
|
||||||
use super::verification::VerificationReportingProvider;
|
use super::verification::VerificationReportingProvider;
|
||||||
use super::{AcceptedEcssTcAndToken, TcInMemory};
|
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> {
|
impl EcssTmSenderCore for mpsc::Sender<StoreAddr> {
|
||||||
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcError> {
|
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcError> {
|
||||||
match tm {
|
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>> {
|
impl EcssTmSenderCore for mpsc::Sender<Vec<u8>> {
|
||||||
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcError> {
|
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcError> {
|
||||||
match tm {
|
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)]
|
#[derive(Clone)]
|
||||||
pub struct TmInSharedPoolSenderWithId<Sender: EcssTmSenderCore> {
|
pub struct TmInSharedPoolSenderWithId<Sender: EcssTmSenderCore> {
|
||||||
channel_id: ChannelId,
|
channel_id: ChannelId,
|
||||||
@ -542,9 +503,6 @@ pub mod std_mod {
|
|||||||
pub type TmInSharedPoolSenderWithMpsc = TmInSharedPoolSenderWithId<mpsc::Sender<StoreAddr>>;
|
pub type TmInSharedPoolSenderWithMpsc = TmInSharedPoolSenderWithId<mpsc::Sender<StoreAddr>>;
|
||||||
pub type TmInSharedPoolSenderWithBoundedMpsc =
|
pub type TmInSharedPoolSenderWithBoundedMpsc =
|
||||||
TmInSharedPoolSenderWithId<mpsc::SyncSender<StoreAddr>>;
|
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.
|
/// 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
|
/// 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 {
|
pub struct CrossbeamTcReceiver {
|
||||||
id: ChannelId,
|
id: ChannelId,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
@ -654,12 +659,13 @@ pub mod std_mod {
|
|||||||
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,
|
||||||
cb::TryRecvError::Disconnected => {
|
cb::TryRecvError::Disconnected => TryRecvTmtcError::Tmtc(EcssTmtcError::from(
|
||||||
TryRecvTmtcError::Tmtc(EcssTmtcError::from(GenericRecvError::TxDisconnected))
|
GenericRecvError::TxDisconnected,
|
||||||
}
|
)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: All these types could probably be no_std if we implemented error handling ourselves..
|
// 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
|
// but thiserror is really nice, so keep it like this for simplicity for now. Maybe thiserror
|
||||||
|
Loading…
Reference in New Issue
Block a user