From 2c1f37b801f59c54eb273b539abb8b28cfd1abd8 Mon Sep 17 00:00:00 2001 From: Florian Guggi Date: Sun, 7 Jan 2024 20:03:57 +0100 Subject: [PATCH] Remove stop command from CEP --- src/command/error.rs | 1 - src/command/store_archive.rs | 2 +- src/communication/cep.rs | 5 --- src/communication/mod.rs | 15 +------ tests/simulation/mod.rs | 2 +- tests/software_tests/command_integration.rs | 7 ---- tests/software_tests/return_result.rs | 44 --------------------- tests/software_tests/store_archive.rs | 22 ----------- 8 files changed, 4 insertions(+), 94 deletions(-) diff --git a/src/command/error.rs b/src/command/error.rs index 74b2085..b6bde51 100644 --- a/src/command/error.rs +++ b/src/command/error.rs @@ -27,7 +27,6 @@ impl From for CommandError { CommunicationError::PacketInvalidError => CommandError::External(Box::new(e)), CommunicationError::CepParsing(_) => CommandError::ProtocolViolation(Box::new(e)), CommunicationError::Io(_) => CommandError::NonRecoverable(Box::new(e)), - CommunicationError::StopCondition => CommandError::External(Box::new(e)), CommunicationError::NotAcknowledged => CommandError::ProtocolViolation(Box::new(e)), CommunicationError::TimedOut => todo!("Timeout not yet specified"), } diff --git a/src/command/store_archive.rs b/src/command/store_archive.rs index fac5ea1..10b9a54 100644 --- a/src/command/store_archive.rs +++ b/src/command/store_archive.rs @@ -17,7 +17,7 @@ pub fn store_archive( let id = u16::from_le_bytes([data[1], data[2]]).to_string(); log::info!("Storing Archive {}", id); - let bytes = com.receive_multi_packet(|| false)?; // !! TODO !! + let bytes = com.receive_multi_packet()?; unpack_archive(id, bytes)?; com.send_packet(&CEPPacket::Ack)?; diff --git a/src/communication/cep.rs b/src/communication/cep.rs index 3e0c69c..46b5749 100644 --- a/src/communication/cep.rs +++ b/src/communication/cep.rs @@ -6,7 +6,6 @@ use crc::{Crc, CRC_32_MPEG_2}; pub enum CEPPacket { Ack, Nack, - Stop, Eof, Data(Vec), } @@ -15,7 +14,6 @@ pub enum CEPPacket { pub enum CEPPacketHeader { Ack = 0xd7, Nack = 0x27, - Stop = 0xb4, Eof = 0x59, Data = 0x8b, } @@ -59,7 +57,6 @@ impl CEPPacket { let header = match self { CEPPacket::Ack => CEPPacketHeader::Ack, CEPPacket::Nack => CEPPacketHeader::Nack, - CEPPacket::Stop => CEPPacketHeader::Stop, CEPPacket::Eof => CEPPacketHeader::Eof, CEPPacket::Data(_) => CEPPacketHeader::Data, }; @@ -75,7 +72,6 @@ impl CEPPacket { let packet = match header { CEPPacketHeader::Ack => CEPPacket::Ack, CEPPacketHeader::Nack => CEPPacket::Nack, - CEPPacketHeader::Stop => CEPPacket::Stop, CEPPacketHeader::Eof => CEPPacket::Eof, CEPPacketHeader::Data => { let mut length_buffer = [0; 2]; @@ -152,7 +148,6 @@ mod tests { #[test_case(vec![0xD7], CEPPacket::Ack)] #[test_case(vec![0x27], CEPPacket::Nack)] #[test_case(vec![0x59], CEPPacket::Eof)] - #[test_case(vec![0xB4], CEPPacket::Stop)] #[test_case(vec![0x8B, 0, 0, 0xff, 0xff, 0xff, 0xff], CEPPacket::Data(vec![]); "empty Data packet")] #[test_case(vec![0x8B, 4, 0, 0x0a, 0x0b, 0x05, 0x73, 0x52, 0x27, 0x92, 0xf4], CEPPacket::Data(vec![0x0a, 0x0b, 0x05, 0x73]); "filled data packet")] fn packet_is_parsed_and_serialized_correctly(vec: Vec, packet: CEPPacket) { diff --git a/src/communication/mod.rs b/src/communication/mod.rs index f85c060..aa2456a 100644 --- a/src/communication/mod.rs +++ b/src/communication/mod.rs @@ -76,15 +76,11 @@ pub trait CommunicationHandle: Read + Write { todo!() } - fn receive_multi_packet(&mut self, stop_fn: impl Fn() -> bool) -> ComResult> { + fn receive_multi_packet(&mut self) -> ComResult> { let mut buffer = Vec::new(); loop { let pack = self.receive_packet(); - if stop_fn() { - self.send_packet(&CEPPacket::Stop)?; - return Err(CommunicationError::StopCondition); - } match pack { Ok(CEPPacket::Data(b)) => { @@ -93,9 +89,6 @@ pub trait CommunicationHandle: Read + Write { Ok(CEPPacket::Eof) => { break; } - Ok(CEPPacket::Stop) => { - return Err(CommunicationError::StopCondition); - } Err(e @ CommunicationError::Io(_)) => { return Err(e); } @@ -141,8 +134,6 @@ pub enum CommunicationError { CepParsing(CEPParseError), /// Signals that the underlying sending or receiving failed. Not recoverable on its own. Io(std::io::Error), - /// Signals that a multi packet receive or send was interrupted by a Stop condition - StopCondition, /// Signals that a receive timed out TimedOut, /// Nack was received when Ack was expected @@ -211,7 +202,6 @@ mod tests { #[test_case(CEPPacket::Ack)] #[test_case(CEPPacket::Nack)] - #[test_case(CEPPacket::Stop)] #[test_case(CEPPacket::Eof)] #[test_case(CEPPacket::Data(vec![1, 2, 3]))] fn packet_is_sent_correctly(packet: CEPPacket) { @@ -225,7 +215,6 @@ mod tests { #[test_case(CEPPacket::Ack)] #[test_case(CEPPacket::Nack)] - #[test_case(CEPPacket::Stop)] #[test_case(CEPPacket::Eof)] #[test_case(CEPPacket::Data(vec![1, 2, 3]))] fn packet_is_received_correctly(packet: CEPPacket) { @@ -298,7 +287,7 @@ mod tests { } com.data_to_read.append(&mut CEPPacket::Eof.serialize()); - assert_eq!(com.receive_multi_packet(|| false).unwrap(), data); + assert_eq!(com.receive_multi_packet().unwrap(), data); assert!(com.data_to_read.is_empty()); assert_eq!(com.written_data, CEPPacket::Ack.serialize().repeat(chunks.len() + 1)) } diff --git a/tests/simulation/mod.rs b/tests/simulation/mod.rs index 6d457bc..003cd6b 100644 --- a/tests/simulation/mod.rs +++ b/tests/simulation/mod.rs @@ -139,7 +139,7 @@ pub fn simulate_return_result( timestamp: u32, ) -> Result, CommunicationError> { com.send_packet(&CEPPacket::Data(return_result(program_id, timestamp)))?; - let data = com.receive_multi_packet(|| false)?; + let data = com.receive_multi_packet()?; Ok(data) } diff --git a/tests/software_tests/command_integration.rs b/tests/software_tests/command_integration.rs index 9612977..d723c25 100644 --- a/tests/software_tests/command_integration.rs +++ b/tests/software_tests/command_integration.rs @@ -48,10 +48,3 @@ fn eof_on_start_panic() { let (mut com, mut exec) = common::prepare_handles(vec![COBC(Eof)], "99"); command::handle_command(&mut com, &mut exec); } - -#[test] -#[should_panic] -fn stop_on_start_panic() { - let (mut com, mut exec) = common::prepare_handles(vec![COBC(Stop)], "99"); - command::handle_command(&mut com, &mut exec); -} diff --git a/tests/software_tests/return_result.rs b/tests/software_tests/return_result.rs index d783e45..19d42a9 100644 --- a/tests/software_tests/return_result.rs +++ b/tests/software_tests/return_result.rs @@ -1,5 +1,3 @@ -use std::io::Write; - use crate::software_tests::common; use crate::software_tests::common::ComEvent::*; use common::*; @@ -85,48 +83,6 @@ fn truncate_result() -> TestResult { Ok(()) } -#[test] -fn stopped_return() -> TestResult { - let packets = vec![ - COBC(Data(execute_program(9, 5, 3))), - EDU(Ack), - EDU(Ack), - SLEEP(std::time::Duration::from_millis(3000)), - COBC(Data(get_status())), - EDU(Ack), - EDU(Data(vec![1, 9, 0, 5, 0, 0, 0, 0])), - COBC(Ack), - COBC(Data(get_status())), - EDU(Ack), - EDU(Data(vec![2, 9, 0, 5, 0, 0, 0])), - COBC(Ack), - COBC(Data(return_result(9, 5))), - EDU(Ack), - ANY, - COBC(Ack), - ANY, - COBC(Stop), - COBC(Data(get_status())), - EDU(Ack), - EDU(Data(vec![2, 9, 0, 5, 0, 0, 0])), - COBC(Ack), - ]; - common::prepare_program("9"); - let (mut com, mut exec) = common::prepare_handles(packets, "9"); - - command::handle_command(&mut com, &mut exec); - command::handle_command(&mut com, &mut exec); - command::handle_command(&mut com, &mut exec); - command::handle_command(&mut com, &mut exec); - command::handle_command(&mut com, &mut exec); - assert!(com.is_complete()); - - assert!(std::fs::File::open("./data/9_5.tar").is_ok()); - - common::cleanup("9"); - Ok(()) -} - #[test] fn no_result_ready() -> TestResult { let packets = vec![COBC(Data(return_result(99, 0))), EDU(Ack), EDU(Nack)]; diff --git a/tests/software_tests/store_archive.rs b/tests/software_tests/store_archive.rs index a94b9b7..e1ab83c 100644 --- a/tests/software_tests/store_archive.rs +++ b/tests/software_tests/store_archive.rs @@ -41,25 +41,3 @@ fn store_archive() -> TestResult { common::cleanup("0"); Ok(()) } - -#[test] -fn stopped_store() -> TestResult { - let packets = vec![ - COBC(Data(vec![0x01, 0x04, 0x00])), // Store Archive with ID 0 - EDU(Ack), - COBC(Data(std::fs::read("./tests/student_program.zip")?)), - EDU(Ack), - COBC(Data(vec![0, 1, 2, 3])), - EDU(Ack), - COBC(Stop), - ]; - - let (mut com, mut exec) = common::prepare_handles(packets, "4"); - - command::handle_command(&mut com, &mut exec); - - assert!(!std::path::Path::new("./archives/4").exists()); - - common::cleanup("4"); - Ok(()) -}