Skip to content

Commit

Permalink
well this is annoying work
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Dec 3, 2023
1 parent 834d56c commit da201a9
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
30 changes: 30 additions & 0 deletions src/ecss/hk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,33 @@ pub enum Subservice {
TcGenerateOneShotDiag = 28,
TcModifyDiagCollectionInterval = 32,
}

#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_try_from_u8() {
let hk_report_subservice_raw = 25;
let hk_report: Subservice = Subservice::try_from(hk_report_subservice_raw).unwrap();
assert_eq!(hk_report, Subservice::TmHkPacket);
}

#[test]
fn test_into_u8() {
let hk_report_raw: u8 = Subservice::TmHkPacket.into();
assert_eq!(hk_report_raw, 25);
}

#[test]
fn test_partial_eq() {
let hk_report_raw = Subservice::TmHkPacket;
assert_ne!(hk_report_raw, Subservice::TcGenerateOneShotHk);
assert_eq!(hk_report_raw, Subservice::TmHkPacket);
}
#[test]
fn test_copy_clone() {
let hk_report = Subservice::TmHkPacket;
let hk_report_copy = hk_report;
assert_eq!(hk_report, hk_report_copy);
}
}
35 changes: 32 additions & 3 deletions src/ecss/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub enum PusServiceId {
/// All PUS versions. Only PUS C is supported by this library.
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[non_exhaustive]
pub enum PusVersion {
EsaPus = 0,
PusA = 1,
Expand All @@ -95,8 +96,9 @@ impl TryFrom<u8> for PusVersion {
}

/// ECSS Packet Type Codes (PTC)s.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(u8)]
pub enum PacketTypeCodes {
Boolean = 1,
Enumerated = 2,
Expand All @@ -115,8 +117,9 @@ pub enum PacketTypeCodes {
pub type Ptc = PacketTypeCodes;

/// ECSS Packet Field Codes (PFC)s for the unsigned [Ptc].
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(u8)]
pub enum UnsignedPfc {
OneByte = 4,
TwelveBits = 8,
Expand All @@ -131,8 +134,9 @@ pub enum UnsignedPfc {
}

/// ECSS Packet Field Codes (PFC)s for the real (floating point) [Ptc].
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(u8)]
pub enum RealPfc {
/// 4 octets simple precision format (IEEE)
Float = 1,
Expand Down Expand Up @@ -376,9 +380,13 @@ pub trait WritablePusPacket {

#[cfg(test)]
mod tests {
use alloc::string::ToString;

use crate::ecss::{EcssEnumU16, EcssEnumU32, EcssEnumU8, UnsignedEnum};
use crate::ByteConversionError;

use super::*;

#[test]
fn test_enum_u8() {
let mut buf = [0, 0, 0];
Expand Down Expand Up @@ -448,4 +456,25 @@ mod tests {
}
}
}

#[test]
fn test_pus_error_display() {
let unsupport_version = PusError::VersionNotSupported(super::PusVersion::EsaPus);
let write_str = unsupport_version.to_string();
assert_eq!(write_str, "PUS version EsaPus not supported")
}

#[test]
fn test_service_id_from_u8() {
let verification_id_raw = 1;
let verification_id = PusServiceId::try_from(verification_id_raw).unwrap();
assert_eq!(verification_id, PusServiceId::Verification);
}

#[test]
fn test_ptc_from_u8() {
let ptc_raw = Ptc::AbsoluteTime as u8;
let ptc = Ptc::try_from(ptc_raw).unwrap();
assert_eq!(ptc, Ptc::AbsoluteTime);
}
}

0 comments on commit da201a9

Please sign in to comment.