updated sat-rs

This commit is contained in:
2024-04-29 23:46:21 +02:00
parent 9d8104be40
commit 3173b18ceb
5 changed files with 71 additions and 118 deletions

View File

@ -3,7 +3,6 @@ use std::sync::mpsc::{self};
use crate::pus::create_verification_reporter;
use ops_sat_rs::config::components::PUS_EVENT_MANAGEMENT;
use satrs::event_man::{EventMessageU32, EventRoutingError};
use satrs::params::WritableToBeBytes;
use satrs::pus::event::EventTmHookProvider;
use satrs::pus::verification::VerificationReporter;
use satrs::request::UniqueApidTargetId;
@ -42,6 +41,7 @@ pub struct PusEventHandler {
tm_sender: mpsc::Sender<PacketAsVec>,
time_provider: CdsTime,
timestamp: [u8; 7],
small_params_buf: [u8; 64],
verif_handler: VerificationReporter,
}
@ -82,6 +82,7 @@ impl PusEventHandler {
pus_event_man_rx,
time_provider: CdsTime::new_with_u16_days(0, 0),
timestamp: [0; 7],
small_params_buf: [0; 64],
verif_handler,
tm_sender,
}
@ -132,19 +133,17 @@ impl PusEventHandler {
// Perform the generation of PUS event packets
match self.pus_event_man_rx.try_recv() {
Ok(event_msg) => {
update_time(&mut self.time_provider, &mut self.timestamp);
let param_vec = event_msg.params().map_or(Vec::new(), |param| {
param.to_vec().expect("failed to convert params to vec")
});
// We use the TM modification hook to set the sender APID for each event.
self.pus_event_tm_creator.reporter.tm_hook.next_apid =
UniqueApidTargetId::from(event_msg.sender_id()).apid;
update_time(&mut self.time_provider, &mut self.timestamp);
self.pus_event_tm_creator
.generate_pus_event_tm_generic(
.generate_pus_event_tm_generic_with_generic_params(
&self.tm_sender,
&self.timestamp,
event_msg.event(),
Some(&param_vec),
&mut self.small_params_buf,
event_msg.params(),
)
.expect("Sending TM as event failed");
}

View File

@ -3,12 +3,12 @@ use ops_sat_rs::config::components::PUS_ACTION_SERVICE;
use ops_sat_rs::config::tmtc_err;
use ops_sat_rs::TimeStampHelper;
use satrs::action::{ActionRequest, ActionRequestVariant};
use satrs::params::WritableToBeBytes;
use satrs::pus::action::{
ActionReplyPus, ActionReplyVariant, ActivePusActionRequestStd, DefaultActiveActionRequestMap,
};
use satrs::pus::verification::{
FailParams, FailParamsWithStep, TcStateAccepted, TcStateStarted, VerificationReporter,
handle_completion_failure_with_generic_params, handle_step_failure_with_generic_params,
FailParamHelper, FailParams, TcStateAccepted, TcStateStarted, VerificationReporter,
VerificationReportingProvider, VerificationToken,
};
use satrs::pus::{
@ -35,13 +35,13 @@ use super::{
pub const DATA_REPLY: u8 = 130;
pub struct ActionReplyHandler {
fail_data_buf: [u8; 2048],
fail_data_buf: [u8; 128],
}
impl Default for ActionReplyHandler {
fn default() -> Self {
Self {
fail_data_buf: [0; 2048],
fail_data_buf: [0; 128],
}
}
}
@ -64,7 +64,7 @@ impl PusReplyHandler<ActivePusActionRequestStd, ActionReplyPus> for ActionReplyH
active_request: &ActivePusActionRequestStd,
tm_sender: &(impl EcssTmSender + ?Sized),
verification_handler: &impl VerificationReportingProvider,
time_stamp: &[u8],
timestamp: &[u8],
) -> Result<bool, Self::Error> {
let verif_token: VerificationToken<TcStateStarted> = active_request
.token()
@ -72,64 +72,23 @@ impl PusReplyHandler<ActivePusActionRequestStd, ActionReplyPus> for ActionReplyH
.expect("invalid token state");
let remove_entry = match &reply.message.variant {
ActionReplyVariant::CompletionFailed { error_code, params } => {
let mut fail_data_len = 0;
if let Some(params) = params {
match params {
satrs::params::Params::Heapless(heapless_param) => {
// TODO: This should be part of the framework.
match heapless_param {
satrs::params::ParamsHeapless::Raw(raw) => {
// TODO: size check.
let _ = raw.write_to_be_bytes(
&mut self.fail_data_buf[0..raw.written_len()],
);
}
satrs::params::ParamsHeapless::EcssEnum(ecss_enum) => {
// TODO: size check.
let _ = ecss_enum.write_to_be_bytes(
&mut self.fail_data_buf[0..ecss_enum.written_len()],
);
}
}
}
satrs::params::Params::Store(_) => {
log::warn!("can not process store parameters")
}
satrs::params::Params::Vec(vec) => {
// Truncate the string for now.
fail_data_len = vec.len();
if vec.len() > self.fail_data_buf.len() {
log::warn!(
"action reply vec too large, truncating to {} bytes",
self.fail_data_buf.len()
);
}
self.fail_data_buf[0..fail_data_len]
.copy_from_slice(&vec[0..fail_data_len]);
}
satrs::params::Params::String(str) => {
fail_data_len = str.len();
// Truncate the string for now.
if str.len() > self.fail_data_buf.len() {
fail_data_len = self.fail_data_buf.len();
log::warn!(
"action reply string too large, truncating to {} bytes",
self.fail_data_buf.len()
);
}
self.fail_data_buf[0..fail_data_len]
.copy_from_slice(&str.as_bytes()[0..fail_data_len]);
log::warn!("received string param with len {}", str.len());
}
_ => todo!(),
}
}
log::warn!("completion failure with fail data len: {}", fail_data_len);
verification_handler.completion_failure(
let error_propagated = handle_completion_failure_with_generic_params(
tm_sender,
verif_token,
FailParams::new(time_stamp, error_code, &self.fail_data_buf[..fail_data_len]),
verification_handler,
FailParamHelper {
error_code,
params: params.as_ref(),
timestamp,
small_data_buf: &mut self.fail_data_buf,
},
)?;
if !error_propagated {
log::warn!(
"error params for completion failure were not propated: {:?}",
params.as_ref()
);
}
true
}
ActionReplyVariant::StepFailed {
@ -137,31 +96,35 @@ impl PusReplyHandler<ActivePusActionRequestStd, ActionReplyPus> for ActionReplyH
step,
params,
} => {
let mut fail_data_len = 0;
if let Some(params) = params {
fail_data_len = params.write_to_be_bytes(&mut self.fail_data_buf)?;
}
verification_handler.step_failure(
let error_propagated = handle_step_failure_with_generic_params(
tm_sender,
verif_token,
FailParamsWithStep::new(
time_stamp,
&EcssEnumU16::new(*step),
verification_handler,
FailParamHelper {
error_code,
&self.fail_data_buf[..fail_data_len],
),
params: params.as_ref(),
timestamp,
small_data_buf: &mut self.fail_data_buf,
},
&EcssEnumU16::new(*step),
)?;
if !error_propagated {
log::warn!(
"error params for completion failure were not propated: {:?}",
params.as_ref()
);
}
true
}
ActionReplyVariant::Completed => {
verification_handler.completion_success(tm_sender, verif_token, time_stamp)?;
verification_handler.completion_success(tm_sender, verif_token, timestamp)?;
true
}
ActionReplyVariant::StepSuccess { step } => {
verification_handler.step_success(
tm_sender,
&verif_token,
time_stamp,
timestamp,
EcssEnumU16::new(*step),
)?;
false

View File

@ -411,24 +411,17 @@ where
return Ok(());
}
let active_request = active_req_opt.unwrap();
match self.reply_handler.handle_reply(
let result = self.reply_handler.handle_reply(
reply,
active_request,
&self.service_helper.common.tm_sender,
&self.service_helper.common.verif_reporter,
time_stamp,
) {
Ok(finished) => {
if finished {
self.active_request_map.remove(reply.request_id());
}
Ok(())
}
Err(e) => {
self.active_request_map.remove(reply.request_id());
Err(e)
}
);
if result.is_err() || (result.is_ok() && *result.as_ref().unwrap()) {
self.active_request_map.remove(reply.request_id());
}
result.map(|_| ())
}
pub fn check_for_request_timeouts(&mut self) {