diff --git a/scripts/ims100_testapp b/scripts/ims100_testapp deleted file mode 100644 index 956a66b..0000000 Binary files a/scripts/ims100_testapp and /dev/null differ diff --git a/src/handlers/camera.rs b/src/handlers/camera.rs index 3fdbb26..6145649 100644 --- a/src/handlers/camera.rs +++ b/src/handlers/camera.rs @@ -35,11 +35,14 @@ use satrs::hk::HkRequest; use satrs::request::{GenericMessage, MessageMetadata, UniqueApidTargetId}; use satrs::tmtc::PacketAsVec; use serde::{Deserialize, Serialize}; -use std::process::Command; +use std::process::{Command, Output}; use std::sync::mpsc; use satrs::pus::action::{ActionReplyPus, ActionReplyVariant}; +use satrs::pus::EcssTmtcError; +use crate::pus::action::send_data_reply; -const IMS_TESTAPP: &str = "scripts/ims100_testapp"; +// const IMS_TESTAPP: &str = "scripts/ims100_testapp"; +const IMS_TESTAPP: &str = "ims100_testapp"; const DEFAULT_SINGLE_CAM_PARAMS: CameraPictureParameters = CameraPictureParameters { R: 8, @@ -141,6 +144,7 @@ pub enum CameraError { DeserializeError, ListFileError, IoError(std::io::Error), + EcssTmtcError(EcssTmtcError), } impl From for CameraError { @@ -149,6 +153,12 @@ impl From for CameraError { } } +impl From 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 { @@ -170,6 +180,9 @@ impl fmt::Display for CameraError { CameraError::IoError(io_error) => { write!(f, "{}", io_error) } + CameraError::EcssTmtcError(ecss_tmtc_error) => { + write!(f ,"{}", ecss_tmtc_error) + } } } } @@ -276,12 +289,14 @@ impl IMS100BatchHandler { _ => return Err(CameraError::VariantNotImplemented), }, }; - self.take_picture(param)?; + let output = self.take_picture(param)?; + debug!("Sending action reply!"); + send_data_reply(self.id, output.stdout, &self.stamp_helper, &self.tm_tx)?; self.action_reply_tx.send(GenericMessage::new(*requestor_info, ActionReplyPus::new(action_request.action_id, ActionReplyVariant::Completed))).unwrap(); Ok(()) } - pub fn take_picture(&mut self, param: CameraPictureParameters) -> Result<(), CameraError> { + pub fn take_picture(&mut self, param: CameraPictureParameters) -> Result { info!("Taking image!"); let mut cmd = Command::new(IMS_TESTAPP); cmd.arg("-R") @@ -305,12 +320,11 @@ impl IMS100BatchHandler { .arg(¶m.E.to_string()) .arg("-w") .arg(¶m.W.to_string()); - let output = cmd.output()?; - debug!("{}", String::from_utf8_lossy(&output.stdout)); + debug!("Imager Output: {}", String::from_utf8_lossy(&output.stdout)); - Ok(()) + Ok(output) } pub fn list_current_images(&self) -> Result, CameraError> { diff --git a/src/pus/action.rs b/src/pus/action.rs index 7d597e4..66d86c7 100644 --- a/src/pus/action.rs +++ b/src/pus/action.rs @@ -1,5 +1,4 @@ use log::{error, warn}; -use ops_sat_rs::config::components::PUS_ACTION_SERVICE; use ops_sat_rs::config::tmtc_err; use satrs::action::{ActionRequest, ActionRequestVariant}; use satrs::params::WritableToBeBytes; @@ -10,17 +9,17 @@ use satrs::pus::verification::{ FailParams, FailParamsWithStep, TcStateAccepted, TcStateStarted, VerificationReporter, VerificationReportingProvider, VerificationToken, }; -use satrs::pus::{ - ActiveRequestProvider, EcssTcAndToken, EcssTcInVecConverter, EcssTmSender, EcssTmtcError, - GenericConversionError, PusPacketHandlerResult, PusReplyHandler, PusServiceHelper, - PusTcToRequestConverter, -}; +use satrs::pus::{ActiveRequestProvider, EcssTcAndToken, EcssTcInVecConverter, EcssTmSender, EcssTmtcError, GenericConversionError, PusPacketHandlerResult, PusReplyHandler, PusServiceHelper, PusTcToRequestConverter, PusTmVariant}; use satrs::request::{GenericMessage, UniqueApidTargetId}; use satrs::spacepackets::ecss::tc::PusTcReader; use satrs::spacepackets::ecss::{EcssEnumU16, PusPacket}; use satrs::tmtc::PacketAsVec; use std::sync::mpsc; use std::time::Duration; +use satrs::spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader}; +use satrs::spacepackets::SpHeader; +use ops_sat_rs::config::components::PUS_ACTION_SERVICE; +use ops_sat_rs::TimeStampHelper; use crate::requests::GenericRequestRouter; @@ -29,6 +28,8 @@ use super::{ PusTargetedRequestService, TargetedPusService, }; +pub const DATA_REPLY: u8 = 130; + pub struct ActionReplyHandler { fail_data_buf: [u8; 128], } @@ -270,6 +271,22 @@ impl TargetedPusService for ActionServiceWrapper { } } +pub fn send_data_reply(apid_target: UniqueApidTargetId, reply_data: Vec, stamp_helper: &TimeStampHelper, tm_sender: &TmSender) -> Result<(), EcssTmtcError> { + let sp_header = SpHeader::new_from_apid(apid_target.apid); + let sec_header = PusTmSecondaryHeader::new(8, DATA_REPLY, 0, 0, stamp_helper.stamp()); + let mut data = Vec::new(); + data.extend(apid_target.apid.to_be_bytes()); + data.extend(apid_target.unique_id.to_be_bytes()); + data.extend(reply_data); + let data_reply_tm = PusTmCreator::new( + sp_header, + sec_header, + &data, + true, + ); + tm_sender.send_tm(apid_target.id(), PusTmVariant::Direct(data_reply_tm)) +} + #[cfg(test)] mod tests { use satrs::pus::test_util::{