PUS Event Generation #17
@ -179,10 +179,10 @@ mod allocvec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EventReporter {
|
impl EventReporter {
|
||||||
pub fn new(apid: u16, max_event_id_and_aux_data: usize) -> Option<Self> {
|
pub fn new(apid: u16, max_event_id_and_aux_data_size: usize) -> Option<Self> {
|
||||||
let reporter = EventReporterBase::new(apid)?;
|
let reporter = EventReporterBase::new(apid)?;
|
||||||
Some(Self {
|
Some(Self {
|
||||||
source_data_buf: vec![0; max_event_id_and_aux_data],
|
source_data_buf: vec![0; max_event_id_and_aux_data_size],
|
||||||
reporter,
|
reporter,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -251,3 +251,16 @@ mod allocvec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
const EXAMPLE_APID: u16 = 0xee;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn basic_event_generation() {
|
||||||
|
let _reporter = EventReporter::new(EXAMPLE_APID, 16);
|
||||||
|
//reporter.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -52,3 +52,58 @@ pub(crate) fn source_buffer_large_enough<E>(cap: usize, len: usize) -> Result<()
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) mod tests {
|
||||||
|
use crate::pus::verification::RequestId;
|
||||||
|
use crate::pus::{EcssTmError, EcssTmSender};
|
||||||
|
use alloc::vec::Vec;
|
||||||
|
use spacepackets::ecss::PusPacket;
|
||||||
|
use spacepackets::tm::{PusTm, PusTmSecondaryHeaderT};
|
||||||
|
use spacepackets::CcsdsPacket;
|
||||||
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
|
pub(crate) struct TmInfo {
|
||||||
|
pub subservice: u8,
|
||||||
|
pub apid: u16,
|
||||||
|
pub msg_counter: u16,
|
||||||
|
pub dest_id: u16,
|
||||||
|
pub time_stamp: [u8; 7],
|
||||||
|
pub req_id: RequestId,
|
||||||
|
pub additional_data: Option<Vec<u8>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub(crate) struct TestSender {
|
||||||
|
pub service_queue: VecDeque<TmInfo>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EcssTmSender<()> for TestSender {
|
||||||
|
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<()>> {
|
||||||
|
assert_eq!(PusPacket::service(&tm), 1);
|
||||||
|
assert!(tm.source_data().is_some());
|
||||||
|
let mut time_stamp = [0; 7];
|
||||||
|
time_stamp.clone_from_slice(&tm.time_stamp()[0..7]);
|
||||||
|
let src_data = tm.source_data().unwrap();
|
||||||
|
assert!(src_data.len() >= 4);
|
||||||
|
let req_id = RequestId::from_bytes(&src_data[0..RequestId::SIZE_AS_BYTES]).unwrap();
|
||||||
|
let mut vec = None;
|
||||||
|
if src_data.len() > 4 {
|
||||||
|
let mut new_vec = Vec::new();
|
||||||
|
new_vec.extend_from_slice(&src_data[RequestId::SIZE_AS_BYTES..]);
|
||||||
|
vec = Some(new_vec);
|
||||||
|
}
|
||||||
|
self.service_queue.push_back(TmInfo {
|
||||||
|
subservice: PusPacket::subservice(&tm),
|
||||||
|
apid: tm.apid(),
|
||||||
|
msg_counter: tm.msg_counter(),
|
||||||
|
dest_id: tm.dest_id(),
|
||||||
|
time_stamp,
|
||||||
|
req_id,
|
||||||
|
additional_data: vec,
|
||||||
|
});
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -191,16 +191,16 @@ pub struct VerificationToken<STATE> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
pub enum StateNone {}
|
pub struct StateNone;
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
pub enum StateAccepted {}
|
pub struct StateAccepted;
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
pub enum StateStarted {}
|
pub struct StateStarted;
|
||||||
|
|
||||||
pub enum StateToken {
|
pub enum StateToken {
|
||||||
None(StateNone),
|
None(StateNone),
|
||||||
Accepted(StateAccepted),
|
Accepted(StateAccepted),
|
||||||
Started(StateStarted)
|
Started(StateStarted),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<STATE> VerificationToken<STATE> {
|
impl<STATE> VerificationToken<STATE> {
|
||||||
@ -1066,6 +1066,7 @@ mod stdmod {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::pus::tests::{TestSender, TmInfo};
|
||||||
use crate::pus::verification::{
|
use crate::pus::verification::{
|
||||||
EcssTmError, EcssTmSender, FailParams, FailParamsWithStep, RequestId, StateNone,
|
EcssTmError, EcssTmSender, FailParams, FailParamsWithStep, RequestId, StateNone,
|
||||||
VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender,
|
VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender,
|
||||||
@ -1073,60 +1074,14 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use alloc::format;
|
use alloc::format;
|
||||||
use alloc::vec::Vec;
|
use spacepackets::ecss::{EcssEnumU16, EcssEnumU32, EcssEnumU8, EcssEnumeration};
|
||||||
use spacepackets::ecss::{EcssEnumU16, EcssEnumU32, EcssEnumU8, EcssEnumeration, PusPacket};
|
|
||||||
use spacepackets::tc::{PusTc, PusTcSecondaryHeader};
|
use spacepackets::tc::{PusTc, PusTcSecondaryHeader};
|
||||||
use spacepackets::tm::{PusTm, PusTmSecondaryHeaderT};
|
use spacepackets::tm::PusTm;
|
||||||
use spacepackets::{ByteConversionError, CcsdsPacket, SpHeader};
|
use spacepackets::{ByteConversionError, SpHeader};
|
||||||
use std::collections::VecDeque;
|
|
||||||
|
|
||||||
const TEST_APID: u16 = 0x02;
|
const TEST_APID: u16 = 0x02;
|
||||||
const EMPTY_STAMP: [u8; 7] = [0; 7];
|
const EMPTY_STAMP: [u8; 7] = [0; 7];
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
|
||||||
struct TmInfo {
|
|
||||||
pub subservice: u8,
|
|
||||||
pub apid: u16,
|
|
||||||
pub msg_counter: u16,
|
|
||||||
pub dest_id: u16,
|
|
||||||
pub time_stamp: [u8; 7],
|
|
||||||
pub req_id: RequestId,
|
|
||||||
pub additional_data: Option<Vec<u8>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
struct TestSender {
|
|
||||||
pub service_queue: VecDeque<TmInfo>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EcssTmSender<()> for TestSender {
|
|
||||||
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<()>> {
|
|
||||||
assert_eq!(PusPacket::service(&tm), 1);
|
|
||||||
assert!(tm.source_data().is_some());
|
|
||||||
let mut time_stamp = [0; 7];
|
|
||||||
time_stamp.clone_from_slice(&tm.time_stamp()[0..7]);
|
|
||||||
let src_data = tm.source_data().unwrap();
|
|
||||||
assert!(src_data.len() >= 4);
|
|
||||||
let req_id = RequestId::from_bytes(&src_data[0..RequestId::SIZE_AS_BYTES]).unwrap();
|
|
||||||
let mut vec = None;
|
|
||||||
if src_data.len() > 4 {
|
|
||||||
let mut new_vec = Vec::new();
|
|
||||||
new_vec.extend_from_slice(&src_data[RequestId::SIZE_AS_BYTES..]);
|
|
||||||
vec = Some(new_vec);
|
|
||||||
}
|
|
||||||
self.service_queue.push_back(TmInfo {
|
|
||||||
subservice: PusPacket::subservice(&tm),
|
|
||||||
apid: tm.apid(),
|
|
||||||
msg_counter: tm.msg_counter(),
|
|
||||||
dest_id: tm.dest_id(),
|
|
||||||
time_stamp,
|
|
||||||
req_id,
|
|
||||||
additional_data: vec,
|
|
||||||
});
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||||
struct DummyError {}
|
struct DummyError {}
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 638e4cda620fbb0ef6aed9faa0e9375d3762a339
|
Subproject commit 603f688ac3e914de13037fd22ac544e125b6305b
|
Loading…
Reference in New Issue
Block a user