Larger update #49

Merged
muellerr merged 41 commits from this-is-complex into main 2023-07-08 15:02:42 +02:00
10 changed files with 308 additions and 420 deletions
Showing only changes of commit f7bf4a4d7b - Show all commits

View File

@ -66,9 +66,7 @@ impl PusServiceHandler for PusService5EventHandler {
token,
));
}
let mut partial_error = None;
let time_stamp = self.psb().get_current_timestamp(&mut partial_error);
let mut handle_enable_disable_request = |enable: bool, stamp: [u8; 7]| {
let handle_enable_disable_request = |enable: bool, stamp: [u8; 7]| {
if tc.user_data().is_none() || tc.user_data().unwrap().len() < 4 {
return Err(PusPacketHandlingError::NotEnoughAppData(
"At least 4 bytes event ID expected".into(),
@ -79,6 +77,7 @@ impl PusServiceHandler for PusService5EventHandler {
let start_token = self
.psb
.verification_handler
.borrow_mut()
.start_success(token, Some(&stamp))
.map_err(|_| PartialPusHandlingError::VerificationError);
let partial_error = start_token.clone().err();
@ -109,6 +108,8 @@ impl PusServiceHandler for PusService5EventHandler {
}
Ok(PusPacketHandlerResult::RequestHandled)
};
let mut partial_error = None;
let time_stamp = self.psb().get_current_timestamp(&mut partial_error);
match srv.unwrap() {
Subservice::TmInfoReport
| Subservice::TmLowSeverityReport

View File

@ -148,6 +148,7 @@ pub mod std_mod {
use spacepackets::time::cds::TimeProvider;
use spacepackets::time::{StdTimestampError, TimeWriter};
use spacepackets::tm::PusTm;
use std::cell::RefCell;
use std::format;
use std::string::String;
use std::sync::{mpsc, RwLockWriteGuard};
@ -340,7 +341,9 @@ pub mod std_mod {
pub tm_tx: mpsc::Sender<StoreAddr>,
pub tm_store: SharedTmStore,
pub tm_apid: u16,
pub verification_handler: StdVerifReporterWithSender,
/// The verification handler is wrapped in a [RefCell] to allow the interior mutability
/// pattern. This makes writing methods which are not mutable a lot easier.
pub verification_handler: RefCell<StdVerifReporterWithSender>,
pub pus_buf: [u8; 2048],
pub pus_size: usize,
}
@ -360,7 +363,7 @@ pub mod std_mod {
tm_apid,
tm_tx,
tm_store,
verification_handler,
verification_handler: RefCell::new(verification_handler),
pus_buf: [0; 2048],
pus_size: 0,
}

View File

@ -72,6 +72,7 @@ impl PusServiceHandler for PusService11SchedHandler {
let start_token = self
.psb
.verification_handler
.get_mut()
.start_success(token, Some(&time_stamp))
.expect("Error sending start success");
@ -79,6 +80,7 @@ impl PusServiceHandler for PusService11SchedHandler {
if self.scheduler.is_enabled() {
self.psb
.verification_handler
.get_mut()
.completion_success(start_token, Some(&time_stamp))
.expect("Error sending completion success");
} else {
@ -89,6 +91,7 @@ impl PusServiceHandler for PusService11SchedHandler {
let start_token = self
.psb
.verification_handler
.get_mut()
.start_success(token, Some(&time_stamp))
.expect("Error sending start success");
@ -96,6 +99,7 @@ impl PusServiceHandler for PusService11SchedHandler {
if !self.scheduler.is_enabled() {
self.psb
.verification_handler
.get_mut()
.completion_success(start_token, Some(&time_stamp))
.expect("Error sending completion success");
} else {
@ -106,6 +110,7 @@ impl PusServiceHandler for PusService11SchedHandler {
let start_token = self
.psb
.verification_handler
.get_mut()
.start_success(token, Some(&time_stamp))
.expect("Error sending start success");
@ -117,6 +122,7 @@ impl PusServiceHandler for PusService11SchedHandler {
self.psb
.verification_handler
.get_mut()
.completion_success(start_token, Some(&time_stamp))
.expect("Error sending completion success");
}
@ -124,6 +130,7 @@ impl PusServiceHandler for PusService11SchedHandler {
let start_token = self
.psb
.verification_handler
.get_mut()
.start_success(token, Some(&time_stamp))
.expect("error sending start success");
@ -134,6 +141,7 @@ impl PusServiceHandler for PusService11SchedHandler {
self.psb
.verification_handler
.get_mut()
.completion_success(start_token, Some(&time_stamp))
.expect("sending completion success failed");
}

View File

@ -62,6 +62,7 @@ impl PusServiceHandler for PusService17TestHandler {
let result = self
.psb
.verification_handler
.get_mut()
.start_success(token, Some(&time_stamp))
.map_err(|_| PartialPusHandlingError::VerificationError);
let start_token = if let Ok(result) = result {
@ -87,6 +88,7 @@ impl PusServiceHandler for PusService17TestHandler {
if self
.psb
.verification_handler
.get_mut()
.completion_success(start_token, Some(&time_stamp))
.is_err()
{

View File

@ -11,13 +11,12 @@ use crate::hk::AcsHkIds;
use crate::logging::setup_logger;
use crate::pus::action::{Pus8Wrapper, PusService8ActionHandler};
use crate::pus::event::Pus5Wrapper;
use crate::pus::hk::{Pus3Wrapper, PusService3HkHandler};
use crate::pus::scheduler::Pus11Wrapper;
use crate::pus::test::Service17CustomWrapper;
use crate::pus::PusTcMpscRouter;
use crate::requests::{Request, RequestWithToken};
use crate::tmtc::{
core_tmtc_task, OtherArgs, PusTcSource, TcArgs, TcStore, TmArgs, TmFunnel, PUS_APID,
};
use crate::tmtc::{core_tmtc_task, PusTcSource, TcArgs, TcStore, TmArgs, TmFunnel, PUS_APID};
use satrs_core::event_man::{
EventManagerWithMpscQueue, MpscEventReceiver, MpscEventU32SendProvider, SendEventProvider,
};
@ -107,7 +106,7 @@ fn main() {
// The event manager will receive the RX handle to receive all the events.
let (event_sender, event_man_rx) = channel();
let event_recv = MpscEventReceiver::<EventU32>::new(event_man_rx);
let test_srv_event_sender = event_sender.clone();
let test_srv_event_sender = event_sender;
let mut event_man = EventManagerWithMpscQueue::new(Box::new(event_recv));
// All events sent to the manager are routed to the PUS event manager, which generates PUS event
@ -132,11 +131,6 @@ fn main() {
};
// Create clones here to allow moving the values
let core_args = OtherArgs {
sock_addr,
verif_reporter: verif_reporter.clone(),
event_sender,
};
let tc_args = TcArgs {
tc_source: tc_source_wrapper.clone(),
tc_receiver: tc_source_rx,
@ -147,13 +141,13 @@ fn main() {
tm_server_rx,
};
let aocs_to_funnel = tm_funnel_tx.clone();
let aocs_tm_funnel = tm_funnel_tx.clone();
let mut aocs_tm_store = tm_store.clone();
let (pus_test_tx, pus_test_rx) = channel();
let (pus_event_tx, pus_event_rx) = channel();
let (pus_sched_tx, pus_sched_rx) = channel();
let (pus_hk_tx, _pus_hk_rx) = channel();
let (pus_hk_tx, pus_hk_rx) = channel();
let (pus_action_tx, pus_action_rx) = channel();
let pus_router = PusTcMpscRouter {
test_service_receiver: pus_test_tx,
@ -206,16 +200,27 @@ fn main() {
tm_funnel_tx.clone(),
tm_store.clone(),
PUS_APID,
verif_reporter,
verif_reporter.clone(),
request_map.clone(),
);
let mut pus_8_wrapper = Pus8Wrapper { pus_8_handler };
let pus_3_handler = PusService3HkHandler::new(
pus_hk_rx,
tc_store.pool.clone(),
tm_funnel_tx.clone(),
tm_store.clone(),
PUS_APID,
verif_reporter.clone(),
request_map,
);
let mut pus_3_wrapper = Pus3Wrapper { pus_3_handler };
info!("Starting TMTC task");
let jh0 = thread::Builder::new()
.name("TMTC".to_string())
.spawn(move || {
core_tmtc_task(core_args, tc_args, tm_args, pus_router);
core_tmtc_task(sock_addr, tc_args, tm_args, verif_reporter, pus_router);
})
.unwrap();
@ -363,7 +368,7 @@ fn main() {
true,
);
let addr = aocs_tm_store.add_pus_tm(&pus_tm);
aocs_to_funnel.send(addr).expect("Sending HK TM failed");
aocs_tm_funnel.send(addr).expect("Sending HK TM failed");
}
}
HkRequest::Enable(_) => {}
@ -412,6 +417,7 @@ fn main() {
is_srv_finished(pus_11_wrapper.handle_next_packet());
is_srv_finished(pus_5_wrapper.handle_next_packet());
is_srv_finished(pus_8_wrapper.handle_next_packet());
is_srv_finished(pus_3_wrapper.handle_next_packet());
if all_queues_empty {
break;
}

View File

@ -44,37 +44,21 @@ impl PusService8ActionHandler {
}
}
impl PusServiceHandler for PusService8ActionHandler {
fn psb_mut(&mut self) -> &mut PusServiceBase {
&mut self.psb
}
fn psb(&self) -> &PusServiceBase {
&self.psb
}
fn handle_one_tc(
&mut self,
addr: StoreAddr,
impl PusService8ActionHandler {
fn handle_action_request_with_id(
&self,
token: VerificationToken<TcStateAccepted>,
) -> Result<PusPacketHandlerResult, PusPacketHandlingError> {
self.copy_tc_to_buf(addr)?;
let (tc, _) = PusTc::from_bytes(&self.psb().pus_buf).unwrap();
let subservice = tc.subservice();
let mut partial_error = None;
let time_stamp = self.psb().get_current_timestamp(&mut partial_error);
match subservice {
128 => {
tc: &PusTc,
time_stamp: &[u8],
) -> Result<(), PusPacketHandlingError> {
let user_data = tc.user_data();
if user_data.is_none() || user_data.unwrap().len() < 8 {
self.psb_mut()
self.psb()
.verification_handler
.borrow_mut()
.start_failure(
token,
FailParams::new(
Some(&time_stamp),
&tmtc_err::NOT_ENOUGH_APP_DATA,
None,
),
FailParams::new(Some(time_stamp), &tmtc_err::NOT_ENOUGH_APP_DATA, None),
)
.expect("Sending start failure failed");
return Err(PusPacketHandlingError::NotEnoughAppData(
@ -98,12 +82,13 @@ impl PusServiceHandler for PusService8ActionHandler {
} else {
let mut fail_data: [u8; 4] = [0; 4];
fail_data.copy_from_slice(&target_id.to_be_bytes());
self.psb_mut()
self.psb()
.verification_handler
.borrow_mut()
.start_failure(
token,
FailParams::new(
Some(&time_stamp),
Some(time_stamp),
&tmtc_err::UNKNOWN_TARGET_ID,
Some(&fail_data),
),
@ -113,11 +98,37 @@ impl PusServiceHandler for PusService8ActionHandler {
"Unknown target ID {target_id}"
)));
}
Ok(())
}
}
impl PusServiceHandler for PusService8ActionHandler {
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> {
self.copy_tc_to_buf(addr)?;
let (tc, _) = PusTc::from_bytes(&self.psb().pus_buf).unwrap();
let subservice = tc.subservice();
let mut partial_error = None;
let time_stamp = self.psb().get_current_timestamp(&mut partial_error);
match subservice {
128 => {
self.handle_action_request_with_id(token, &tc, &time_stamp)?;
}
_ => {
let fail_data = [subservice];
self.psb_mut()
.verification_handler
.get_mut()
.start_failure(
token,
FailParams::new(

View File

@ -1 +1,195 @@
use crate::requests::{Request, RequestWithToken};
use log::{error, warn};
use satrs_core::hk::{CollectionIntervalFactor, HkRequest};
use satrs_core::pool::{SharedPool, StoreAddr};
use satrs_core::pus::verification::{
FailParams, StdVerifReporterWithSender, TcStateAccepted, VerificationToken,
};
use satrs_core::pus::{
AcceptedTc, PusPacketHandlerResult, PusPacketHandlingError, PusServiceBase, PusServiceHandler,
};
use satrs_core::spacepackets::ecss::{hk, PusPacket};
use satrs_core::spacepackets::tc::PusTc;
use satrs_core::tmtc::tm_helper::SharedTmStore;
use satrs_core::tmtc::{AddressableId, TargetId};
use satrs_example::{hk_err, tmtc_err};
use std::collections::HashMap;
use std::sync::mpsc::{Receiver, Sender};
pub struct PusService3HkHandler {
psb: PusServiceBase,
request_handlers: HashMap<TargetId, Sender<RequestWithToken>>,
}
impl PusService3HkHandler {
pub fn new(
receiver: Receiver<AcceptedTc>,
tc_pool: SharedPool,
tm_tx: Sender<StoreAddr>,
tm_store: SharedTmStore,
tm_apid: u16,
verification_handler: StdVerifReporterWithSender,
request_handlers: HashMap<TargetId, Sender<RequestWithToken>>,
) -> Self {
Self {
psb: PusServiceBase::new(
receiver,
tc_pool,
tm_tx,
tm_store,
tm_apid,
verification_handler,
),
request_handlers,
}
}
}
impl PusServiceHandler for PusService3HkHandler {
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> {
self.copy_tc_to_buf(addr)?;
let (tc, _) = PusTc::from_bytes(&self.psb().pus_buf).unwrap();
let subservice = tc.subservice();
let mut partial_error = None;
let time_stamp = self.psb().get_current_timestamp(&mut partial_error);
let user_data = tc.user_data().unwrap();
if tc.user_data().is_none() {
self.psb
.verification_handler
.borrow_mut()
.start_failure(
token,
FailParams::new(Some(&time_stamp), &tmtc_err::NOT_ENOUGH_APP_DATA, None),
)
.expect("Sending start failure TM failed");
return Err(PusPacketHandlingError::NotEnoughAppData(
"Expected at least 8 bytes of app data".into(),
));
}
if user_data.len() < 8 {
let err = if user_data.len() < 4 {
&hk_err::TARGET_ID_MISSING
} else {
&hk_err::UNIQUE_ID_MISSING
};
self.psb
.verification_handler
.borrow_mut()
.start_failure(token, FailParams::new(Some(&time_stamp), err, None))
.expect("Sending start failure TM failed");
return Err(PusPacketHandlingError::NotEnoughAppData(
"Expected at least 8 bytes of app data".into(),
));
}
let addressable_id = AddressableId::from_raw_be(user_data).unwrap();
if !self
.request_handlers
.contains_key(&addressable_id.target_id)
{
self.psb
.verification_handler
.borrow_mut()
.start_failure(
token,
FailParams::new(Some(&time_stamp), &hk_err::UNKNOWN_TARGET_ID, None),
)
.expect("Sending start failure TM failed");
let tgt_id = addressable_id.target_id;
return Err(PusPacketHandlingError::NotEnoughAppData(format!(
"Unknown target ID {tgt_id}"
)));
}
let send_request = |target: TargetId, request: HkRequest| {
let sender = self
.request_handlers
.get(&addressable_id.target_id)
.unwrap();
sender
.send(RequestWithToken::new(target, Request::Hk(request), token))
.unwrap_or_else(|_| panic!("Sending HK request {request:?} failed"));
};
if subservice == hk::Subservice::TcEnableHkGeneration as u8 {
send_request(
addressable_id.target_id,
HkRequest::Enable(addressable_id.unique_id),
);
} else if subservice == hk::Subservice::TcDisableHkGeneration as u8 {
send_request(
addressable_id.target_id,
HkRequest::Disable(addressable_id.unique_id),
);
} else if subservice == hk::Subservice::TcGenerateOneShotHk as u8 {
send_request(
addressable_id.target_id,
HkRequest::OneShot(addressable_id.unique_id),
);
} else if subservice == hk::Subservice::TcModifyHkCollectionInterval as u8 {
if user_data.len() < 12 {
self.psb
.verification_handler
.borrow_mut()
.start_failure(
token,
FailParams::new(
Some(&time_stamp),
&hk_err::COLLECTION_INTERVAL_MISSING,
None,
),
)
.expect("Sending start failure TM failed");
return Err(PusPacketHandlingError::NotEnoughAppData(
"Collection interval missing".into(),
));
}
send_request(
addressable_id.target_id,
HkRequest::ModifyCollectionInterval(
addressable_id.unique_id,
CollectionIntervalFactor::from_be_bytes(user_data[8..12].try_into().unwrap()),
),
);
}
Ok(PusPacketHandlerResult::RequestHandled)
}
}
pub struct Pus3Wrapper {
pub(crate) pus_3_handler: PusService3HkHandler,
}
impl Pus3Wrapper {
pub fn handle_next_packet(&mut self) -> bool {
match self.pus_3_handler.handle_next_packet() {
Ok(result) => match result {
PusPacketHandlerResult::RequestHandled => {}
PusPacketHandlerResult::RequestHandledPartialSuccess(e) => {
warn!("PUS 3 partial packet handling success: {e:?}")
}
PusPacketHandlerResult::CustomSubservice(invalid, _) => {
warn!("PUS 3 invalid subservice {invalid}");
}
PusPacketHandlerResult::SubserviceNotImplemented(subservice, _) => {
warn!("PUS 3 subservice {subservice} not implemented");
}
PusPacketHandlerResult::Empty => {
return true;
}
},
Err(error) => {
error!("PUS packet handling error: {error:?}")
}
}
false
}
}

View File

@ -1,6 +1,4 @@
use crate::tmtc::MpscStoreAndSendError;
use satrs_core::events::EventU32;
use satrs_core::params::Params;
use satrs_core::pool::StoreAddr;
use satrs_core::pus::verification::{FailParams, StdVerifReporterWithSender};
use satrs_core::pus::AcceptedTc;
@ -8,7 +6,6 @@ use satrs_core::spacepackets::ecss::PusServiceId;
use satrs_core::spacepackets::tc::PusTc;
use satrs_core::spacepackets::time::cds::TimeProvider;
use satrs_core::spacepackets::time::TimeWriter;
use satrs_core::tmtc::tm_helper::PusTmWithCdsShortHelper;
use satrs_example::{tmtc_err, CustomPusServiceId};
use std::sync::mpsc::Sender;
@ -27,28 +24,9 @@ pub struct PusTcMpscRouter {
}
pub struct PusReceiver {
pub tm_helper: PusTmWithCdsShortHelper,
pub tm_args: PusTmArgs,
pub tc_args: PusTcArgs,
stamp_helper: TimeStampHelper,
}
pub struct PusTmArgs {
/// All verification reporting is done with this reporter.
pub verif_reporter: StdVerifReporterWithSender,
}
impl PusTmArgs {
fn vr(&mut self) -> &mut StdVerifReporterWithSender {
&mut self.verif_reporter
}
}
pub struct PusTcArgs {
/// This routes all telecommands to their respective recipients
pub pus_router: PusTcMpscRouter,
/// Used to send events from within the TC router
pub event_sender: Sender<(EventU32, Option<Params>)>,
stamp_helper: TimeStampHelper,
}
struct TimeStampHelper {
@ -79,11 +57,10 @@ impl TimeStampHelper {
}
impl PusReceiver {
pub fn new(apid: u16, tm_arguments: PusTmArgs, tc_arguments: PusTcArgs) -> Self {
pub fn new(verif_reporter: StdVerifReporterWithSender, pus_router: PusTcMpscRouter) -> Self {
Self {
tm_helper: PusTmWithCdsShortHelper::new(apid),
tm_args: tm_arguments,
tc_args: tc_arguments,
verif_reporter,
pus_router,
stamp_helper: TimeStampHelper::new(),
}
}
@ -96,11 +73,10 @@ impl PusReceiver {
service: u8,
pus_tc: &PusTc,
) -> Result<(), MpscStoreAndSendError> {
let init_token = self.tm_args.verif_reporter.add_tc(pus_tc);
let init_token = self.verif_reporter.add_tc(pus_tc);
self.stamp_helper.update_from_now();
let accepted_token = self
.tm_args
.vr()
.verif_reporter
.acceptance_success(init_token, Some(self.stamp_helper.stamp()))
.expect("Acceptance success failure");
let service = PusServiceId::try_from(service);
@ -108,7 +84,6 @@ impl PusReceiver {
Ok(standard_service) => match standard_service {
PusServiceId::Test => {
let res = self
.tc_args
.pus_router
.test_service_receiver
.send((store_addr, accepted_token));
@ -120,25 +95,21 @@ impl PusReceiver {
}
}
PusServiceId::Housekeeping => self
.tc_args
.pus_router
.hk_service_receiver
.send((store_addr, accepted_token))
.unwrap(),
PusServiceId::Event => self
.tc_args
.pus_router
.event_service_receiver
.send((store_addr, accepted_token))
.unwrap(),
PusServiceId::Scheduling => self
.tc_args
.pus_router
.sched_service_receiver
.send((store_addr, accepted_token))
.unwrap(),
_ => self
.tm_args
.verif_reporter
.start_failure(
accepted_token,
@ -159,8 +130,7 @@ impl PusReceiver {
CustomPusServiceId::Health => {}
}
} else {
self.tm_args
.verif_reporter
self.verif_reporter
.start_failure(
accepted_token,
FailParams::new(
@ -176,299 +146,3 @@ impl PusReceiver {
Ok(())
}
}
// impl PusServiceProvider for PusReceiver {
// type Error = ();
//
// fn handle_pus_tc_packet(
// &mut self,
// service: u8,
// _header: &SpHeader,
// pus_tc: &PusTc,
// ) -> Result<(), Self::Error> {
// let init_token = self.tm_args.verif_reporter.add_tc(pus_tc);
// self.stamp_helper.update_from_now();
// let accepted_token = self
// .tm_args
// .vr()
// .acceptance_success(init_token, Some(self.stamp_helper.stamp()))
// .expect("Acceptance success failure");
// let service = PusServiceId::try_from(service);
// match service {
// Ok(standard_service) => match standard_service {
// PusServiceId::Test => self
// .tc_args
// .pus_router
// .test_service_receiver
// .send_tc(*pus_tc),
// PusServiceId::Housekeeping => {
// self.tc_args.pus_router.hk_service_receiver.send_tc(*pus_tc)
// } //self.handle_hk_request(pus_tc, accepted_token),
// PusServiceId::Event => self
// .tc_args
// .pus_router
// .event_service_receiver
// .send_tc(*pus_tc), //self.handle_event_request(pus_tc, accepted_token),
// PusServiceId::Scheduling => self
// .tc_args
// .pus_router
// .sched_service_receiver
// .send_tc(*pus_tc), //self.handle_scheduled_tc(pus_tc, accepted_token),
// _ => self
// .tm_args
// .verif_reporter
// .start_failure(
// accepted_token,
// FailParams::new(
// Some(self.stamp_helper.stamp()),
// &tmtc_err::PUS_SERVICE_NOT_IMPLEMENTED,
// Some(&[standard_service as u8]),
// ),
// )
// .expect("Start failure verification failed"),
// },
// Err(e) => {
// if let Ok(custom_service) = CustomPusServiceId::try_from(e.number) {
// match custom_service {
// CustomPusServiceId::Mode => {
// self.handle_mode_service(pus_tc, accepted_token)
// }
// CustomPusServiceId::Health => {}
// }
// } else {
// self.tm_args
// .verif_reporter
// .start_failure(
// accepted_token,
// FailParams::new(
// Some(self.stamp_helper.stamp()),
// &tmtc_err::INVALID_PUS_SUBSERVICE,
// Some(&[e.number]),
// ),
// )
// .expect("Start failure verification failed")
// }
// }
// }
// Ok(())
// }
// }
// impl PusReceiver {
//
// fn handle_hk_request(&mut self, pus_tc: &PusTc, token: VerificationToken<TcStateAccepted>) {
// if pus_tc.user_data().is_none() {
// self.tm_args
// .verif_reporter
// .start_failure(
// token,
// FailParams::new(
// Some(self.stamp_helper.stamp()),
// &tmtc_err::NOT_ENOUGH_APP_DATA,
// None,
// ),
// )
// .expect("Sending start failure TM failed");
// return;
// }
// let user_data = pus_tc.user_data().unwrap();
// if user_data.len() < 8 {
// let err = if user_data.len() < 4 {
// &hk_err::TARGET_ID_MISSING
// } else {
// &hk_err::UNIQUE_ID_MISSING
// };
// self.tm_args
// .verif_reporter
// .start_failure(
// token,
// FailParams::new(Some(self.stamp_helper.stamp()), err, None),
// )
// .expect("Sending start failure TM failed");
// return;
// }
// let addressable_id = AddressableId::from_raw_be(user_data).unwrap();
// if !self
// .tc_args
// .request_map
// .contains_key(&addressable_id.target_id)
// {
// self.tm_args
// .verif_reporter
// .start_failure(
// token,
// FailParams::new(
// Some(self.stamp_helper.stamp()),
// &hk_err::UNKNOWN_TARGET_ID,
// None,
// ),
// )
// .expect("Sending start failure TM failed");
// return;
// }
// let send_request = |target: TargetId, request: HkRequest| {
// let sender = self
// .tc_args
// .request_map
// .get(&addressable_id.target_id)
// .unwrap();
// sender
// .send(RequestWithToken::new(
// target,
// Request::HkRequest(request),
// token,
// ))
// .unwrap_or_else(|_| panic!("Sending HK request {request:?} failed"));
// };
// if PusPacket::subservice(pus_tc) == hk::Subservice::TcEnableHkGeneration as u8 {
// send_request(
// addressable_id.target_id,
// HkRequest::Enable(addressable_id.unique_id),
// );
// } else if PusPacket::subservice(pus_tc) == hk::Subservice::TcDisableHkGeneration as u8 {
// send_request(
// addressable_id.target_id,
// HkRequest::Disable(addressable_id.unique_id),
// );
// } else if PusPacket::subservice(pus_tc) == hk::Subservice::TcGenerateOneShotHk as u8 {
// send_request(
// addressable_id.target_id,
// HkRequest::OneShot(addressable_id.unique_id),
// );
// } else if PusPacket::subservice(pus_tc)
// == hk::Subservice::TcModifyHkCollectionInterval as u8
// {
// if user_data.len() < 12 {
// self.tm_args
// .verif_reporter
// .start_failure(
// token,
// FailParams::new(
// Some(self.stamp_helper.stamp()),
// &hk_err::COLLECTION_INTERVAL_MISSING,
// None,
// ),
// )
// .expect("Sending start failure TM failed");
// return;
// }
// send_request(
// addressable_id.target_id,
// HkRequest::ModifyCollectionInterval(
// addressable_id.unique_id,
// CollectionIntervalFactor::from_be_bytes(user_data[8..12].try_into().unwrap()),
// ),
// );
// }
// }
//
//
// fn handle_mode_service(&mut self, pus_tc: &PusTc, token: VerificationToken<TcStateAccepted>) {
// let mut app_data_len = 0;
// let app_data = pus_tc.user_data();
// if app_data.is_some() {
// app_data_len = pus_tc.user_data().unwrap().len();
// }
// if app_data_len < 4 {
// self.tm_args
// .verif_reporter
// .start_failure(
// token,
// FailParams::new(
// Some(self.stamp_helper.stamp()),
// &tmtc_err::NOT_ENOUGH_APP_DATA,
// Some(format!("expected {} bytes, found {}", 4, app_data_len).as_bytes()),
// ),
// )
// .expect("Sending start failure TM failed");
// }
// let app_data = app_data.unwrap();
// let mut invalid_subservice_handler = || {
// self.tm_args
// .verif_reporter
// .start_failure(
// token,
// FailParams::new(
// Some(self.stamp_helper.stamp()),
// &tmtc_err::INVALID_PUS_SUBSERVICE,
// Some(&[PusPacket::subservice(pus_tc)]),
// ),
// )
// .expect("Sending start failure TM failed");
// };
// let subservice = mode::Subservice::try_from(PusPacket::subservice(pus_tc));
// if let Ok(subservice) = subservice {
// let forward_mode_request = |target_id, mode_request: ModeRequest| match self
// .tc_args
// .request_map
// .get(&target_id)
// {
// None => warn!("not mode request recipient for target ID {target_id} found"),
// Some(sender_to_recipient) => {
// sender_to_recipient
// .send(RequestWithToken::new(
// target_id,
// Request::ModeRequest(mode_request),
// token,
// ))
// .expect("sending mode request failed");
// }
// };
// let mut valid_subservice = true;
// match subservice {
// Subservice::TcSetMode => {
// let target_id = u32::from_be_bytes(app_data[0..4].try_into().unwrap());
// let min_len = ModeAndSubmode::raw_len() + 4;
// if app_data_len < min_len {
// self.tm_args
// .verif_reporter
// .start_failure(
// token,
// FailParams::new(
// Some(self.stamp_helper.stamp()),
// &tmtc_err::NOT_ENOUGH_APP_DATA,
// Some(
// format!("expected {min_len} bytes, found {app_data_len}")
// .as_bytes(),
// ),
// ),
// )
// .expect("Sending start failure TM failed");
// }
// // Should never fail after size check
// let mode_submode = ModeAndSubmode::from_be_bytes(
// app_data[4..4 + ModeAndSubmode::raw_len()]
// .try_into()
// .unwrap(),
// )
// .unwrap();
// forward_mode_request(target_id, ModeRequest::SetMode(mode_submode));
// }
// Subservice::TcReadMode => {
// let target_id = u32::from_be_bytes(app_data[0..4].try_into().unwrap());
// forward_mode_request(target_id, ModeRequest::ReadMode);
// }
// Subservice::TcAnnounceMode => {
// let target_id = u32::from_be_bytes(app_data[0..4].try_into().unwrap());
// forward_mode_request(target_id, ModeRequest::AnnounceMode);
// }
// Subservice::TcAnnounceModeRecursive => {
// let target_id = u32::from_be_bytes(app_data[0..4].try_into().unwrap());
// forward_mode_request(target_id, ModeRequest::AnnounceModeRecursive);
// }
// _ => {
// warn!("Can not process mode request with subservice {subservice:?}");
// invalid_subservice_handler();
// valid_subservice = false;
// }
// }
// if valid_subservice {
// self.tm_args
// .verif_reporter
// .start_success(token, Some(self.stamp_helper.stamp()))
// .expect("sending start success TM failed");
// }
// } else {
// invalid_subservice_handler();
// }
// }
// }

View File

@ -51,10 +51,12 @@ impl Service17CustomWrapper {
.expect("Sending test event failed");
let start_token = psb_mut
.verification_handler
.get_mut()
.start_success(token, Some(&stamp_buf))
.expect("Error sending start success");
psb_mut
.verification_handler
.get_mut()
.completion_success(start_token, Some(&stamp_buf))
.expect("Error sending completion success");
} else {
@ -62,6 +64,7 @@ impl Service17CustomWrapper {
self.pus17_handler
.psb_mut()
.verification_handler
.get_mut()
.start_failure(
token,
FailParams::new(

View File

@ -1,7 +1,5 @@
use log::info;
use satrs_core::events::EventU32;
use satrs_core::hal::host::udp_server::{ReceiveResult, UdpTcServer};
use satrs_core::params::Params;
use std::error::Error;
use std::fmt::{Display, Formatter};
use std::net::SocketAddr;
@ -10,7 +8,7 @@ use std::thread;
use std::time::Duration;
use crate::ccsds::CcsdsReceiver;
use crate::pus::{PusReceiver, PusTcArgs, PusTcMpscRouter, PusTmArgs};
use crate::pus::{PusReceiver, PusTcMpscRouter};
use satrs_core::pool::{SharedPool, StoreAddr, StoreError};
use satrs_core::pus::verification::StdVerifReporterWithSender;
use satrs_core::spacepackets::ecss::{PusPacket, SerializablePusPacket};
@ -21,12 +19,6 @@ use satrs_core::tmtc::{CcsdsDistributor, CcsdsError, ReceivesCcsdsTc, ReceivesEc
pub const PUS_APID: u16 = 0x02;
pub struct OtherArgs {
pub sock_addr: SocketAddr,
pub verif_reporter: StdVerifReporterWithSender,
pub event_sender: Sender<(EventU32, Option<Params>)>,
}
pub struct TmArgs {
pub tm_store: SharedTmStore,
pub tm_sink_sender: Sender<StoreAddr>,
@ -141,19 +133,13 @@ impl ReceivesCcsdsTc for PusTcSource {
}
pub fn core_tmtc_task(
args: OtherArgs,
socket_addr: SocketAddr,
mut tc_args: TcArgs,
tm_args: TmArgs,
verif_reporter: StdVerifReporterWithSender,
pus_router: PusTcMpscRouter,
) {
let pus_tm_args = PusTmArgs {
verif_reporter: args.verif_reporter,
};
let pus_tc_args = PusTcArgs {
pus_router,
event_sender: args.event_sender,
};
let mut pus_receiver = PusReceiver::new(PUS_APID, pus_tm_args, pus_tc_args);
let mut pus_receiver = PusReceiver::new(verif_reporter, pus_router);
let ccsds_receiver = CcsdsReceiver {
tc_source: tc_args.tc_source.clone(),
@ -161,7 +147,7 @@ pub fn core_tmtc_task(
let ccsds_distributor = CcsdsDistributor::new(Box::new(ccsds_receiver));
let udp_tc_server = UdpTcServer::new(args.sock_addr, 2048, Box::new(ccsds_distributor))
let udp_tc_server = UdpTcServer::new(socket_addr, 2048, Box::new(ccsds_distributor))
.expect("Creating UDP TMTC server failed");
let mut udp_tmtc_server = UdpTmtcServer {