From 8b110be07a552576f936e0b9bc66b418bdf8ac01 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 12 Nov 2022 23:37:19 +0100 Subject: [PATCH] start adding first event components in example --- fsrc-core/src/event_man.rs | 4 ++-- fsrc-core/src/pus/event_man.rs | 14 +++++++------- fsrc-core/tests/pus_events.rs | 4 ++-- fsrc-example/src/bin/obsw/main.rs | 26 +++++++++++++++++++++++++- fsrc-example/src/bin/obsw/tmtc.rs | 6 +++++- 5 files changed, 41 insertions(+), 13 deletions(-) diff --git a/fsrc-core/src/event_man.rs b/fsrc-core/src/event_man.rs index 344195a..9b2812d 100644 --- a/fsrc-core/src/event_man.rs +++ b/fsrc-core/src/event_man.rs @@ -118,9 +118,9 @@ unsafe impl Send { } -pub enum HandlerResult { +pub enum HandlerResult { Empty, - Handled(u32, Provider, Option), + Handled(u32, Event, Option), } impl EventManager { diff --git a/fsrc-core/src/pus/event_man.rs b/fsrc-core/src/pus/event_man.rs index feef852..bbfe570 100644 --- a/fsrc-core/src/pus/event_man.rs +++ b/fsrc-core/src/pus/event_man.rs @@ -120,15 +120,15 @@ impl From> for EventManError { } } -pub struct PusEventTmManager { +pub struct PusEventDispatcher { reporter: EventReporter, backend: Box>, } /// Safety: All contained fields are send as well. -unsafe impl Send for PusEventTmManager {} +unsafe impl Send for PusEventDispatcher {} -impl PusEventTmManager { +impl PusEventDispatcher { pub fn new( reporter: EventReporter, backend: Box>, @@ -137,7 +137,7 @@ impl PusEventTmManager PusEventTmManager { +impl PusEventDispatcher { pub fn enable_tm_for_event(&mut self, event: &Event) -> Result { self.backend.enable_event_reporting(event) } @@ -181,7 +181,7 @@ impl PusEventTmManager { } } -impl PusEventTmManager { +impl PusEventDispatcher { pub fn enable_tm_for_event_with_sev( &mut self, event: &EventU32TypedSev, @@ -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 backend = DefaultPusMgmtBackendProvider::::default(); - PusEventTmManager::new(reporter, Box::new(backend)) + PusEventDispatcher::new(reporter, Box::new(backend)) } #[test] diff --git a/fsrc-core/tests/pus_events.rs b/fsrc-core/tests/pus_events.rs index 8250afb..d51a5f1 100644 --- a/fsrc-core/tests/pus_events.rs +++ b/fsrc-core/tests/pus_events.rs @@ -2,7 +2,7 @@ use fsrc_core::event_man::{EventManager, MpscEventReceiver, MpscEventU32SendProv use fsrc_core::events::{EventU32, EventU32TypedSev, Severity, SeverityInfo}; use fsrc_core::params::U32Pair; 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 spacepackets::ecss::PusPacket; use spacepackets::tm::PusTm; @@ -40,7 +40,7 @@ fn test_threaded_usage() { let (event_tx, event_rx) = channel(); let reporter = EventReporter::new(0x02, 128).expect("Creating event reporter failed"); let backend = DefaultPusMgmtBackendProvider::::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 let jh0 = thread::spawn(move || { let mut sender = EventTmSender { sender: event_tx }; diff --git a/fsrc-example/src/bin/obsw/main.rs b/fsrc-example/src/bin/obsw/main.rs index a7c5de1..f276e6f 100644 --- a/fsrc-example/src/bin/obsw/main.rs +++ b/fsrc-example/src/bin/obsw/main.rs @@ -3,14 +3,19 @@ mod pus; mod tmtc; 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::params::Params; use fsrc_core::pool::{LocalPool, PoolCfg, SharedPool, StoreAddr}; +use fsrc_core::pus::event_man::{DefaultPusMgmtBackendProvider, EventReporter, PusEventDispatcher}; use fsrc_core::pus::verification::{ MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender, }; use fsrc_core::tmtc::CcsdsError; use fsrc_example::{OBSW_SERVER_ADDR, SERVER_PORT}; use std::net::{IpAddr, SocketAddr}; +use std::sync::mpsc::{channel, TryRecvError}; use std::sync::{mpsc, Arc, Mutex, RwLock}; use std::thread; @@ -44,13 +49,23 @@ fn main() { verif_cfg, Box::new(sender), ))); + let (event_sender, event_man_rx) = channel(); + let event_recv = MpscEventReceiver::::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::::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 || { core_tmtc_task( tm_funnel_tx.clone(), tm_server_rx, tm_store_helper.clone(), 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"); jh1.join().expect("Joining TM Funnel thread failed"); + jh2.join().expect("Joining Event Manager thread failed"); } diff --git a/fsrc-example/src/bin/obsw/tmtc.rs b/fsrc-example/src/bin/obsw/tmtc.rs index 3b3e88e..56352b0 100644 --- a/fsrc-example/src/bin/obsw/tmtc.rs +++ b/fsrc-example/src/bin/obsw/tmtc.rs @@ -1,6 +1,9 @@ +use fsrc_core::events::EventU32; use fsrc_core::hal::host::udp_server::{ReceiveResult, UdpTcServer}; +use fsrc_core::params::Params; use std::net::SocketAddr; use std::sync::mpsc; +use std::sync::mpsc::Sender; use std::thread; use std::time::Duration; @@ -31,11 +34,12 @@ impl TmStore { } pub fn core_tmtc_task( - tm_creator_tx: mpsc::Sender, + tm_creator_tx: Sender, tm_server_rx: mpsc::Receiver, tm_store_helper: TmStore, addr: SocketAddr, verif_reporter: SharedStdVerifReporterWithSender, + _event_tx: Sender<(EventU32, Option)>, ) { let pus_receiver = PusReceiver::new( PUS_APID,