Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Dec 3, 2023
1 parent a253550 commit 5206332
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Removed the `PusError::RawDataTooShort` variant which is already covered by
`PusError::ByteConversionError` variant.
- Ranamed `TlvLvError::ByteConversionError` to `TlvLvError::ByteConversion`.
- Renamed `PusError::IncorrectCrc` to `PusError::ChecksumFailure`.

## Removed

- Removed `PusError::NoRawData` and renamed `PusError::IncorrectCrc` to
`PusError::ChecksumFailure`.
- `PusError::NoRawData` variant.
- `cfdp::LenInBytes` which was not used.

# [v0.7.0-beta.2] 2023-09-26

Expand Down
18 changes: 7 additions & 11 deletions src/cfdp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ pub enum FaultHandlerCode {
AbandonTransaction = 0b0100,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(u8)]
pub enum LenInBytes {
ZeroOrNone = 0,
OneByte = 1,
TwoBytes = 2,
ThreeBytes = 4,
FourBytes = 8,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(u8)]
Expand Down Expand Up @@ -264,4 +253,11 @@ mod tests {
let checksum = ChecksumType::default();
assert_eq!(checksum, ChecksumType::NullChecksum);
}

#[test]
fn test_fault_handler_code_from_u8() {
let fault_handler_code_raw = FaultHandlerCode::NoticeOfSuspension as u8;
let fault_handler_code = FaultHandlerCode::try_from(fault_handler_code_raw).unwrap();
assert_eq!(fault_handler_code, FaultHandlerCode::NoticeOfSuspension);
}
}
35 changes: 33 additions & 2 deletions src/cfdp/tlv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ impl EntityIdTlv {
Ok(())
}

pub fn entity_id(&self) -> &UnsignedByteField {
&self.entity_id
}

pub fn len_value(&self) -> usize {
self.entity_id.size()
}
Expand All @@ -220,7 +224,7 @@ impl EntityIdTlv {
Self::len_check(buf)?;
buf[0] = TlvType::EntityId as u8;
buf[1] = self.entity_id.size() as u8;
self.entity_id.write_to_be_bytes(&mut buf[2..])
Ok(2 + self.entity_id.write_to_be_bytes(&mut buf[2..])?)
}

pub fn from_bytes(buf: &[u8]) -> Result<Self, TlvLvError> {
Expand Down Expand Up @@ -481,10 +485,13 @@ impl<'first_name, 'second_name> FilestoreRequestTlv<'first_name, 'second_name> {

#[cfg(test)]
mod tests {
use std::println;

use super::*;
use crate::cfdp::lv::Lv;
use crate::cfdp::tlv::{FilestoreActionCode, FilestoreRequestTlv, Tlv, TlvType, TlvTypeField};
use crate::cfdp::TlvLvError;
use crate::util::{UbfU8, UnsignedEnum};
use crate::util::{UbfU16, UbfU8, UnsignedEnum};

const TLV_TEST_STR_0: &str = "hello.txt";
const TLV_TEST_STR_1: &str = "hello2.txt";
Expand Down Expand Up @@ -544,6 +551,30 @@ mod tests {
assert_eq!(tlv_from_raw.value()[0], 5);
}

#[test]
fn test_entity_id_tlv() {
let entity_id = UbfU16::new(0x0102);
let entity_id_tlv = EntityIdTlv::new(entity_id.into());
let mut buf: [u8; 16] = [0; 16];
let written_len = entity_id_tlv.write_to_be_bytes(&mut buf).unwrap();
assert_eq!(written_len, entity_id_tlv.len_full());
assert_eq!(buf[0], TlvType::EntityId as u8);
assert_eq!(buf[1], 2);
assert_eq!(u16::from_be_bytes(buf[2..4].try_into().unwrap()), 0x0102);
}

#[test]
fn test_entity_id_from_raw() {
let entity_id = UbfU16::new(0x0102);
let entity_id_tlv = EntityIdTlv::new(entity_id.into());
let mut buf: [u8; 16] = [0; 16];
let _ = entity_id_tlv.write_to_be_bytes(&mut buf).unwrap();
let entity_tlv_from_raw =
EntityIdTlv::from_bytes(&buf).expect("creating entity ID TLV failed");
assert_eq!(entity_tlv_from_raw, entity_id_tlv);
assert_eq!(entity_tlv_from_raw.entity_id(), &entity_id.into());
}

#[test]
fn test_empty() {
let tlv_empty = Tlv::new_empty(TlvType::MsgToUser);
Expand Down

0 comments on commit 5206332

Please sign in to comment.