From 88d4384beb3bb54af2e6104bfcd03fe9089338f9 Mon Sep 17 00:00:00 2001 From: lkoester Date: Mon, 22 Apr 2024 16:56:49 +0200 Subject: [PATCH] this should be good for now --- Cargo.lock | 42 +++++++++++++------------- src/config.rs | 5 ++-- src/handlers/camera.rs | 68 ++++++++++++++++++++++++++++++++++-------- 3 files changed, 78 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f0a16ca..d468c5f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -360,7 +360,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -834,21 +834,21 @@ dependencies = [ ] [[package]] -<<<<<<< HEAD -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -======= name = "serde_spanned" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" dependencies = [ "serde", ->>>>>>> main +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", ] [[package]] @@ -1114,7 +1114,7 @@ checksum = "12168c33176773b86799be25e2a2ba07c7aab9968b37541f1094dbd7a60c8946" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -1125,7 +1125,7 @@ checksum = "9d8dc32e0095a7eeccebd0e3f09e9509365ecb3fc6ac4d6f5f14a3f6392942d1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.60", ] [[package]] @@ -1277,7 +1277,15 @@ dependencies = [ ] [[package]] -<<<<<<< HEAD +name = "winnow" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c976aaaa0e1f90dbb21e9587cdaf1d9679a1cde8875c0d6bd83ab96a208352" +dependencies = [ + "memchr", +] + +[[package]] name = "wmi" version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1289,14 +1297,6 @@ dependencies = [ "serde", "thiserror", "windows", -======= -name = "winnow" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c976aaaa0e1f90dbb21e9587cdaf1d9679a1cde8875c0d6bd83ab96a208352" -dependencies = [ - "memchr", ->>>>>>> main ] [[package]] diff --git a/src/config.rs b/src/config.rs index e02650d..dfeea50 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,13 +3,12 @@ use num_enum::{IntoPrimitive, TryFromPrimitive}; use satrs::spacepackets::PacketId; use satrs_mib::res_code::ResultU16Info; use satrs_mib::resultcode; -use std::env; use std::net::Ipv4Addr; use std::path::{Path, PathBuf}; pub const STOP_FILE_NAME: &str = "stop-experiment"; pub const CONFIG_FILE_NAME: &str = "exp278.toml"; -pub const HOME_FOLER_EXPERIMENT: &str = "/home/exp278"; +pub const HOME_FOLDER_EXPERIMENT: &str = "/home/exp278"; pub const LOG_FOLDER: &str = "logs"; pub const OBSW_SERVER_ADDR: Ipv4Addr = Ipv4Addr::UNSPECIFIED; @@ -43,7 +42,7 @@ pub enum GroupId { lazy_static! { pub static ref HOME_PATH: PathBuf = { let mut home_path = PathBuf::new(); - let mut home_path_default = homedir::get_my_home().expect("Getting home dir from OS failed.").expect("No home dir found."); + let home_path_default = homedir::get_my_home().expect("Getting home dir from OS failed.").expect("No home dir found."); home_path.push(if Path::new(HOME_FOLDER_EXPERIMENT).exists() { HOME_FOLDER_EXPERIMENT diff --git a/src/handlers/camera.rs b/src/handlers/camera.rs index e93a92c..3fdbb26 100644 --- a/src/handlers/camera.rs +++ b/src/handlers/camera.rs @@ -1,3 +1,5 @@ +use std::fmt; +use std::fmt::Formatter; /// Device handler implementation for the IMS-100 Imager used on the OPS-SAT mission. /// /// from the [OPSSAT Experimenter Wiki](https://opssat1.esoc.esa.int/projects/experimenter-information/wiki/Camera_Introduction): @@ -26,14 +28,13 @@ /// see also https://opssat1.esoc.esa.int/dmsf/files/6/view use crate::requests::CompositeRequest; use derive_new::new; -use log::debug; +use log::{debug, info}; use ops_sat_rs::TimeStampHelper; use satrs::action::{ActionRequest, ActionRequestVariant}; use satrs::hk::HkRequest; use satrs::request::{GenericMessage, MessageMetadata, UniqueApidTargetId}; use satrs::tmtc::PacketAsVec; use serde::{Deserialize, Serialize}; -use std::io::Error; use std::process::Command; use std::sync::mpsc; use satrs::pus::action::{ActionReplyPus, ActionReplyVariant}; @@ -131,6 +132,48 @@ pub struct CameraPictureParameters { 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), +} + +impl From for CameraError { + fn from(value: std::io::Error) -> Self { + Self::IoError(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) + } + } + } +} + #[allow(dead_code)] #[derive(Debug)] pub struct IMS100BatchHandler { @@ -207,20 +250,18 @@ impl IMS100BatchHandler { &mut self, requestor_info: &MessageMetadata, action_request: &ActionRequest, - ) -> std::io::Result<()> { + ) -> Result<(), CameraError> { let param = match CameraActionId::try_from(action_request.action_id).expect("Invalid action id") { CameraActionId::DefaultSingle => DEFAULT_SINGLE_CAM_PARAMS, CameraActionId::BalancedSingle => BALANCED_SINGLE_CAM_PARAMS, CameraActionId::DefaultSingleFlatSat => DEFAULT_SINGLE_FLATSAT_CAM_PARAMS, CameraActionId::BalancedSingleFlatSat => BALANCED_SINGLE_FLATSAT_CAM_PARAMS, CameraActionId::CustomParameters => match &action_request.variant { - ActionRequestVariant::NoData => return Err(Error::other("No Data sent!")), + ActionRequestVariant::NoData => return Err(CameraError::NoDataSent), ActionRequestVariant::StoreData(_) => { // let param = serde_json::from_slice() // TODO implement non dynamic version - return Err(Error::other( - "Static parameter transfer not implemented yet!", - )); + return Err(CameraError::VariantNotImplemented); } ActionRequestVariant::VecData(data) => { let param: serde_json::Result = @@ -228,11 +269,11 @@ impl IMS100BatchHandler { match param { Ok(param) => param, Err(_) => { - return Err(Error::other("Unable to deserialize parameters")); + return Err(CameraError::DeserializeError); } } } - _ => return Err(Error::other("Invalid Action Request Variant!")), + _ => return Err(CameraError::VariantNotImplemented), }, }; self.take_picture(param)?; @@ -240,7 +281,8 @@ impl IMS100BatchHandler { Ok(()) } - pub fn take_picture(&mut self, param: CameraPictureParameters) -> std::io::Result<()> { + pub fn take_picture(&mut self, param: CameraPictureParameters) -> Result<(), CameraError> { + info!("Taking image!"); let mut cmd = Command::new(IMS_TESTAPP); cmd.arg("-R") .arg(¶m.R.to_string()) @@ -271,7 +313,7 @@ impl IMS100BatchHandler { Ok(()) } - pub fn list_current_images(&self) -> std::io::Result> { + pub fn list_current_images(&self) -> Result, CameraError> { let output = Command::new("ls").arg("-l") .arg("*.png") .output()?; @@ -282,7 +324,7 @@ impl IMS100BatchHandler { Ok(files) } else { - Err(Error::other("Error getting file list.")) + Err(CameraError::ListFileError) } } @@ -295,7 +337,7 @@ impl IMS100BatchHandler { P: &str, E: &str, W: &str, - ) -> std::io::Result<()> { + ) -> Result<(), CameraError> { let mut cmd = Command::new("ims100_testapp"); cmd.arg("-R") .arg(R)