PUS Event Manager #19

Merged
muellerr merged 41 commits from pus-event-manager into main 2022-11-19 12:26:17 +01:00
5 changed files with 195 additions and 99 deletions
Showing only changes of commit 9cc58432c8 - Show all commits

View File

@ -5,6 +5,7 @@ use hashbrown::HashSet;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
pub use crate::pus::event::EventReporter; pub use crate::pus::event::EventReporter;
use crate::pus::verification::{TcStateStarted, VerificationToken};
use crate::pus::{EcssTmError, EcssTmSender}; use crate::pus::{EcssTmError, EcssTmSender};
#[cfg(feature = "heapless")] #[cfg(feature = "heapless")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "heapless")))] #[cfg_attr(doc_cfg, doc(cfg(feature = "heapless")))]
@ -108,6 +109,18 @@ pub mod heapless_mod {
} }
} }
#[derive(Debug)]
pub enum EventRequest<Event: GenericEvent = EventU32> {
Enable(Event),
Disable(Event),
}
#[derive(Debug)]
pub struct EventRequestWithToken<Event: GenericEvent = EventU32> {
pub request: EventRequest<Event>,
pub token: VerificationToken<TcStateStarted>,
}
#[derive(Debug)] #[derive(Debug)]
pub enum EventManError<SenderE> { pub enum EventManError<SenderE> {
EcssTmError(EcssTmError<SenderE>), EcssTmError(EcssTmError<SenderE>),

View File

@ -191,39 +191,39 @@ pub struct VerificationToken<STATE> {
} }
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct StateNone; pub struct TcStateNone;
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct StateAccepted; pub struct TcStateAccepted;
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct StateStarted; pub struct TcStateStarted;
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub enum StateToken { pub enum TcStateToken {
None(StateNone), None(VerificationToken<TcStateNone>),
Accepted(StateAccepted), Accepted(VerificationToken<TcStateAccepted>),
Started(StateStarted), Started(VerificationToken<TcStateStarted>),
} }
impl From<StateNone> for StateToken { impl From<VerificationToken<TcStateNone>> for TcStateToken {
fn from(t: StateNone) -> Self { fn from(t: VerificationToken<TcStateNone>) -> Self {
StateToken::None(t) TcStateToken::None(t)
} }
} }
impl From<StateAccepted> for StateToken { impl From<VerificationToken<TcStateAccepted>> for TcStateToken {
fn from(t: StateAccepted) -> Self { fn from(t: VerificationToken<TcStateAccepted>) -> Self {
StateToken::Accepted(t) TcStateToken::Accepted(t)
} }
} }
impl From<StateStarted> for StateToken { impl From<VerificationToken<TcStateStarted>> for TcStateToken {
fn from(t: StateStarted) -> Self { fn from(t: VerificationToken<TcStateStarted>) -> Self {
StateToken::Started(t) TcStateToken::Started(t)
} }
} }
impl<STATE> VerificationToken<STATE> { impl<STATE> VerificationToken<STATE> {
fn new(req_id: RequestId) -> VerificationToken<StateNone> { fn new(req_id: RequestId) -> VerificationToken<TcStateNone> {
VerificationToken { VerificationToken {
state: PhantomData, state: PhantomData,
req_id, req_id,
@ -316,24 +316,25 @@ impl VerificationReporterBasic {
/// Initialize verification handling by passing a TC reference. This returns a token required /// Initialize verification handling by passing a TC reference. This returns a token required
/// to call the acceptance functions /// to call the acceptance functions
pub fn add_tc(&mut self, pus_tc: &PusTc) -> VerificationToken<StateNone> { pub fn add_tc(&mut self, pus_tc: &PusTc) -> VerificationToken<TcStateNone> {
self.add_tc_with_req_id(RequestId::new(pus_tc)) self.add_tc_with_req_id(RequestId::new(pus_tc))
} }
/// Same as [Self::add_tc] but pass a request ID instead of the direct telecommand. /// Same as [Self::add_tc] but pass a request ID instead of the direct telecommand.
/// This can be useful if the executing thread does not have full access to the telecommand. /// This can be useful if the executing thread does not have full access to the telecommand.
pub fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<StateNone> { pub fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone> {
VerificationToken::<StateNone>::new(req_id) VerificationToken::<TcStateNone>::new(req_id)
} }
/// Package and send a PUS TM\[1, 1\] packet, see 8.1.2.1 of the PUS standard /// Package and send a PUS TM\[1, 1\] packet, see 8.1.2.1 of the PUS standard
pub fn acceptance_success<E>( pub fn acceptance_success<E>(
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<StateNone>, token: VerificationToken<TcStateNone>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<StateAccepted>, VerificationErrorWithToken<E, StateNone>> { ) -> Result<VerificationToken<TcStateAccepted>, VerificationErrorWithToken<E, TcStateNone>>
{
let tm = self let tm = self
.create_pus_verif_success_tm( .create_pus_verif_success_tm(
buf, buf,
@ -357,10 +358,10 @@ impl VerificationReporterBasic {
pub fn acceptance_failure<E>( pub fn acceptance_failure<E>(
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<StateNone>, token: VerificationToken<TcStateNone>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, StateNone>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateNone>> {
let tm = self let tm = self
.create_pus_verif_fail_tm( .create_pus_verif_fail_tm(
buf, buf,
@ -383,10 +384,11 @@ impl VerificationReporterBasic {
pub fn start_success<E>( pub fn start_success<E>(
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<StateAccepted>, token: VerificationToken<TcStateAccepted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<StateStarted>, VerificationErrorWithToken<E, StateAccepted>> { ) -> Result<VerificationToken<TcStateStarted>, VerificationErrorWithToken<E, TcStateAccepted>>
{
let tm = self let tm = self
.create_pus_verif_success_tm( .create_pus_verif_success_tm(
buf, buf,
@ -413,10 +415,10 @@ impl VerificationReporterBasic {
pub fn start_failure<E>( pub fn start_failure<E>(
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<StateAccepted>, token: VerificationToken<TcStateAccepted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, StateAccepted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateAccepted>> {
let tm = self let tm = self
.create_pus_verif_fail_tm( .create_pus_verif_fail_tm(
buf, buf,
@ -439,7 +441,7 @@ impl VerificationReporterBasic {
pub fn step_success<E>( pub fn step_success<E>(
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
token: &VerificationToken<StateStarted>, token: &VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
step: impl EcssEnumeration, step: impl EcssEnumeration,
@ -463,10 +465,10 @@ impl VerificationReporterBasic {
pub fn step_failure<E>( pub fn step_failure<E>(
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<StateStarted>, token: VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
params: FailParamsWithStep, params: FailParamsWithStep,
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
let tm = self let tm = self
.create_pus_verif_fail_tm( .create_pus_verif_fail_tm(
buf, buf,
@ -490,10 +492,10 @@ impl VerificationReporterBasic {
pub fn completion_success<E>( pub fn completion_success<E>(
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<StateStarted>, token: VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
let tm = self let tm = self
.create_pus_verif_success_tm( .create_pus_verif_success_tm(
buf, buf,
@ -517,10 +519,10 @@ impl VerificationReporterBasic {
pub fn completion_failure<E>( pub fn completion_failure<E>(
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
token: VerificationToken<StateStarted>, token: VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
let tm = self let tm = self
.create_pus_verif_fail_tm( .create_pus_verif_fail_tm(
buf, buf,
@ -689,8 +691,8 @@ mod allocmod {
to self.reporter { to self.reporter {
pub fn set_apid(&mut self, apid: u16) -> bool; pub fn set_apid(&mut self, apid: u16) -> bool;
pub fn apid(&self) -> u16; pub fn apid(&self) -> u16;
pub fn add_tc(&mut self, pus_tc: &PusTc) -> VerificationToken<StateNone>; pub fn add_tc(&mut self, pus_tc: &PusTc) -> VerificationToken<TcStateNone>;
pub fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<StateNone>; pub fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone>;
pub fn dest_id(&self) -> u16; pub fn dest_id(&self) -> u16;
pub fn set_dest_id(&mut self, dest_id: u16); pub fn set_dest_id(&mut self, dest_id: u16);
} }
@ -703,10 +705,10 @@ mod allocmod {
/// Package and send a PUS TM\[1, 1\] packet, see 8.1.2.1 of the PUS standard /// Package and send a PUS TM\[1, 1\] packet, see 8.1.2.1 of the PUS standard
pub fn acceptance_success<E>( pub fn acceptance_success<E>(
&mut self, &mut self,
token: VerificationToken<StateNone>, token: VerificationToken<TcStateNone>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<StateAccepted>, VerificationErrorWithToken<E, StateNone>> ) -> Result<VerificationToken<TcStateAccepted>, VerificationErrorWithToken<E, TcStateNone>>
{ {
self.reporter.acceptance_success( self.reporter.acceptance_success(
self.source_data_buf.as_mut_slice(), self.source_data_buf.as_mut_slice(),
@ -719,10 +721,10 @@ mod allocmod {
/// Package and send a PUS TM\[1, 2\] packet, see 8.1.2.2 of the PUS standard /// Package and send a PUS TM\[1, 2\] packet, see 8.1.2.2 of the PUS standard
pub fn acceptance_failure<E>( pub fn acceptance_failure<E>(
&mut self, &mut self,
token: VerificationToken<StateNone>, token: VerificationToken<TcStateNone>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, StateNone>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateNone>> {
self.reporter.acceptance_failure( self.reporter.acceptance_failure(
self.source_data_buf.as_mut_slice(), self.source_data_buf.as_mut_slice(),
token, token,
@ -736,10 +738,10 @@ mod allocmod {
/// Requires a token previously acquired by calling [Self::acceptance_success]. /// Requires a token previously acquired by calling [Self::acceptance_success].
pub fn start_success<E>( pub fn start_success<E>(
&mut self, &mut self,
token: VerificationToken<StateAccepted>, token: VerificationToken<TcStateAccepted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<StateStarted>, VerificationErrorWithToken<E, StateAccepted>> ) -> Result<VerificationToken<TcStateStarted>, VerificationErrorWithToken<E, TcStateAccepted>>
{ {
self.reporter.start_success( self.reporter.start_success(
self.source_data_buf.as_mut_slice(), self.source_data_buf.as_mut_slice(),
@ -755,10 +757,10 @@ mod allocmod {
/// the token because verification handling is done. /// the token because verification handling is done.
pub fn start_failure<E>( pub fn start_failure<E>(
&mut self, &mut self,
token: VerificationToken<StateAccepted>, token: VerificationToken<TcStateAccepted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, StateAccepted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateAccepted>> {
self.reporter self.reporter
.start_failure(self.source_data_buf.as_mut_slice(), token, sender, params) .start_failure(self.source_data_buf.as_mut_slice(), token, sender, params)
} }
@ -768,7 +770,7 @@ mod allocmod {
/// Requires a token previously acquired by calling [Self::start_success]. /// Requires a token previously acquired by calling [Self::start_success].
pub fn step_success<E>( pub fn step_success<E>(
&mut self, &mut self,
token: &VerificationToken<StateStarted>, token: &VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
step: impl EcssEnumeration, step: impl EcssEnumeration,
@ -788,10 +790,10 @@ mod allocmod {
/// token because verification handling is done. /// token because verification handling is done.
pub fn step_failure<E>( pub fn step_failure<E>(
&mut self, &mut self,
token: VerificationToken<StateStarted>, token: VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
params: FailParamsWithStep, params: FailParamsWithStep,
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
self.reporter self.reporter
.step_failure(self.source_data_buf.as_mut_slice(), token, sender, params) .step_failure(self.source_data_buf.as_mut_slice(), token, sender, params)
} }
@ -802,10 +804,10 @@ mod allocmod {
/// token because verification handling is done. /// token because verification handling is done.
pub fn completion_success<E>( pub fn completion_success<E>(
&mut self, &mut self,
token: VerificationToken<StateStarted>, token: VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
self.reporter.completion_success( self.reporter.completion_success(
self.source_data_buf.as_mut_slice(), self.source_data_buf.as_mut_slice(),
token, token,
@ -820,10 +822,10 @@ mod allocmod {
/// token because verification handling is done. /// token because verification handling is done.
pub fn completion_failure<E>( pub fn completion_failure<E>(
&mut self, &mut self,
token: VerificationToken<StateStarted>, token: VerificationToken<TcStateStarted>,
sender: &mut (impl EcssTmSender<Error = E> + ?Sized), sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
self.reporter.completion_failure( self.reporter.completion_failure(
self.source_data_buf.as_mut_slice(), self.source_data_buf.as_mut_slice(),
token, token,
@ -857,8 +859,8 @@ mod allocmod {
to self.reporter { to self.reporter {
pub fn set_apid(&mut self, apid: u16) -> bool; pub fn set_apid(&mut self, apid: u16) -> bool;
pub fn apid(&self) -> u16; pub fn apid(&self) -> u16;
pub fn add_tc(&mut self, pus_tc: &PusTc) -> VerificationToken<StateNone>; pub fn add_tc(&mut self, pus_tc: &PusTc) -> VerificationToken<TcStateNone>;
pub fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<StateNone>; pub fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone>;
pub fn dest_id(&self) -> u16; pub fn dest_id(&self) -> u16;
pub fn set_dest_id(&mut self, dest_id: u16); pub fn set_dest_id(&mut self, dest_id: u16);
} }
@ -866,9 +868,9 @@ mod allocmod {
pub fn acceptance_success( pub fn acceptance_success(
&mut self, &mut self,
token: VerificationToken<StateNone>, token: VerificationToken<TcStateNone>,
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<StateAccepted>, VerificationErrorWithToken<E, StateNone>> ) -> Result<VerificationToken<TcStateAccepted>, VerificationErrorWithToken<E, TcStateNone>>
{ {
self.reporter self.reporter
.acceptance_success(token, self.sender.as_mut(), time_stamp) .acceptance_success(token, self.sender.as_mut(), time_stamp)
@ -876,18 +878,18 @@ mod allocmod {
pub fn acceptance_failure( pub fn acceptance_failure(
&mut self, &mut self,
token: VerificationToken<StateNone>, token: VerificationToken<TcStateNone>,
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, StateNone>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateNone>> {
self.reporter self.reporter
.acceptance_failure(token, self.sender.as_mut(), params) .acceptance_failure(token, self.sender.as_mut(), params)
} }
pub fn start_success( pub fn start_success(
&mut self, &mut self,
token: VerificationToken<StateAccepted>, token: VerificationToken<TcStateAccepted>,
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<StateStarted>, VerificationErrorWithToken<E, StateAccepted>> ) -> Result<VerificationToken<TcStateStarted>, VerificationErrorWithToken<E, TcStateAccepted>>
{ {
self.reporter self.reporter
.start_success(token, self.sender.as_mut(), time_stamp) .start_success(token, self.sender.as_mut(), time_stamp)
@ -895,16 +897,16 @@ mod allocmod {
pub fn start_failure( pub fn start_failure(
&mut self, &mut self,
token: VerificationToken<StateAccepted>, token: VerificationToken<TcStateAccepted>,
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, StateAccepted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateAccepted>> {
self.reporter self.reporter
.start_failure(token, self.sender.as_mut(), params) .start_failure(token, self.sender.as_mut(), params)
} }
pub fn step_success( pub fn step_success(
&mut self, &mut self,
token: &VerificationToken<StateStarted>, token: &VerificationToken<TcStateStarted>,
time_stamp: &[u8], time_stamp: &[u8],
step: impl EcssEnumeration, step: impl EcssEnumeration,
) -> Result<(), EcssTmError<E>> { ) -> Result<(), EcssTmError<E>> {
@ -914,27 +916,27 @@ mod allocmod {
pub fn step_failure( pub fn step_failure(
&mut self, &mut self,
token: VerificationToken<StateStarted>, token: VerificationToken<TcStateStarted>,
params: FailParamsWithStep, params: FailParamsWithStep,
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
self.reporter self.reporter
.step_failure(token, self.sender.as_mut(), params) .step_failure(token, self.sender.as_mut(), params)
} }
pub fn completion_success( pub fn completion_success(
&mut self, &mut self,
token: VerificationToken<StateStarted>, token: VerificationToken<TcStateStarted>,
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
self.reporter self.reporter
.completion_success(token, self.sender.as_mut(), time_stamp) .completion_success(token, self.sender.as_mut(), time_stamp)
} }
pub fn completion_failure( pub fn completion_failure(
&mut self, &mut self,
token: VerificationToken<StateStarted>, token: VerificationToken<TcStateStarted>,
params: FailParams, params: FailParams,
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> { ) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
self.reporter self.reporter
.completion_failure(token, self.sender.as_mut(), params) .completion_failure(token, self.sender.as_mut(), params)
} }
@ -1092,7 +1094,7 @@ mod stdmod {
mod tests { mod tests {
use crate::pus::tests::CommonTmInfo; use crate::pus::tests::CommonTmInfo;
use crate::pus::verification::{ use crate::pus::verification::{
EcssTmError, EcssTmSender, FailParams, FailParamsWithStep, RequestId, StateNone, EcssTmError, EcssTmSender, FailParams, FailParamsWithStep, RequestId, TcStateNone,
VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender, VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender,
VerificationToken, VerificationToken,
}; };
@ -1193,7 +1195,7 @@ mod tests {
(pus_tc, req_id) (pus_tc, req_id)
} }
fn base_init(api_sel: bool) -> (TestBase<'static>, VerificationToken<StateNone>) { fn base_init(api_sel: bool) -> (TestBase<'static>, VerificationToken<TcStateNone>) {
let mut reporter = base_reporter(); let mut reporter = base_reporter();
let (tc, req_id) = base_tc_init(None); let (tc, req_id) = base_tc_init(None);
let init_tok; let init_tok;
@ -1207,7 +1209,7 @@ mod tests {
fn base_with_helper_init() -> ( fn base_with_helper_init() -> (
TestBaseWithHelper<'static, ()>, TestBaseWithHelper<'static, ()>,
VerificationToken<StateNone>, VerificationToken<TcStateNone>,
) { ) {
let mut reporter = base_reporter(); let mut reporter = base_reporter();
let (tc, _) = base_tc_init(None); let (tc, _) = base_tc_init(None);

View File

@ -2,20 +2,25 @@ mod ccsds;
mod pus; mod pus;
mod tmtc; mod tmtc;
use crate::tmtc::{core_tmtc_task, TmStore, PUS_APID}; use crate::tmtc::{core_tmtc_task, CoreTmtcArgs, TmStore, PUS_APID};
use fsrc_core::event_man::{EventManager, MpscEventReceiver, MpscEventU32SendProvider}; use fsrc_core::event_man::{EventManager, MpscEventReceiver, MpscEventU32SendProvider};
use fsrc_core::events::EventU32; use fsrc_core::events::EventU32;
use fsrc_core::hal::host::udp_server::UdpTcServer; use fsrc_core::hal::host::udp_server::UdpTcServer;
use fsrc_core::params::Params;
use fsrc_core::pool::{LocalPool, PoolCfg, SharedPool, StoreAddr}; use fsrc_core::pool::{LocalPool, PoolCfg, SharedPool, StoreAddr};
use fsrc_core::pus::event_man::{DefaultPusMgmtBackendProvider, EventReporter, PusEventDispatcher}; use fsrc_core::pus::event_man::{
DefaultPusMgmtBackendProvider, EventReporter, EventRequest, EventRequestWithToken,
PusEventDispatcher,
};
use fsrc_core::pus::verification::{ use fsrc_core::pus::verification::{
MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender, MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender,
}; };
use fsrc_core::pus::{EcssTmError, EcssTmSender};
use fsrc_core::tmtc::CcsdsError; use fsrc_core::tmtc::CcsdsError;
use fsrc_example::{OBSW_SERVER_ADDR, SERVER_PORT}; use fsrc_example::{OBSW_SERVER_ADDR, SERVER_PORT};
use spacepackets::time::{CdsShortTimeProvider, TimeWriter};
use spacepackets::tm::PusTm;
use std::net::{IpAddr, SocketAddr}; use std::net::{IpAddr, SocketAddr};
use std::sync::mpsc::{channel, TryRecvError}; use std::sync::mpsc::channel;
use std::sync::{mpsc, Arc, Mutex, RwLock}; use std::sync::{mpsc, Arc, Mutex, RwLock};
use std::thread; use std::thread;
@ -32,6 +37,28 @@ struct UdpTmtcServer {
unsafe impl Send for UdpTmtcServer {} unsafe impl Send for UdpTmtcServer {}
struct EventTmSender {
store_helper: TmStore,
sender: mpsc::Sender<StoreAddr>,
}
impl EventTmSender {
fn new(store_helper: TmStore, sender: mpsc::Sender<StoreAddr>) -> Self {
Self {
store_helper,
sender,
}
}
}
impl EcssTmSender for EventTmSender {
type Error = mpsc::SendError<StoreAddr>;
fn send_tm(&mut self, tm: PusTm) -> Result<(), EcssTmError<Self::Error>> {
let addr = self.store_helper.add_pus_tm(&tm);
self.sender.send(addr).map_err(EcssTmError::SendError)
}
}
fn main() { fn main() {
println!("Running OBSW example"); println!("Running OBSW example");
let pool_cfg = PoolCfg::new(vec![(8, 32), (4, 64), (2, 128)]); let pool_cfg = PoolCfg::new(vec![(8, 32), (4, 64), (2, 128)]);
@ -41,32 +68,38 @@ fn main() {
pool: tm_store.clone(), pool: tm_store.clone(),
}; };
let addr = SocketAddr::new(IpAddr::V4(OBSW_SERVER_ADDR), SERVER_PORT); let addr = SocketAddr::new(IpAddr::V4(OBSW_SERVER_ADDR), SERVER_PORT);
let (tm_funnel_tx, tm_funnel_rx) = mpsc::channel(); let (tm_funnel_tx, tm_funnel_rx) = channel();
let (tm_server_tx, tm_server_rx) = mpsc::channel(); let (tm_server_tx, tm_server_rx) = channel();
let sender = MpscVerifSender::new(tm_store.clone(), tm_funnel_tx.clone()); let sender = MpscVerifSender::new(tm_store.clone(), tm_funnel_tx.clone());
let verif_cfg = VerificationReporterCfg::new(PUS_APID, 1, 2, 8).unwrap(); let verif_cfg = VerificationReporterCfg::new(PUS_APID, 1, 2, 8).unwrap();
let reporter_with_sender_0 = Arc::new(Mutex::new(VerificationReporterWithSender::new( let reporter_with_sender_0 = Arc::new(Mutex::new(VerificationReporterWithSender::new(
verif_cfg, verif_cfg,
Box::new(sender), Box::new(sender),
))); )));
// Create event handling components
let (event_request_tx, event_request_rx) = channel::<EventRequestWithToken>();
let (event_sender, event_man_rx) = channel(); let (event_sender, event_man_rx) = channel();
let event_recv = MpscEventReceiver::<EventU32>::new(event_man_rx); let event_recv = MpscEventReceiver::<EventU32>::new(event_man_rx);
let mut event_man = EventManager::new(Box::new(event_recv)); let mut event_man = EventManager::new(Box::new(event_recv));
let event_reporter = EventReporter::new(PUS_APID, 128).unwrap(); let event_reporter = EventReporter::new(PUS_APID, 128).unwrap();
let pus_tm_backend = DefaultPusMgmtBackendProvider::<EventU32>::default(); let pus_tm_backend = DefaultPusMgmtBackendProvider::<EventU32>::default();
let pus_event_man = PusEventDispatcher::new(event_reporter, Box::new(pus_tm_backend)); let mut pus_event_dispatcher =
PusEventDispatcher::new(event_reporter, Box::new(pus_tm_backend));
let (pus_event_man_tx, pus_event_man_rx) = channel(); let (pus_event_man_tx, pus_event_man_rx) = channel();
let pus_event_man_send_provider = MpscEventU32SendProvider::new(1, pus_event_man_tx); let pus_event_man_send_provider = MpscEventU32SendProvider::new(1, pus_event_man_tx);
let reporter1 = reporter_with_sender_0.clone();
event_man.subscribe_all(pus_event_man_send_provider); event_man.subscribe_all(pus_event_man_send_provider);
// Create clones here to allow move for thread 0
let core_args = CoreTmtcArgs {
tm_store: tm_store_helper.clone(),
tm_sender: tm_funnel_tx.clone(),
event_sender,
event_request_tx,
};
let jh0 = thread::spawn(move || { let jh0 = thread::spawn(move || {
core_tmtc_task( core_tmtc_task(core_args, tm_server_rx, addr, reporter_with_sender_0);
tm_funnel_tx.clone(),
tm_server_rx,
tm_store_helper.clone(),
addr,
reporter_with_sender_0.clone(),
event_sender.clone(),
);
}); });
let jh1 = thread::spawn(move || { let jh1 = thread::spawn(move || {
@ -84,10 +117,43 @@ fn main() {
} }
}); });
let jh2 = thread::spawn(move || loop { let jh2 = thread::spawn(move || {
match pus_event_man_rx.try_recv() { let mut timestamp: [u8; 7] = [0; 7];
Ok(_) => {} let mut sender = EventTmSender::new(tm_store_helper, tm_funnel_tx);
Err(_) => {} let mut time_provider = CdsShortTimeProvider::new(0, 0);
let report_completion = |event_req: EventRequestWithToken, timestamp: &[u8]| {
let mut reporter = reporter1
.lock()
.expect("Locking Verification reporter failed");
reporter
.completion_success(event_req.token, timestamp)
.expect("Sending completion success failed");
};
loop {
if let Ok(event_req) = event_request_rx.try_recv() {
match event_req.request {
EventRequest::Enable(event) => {
pus_event_dispatcher
.enable_tm_for_event(&event)
.expect("Enabling TM failed");
update_time(&mut time_provider, &mut timestamp);
report_completion(event_req, &timestamp);
}
EventRequest::Disable(event) => {
pus_event_dispatcher
.disable_tm_for_event(&event)
.expect("Disabling TM failed");
update_time(&mut time_provider, &mut timestamp);
report_completion(event_req, &timestamp);
}
}
}
if let Ok((event, _param)) = pus_event_man_rx.try_recv() {
update_time(&mut time_provider, &mut timestamp);
pus_event_dispatcher
.generate_pus_event_tm_generic(&mut sender, &timestamp, event, None)
.expect("Sending TM as event failed");
}
} }
}); });
@ -95,3 +161,12 @@ fn main() {
jh1.join().expect("Joining TM Funnel thread failed"); jh1.join().expect("Joining TM Funnel thread failed");
jh2.join().expect("Joining Event Manager thread failed"); jh2.join().expect("Joining Event Manager thread failed");
} }
pub fn update_time(time_provider: &mut CdsShortTimeProvider, timestamp: &mut [u8]) {
time_provider
.update_from_now()
.expect("Could not get current time");
time_provider
.write_to_bytes(timestamp)
.expect("Writing timestamp failed");
}

View File

@ -1,7 +1,7 @@
use crate::tmtc::TmStore; use crate::tmtc::TmStore;
use fsrc_core::pool::StoreAddr; use fsrc_core::pool::StoreAddr;
use fsrc_core::pus::verification::{ use fsrc_core::pus::verification::{
SharedStdVerifReporterWithSender, StateAccepted, VerificationToken, SharedStdVerifReporterWithSender, TcStateAccepted, VerificationToken,
}; };
use fsrc_core::tmtc::tm_helper::PusTmWithCdsShortHelper; use fsrc_core::tmtc::tm_helper::PusTmWithCdsShortHelper;
use fsrc_core::tmtc::PusServiceProvider; use fsrc_core::tmtc::PusServiceProvider;
@ -71,7 +71,7 @@ impl PusServiceProvider for PusReceiver {
} }
impl PusReceiver { impl PusReceiver {
fn handle_test_service(&mut self, pus_tc: &PusTc, token: VerificationToken<StateAccepted>) { fn handle_test_service(&mut self, pus_tc: &PusTc, token: VerificationToken<TcStateAccepted>) {
if pus_tc.subservice() == 1 { if pus_tc.subservice() == 1 {
println!("Received PUS ping command TC[17,1]"); println!("Received PUS ping command TC[17,1]");
println!("Sending ping reply PUS TM[17,2]"); println!("Sending ping reply PUS TM[17,2]");

View File

@ -11,12 +11,20 @@ use crate::ccsds::CcsdsReceiver;
use crate::pus::PusReceiver; use crate::pus::PusReceiver;
use crate::UdpTmtcServer; use crate::UdpTmtcServer;
use fsrc_core::pool::{SharedPool, StoreAddr}; use fsrc_core::pool::{SharedPool, StoreAddr};
use fsrc_core::pus::event_man::EventRequestWithToken;
use fsrc_core::pus::verification::SharedStdVerifReporterWithSender; use fsrc_core::pus::verification::SharedStdVerifReporterWithSender;
use fsrc_core::tmtc::{CcsdsDistributor, CcsdsError, PusDistributor}; use fsrc_core::tmtc::{CcsdsDistributor, CcsdsError, PusDistributor};
use spacepackets::tm::PusTm; use spacepackets::tm::PusTm;
pub const PUS_APID: u16 = 0x02; pub const PUS_APID: u16 = 0x02;
pub struct CoreTmtcArgs {
pub tm_store: TmStore,
pub tm_sender: Sender<StoreAddr>,
pub event_sender: Sender<(EventU32, Option<Params>)>,
pub event_request_tx: Sender<EventRequestWithToken>,
}
#[derive(Clone)] #[derive(Clone)]
pub struct TmStore { pub struct TmStore {
pub pool: SharedPool, pub pool: SharedPool,
@ -34,17 +42,15 @@ impl TmStore {
} }
pub fn core_tmtc_task( pub fn core_tmtc_task(
tm_creator_tx: Sender<StoreAddr>, args: CoreTmtcArgs,
tm_server_rx: mpsc::Receiver<StoreAddr>, tm_server_rx: mpsc::Receiver<StoreAddr>,
tm_store_helper: TmStore,
addr: SocketAddr, addr: SocketAddr,
verif_reporter: SharedStdVerifReporterWithSender, verif_reporter: SharedStdVerifReporterWithSender,
_event_tx: Sender<(EventU32, Option<Params>)>,
) { ) {
let pus_receiver = PusReceiver::new( let pus_receiver = PusReceiver::new(
PUS_APID, PUS_APID,
tm_creator_tx, args.tm_sender,
tm_store_helper.clone(), args.tm_store.clone(),
verif_reporter, verif_reporter,
); );
let pus_distributor = PusDistributor::new(Box::new(pus_receiver)); let pus_distributor = PusDistributor::new(Box::new(pus_receiver));
@ -58,7 +64,7 @@ pub fn core_tmtc_task(
let mut udp_tmtc_server = UdpTmtcServer { let mut udp_tmtc_server = UdpTmtcServer {
udp_tc_server, udp_tc_server,
tm_rx: tm_server_rx, tm_rx: tm_server_rx,
tm_store: tm_store_helper.pool.clone(), tm_store: args.tm_store.pool.clone(),
}; };
loop { loop {
core_tmtc_loop(&mut udp_tmtc_server); core_tmtc_loop(&mut udp_tmtc_server);