maybe this will work for bare metal code as well

This commit is contained in:
Robin Müller 2023-01-03 16:35:23 +01:00
parent 74c3f78183
commit b5d3b47056
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
4 changed files with 40 additions and 14 deletions

View File

@ -17,7 +17,7 @@
//! use std::time::Duration;
//! use satrs_core::pool::{LocalPool, PoolCfg, PoolProvider, SharedPool};
//! use satrs_core::pus::verification::{MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender};
//! use satrs_core::seq_count::SimpleSeqCountProvider;
//! use satrs_core::seq_count::SeqCountProviderSimple;
//! use spacepackets::ecss::PusPacket;
//! use spacepackets::SpHeader;
//! use spacepackets::tc::{PusTc, PusTcSecondaryHeader};
@ -30,7 +30,7 @@
//! let shared_tm_pool: SharedPool = Arc::new(RwLock::new(Box::new(LocalPool::new(pool_cfg.clone()))));
//! let (verif_tx, verif_rx) = mpsc::channel();
//! let sender = MpscVerifSender::new(shared_tm_pool.clone(), verif_tx);
//! let cfg = VerificationReporterCfg::new(TEST_APID, Box::new(SimpleSeqCountProvider::default()), 1, 2, 8).unwrap();
//! let cfg = VerificationReporterCfg::new(TEST_APID, Box::new(SeqCountProviderSimple::default()), 1, 2, 8).unwrap();
//! let mut reporter = VerificationReporterWithSender::new(&cfg , Box::new(sender));
//!
//! let mut sph = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
@ -87,7 +87,7 @@ use spacepackets::tm::{PusTm, PusTmSecondaryHeader};
use spacepackets::{CcsdsPacket, PacketId, PacketSequenceCtrl};
use spacepackets::{SpHeader, MAX_APID};
pub use crate::seq_count::SimpleSeqCountProvider;
pub use crate::seq_count::SeqCountProviderSimple;
#[cfg(feature = "alloc")]
pub use alloc_mod::{
@ -1158,7 +1158,7 @@ mod tests {
TcStateNone, VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender,
VerificationToken,
};
use crate::seq_count::SimpleSeqCountProvider;
use crate::seq_count::SeqCountProviderSimple;
use alloc::boxed::Box;
use alloc::format;
use spacepackets::ecss::{EcssEnumU16, EcssEnumU32, EcssEnumU8, EcssEnumeration, PusPacket};
@ -1252,7 +1252,7 @@ mod tests {
fn base_reporter() -> VerificationReporter {
let cfg = VerificationReporterCfg::new(
TEST_APID,
Box::new(SimpleSeqCountProvider::default()),
Box::new(SeqCountProviderSimple::default()),
1,
2,
8,

View File

@ -24,11 +24,11 @@ dyn_clone::clone_trait_object!(SequenceCountProvider<u16>);
impl<T, Raw> SequenceCountProvider<Raw> for T where T: SequenceCountProviderCore<Raw> + Clone {}
#[derive(Default, Clone)]
pub struct SimpleSeqCountProvider {
pub struct SeqCountProviderSimple {
seq_count: u16,
}
impl SequenceCountProviderCore<u16> for SimpleSeqCountProvider {
impl SequenceCountProviderCore<u16> for SeqCountProviderSimple {
fn get(&self) -> u16 {
self.seq_count
}
@ -42,18 +42,44 @@ impl SequenceCountProviderCore<u16> for SimpleSeqCountProvider {
}
}
use core::sync::atomic::{AtomicU16, Ordering};
pub struct SeqCountProviderAtomicRef {
atomic: &'static AtomicU16,
ordering: Ordering,
}
impl SeqCountProviderAtomicRef {
pub const fn new(atomic: &'static AtomicU16, ordering: Ordering) -> Self {
Self { atomic, ordering }
}
}
impl SequenceCountProviderCore<u16> for SeqCountProviderAtomicRef {
fn get(&self) -> u16 {
self.atomic.load(self.ordering)
}
fn increment(&mut self) {
self.atomic.fetch_add(1, self.ordering);
}
fn get_and_increment(&mut self) -> u16 {
self.atomic.fetch_add(1, self.ordering)
}
}
#[cfg(feature = "std")]
pub mod stdmod {
use super::*;
use std::sync::atomic::{AtomicU16, Ordering};
use std::sync::Arc;
#[derive(Clone, Default)]
pub struct SyncSeqCountProvider {
pub struct SeqCountProviderSync {
seq_count: Arc<AtomicU16>,
}
impl SequenceCountProviderCore<u16> for SyncSeqCountProvider {
impl SequenceCountProviderCore<u16> for SeqCountProviderSync {
fn get(&self) -> u16 {
self.seq_count.load(Ordering::SeqCst)
}

View File

@ -7,7 +7,7 @@ pub mod crossbeam_test {
CrossbeamVerifSender, FailParams, RequestId, VerificationReporterCfg,
VerificationReporterWithSender,
};
use satrs_core::seq_count::SyncSeqCountProvider;
use satrs_core::seq_count::SeqCountProviderSync;
use spacepackets::ecss::{EcssEnumU16, EcssEnumU8, PusPacket};
use spacepackets::tc::{PusTc, PusTcSecondaryHeader};
use spacepackets::tm::PusTm;
@ -34,7 +34,7 @@ pub mod crossbeam_test {
// each reporter have an own sequence count provider.
let cfg = VerificationReporterCfg::new(
TEST_APID,
Box::new(SyncSeqCountProvider::default()),
Box::new(SeqCountProviderSync::default()),
1,
2,
8,

View File

@ -23,7 +23,7 @@ use satrs_core::pus::verification::{
MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender,
};
use satrs_core::pus::{EcssTmError, EcssTmSenderCore};
use satrs_core::seq_count::SimpleSeqCountProvider;
use satrs_core::seq_count::SeqCountProviderSimple;
use satrs_example::{RequestTargetId, OBSW_SERVER_ADDR, SERVER_PORT};
use spacepackets::time::cds::TimeProvider;
use spacepackets::time::TimeWriter;
@ -93,7 +93,7 @@ fn main() {
let verif_cfg = VerificationReporterCfg::new(
PUS_APID,
#[allow(clippy::box_default)]
Box::new(SimpleSeqCountProvider::default()),
Box::new(SeqCountProviderSimple::default()),
1,
2,
8,