improved module structure, new archive file

This commit is contained in:
Robin Müller 2022-06-14 17:39:13 +02:00
parent 7f369e1d5a
commit 933d946f68
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
4 changed files with 104 additions and 85 deletions

View File

@ -7,6 +7,7 @@
<option name="allFeatures" value="false" /> <option name="allFeatures" value="false" />
<option name="emulateTerminal" value="false" /> <option name="emulateTerminal" value="false" />
<option name="withSudo" value="false" /> <option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" /> <option name="backtrace" value="SHORT" />
<envs /> <envs />
<option name="isRedirectInput" value="false" /> <option name="isRedirectInput" value="false" />

82
src/archive.rs Normal file
View File

@ -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<u8>) -> 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();
}
*/

View File

@ -271,7 +271,6 @@ pub mod srd {
} }
sph_from_other!(SpHeader, sp::zc::SpHeader); sph_from_other!(SpHeader, sp::zc::SpHeader);
// sph_from_other!(SpHeader, sp::deku::SpHeader);
} }
pub mod zc { pub mod zc {
@ -336,86 +335,35 @@ pub mod zc {
} }
sph_from_other!(SpHeader, sp::srd::SpHeader); 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<u8>) -> 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)] #[cfg(test)]
mod tests { mod tests {
use crate::sp; use crate::sp;
use crate::sp::srd::SpHeader; 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}; 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] #[test]
fn test_deser_internally() { fn test_deser_internally() {
let sp_header = SpHeader::tc(0x42, 12).expect("Error creating SP header"); let sp_header = SpHeader::tc(0x42, 12).expect("Error creating SP header");
@ -453,18 +401,6 @@ mod tests {
assert_eq!(sp_header.version(), 0b000); 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] #[test]
fn test_deser_zerocopy() { fn test_deser_zerocopy() {
use zerocopy::AsBytes; use zerocopy::AsBytes;