start adding first event components in example

This commit is contained in:
Robin Müller 2022-11-12 23:37:19 +01:00
parent cf556a407f
commit 8b110be07a
No known key found for this signature in database
GPG Key ID: BE6480244DFE612C
5 changed files with 41 additions and 13 deletions

View File

@ -118,9 +118,9 @@ unsafe impl<E, Event: GenericEvent + Send, AuxDataProvider: Send> Send
{ {
} }
pub enum HandlerResult<Provider: GenericEvent, AuxDataProvider> { pub enum HandlerResult<Event: GenericEvent, AuxDataProvider> {
Empty, Empty,
Handled(u32, Provider, Option<AuxDataProvider>), Handled(u32, Event, Option<AuxDataProvider>),
} }
impl<E, Event: GenericEvent + Copy> EventManager<E, Event> { impl<E, Event: GenericEvent + Copy> EventManager<E, Event> {

View File

@ -120,15 +120,15 @@ impl<SenderE> From<EcssTmError<SenderE>> for EventManError<SenderE> {
} }
} }
pub struct PusEventTmManager<BackendError, Provider: GenericEvent> { pub struct PusEventDispatcher<BackendError, Provider: GenericEvent> {
reporter: EventReporter, reporter: EventReporter,
backend: Box<dyn PusEventMgmtBackendProvider<Provider, Error = BackendError>>, backend: Box<dyn PusEventMgmtBackendProvider<Provider, Error = BackendError>>,
} }
/// Safety: All contained fields are send as well. /// Safety: All contained fields are send as well.
unsafe impl<E: Send, Event: GenericEvent + Send> Send for PusEventTmManager<E, Event> {} unsafe impl<E: Send, Event: GenericEvent + Send> Send for PusEventDispatcher<E, Event> {}
impl<BackendError, Provider: GenericEvent> PusEventTmManager<BackendError, Provider> { impl<BackendError, Provider: GenericEvent> PusEventDispatcher<BackendError, Provider> {
pub fn new( pub fn new(
reporter: EventReporter, reporter: EventReporter,
backend: Box<dyn PusEventMgmtBackendProvider<Provider, Error = BackendError>>, backend: Box<dyn PusEventMgmtBackendProvider<Provider, Error = BackendError>>,
@ -137,7 +137,7 @@ impl<BackendError, Provider: GenericEvent> PusEventTmManager<BackendError, Provi
} }
} }
impl<BackendError, Event: GenericEvent> PusEventTmManager<BackendError, Event> { impl<BackendError, Event: GenericEvent> PusEventDispatcher<BackendError, Event> {
pub fn enable_tm_for_event(&mut self, event: &Event) -> Result<bool, BackendError> { pub fn enable_tm_for_event(&mut self, event: &Event) -> Result<bool, BackendError> {
self.backend.enable_event_reporting(event) self.backend.enable_event_reporting(event)
} }
@ -181,7 +181,7 @@ impl<BackendError, Event: GenericEvent> PusEventTmManager<BackendError, Event> {
} }
} }
impl<BackendError> PusEventTmManager<BackendError, EventU32> { impl<BackendError> PusEventDispatcher<BackendError, EventU32> {
pub fn enable_tm_for_event_with_sev<Severity: HasSeverity>( pub fn enable_tm_for_event_with_sev<Severity: HasSeverity>(
&mut self, &mut self,
event: &EventU32TypedSev<Severity>, event: &EventU32TypedSev<Severity>,
@ -234,10 +234,10 @@ mod tests {
} }
} }
fn create_basic_man() -> PusEventTmManager<(), EventU32> { fn create_basic_man() -> PusEventDispatcher<(), EventU32> {
let reporter = EventReporter::new(0x02, 128).expect("Creating event repoter failed"); let reporter = EventReporter::new(0x02, 128).expect("Creating event repoter failed");
let backend = DefaultPusMgmtBackendProvider::<EventU32>::default(); let backend = DefaultPusMgmtBackendProvider::<EventU32>::default();
PusEventTmManager::new(reporter, Box::new(backend)) PusEventDispatcher::new(reporter, Box::new(backend))
} }
#[test] #[test]

View File

@ -2,7 +2,7 @@ use fsrc_core::event_man::{EventManager, MpscEventReceiver, MpscEventU32SendProv
use fsrc_core::events::{EventU32, EventU32TypedSev, Severity, SeverityInfo}; use fsrc_core::events::{EventU32, EventU32TypedSev, Severity, SeverityInfo};
use fsrc_core::params::U32Pair; use fsrc_core::params::U32Pair;
use fsrc_core::params::{Params, ParamsHeapless, WritableToBeBytes}; use fsrc_core::params::{Params, ParamsHeapless, WritableToBeBytes};
use fsrc_core::pus::event_man::{DefaultPusMgmtBackendProvider, EventReporter, PusEventTmManager}; use fsrc_core::pus::event_man::{DefaultPusMgmtBackendProvider, EventReporter, PusEventDispatcher};
use fsrc_core::pus::{EcssTmError, EcssTmSender}; use fsrc_core::pus::{EcssTmError, EcssTmSender};
use spacepackets::ecss::PusPacket; use spacepackets::ecss::PusPacket;
use spacepackets::tm::PusTm; use spacepackets::tm::PusTm;
@ -40,7 +40,7 @@ fn test_threaded_usage() {
let (event_tx, event_rx) = channel(); let (event_tx, event_rx) = channel();
let reporter = EventReporter::new(0x02, 128).expect("Creating event reporter failed"); let reporter = EventReporter::new(0x02, 128).expect("Creating event reporter failed");
let backend = DefaultPusMgmtBackendProvider::<EventU32>::default(); let backend = DefaultPusMgmtBackendProvider::<EventU32>::default();
let mut pus_event_man = PusEventTmManager::new(reporter, Box::new(backend)); let mut pus_event_man = PusEventDispatcher::new(reporter, Box::new(backend));
// PUS + Generic event manager thread // PUS + Generic event manager thread
let jh0 = thread::spawn(move || { let jh0 = thread::spawn(move || {
let mut sender = EventTmSender { sender: event_tx }; let mut sender = EventTmSender { sender: event_tx };

View File

@ -3,14 +3,19 @@ mod pus;
mod tmtc; mod tmtc;
use crate::tmtc::{core_tmtc_task, TmStore, PUS_APID}; use crate::tmtc::{core_tmtc_task, 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::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::verification::{ use fsrc_core::pus::verification::{
MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender, MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender,
}; };
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 std::net::{IpAddr, SocketAddr}; use std::net::{IpAddr, SocketAddr};
use std::sync::mpsc::{channel, TryRecvError};
use std::sync::{mpsc, Arc, Mutex, RwLock}; use std::sync::{mpsc, Arc, Mutex, RwLock};
use std::thread; use std::thread;
@ -44,13 +49,23 @@ fn main() {
verif_cfg, verif_cfg,
Box::new(sender), Box::new(sender),
))); )));
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 (pus_event_man_tx, pus_event_man_rx) = channel();
let pus_event_man_send_provider = MpscEventU32SendProvider::new(1, pus_event_man_tx);
event_man.subscribe_all(pus_event_man_send_provider);
let jh0 = thread::spawn(move || { let jh0 = thread::spawn(move || {
core_tmtc_task( core_tmtc_task(
tm_funnel_tx.clone(), tm_funnel_tx.clone(),
tm_server_rx, tm_server_rx,
tm_store_helper.clone(), tm_store_helper.clone(),
addr, addr,
reporter_with_sender_0, reporter_with_sender_0.clone(),
event_sender.clone(),
); );
}); });
@ -68,6 +83,15 @@ fn main() {
} }
} }
}); });
let jh2 = thread::spawn(move || loop {
match pus_event_man_rx.try_recv() {
Ok(_) => {}
Err(_) => {}
}
});
jh0.join().expect("Joining UDP TMTC server thread failed"); jh0.join().expect("Joining UDP TMTC server thread failed");
jh1.join().expect("Joining TM Funnel thread failed"); jh1.join().expect("Joining TM Funnel thread failed");
jh2.join().expect("Joining Event Manager thread failed");
} }

View File

@ -1,6 +1,9 @@
use fsrc_core::events::EventU32;
use fsrc_core::hal::host::udp_server::{ReceiveResult, UdpTcServer}; use fsrc_core::hal::host::udp_server::{ReceiveResult, UdpTcServer};
use fsrc_core::params::Params;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::sync::mpsc; use std::sync::mpsc;
use std::sync::mpsc::Sender;
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
@ -31,11 +34,12 @@ impl TmStore {
} }
pub fn core_tmtc_task( pub fn core_tmtc_task(
tm_creator_tx: mpsc::Sender<StoreAddr>, tm_creator_tx: Sender<StoreAddr>,
tm_server_rx: mpsc::Receiver<StoreAddr>, tm_server_rx: mpsc::Receiver<StoreAddr>,
tm_store_helper: TmStore, 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,