PUS Event Manager #19
@ -5,6 +5,7 @@ use hashbrown::HashSet;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub use crate::pus::event::EventReporter;
|
||||
use crate::pus::verification::{TcStateStarted, VerificationToken};
|
||||
use crate::pus::{EcssTmError, EcssTmSender};
|
||||
#[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)]
|
||||
pub enum EventManError<SenderE> {
|
||||
EcssTmError(EcssTmError<SenderE>),
|
||||
|
@ -191,39 +191,39 @@ pub struct VerificationToken<STATE> {
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub struct StateNone;
|
||||
pub struct TcStateNone;
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub struct StateAccepted;
|
||||
pub struct TcStateAccepted;
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub struct StateStarted;
|
||||
pub struct TcStateStarted;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum StateToken {
|
||||
None(StateNone),
|
||||
Accepted(StateAccepted),
|
||||
Started(StateStarted),
|
||||
pub enum TcStateToken {
|
||||
None(VerificationToken<TcStateNone>),
|
||||
Accepted(VerificationToken<TcStateAccepted>),
|
||||
Started(VerificationToken<TcStateStarted>),
|
||||
}
|
||||
|
||||
impl From<StateNone> for StateToken {
|
||||
fn from(t: StateNone) -> Self {
|
||||
StateToken::None(t)
|
||||
impl From<VerificationToken<TcStateNone>> for TcStateToken {
|
||||
fn from(t: VerificationToken<TcStateNone>) -> Self {
|
||||
TcStateToken::None(t)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StateAccepted> for StateToken {
|
||||
fn from(t: StateAccepted) -> Self {
|
||||
StateToken::Accepted(t)
|
||||
impl From<VerificationToken<TcStateAccepted>> for TcStateToken {
|
||||
fn from(t: VerificationToken<TcStateAccepted>) -> Self {
|
||||
TcStateToken::Accepted(t)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StateStarted> for StateToken {
|
||||
fn from(t: StateStarted) -> Self {
|
||||
StateToken::Started(t)
|
||||
impl From<VerificationToken<TcStateStarted>> for TcStateToken {
|
||||
fn from(t: VerificationToken<TcStateStarted>) -> Self {
|
||||
TcStateToken::Started(t)
|
||||
}
|
||||
}
|
||||
|
||||
impl<STATE> VerificationToken<STATE> {
|
||||
fn new(req_id: RequestId) -> VerificationToken<StateNone> {
|
||||
fn new(req_id: RequestId) -> VerificationToken<TcStateNone> {
|
||||
VerificationToken {
|
||||
state: PhantomData,
|
||||
req_id,
|
||||
@ -316,24 +316,25 @@ impl VerificationReporterBasic {
|
||||
|
||||
/// Initialize verification handling by passing a TC reference. This returns a token required
|
||||
/// 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))
|
||||
}
|
||||
|
||||
/// 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.
|
||||
pub fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<StateNone> {
|
||||
VerificationToken::<StateNone>::new(req_id)
|
||||
pub fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone> {
|
||||
VerificationToken::<TcStateNone>::new(req_id)
|
||||
}
|
||||
|
||||
/// Package and send a PUS TM\[1, 1\] packet, see 8.1.2.1 of the PUS standard
|
||||
pub fn acceptance_success<E>(
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<StateNone>,
|
||||
token: VerificationToken<TcStateNone>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
) -> Result<VerificationToken<StateAccepted>, VerificationErrorWithToken<E, StateNone>> {
|
||||
) -> Result<VerificationToken<TcStateAccepted>, VerificationErrorWithToken<E, TcStateNone>>
|
||||
{
|
||||
let tm = self
|
||||
.create_pus_verif_success_tm(
|
||||
buf,
|
||||
@ -357,10 +358,10 @@ impl VerificationReporterBasic {
|
||||
pub fn acceptance_failure<E>(
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<StateNone>,
|
||||
token: VerificationToken<TcStateNone>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, StateNone>> {
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateNone>> {
|
||||
let tm = self
|
||||
.create_pus_verif_fail_tm(
|
||||
buf,
|
||||
@ -383,10 +384,11 @@ impl VerificationReporterBasic {
|
||||
pub fn start_success<E>(
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<StateAccepted>,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
) -> Result<VerificationToken<StateStarted>, VerificationErrorWithToken<E, StateAccepted>> {
|
||||
) -> Result<VerificationToken<TcStateStarted>, VerificationErrorWithToken<E, TcStateAccepted>>
|
||||
{
|
||||
let tm = self
|
||||
.create_pus_verif_success_tm(
|
||||
buf,
|
||||
@ -413,10 +415,10 @@ impl VerificationReporterBasic {
|
||||
pub fn start_failure<E>(
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<StateAccepted>,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, StateAccepted>> {
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateAccepted>> {
|
||||
let tm = self
|
||||
.create_pus_verif_fail_tm(
|
||||
buf,
|
||||
@ -439,7 +441,7 @@ impl VerificationReporterBasic {
|
||||
pub fn step_success<E>(
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
token: &VerificationToken<StateStarted>,
|
||||
token: &VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
step: impl EcssEnumeration,
|
||||
@ -463,10 +465,10 @@ impl VerificationReporterBasic {
|
||||
pub fn step_failure<E>(
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<StateStarted>,
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
params: FailParamsWithStep,
|
||||
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> {
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
let tm = self
|
||||
.create_pus_verif_fail_tm(
|
||||
buf,
|
||||
@ -490,10 +492,10 @@ impl VerificationReporterBasic {
|
||||
pub fn completion_success<E>(
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<StateStarted>,
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> {
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
let tm = self
|
||||
.create_pus_verif_success_tm(
|
||||
buf,
|
||||
@ -517,10 +519,10 @@ impl VerificationReporterBasic {
|
||||
pub fn completion_failure<E>(
|
||||
&mut self,
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<StateStarted>,
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> {
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
let tm = self
|
||||
.create_pus_verif_fail_tm(
|
||||
buf,
|
||||
@ -689,8 +691,8 @@ mod allocmod {
|
||||
to self.reporter {
|
||||
pub fn set_apid(&mut self, apid: u16) -> bool;
|
||||
pub fn apid(&self) -> u16;
|
||||
pub fn add_tc(&mut self, pus_tc: &PusTc) -> VerificationToken<StateNone>;
|
||||
pub fn add_tc_with_req_id(&mut self, req_id: RequestId) -> 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<TcStateNone>;
|
||||
pub fn dest_id(&self) -> 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
|
||||
pub fn acceptance_success<E>(
|
||||
&mut self,
|
||||
token: VerificationToken<StateNone>,
|
||||
token: VerificationToken<TcStateNone>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
) -> Result<VerificationToken<StateAccepted>, VerificationErrorWithToken<E, StateNone>>
|
||||
) -> Result<VerificationToken<TcStateAccepted>, VerificationErrorWithToken<E, TcStateNone>>
|
||||
{
|
||||
self.reporter.acceptance_success(
|
||||
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
|
||||
pub fn acceptance_failure<E>(
|
||||
&mut self,
|
||||
token: VerificationToken<StateNone>,
|
||||
token: VerificationToken<TcStateNone>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, StateNone>> {
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateNone>> {
|
||||
self.reporter.acceptance_failure(
|
||||
self.source_data_buf.as_mut_slice(),
|
||||
token,
|
||||
@ -736,10 +738,10 @@ mod allocmod {
|
||||
/// Requires a token previously acquired by calling [Self::acceptance_success].
|
||||
pub fn start_success<E>(
|
||||
&mut self,
|
||||
token: VerificationToken<StateAccepted>,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
) -> Result<VerificationToken<StateStarted>, VerificationErrorWithToken<E, StateAccepted>>
|
||||
) -> Result<VerificationToken<TcStateStarted>, VerificationErrorWithToken<E, TcStateAccepted>>
|
||||
{
|
||||
self.reporter.start_success(
|
||||
self.source_data_buf.as_mut_slice(),
|
||||
@ -755,10 +757,10 @@ mod allocmod {
|
||||
/// the token because verification handling is done.
|
||||
pub fn start_failure<E>(
|
||||
&mut self,
|
||||
token: VerificationToken<StateAccepted>,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, StateAccepted>> {
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateAccepted>> {
|
||||
self.reporter
|
||||
.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].
|
||||
pub fn step_success<E>(
|
||||
&mut self,
|
||||
token: &VerificationToken<StateStarted>,
|
||||
token: &VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
step: impl EcssEnumeration,
|
||||
@ -788,10 +790,10 @@ mod allocmod {
|
||||
/// token because verification handling is done.
|
||||
pub fn step_failure<E>(
|
||||
&mut self,
|
||||
token: VerificationToken<StateStarted>,
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
params: FailParamsWithStep,
|
||||
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> {
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
self.reporter
|
||||
.step_failure(self.source_data_buf.as_mut_slice(), token, sender, params)
|
||||
}
|
||||
@ -802,10 +804,10 @@ mod allocmod {
|
||||
/// token because verification handling is done.
|
||||
pub fn completion_success<E>(
|
||||
&mut self,
|
||||
token: VerificationToken<StateStarted>,
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> {
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
self.reporter.completion_success(
|
||||
self.source_data_buf.as_mut_slice(),
|
||||
token,
|
||||
@ -820,10 +822,10 @@ mod allocmod {
|
||||
/// token because verification handling is done.
|
||||
pub fn completion_failure<E>(
|
||||
&mut self,
|
||||
token: VerificationToken<StateStarted>,
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSender<Error = E> + ?Sized),
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> {
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
self.reporter.completion_failure(
|
||||
self.source_data_buf.as_mut_slice(),
|
||||
token,
|
||||
@ -857,8 +859,8 @@ mod allocmod {
|
||||
to self.reporter {
|
||||
pub fn set_apid(&mut self, apid: u16) -> bool;
|
||||
pub fn apid(&self) -> u16;
|
||||
pub fn add_tc(&mut self, pus_tc: &PusTc) -> VerificationToken<StateNone>;
|
||||
pub fn add_tc_with_req_id(&mut self, req_id: RequestId) -> 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<TcStateNone>;
|
||||
pub fn dest_id(&self) -> u16;
|
||||
pub fn set_dest_id(&mut self, dest_id: u16);
|
||||
}
|
||||
@ -866,9 +868,9 @@ mod allocmod {
|
||||
|
||||
pub fn acceptance_success(
|
||||
&mut self,
|
||||
token: VerificationToken<StateNone>,
|
||||
token: VerificationToken<TcStateNone>,
|
||||
time_stamp: &[u8],
|
||||
) -> Result<VerificationToken<StateAccepted>, VerificationErrorWithToken<E, StateNone>>
|
||||
) -> Result<VerificationToken<TcStateAccepted>, VerificationErrorWithToken<E, TcStateNone>>
|
||||
{
|
||||
self.reporter
|
||||
.acceptance_success(token, self.sender.as_mut(), time_stamp)
|
||||
@ -876,18 +878,18 @@ mod allocmod {
|
||||
|
||||
pub fn acceptance_failure(
|
||||
&mut self,
|
||||
token: VerificationToken<StateNone>,
|
||||
token: VerificationToken<TcStateNone>,
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, StateNone>> {
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateNone>> {
|
||||
self.reporter
|
||||
.acceptance_failure(token, self.sender.as_mut(), params)
|
||||
}
|
||||
|
||||
pub fn start_success(
|
||||
&mut self,
|
||||
token: VerificationToken<StateAccepted>,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
time_stamp: &[u8],
|
||||
) -> Result<VerificationToken<StateStarted>, VerificationErrorWithToken<E, StateAccepted>>
|
||||
) -> Result<VerificationToken<TcStateStarted>, VerificationErrorWithToken<E, TcStateAccepted>>
|
||||
{
|
||||
self.reporter
|
||||
.start_success(token, self.sender.as_mut(), time_stamp)
|
||||
@ -895,16 +897,16 @@ mod allocmod {
|
||||
|
||||
pub fn start_failure(
|
||||
&mut self,
|
||||
token: VerificationToken<StateAccepted>,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, StateAccepted>> {
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateAccepted>> {
|
||||
self.reporter
|
||||
.start_failure(token, self.sender.as_mut(), params)
|
||||
}
|
||||
|
||||
pub fn step_success(
|
||||
&mut self,
|
||||
token: &VerificationToken<StateStarted>,
|
||||
token: &VerificationToken<TcStateStarted>,
|
||||
time_stamp: &[u8],
|
||||
step: impl EcssEnumeration,
|
||||
) -> Result<(), EcssTmError<E>> {
|
||||
@ -914,27 +916,27 @@ mod allocmod {
|
||||
|
||||
pub fn step_failure(
|
||||
&mut self,
|
||||
token: VerificationToken<StateStarted>,
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
params: FailParamsWithStep,
|
||||
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> {
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
self.reporter
|
||||
.step_failure(token, self.sender.as_mut(), params)
|
||||
}
|
||||
|
||||
pub fn completion_success(
|
||||
&mut self,
|
||||
token: VerificationToken<StateStarted>,
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
time_stamp: &[u8],
|
||||
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> {
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
self.reporter
|
||||
.completion_success(token, self.sender.as_mut(), time_stamp)
|
||||
}
|
||||
|
||||
pub fn completion_failure(
|
||||
&mut self,
|
||||
token: VerificationToken<StateStarted>,
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, StateStarted>> {
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
self.reporter
|
||||
.completion_failure(token, self.sender.as_mut(), params)
|
||||
}
|
||||
@ -1092,7 +1094,7 @@ mod stdmod {
|
||||
mod tests {
|
||||
use crate::pus::tests::CommonTmInfo;
|
||||
use crate::pus::verification::{
|
||||
EcssTmError, EcssTmSender, FailParams, FailParamsWithStep, RequestId, StateNone,
|
||||
EcssTmError, EcssTmSender, FailParams, FailParamsWithStep, RequestId, TcStateNone,
|
||||
VerificationReporter, VerificationReporterCfg, VerificationReporterWithSender,
|
||||
VerificationToken,
|
||||
};
|
||||
@ -1193,7 +1195,7 @@ mod tests {
|
||||
(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 (tc, req_id) = base_tc_init(None);
|
||||
let init_tok;
|
||||
@ -1207,7 +1209,7 @@ mod tests {
|
||||
|
||||
fn base_with_helper_init() -> (
|
||||
TestBaseWithHelper<'static, ()>,
|
||||
VerificationToken<StateNone>,
|
||||
VerificationToken<TcStateNone>,
|
||||
) {
|
||||
let mut reporter = base_reporter();
|
||||
let (tc, _) = base_tc_init(None);
|
||||
|
@ -2,20 +2,25 @@ mod ccsds;
|
||||
mod pus;
|
||||
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::events::EventU32;
|
||||
use fsrc_core::hal::host::udp_server::UdpTcServer;
|
||||
use fsrc_core::params::Params;
|
||||
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::{
|
||||
MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender,
|
||||
};
|
||||
use fsrc_core::pus::{EcssTmError, EcssTmSender};
|
||||
use fsrc_core::tmtc::CcsdsError;
|
||||
use fsrc_example::{OBSW_SERVER_ADDR, SERVER_PORT};
|
||||
use spacepackets::time::{CdsShortTimeProvider, TimeWriter};
|
||||
use spacepackets::tm::PusTm;
|
||||
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::thread;
|
||||
|
||||
@ -32,6 +37,28 @@ struct 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() {
|
||||
println!("Running OBSW example");
|
||||
let pool_cfg = PoolCfg::new(vec![(8, 32), (4, 64), (2, 128)]);
|
||||
@ -41,32 +68,38 @@ fn main() {
|
||||
pool: tm_store.clone(),
|
||||
};
|
||||
let addr = SocketAddr::new(IpAddr::V4(OBSW_SERVER_ADDR), SERVER_PORT);
|
||||
let (tm_funnel_tx, tm_funnel_rx) = mpsc::channel();
|
||||
let (tm_server_tx, tm_server_rx) = mpsc::channel();
|
||||
let (tm_funnel_tx, tm_funnel_rx) = channel();
|
||||
let (tm_server_tx, tm_server_rx) = channel();
|
||||
let sender = MpscVerifSender::new(tm_store.clone(), tm_funnel_tx.clone());
|
||||
let verif_cfg = VerificationReporterCfg::new(PUS_APID, 1, 2, 8).unwrap();
|
||||
let reporter_with_sender_0 = Arc::new(Mutex::new(VerificationReporterWithSender::new(
|
||||
verif_cfg,
|
||||
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_recv = MpscEventReceiver::<EventU32>::new(event_man_rx);
|
||||
let mut event_man = EventManager::new(Box::new(event_recv));
|
||||
let event_reporter = EventReporter::new(PUS_APID, 128).unwrap();
|
||||
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_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);
|
||||
|
||||
// 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 || {
|
||||
core_tmtc_task(
|
||||
tm_funnel_tx.clone(),
|
||||
tm_server_rx,
|
||||
tm_store_helper.clone(),
|
||||
addr,
|
||||
reporter_with_sender_0.clone(),
|
||||
event_sender.clone(),
|
||||
);
|
||||
core_tmtc_task(core_args, tm_server_rx, addr, reporter_with_sender_0);
|
||||
});
|
||||
|
||||
let jh1 = thread::spawn(move || {
|
||||
@ -84,10 +117,43 @@ fn main() {
|
||||
}
|
||||
});
|
||||
|
||||
let jh2 = thread::spawn(move || loop {
|
||||
match pus_event_man_rx.try_recv() {
|
||||
Ok(_) => {}
|
||||
Err(_) => {}
|
||||
let jh2 = thread::spawn(move || {
|
||||
let mut timestamp: [u8; 7] = [0; 7];
|
||||
let mut sender = EventTmSender::new(tm_store_helper, tm_funnel_tx);
|
||||
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, ×tamp);
|
||||
}
|
||||
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, ×tamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
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, ×tamp, event, None)
|
||||
.expect("Sending TM as event failed");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -95,3 +161,12 @@ fn main() {
|
||||
jh1.join().expect("Joining TM Funnel 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");
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::tmtc::TmStore;
|
||||
use fsrc_core::pool::StoreAddr;
|
||||
use fsrc_core::pus::verification::{
|
||||
SharedStdVerifReporterWithSender, StateAccepted, VerificationToken,
|
||||
SharedStdVerifReporterWithSender, TcStateAccepted, VerificationToken,
|
||||
};
|
||||
use fsrc_core::tmtc::tm_helper::PusTmWithCdsShortHelper;
|
||||
use fsrc_core::tmtc::PusServiceProvider;
|
||||
@ -71,7 +71,7 @@ impl PusServiceProvider for 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 {
|
||||
println!("Received PUS ping command TC[17,1]");
|
||||
println!("Sending ping reply PUS TM[17,2]");
|
||||
|
@ -11,12 +11,20 @@ use crate::ccsds::CcsdsReceiver;
|
||||
use crate::pus::PusReceiver;
|
||||
use crate::UdpTmtcServer;
|
||||
use fsrc_core::pool::{SharedPool, StoreAddr};
|
||||
use fsrc_core::pus::event_man::EventRequestWithToken;
|
||||
use fsrc_core::pus::verification::SharedStdVerifReporterWithSender;
|
||||
use fsrc_core::tmtc::{CcsdsDistributor, CcsdsError, PusDistributor};
|
||||
use spacepackets::tm::PusTm;
|
||||
|
||||
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)]
|
||||
pub struct TmStore {
|
||||
pub pool: SharedPool,
|
||||
@ -34,17 +42,15 @@ impl TmStore {
|
||||
}
|
||||
|
||||
pub fn core_tmtc_task(
|
||||
tm_creator_tx: Sender<StoreAddr>,
|
||||
args: CoreTmtcArgs,
|
||||
tm_server_rx: mpsc::Receiver<StoreAddr>,
|
||||
tm_store_helper: TmStore,
|
||||
addr: SocketAddr,
|
||||
verif_reporter: SharedStdVerifReporterWithSender,
|
||||
_event_tx: Sender<(EventU32, Option<Params>)>,
|
||||
) {
|
||||
let pus_receiver = PusReceiver::new(
|
||||
PUS_APID,
|
||||
tm_creator_tx,
|
||||
tm_store_helper.clone(),
|
||||
args.tm_sender,
|
||||
args.tm_store.clone(),
|
||||
verif_reporter,
|
||||
);
|
||||
let pus_distributor = PusDistributor::new(Box::new(pus_receiver));
|
||||
@ -58,7 +64,7 @@ pub fn core_tmtc_task(
|
||||
let mut udp_tmtc_server = UdpTmtcServer {
|
||||
udp_tc_server,
|
||||
tm_rx: tm_server_rx,
|
||||
tm_store: tm_store_helper.pool.clone(),
|
||||
tm_store: args.tm_store.pool.clone(),
|
||||
};
|
||||
loop {
|
||||
core_tmtc_loop(&mut udp_tmtc_server);
|
||||
|
Loading…
Reference in New Issue
Block a user