Skip to content

Commit

Permalink
Remove stop command from CEP
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Guggi committed Jan 13, 2024
1 parent 6aa4a91 commit 2c1f37b
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 94 deletions.
1 change: 0 additions & 1 deletion src/command/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ impl From<CommunicationError> 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"),
}
Expand Down
2 changes: 1 addition & 1 deletion src/command/store_archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
5 changes: 0 additions & 5 deletions src/communication/cep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crc::{Crc, CRC_32_MPEG_2};
pub enum CEPPacket {
Ack,
Nack,
Stop,
Eof,
Data(Vec<u8>),
}
Expand All @@ -15,7 +14,6 @@ pub enum CEPPacket {
pub enum CEPPacketHeader {
Ack = 0xd7,
Nack = 0x27,
Stop = 0xb4,
Eof = 0x59,
Data = 0x8b,
}
Expand Down Expand Up @@ -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,
};
Expand All @@ -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];
Expand Down Expand Up @@ -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<u8>, packet: CEPPacket) {
Expand Down
15 changes: 2 additions & 13 deletions src/communication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,11 @@ pub trait CommunicationHandle: Read + Write {
todo!()
}

fn receive_multi_packet(&mut self, stop_fn: impl Fn() -> bool) -> ComResult<Vec<u8>> {
fn receive_multi_packet(&mut self) -> ComResult<Vec<u8>> {
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)) => {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion tests/simulation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub fn simulate_return_result(
timestamp: u32,
) -> Result<Vec<u8>, 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)
}
Expand Down
7 changes: 0 additions & 7 deletions tests/software_tests/command_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
44 changes: 0 additions & 44 deletions tests/software_tests/return_result.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::io::Write;

use crate::software_tests::common;
use crate::software_tests::common::ComEvent::*;
use common::*;
Expand Down Expand Up @@ -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)];
Expand Down
22 changes: 0 additions & 22 deletions tests/software_tests/store_archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

0 comments on commit 2c1f37b

Please sign in to comment.