diff --git a/Cargo.lock b/Cargo.lock index 8bfd1c1..55bea81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -593,9 +593,9 @@ checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "satrs" -version = "0.2.0-rc.1" +version = "0.2.0-rc.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d6f3286d35464fdc75dc846b663aaad4a81437a50e623053b1b4d481d782cd0" +checksum = "6aa9241e4d6cb0cc395927cfe653d8bc4a9cb6b2c27f28fec713d5e6ceb0ba23" dependencies = [ "bus", "cobs", diff --git a/src/handlers/camera.rs b/src/handlers/camera.rs index d0eae69..629bbd2 100644 --- a/src/handlers/camera.rs +++ b/src/handlers/camera.rs @@ -114,7 +114,7 @@ impl TryFrom for CameraActionIds { // TODO what happens if limits are exceded #[allow(non_snake_case)] -#[derive(Serialize, Deserialize, new)] +#[derive(Debug, Serialize, Deserialize, new)] pub struct CameraPictureParameters { pub R: u8, pub G: u8, @@ -277,8 +277,59 @@ impl IMS100BatchHandler { #[cfg(test)] mod tests { + use std::sync::mpsc; + use std::sync::mpsc::{Receiver, Sender}; + use satrs::action::{ActionRequest, ActionRequestVariant}; + use satrs::request::{GenericMessage, MessageMetadata, UniqueApidTargetId}; + use satrs::tmtc::PacketAsVec; + use ops_sat_rs::TimeStampHelper; + use crate::handlers::camera::{CameraActionIds, CameraPictureParameters, DEFAULT_SINGLE_FLATSAT_CAM_PARAMS, IMS100BatchHandler}; + use crate::requests::CompositeRequest; + + fn create_handler() -> (IMS100BatchHandler, Sender>, Receiver) { + let id = UniqueApidTargetId::new(1,1); + let (req_tx,req_rx) = mpsc::channel(); + let (tm_tx, tm_rx) = mpsc::channel(); + let time_helper = TimeStampHelper::default(); + let mut cam_handler: IMS100BatchHandler = IMS100BatchHandler::new(id, req_rx, tm_tx, time_helper); + (cam_handler, req_tx, tm_rx) + } + #[test] - fn test_crc() { - // TODO + fn command_line_execution() { + let (mut cam_handler, mut req_tx, mut tm_rx) = create_handler(); + cam_handler.take_picture(DEFAULT_SINGLE_FLATSAT_CAM_PARAMS).unwrap(); + } + + #[test] + fn serialize_and_deserialize_command() { + let (mut cam_handler, mut req_tx, mut tm_rx) = create_handler(); + + let data = serde_json::to_string(&DEFAULT_SINGLE_FLATSAT_CAM_PARAMS).unwrap(); + println!("{}", data); + let param: CameraPictureParameters = serde_json::from_str(&data).unwrap(); + println!("{:?}", param); + } + + #[test] + fn test_action_req() { + let (mut cam_handler, mut req_tx, mut tm_rx) = create_handler(); + + let data = serde_json::to_string(&DEFAULT_SINGLE_FLATSAT_CAM_PARAMS).unwrap(); + let req = ActionRequest::new(CameraActionIds::CustomParameters as u32, ActionRequestVariant::VecData(data.as_bytes().to_vec())); + + cam_handler.handle_action_request(&MessageMetadata::new(1,1),&req).unwrap(); + } + + #[test] + fn test_action_req_channel() { + let (mut cam_handler, mut req_tx, mut tm_rx) = create_handler(); + + let data = serde_json::to_string(&DEFAULT_SINGLE_FLATSAT_CAM_PARAMS).unwrap(); + let req = ActionRequest::new(CameraActionIds::CustomParameters as u32, ActionRequestVariant::VecData(data.as_bytes().to_vec())); + let req = CompositeRequest::Action(req); + req_tx.send(GenericMessage::new(MessageMetadata::new(1,1), req)).unwrap(); + + cam_handler.periodic_operation(); } } \ No newline at end of file diff --git a/src/pus/action.rs b/src/pus/action.rs index cd2472f..f81d069 100644 --- a/src/pus/action.rs +++ b/src/pus/action.rs @@ -275,7 +275,7 @@ mod tests { use satrs::pus::test_util::{ TEST_APID, TEST_COMPONENT_ID_0, TEST_COMPONENT_ID_1, TEST_UNIQUE_ID_0, TEST_UNIQUE_ID_1, }; - use satrs::pus::verification; + use satrs::pus::{TcInMemory, verification}; use satrs::pus::verification::test_util::TestVerificationReporter; use satrs::request::MessageMetadata; use satrs::ComponentId; @@ -429,7 +429,7 @@ mod tests { .verif_reporter() .check_next_is_acceptance_success(id, accepted_token.request_id()); self.pus_packet_tx - .send(EcssTcAndToken::new(tc.to_vec().unwrap(), accepted_token)) + .send(EcssTcAndToken::new(TcInMemory::Vec(PacketAsVec::new(self.service.service_helper.id(), tc.to_vec().unwrap().into())), accepted_token)) .unwrap(); } } @@ -713,4 +713,4 @@ mod tests { tmtc_err::REQUEST_TIMEOUT.raw() as u64, ); } -} +} \ No newline at end of file