implemented basic event reporter

This commit is contained in:
Robin Müller 2022-09-11 21:14:19 +02:00
parent 08e3242f84
commit 1eee8da4de
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
2 changed files with 213 additions and 62 deletions

View File

@ -5,15 +5,33 @@ use spacepackets::tm::PusTmSecondaryHeader;
use spacepackets::{SpHeader, MAX_APID};
#[cfg(feature = "alloc")]
pub use allocvec::EventReporterWithVec;
pub use allocvec::EventReporter;
pub struct EventReporter {
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum Subservices {
TmInfoReport = 1,
TmLowSeverityReport = 2,
TmMediumSeverityReport = 3,
TmHighSeverityReport = 4,
TcEnableEventGeneration = 5,
TcDisableEventGeneration = 6,
TcReportDisabledList = 7,
TmDisabledEventsReport = 8,
}
impl From<Subservices> for u8 {
fn from(enumeration: Subservices) -> Self {
enumeration as u8
}
}
pub struct EventReporterBase {
msg_count: u16,
apid: u16,
pub dest_id: u16,
}
impl EventReporter {
impl EventReporterBase {
pub fn new(apid: u16) -> Option<Self> {
if apid > MAX_APID {
return None;
@ -33,13 +51,106 @@ impl EventReporter {
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<(), EcssTmError<E>> {
self.generate_and_send_generic_tm(
buf,
Subservices::TmInfoReport,
sender,
time_stamp,
event_id,
aux_data,
)
}
pub fn event_low_severity<E>(
&mut self,
buf: &mut [u8],
sender: &mut (impl EcssTmSender<E> + ?Sized),
time_stamp: &[u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<(), EcssTmError<E>> {
self.generate_and_send_generic_tm(
buf,
Subservices::TmLowSeverityReport,
sender,
time_stamp,
event_id,
aux_data,
)
}
pub fn event_medium_severity<E>(
&mut self,
buf: &mut [u8],
sender: &mut (impl EcssTmSender<E> + ?Sized),
time_stamp: &[u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<(), EcssTmError<E>> {
self.generate_and_send_generic_tm(
buf,
Subservices::TmMediumSeverityReport,
sender,
time_stamp,
event_id,
aux_data,
)
}
pub fn event_high_severity<E>(
&mut self,
buf: &mut [u8],
sender: &mut (impl EcssTmSender<E> + ?Sized),
time_stamp: &[u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<(), EcssTmError<E>> {
self.generate_and_send_generic_tm(
buf,
Subservices::TmHighSeverityReport,
sender,
time_stamp,
event_id,
aux_data,
)
}
fn generate_and_send_generic_tm<E>(
&mut self,
buf: &mut [u8],
subservice: Subservices,
sender: &mut (impl EcssTmSender<E> + ?Sized),
time_stamp: &[u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<(), EcssTmError<E>> {
let tm = self.generate_generic_event_tm(buf, subservice, time_stamp, event_id, aux_data)?;
sender.send_tm(tm)?;
self.msg_count += 1;
Ok(())
}
fn generate_generic_event_tm<'a, E>(
&'a self,
buf: &'a mut [u8],
subservice: Subservices,
time_stamp: &'a [u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<PusTm, EcssTmError<E>> {
let mut src_data_len = event_id.byte_width();
if let Some(aux_data) = aux_data {
src_data_len += aux_data.len();
}
source_buffer_large_enough(buf.len(), src_data_len)?;
let mut sp_header = SpHeader::tm(self.apid, 0, 0).unwrap();
let sec_header = PusTmSecondaryHeader::new(5, 0, self.msg_count, self.dest_id, time_stamp);
let sec_header = PusTmSecondaryHeader::new(
5,
subservice.into(),
self.msg_count,
self.dest_id,
time_stamp,
);
let mut current_idx = 0;
event_id.write_to_bytes(&mut buf[0..event_id.byte_width()])?;
current_idx += event_id.byte_width();
@ -47,10 +158,12 @@ impl EventReporter {
buf[current_idx..current_idx + aux_data.len()].copy_from_slice(aux_data);
current_idx += aux_data.len();
}
let tm = PusTm::new(&mut sp_header, sec_header, Some(&buf[0..current_idx]), true);
sender.send_tm(tm)?;
self.msg_count += 1;
Ok(())
Ok(PusTm::new(
&mut sp_header,
sec_header,
Some(&buf[0..current_idx]),
true,
))
}
}
@ -60,14 +173,14 @@ mod allocvec {
use alloc::vec;
use alloc::vec::Vec;
pub struct EventReporterWithVec {
pub struct EventReporter {
source_data_buf: Vec<u8>,
pub reporter: EventReporter,
pub reporter: EventReporterBase,
}
impl EventReporterWithVec {
impl EventReporter {
pub fn new(apid: u16, max_event_id_and_aux_data: usize) -> Option<Self> {
let reporter = EventReporter::new(apid)?;
let reporter = EventReporterBase::new(apid)?;
Some(Self {
source_data_buf: vec![0; max_event_id_and_aux_data],
reporter,
@ -88,28 +201,53 @@ mod allocvec {
aux_data,
)
}
// pub fn event_low_severity<E>(
// &mut self,
// _sender: &mut (impl EcssTmSender<E> + ?Sized),
// _event_id: impl EcssEnumeration,
// _aux_data: Option<&[u8]>,
// ) {
// }
//
// pub fn event_medium_severity<E>(
// &mut self,
// _sender: &mut (impl EcssTmSender<E> + ?Sized),
// _event_id: impl EcssEnumeration,
// _aux_data: Option<&[u8]>,
// ) {
// }
//
// pub fn event_high_severity<E>(
// &mut self,
// _sender: &mut (impl EcssTmSender<E> + ?Sized),
// _event_id: impl EcssEnumeration,
// _aux_data: Option<&[u8]>,
// ) {
// }
pub fn event_low_severity<E>(
&mut self,
sender: &mut (impl EcssTmSender<E> + ?Sized),
time_stamp: &[u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<(), EcssTmError<E>> {
self.reporter.event_low_severity(
self.source_data_buf.as_mut_slice(),
sender,
time_stamp,
event_id,
aux_data,
)
}
pub fn event_medium_severity<E>(
&mut self,
sender: &mut (impl EcssTmSender<E> + ?Sized),
time_stamp: &[u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<(), EcssTmError<E>> {
self.reporter.event_medium_severity(
self.source_data_buf.as_mut_slice(),
sender,
time_stamp,
event_id,
aux_data,
)
}
pub fn event_high_severity<E>(
&mut self,
sender: &mut (impl EcssTmSender<E> + ?Sized),
time_stamp: &[u8],
event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>,
) -> Result<(), EcssTmError<E>> {
self.reporter.event_high_severity(
self.source_data_buf.as_mut_slice(),
sender,
time_stamp,
event_id,
aux_data,
)
}
}
}

View File

@ -92,6 +92,24 @@ pub use stdmod::{
StdVerifReporterWithSender, StdVerifSenderError,
};
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum Subservices {
TmAcceptanceSuccess = 1,
TmAcceptanceFailure = 2,
TmStartSuccess = 3,
TmStartFailure = 4,
TmStepSuccess = 5,
TmStepFailure = 6,
TmCompletionSuccess = 7,
TmCompletionFailure = 8,
}
impl From<Subservices> for u8 {
fn from(enumeration: Subservices) -> Self {
enumeration as u8
}
}
/// This is a request identifier as specified in 5.4.11.2 c. of the PUS standard
/// This field equivalent to the first two bytes of the CCSDS space packet header.
#[derive(Debug, Eq, Copy, Clone)]
@ -294,8 +312,7 @@ impl VerificationReporterBasic {
let tm = self
.create_pus_verif_success_tm(
buf,
1,
1,
Subservices::TmAcceptanceSuccess.into(),
&token.req_id,
time_stamp,
None::<&dyn EcssEnumeration>,
@ -322,8 +339,7 @@ impl VerificationReporterBasic {
let tm = self
.create_pus_verif_fail_tm(
buf,
1,
2,
Subservices::TmAcceptanceFailure.into(),
&token.req_id,
None::<&dyn EcssEnumeration>,
&params,
@ -349,8 +365,7 @@ impl VerificationReporterBasic {
let tm = self
.create_pus_verif_success_tm(
buf,
1,
3,
Subservices::TmStartSuccess.into(),
&token.req_id,
time_stamp,
None::<&dyn EcssEnumeration>,
@ -380,8 +395,7 @@ impl VerificationReporterBasic {
let tm = self
.create_pus_verif_fail_tm(
buf,
1,
4,
Subservices::TmStartFailure.into(),
&token.req_id,
None::<&dyn EcssEnumeration>,
&params,
@ -405,8 +419,13 @@ impl VerificationReporterBasic {
time_stamp: &[u8],
step: impl EcssEnumeration,
) -> Result<(), EcssTmError<E>> {
let tm =
self.create_pus_verif_success_tm(buf, 1, 5, &token.req_id, time_stamp, Some(&step))?;
let tm = self.create_pus_verif_success_tm(
buf,
Subservices::TmStepSuccess.into(),
&token.req_id,
time_stamp,
Some(&step),
)?;
sender.send_tm(tm)?;
self.msg_count += 1;
Ok(())
@ -424,7 +443,13 @@ impl VerificationReporterBasic {
params: FailParamsWithStep,
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> {
let tm = self
.create_pus_verif_fail_tm(buf, 1, 6, &token.req_id, Some(params.step), &params.bp)
.create_pus_verif_fail_tm(
buf,
Subservices::TmStepFailure.into(),
&token.req_id,
Some(params.step),
&params.bp,
)
.map_err(|e| VerificationErrorWithToken(e, token))?;
sender
.send_tm(tm)
@ -447,8 +472,7 @@ impl VerificationReporterBasic {
let tm = self
.create_pus_verif_success_tm(
buf,
1,
7,
Subservices::TmCompletionSuccess.into(),
&token.req_id,
time_stamp,
None::<&dyn EcssEnumeration>,
@ -475,8 +499,7 @@ impl VerificationReporterBasic {
let tm = self
.create_pus_verif_fail_tm(
buf,
1,
8,
Subservices::TmCompletionFailure.into(),
&token.req_id,
None::<&dyn EcssEnumeration>,
&params,
@ -492,7 +515,6 @@ impl VerificationReporterBasic {
fn create_pus_verif_success_tm<'a, E>(
&'a mut self,
buf: &'a mut [u8],
service: u8,
subservice: u8,
req_id: &RequestId,
time_stamp: &'a [u8],
@ -514,7 +536,6 @@ impl VerificationReporterBasic {
let mut sp_header = SpHeader::tm(self.apid(), 0, 0).unwrap();
Ok(self.create_pus_verif_tm_base(
buf,
service,
subservice,
&mut sp_header,
time_stamp,
@ -525,7 +546,6 @@ impl VerificationReporterBasic {
fn create_pus_verif_fail_tm<'a, E>(
&'a mut self,
buf: &'a mut [u8],
service: u8,
subservice: u8,
req_id: &RequestId,
step: Option<&(impl EcssEnumeration + ?Sized)>,
@ -559,7 +579,6 @@ impl VerificationReporterBasic {
let mut sp_header = SpHeader::tm(self.apid(), 0, 0).unwrap();
Ok(self.create_pus_verif_tm_base(
buf,
service,
subservice,
&mut sp_header,
params.time_stamp,
@ -570,19 +589,13 @@ impl VerificationReporterBasic {
fn create_pus_verif_tm_base<'a>(
&'a mut self,
buf: &'a mut [u8],
service: u8,
subservice: u8,
sp_header: &mut SpHeader,
time_stamp: &'a [u8],
source_data_len: usize,
) -> PusTm {
let tm_sec_header = PusTmSecondaryHeader::new(
service,
subservice,
self.msg_count,
self.dest_id,
time_stamp,
);
let tm_sec_header =
PusTmSecondaryHeader::new(1, subservice, self.msg_count, self.dest_id, time_stamp);
PusTm::new(
sp_header,
tm_sec_header,