PUS Event Generation #17

Merged
muellerr merged 13 commits from event-pus-generation into main 2022-10-22 17:34:00 +02:00
4 changed files with 79 additions and 56 deletions
Showing only changes of commit 4d415cc0ad - Show all commits

View File

@ -179,10 +179,10 @@ mod allocvec {
}
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)?;
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,
})
}
@ -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.
}
}

View File

@ -52,3 +52,58 @@ pub(crate) fn source_buffer_large_enough<E>(cap: usize, len: usize) -> Result<()
}
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(())
}
}
}

View File

@ -191,16 +191,16 @@ pub struct VerificationToken<STATE> {
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum StateNone {}
pub struct StateNone;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum StateAccepted {}
pub struct StateAccepted;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum StateStarted {}
pub struct StateStarted;
pub enum StateToken {
None(StateNone),
Accepted(StateAccepted),
Started(StateStarted)
Started(StateStarted),
}
impl<STATE> VerificationToken<STATE> {
@ -1066,6 +1066,7 @@ mod stdmod {
#[cfg(test)]
mod tests {
use crate::pus::tests::{TestSender, TmInfo};
use crate::pus::verification::{
EcssTmError, EcssTmSender, FailParams, FailParamsWithStep, RequestId, StateNone,
VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender,
@ -1073,60 +1074,14 @@ mod tests {
};
use alloc::boxed::Box;
use alloc::format;
use alloc::vec::Vec;
use spacepackets::ecss::{EcssEnumU16, EcssEnumU32, EcssEnumU8, EcssEnumeration, PusPacket};
use spacepackets::ecss::{EcssEnumU16, EcssEnumU32, EcssEnumU8, EcssEnumeration};
use spacepackets::tc::{PusTc, PusTcSecondaryHeader};
use spacepackets::tm::{PusTm, PusTmSecondaryHeaderT};
use spacepackets::{ByteConversionError, CcsdsPacket, SpHeader};
use std::collections::VecDeque;
use spacepackets::tm::PusTm;
use spacepackets::{ByteConversionError, SpHeader};
const TEST_APID: u16 = 0x02;
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)]
struct DummyError {}
#[derive(Default)]

@ -1 +1 @@
Subproject commit 638e4cda620fbb0ef6aed9faa0e9375d3762a339
Subproject commit 603f688ac3e914de13037fd22ac544e125b6305b