From 3173b18cebe289ae86ccd7f987179485a7f7a6ae Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 29 Apr 2024 23:46:21 +0200 Subject: [PATCH] updated sat-rs --- Cargo.lock | 48 ++++++++++----------- Cargo.toml | 4 +- src/events.rs | 13 +++--- src/pus/action.rs | 107 +++++++++++++++------------------------------- src/pus/mod.rs | 17 +++----- 5 files changed, 71 insertions(+), 118 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a90bdfb..bfbcfa3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -172,8 +172,7 @@ dependencies = [ [[package]] name = "cobs" version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" +source = "git+https://github.com/robamu/cobs.rs.git?branch=all_features#c70a7f30fd00a7cbdb7666dec12b437977385d40" [[package]] name = "colorchoice" @@ -313,9 +312,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "fern" @@ -417,9 +416,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash", "allocator-api2", @@ -513,9 +512,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" [[package]] name = "linux-raw-sys" @@ -655,15 +654,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec 1.13.2", - "windows-targets 0.48.5", + "windows-targets 0.52.5", ] [[package]] @@ -713,11 +712,11 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", ] [[package]] @@ -777,8 +776,7 @@ checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "satrs" version = "0.2.0-rc.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2adc1d9369e3f7e21dabb3181e36c914d1a3f68f4900207a2baa129c2fd5baba" +source = "git+https://egit.irs.uni-stuttgart.de/rust/sat-rs.git?branch=rework-params-a-bit#2cc7f03a05eecd7e3f9d33d73651c1ecc230aa6a" dependencies = [ "bus", "cobs", @@ -836,9 +834,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.198" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a" dependencies = [ "serde_derive", ] @@ -856,9 +854,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc" dependencies = [ "proc-macro2", "quote", @@ -911,9 +909,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", "windows-sys 0.52.0", @@ -1053,7 +1051,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.6", + "winnow 0.6.7", ] [[package]] @@ -1333,9 +1331,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c976aaaa0e1f90dbb21e9587cdaf1d9679a1cde8875c0d6bd83ab96a208352" +checksum = "14b9415ee827af173ebb3f15f9083df5a122eb93572ec28741fb153356ea2578" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 3b8f17a..adeb082 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,8 +25,8 @@ once_cell = "1.19" [dependencies.satrs] version = "0.2.0-rc.5" -# git = "https://egit.irs.uni-stuttgart.de/rust/sat-rs.git" -# branch = "main" +git = "https://egit.irs.uni-stuttgart.de/rust/sat-rs.git" +branch = "rework-params-a-bit" features = ["test_util"] [dependencies.satrs-mib] diff --git a/src/events.rs b/src/events.rs index b341b33..44ca289 100644 --- a/src/events.rs +++ b/src/events.rs @@ -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, 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(¶m_vec), + &mut self.small_params_buf, + event_msg.params(), ) .expect("Sending TM as event failed"); } diff --git a/src/pus/action.rs b/src/pus/action.rs index fda6d03..845bcfe 100644 --- a/src/pus/action.rs +++ b/src/pus/action.rs @@ -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 for ActionReplyH active_request: &ActivePusActionRequestStd, tm_sender: &(impl EcssTmSender + ?Sized), verification_handler: &impl VerificationReportingProvider, - time_stamp: &[u8], + timestamp: &[u8], ) -> Result { let verif_token: VerificationToken = active_request .token() @@ -72,64 +72,23 @@ impl PusReplyHandler 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 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 diff --git a/src/pus/mod.rs b/src/pus/mod.rs index 5c85223..e34c565 100644 --- a/src/pus/mod.rs +++ b/src/pus/mod.rs @@ -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) {