update scheduler helper
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit

This commit is contained in:
Robin Müller 2024-02-01 15:43:17 +01:00
parent 80fd8bc13e
commit 2ff0da633e
Signed by: muellerr
GPG Key ID: A649FB78196E3849
4 changed files with 72 additions and 38 deletions

View File

@ -150,10 +150,9 @@ mod tests {
impl Pus5HandlerWithStoreTester { impl Pus5HandlerWithStoreTester {
pub fn new(event_request_tx: Sender<EventRequestWithToken>) -> Self { pub fn new(event_request_tx: Sender<EventRequestWithToken>) -> Self {
let (common, srv_handler) = PusServiceHandlerWithStoreCommon::new(); let (common, srv_handler) = PusServiceHandlerWithStoreCommon::new();
let pus_17_handler = PusService5EventHandler::new(srv_handler, event_request_tx);
Self { Self {
common, common,
handler: pus_17_handler, handler: PusService5EventHandler::new(srv_handler, event_request_tx)
} }
} }
} }

View File

@ -1,12 +1,9 @@
use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHelper};
use crate::pool::SharedPool; use crate::pool::SharedPool;
use crate::pus::scheduler::PusScheduler; use crate::pus::scheduler::PusScheduler;
use crate::pus::{EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError}; use crate::pus::{PusPacketHandlerResult, PusPacketHandlingError};
use spacepackets::ecss::{scheduling, PusPacket}; use spacepackets::ecss::{scheduling, PusPacket};
use spacepackets::time::cds::TimeProvider; use spacepackets::time::cds::TimeProvider;
use std::boxed::Box;
use super::verification::VerificationReporterWithSender;
use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHelper};
/// This is a helper class for [std] environments to handle generic PUS 11 (scheduling service) /// This is a helper class for [std] environments to handle generic PUS 11 (scheduling service)
/// packets. This handler is constrained to using the [PusScheduler], but is able to process /// packets. This handler is constrained to using the [PusScheduler], but is able to process
@ -17,29 +14,19 @@ use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHelper};
/// [Self::scheduler] and [Self::scheduler_mut] function and then use the scheduler API to release /// [Self::scheduler] and [Self::scheduler_mut] function and then use the scheduler API to release
/// telecommands when applicable. /// telecommands when applicable.
pub struct PusService11SchedHandler<TcInMemConverter: EcssTcInMemConverter> { pub struct PusService11SchedHandler<TcInMemConverter: EcssTcInMemConverter> {
pub psb: PusServiceHelper<TcInMemConverter>, pub service_helper: PusServiceHelper<TcInMemConverter>,
shared_tc_store: SharedPool, shared_tc_store: SharedPool,
scheduler: PusScheduler, scheduler: PusScheduler,
} }
impl<TcInMemConverter: EcssTcInMemConverter> PusService11SchedHandler<TcInMemConverter> { impl<TcInMemConverter: EcssTcInMemConverter> PusService11SchedHandler<TcInMemConverter> {
pub fn new( pub fn new(
tc_receiver: Box<dyn EcssTcReceiver>, service_helper: PusServiceHelper<TcInMemConverter>,
tm_sender: Box<dyn EcssTmSender>,
tm_apid: u16,
verification_handler: VerificationReporterWithSender,
tc_in_mem_converter: TcInMemConverter,
shared_tc_store: SharedPool, shared_tc_store: SharedPool,
scheduler: PusScheduler, scheduler: PusScheduler,
) -> Self { ) -> Self {
Self { Self {
psb: PusServiceHelper::new( service_helper,
tc_receiver,
tm_sender,
tm_apid,
verification_handler,
tc_in_mem_converter,
),
shared_tc_store, shared_tc_store,
scheduler, scheduler,
} }
@ -54,13 +41,13 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService11SchedHandler<TcInMemCon
} }
pub fn handle_one_tc(&mut self) -> Result<PusPacketHandlerResult, PusPacketHandlingError> { pub fn handle_one_tc(&mut self) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
let possible_packet = self.psb.retrieve_and_accept_next_packet()?; let possible_packet = self.service_helper.retrieve_and_accept_next_packet()?;
if possible_packet.is_none() { if possible_packet.is_none() {
return Ok(PusPacketHandlerResult::Empty); return Ok(PusPacketHandlerResult::Empty);
} }
let ecss_tc_and_token = possible_packet.unwrap(); let ecss_tc_and_token = possible_packet.unwrap();
let tc = self let tc = self
.psb .service_helper
.tc_in_mem_converter .tc_in_mem_converter
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?; .convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token.tc_in_memory)?;
let subservice = tc.subservice(); let subservice = tc.subservice();
@ -76,7 +63,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService11SchedHandler<TcInMemCon
match std_service.unwrap() { match std_service.unwrap() {
scheduling::Subservice::TcEnableScheduling => { scheduling::Subservice::TcEnableScheduling => {
let start_token = self let start_token = self
.psb .service_helper
.common .common
.verification_handler .verification_handler
.get_mut() .get_mut()
@ -85,7 +72,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService11SchedHandler<TcInMemCon
self.scheduler.enable(); self.scheduler.enable();
if self.scheduler.is_enabled() { if self.scheduler.is_enabled() {
self.psb self.service_helper
.common .common
.verification_handler .verification_handler
.get_mut() .get_mut()
@ -97,7 +84,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService11SchedHandler<TcInMemCon
} }
scheduling::Subservice::TcDisableScheduling => { scheduling::Subservice::TcDisableScheduling => {
let start_token = self let start_token = self
.psb .service_helper
.common .common
.verification_handler .verification_handler
.get_mut() .get_mut()
@ -106,7 +93,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService11SchedHandler<TcInMemCon
self.scheduler.disable(); self.scheduler.disable();
if !self.scheduler.is_enabled() { if !self.scheduler.is_enabled() {
self.psb self.service_helper
.common .common
.verification_handler .verification_handler
.get_mut() .get_mut()
@ -118,7 +105,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService11SchedHandler<TcInMemCon
} }
scheduling::Subservice::TcResetScheduling => { scheduling::Subservice::TcResetScheduling => {
let start_token = self let start_token = self
.psb .service_helper
.common .common
.verification_handler .verification_handler
.get_mut() .get_mut()
@ -131,7 +118,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService11SchedHandler<TcInMemCon
.reset(pool.as_mut()) .reset(pool.as_mut())
.expect("Error resetting TC Pool"); .expect("Error resetting TC Pool");
self.psb self.service_helper
.common .common
.verification_handler .verification_handler
.get_mut() .get_mut()
@ -140,7 +127,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService11SchedHandler<TcInMemCon
} }
scheduling::Subservice::TcInsertActivity => { scheduling::Subservice::TcInsertActivity => {
let start_token = self let start_token = self
.psb .service_helper
.common .common
.verification_handler .verification_handler
.get_mut() .get_mut()
@ -152,7 +139,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService11SchedHandler<TcInMemCon
.insert_wrapped_tc::<TimeProvider>(&tc, pool.as_mut()) .insert_wrapped_tc::<TimeProvider>(&tc, pool.as_mut())
.expect("insertion of activity into pool failed"); .expect("insertion of activity into pool failed");
self.psb self.service_helper
.common .common
.verification_handler .verification_handler
.get_mut() .get_mut()
@ -177,4 +164,51 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService11SchedHandler<TcInMemCon
} }
#[cfg(test)] #[cfg(test)]
mod tests {} mod tests {
use crate::{
events::EventU32,
pool::SharedPool,
pus::{
scheduler::{PusScheduler, RequestId},
tests::{PusServiceHandlerWithStoreCommon, PusTestHarness},
verification::{TcStateAccepted, VerificationToken},
EcssTcInStoreConverter, PusPacketHandlerResult, PusPacketHandlingError,
},
};
use delegate::delegate;
use spacepackets::ecss::{tc::PusTcCreator, tm::PusTmReader};
use super::PusService11SchedHandler;
const TEST_EVENT_0: EventU32 = EventU32::const_new(crate::events::Severity::INFO, 5, 25);
struct Pus11HandlerWithStoreTester {
common: PusServiceHandlerWithStoreCommon,
handler: PusService11SchedHandler<EcssTcInStoreConverter>,
}
impl Pus11HandlerWithStoreTester {
pub fn new(shared_tc_store: SharedPool, scheduler: PusScheduler) -> Self {
let (common, srv_handler) = PusServiceHandlerWithStoreCommon::new();
Self {
common,
handler: PusService11SchedHandler::new(srv_handler, shared_tc_store, scheduler),
}
}
}
impl PusTestHarness for Pus11HandlerWithStoreTester {
delegate! {
to self.common {
fn send_tc(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted>;
fn read_next_tm(&mut self) -> PusTmReader<'_>;
fn check_no_tm_available(&self) -> bool;
fn check_next_verification_tm(&self, subservice: u8, expected_request_id: RequestId);
}
to self.handler {
fn handle_one_tc(&mut self) -> Result<PusPacketHandlerResult, PusPacketHandlingError>;
}
}
}
}

View File

@ -151,10 +151,9 @@ mod tests {
impl Pus17HandlerWithVecTester { impl Pus17HandlerWithVecTester {
pub fn new() -> Self { pub fn new() -> Self {
let (common, srv_handler) = PusServiceHandlerWithVecCommon::new(); let (common, srv_handler) = PusServiceHandlerWithVecCommon::new();
let pus_17_handler = PusService17TestHandler::new(srv_handler);
Self { Self {
common, common,
handler: pus_17_handler, handler: PusService17TestHandler::new(srv_handler)
} }
} }
} }

View File

@ -205,11 +205,13 @@ fn main() {
let scheduler = PusScheduler::new_with_current_init_time(Duration::from_secs(5)) let scheduler = PusScheduler::new_with_current_init_time(Duration::from_secs(5))
.expect("Creating PUS Scheduler failed"); .expect("Creating PUS Scheduler failed");
let pus_11_handler = PusService11SchedHandler::new( let pus_11_handler = PusService11SchedHandler::new(
Box::new(sched_srv_receiver), PusServiceHelper::new(
Box::new(sched_srv_tm_sender), Box::new(sched_srv_receiver),
PUS_APID, Box::new(sched_srv_tm_sender),
verif_reporter.clone(), PUS_APID,
EcssTcInStoreConverter::new(tc_store.pool.clone(), 2048), verif_reporter.clone(),
EcssTcInStoreConverter::new(tc_store.pool.clone(), 2048),
),
tc_store.pool.clone(), tc_store.pool.clone(),
scheduler, scheduler,
); );