Improvements for example and documentation
All checks were successful
Rust/sat-rs/pipeline/pr-main This commit looks good
All checks were successful
Rust/sat-rs/pipeline/pr-main This commit looks good
- Added diagrams for sat-rs example for both structure and data flow. - Added explanations for those diagrams as well. - Some renaming: Use `Pool` instead of `Store` for pool components. - General improvements for satrs-book.
This commit is contained in:
@ -399,7 +399,7 @@ pub mod std_mod {
|
||||
EcssTmSenderCore, EcssTmtcError, GenericRecvError, GenericSendError, PusTmWrapper,
|
||||
TryRecvTmtcError,
|
||||
};
|
||||
use crate::tmtc::tm_helper::SharedTmStore;
|
||||
use crate::tmtc::tm_helper::SharedTmPool;
|
||||
use crate::ChannelId;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::vec::Vec;
|
||||
@ -441,14 +441,14 @@ pub mod std_mod {
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct MpscTmInStoreSender {
|
||||
pub struct MpscTmInSharedPoolSender {
|
||||
id: ChannelId,
|
||||
name: &'static str,
|
||||
shared_tm_store: SharedTmStore,
|
||||
shared_tm_store: SharedTmPool,
|
||||
sender: mpsc::Sender<StoreAddr>,
|
||||
}
|
||||
|
||||
impl EcssChannel for MpscTmInStoreSender {
|
||||
impl EcssChannel for MpscTmInSharedPoolSender {
|
||||
fn id(&self) -> ChannelId {
|
||||
self.id
|
||||
}
|
||||
@ -458,7 +458,7 @@ pub mod std_mod {
|
||||
}
|
||||
}
|
||||
|
||||
impl MpscTmInStoreSender {
|
||||
impl MpscTmInSharedPoolSender {
|
||||
pub fn send_direct_tm(&self, tm: PusTmCreator) -> Result<(), EcssTmtcError> {
|
||||
let addr = self.shared_tm_store.add_pus_tm(&tm)?;
|
||||
self.sender
|
||||
@ -467,7 +467,7 @@ pub mod std_mod {
|
||||
}
|
||||
}
|
||||
|
||||
impl EcssTmSenderCore for MpscTmInStoreSender {
|
||||
impl EcssTmSenderCore for MpscTmInSharedPoolSender {
|
||||
fn send_tm(&self, tm: PusTmWrapper) -> Result<(), EcssTmtcError> {
|
||||
match tm {
|
||||
PusTmWrapper::InStore(addr) => {
|
||||
@ -479,11 +479,11 @@ pub mod std_mod {
|
||||
}
|
||||
}
|
||||
|
||||
impl MpscTmInStoreSender {
|
||||
impl MpscTmInSharedPoolSender {
|
||||
pub fn new(
|
||||
id: ChannelId,
|
||||
name: &'static str,
|
||||
shared_tm_store: SharedTmStore,
|
||||
shared_tm_store: SharedTmPool,
|
||||
sender: mpsc::Sender<StoreAddr>,
|
||||
) -> Self {
|
||||
Self {
|
||||
@ -582,7 +582,7 @@ pub mod std_mod {
|
||||
pub struct CrossbeamTmInStoreSender {
|
||||
id: ChannelId,
|
||||
name: &'static str,
|
||||
shared_tm_store: SharedTmStore,
|
||||
shared_tm_store: SharedTmPool,
|
||||
sender: crossbeam_channel::Sender<StoreAddr>,
|
||||
}
|
||||
|
||||
@ -590,7 +590,7 @@ pub mod std_mod {
|
||||
pub fn new(
|
||||
id: ChannelId,
|
||||
name: &'static str,
|
||||
shared_tm_store: SharedTmStore,
|
||||
shared_tm_store: SharedTmPool,
|
||||
sender: crossbeam_channel::Sender<StoreAddr>,
|
||||
) -> Self {
|
||||
Self {
|
||||
@ -951,15 +951,15 @@ pub mod tests {
|
||||
StoreAddr,
|
||||
};
|
||||
use crate::pus::verification::RequestId;
|
||||
use crate::tmtc::tm_helper::SharedTmStore;
|
||||
use crate::tmtc::tm_helper::SharedTmPool;
|
||||
|
||||
use super::verification::{
|
||||
TcStateAccepted, VerificationReporterCfg, VerificationReporterWithSender, VerificationToken,
|
||||
};
|
||||
use super::{
|
||||
EcssTcAndToken, EcssTcInSharedStoreConverter, EcssTcInVecConverter, MpscTcReceiver,
|
||||
MpscTmAsVecSender, MpscTmInStoreSender, PusPacketHandlerResult, PusPacketHandlingError,
|
||||
PusServiceHelper, TcInMemory,
|
||||
MpscTmAsVecSender, MpscTmInSharedPoolSender, PusPacketHandlerResult,
|
||||
PusPacketHandlingError, PusServiceHelper, TcInMemory,
|
||||
};
|
||||
|
||||
pub const TEST_APID: u16 = 0x101;
|
||||
@ -1003,7 +1003,7 @@ pub mod tests {
|
||||
pus_buf: [u8; 2048],
|
||||
tm_buf: [u8; 2048],
|
||||
tc_pool: SharedStaticMemoryPool,
|
||||
tm_pool: SharedTmStore,
|
||||
tm_pool: SharedTmPool,
|
||||
tc_sender: mpsc::Sender<EcssTcAndToken>,
|
||||
tm_receiver: mpsc::Receiver<StoreAddr>,
|
||||
verification_handler: VerificationReporterWithSender,
|
||||
@ -1019,17 +1019,21 @@ pub mod tests {
|
||||
let tc_pool = StaticMemoryPool::new(pool_cfg.clone());
|
||||
let tm_pool = StaticMemoryPool::new(pool_cfg);
|
||||
let shared_tc_pool = SharedStaticMemoryPool::new(RwLock::new(tc_pool));
|
||||
let shared_tm_pool = SharedTmStore::new(tm_pool);
|
||||
let shared_tm_pool = SharedTmPool::new(tm_pool);
|
||||
let (test_srv_tc_tx, test_srv_tc_rx) = mpsc::channel();
|
||||
let (tm_tx, tm_rx) = mpsc::channel();
|
||||
|
||||
let verif_sender =
|
||||
MpscTmInStoreSender::new(0, "verif_sender", shared_tm_pool.clone(), tm_tx.clone());
|
||||
let verif_sender = MpscTmInSharedPoolSender::new(
|
||||
0,
|
||||
"verif_sender",
|
||||
shared_tm_pool.clone(),
|
||||
tm_tx.clone(),
|
||||
);
|
||||
let verif_cfg = VerificationReporterCfg::new(TEST_APID, 1, 2, 8).unwrap();
|
||||
let verification_handler =
|
||||
VerificationReporterWithSender::new(&verif_cfg, Box::new(verif_sender));
|
||||
let test_srv_tm_sender =
|
||||
MpscTmInStoreSender::new(0, "TEST_SENDER", shared_tm_pool.clone(), tm_tx);
|
||||
MpscTmInSharedPoolSender::new(0, "TEST_SENDER", shared_tm_pool.clone(), tm_tx);
|
||||
let test_srv_tc_receiver = MpscTcReceiver::new(0, "TEST_RECEIVER", test_srv_tc_rx);
|
||||
let in_store_converter =
|
||||
EcssTcInSharedStoreConverter::new(shared_tc_pool.clone(), 2048);
|
||||
@ -1073,7 +1077,7 @@ pub mod tests {
|
||||
let next_msg = self.tm_receiver.try_recv();
|
||||
assert!(next_msg.is_ok());
|
||||
let tm_addr = next_msg.unwrap();
|
||||
let tm_pool = self.tm_pool.shared_pool.read().unwrap();
|
||||
let tm_pool = self.tm_pool.0.read().unwrap();
|
||||
let tm_raw = tm_pool.read(&tm_addr).unwrap();
|
||||
self.tm_buf[0..tm_raw.len()].copy_from_slice(tm_raw);
|
||||
PusTmReader::new(&self.tm_buf, 7).unwrap().0
|
||||
@ -1091,7 +1095,7 @@ pub mod tests {
|
||||
let next_msg = self.tm_receiver.try_recv();
|
||||
assert!(next_msg.is_ok());
|
||||
let tm_addr = next_msg.unwrap();
|
||||
let tm_pool = self.tm_pool.shared_pool.read().unwrap();
|
||||
let tm_pool = self.tm_pool.0.read().unwrap();
|
||||
let tm_raw = tm_pool.read(&tm_addr).unwrap();
|
||||
let tm = PusTmReader::new(tm_raw, 7).unwrap().0;
|
||||
assert_eq!(PusPacket::service(&tm), 1);
|
||||
|
@ -18,8 +18,8 @@
|
||||
//! use satrs_core::pool::{PoolProviderMemInPlaceWithGuards, StaticMemoryPool, StaticPoolConfig};
|
||||
//! use satrs_core::pus::verification::{VerificationReporterCfg, VerificationReporterWithSender};
|
||||
//! use satrs_core::seq_count::SeqCountProviderSimple;
|
||||
//! use satrs_core::pus::MpscTmInStoreSender;
|
||||
//! use satrs_core::tmtc::tm_helper::SharedTmStore;
|
||||
//! use satrs_core::pus::MpscTmInSharedPoolSender;
|
||||
//! use satrs_core::tmtc::tm_helper::SharedTmPool;
|
||||
//! use spacepackets::ecss::PusPacket;
|
||||
//! use spacepackets::SpHeader;
|
||||
//! use spacepackets::ecss::tc::{PusTcCreator, PusTcSecondaryHeader};
|
||||
@ -30,10 +30,10 @@
|
||||
//!
|
||||
//! let pool_cfg = StaticPoolConfig::new(vec![(10, 32), (10, 64), (10, 128), (10, 1024)]);
|
||||
//! let tm_pool = StaticMemoryPool::new(pool_cfg.clone());
|
||||
//! let shared_tm_store = SharedTmStore::new(tm_pool);
|
||||
//! let shared_tm_store = SharedTmPool::new(tm_pool);
|
||||
//! let tm_store = shared_tm_store.clone_backing_pool();
|
||||
//! let (verif_tx, verif_rx) = mpsc::channel();
|
||||
//! let sender = MpscTmInStoreSender::new(0, "Test Sender", shared_tm_store, verif_tx);
|
||||
//! let sender = MpscTmInSharedPoolSender::new(0, "Test Sender", shared_tm_store, verif_tx);
|
||||
//! let cfg = VerificationReporterCfg::new(TEST_APID, 1, 2, 8).unwrap();
|
||||
//! let mut reporter = VerificationReporterWithSender::new(&cfg , Box::new(sender));
|
||||
//!
|
||||
@ -1332,8 +1332,8 @@ mod tests {
|
||||
VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender,
|
||||
VerificationToken,
|
||||
};
|
||||
use crate::pus::{EcssChannel, MpscTmInStoreSender, PusTmWrapper};
|
||||
use crate::tmtc::tm_helper::SharedTmStore;
|
||||
use crate::pus::{EcssChannel, MpscTmInSharedPoolSender, PusTmWrapper};
|
||||
use crate::tmtc::tm_helper::SharedTmPool;
|
||||
use crate::ChannelId;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::format;
|
||||
@ -1487,9 +1487,10 @@ mod tests {
|
||||
#[test]
|
||||
fn test_mpsc_verif_send_sync() {
|
||||
let pool = StaticMemoryPool::new(StaticPoolConfig::new(vec![(8, 8)]));
|
||||
let shared_tm_store = SharedTmStore::new(pool);
|
||||
let shared_tm_store = SharedTmPool::new(pool);
|
||||
let (tx, _) = mpsc::channel();
|
||||
let mpsc_verif_sender = MpscTmInStoreSender::new(0, "verif_sender", shared_tm_store, tx);
|
||||
let mpsc_verif_sender =
|
||||
MpscTmInSharedPoolSender::new(0, "verif_sender", shared_tm_store, tx);
|
||||
is_send(&mpsc_verif_sender);
|
||||
}
|
||||
|
||||
@ -2142,10 +2143,11 @@ mod tests {
|
||||
fn test_seq_count_increment() {
|
||||
let pool_cfg = StaticPoolConfig::new(vec![(10, 32), (10, 64), (10, 128), (10, 1024)]);
|
||||
let tm_pool = StaticMemoryPool::new(pool_cfg.clone());
|
||||
let shared_tm_store = SharedTmStore::new(tm_pool);
|
||||
let shared_tm_store = SharedTmPool::new(tm_pool);
|
||||
let shared_tm_pool = shared_tm_store.clone_backing_pool();
|
||||
let (verif_tx, verif_rx) = mpsc::channel();
|
||||
let sender = MpscTmInStoreSender::new(0, "Verification Sender", shared_tm_store, verif_tx);
|
||||
let sender =
|
||||
MpscTmInSharedPoolSender::new(0, "Verification Sender", shared_tm_store, verif_tx);
|
||||
let cfg = VerificationReporterCfg::new(TEST_APID, 1, 2, 8).unwrap();
|
||||
let mut reporter = VerificationReporterWithSender::new(&cfg, Box::new(sender));
|
||||
|
||||
|
@ -17,26 +17,26 @@ pub mod std_mod {
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SharedTmStore {
|
||||
pub shared_pool: SharedStaticMemoryPool,
|
||||
}
|
||||
pub struct SharedTmPool(pub SharedStaticMemoryPool);
|
||||
|
||||
impl SharedTmStore {
|
||||
impl SharedTmPool {
|
||||
pub fn new(shared_pool: StaticMemoryPool) -> Self {
|
||||
Self {
|
||||
shared_pool: Arc::new(RwLock::new(shared_pool)),
|
||||
}
|
||||
Self(Arc::new(RwLock::new(shared_pool)))
|
||||
}
|
||||
|
||||
pub fn clone_backing_pool(&self) -> SharedStaticMemoryPool {
|
||||
self.shared_pool.clone()
|
||||
self.0.clone()
|
||||
}
|
||||
pub fn shared_pool(&self) -> &SharedStaticMemoryPool {
|
||||
&self.0
|
||||
}
|
||||
|
||||
pub fn shared_pool_mut(&mut self) -> &mut SharedStaticMemoryPool {
|
||||
&mut self.0
|
||||
}
|
||||
|
||||
pub fn add_pus_tm(&self, pus_tm: &PusTmCreator) -> Result<StoreAddr, EcssTmtcError> {
|
||||
let mut pg = self
|
||||
.shared_pool
|
||||
.write()
|
||||
.map_err(|_| EcssTmtcError::StoreLock)?;
|
||||
let mut pg = self.0.write().map_err(|_| EcssTmtcError::StoreLock)?;
|
||||
let (addr, buf) = pg.free_element(pus_tm.len_written())?;
|
||||
pus_tm
|
||||
.write_to_bytes(buf)
|
||||
|
@ -1,4 +1,4 @@
|
||||
#[cfg(feature = "crossbeam")]
|
||||
//#[cfg(feature = "crossbeam")]
|
||||
pub mod crossbeam_test {
|
||||
use hashbrown::HashMap;
|
||||
use satrs_core::pool::{
|
||||
@ -9,7 +9,7 @@ pub mod crossbeam_test {
|
||||
FailParams, RequestId, VerificationReporterCfg, VerificationReporterWithSender,
|
||||
};
|
||||
use satrs_core::pus::CrossbeamTmInStoreSender;
|
||||
use satrs_core::tmtc::tm_helper::SharedTmStore;
|
||||
use satrs_core::tmtc::tm_helper::SharedTmPool;
|
||||
use spacepackets::ecss::tc::{PusTcCreator, PusTcReader, PusTcSecondaryHeader};
|
||||
use spacepackets::ecss::tm::PusTmReader;
|
||||
use spacepackets::ecss::{EcssEnumU16, EcssEnumU8, PusPacket, WritablePusPacket};
|
||||
@ -37,12 +37,12 @@ pub mod crossbeam_test {
|
||||
let cfg = VerificationReporterCfg::new(TEST_APID, 1, 2, 8).unwrap();
|
||||
// Shared pool object to store the verification PUS telemetry
|
||||
let pool_cfg = StaticPoolConfig::new(vec![(10, 32), (10, 64), (10, 128), (10, 1024)]);
|
||||
let shared_tm_store = SharedTmStore::new(StaticMemoryPool::new(pool_cfg.clone()));
|
||||
let shared_tm_pool = SharedTmPool::new(StaticMemoryPool::new(pool_cfg.clone()));
|
||||
let shared_tc_pool_0 = Arc::new(RwLock::new(StaticMemoryPool::new(pool_cfg)));
|
||||
let shared_tc_pool_1 = shared_tc_pool_0.clone();
|
||||
let (tx, rx) = crossbeam_channel::bounded(10);
|
||||
let sender =
|
||||
CrossbeamTmInStoreSender::new(0, "verif_sender", shared_tm_store.clone(), tx.clone());
|
||||
CrossbeamTmInStoreSender::new(0, "verif_sender", shared_tm_pool.clone(), tx.clone());
|
||||
let mut reporter_with_sender_0 =
|
||||
VerificationReporterWithSender::new(&cfg, Box::new(sender));
|
||||
let mut reporter_with_sender_1 = reporter_with_sender_0.clone();
|
||||
@ -145,7 +145,7 @@ pub mod crossbeam_test {
|
||||
.recv_timeout(Duration::from_millis(50))
|
||||
.expect("Packet reception timeout");
|
||||
let tm_len;
|
||||
let shared_tm_store = shared_tm_store.clone_backing_pool();
|
||||
let shared_tm_store = shared_tm_pool.clone_backing_pool();
|
||||
{
|
||||
let mut rg = shared_tm_store.write().expect("Error locking shared pool");
|
||||
let store_guard = rg.read_with_guard(verif_addr);
|
||||
|
Reference in New Issue
Block a user