refactored PUS handlers
All checks were successful
Rust/sat-rs/pipeline/head This commit looks good

This commit is contained in:
Robin Müller 2024-01-30 01:18:48 +01:00
parent 0681f5847e
commit 5f227d1a20
Signed by: muellerr
GPG Key ID: A649FB78196E3849
9 changed files with 100 additions and 152 deletions

View File

@ -1,12 +1,10 @@
use crate::events::EventU32; use crate::events::EventU32;
use crate::pool::{SharedPool, StoreAddr}; use crate::pool::SharedPool;
use crate::pus::event_man::{EventRequest, EventRequestWithToken}; use crate::pus::event_man::{EventRequest, EventRequestWithToken};
use crate::pus::verification::{ use crate::pus::verification::{StdVerifReporterWithSender, TcStateToken};
StdVerifReporterWithSender, TcStateAccepted, TcStateToken, VerificationToken,
};
use crate::pus::{ use crate::pus::{
EcssTcReceiver, EcssTmSender, PartialPusHandlingError, PusPacketHandlerResult, EcssTcReceiver, EcssTmSender, PartialPusHandlingError, PusPacketHandlerResult,
PusPacketHandlingError, PusServiceBase, PusServiceHandler, PusPacketHandlingError, PusServiceBaseWithStore,
}; };
use alloc::boxed::Box; use alloc::boxed::Box;
use spacepackets::ecss::event::Subservice; use spacepackets::ecss::event::Subservice;
@ -15,7 +13,7 @@ use spacepackets::ecss::PusPacket;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
pub struct PusService5EventHandler { pub struct PusService5EventHandler {
psb: PusServiceBase, psb: PusServiceBaseWithStore,
event_request_tx: Sender<EventRequestWithToken>, event_request_tx: Sender<EventRequestWithToken>,
} }
@ -29,7 +27,7 @@ impl PusService5EventHandler {
event_request_tx: Sender<EventRequestWithToken>, event_request_tx: Sender<EventRequestWithToken>,
) -> Self { ) -> Self {
Self { Self {
psb: PusServiceBase::new( psb: PusServiceBaseWithStore::new(
tc_receiver, tc_receiver,
shared_tc_store, shared_tc_store,
tm_sender, tm_sender,
@ -39,22 +37,14 @@ impl PusService5EventHandler {
event_request_tx, event_request_tx,
} }
} }
}
impl PusServiceHandler for PusService5EventHandler { pub fn handle_one_tc(&mut self) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
fn psb_mut(&mut self) -> &mut PusServiceBase { let possible_packet = self.psb.retrieve_next_packet()?;
&mut self.psb if possible_packet.is_none() {
return Ok(PusPacketHandlerResult::Empty);
} }
fn psb(&self) -> &PusServiceBase { let (addr, token) = possible_packet.unwrap();
&self.psb self.psb.copy_tc_to_buf(addr)?;
}
fn handle_one_tc(
&mut self,
addr: StoreAddr,
token: VerificationToken<TcStateAccepted>,
) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
self.copy_tc_to_buf(addr)?;
let (tc, _) = PusTcReader::new(&self.psb.pus_buf)?; let (tc, _) = PusTcReader::new(&self.psb.pus_buf)?;
let subservice = tc.subservice(); let subservice = tc.subservice();
let srv = Subservice::try_from(subservice); let srv = Subservice::try_from(subservice);
@ -107,7 +97,7 @@ impl PusServiceHandler for PusService5EventHandler {
Ok(PusPacketHandlerResult::RequestHandled) Ok(PusPacketHandlerResult::RequestHandled)
}; };
let mut partial_error = None; let mut partial_error = None;
let time_stamp = self.psb().get_current_timestamp(&mut partial_error); let time_stamp = self.psb.get_current_timestamp(&mut partial_error);
match srv.unwrap() { match srv.unwrap() {
Subservice::TmInfoReport Subservice::TmInfoReport
| Subservice::TmLowSeverityReport | Subservice::TmLowSeverityReport

View File

@ -637,7 +637,7 @@ pub mod std_mod {
/// Base class for handlers which can handle PUS TC packets. Right now, the verification /// Base class for handlers which can handle PUS TC packets. Right now, the verification
/// reporter is constrained to the [StdVerifReporterWithSender] and the service handler /// reporter is constrained to the [StdVerifReporterWithSender] and the service handler
/// relies on TMTC packets being exchanged via a [SharedPool]. /// relies on TMTC packets being exchanged via a [SharedPool].
pub struct PusServiceBase { pub struct PusServiceBaseWithStore {
pub tc_receiver: Box<dyn EcssTcReceiver>, pub tc_receiver: Box<dyn EcssTcReceiver>,
pub shared_tc_store: SharedPool, pub shared_tc_store: SharedPool,
pub tm_sender: Box<dyn EcssTmSender>, pub tm_sender: Box<dyn EcssTmSender>,
@ -649,7 +649,7 @@ pub mod std_mod {
pub pus_size: usize, pub pus_size: usize,
} }
impl PusServiceBase { impl PusServiceBaseWithStore {
pub fn new( pub fn new(
tc_receiver: Box<dyn EcssTcReceiver>, tc_receiver: Box<dyn EcssTcReceiver>,
shared_tc_store: SharedPool, shared_tc_store: SharedPool,
@ -688,32 +688,24 @@ pub mod std_mod {
let mut dummy = None; let mut dummy = None;
self.get_current_timestamp(&mut dummy) self.get_current_timestamp(&mut dummy)
} }
}
pub trait PusServiceHandler { pub fn copy_tc_to_buf(&mut self, addr: StoreAddr) -> Result<(), PusPacketHandlingError> {
fn psb_mut(&mut self) -> &mut PusServiceBase;
fn psb(&self) -> &PusServiceBase;
fn handle_one_tc(
&mut self,
addr: StoreAddr,
token: VerificationToken<TcStateAccepted>,
) -> Result<PusPacketHandlerResult, PusPacketHandlingError>;
fn copy_tc_to_buf(&mut self, addr: StoreAddr) -> Result<(), PusPacketHandlingError> {
// Keep locked section as short as possible. // Keep locked section as short as possible.
let psb_mut = self.psb_mut(); let mut tc_pool = self
let mut tc_pool = psb_mut
.shared_tc_store .shared_tc_store
.write() .write()
.map_err(|_| PusPacketHandlingError::EcssTmtc(EcssTmtcError::StoreLock))?; .map_err(|_| PusPacketHandlingError::EcssTmtc(EcssTmtcError::StoreLock))?;
let tc_guard = tc_pool.read_with_guard(addr); let tc_guard = tc_pool.read_with_guard(addr);
let tc_raw = tc_guard.read().unwrap(); let tc_raw = tc_guard.read().unwrap();
psb_mut.pus_buf[0..tc_raw.len()].copy_from_slice(tc_raw); self.pus_buf[0..tc_raw.len()].copy_from_slice(tc_raw);
Ok(()) Ok(())
} }
fn handle_next_packet(&mut self) -> Result<PusPacketHandlerResult, PusPacketHandlingError> { pub fn retrieve_next_packet(
match self.psb().tc_receiver.recv_tc() { &mut self,
) -> Result<Option<(StoreAddr, VerificationToken<TcStateAccepted>)>, PusPacketHandlingError>
{
match self.tc_receiver.recv_tc() {
Ok(ReceivedTcWrapper { store_addr, token }) => { Ok(ReceivedTcWrapper { store_addr, token }) => {
if token.is_none() { if token.is_none() {
return Err(PusPacketHandlingError::InvalidVerificationToken); return Err(PusPacketHandlingError::InvalidVerificationToken);
@ -721,11 +713,11 @@ pub mod std_mod {
let token = token.unwrap(); let token = token.unwrap();
let accepted_token = VerificationToken::<TcStateAccepted>::try_from(token) let accepted_token = VerificationToken::<TcStateAccepted>::try_from(token)
.map_err(|_| PusPacketHandlingError::InvalidVerificationToken)?; .map_err(|_| PusPacketHandlingError::InvalidVerificationToken)?;
self.handle_one_tc(store_addr, accepted_token) Ok(Some((store_addr, accepted_token)))
} }
Err(e) => match e { Err(e) => match e {
TryRecvTmtcError::Error(e) => Err(PusPacketHandlingError::EcssTmtc(e)), TryRecvTmtcError::Error(e) => Err(PusPacketHandlingError::EcssTmtc(e)),
TryRecvTmtcError::Empty => Ok(PusPacketHandlerResult::Empty), TryRecvTmtcError::Empty => Ok(None),
}, },
} }
} }

View File

@ -1,9 +1,9 @@
use crate::pool::{SharedPool, StoreAddr}; use crate::pool::SharedPool;
use crate::pus::scheduler::PusScheduler; use crate::pus::scheduler::PusScheduler;
use crate::pus::verification::{StdVerifReporterWithSender, TcStateAccepted, VerificationToken}; use crate::pus::verification::StdVerifReporterWithSender;
use crate::pus::{ use crate::pus::{
EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError, PusServiceBase, EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError,
PusServiceHandler, PusServiceBaseWithStore,
}; };
use spacepackets::ecss::tc::PusTcReader; use spacepackets::ecss::tc::PusTcReader;
use spacepackets::ecss::{scheduling, PusPacket}; use spacepackets::ecss::{scheduling, PusPacket};
@ -19,7 +19,7 @@ use std::boxed::Box;
/// [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 { pub struct PusService11SchedHandler {
psb: PusServiceBase, psb: PusServiceBaseWithStore,
scheduler: PusScheduler, scheduler: PusScheduler,
} }
@ -33,7 +33,7 @@ impl PusService11SchedHandler {
scheduler: PusScheduler, scheduler: PusScheduler,
) -> Self { ) -> Self {
Self { Self {
psb: PusServiceBase::new( psb: PusServiceBaseWithStore::new(
tc_receiver, tc_receiver,
shared_tc_store, shared_tc_store,
tm_sender, tm_sender,
@ -51,22 +51,14 @@ impl PusService11SchedHandler {
pub fn scheduler(&self) -> &PusScheduler { pub fn scheduler(&self) -> &PusScheduler {
&self.scheduler &self.scheduler
} }
}
impl PusServiceHandler for PusService11SchedHandler { pub fn handle_one_tc(&mut self) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
fn psb_mut(&mut self) -> &mut PusServiceBase { let possible_packet = self.psb.retrieve_next_packet()?;
&mut self.psb if possible_packet.is_none() {
return Ok(PusPacketHandlerResult::Empty);
} }
fn psb(&self) -> &PusServiceBase { let (addr, token) = possible_packet.unwrap();
&self.psb self.psb.copy_tc_to_buf(addr)?;
}
fn handle_one_tc(
&mut self,
addr: StoreAddr,
token: VerificationToken<TcStateAccepted>,
) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
self.copy_tc_to_buf(addr)?;
let (tc, _) = PusTcReader::new(&self.psb.pus_buf)?; let (tc, _) = PusTcReader::new(&self.psb.pus_buf)?;
let subservice = tc.subservice(); let subservice = tc.subservice();
let std_service = scheduling::Subservice::try_from(subservice); let std_service = scheduling::Subservice::try_from(subservice);
@ -77,7 +69,7 @@ impl PusServiceHandler for PusService11SchedHandler {
)); ));
} }
let mut partial_error = None; let mut partial_error = None;
let time_stamp = self.psb().get_current_timestamp(&mut partial_error); let time_stamp = self.psb.get_current_timestamp(&mut partial_error);
match std_service.unwrap() { match std_service.unwrap() {
scheduling::Subservice::TcEnableScheduling => { scheduling::Subservice::TcEnableScheduling => {
let start_token = self let start_token = self

View File

@ -1,8 +1,8 @@
use crate::pool::{SharedPool, StoreAddr}; use crate::pool::SharedPool;
use crate::pus::verification::{StdVerifReporterWithSender, TcStateAccepted, VerificationToken}; use crate::pus::verification::StdVerifReporterWithSender;
use crate::pus::{ use crate::pus::{
EcssTcReceiver, EcssTmSender, PartialPusHandlingError, PusPacketHandlerResult, EcssTcReceiver, EcssTmSender, PartialPusHandlingError, PusPacketHandlerResult,
PusPacketHandlingError, PusServiceBase, PusServiceHandler, PusTmWrapper, PusPacketHandlingError, PusServiceBaseWithStore, PusTmWrapper,
}; };
use spacepackets::ecss::tc::PusTcReader; use spacepackets::ecss::tc::PusTcReader;
use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader}; use spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader};
@ -13,7 +13,7 @@ use std::boxed::Box;
/// This is a helper class for [std] environments to handle generic PUS 17 (test service) packets. /// This is a helper class for [std] environments to handle generic PUS 17 (test service) packets.
/// This handler only processes ping requests and generates a ping reply for them accordingly. /// This handler only processes ping requests and generates a ping reply for them accordingly.
pub struct PusService17TestHandler { pub struct PusService17TestHandler {
psb: PusServiceBase, pub psb: PusServiceBaseWithStore,
} }
impl PusService17TestHandler { impl PusService17TestHandler {
@ -25,7 +25,7 @@ impl PusService17TestHandler {
verification_handler: StdVerifReporterWithSender, verification_handler: StdVerifReporterWithSender,
) -> Self { ) -> Self {
Self { Self {
psb: PusServiceBase::new( psb: PusServiceBaseWithStore::new(
tc_receiver, tc_receiver,
shared_tc_store, shared_tc_store,
tm_sender, tm_sender,
@ -34,29 +34,21 @@ impl PusService17TestHandler {
), ),
} }
} }
}
impl PusServiceHandler for PusService17TestHandler { pub fn handle_one_tc(&mut self) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
fn psb_mut(&mut self) -> &mut PusServiceBase { let possible_packet = self.psb.retrieve_next_packet()?;
&mut self.psb if possible_packet.is_none() {
return Ok(PusPacketHandlerResult::Empty);
} }
fn psb(&self) -> &PusServiceBase { let (addr, token) = possible_packet.unwrap();
&self.psb self.psb.copy_tc_to_buf(addr)?;
}
fn handle_one_tc(
&mut self,
addr: StoreAddr,
token: VerificationToken<TcStateAccepted>,
) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
self.copy_tc_to_buf(addr)?;
let (tc, _) = PusTcReader::new(&self.psb.pus_buf)?; let (tc, _) = PusTcReader::new(&self.psb.pus_buf)?;
if tc.service() != 17 { if tc.service() != 17 {
return Err(PusPacketHandlingError::WrongService(tc.service())); return Err(PusPacketHandlingError::WrongService(tc.service()));
} }
if tc.subservice() == 1 { if tc.subservice() == 1 {
let mut partial_error = None; let mut partial_error = None;
let time_stamp = self.psb().get_current_timestamp(&mut partial_error); let time_stamp = self.psb.get_current_timestamp(&mut partial_error);
let result = self let result = self
.psb .psb
.verification_handler .verification_handler
@ -114,7 +106,7 @@ mod tests {
use crate::pus::verification::{ use crate::pus::verification::{
RequestId, StdVerifReporterWithSender, VerificationReporterCfg, RequestId, StdVerifReporterWithSender, VerificationReporterCfg,
}; };
use crate::pus::{MpscTcInStoreReceiver, MpscTmInStoreSender, PusServiceHandler}; use crate::pus::{MpscTcInStoreReceiver, MpscTmInStoreSender};
use crate::tmtc::tm_helper::SharedTmStore; use crate::tmtc::tm_helper::SharedTmStore;
use spacepackets::ecss::tc::{PusTcCreator, PusTcSecondaryHeader}; use spacepackets::ecss::tc::{PusTcCreator, PusTcSecondaryHeader};
use spacepackets::ecss::tm::PusTmReader; use spacepackets::ecss::tm::PusTmReader;
@ -165,7 +157,7 @@ mod tests {
drop(tc_pool); drop(tc_pool);
// Send accepted TC to test service handler. // Send accepted TC to test service handler.
test_srv_tc_tx.send((addr, token.into())).unwrap(); test_srv_tc_tx.send((addr, token.into())).unwrap();
let result = pus_17_handler.handle_next_packet(); let result = pus_17_handler.handle_one_tc();
assert!(result.is_ok()); assert!(result.is_ok());
// We should see 4 replies in the TM queue now: Acceptance TM, Start TM, ping reply and // We should see 4 replies in the TM queue now: Acceptance TM, Start TM, ping reply and
// Completion TM // Completion TM
@ -174,7 +166,7 @@ mod tests {
let mut tm_addr = next_msg.unwrap(); let mut tm_addr = next_msg.unwrap();
let tm_pool = tm_pool_shared.read().unwrap(); let tm_pool = tm_pool_shared.read().unwrap();
let tm_raw = tm_pool.read(&tm_addr).unwrap(); let tm_raw = tm_pool.read(&tm_addr).unwrap();
let (tm, _) = PusTmReader::new(&tm_raw, 0).unwrap(); let (tm, _) = PusTmReader::new(tm_raw, 0).unwrap();
assert_eq!(tm.service(), 1); assert_eq!(tm.service(), 1);
assert_eq!(tm.subservice(), 1); assert_eq!(tm.subservice(), 1);
let req_id = RequestId::from_bytes(tm.user_data()).expect("generating request ID failed"); let req_id = RequestId::from_bytes(tm.user_data()).expect("generating request ID failed");
@ -186,7 +178,7 @@ mod tests {
tm_addr = next_msg.unwrap(); tm_addr = next_msg.unwrap();
let tm_raw = tm_pool.read(&tm_addr).unwrap(); let tm_raw = tm_pool.read(&tm_addr).unwrap();
// Is generated with CDS short timestamp. // Is generated with CDS short timestamp.
let (tm, _) = PusTmReader::new(&tm_raw, 7).unwrap(); let (tm, _) = PusTmReader::new(tm_raw, 7).unwrap();
assert_eq!(tm.service(), 1); assert_eq!(tm.service(), 1);
assert_eq!(tm.subservice(), 3); assert_eq!(tm.subservice(), 3);
let req_id = RequestId::from_bytes(tm.user_data()).expect("generating request ID failed"); let req_id = RequestId::from_bytes(tm.user_data()).expect("generating request ID failed");
@ -198,7 +190,7 @@ mod tests {
tm_addr = next_msg.unwrap(); tm_addr = next_msg.unwrap();
let tm_raw = tm_pool.read(&tm_addr).unwrap(); let tm_raw = tm_pool.read(&tm_addr).unwrap();
// Is generated with CDS short timestamp. // Is generated with CDS short timestamp.
let (tm, _) = PusTmReader::new(&tm_raw, 7).unwrap(); let (tm, _) = PusTmReader::new(tm_raw, 7).unwrap();
assert_eq!(tm.service(), 17); assert_eq!(tm.service(), 17);
assert_eq!(tm.subservice(), 2); assert_eq!(tm.subservice(), 2);
assert!(tm.user_data().is_empty()); assert!(tm.user_data().is_empty());
@ -209,7 +201,7 @@ mod tests {
tm_addr = next_msg.unwrap(); tm_addr = next_msg.unwrap();
let tm_raw = tm_pool.read(&tm_addr).unwrap(); let tm_raw = tm_pool.read(&tm_addr).unwrap();
// Is generated with CDS short timestamp. // Is generated with CDS short timestamp.
let (tm, _) = PusTmReader::new(&tm_raw, 7).unwrap(); let (tm, _) = PusTmReader::new(tm_raw, 7).unwrap();
assert_eq!(tm.service(), 1); assert_eq!(tm.service(), 1);
assert_eq!(tm.subservice(), 7); assert_eq!(tm.subservice(), 7);
let req_id = RequestId::from_bytes(tm.user_data()).expect("generating request ID failed"); let req_id = RequestId::from_bytes(tm.user_data()).expect("generating request ID failed");

View File

@ -1,12 +1,12 @@
use crate::requests::{ActionRequest, Request, RequestWithToken}; use crate::requests::{ActionRequest, Request, RequestWithToken};
use log::{error, warn}; use log::{error, warn};
use satrs_core::pool::{SharedPool, StoreAddr}; use satrs_core::pool::SharedPool;
use satrs_core::pus::verification::{ use satrs_core::pus::verification::{
FailParams, StdVerifReporterWithSender, TcStateAccepted, VerificationToken, FailParams, StdVerifReporterWithSender, TcStateAccepted, VerificationToken,
}; };
use satrs_core::pus::{ use satrs_core::pus::{
EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError, PusServiceBase, EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError,
PusServiceHandler, PusServiceBaseWithStore,
}; };
use satrs_core::spacepackets::ecss::tc::PusTcReader; use satrs_core::spacepackets::ecss::tc::PusTcReader;
use satrs_core::spacepackets::ecss::PusPacket; use satrs_core::spacepackets::ecss::PusPacket;
@ -16,7 +16,7 @@ use std::collections::HashMap;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
pub struct PusService8ActionHandler { pub struct PusService8ActionHandler {
psb: PusServiceBase, psb: PusServiceBaseWithStore,
request_handlers: HashMap<TargetId, Sender<RequestWithToken>>, request_handlers: HashMap<TargetId, Sender<RequestWithToken>>,
} }
@ -30,7 +30,7 @@ impl PusService8ActionHandler {
request_handlers: HashMap<TargetId, Sender<RequestWithToken>>, request_handlers: HashMap<TargetId, Sender<RequestWithToken>>,
) -> Self { ) -> Self {
Self { Self {
psb: PusServiceBase::new( psb: PusServiceBaseWithStore::new(
tc_receiver, tc_receiver,
shared_tc_pool, shared_tc_pool,
tm_sender, tm_sender,
@ -51,7 +51,7 @@ impl PusService8ActionHandler {
) -> Result<(), PusPacketHandlingError> { ) -> Result<(), PusPacketHandlingError> {
let user_data = tc.user_data(); let user_data = tc.user_data();
if user_data.len() < 8 { if user_data.len() < 8 {
self.psb() self.psb
.verification_handler .verification_handler
.borrow_mut() .borrow_mut()
.start_failure( .start_failure(
@ -79,7 +79,7 @@ impl PusService8ActionHandler {
} else { } else {
let mut fail_data: [u8; 4] = [0; 4]; let mut fail_data: [u8; 4] = [0; 4];
fail_data.copy_from_slice(&target_id.to_be_bytes()); fail_data.copy_from_slice(&target_id.to_be_bytes());
self.psb() self.psb
.verification_handler .verification_handler
.borrow_mut() .borrow_mut()
.start_failure( .start_failure(
@ -97,33 +97,25 @@ impl PusService8ActionHandler {
} }
Ok(()) Ok(())
} }
}
impl PusServiceHandler for PusService8ActionHandler { fn handle_one_tc(&mut self) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
fn psb_mut(&mut self) -> &mut PusServiceBase { let possible_packet = self.psb.retrieve_next_packet()?;
&mut self.psb if possible_packet.is_none() {
return Ok(PusPacketHandlerResult::Empty);
} }
fn psb(&self) -> &PusServiceBase { let (addr, token) = possible_packet.unwrap();
&self.psb self.psb.copy_tc_to_buf(addr)?;
} let (tc, _) = PusTcReader::new(&self.psb.pus_buf).unwrap();
fn handle_one_tc(
&mut self,
addr: StoreAddr,
token: VerificationToken<TcStateAccepted>,
) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
self.copy_tc_to_buf(addr)?;
let (tc, _) = PusTcReader::new(&self.psb().pus_buf).unwrap();
let subservice = tc.subservice(); let subservice = tc.subservice();
let mut partial_error = None; let mut partial_error = None;
let time_stamp = self.psb().get_current_timestamp(&mut partial_error); let time_stamp = self.psb.get_current_timestamp(&mut partial_error);
match subservice { match subservice {
128 => { 128 => {
self.handle_action_request_with_id(token, &tc, &time_stamp)?; self.handle_action_request_with_id(token, &tc, &time_stamp)?;
} }
_ => { _ => {
let fail_data = [subservice]; let fail_data = [subservice];
self.psb_mut() self.psb
.verification_handler .verification_handler
.get_mut() .get_mut()
.start_failure( .start_failure(
@ -153,7 +145,7 @@ pub struct Pus8Wrapper {
impl Pus8Wrapper { impl Pus8Wrapper {
pub fn handle_next_packet(&mut self) -> bool { pub fn handle_next_packet(&mut self) -> bool {
match self.pus_8_handler.handle_next_packet() { match self.pus_8_handler.handle_one_tc() {
Ok(result) => match result { Ok(result) => match result {
PusPacketHandlerResult::RequestHandled => {} PusPacketHandlerResult::RequestHandled => {}
PusPacketHandlerResult::RequestHandledPartialSuccess(e) => { PusPacketHandlerResult::RequestHandledPartialSuccess(e) => {

View File

@ -1,6 +1,6 @@
use log::{error, warn}; use log::{error, warn};
use satrs_core::pus::event_srv::PusService5EventHandler; use satrs_core::pus::event_srv::PusService5EventHandler;
use satrs_core::pus::{PusPacketHandlerResult, PusServiceHandler}; use satrs_core::pus::PusPacketHandlerResult;
pub struct Pus5Wrapper { pub struct Pus5Wrapper {
pub pus_5_handler: PusService5EventHandler, pub pus_5_handler: PusService5EventHandler,
@ -8,7 +8,7 @@ pub struct Pus5Wrapper {
impl Pus5Wrapper { impl Pus5Wrapper {
pub fn handle_next_packet(&mut self) -> bool { pub fn handle_next_packet(&mut self) -> bool {
match self.pus_5_handler.handle_next_packet() { match self.pus_5_handler.handle_one_tc() {
Ok(result) => match result { Ok(result) => match result {
PusPacketHandlerResult::RequestHandled => {} PusPacketHandlerResult::RequestHandled => {}
PusPacketHandlerResult::RequestHandledPartialSuccess(e) => { PusPacketHandlerResult::RequestHandledPartialSuccess(e) => {

View File

@ -1,13 +1,11 @@
use crate::requests::{Request, RequestWithToken}; use crate::requests::{Request, RequestWithToken};
use log::{error, warn}; use log::{error, warn};
use satrs_core::hk::{CollectionIntervalFactor, HkRequest}; use satrs_core::hk::{CollectionIntervalFactor, HkRequest};
use satrs_core::pool::{SharedPool, StoreAddr}; use satrs_core::pool::SharedPool;
use satrs_core::pus::verification::{ use satrs_core::pus::verification::{FailParams, StdVerifReporterWithSender};
FailParams, StdVerifReporterWithSender, TcStateAccepted, VerificationToken,
};
use satrs_core::pus::{ use satrs_core::pus::{
EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError, PusServiceBase, EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError,
PusServiceHandler, PusServiceBaseWithStore,
}; };
use satrs_core::spacepackets::ecss::tc::PusTcReader; use satrs_core::spacepackets::ecss::tc::PusTcReader;
use satrs_core::spacepackets::ecss::{hk, PusPacket}; use satrs_core::spacepackets::ecss::{hk, PusPacket};
@ -17,7 +15,7 @@ use std::collections::HashMap;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
pub struct PusService3HkHandler { pub struct PusService3HkHandler {
psb: PusServiceBase, psb: PusServiceBaseWithStore,
request_handlers: HashMap<TargetId, Sender<RequestWithToken>>, request_handlers: HashMap<TargetId, Sender<RequestWithToken>>,
} }
@ -31,7 +29,7 @@ impl PusService3HkHandler {
request_handlers: HashMap<TargetId, Sender<RequestWithToken>>, request_handlers: HashMap<TargetId, Sender<RequestWithToken>>,
) -> Self { ) -> Self {
Self { Self {
psb: PusServiceBase::new( psb: PusServiceBaseWithStore::new(
tc_receiver, tc_receiver,
shared_tc_pool, shared_tc_pool,
tm_sender, tm_sender,
@ -41,26 +39,18 @@ impl PusService3HkHandler {
request_handlers, request_handlers,
} }
} }
}
impl PusServiceHandler for PusService3HkHandler { fn handle_one_tc(&mut self) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
fn psb_mut(&mut self) -> &mut PusServiceBase { let possible_packet = self.psb.retrieve_next_packet()?;
&mut self.psb if possible_packet.is_none() {
return Ok(PusPacketHandlerResult::Empty);
} }
fn psb(&self) -> &PusServiceBase { let (addr, token) = possible_packet.unwrap();
&self.psb self.psb.copy_tc_to_buf(addr)?;
} let (tc, _) = PusTcReader::new(&self.psb.pus_buf).unwrap();
fn handle_one_tc(
&mut self,
addr: StoreAddr,
token: VerificationToken<TcStateAccepted>,
) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
self.copy_tc_to_buf(addr)?;
let (tc, _) = PusTcReader::new(&self.psb().pus_buf).unwrap();
let subservice = tc.subservice(); let subservice = tc.subservice();
let mut partial_error = None; let mut partial_error = None;
let time_stamp = self.psb().get_current_timestamp(&mut partial_error); let time_stamp = self.psb.get_current_timestamp(&mut partial_error);
let user_data = tc.user_data(); let user_data = tc.user_data();
if user_data.is_empty() { if user_data.is_empty() {
self.psb self.psb
@ -168,7 +158,7 @@ pub struct Pus3Wrapper {
impl Pus3Wrapper { impl Pus3Wrapper {
pub fn handle_next_packet(&mut self) -> bool { pub fn handle_next_packet(&mut self) -> bool {
match self.pus_3_handler.handle_next_packet() { match self.pus_3_handler.handle_one_tc() {
Ok(result) => match result { Ok(result) => match result {
PusPacketHandlerResult::RequestHandled => {} PusPacketHandlerResult::RequestHandled => {}
PusPacketHandlerResult::RequestHandledPartialSuccess(e) => { PusPacketHandlerResult::RequestHandledPartialSuccess(e) => {

View File

@ -2,7 +2,7 @@ use crate::tmtc::PusTcSource;
use log::{error, info, warn}; use log::{error, info, warn};
use satrs_core::pus::scheduler::TcInfo; use satrs_core::pus::scheduler::TcInfo;
use satrs_core::pus::scheduler_srv::PusService11SchedHandler; use satrs_core::pus::scheduler_srv::PusService11SchedHandler;
use satrs_core::pus::{PusPacketHandlerResult, PusServiceHandler}; use satrs_core::pus::PusPacketHandlerResult;
pub struct Pus11Wrapper { pub struct Pus11Wrapper {
pub pus_11_handler: PusService11SchedHandler, pub pus_11_handler: PusService11SchedHandler,
@ -44,7 +44,7 @@ impl Pus11Wrapper {
} }
pub fn handle_next_packet(&mut self) -> bool { pub fn handle_next_packet(&mut self) -> bool {
match self.pus_11_handler.handle_next_packet() { match self.pus_11_handler.handle_one_tc() {
Ok(result) => match result { Ok(result) => match result {
PusPacketHandlerResult::RequestHandled => {} PusPacketHandlerResult::RequestHandled => {}
PusPacketHandlerResult::RequestHandledPartialSuccess(e) => { PusPacketHandlerResult::RequestHandledPartialSuccess(e) => {

View File

@ -3,7 +3,7 @@ use satrs_core::events::EventU32;
use satrs_core::params::Params; use satrs_core::params::Params;
use satrs_core::pus::test::PusService17TestHandler; use satrs_core::pus::test::PusService17TestHandler;
use satrs_core::pus::verification::FailParams; use satrs_core::pus::verification::FailParams;
use satrs_core::pus::{PusPacketHandlerResult, PusServiceHandler}; use satrs_core::pus::PusPacketHandlerResult;
use satrs_core::spacepackets::ecss::tc::PusTcReader; use satrs_core::spacepackets::ecss::tc::PusTcReader;
use satrs_core::spacepackets::ecss::PusPacket; use satrs_core::spacepackets::ecss::PusPacket;
use satrs_core::spacepackets::time::cds::TimeProvider; use satrs_core::spacepackets::time::cds::TimeProvider;
@ -18,7 +18,7 @@ pub struct Service17CustomWrapper {
impl Service17CustomWrapper { impl Service17CustomWrapper {
pub fn handle_next_packet(&mut self) -> bool { pub fn handle_next_packet(&mut self) -> bool {
let res = self.pus17_handler.handle_next_packet(); let res = self.pus17_handler.handle_one_tc();
if res.is_err() { if res.is_err() {
warn!("PUS17 handler failed with error {:?}", res.unwrap_err()); warn!("PUS17 handler failed with error {:?}", res.unwrap_err());
return true; return true;
@ -38,7 +38,7 @@ impl Service17CustomWrapper {
warn!("PUS17: Subservice {subservice} not implemented") warn!("PUS17: Subservice {subservice} not implemented")
} }
PusPacketHandlerResult::CustomSubservice(subservice, token) => { PusPacketHandlerResult::CustomSubservice(subservice, token) => {
let psb_mut = self.pus17_handler.psb_mut(); let psb_mut = &mut self.pus17_handler.psb;
let buf = psb_mut.pus_buf; let buf = psb_mut.pus_buf;
let (tc, _) = PusTcReader::new(&buf).unwrap(); let (tc, _) = PusTcReader::new(&buf).unwrap();
let time_stamper = TimeProvider::from_now_with_u16_days().unwrap(); let time_stamper = TimeProvider::from_now_with_u16_days().unwrap();
@ -62,7 +62,7 @@ impl Service17CustomWrapper {
} else { } else {
let fail_data = [tc.subservice()]; let fail_data = [tc.subservice()];
self.pus17_handler self.pus17_handler
.psb_mut() .psb
.verification_handler .verification_handler
.get_mut() .get_mut()
.start_failure( .start_failure(