Fixes and optimizations for camera #27

Merged
muellerr merged 5 commits from fixes-and-optimizations-camera into main 2024-04-30 17:34:28 +02:00
12 changed files with 272 additions and 233 deletions

53
Cargo.lock generated
View File

@ -144,9 +144,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.95" version = "1.0.96"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b" checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
@ -172,8 +172,7 @@ dependencies = [
[[package]] [[package]]
name = "cobs" name = "cobs"
version = "0.2.3" version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/robamu/cobs.rs.git?branch=all_features#c70a7f30fd00a7cbdb7666dec12b437977385d40"
checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15"
[[package]] [[package]]
name = "colorchoice" name = "colorchoice"
@ -313,9 +312,9 @@ dependencies = [
[[package]] [[package]]
name = "fastrand" name = "fastrand"
version = "2.0.2" version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a"
[[package]] [[package]]
name = "fern" name = "fern"
@ -417,9 +416,9 @@ dependencies = [
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.14.3" version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
dependencies = [ dependencies = [
"ahash", "ahash",
"allocator-api2", "allocator-api2",
@ -513,9 +512,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.153" version = "0.2.154"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346"
[[package]] [[package]]
name = "linux-raw-sys" name = "linux-raw-sys"
@ -655,15 +654,15 @@ dependencies = [
[[package]] [[package]]
name = "parking_lot_core" name = "parking_lot_core"
version = "0.9.9" version = "0.9.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
"redox_syscall", "redox_syscall",
"smallvec 1.13.2", "smallvec 1.13.2",
"windows-targets 0.48.5", "windows-targets 0.52.5",
] ]
[[package]] [[package]]
@ -713,11 +712,11 @@ dependencies = [
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.4.1" version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 2.5.0",
] ]
[[package]] [[package]]
@ -777,14 +776,14 @@ checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
[[package]] [[package]]
name = "satrs" name = "satrs"
version = "0.2.0-rc.5" version = "0.2.0-rc.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://egit.irs.uni-stuttgart.de/rust/sat-rs.git?branch=main#29f71c2a571e7492cf5d997d4c11c3f844de83bc"
checksum = "2adc1d9369e3f7e21dabb3181e36c914d1a3f68f4900207a2baa129c2fd5baba"
dependencies = [ dependencies = [
"bus", "bus",
"cobs", "cobs",
"crc", "crc",
"crossbeam-channel", "crossbeam-channel",
"delegate", "delegate",
"derive-new",
"downcast-rs", "downcast-rs",
"dyn-clone", "dyn-clone",
"hashbrown", "hashbrown",
@ -836,9 +835,9 @@ dependencies = [
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.198" version = "1.0.199"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
@ -856,9 +855,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.198" version = "1.0.199"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -911,9 +910,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]] [[package]]
name = "socket2" name = "socket2"
version = "0.5.6" version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c"
dependencies = [ dependencies = [
"libc", "libc",
"windows-sys 0.52.0", "windows-sys 0.52.0",
@ -1053,7 +1052,7 @@ dependencies = [
"serde", "serde",
"serde_spanned", "serde_spanned",
"toml_datetime", "toml_datetime",
"winnow 0.6.6", "winnow 0.6.7",
] ]
[[package]] [[package]]
@ -1333,9 +1332,9 @@ dependencies = [
[[package]] [[package]]
name = "winnow" name = "winnow"
version = "0.6.6" version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0c976aaaa0e1f90dbb21e9587cdaf1d9679a1cde8875c0d6bd83ab96a208352" checksum = "14b9415ee827af173ebb3f15f9083df5a122eb93572ec28741fb153356ea2578"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]

View File

@ -25,8 +25,8 @@ once_cell = "1.19"
[dependencies.satrs] [dependencies.satrs]
version = "0.2.0-rc.5" version = "0.2.0-rc.5"
# git = "https://egit.irs.uni-stuttgart.de/rust/sat-rs.git" git = "https://egit.irs.uni-stuttgart.de/rust/sat-rs.git"
# branch = "main" branch = "main"
features = ["test_util"] features = ["test_util"]
[dependencies.satrs-mib] [dependencies.satrs-mib]

View File

@ -2,6 +2,7 @@ use lazy_static::lazy_static;
use num_enum::{IntoPrimitive, TryFromPrimitive}; use num_enum::{IntoPrimitive, TryFromPrimitive};
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use satrs::events::{EventU32TypedSev, SeverityInfo}; use satrs::events::{EventU32TypedSev, SeverityInfo};
use satrs::res_code::ResultU16;
use satrs::spacepackets::PacketId; use satrs::spacepackets::PacketId;
use satrs_mib::res_code::ResultU16Info; use satrs_mib::res_code::ResultU16Info;
use satrs_mib::resultcode; use satrs_mib::resultcode;
@ -40,11 +41,13 @@ pub enum CustomPusServiceId {
#[derive(Debug)] #[derive(Debug)]
pub enum GroupId { pub enum GroupId {
Tmtc = 0, Generic = 0,
Hk = 1, Tmtc = 1,
Mode = 2, Hk = 2,
Action = 3, Mode = 3,
Controller = 4, Action = 4,
Controller = 5,
Camera = 6,
} }
pub const TEST_EVENT: EventU32TypedSev<SeverityInfo> = pub const TEST_EVENT: EventU32TypedSev<SeverityInfo> =
@ -187,9 +190,11 @@ pub mod cfg_file {
} }
} }
#[resultcode]
pub const GENERIC_FAILED: ResultU16 = ResultU16::new(GroupId::Generic as u8, 1);
pub mod tmtc_err { pub mod tmtc_err {
use super::*; use super::*;
use satrs::res_code::ResultU16;
#[resultcode] #[resultcode]
pub const INVALID_PUS_SERVICE: ResultU16 = ResultU16::new(GroupId::Tmtc as u8, 0); pub const INVALID_PUS_SERVICE: ResultU16 = ResultU16::new(GroupId::Tmtc as u8, 0);
@ -220,12 +225,12 @@ pub mod tmtc_err {
UNKNOWN_TARGET_ID_EXT, UNKNOWN_TARGET_ID_EXT,
ROUTING_ERROR_EXT, ROUTING_ERROR_EXT,
NOT_ENOUGH_APP_DATA_EXT, NOT_ENOUGH_APP_DATA_EXT,
REQUEST_TIMEOUT_EXT,
]; ];
} }
pub mod action_err { pub mod action_err {
use super::*; use super::*;
use satrs::res_code::ResultU16;
#[resultcode] #[resultcode]
pub const INVALID_ACTION_ID: ResultU16 = ResultU16::new(GroupId::Action as u8, 0); pub const INVALID_ACTION_ID: ResultU16 = ResultU16::new(GroupId::Action as u8, 0);
@ -235,7 +240,6 @@ pub mod action_err {
pub mod hk_err { pub mod hk_err {
use super::*; use super::*;
use satrs::res_code::ResultU16;
#[resultcode] #[resultcode]
pub const TARGET_ID_MISSING: ResultU16 = ResultU16::new(GroupId::Hk as u8, 0); pub const TARGET_ID_MISSING: ResultU16 = ResultU16::new(GroupId::Hk as u8, 0);
@ -256,7 +260,6 @@ pub mod hk_err {
pub mod mode_err { pub mod mode_err {
use super::*; use super::*;
use satrs::res_code::ResultU16;
#[resultcode] #[resultcode]
pub const WRONG_MODE: ResultU16 = ResultU16::new(GroupId::Mode as u8, 0); pub const WRONG_MODE: ResultU16 = ResultU16::new(GroupId::Mode as u8, 0);
@ -264,7 +267,6 @@ pub mod mode_err {
pub mod ctrl_err { pub mod ctrl_err {
use super::*; use super::*;
use satrs::res_code::ResultU16;
#[resultcode] #[resultcode]
pub const INVALID_CMD_FORMAT: ResultU16 = ResultU16::new(GroupId::Controller as u8, 0); pub const INVALID_CMD_FORMAT: ResultU16 = ResultU16::new(GroupId::Controller as u8, 0);
@ -287,6 +289,47 @@ pub mod ctrl_err {
SHELL_CMD_IO_ERROR_EXT, SHELL_CMD_IO_ERROR_EXT,
SHELL_CMD_EXECUTION_FAILURE_EXT, SHELL_CMD_EXECUTION_FAILURE_EXT,
SHELL_CMD_INVALID_FORMAT_EXT, SHELL_CMD_INVALID_FORMAT_EXT,
FILESYSTEM_COPY_ERROR_EXT,
IMAGE_NOT_FOUND_FOR_COPY_EXT,
INVALID_LOGFILE_PATH_EXT,
];
}
pub mod cam_error {
use super::*;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum CameraError {
#[error("Error taking image: {0}")]
TakeImageError(String),
#[error("error listing image files: {0}")]
ListFileError(String),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
}
#[resultcode]
pub const TAKE_IMAGE_ERROR: ResultU16 = ResultU16::new(GroupId::Camera as u8, 0);
#[resultcode]
pub const NO_DATA: ResultU16 = ResultU16::new(GroupId::Camera as u8, 1);
#[resultcode]
pub const ACTION_REQ_VARIANT_NOT_IMPL: ResultU16 = ResultU16::new(GroupId::Camera as u8, 2);
#[resultcode]
pub const DESERIALIZE_ERROR: ResultU16 = ResultU16::new(GroupId::Camera as u8, 3);
// TODO: Probably could be in a dedicated modules for these returnvalues.
#[resultcode]
pub const LIST_FILE_ERROR: ResultU16 = ResultU16::new(GroupId::Camera as u8, 4);
#[resultcode]
pub const IO_ERROR: ResultU16 = ResultU16::new(GroupId::Camera as u8, 5);
pub const CAM_ERR_RESULTS: &[ResultU16Info] = &[
TAKE_IMAGE_ERROR_EXT,
NO_DATA_EXT,
ACTION_REQ_VARIANT_NOT_IMPL_EXT,
DESERIALIZE_ERROR_EXT,
LIST_FILE_ERROR_EXT,
IO_ERROR_EXT,
]; ];
} }

View File

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

View File

@ -27,22 +27,22 @@
use crate::pus::action::send_data_reply; use crate::pus::action::send_data_reply;
use crate::requests::CompositeRequest; use crate::requests::CompositeRequest;
use derive_new::new; use derive_new::new;
use log::{debug, info}; use log::info;
use num_enum::TryFromPrimitive; use num_enum::TryFromPrimitive;
use ops_sat_rs::config::cam_error::{self, CameraError};
use ops_sat_rs::config::GENERIC_FAILED;
use ops_sat_rs::TimeStampHelper; use ops_sat_rs::TimeStampHelper;
use satrs::action::{ActionRequest, ActionRequestVariant}; use satrs::action::{ActionRequest, ActionRequestVariant};
use satrs::hk::HkRequest; use satrs::hk::HkRequest;
use satrs::params::Params;
use satrs::pus::action::{ActionReplyPus, ActionReplyVariant}; use satrs::pus::action::{ActionReplyPus, ActionReplyVariant};
use satrs::pus::EcssTmtcError;
use satrs::request::{GenericMessage, MessageMetadata, UniqueApidTargetId}; use satrs::request::{GenericMessage, MessageMetadata, UniqueApidTargetId};
use satrs::res_code::ResultU16;
use satrs::tmtc::PacketAsVec; use satrs::tmtc::PacketAsVec;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fmt;
use std::fmt::Formatter;
use std::process::{Command, Output}; use std::process::{Command, Output};
use std::sync::mpsc; use std::sync::mpsc;
// const IMS_TESTAPP: &str = "scripts/ims100_testapp";
const IMS_TESTAPP: &str = "ims100_testapp"; const IMS_TESTAPP: &str = "ims100_testapp";
const DEFAULT_SINGLE_CAM_PARAMS: CameraPictureParameters = CameraPictureParameters { const DEFAULT_SINGLE_CAM_PARAMS: CameraPictureParameters = CameraPictureParameters {
@ -112,58 +112,6 @@ pub struct CameraPictureParameters {
pub W: u32, // wait time between pictures in ms, max: 40000 pub W: u32, // wait time between pictures in ms, max: 40000
} }
#[derive(Debug)]
#[allow(dead_code)]
pub enum CameraError {
TakeImageError,
NoDataSent,
VariantNotImplemented,
DeserializeError,
ListFileError,
IoError(std::io::Error),
EcssTmtcError(EcssTmtcError),
}
impl From<std::io::Error> for CameraError {
fn from(value: std::io::Error) -> Self {
Self::IoError(value)
}
}
impl From<EcssTmtcError> for CameraError {
fn from(value: EcssTmtcError) -> Self {
Self::EcssTmtcError(value)
}
}
impl fmt::Display for CameraError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
CameraError::TakeImageError => {
write!(f, "Error taking image.")
}
CameraError::NoDataSent => {
write!(f, "No data sent.")
}
CameraError::VariantNotImplemented => {
write!(f, "Request variant not implemented.")
}
CameraError::DeserializeError => {
write!(f, "Unable to deserialize parameters.")
}
CameraError::ListFileError => {
write!(f, "Error listing image files.")
}
CameraError::IoError(io_error) => {
write!(f, "{}", io_error)
}
CameraError::EcssTmtcError(ecss_tmtc_error) => {
write!(f, "{}", ecss_tmtc_error)
}
}
}
}
#[derive(Debug)] #[derive(Debug)]
pub struct Ims100BatchHandler { pub struct Ims100BatchHandler {
id: UniqueApidTargetId, id: UniqueApidTargetId,
@ -205,11 +153,7 @@ impl Ims100BatchHandler {
self.handle_hk_request(&msg.requestor_info, hk_request); self.handle_hk_request(&msg.requestor_info, hk_request);
} }
CompositeRequest::Action(action_request) => { CompositeRequest::Action(action_request) => {
if let Err(e) = self.handle_action_request(&msg.requestor_info, action_request);
self.handle_action_request(&msg.requestor_info, action_request)
{
log::warn!("camera action request IO error: {e}");
}
} }
}, },
Err(e) => match e { Err(e) => match e {
@ -235,53 +179,124 @@ impl Ims100BatchHandler {
&mut self, &mut self,
requestor_info: &MessageMetadata, requestor_info: &MessageMetadata,
action_request: &ActionRequest, action_request: &ActionRequest,
) -> Result<(), CameraError> { ) {
let param = match ActionId::try_from(action_request.action_id).expect("Invalid action id") { let param = match ActionId::try_from(action_request.action_id).expect("Invalid action id") {
ActionId::DefaultSingle => DEFAULT_SINGLE_CAM_PARAMS, ActionId::DefaultSingle => DEFAULT_SINGLE_CAM_PARAMS,
ActionId::BalancedSingle => BALANCED_SINGLE_CAM_PARAMS, ActionId::BalancedSingle => BALANCED_SINGLE_CAM_PARAMS,
ActionId::DefaultSingleFlatSat => DEFAULT_SINGLE_FLATSAT_CAM_PARAMS, ActionId::DefaultSingleFlatSat => DEFAULT_SINGLE_FLATSAT_CAM_PARAMS,
ActionId::BalancedSingleFlatSat => BALANCED_SINGLE_FLATSAT_CAM_PARAMS, ActionId::BalancedSingleFlatSat => BALANCED_SINGLE_FLATSAT_CAM_PARAMS,
ActionId::CustomParameters => match &action_request.variant { ActionId::CustomParameters => match &action_request.variant {
ActionRequestVariant::NoData => return Err(CameraError::NoDataSent), ActionRequestVariant::NoData => {
ActionRequestVariant::StoreData(_) => { self.send_completion_failure(
// let param = serde_json::from_slice() requestor_info,
// TODO implement non dynamic version action_request,
return Err(CameraError::VariantNotImplemented); cam_error::NO_DATA,
None,
);
return;
} }
ActionRequestVariant::VecData(data) => { ActionRequestVariant::VecData(data) => {
let param: serde_json::Result<CameraPictureParameters> = let param: serde_json::Result<CameraPictureParameters> =
serde_json::from_slice(data.as_slice()); serde_json::from_slice(data.as_slice());
match param { match param {
Ok(param) => param, Ok(param) => param,
Err(_) => { Err(e) => {
return Err(CameraError::DeserializeError); self.send_completion_failure(
requestor_info,
action_request,
cam_error::DESERIALIZE_ERROR,
Some(e.to_string().into()),
);
return;
} }
} }
} }
_ => return Err(CameraError::VariantNotImplemented), _ => {
self.send_completion_failure(
requestor_info,
action_request,
cam_error::ACTION_REQ_VARIANT_NOT_IMPL,
None,
);
return;
}
}, },
}; };
let output = self.take_picture(param)?; match self.take_picture(&param) {
info!("Sending action reply!"); Ok(ref output) => {
send_data_reply(self.id, output.stdout, &self.stamp_helper, &self.tm_tx)?; self.send_completion_success(requestor_info, action_request);
self.action_reply_tx if let Err(e) =
.send(GenericMessage::new( send_data_reply(self.id, &output.stdout, &self.stamp_helper, &self.tm_tx)
*requestor_info, {
ActionReplyPus::new(action_request.action_id, ActionReplyVariant::Completed), log::error!("sending data reply unexpectedly failed: {e}");
)) }
.unwrap(); }
Ok(()) Err(e) => match e {
CameraError::TakeImageError(ref err_str) => {
self.send_completion_failure(
requestor_info,
action_request,
cam_error::TAKE_IMAGE_ERROR,
Some(err_str.to_string().into()),
);
}
CameraError::IoError(ref e) => {
self.send_completion_failure(
requestor_info,
action_request,
cam_error::IO_ERROR,
Some(e.to_string().into()),
);
}
_ => {
log::warn!("unexpected error: {:?}", e);
self.send_completion_failure(
requestor_info,
action_request,
GENERIC_FAILED,
None,
);
}
},
}
} }
pub fn take_picture(&mut self, param: CameraPictureParameters) -> Result<Output, CameraError> { pub fn send_completion_success(&self, requestor: &MessageMetadata, action_req: &ActionRequest) {
info!("Taking image!"); let result = self.action_reply_tx.send(GenericMessage::new_action_reply(
*requestor,
action_req.action_id,
ActionReplyVariant::Completed,
));
if result.is_err() {
log::error!("sending action reply failed");
}
}
pub fn send_completion_failure(
&self,
requestor: &MessageMetadata,
action_req: &ActionRequest,
error_code: ResultU16,
params: Option<Params>,
) {
let result = self.action_reply_tx.send(GenericMessage::new_action_reply(
*requestor,
action_req.action_id,
ActionReplyVariant::CompletionFailed { error_code, params },
));
if result.is_err() {
log::error!("sending action reply failed");
}
}
pub fn take_picture(&mut self, param: &CameraPictureParameters) -> Result<Output, CameraError> {
let mut cmd = Command::new(IMS_TESTAPP); let mut cmd = Command::new(IMS_TESTAPP);
cmd.arg("-R") cmd.arg("-R")
.arg(&param.R.to_string()) .arg(param.R.to_string())
.arg("-G") .arg("-G")
.arg(&param.G.to_string()) .arg(param.G.to_string())
.arg("-B") .arg("-B")
.arg(&param.B.to_string()) .arg(param.B.to_string())
.arg("-c") .arg("-c")
.arg("/dev/cam_tty") .arg("/dev/cam_tty")
.arg("-m") .arg("-m")
@ -289,18 +304,27 @@ impl Ims100BatchHandler {
.arg("-v") .arg("-v")
.arg("0") .arg("0")
.arg("-n") .arg("-n")
.arg(&param.N.to_string()); .arg(param.N.to_string());
if param.P { if param.P {
cmd.arg("-p"); cmd.arg("-p");
} }
cmd.arg("-e") cmd.arg("-e")
.arg(&param.E.to_string()) .arg(param.E.to_string())
.arg("-w") .arg("-w")
.arg(&param.W.to_string()); .arg(param.W.to_string());
info!("taking image with command: {cmd:?}");
let output = cmd.output()?; let output = cmd.output()?;
debug!("Imager Output: {}", String::from_utf8_lossy(&output.stdout)); info!("imager cmd status: {}", &output.status);
info!("imager output: {}", String::from_utf8_lossy(&output.stdout));
let mut error_string = String::new();
if !output.stderr.is_empty() {
error_string = String::from_utf8_lossy(&output.stderr).to_string();
log::warn!("imager error: {}", error_string);
}
if !output.status.success() {
return Err(CameraError::TakeImageError(error_string.to_string()));
}
Ok(output) Ok(output)
} }
@ -313,49 +337,11 @@ impl Ims100BatchHandler {
let files: Vec<String> = output_str.lines().map(|s| s.to_string()).collect(); let files: Vec<String> = output_str.lines().map(|s| s.to_string()).collect();
Ok(files) Ok(files)
} else { } else {
Err(CameraError::ListFileError) Err(CameraError::ListFileError(
String::from_utf8_lossy(&output.stderr).to_string(),
))
} }
} }
#[allow(clippy::too_many_arguments)]
#[allow(dead_code)]
pub fn take_picture_from_str(
&mut self,
R: &str,
G: &str,
B: &str,
N: &str,
P: &str,
E: &str,
W: &str,
) -> Result<(), CameraError> {
let mut cmd = Command::new("ims100_testapp");
cmd.arg("-R")
.arg(R)
.arg("-G")
.arg(G)
.arg("-B")
.arg(B)
.arg("-c")
.arg("/dev/cam_tty")
.arg("-m")
.arg("/dev/cam_sd")
.arg("-v")
.arg("0")
.arg("-n")
.arg(N)
.arg(P)
.arg("-e")
.arg(E)
.arg("-w")
.arg(W);
let output = cmd.output()?;
debug!("{}", String::from_utf8_lossy(&output.stdout));
Ok(())
}
} }
#[cfg(test)] #[cfg(test)]
@ -372,6 +358,7 @@ mod tests {
use satrs::tmtc::PacketAsVec; use satrs::tmtc::PacketAsVec;
use std::sync::mpsc; use std::sync::mpsc;
#[allow(dead_code)]
struct Ims1000Testbench { struct Ims1000Testbench {
pub handler: Ims100BatchHandler, pub handler: Ims100BatchHandler,
pub composite_req_tx: mpsc::Sender<GenericMessage<CompositeRequest>>, pub composite_req_tx: mpsc::Sender<GenericMessage<CompositeRequest>>,
@ -393,13 +380,7 @@ mod tests {
time_helper, time_helper,
); );
Ims1000Testbench { Ims1000Testbench {
handler: Ims100BatchHandler::new( handler: cam_handler,
CAMERA_HANDLER,
composite_request_rx,
tm_tx,
action_reply_tx,
time_helper,
),
composite_req_tx: composite_request_tx, composite_req_tx: composite_request_tx,
tm_receiver: tm_rx, tm_receiver: tm_rx,
action_reply_rx, action_reply_rx,
@ -412,7 +393,7 @@ mod tests {
let mut testbench = Ims1000Testbench::default(); let mut testbench = Ims1000Testbench::default();
testbench testbench
.handler .handler
.take_picture(DEFAULT_SINGLE_FLATSAT_CAM_PARAMS) .take_picture(&DEFAULT_SINGLE_FLATSAT_CAM_PARAMS)
.unwrap(); .unwrap();
} }
@ -436,7 +417,6 @@ mod tests {
testbench testbench
.handler .handler
.handle_action_request(&MessageMetadata::new(1, 1), &req) .handle_action_request(&MessageMetadata::new(1, 1), &req)
.unwrap();
} }
#[test] #[test]

View File

@ -1,14 +1,14 @@
use log::{debug, error, warn}; use log::{error, warn};
use ops_sat_rs::config::components::PUS_ACTION_SERVICE; use ops_sat_rs::config::components::PUS_ACTION_SERVICE;
use ops_sat_rs::config::tmtc_err; use ops_sat_rs::config::tmtc_err;
use ops_sat_rs::TimeStampHelper; use ops_sat_rs::TimeStampHelper;
use satrs::action::{ActionRequest, ActionRequestVariant}; use satrs::action::{ActionRequest, ActionRequestVariant};
use satrs::params::WritableToBeBytes;
use satrs::pus::action::{ use satrs::pus::action::{
ActionReplyPus, ActionReplyVariant, ActivePusActionRequestStd, DefaultActiveActionRequestMap, ActionReplyPus, ActionReplyVariant, ActivePusActionRequestStd, DefaultActiveActionRequestMap,
}; };
use satrs::pus::verification::{ 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, VerificationReportingProvider, VerificationToken,
}; };
use satrs::pus::{ use satrs::pus::{
@ -64,7 +64,7 @@ impl PusReplyHandler<ActivePusActionRequestStd, ActionReplyPus> for ActionReplyH
active_request: &ActivePusActionRequestStd, active_request: &ActivePusActionRequestStd,
tm_sender: &(impl EcssTmSender + ?Sized), tm_sender: &(impl EcssTmSender + ?Sized),
verification_handler: &impl VerificationReportingProvider, verification_handler: &impl VerificationReportingProvider,
time_stamp: &[u8], timestamp: &[u8],
) -> Result<bool, Self::Error> { ) -> Result<bool, Self::Error> {
let verif_token: VerificationToken<TcStateStarted> = active_request let verif_token: VerificationToken<TcStateStarted> = active_request
.token() .token()
@ -72,15 +72,23 @@ impl PusReplyHandler<ActivePusActionRequestStd, ActionReplyPus> for ActionReplyH
.expect("invalid token state"); .expect("invalid token state");
let remove_entry = match &reply.message.variant { let remove_entry = match &reply.message.variant {
ActionReplyVariant::CompletionFailed { error_code, params } => { ActionReplyVariant::CompletionFailed { error_code, params } => {
let mut fail_data_len = 0; let error_propagated = handle_completion_failure_with_generic_params(
if let Some(params) = params {
fail_data_len = params.write_to_be_bytes(&mut self.fail_data_buf)?;
}
verification_handler.completion_failure(
tm_sender, tm_sender,
verif_token, 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 true
} }
ActionReplyVariant::StepFailed { ActionReplyVariant::StepFailed {
@ -88,31 +96,35 @@ impl PusReplyHandler<ActivePusActionRequestStd, ActionReplyPus> for ActionReplyH
step, step,
params, params,
} => { } => {
let mut fail_data_len = 0; let error_propagated = handle_step_failure_with_generic_params(
if let Some(params) = params {
fail_data_len = params.write_to_be_bytes(&mut self.fail_data_buf)?;
}
verification_handler.step_failure(
tm_sender, tm_sender,
verif_token, verif_token,
FailParamsWithStep::new( verification_handler,
time_stamp, FailParamHelper {
&EcssEnumU16::new(*step),
error_code, 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 true
} }
ActionReplyVariant::Completed => { ActionReplyVariant::Completed => {
verification_handler.completion_success(tm_sender, verif_token, time_stamp)?; verification_handler.completion_success(tm_sender, verif_token, timestamp)?;
true true
} }
ActionReplyVariant::StepSuccess { step } => { ActionReplyVariant::StepSuccess { step } => {
verification_handler.step_success( verification_handler.step_success(
tm_sender, tm_sender,
&verif_token, &verif_token,
time_stamp, timestamp,
EcssEnumU16::new(*step), EcssEnumU16::new(*step),
)?; )?;
false false
@ -209,7 +221,7 @@ pub fn create_action_service(
PUS_ACTION_SERVICE.id(), PUS_ACTION_SERVICE.id(),
pus_action_rx, pus_action_rx,
tm_funnel_tx, tm_funnel_tx,
create_verification_reporter(PUS_ACTION_SERVICE.id(), PUS_ACTION_SERVICE.apid), create_verification_reporter(PUS_ACTION_SERVICE.id(), PUS_ACTION_SERVICE.apid, 2048),
EcssTcInVecConverter::default(), EcssTcInVecConverter::default(),
), ),
ActionRequestConverter::default(), ActionRequestConverter::default(),
@ -277,7 +289,7 @@ impl TargetedPusService for ActionServiceWrapper {
pub fn send_data_reply<TmSender: EcssTmSender>( pub fn send_data_reply<TmSender: EcssTmSender>(
apid_target: UniqueApidTargetId, apid_target: UniqueApidTargetId,
reply_data: Vec<u8>, reply_data: &Vec<u8>,
stamp_helper: &TimeStampHelper, stamp_helper: &TimeStampHelper,
tm_sender: &TmSender, tm_sender: &TmSender,
) -> Result<(), EcssTmtcError> { ) -> Result<(), EcssTmtcError> {
@ -287,8 +299,8 @@ pub fn send_data_reply<TmSender: EcssTmSender>(
data.extend(apid_target.apid.to_be_bytes()); data.extend(apid_target.apid.to_be_bytes());
data.extend(apid_target.unique_id.to_be_bytes()); data.extend(apid_target.unique_id.to_be_bytes());
data.extend(reply_data); data.extend(reply_data);
debug!( log::trace!(
"{}", "PUS action reply: {}",
String::from_utf8(data.clone()[6..].to_vec()).expect("Error decoding data reply.") String::from_utf8(data.clone()[6..].to_vec()).expect("Error decoding data reply.")
); );
let data_reply_tm = PusTmCreator::new(sp_header, sec_header, &data, true); let data_reply_tm = PusTmCreator::new(sp_header, sec_header, &data, true);

View File

@ -22,7 +22,7 @@ pub fn create_event_service(
PUS_EVENT_MANAGEMENT.id(), PUS_EVENT_MANAGEMENT.id(),
pus_event_rx, pus_event_rx,
tm_funnel_tx, tm_funnel_tx,
create_verification_reporter(PUS_EVENT_MANAGEMENT.id(), PUS_EVENT_MANAGEMENT.apid), create_verification_reporter(PUS_EVENT_MANAGEMENT.id(), PUS_EVENT_MANAGEMENT.apid, 16),
EcssTcInVecConverter::default(), EcssTcInVecConverter::default(),
), ),
event_request_tx, event_request_tx,

View File

@ -241,7 +241,7 @@ pub fn create_hk_service(
PUS_HK_SERVICE.id(), PUS_HK_SERVICE.id(),
pus_hk_rx, pus_hk_rx,
tm_funnel_tx, tm_funnel_tx,
create_verification_reporter(PUS_HK_SERVICE.id(), PUS_HK_SERVICE.apid), create_verification_reporter(PUS_HK_SERVICE.id(), PUS_HK_SERVICE.apid, 16),
EcssTcInVecConverter::default(), EcssTcInVecConverter::default(),
), ),
HkRequestConverter::default(), HkRequestConverter::default(),

View File

@ -30,8 +30,12 @@ use satrs::ComponentId;
use std::fmt::Debug; use std::fmt::Debug;
use std::sync::mpsc::{self, Sender}; use std::sync::mpsc::{self, Sender};
pub fn create_verification_reporter(owner_id: ComponentId, apid: Apid) -> VerificationReporter { pub fn create_verification_reporter(
let verif_cfg = VerificationReporterCfg::new(apid, 1, 2, 8).unwrap(); owner_id: ComponentId,
apid: Apid,
max_fail_data_len: usize,
) -> VerificationReporter {
let verif_cfg = VerificationReporterCfg::new(apid, 1, 2, max_fail_data_len).unwrap();
// Every software component which needs to generate verification telemetry, gets a cloned // Every software component which needs to generate verification telemetry, gets a cloned
// verification reporter. // verification reporter.
VerificationReporter::new(owner_id, &verif_cfg) VerificationReporter::new(owner_id, &verif_cfg)
@ -63,6 +67,7 @@ impl<TmSender: EcssTmSender> PusTcDistributor<TmSender> {
verif_reporter: create_verification_reporter( verif_reporter: create_verification_reporter(
PUS_ROUTING_SERVICE.id(), PUS_ROUTING_SERVICE.id(),
PUS_ROUTING_SERVICE.apid, PUS_ROUTING_SERVICE.apid,
16,
), ),
pus_router, pus_router,
stamp_helper: TimeStampHelper::default(), stamp_helper: TimeStampHelper::default(),
@ -399,20 +404,17 @@ where
return Ok(()); return Ok(());
} }
let active_request = active_req_opt.unwrap(); let active_request = active_req_opt.unwrap();
let request_finished = self let result = self.reply_handler.handle_reply(
.reply_handler
.handle_reply(
reply, reply,
active_request, active_request,
&self.service_helper.common.tm_sender, &self.service_helper.common.tm_sender,
&self.service_helper.common.verif_reporter, &self.service_helper.common.verif_reporter,
time_stamp, time_stamp,
) );
.unwrap_or(false); if result.is_err() || (result.is_ok() && *result.as_ref().unwrap()) {
if request_finished {
self.active_request_map.remove(reply.request_id()); self.active_request_map.remove(reply.request_id());
} }
Ok(()) result.map(|_| ())
} }
pub fn check_for_request_timeouts(&mut self) { pub fn check_for_request_timeouts(&mut self) {

View File

@ -212,7 +212,7 @@ pub fn create_mode_service(
PUS_MODE_SERVICE.id(), PUS_MODE_SERVICE.id(),
pus_action_rx, pus_action_rx,
tm_funnel_tx, tm_funnel_tx,
create_verification_reporter(PUS_MODE_SERVICE.id(), PUS_MODE_SERVICE.apid), create_verification_reporter(PUS_MODE_SERVICE.id(), PUS_MODE_SERVICE.apid, 16),
EcssTcInVecConverter::default(), EcssTcInVecConverter::default(),
), ),
ModeRequestConverter::default(), ModeRequestConverter::default(),

View File

@ -139,7 +139,11 @@ pub fn create_scheduler_service(
PUS_SCHEDULER_SERVICE.id(), PUS_SCHEDULER_SERVICE.id(),
pus_sched_rx, pus_sched_rx,
tm_funnel_tx, tm_funnel_tx,
create_verification_reporter(PUS_SCHEDULER_SERVICE.id(), PUS_SCHEDULER_SERVICE.apid), create_verification_reporter(
PUS_SCHEDULER_SERVICE.id(),
PUS_SCHEDULER_SERVICE.apid,
16,
),
EcssTcInVecConverter::default(), EcssTcInVecConverter::default(),
), ),
scheduler, scheduler,

View File

@ -27,7 +27,7 @@ pub fn create_test_service(
PUS_TEST_SERVICE.id(), PUS_TEST_SERVICE.id(),
pus_test_rx, pus_test_rx,
tm_funnel_tx, tm_funnel_tx,
create_verification_reporter(PUS_TEST_SERVICE.id(), PUS_TEST_SERVICE.apid), create_verification_reporter(PUS_TEST_SERVICE.id(), PUS_TEST_SERVICE.apid, 16),
EcssTcInVecConverter::default(), EcssTcInVecConverter::default(),
)); ));
TestCustomServiceWrapper { TestCustomServiceWrapper {