diff --git a/.idea/runConfigurations/Test.xml b/.idea/runConfigurations/Test.xml
index 15edb2f..9f2b663 100644
--- a/.idea/runConfigurations/Test.xml
+++ b/.idea/runConfigurations/Test.xml
@@ -7,6 +7,7 @@
+
diff --git a/src/archive.rs b/src/archive.rs
new file mode 100644
index 0000000..a9bdce0
--- /dev/null
+++ b/src/archive.rs
@@ -0,0 +1,82 @@
+
+/*
+pub mod deku {
+ pub use ccsds_spacepacket::PrimaryHeader as SpHeader;
+ use crate::sp::{self, PacketId, PacketSequenceCtrl};
+ use crate::sp::{CcsdsPrimaryHeader, PacketType, SequenceFlags};
+
+ impl CcsdsPrimaryHeader for SpHeader {
+ fn from_composite_fields(packet_id: PacketId, psc: PacketSequenceCtrl, data_len: u16, version: Option) -> Self {
+ let mut version_to_set = 0b000;
+ if let Some(version) = version {
+ version_to_set = version;
+ }
+ let packet_type = match packet_id.ptype {
+ PacketType::Tm => ccsds_spacepacket::types::PacketType::Data,
+ PacketType::Tc => ccsds_spacepacket::types::PacketType::Command
+ };
+ let sec_header_flag = match packet_id.sec_header_flag {
+ true => ccsds_spacepacket::types::SecondaryHeaderFlag::Present,
+ false => ccsds_spacepacket::types::SecondaryHeaderFlag::NotPresent
+ };
+ let sequence_flags = match psc.seq_flags {
+ SequenceFlags::ContinuationSegment => ccsds_spacepacket::types::SeqFlag::Continuation,
+ SequenceFlags::FirstSegment => ccsds_spacepacket::types::SeqFlag::FirstSegment,
+ SequenceFlags::LastSegment => ccsds_spacepacket::types::SeqFlag::LastSegment,
+ SequenceFlags::Unsegmented => ccsds_spacepacket::types::SeqFlag::Unsegmented
+ };
+ SpHeader {
+ version: version_to_set,
+ packet_type,
+ sec_header_flag,
+ app_proc_id: packet_id.apid,
+ sequence_flags,
+ sequence_count: psc.ssc,
+ data_length: data_len
+ }
+ }
+
+ #[inline]
+ fn version(&self) -> u8 {
+ self.version
+ }
+
+ #[inline]
+ fn packet_id(&self) -> PacketId {
+ PacketId {
+ ptype: PacketType::try_from(self.packet_type as u8).unwrap(),
+ apid: self.app_proc_id,
+ sec_header_flag: self.sec_header_flag as u8 != 0
+ }
+ }
+
+ #[inline]
+ fn psc(&self) -> PacketSequenceCtrl {
+ PacketSequenceCtrl {
+ seq_flags: SequenceFlags::try_from(self.sequence_flags as u8).unwrap(),
+ ssc: self.sequence_count
+ }
+ }
+
+ #[inline]
+ fn data_len(&self) -> u16 {
+ self.data_length
+ }
+ }
+
+ sph_from_other!(SpHeader, sp::srd::SpHeader);
+ sph_from_other!(SpHeader, sp::zc::SpHeader);
+}
+*/
+
+/*
+#[test]
+fn test_deser_to_raw_packed_deku() {
+ let sp_header = SpHeader::tc(0x42, 12).expect("Error creating SP header");
+ // TODO: Wait with these tests until KubOS merged
+ // https://github.com/KubOS-Preservation-Group/ccsds-spacepacket/pull/14
+ let _deku_header =
+ deku::SpHeader::try_from(sp_header).expect("Error creating Deku Sp Header");
+ // deku_header.to_bytes().unwrap();
+}
+ */
diff --git a/src/core.rs b/src/core/mod.rs
similarity index 100%
rename from src/core.rs
rename to src/core/mod.rs
diff --git a/src/sp.rs b/src/sp/mod.rs
similarity index 79%
rename from src/sp.rs
rename to src/sp/mod.rs
index ccfaf77..8d4a8e8 100644
--- a/src/sp.rs
+++ b/src/sp/mod.rs
@@ -271,7 +271,6 @@ pub mod srd {
}
sph_from_other!(SpHeader, sp::zc::SpHeader);
- // sph_from_other!(SpHeader, sp::deku::SpHeader);
}
pub mod zc {
@@ -336,86 +335,35 @@ pub mod zc {
}
sph_from_other!(SpHeader, sp::srd::SpHeader);
- //sph_from_other!(SpHeader, sp::deku::SpHeader);
}
-/*
-pub mod deku {
- pub use ccsds_spacepacket::PrimaryHeader as SpHeader;
- use crate::sp::{self, PacketId, PacketSequenceCtrl};
- use crate::sp::{CcsdsPrimaryHeader, PacketType, SequenceFlags};
-
- impl CcsdsPrimaryHeader for SpHeader {
- fn from_composite_fields(packet_id: PacketId, psc: PacketSequenceCtrl, data_len: u16, version: Option) -> Self {
- let mut version_to_set = 0b000;
- if let Some(version) = version {
- version_to_set = version;
- }
- let packet_type = match packet_id.ptype {
- PacketType::Tm => ccsds_spacepacket::types::PacketType::Data,
- PacketType::Tc => ccsds_spacepacket::types::PacketType::Command
- };
- let sec_header_flag = match packet_id.sec_header_flag {
- true => ccsds_spacepacket::types::SecondaryHeaderFlag::Present,
- false => ccsds_spacepacket::types::SecondaryHeaderFlag::NotPresent
- };
- let sequence_flags = match psc.seq_flags {
- SequenceFlags::ContinuationSegment => ccsds_spacepacket::types::SeqFlag::Continuation,
- SequenceFlags::FirstSegment => ccsds_spacepacket::types::SeqFlag::FirstSegment,
- SequenceFlags::LastSegment => ccsds_spacepacket::types::SeqFlag::LastSegment,
- SequenceFlags::Unsegmented => ccsds_spacepacket::types::SeqFlag::Unsegmented
- };
- SpHeader {
- version: version_to_set,
- packet_type,
- sec_header_flag,
- app_proc_id: packet_id.apid,
- sequence_flags,
- sequence_count: psc.ssc,
- data_length: data_len
- }
- }
-
- #[inline]
- fn version(&self) -> u8 {
- self.version
- }
-
- #[inline]
- fn packet_id(&self) -> PacketId {
- PacketId {
- ptype: PacketType::try_from(self.packet_type as u8).unwrap(),
- apid: self.app_proc_id,
- sec_header_flag: self.sec_header_flag as u8 != 0
- }
- }
-
- #[inline]
- fn psc(&self) -> PacketSequenceCtrl {
- PacketSequenceCtrl {
- seq_flags: SequenceFlags::try_from(self.sequence_flags as u8).unwrap(),
- ssc: self.sequence_count
- }
- }
-
- #[inline]
- fn data_len(&self) -> u16 {
- self.data_length
- }
- }
-
- sph_from_other!(SpHeader, sp::srd::SpHeader);
- sph_from_other!(SpHeader, sp::zc::SpHeader);
-}
-*/
-
#[cfg(test)]
mod tests {
use crate::sp;
use crate::sp::srd::SpHeader;
- use crate::sp::{CcsdsPrimaryHeader, PacketType, SequenceFlags};
+ use crate::sp::{CcsdsPrimaryHeader, PacketId, PacketSequenceCtrl, PacketType, SequenceFlags};
use postcard::{from_bytes, to_stdvec};
+ #[test]
+ fn test_helpers() {
+ let packet_id = PacketId {
+ ptype: PacketType::Tm,
+ sec_header_flag: false,
+ apid: 0x42,
+ };
+ assert_eq!(packet_id.raw(), 0x42);
+ let packet_id_from_raw = PacketId::from(packet_id.raw());
+ assert_eq!(packet_id_from_raw, packet_id);
+
+ let psc = PacketSequenceCtrl {
+ seq_flags: SequenceFlags::ContinuationSegment,
+ ssc: 77,
+ };
+ assert_eq!(psc.raw(), 77);
+ let psc_from_raw = PacketSequenceCtrl::from(psc.raw());
+ assert_eq!(psc_from_raw, psc);
+ }
+
#[test]
fn test_deser_internally() {
let sp_header = SpHeader::tc(0x42, 12).expect("Error creating SP header");
@@ -453,18 +401,6 @@ mod tests {
assert_eq!(sp_header.version(), 0b000);
}
- /*
- #[test]
- fn test_deser_to_raw_packed_deku() {
- let sp_header = SpHeader::tc(0x42, 12).expect("Error creating SP header");
- // TODO: Wait with these tests until KubOS merged
- // https://github.com/KubOS-Preservation-Group/ccsds-spacepacket/pull/14
- let _deku_header =
- deku::SpHeader::try_from(sp_header).expect("Error creating Deku Sp Header");
- // deku_header.to_bytes().unwrap();
- }
- */
-
#[test]
fn test_deser_zerocopy() {
use zerocopy::AsBytes;