Larger update #49
@ -944,6 +944,8 @@ mod alloc_mod {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct VerificationReporter {
|
pub struct VerificationReporter {
|
||||||
source_data_buf: Vec<u8>,
|
source_data_buf: Vec<u8>,
|
||||||
|
//pub seq_count_provider: Option<Box<dyn >>
|
||||||
|
//pub msg_count_provider: Option<Box<dyn SequenceCountProvider<u16>>>,
|
||||||
pub reporter: VerificationReporterCore,
|
pub reporter: VerificationReporterCore,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ use core::cell::Cell;
|
|||||||
use core::sync::atomic::{AtomicU16, Ordering};
|
use core::sync::atomic::{AtomicU16, Ordering};
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
use dyn_clone::DynClone;
|
use dyn_clone::DynClone;
|
||||||
|
use paste::paste;
|
||||||
|
use spacepackets::MAX_SEQ_COUNT;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use stdmod::*;
|
pub use stdmod::*;
|
||||||
|
|
||||||
@ -15,21 +17,11 @@ pub trait SequenceCountProviderCore<Raw> {
|
|||||||
|
|
||||||
fn increment(&self);
|
fn increment(&self);
|
||||||
|
|
||||||
// TODO: Maybe remove this?
|
|
||||||
fn increment_mut(&mut self) {
|
|
||||||
self.increment();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_and_increment(&self) -> Raw {
|
fn get_and_increment(&self) -> Raw {
|
||||||
let val = self.get();
|
let val = self.get();
|
||||||
self.increment();
|
self.increment();
|
||||||
val
|
val
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Maybe remove this?
|
|
||||||
fn get_and_increment_mut(&mut self) -> Raw {
|
|
||||||
self.get_and_increment()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extension trait which allows cloning a sequence count provider after it was turned into
|
/// Extension trait which allows cloning a sequence count provider after it was turned into
|
||||||
@ -42,20 +34,33 @@ 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 SeqCountProviderSimple {
|
pub struct SeqCountProviderSimple<T: Copy> {
|
||||||
seq_count: Cell<u16>,
|
seq_count: Cell<T>,
|
||||||
|
max_val: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SeqCountProviderSimple {
|
macro_rules! impl_for_primitives {
|
||||||
pub fn new() -> Self {
|
($($ty: ident,)+) => {
|
||||||
|
$(
|
||||||
|
paste! {
|
||||||
|
impl SeqCountProviderSimple<$ty> {
|
||||||
|
pub fn [<new_ $ty _max_val>](max_val: $ty) -> Self {
|
||||||
Self {
|
Self {
|
||||||
seq_count: Cell::new(0),
|
seq_count: Cell::new(0),
|
||||||
|
max_val,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl SequenceCountProviderCore<u16> for SeqCountProviderSimple {
|
pub fn [<new_ $ty>]() -> Self {
|
||||||
fn get(&self) -> u16 {
|
Self {
|
||||||
|
seq_count: Cell::new(0),
|
||||||
|
max_val: $ty::MAX
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SequenceCountProviderCore<$ty> for SeqCountProviderSimple<$ty> {
|
||||||
|
fn get(&self) -> $ty {
|
||||||
self.seq_count.get()
|
self.seq_count.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,16 +68,51 @@ impl SequenceCountProviderCore<u16> for SeqCountProviderSimple {
|
|||||||
self.get_and_increment();
|
self.get_and_increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_and_increment(&self) -> u16 {
|
fn get_and_increment(&self) -> $ty {
|
||||||
let curr_count = self.seq_count.get();
|
let curr_count = self.seq_count.get();
|
||||||
|
|
||||||
if curr_count == u16::MAX {
|
if curr_count == self.max_val {
|
||||||
self.seq_count.set(0);
|
self.seq_count.set(0);
|
||||||
} else {
|
} else {
|
||||||
self.seq_count.set(curr_count + 1);
|
self.seq_count.set(curr_count + 1);
|
||||||
}
|
}
|
||||||
curr_count
|
curr_count
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl_for_primitives!(u8, u16, u32, u64,);
|
||||||
|
|
||||||
|
/// This is a sequence count provider which wraps around at [MAX_SEQ_COUNT].
|
||||||
|
pub struct CcsdsSimpleSeqCountProvider {
|
||||||
|
provider: SeqCountProviderSimple<u16>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CcsdsSimpleSeqCountProvider {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
provider: SeqCountProviderSimple::new_u16_max_val(MAX_SEQ_COUNT),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for CcsdsSimpleSeqCountProvider {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SequenceCountProviderCore<u16> for CcsdsSimpleSeqCountProvider {
|
||||||
|
delegate::delegate! {
|
||||||
|
to self.provider {
|
||||||
|
fn get(&self) -> u16;
|
||||||
|
fn increment(&self);
|
||||||
|
fn get_and_increment(&self) -> u16;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SeqCountProviderAtomicRef {
|
pub struct SeqCountProviderAtomicRef {
|
||||||
@ -127,3 +167,47 @@ pub mod stdmod {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::seq_count::{
|
||||||
|
CcsdsSimpleSeqCountProvider, SeqCountProviderSimple, SequenceCountProviderCore,
|
||||||
|
};
|
||||||
|
use spacepackets::MAX_SEQ_COUNT;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_u8_counter() {
|
||||||
|
let u8_counter = SeqCountProviderSimple::new_u8();
|
||||||
|
assert_eq!(u8_counter.get(), 0);
|
||||||
|
assert_eq!(u8_counter.get_and_increment(), 0);
|
||||||
|
assert_eq!(u8_counter.get_and_increment(), 1);
|
||||||
|
assert_eq!(u8_counter.get(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_u8_counter_overflow() {
|
||||||
|
let u8_counter = SeqCountProviderSimple::new_u8();
|
||||||
|
for _ in 0..256 {
|
||||||
|
u8_counter.increment();
|
||||||
|
}
|
||||||
|
assert_eq!(u8_counter.get(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_ccsds_counter() {
|
||||||
|
let ccsds_counter = CcsdsSimpleSeqCountProvider::default();
|
||||||
|
assert_eq!(ccsds_counter.get(), 0);
|
||||||
|
assert_eq!(ccsds_counter.get_and_increment(), 0);
|
||||||
|
assert_eq!(ccsds_counter.get_and_increment(), 1);
|
||||||
|
assert_eq!(ccsds_counter.get(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_ccsds_counter_overflow() {
|
||||||
|
let ccsds_counter = CcsdsSimpleSeqCountProvider::default();
|
||||||
|
for _ in 0..MAX_SEQ_COUNT + 1 {
|
||||||
|
ccsds_counter.increment();
|
||||||
|
}
|
||||||
|
assert_eq!(ccsds_counter.get(), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -36,7 +36,7 @@ use satrs_core::pus::verification::{
|
|||||||
MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender,
|
MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender,
|
||||||
};
|
};
|
||||||
use satrs_core::pus::MpscTmtcInStoreSender;
|
use satrs_core::pus::MpscTmtcInStoreSender;
|
||||||
use satrs_core::seq_count::{SeqCountProviderSimple, SequenceCountProviderCore};
|
use satrs_core::seq_count::{CcsdsSimpleSeqCountProvider, SequenceCountProviderCore};
|
||||||
use satrs_core::spacepackets::tm::PusTmZeroCopyWriter;
|
use satrs_core::spacepackets::tm::PusTmZeroCopyWriter;
|
||||||
use satrs_core::spacepackets::{
|
use satrs_core::spacepackets::{
|
||||||
time::cds::TimeProvider,
|
time::cds::TimeProvider,
|
||||||
@ -79,7 +79,7 @@ fn main() {
|
|||||||
pool: Arc::new(RwLock::new(Box::new(tc_pool))),
|
pool: Arc::new(RwLock::new(Box::new(tc_pool))),
|
||||||
};
|
};
|
||||||
|
|
||||||
let seq_count_provider = SeqCountProviderSimple::new();
|
let seq_count_provider = CcsdsSimpleSeqCountProvider::new();
|
||||||
let mut msg_counter_map: HashMap<u8, u16> = HashMap::new();
|
let mut msg_counter_map: HashMap<u8, u16> = HashMap::new();
|
||||||
let sock_addr = SocketAddr::new(IpAddr::V4(OBSW_SERVER_ADDR), SERVER_PORT);
|
let sock_addr = SocketAddr::new(IpAddr::V4(OBSW_SERVER_ADDR), SERVER_PORT);
|
||||||
let (tc_source_tx, tc_source_rx) = channel();
|
let (tc_source_tx, tc_source_rx) = channel();
|
||||||
|
Loading…
Reference in New Issue
Block a user