start adding event service
This commit is contained in:
parent
d2e896fc92
commit
363770066d
@ -136,13 +136,13 @@ mod alloc_mod {
|
||||
pub mod std_mod {
|
||||
use crate::pool::{ShareablePoolProvider, SharedPool, StoreAddr, StoreError};
|
||||
use crate::pus::verification::{
|
||||
StdVerifReporterWithSender, TcStateAccepted, VerificationToken,
|
||||
FailParams, StdVerifReporterWithSender, TcStateAccepted, VerificationToken,
|
||||
};
|
||||
use crate::pus::{EcssSender, EcssTcSenderCore, EcssTmSenderCore};
|
||||
use crate::tmtc::tm_helper::SharedTmStore;
|
||||
use crate::SenderId;
|
||||
use alloc::vec::Vec;
|
||||
use spacepackets::ecss::{PusError, SerializablePusPacket};
|
||||
use spacepackets::ecss::{EcssEnumeration, PusError, SerializablePusPacket};
|
||||
use spacepackets::tc::PusTc;
|
||||
use spacepackets::time::cds::TimeProvider;
|
||||
use spacepackets::time::{StdTimestampError, TimeWriter};
|
||||
@ -315,7 +315,7 @@ pub mod std_mod {
|
||||
pub enum PusPacketHandlerResult {
|
||||
RequestHandled,
|
||||
RequestHandledPartialSuccess(PartialPusHandlingError),
|
||||
CustomSubservice(VerificationToken<TcStateAccepted>),
|
||||
CustomSubservice(u8, VerificationToken<TcStateAccepted>),
|
||||
Empty,
|
||||
}
|
||||
|
||||
@ -372,6 +372,20 @@ pub mod std_mod {
|
||||
Err(time_provider.unwrap_err())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn report_start_failure(
|
||||
&mut self,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
failure_code: &impl EcssEnumeration,
|
||||
failure_data: Option<&[u8]>,
|
||||
) -> Result<(), VerificationToken<TcStateAccepted>> {
|
||||
self.verification_handler
|
||||
.start_failure(
|
||||
token,
|
||||
FailParams::new(Some(&self.stamp_buf), failure_code, failure_data),
|
||||
)
|
||||
.map_err(|e| e.1)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait PusServiceHandler {
|
||||
|
@ -69,7 +69,10 @@ impl PusServiceHandler for PusService11SchedHandler {
|
||||
let (tc, _) = PusTc::from_bytes(&self.psb.pus_buf).unwrap();
|
||||
let std_service = scheduling::Subservice::try_from(tc.subservice());
|
||||
if std_service.is_err() {
|
||||
return Ok(PusPacketHandlerResult::CustomSubservice(token));
|
||||
return Ok(PusPacketHandlerResult::CustomSubservice(
|
||||
tc.subservice(),
|
||||
token,
|
||||
));
|
||||
}
|
||||
//let partial_error = self.psb.update_stamp().err();
|
||||
let time_provider =
|
||||
@ -155,7 +158,10 @@ impl PusServiceHandler for PusService11SchedHandler {
|
||||
.expect("sending completion success failed");
|
||||
}
|
||||
_ => {
|
||||
return Ok(PusPacketHandlerResult::CustomSubservice(token));
|
||||
return Ok(PusPacketHandlerResult::CustomSubservice(
|
||||
tc.subservice(),
|
||||
token,
|
||||
));
|
||||
}
|
||||
}
|
||||
if let Some(partial_error) = partial_error {
|
||||
@ -163,6 +169,9 @@ impl PusServiceHandler for PusService11SchedHandler {
|
||||
partial_error,
|
||||
));
|
||||
}
|
||||
Ok(PusPacketHandlerResult::CustomSubservice(token))
|
||||
Ok(PusPacketHandlerResult::CustomSubservice(
|
||||
tc.subservice(),
|
||||
token,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -109,6 +109,9 @@ impl PusServiceHandler for PusService17TestHandler {
|
||||
};
|
||||
return Ok(PusPacketHandlerResult::RequestHandled);
|
||||
}
|
||||
Ok(PusPacketHandlerResult::CustomSubservice(token))
|
||||
Ok(PusPacketHandlerResult::CustomSubservice(
|
||||
tc.subservice(),
|
||||
token,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ use log::{info, warn};
|
||||
|
||||
use crate::hk::AcsHkIds;
|
||||
use crate::logging::setup_logger;
|
||||
use crate::pus::scheduler::Pus11Wrapper;
|
||||
use crate::pus::test::Service17CustomWrapper;
|
||||
use crate::pus::PusTcMpscRouter;
|
||||
use crate::requests::{Request, RequestWithToken};
|
||||
@ -26,6 +27,8 @@ use satrs_core::pus::event_man::{
|
||||
PusEventDispatcher,
|
||||
};
|
||||
use satrs_core::pus::hk::Subservice as HkSubservice;
|
||||
use satrs_core::pus::scheduler::PusScheduler;
|
||||
use satrs_core::pus::scheduler_srv::PusService11SchedHandler;
|
||||
use satrs_core::pus::test::PusService17TestHandler;
|
||||
use satrs_core::pus::verification::{
|
||||
MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender,
|
||||
@ -173,12 +176,24 @@ fn main() {
|
||||
tm_funnel_tx.clone(),
|
||||
tm_store.clone(),
|
||||
PUS_APID,
|
||||
verif_reporter,
|
||||
verif_reporter.clone(),
|
||||
);
|
||||
let mut srv_17_wrapper = Service17CustomWrapper {
|
||||
let mut pus_17_wrapper = Service17CustomWrapper {
|
||||
pus17_handler,
|
||||
test_srv_event_sender,
|
||||
};
|
||||
let scheduler = PusScheduler::new_with_current_init_time(Duration::from_secs(5))
|
||||
.expect("Creating PUS Scheduler failed");
|
||||
let pus11_handler = PusService11SchedHandler::new(
|
||||
pus_sched_rx,
|
||||
tc_store.pool.clone(),
|
||||
tm_funnel_tx.clone(),
|
||||
tm_store.clone(),
|
||||
PUS_APID,
|
||||
verif_reporter,
|
||||
scheduler,
|
||||
);
|
||||
let mut pus_11_wrapper = Pus11Wrapper { pus11_handler };
|
||||
|
||||
info!("Starting TMTC task");
|
||||
let jh0 = thread::Builder::new()
|
||||
@ -343,8 +358,15 @@ fn main() {
|
||||
let jh4 = thread::Builder::new()
|
||||
.name("PUS".to_string())
|
||||
.spawn(move || loop {
|
||||
let queue_empty = srv_17_wrapper.perform_operation();
|
||||
if queue_empty {
|
||||
let mut all_queues_empty = true;
|
||||
let mut is_srv_finished = |srv_handler_finished: bool| {
|
||||
if !srv_handler_finished {
|
||||
all_queues_empty = false;
|
||||
}
|
||||
};
|
||||
is_srv_finished(pus_17_wrapper.perform_operation());
|
||||
is_srv_finished(pus_11_wrapper.perform_operation());
|
||||
if all_queues_empty {
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
}
|
||||
})
|
||||
|
59
satrs-example/src/pus/events.rs
Normal file
59
satrs-example/src/pus/events.rs
Normal file
@ -0,0 +1,59 @@
|
||||
use satrs_core::event_man::{EventManager, EventManagerWithMpscQueue};
|
||||
use satrs_core::events::EventU32;
|
||||
use satrs_core::params::Params;
|
||||
use satrs_core::pool::{SharedPool, StoreAddr};
|
||||
use satrs_core::pus::event_man::EventReporter;
|
||||
use satrs_core::pus::verification::{
|
||||
StdVerifReporterWithSender, TcStateAccepted, VerificationToken,
|
||||
};
|
||||
use satrs_core::pus::{
|
||||
AcceptedTc, PusPacketHandlerResult, PusPacketHandlingError, PusServiceBase, PusServiceHandler,
|
||||
};
|
||||
use satrs_core::tmtc::tm_helper::SharedTmStore;
|
||||
use std::sync::mpsc::{Receiver, Sender};
|
||||
|
||||
pub struct PusService5EventHandler {
|
||||
psb: PusServiceBase,
|
||||
event_manager: EventManagerWithMpscQueue<EventU32, Params>,
|
||||
}
|
||||
|
||||
impl PusService5EventHandler {
|
||||
pub fn new(
|
||||
receiver: Receiver<AcceptedTc>,
|
||||
tc_pool: SharedPool,
|
||||
tm_tx: Sender<StoreAddr>,
|
||||
tm_store: SharedTmStore,
|
||||
tm_apid: u16,
|
||||
verification_handler: StdVerifReporterWithSender,
|
||||
event_manager: EventManagerWithMpscQueue<EventU32, Params>,
|
||||
) -> Self {
|
||||
Self {
|
||||
psb: PusServiceBase::new(
|
||||
receiver,
|
||||
tc_pool,
|
||||
tm_tx,
|
||||
tm_store,
|
||||
tm_apid,
|
||||
verification_handler,
|
||||
),
|
||||
event_manager,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PusServiceHandler for PusService5EventHandler {
|
||||
fn psb_mut(&mut self) -> &mut PusServiceBase {
|
||||
&mut self.psb
|
||||
}
|
||||
fn psb(&self) -> &PusServiceBase {
|
||||
&self.psb
|
||||
}
|
||||
|
||||
fn handle_one_tc(
|
||||
&mut self,
|
||||
addr: StoreAddr,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
|
||||
Ok(PusPacketHandlerResult::RequestHandled)
|
||||
}
|
||||
}
|
@ -13,14 +13,10 @@ use satrs_core::tmtc::tm_helper::{PusTmWithCdsShortHelper, SharedTmStore};
|
||||
use satrs_example::{tmtc_err, CustomPusServiceId};
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
pub mod events;
|
||||
pub mod scheduler;
|
||||
pub mod test;
|
||||
|
||||
pub enum PusTcWrapper<'tc> {
|
||||
PusTc(&'tc PusTc<'tc>),
|
||||
StoreAddr(StoreAddr),
|
||||
}
|
||||
|
||||
pub struct PusTcMpscRouter {
|
||||
pub test_service_receiver: Sender<AcceptedTc>,
|
||||
pub event_service_receiver: Sender<AcceptedTc>,
|
||||
|
@ -1 +1,30 @@
|
||||
use log::{error, warn};
|
||||
use satrs_core::pus::scheduler_srv::PusService11SchedHandler;
|
||||
use satrs_core::pus::{PusPacketHandlerResult, PusServiceHandler};
|
||||
|
||||
pub struct Pus11Wrapper {
|
||||
pub pus11_handler: PusService11SchedHandler,
|
||||
}
|
||||
|
||||
impl Pus11Wrapper {
|
||||
pub fn perform_operation(&mut self) -> bool {
|
||||
match self.pus11_handler.handle_next_packet() {
|
||||
Ok(result) => match result {
|
||||
PusPacketHandlerResult::RequestHandled => {}
|
||||
PusPacketHandlerResult::RequestHandledPartialSuccess(e) => {
|
||||
warn!("PUS11 partial packet handling success: {e:?}")
|
||||
}
|
||||
PusPacketHandlerResult::CustomSubservice(invalid, _) => {
|
||||
warn!("PUS11 invalid subservice {invalid}");
|
||||
}
|
||||
PusPacketHandlerResult::Empty => {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
Err(error) => {
|
||||
error!("PUS packet handling error: {error:?}")
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ use log::{info, warn};
|
||||
use satrs_core::events::EventU32;
|
||||
use satrs_core::params::Params;
|
||||
use satrs_core::pus::test::PusService17TestHandler;
|
||||
use satrs_core::pus::verification::FailParams;
|
||||
use satrs_core::pus::{PusPacketHandlerResult, PusServiceHandler};
|
||||
use satrs_core::spacepackets::ecss::PusPacket;
|
||||
use satrs_core::spacepackets::tc::PusTc;
|
||||
@ -34,13 +33,13 @@ impl Service17CustomWrapper {
|
||||
partial_err
|
||||
);
|
||||
}
|
||||
PusPacketHandlerResult::CustomSubservice(token) => {
|
||||
PusPacketHandlerResult::CustomSubservice(subservice, token) => {
|
||||
let (buf, _) = self.pus17_handler.pus_tc_buf();
|
||||
let (tc, _) = PusTc::from_bytes(buf).unwrap();
|
||||
let time_stamper = TimeProvider::from_now_with_u16_days().unwrap();
|
||||
let mut stamp_buf: [u8; 7] = [0; 7];
|
||||
time_stamper.write_to_bytes(&mut stamp_buf).unwrap();
|
||||
if tc.subservice() == 128 {
|
||||
if subservice == 128 {
|
||||
info!("Generating test event");
|
||||
self.test_srv_event_sender
|
||||
.send((TEST_EVENT.into(), None))
|
||||
@ -57,14 +56,11 @@ impl Service17CustomWrapper {
|
||||
} else {
|
||||
let fail_data = [tc.subservice()];
|
||||
self.pus17_handler
|
||||
.verification_reporter()
|
||||
.start_failure(
|
||||
.psb_mut()
|
||||
.report_start_failure(
|
||||
token,
|
||||
FailParams::new(
|
||||
Some(&stamp_buf),
|
||||
&tmtc_err::INVALID_PUS_SUBSERVICE,
|
||||
Some(&fail_data),
|
||||
),
|
||||
&tmtc_err::INVALID_PUS_SUBSERVICE,
|
||||
Some(&fail_data),
|
||||
)
|
||||
.expect("Sending start failure verification failed");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user