move PacketAsVec and PacketInPool
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit

This commit is contained in:
Robin Müller 2024-04-15 13:02:34 +02:00
parent 301a7a19a6
commit ef26074bf6
Signed by: muellerr
GPG Key ID: A649FB78196E3849
19 changed files with 158 additions and 153 deletions

View File

@ -3,8 +3,7 @@ use std::net::{SocketAddr, UdpSocket};
use std::sync::mpsc; use std::sync::mpsc;
use log::{info, warn}; use log::{info, warn};
use satrs::pus::{PacketAsVec, PacketInPool}; use satrs::tmtc::{PacketAsVec, PacketInPool, PacketSenderRaw};
use satrs::tmtc::PacketSenderRaw;
use satrs::{ use satrs::{
hal::std::udp_server::{ReceiveResult, UdpTcServer}, hal::std::udp_server::{ReceiveResult, UdpTcServer},
pool::{PoolProviderWithGuards, SharedStaticMemoryPool}, pool::{PoolProviderWithGuards, SharedStaticMemoryPool},

View File

@ -12,13 +12,13 @@ use satrs::pus::verification::{
use satrs::pus::{ use satrs::pus::{
ActiveRequestProvider, EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter, ActiveRequestProvider, EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter,
EcssTcInVecConverter, EcssTmSender, EcssTmtcError, GenericConversionError, MpscTcReceiver, EcssTcInVecConverter, EcssTmSender, EcssTmtcError, GenericConversionError, MpscTcReceiver,
MpscTmAsVecSender, PacketAsVec, PusPacketHandlerResult, PusReplyHandler, PusServiceHelper, MpscTmAsVecSender, PusPacketHandlerResult, PusReplyHandler, PusServiceHelper,
PusTcToRequestConverter, PusTcToRequestConverter,
}; };
use satrs::request::{GenericMessage, UniqueApidTargetId}; use satrs::request::{GenericMessage, UniqueApidTargetId};
use satrs::spacepackets::ecss::tc::PusTcReader; use satrs::spacepackets::ecss::tc::PusTcReader;
use satrs::spacepackets::ecss::{EcssEnumU16, PusPacket}; use satrs::spacepackets::ecss::{EcssEnumU16, PusPacket};
use satrs::tmtc::PacketSenderWithSharedPool; use satrs::tmtc::{PacketAsVec, PacketSenderWithSharedPool};
use satrs_example::config::components::PUS_ACTION_SERVICE; use satrs_example::config::components::PUS_ACTION_SERVICE;
use satrs_example::config::tmtc_err; use satrs_example::config::tmtc_err;
use std::sync::mpsc; use std::sync::mpsc;

View File

@ -8,10 +8,9 @@ use satrs::pus::event_srv::PusEventServiceHandler;
use satrs::pus::verification::VerificationReporter; use satrs::pus::verification::VerificationReporter;
use satrs::pus::{ use satrs::pus::{
EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter,
EcssTmSender, MpscTcReceiver, MpscTmAsVecSender, PacketAsVec, PusPacketHandlerResult, EcssTmSender, MpscTcReceiver, MpscTmAsVecSender, PusPacketHandlerResult, PusServiceHelper,
PusServiceHelper,
}; };
use satrs::tmtc::PacketSenderWithSharedPool; use satrs::tmtc::{PacketAsVec, PacketSenderWithSharedPool};
use satrs_example::config::components::PUS_EVENT_MANAGEMENT; use satrs_example::config::components::PUS_EVENT_MANAGEMENT;
use super::HandlingStatus; use super::HandlingStatus;

View File

@ -9,13 +9,13 @@ use satrs::pus::verification::{
use satrs::pus::{ use satrs::pus::{
ActivePusRequestStd, ActiveRequestProvider, DefaultActiveRequestMap, EcssTcAndToken, ActivePusRequestStd, ActiveRequestProvider, DefaultActiveRequestMap, EcssTcAndToken,
EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, EcssTmSender, EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, EcssTmSender,
EcssTmtcError, GenericConversionError, MpscTcReceiver, MpscTmAsVecSender, PacketAsVec, EcssTmtcError, GenericConversionError, MpscTcReceiver, MpscTmAsVecSender,
PusPacketHandlerResult, PusReplyHandler, PusServiceHelper, PusTcToRequestConverter, PusPacketHandlerResult, PusReplyHandler, PusServiceHelper, PusTcToRequestConverter,
}; };
use satrs::request::{GenericMessage, UniqueApidTargetId}; use satrs::request::{GenericMessage, UniqueApidTargetId};
use satrs::spacepackets::ecss::tc::PusTcReader; use satrs::spacepackets::ecss::tc::PusTcReader;
use satrs::spacepackets::ecss::{hk, PusPacket}; use satrs::spacepackets::ecss::{hk, PusPacket};
use satrs::tmtc::PacketSenderWithSharedPool; use satrs::tmtc::{PacketAsVec, PacketSenderWithSharedPool};
use satrs_example::config::components::PUS_HK_SERVICE; use satrs_example::config::components::PUS_HK_SERVICE;
use satrs_example::config::{hk_err, tmtc_err}; use satrs_example::config::{hk_err, tmtc_err};
use std::sync::mpsc; use std::sync::mpsc;

View File

@ -1,5 +1,6 @@
use crate::requests::GenericRequestRouter; use crate::requests::GenericRequestRouter;
use log::warn; use log::warn;
use satrs::pool::StoreAddr;
use satrs::pus::verification::{ use satrs::pus::verification::{
self, FailParams, TcStateAccepted, TcStateStarted, VerificationReporter, self, FailParams, TcStateAccepted, TcStateStarted, VerificationReporter,
VerificationReporterCfg, VerificationReportingProvider, VerificationToken, VerificationReporterCfg, VerificationReportingProvider, VerificationToken,
@ -13,7 +14,8 @@ use satrs::pus::{
use satrs::queue::{GenericReceiveError, GenericSendError}; use satrs::queue::{GenericReceiveError, GenericSendError};
use satrs::request::{Apid, GenericMessage, MessageMetadata}; use satrs::request::{Apid, GenericMessage, MessageMetadata};
use satrs::spacepackets::ecss::tc::PusTcReader; use satrs::spacepackets::ecss::tc::PusTcReader;
use satrs::spacepackets::ecss::PusServiceId; use satrs::spacepackets::ecss::{PusPacket, PusServiceId};
use satrs::tmtc::{PacketAsVec, PacketInPool};
use satrs::ComponentId; use satrs::ComponentId;
use satrs_example::config::components::PUS_ROUTING_SERVICE; use satrs_example::config::components::PUS_ROUTING_SERVICE;
use satrs_example::config::{tmtc_err, CustomPusServiceId}; use satrs_example::config::{tmtc_err, CustomPusServiceId};
@ -74,19 +76,54 @@ impl<TmSender: EcssTmSender> PusTcDistributor<TmSender> {
} }
} }
pub fn handle_tc_packet( pub fn handle_tc_packet_vec(
&mut self, &mut self,
tc_in_memory: TcInMemory, packet_as_vec: PacketAsVec,
service: u8,
pus_tc: &PusTcReader,
) -> Result<PusPacketHandlerResult, GenericSendError> { ) -> Result<PusPacketHandlerResult, GenericSendError> {
let init_token = self.verif_reporter.add_tc(pus_tc); self.handle_tc_generic(packet_as_vec.sender_id, None, &packet_as_vec.packet)
}
pub fn handle_tc_packet_in_store(
&mut self,
packet_in_pool: PacketInPool,
pus_tc_copy: &[u8],
) -> Result<PusPacketHandlerResult, GenericSendError> {
self.handle_tc_generic(
packet_in_pool.sender_id,
Some(packet_in_pool.store_addr),
pus_tc_copy,
)
}
pub fn handle_tc_generic(
&mut self,
sender_id: ComponentId,
addr_opt: Option<StoreAddr>,
raw_tc: &[u8],
) -> Result<PusPacketHandlerResult, GenericSendError> {
let pus_tc_result = PusTcReader::new(raw_tc);
if pus_tc_result.is_err() {
log::warn!(
"error creating PUS TC from raw data received from {}: {}",
sender_id,
pus_tc_result.unwrap_err()
);
log::warn!("raw data: {:x?}", raw_tc);
return Ok(PusPacketHandlerResult::RequestHandled);
}
let pus_tc = pus_tc_result.unwrap().0;
let init_token = self.verif_reporter.add_tc(&pus_tc);
self.stamp_helper.update_from_now(); self.stamp_helper.update_from_now();
let accepted_token = self let accepted_token = self
.verif_reporter .verif_reporter
.acceptance_success(&self.tm_sender, init_token, self.stamp_helper.stamp()) .acceptance_success(&self.tm_sender, init_token, self.stamp_helper.stamp())
.expect("Acceptance success failure"); .expect("Acceptance success failure");
let service = PusServiceId::try_from(service); let service = PusServiceId::try_from(pus_tc.service());
let tc_in_memory = if let Some(store_addr) = addr_opt {
TcInMemory::StoreAddr(store_addr)
} else {
TcInMemory::Vec(Vec::from(raw_tc))
};
match service { match service {
Ok(standard_service) => match standard_service { Ok(standard_service) => match standard_service {
PusServiceId::Test => self.pus_router.test_tc_sender.send(EcssTcAndToken { PusServiceId::Test => self.pus_router.test_tc_sender.send(EcssTcAndToken {
@ -461,7 +498,7 @@ pub(crate) mod tests {
use std::time::Duration; use std::time::Duration;
use satrs::pus::test_util::TEST_COMPONENT_ID_0; use satrs::pus::test_util::TEST_COMPONENT_ID_0;
use satrs::pus::{MpscTmAsVecSender, PacketAsVec, PusTmVariant}; use satrs::pus::{MpscTmAsVecSender, PusTmVariant};
use satrs::request::RequestId; use satrs::request::RequestId;
use satrs::{ use satrs::{
pus::{ pus::{

View File

@ -1,6 +1,6 @@
use derive_new::new; use derive_new::new;
use log::{error, warn}; use log::{error, warn};
use satrs::tmtc::PacketSenderWithSharedPool; use satrs::tmtc::{PacketAsVec, PacketSenderWithSharedPool};
use std::sync::mpsc; use std::sync::mpsc;
use std::time::Duration; use std::time::Duration;
@ -9,7 +9,7 @@ use satrs::pool::SharedStaticMemoryPool;
use satrs::pus::verification::VerificationReporter; use satrs::pus::verification::VerificationReporter;
use satrs::pus::{ use satrs::pus::{
DefaultActiveRequestMap, EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter, DefaultActiveRequestMap, EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter,
EcssTcInVecConverter, MpscTcReceiver, MpscTmAsVecSender, PacketAsVec, PusPacketHandlerResult, EcssTcInVecConverter, MpscTcReceiver, MpscTmAsVecSender, PusPacketHandlerResult,
PusServiceHelper, PusServiceHelper,
}; };
use satrs::request::GenericMessage; use satrs::request::GenericMessage;

View File

@ -9,10 +9,9 @@ use satrs::pus::scheduler_srv::PusSchedServiceHandler;
use satrs::pus::verification::VerificationReporter; use satrs::pus::verification::VerificationReporter;
use satrs::pus::{ use satrs::pus::{
EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, EcssTcAndToken, EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter,
EcssTmSender, MpscTcReceiver, MpscTmAsVecSender, PacketAsVec, PacketInPool, EcssTmSender, MpscTcReceiver, MpscTmAsVecSender, PusPacketHandlerResult, PusServiceHelper,
PusPacketHandlerResult, PusServiceHelper,
}; };
use satrs::tmtc::PacketSenderWithSharedPool; use satrs::tmtc::{PacketAsVec, PacketInPool, PacketSenderWithSharedPool};
use satrs::ComponentId; use satrs::ComponentId;
use satrs_example::config::components::PUS_SCHED_SERVICE; use satrs_example::config::components::PUS_SCHED_SERVICE;

View File

@ -7,13 +7,13 @@ use satrs::pus::verification::{FailParams, VerificationReporter, VerificationRep
use satrs::pus::EcssTcInSharedStoreConverter; use satrs::pus::EcssTcInSharedStoreConverter;
use satrs::pus::{ use satrs::pus::{
EcssTcAndToken, EcssTcInMemConverter, EcssTcInVecConverter, EcssTmSender, MpscTcReceiver, EcssTcAndToken, EcssTcInMemConverter, EcssTcInVecConverter, EcssTmSender, MpscTcReceiver,
MpscTmAsVecSender, PacketAsVec, PusPacketHandlerResult, PusServiceHelper, MpscTmAsVecSender, PusPacketHandlerResult, PusServiceHelper,
}; };
use satrs::spacepackets::ecss::tc::PusTcReader; use satrs::spacepackets::ecss::tc::PusTcReader;
use satrs::spacepackets::ecss::PusPacket; use satrs::spacepackets::ecss::PusPacket;
use satrs::spacepackets::time::cds::CdsTime; use satrs::spacepackets::time::cds::CdsTime;
use satrs::spacepackets::time::TimeWriter; use satrs::spacepackets::time::TimeWriter;
use satrs::tmtc::PacketSenderWithSharedPool; use satrs::tmtc::{PacketAsVec, PacketSenderWithSharedPool};
use satrs_example::config::components::PUS_TEST_SERVICE; use satrs_example::config::components::PUS_TEST_SERVICE;
use satrs_example::config::{tmtc_err, TEST_EVENT}; use satrs_example::config::{tmtc_err, TEST_EVENT};
use std::sync::mpsc; use std::sync::mpsc;

View File

@ -1,23 +1,19 @@
use satrs::{ use satrs::{
pool::PoolProvider, pool::PoolProvider,
pus::{PacketAsVec, PacketInPool}, tmtc::{PacketAsVec, PacketInPool, PacketSenderWithSharedPool, SharedPacketPool},
tmtc::{PacketSenderWithSharedPool, SharedPacketPool},
}; };
use std::sync::mpsc::{self, TryRecvError}; use std::sync::mpsc::{self, TryRecvError};
use satrs::{ use satrs::pus::MpscTmAsVecSender;
pus::MpscTmAsVecSender,
spacepackets::ecss::{tc::PusTcReader, PusPacket},
};
use crate::pus::PusTcDistributor; use crate::pus::{HandlingStatus, PusTcDistributor};
// TC source components where static pools are the backing memory of the received telecommands. // TC source components where static pools are the backing memory of the received telecommands.
pub struct TcSourceTaskStatic { pub struct TcSourceTaskStatic {
shared_tc_pool: SharedPacketPool, shared_tc_pool: SharedPacketPool,
tc_receiver: mpsc::Receiver<PacketInPool>, tc_receiver: mpsc::Receiver<PacketInPool>,
tc_buf: [u8; 4096], tc_buf: [u8; 4096],
pus_receiver: PusTcDistributor<PacketSenderWithSharedPool>, pus_distributor: PusTcDistributor<PacketSenderWithSharedPool>,
} }
impl TcSourceTaskStatic { impl TcSourceTaskStatic {
@ -30,7 +26,7 @@ impl TcSourceTaskStatic {
shared_tc_pool, shared_tc_pool,
tc_receiver, tc_receiver,
tc_buf: [0; 4096], tc_buf: [0; 4096],
pus_receiver, pus_distributor: pus_receiver,
} }
} }
@ -38,7 +34,9 @@ impl TcSourceTaskStatic {
self.poll_tc(); self.poll_tc();
} }
pub fn poll_tc(&mut self) -> bool { pub fn poll_tc(&mut self) -> HandlingStatus {
// Right now, we only expect ECSS PUS packets.
// If packets like CFDP are expected, we might have to check the APID first.
match self.tc_receiver.try_recv() { match self.tc_receiver.try_recv() {
Ok(packet_in_pool) => { Ok(packet_in_pool) => {
let pool = self let pool = self
@ -49,29 +47,16 @@ impl TcSourceTaskStatic {
pool.read(&packet_in_pool.store_addr, &mut self.tc_buf) pool.read(&packet_in_pool.store_addr, &mut self.tc_buf)
.expect("reading pool failed"); .expect("reading pool failed");
drop(pool); drop(pool);
match PusTcReader::new(&self.tc_buf) { self.pus_distributor
Ok((pus_tc, _)) => { .handle_tc_packet_in_store(packet_in_pool, &self.tc_buf)
self.pus_receiver .ok();
.handle_tc_packet( HandlingStatus::HandledOne
satrs::pus::TcInMemory::StoreAddr(packet_in_pool.store_addr),
pus_tc.service(),
&pus_tc,
)
.ok();
true
}
Err(e) => {
log::warn!("error creating PUS TC from raw data: {e}");
log::warn!("raw data: {:x?}", self.tc_buf);
true
}
}
} }
Err(e) => match e { Err(e) => match e {
TryRecvError::Empty => false, TryRecvError::Empty => HandlingStatus::Empty,
TryRecvError::Disconnected => { TryRecvError::Disconnected => {
log::warn!("tmtc thread: sender disconnected"); log::warn!("tmtc thread: sender disconnected");
false HandlingStatus::Empty
} }
}, },
} }
@ -81,7 +66,7 @@ impl TcSourceTaskStatic {
// TC source components where the heap is the backing memory of the received telecommands. // TC source components where the heap is the backing memory of the received telecommands.
pub struct TcSourceTaskDynamic { pub struct TcSourceTaskDynamic {
pub tc_receiver: mpsc::Receiver<PacketAsVec>, pub tc_receiver: mpsc::Receiver<PacketAsVec>,
pus_receiver: PusTcDistributor<MpscTmAsVecSender>, pus_distributor: PusTcDistributor<MpscTmAsVecSender>,
} }
impl TcSourceTaskDynamic { impl TcSourceTaskDynamic {
@ -91,7 +76,7 @@ impl TcSourceTaskDynamic {
) -> Self { ) -> Self {
Self { Self {
tc_receiver, tc_receiver,
pus_receiver, pus_distributor: pus_receiver,
} }
} }
@ -99,31 +84,21 @@ impl TcSourceTaskDynamic {
self.poll_tc(); self.poll_tc();
} }
pub fn poll_tc(&mut self) -> bool { pub fn poll_tc(&mut self) -> HandlingStatus {
// Right now, we only expect PUS packets. // Right now, we only expect ECSS PUS packets.
// If packets like CFDP are expected, we might have to check the APID first.
match self.tc_receiver.try_recv() { match self.tc_receiver.try_recv() {
Ok(packet_as_vec) => match PusTcReader::new(&packet_as_vec.packet) { Ok(packet_as_vec) => {
Ok((pus_tc, _)) => { self.pus_distributor
self.pus_receiver .handle_tc_packet_vec(packet_as_vec)
.handle_tc_packet( .ok();
satrs::pus::TcInMemory::Vec(packet_as_vec.packet.clone()), HandlingStatus::HandledOne
pus_tc.service(), }
&pus_tc,
)
.ok();
true
}
Err(e) => {
log::warn!("error creating PUS TC from raw data: {e}");
log::warn!("raw data: {:x?}", packet_as_vec.packet);
true
}
},
Err(e) => match e { Err(e) => match e {
TryRecvError::Empty => false, TryRecvError::Empty => HandlingStatus::Empty,
TryRecvError::Disconnected => { TryRecvError::Disconnected => {
log::warn!("tmtc thread: sender disconnected"); log::warn!("tmtc thread: sender disconnected");
false HandlingStatus::Empty
} }
}, },
} }

View File

@ -4,6 +4,7 @@ use std::{
}; };
use log::info; use log::info;
use satrs::tmtc::{PacketAsVec, PacketInPool, SharedPacketPool};
use satrs::{ use satrs::{
pool::PoolProvider, pool::PoolProvider,
seq_count::{CcsdsSimpleSeqCountProvider, SequenceCountProviderCore}, seq_count::{CcsdsSimpleSeqCountProvider, SequenceCountProviderCore},
@ -13,10 +14,6 @@ use satrs::{
CcsdsPacket, CcsdsPacket,
}, },
}; };
use satrs::{
pus::{PacketAsVec, PacketInPool},
tmtc::SharedPacketPool,
};
use crate::interface::tcp::SyncTcpTmSource; use crate::interface::tcp::SyncTcpTmSource;

View File

@ -10,7 +10,7 @@ pub(crate) mod tests {
use alloc::collections::VecDeque; use alloc::collections::VecDeque;
use crate::{pus::PacketAsVec, tmtc::PacketSenderRaw, ComponentId}; use crate::{tmtc::{PacketAsVec, PacketSenderRaw}, ComponentId};
use super::cobs::encode_packet_with_cobs; use super::cobs::encode_packet_with_cobs;

View File

@ -206,14 +206,10 @@ mod tests {
}; };
use crate::{ use crate::{
encoding::tests::{INVERTED_PACKET, SIMPLE_PACKET}, encoding::tests::{INVERTED_PACKET, SIMPLE_PACKET}, hal::std::tcp_server::{
hal::std::tcp_server::{
tests::{ConnectionFinishedHandler, SyncTmSource}, tests::{ConnectionFinishedHandler, SyncTmSource},
ConnectionResult, ServerConfig, ConnectionResult, ServerConfig,
}, }, queue::GenericSendError, tmtc::PacketAsVec, ComponentId
pus::PacketAsVec,
queue::GenericSendError,
ComponentId,
}; };
use alloc::sync::Arc; use alloc::sync::Arc;
use cobs::encode; use cobs::encode;

View File

@ -204,10 +204,7 @@ mod tests {
hal::std::tcp_server::{ hal::std::tcp_server::{
tests::{ConnectionFinishedHandler, SyncTmSource}, tests::{ConnectionFinishedHandler, SyncTmSource},
ConnectionResult, ServerConfig, ConnectionResult, ServerConfig,
}, }, queue::GenericSendError, tmtc::PacketAsVec, ComponentId
pus::PacketAsVec,
queue::GenericSendError,
ComponentId,
}; };
use super::TcpSpacepacketsServer; use super::TcpSpacepacketsServer;

View File

@ -257,8 +257,7 @@ pub mod alloc_mod {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::events::SeverityInfo; use crate::{events::SeverityInfo, tmtc::PacketAsVec};
use crate::pus::PacketAsVec;
use crate::request::UniqueApidTargetId; use crate::request::UniqueApidTargetId;
use std::sync::mpsc::{self, TryRecvError}; use std::sync::mpsc::{self, TryRecvError};

View File

@ -660,7 +660,7 @@ pub mod std_mod {
EcssTcAndToken, EcssTcReceiver, EcssTmSender, EcssTmtcError, GenericReceiveError, EcssTcAndToken, EcssTcReceiver, EcssTmSender, EcssTmtcError, GenericReceiveError,
GenericSendError, PusTmVariant, TryRecvTmtcError, GenericSendError, PusTmVariant, TryRecvTmtcError,
}; };
use crate::tmtc::PacketSenderWithSharedPool; use crate::tmtc::{PacketAsVec, PacketSenderWithSharedPool};
use crate::ComponentId; use crate::ComponentId;
use alloc::vec::Vec; use alloc::vec::Vec;
use core::time::Duration; use core::time::Duration;
@ -678,21 +678,7 @@ pub mod std_mod {
use super::verification::{TcStateToken, VerificationReportingProvider}; use super::verification::{TcStateToken, VerificationReportingProvider};
use super::{AcceptedEcssTcAndToken, ActiveRequestProvider, TcInMemory}; use super::{AcceptedEcssTcAndToken, ActiveRequestProvider, TcInMemory};
use crate::tmtc::PacketInPool;
#[derive(Debug)]
pub struct PacketInPool {
pub sender_id: ComponentId,
pub store_addr: StoreAddr,
}
impl PacketInPool {
pub fn new(sender_id: ComponentId, store_addr: StoreAddr) -> Self {
Self {
sender_id,
store_addr,
}
}
}
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 {
@ -730,18 +716,6 @@ pub mod std_mod {
} }
} }
#[derive(Debug)]
pub struct PacketAsVec {
pub sender_id: ComponentId,
pub packet: Vec<u8>,
}
impl PacketAsVec {
pub fn new(sender_id: ComponentId, packet: Vec<u8>) -> Self {
Self { sender_id, packet }
}
}
pub type MpscTmAsVecSender = mpsc::Sender<PacketAsVec>; pub type MpscTmAsVecSender = mpsc::Sender<PacketAsVec>;
impl EcssTmSender for MpscTmAsVecSender { impl EcssTmSender for MpscTmAsVecSender {
@ -1280,7 +1254,7 @@ pub mod tests {
use crate::pool::{PoolProvider, SharedStaticMemoryPool, StaticMemoryPool, StaticPoolConfig}; use crate::pool::{PoolProvider, SharedStaticMemoryPool, StaticMemoryPool, StaticPoolConfig};
use crate::pus::verification::{RequestId, VerificationReporter}; use crate::pus::verification::{RequestId, VerificationReporter};
use crate::tmtc::{PacketSenderWithSharedPool, SharedPacketPool}; use crate::tmtc::{PacketAsVec, PacketInPool, PacketSenderWithSharedPool, SharedPacketPool};
use crate::ComponentId; use crate::ComponentId;
use super::test_util::{TEST_APID, TEST_COMPONENT_ID_0}; use super::test_util::{TEST_APID, TEST_COMPONENT_ID_0};

View File

@ -2,11 +2,11 @@ use super::scheduler::PusSchedulerProvider;
use super::verification::{VerificationReporter, VerificationReportingProvider}; use super::verification::{VerificationReporter, VerificationReportingProvider};
use super::{ use super::{
EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, EcssTcReceiver, EcssTcInMemConverter, EcssTcInSharedStoreConverter, EcssTcInVecConverter, EcssTcReceiver,
EcssTmSender, MpscTcReceiver, PacketAsVec, PusServiceHelper, EcssTmSender, MpscTcReceiver, PusServiceHelper,
}; };
use crate::pool::PoolProvider; use crate::pool::PoolProvider;
use crate::pus::{PusPacketHandlerResult, PusPacketHandlingError}; use crate::pus::{PusPacketHandlerResult, PusPacketHandlingError};
use crate::tmtc::PacketSenderWithSharedPool; use crate::tmtc::{PacketAsVec, PacketSenderWithSharedPool};
use alloc::string::ToString; use alloc::string::ToString;
use spacepackets::ecss::{scheduling, PusPacket}; use spacepackets::ecss::{scheduling, PusPacket};
use spacepackets::time::cds::CdsTime; use spacepackets::time::cds::CdsTime;

View File

@ -1,8 +1,7 @@
use crate::pus::{ use crate::pus::{
PacketAsVec, PartialPusHandlingError, PusPacketHandlerResult, PusPacketHandlingError, PartialPusHandlingError, PusPacketHandlerResult, PusPacketHandlingError, PusTmVariant,
PusTmVariant,
}; };
use crate::tmtc::PacketSenderWithSharedPool; use crate::tmtc::{PacketAsVec, PacketSenderWithSharedPool};
use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader}; use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader};
use spacepackets::ecss::PusPacket; use spacepackets::ecss::PusPacket;
use spacepackets::SpHeader; use spacepackets::SpHeader;

View File

@ -11,9 +11,10 @@
use crate::queue::GenericSendError; use crate::queue::GenericSendError;
use crate::{ use crate::{
pool::{PoolProvider, StoreAddr, StoreError}, pool::{PoolProvider, StoreAddr, StoreError},
pus::PacketAsVec,
ComponentId, ComponentId,
}; };
#[cfg(feature = "std")]
pub use alloc_mod::*;
use core::cell::RefCell; use core::cell::RefCell;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use downcast_rs::{impl_downcast, Downcast}; use downcast_rs::{impl_downcast, Downcast};
@ -32,6 +33,21 @@ pub use std_mod::*;
pub mod tm_helper; pub mod tm_helper;
#[derive(Debug)]
pub struct PacketInPool {
pub sender_id: ComponentId,
pub store_addr: StoreAddr,
}
impl PacketInPool {
pub fn new(sender_id: ComponentId, store_addr: StoreAddr) -> Self {
Self {
sender_id,
store_addr,
}
}
}
/// Generic trait for object which can send any packets in form of a raw bytestream, with /// Generic trait for object which can send any packets in form of a raw bytestream, with
/// no assumptions about the received protocol. /// no assumptions about the received protocol.
pub trait PacketSenderRaw: Send { pub trait PacketSenderRaw: Send {
@ -39,29 +55,6 @@ pub trait PacketSenderRaw: Send {
fn send_packet(&self, sender_id: ComponentId, packet: &[u8]) -> Result<(), Self::Error>; fn send_packet(&self, sender_id: ComponentId, packet: &[u8]) -> Result<(), Self::Error>;
} }
#[cfg(feature = "std")]
impl PacketSenderRaw for mpsc::Sender<PacketAsVec> {
type Error = GenericSendError;
fn send_packet(&self, sender_id: ComponentId, packet: &[u8]) -> Result<(), Self::Error> {
self.send(PacketAsVec::new(sender_id, packet.to_vec()))
.map_err(|_| GenericSendError::RxDisconnected)
}
}
#[cfg(feature = "std")]
impl PacketSenderRaw for mpsc::SyncSender<PacketAsVec> {
type Error = GenericSendError;
fn send_packet(&self, sender_id: ComponentId, tc_raw: &[u8]) -> Result<(), Self::Error> {
self.try_send(PacketAsVec::new(sender_id, tc_raw.to_vec()))
.map_err(|e| match e {
mpsc::TrySendError::Full(_) => GenericSendError::QueueFull(None),
mpsc::TrySendError::Disconnected(_) => GenericSendError::RxDisconnected,
})
}
}
/// Extension trait of [PacketSenderRaw] which allows downcasting by implementing [Downcast]. /// Extension trait of [PacketSenderRaw] which allows downcasting by implementing [Downcast].
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
pub trait PacketSenderRawExt: PacketSenderRaw + Downcast { pub trait PacketSenderRawExt: PacketSenderRaw + Downcast {
@ -257,6 +250,24 @@ pub trait PacketInPoolSender: Send {
) -> Result<(), GenericSendError>; ) -> Result<(), GenericSendError>;
} }
#[cfg(feature = "alloc")]
pub mod alloc_mod {
use alloc::vec::Vec;
use super::*;
#[derive(Debug)]
pub struct PacketAsVec {
pub sender_id: ComponentId,
pub packet: Vec<u8>,
}
impl PacketAsVec {
pub fn new(sender_id: ComponentId, packet: Vec<u8>) -> Self {
Self { sender_id, packet }
}
}
}
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub mod std_mod { pub mod std_mod {
@ -264,10 +275,33 @@ pub mod std_mod {
use crossbeam_channel as cb; use crossbeam_channel as cb;
use thiserror::Error; use thiserror::Error;
use crate::pus::{EcssTmSender, EcssTmtcError, PacketInPool, PacketSenderPusTc}; use crate::pus::{EcssTmSender, EcssTmtcError, PacketSenderPusTc};
use super::*; use super::*;
#[cfg(feature = "std")]
impl PacketSenderRaw for mpsc::Sender<PacketAsVec> {
type Error = GenericSendError;
fn send_packet(&self, sender_id: ComponentId, packet: &[u8]) -> Result<(), Self::Error> {
self.send(PacketAsVec::new(sender_id, packet.to_vec()))
.map_err(|_| GenericSendError::RxDisconnected)
}
}
#[cfg(feature = "std")]
impl PacketSenderRaw for mpsc::SyncSender<PacketAsVec> {
type Error = GenericSendError;
fn send_packet(&self, sender_id: ComponentId, tc_raw: &[u8]) -> Result<(), Self::Error> {
self.try_send(PacketAsVec::new(sender_id, tc_raw.to_vec()))
.map_err(|e| match e {
mpsc::TrySendError::Full(_) => GenericSendError::QueueFull(None),
mpsc::TrySendError::Disconnected(_) => GenericSendError::RxDisconnected,
})
}
}
#[derive(Debug, Clone, PartialEq, Eq, Error)] #[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum StoreAndSendError { pub enum StoreAndSendError {
#[error("Store error: {0}")] #[error("Store error: {0}")]

View File

@ -7,8 +7,8 @@ use satrs::params::U32Pair;
use satrs::params::{Params, ParamsHeapless, WritableToBeBytes}; use satrs::params::{Params, ParamsHeapless, WritableToBeBytes};
use satrs::pus::event_man::{DefaultPusEventMgmtBackend, EventReporter, PusEventDispatcher}; use satrs::pus::event_man::{DefaultPusEventMgmtBackend, EventReporter, PusEventDispatcher};
use satrs::pus::test_util::TEST_COMPONENT_ID_0; use satrs::pus::test_util::TEST_COMPONENT_ID_0;
use satrs::pus::PacketAsVec;
use satrs::request::UniqueApidTargetId; use satrs::request::UniqueApidTargetId;
use satrs::tmtc::PacketAsVec;
use spacepackets::ecss::tm::PusTmReader; use spacepackets::ecss::tm::PusTmReader;
use spacepackets::ecss::{PusError, PusPacket}; use spacepackets::ecss::{PusError, PusPacket};
use std::sync::mpsc::{self, SendError, TryRecvError}; use std::sync::mpsc::{self, SendError, TryRecvError};