maybe this will work for bare metal code as well
This commit is contained in:
parent
74c3f78183
commit
b5d3b47056
@ -17,7 +17,7 @@
|
|||||||
//! use std::time::Duration;
|
//! use std::time::Duration;
|
||||||
//! use satrs_core::pool::{LocalPool, PoolCfg, PoolProvider, SharedPool};
|
//! use satrs_core::pool::{LocalPool, PoolCfg, PoolProvider, SharedPool};
|
||||||
//! use satrs_core::pus::verification::{MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender};
|
//! 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::ecss::PusPacket;
|
||||||
//! use spacepackets::SpHeader;
|
//! use spacepackets::SpHeader;
|
||||||
//! use spacepackets::tc::{PusTc, PusTcSecondaryHeader};
|
//! 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 shared_tm_pool: SharedPool = Arc::new(RwLock::new(Box::new(LocalPool::new(pool_cfg.clone()))));
|
||||||
//! let (verif_tx, verif_rx) = mpsc::channel();
|
//! let (verif_tx, verif_rx) = mpsc::channel();
|
||||||
//! let sender = MpscVerifSender::new(shared_tm_pool.clone(), verif_tx);
|
//! 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 reporter = VerificationReporterWithSender::new(&cfg , Box::new(sender));
|
||||||
//!
|
//!
|
||||||
//! let mut sph = SpHeader::tc_unseg(TEST_APID, 0, 0).unwrap();
|
//! 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::{CcsdsPacket, PacketId, PacketSequenceCtrl};
|
||||||
use spacepackets::{SpHeader, MAX_APID};
|
use spacepackets::{SpHeader, MAX_APID};
|
||||||
|
|
||||||
pub use crate::seq_count::SimpleSeqCountProvider;
|
pub use crate::seq_count::SeqCountProviderSimple;
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
pub use alloc_mod::{
|
pub use alloc_mod::{
|
||||||
@ -1158,7 +1158,7 @@ mod tests {
|
|||||||
TcStateNone, VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender,
|
TcStateNone, VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender,
|
||||||
VerificationToken,
|
VerificationToken,
|
||||||
};
|
};
|
||||||
use crate::seq_count::SimpleSeqCountProvider;
|
use crate::seq_count::SeqCountProviderSimple;
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use alloc::format;
|
use alloc::format;
|
||||||
use spacepackets::ecss::{EcssEnumU16, EcssEnumU32, EcssEnumU8, EcssEnumeration, PusPacket};
|
use spacepackets::ecss::{EcssEnumU16, EcssEnumU32, EcssEnumU8, EcssEnumeration, PusPacket};
|
||||||
@ -1252,7 +1252,7 @@ mod tests {
|
|||||||
fn base_reporter() -> VerificationReporter {
|
fn base_reporter() -> VerificationReporter {
|
||||||
let cfg = VerificationReporterCfg::new(
|
let cfg = VerificationReporterCfg::new(
|
||||||
TEST_APID,
|
TEST_APID,
|
||||||
Box::new(SimpleSeqCountProvider::default()),
|
Box::new(SeqCountProviderSimple::default()),
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
8,
|
8,
|
||||||
|
@ -24,11 +24,11 @@ dyn_clone::clone_trait_object!(SequenceCountProvider<u16>);
|
|||||||
impl<T, Raw> SequenceCountProvider<Raw> for T where T: SequenceCountProviderCore<Raw> + Clone {}
|
impl<T, Raw> SequenceCountProvider<Raw> for T where T: SequenceCountProviderCore<Raw> + Clone {}
|
||||||
|
|
||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone)]
|
||||||
pub struct SimpleSeqCountProvider {
|
pub struct SeqCountProviderSimple {
|
||||||
seq_count: u16,
|
seq_count: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SequenceCountProviderCore<u16> for SimpleSeqCountProvider {
|
impl SequenceCountProviderCore<u16> for SeqCountProviderSimple {
|
||||||
fn get(&self) -> u16 {
|
fn get(&self) -> u16 {
|
||||||
self.seq_count
|
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")]
|
#[cfg(feature = "std")]
|
||||||
pub mod stdmod {
|
pub mod stdmod {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::sync::atomic::{AtomicU16, Ordering};
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct SyncSeqCountProvider {
|
pub struct SeqCountProviderSync {
|
||||||
seq_count: Arc<AtomicU16>,
|
seq_count: Arc<AtomicU16>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SequenceCountProviderCore<u16> for SyncSeqCountProvider {
|
impl SequenceCountProviderCore<u16> for SeqCountProviderSync {
|
||||||
fn get(&self) -> u16 {
|
fn get(&self) -> u16 {
|
||||||
self.seq_count.load(Ordering::SeqCst)
|
self.seq_count.load(Ordering::SeqCst)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ pub mod crossbeam_test {
|
|||||||
CrossbeamVerifSender, FailParams, RequestId, VerificationReporterCfg,
|
CrossbeamVerifSender, FailParams, RequestId, VerificationReporterCfg,
|
||||||
VerificationReporterWithSender,
|
VerificationReporterWithSender,
|
||||||
};
|
};
|
||||||
use satrs_core::seq_count::SyncSeqCountProvider;
|
use satrs_core::seq_count::SeqCountProviderSync;
|
||||||
use spacepackets::ecss::{EcssEnumU16, EcssEnumU8, PusPacket};
|
use spacepackets::ecss::{EcssEnumU16, EcssEnumU8, PusPacket};
|
||||||
use spacepackets::tc::{PusTc, PusTcSecondaryHeader};
|
use spacepackets::tc::{PusTc, PusTcSecondaryHeader};
|
||||||
use spacepackets::tm::PusTm;
|
use spacepackets::tm::PusTm;
|
||||||
@ -34,7 +34,7 @@ pub mod crossbeam_test {
|
|||||||
// each reporter have an own sequence count provider.
|
// each reporter have an own sequence count provider.
|
||||||
let cfg = VerificationReporterCfg::new(
|
let cfg = VerificationReporterCfg::new(
|
||||||
TEST_APID,
|
TEST_APID,
|
||||||
Box::new(SyncSeqCountProvider::default()),
|
Box::new(SeqCountProviderSync::default()),
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
8,
|
8,
|
||||||
|
@ -23,7 +23,7 @@ use satrs_core::pus::verification::{
|
|||||||
MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender,
|
MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender,
|
||||||
};
|
};
|
||||||
use satrs_core::pus::{EcssTmError, EcssTmSenderCore};
|
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 satrs_example::{RequestTargetId, OBSW_SERVER_ADDR, SERVER_PORT};
|
||||||
use spacepackets::time::cds::TimeProvider;
|
use spacepackets::time::cds::TimeProvider;
|
||||||
use spacepackets::time::TimeWriter;
|
use spacepackets::time::TimeWriter;
|
||||||
@ -93,7 +93,7 @@ fn main() {
|
|||||||
let verif_cfg = VerificationReporterCfg::new(
|
let verif_cfg = VerificationReporterCfg::new(
|
||||||
PUS_APID,
|
PUS_APID,
|
||||||
#[allow(clippy::box_default)]
|
#[allow(clippy::box_default)]
|
||||||
Box::new(SimpleSeqCountProvider::default()),
|
Box::new(SeqCountProviderSimple::default()),
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
8,
|
8,
|
||||||
|
Loading…
Reference in New Issue
Block a user