Compare commits
42 Commits
b9cd08cefe
...
v0.4.0
Author | SHA1 | Date | |
---|---|---|---|
d972dd5223 | |||
481de83fdb | |||
09b305f529 | |||
78c5787e07 | |||
e9e33b0335 | |||
455be77f4a | |||
c748657499 | |||
2e90cba5bd | |||
f290d2a54e | |||
da695e4705 | |||
5c222735d4 | |||
1432c298b3 | |||
1b45082ace | |||
4c20158dcc | |||
c879181093 | |||
6c88e94742 | |||
3fb2fbd20c | |||
ec8a2e1d24 | |||
192e2f2c76 | |||
5df221759f | |||
f137bd2549 | |||
630bffec51 | |||
a14ae37cac | |||
2758699601 | |||
b07cec28ea | |||
51963d0f72 | |||
83e2cad753 | |||
472bfa9964 | |||
14fa1bad92 | |||
3828a98c76 | |||
f641248ac2 | |||
884de647ad | |||
0d8074c6b9 | |||
6798e3a6f5 | |||
7e763fe055 | |||
4410ee7eec | |||
2895d7645a | |||
692d12e5a5 | |||
9e57ce3872 | |||
fd13694904 | |||
f964342556 | |||
5a878ef6a3 |
12
CHANGELOG.md
12
CHANGELOG.md
@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
# [unreleased]
|
||||
|
||||
# [v0.4.0] 10.01.2023
|
||||
|
||||
## Fixed
|
||||
|
||||
- Remove `Default` derive on CDS time provider. This can lead to uninitialized preamble fields.
|
||||
|
||||
## Changed
|
||||
|
||||
- `serde` support is now optional and behind the `serde` feature.
|
||||
@ -19,12 +25,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
The function now returns the remaining slice as well.
|
||||
- All CDS specific functionality was moved into the `cds` submodule of the `time`
|
||||
module. `CdsShortTimeProvider` was renamed to `TimeProvider`.
|
||||
PR: https://egit.irs.uni-stuttgart.de/rust/spacepackets/pulls/3
|
||||
|
||||
## Added
|
||||
|
||||
- `SpHeader` getter function `sp_header` added for `PusTc`
|
||||
PR: https://egit.irs.uni-stuttgart.de/rust/spacepackets/pulls/6
|
||||
- Added PFC enumerations: `ecss::UnsignedPfc` and `ecss::RealPfc`.
|
||||
PR: https://egit.irs.uni-stuttgart.de/rust/spacepackets/pulls/5
|
||||
- Added `std::error::Error` implementation for all error enumerations if the `std` feature
|
||||
is enabled.
|
||||
- CUC timestamp implementation as specified in CCSDS 301.0-B-4 section 3.2.
|
||||
PR: https://egit.irs.uni-stuttgart.de/rust/spacepackets/pulls/4/files
|
||||
- ACII timestamps as specified in CCSDS 301.0-B-4 section 3.5.
|
||||
- Added MSRV in `Cargo.toml` with the `rust-version` field set to Rust 1.60.
|
||||
- `serde` `Serialize` and `Deserialize` added to all types.
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "spacepackets"
|
||||
version = "0.3.1"
|
||||
version = "0.4.0"
|
||||
edition = "2021"
|
||||
rust-version = "1.60"
|
||||
authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]
|
||||
@ -14,11 +14,11 @@ categories = ["aerospace", "aerospace::space-protocols", "no-std", "hardware-sup
|
||||
|
||||
[dependencies]
|
||||
zerocopy = "0.6"
|
||||
crc = "3.0"
|
||||
crc = "3"
|
||||
delegate = "0.8"
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0"
|
||||
version = "1"
|
||||
optional = true
|
||||
default-features = false
|
||||
features = ["derive"]
|
||||
|
@ -15,7 +15,9 @@ Currently, this includes the following components:
|
||||
[CCSDS Blue Book 133.0-B-2](https://public.ccsds.org/Pubs/133x0b2e1.pdf)
|
||||
- PUS Telecommand and PUS Telemetry implementation according to the
|
||||
[ECSS-E-ST-70-41C standard](https://ecss.nl/standard/ecss-e-st-70-41c-space-engineering-telemetry-and-telecommand-packet-utilization-15-april-2016/).
|
||||
- CDS Short Time Code implementation according to
|
||||
- CUC (CCSDS Unsegmented Time Code) implementation according to
|
||||
[CCSDS 301.0-B-4 3.2](https://public.ccsds.org/Pubs/301x0b4e1.pdf)
|
||||
- CDS (CCSDS Day Segmented Time Code) implementation according to
|
||||
[CCSDS 301.0-B-4 3.3](https://public.ccsds.org/Pubs/301x0b4e1.pdf)
|
||||
- Some helper types to support ASCII timecodes ad specified in
|
||||
[CCSDS 301.0-B-4 3.5](https://public.ccsds.org/Pubs/301x0b4e1.pdf)
|
||||
|
20
src/ecss.rs
20
src/ecss.rs
@ -15,6 +15,21 @@ pub type CrcType = u16;
|
||||
pub const CRC_CCITT_FALSE: Crc<u16> = Crc::<u16>::new(&CRC_16_IBM_3740);
|
||||
pub const CCSDS_HEADER_LEN: usize = size_of::<crate::zc::SpHeader>();
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub enum PusServiceId {
|
||||
/// Service 1
|
||||
Verification = 1,
|
||||
/// Service 3
|
||||
Housekeeping = 3,
|
||||
/// Service 5
|
||||
Event = 5,
|
||||
/// Service 8
|
||||
Action = 8,
|
||||
/// Service 17
|
||||
Test = 17,
|
||||
}
|
||||
|
||||
/// All PUS versions. Only PUS C is supported by this library.
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
@ -38,6 +53,7 @@ impl TryFrom<u8> for PusVersion {
|
||||
}
|
||||
}
|
||||
|
||||
/// ECSS Packet Type Codes (PTC)s.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub enum PacketTypeCodes {
|
||||
@ -57,6 +73,7 @@ pub enum PacketTypeCodes {
|
||||
|
||||
pub type Ptc = PacketTypeCodes;
|
||||
|
||||
/// ECSS Packet Field Codes (PFC)s for the unsigned [Ptc].
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub enum UnsignedPfc {
|
||||
@ -72,6 +89,7 @@ pub enum UnsignedPfc {
|
||||
ThreeBits = 19,
|
||||
}
|
||||
|
||||
/// ECSS Packet Field Codes (PFC)s for the real (floating point) [Ptc].
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub enum RealPfc {
|
||||
@ -142,6 +160,8 @@ impl From<ByteConversionError> for PusError {
|
||||
}
|
||||
}
|
||||
|
||||
/// Generic trait to describe common attributes for both PUS Telecommands (TC) and PUS Telemetry
|
||||
/// (TM) packets. All PUS packets are also a special type of [CcsdsPacket]s.
|
||||
pub trait PusPacket: CcsdsPacket {
|
||||
const PUS_VERSION: PusVersion = PusVersion::PusC;
|
||||
|
||||
|
13
src/lib.rs
13
src/lib.rs
@ -9,9 +9,11 @@
|
||||
//! [CCSDS Blue Book 133.0-B-2](https://public.ccsds.org/Pubs/133x0b2e1.pdf)
|
||||
//! - PUS Telecommand and PUS Telemetry implementation according to the
|
||||
//! [ECSS-E-ST-70-41C standard](https://ecss.nl/standard/ecss-e-st-70-41c-space-engineering-telemetry-and-telecommand-packet-utilization-15-april-2016/).
|
||||
//! - CDS Short Time Code implementation according to
|
||||
//! [CCSDS CCSDS 301.0-B-4](https://public.ccsds.org/Pubs/301x0b4e1.pdf)
|
||||
//! - Some helper types and functions to support ASCII timecodes ad specified in
|
||||
//! - CUC (CCSDS Unsegmented Time Code) implementation according to
|
||||
//! [CCSDS 301.0-B-4 3.2](https://public.ccsds.org/Pubs/301x0b4e1.pdf)
|
||||
//! - CDS (CCSDS Day Segmented Time Code) implementation according to
|
||||
//! [CCSDS 301.0-B-4 3.3](https://public.ccsds.org/Pubs/301x0b4e1.pdf)
|
||||
//! - Some helper types to support ASCII timecodes ad specified in
|
||||
//! [CCSDS 301.0-B-4 3.5](https://public.ccsds.org/Pubs/301x0b4e1.pdf)
|
||||
//!
|
||||
//! ## Features
|
||||
@ -127,6 +129,7 @@ impl Display for ByteConversionError {
|
||||
#[cfg(feature = "std")]
|
||||
impl Error for ByteConversionError {}
|
||||
|
||||
/// CCSDS packet type enumeration.
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub enum PacketType {
|
||||
@ -175,6 +178,8 @@ impl TryFrom<u8> for SequenceFlags {
|
||||
}
|
||||
}
|
||||
|
||||
/// Abstraction for the CCSDS Packet ID, which forms the last thirteen bits
|
||||
/// of the first two bytes in the CCSDS primary header.
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct PacketId {
|
||||
@ -258,6 +263,8 @@ impl From<u16> for PacketId {
|
||||
}
|
||||
}
|
||||
|
||||
/// Abstraction for the CCSDS Packet Sequence Control (PSC) field which is the
|
||||
/// third and the fourth byte in the CCSDS primary header.
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct PacketSequenceCtrl {
|
||||
|
20
src/tc.rs
20
src/tc.rs
@ -215,19 +215,19 @@ impl PusTcSecondaryHeader {
|
||||
/// There is no spare bytes support yet.
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct PusTc<'slice> {
|
||||
pub struct PusTc<'app_data> {
|
||||
sp_header: SpHeader,
|
||||
pub sec_header: PusTcSecondaryHeader,
|
||||
/// If this is set to false, a manual call to [PusTc::calc_own_crc16] or
|
||||
/// [PusTc::update_packet_fields] is necessary for the serialized or cached CRC16 to be valid.
|
||||
pub calc_crc_on_serialization: bool,
|
||||
#[cfg_attr(feature = "serde", serde(skip))]
|
||||
raw_data: Option<&'slice [u8]>,
|
||||
app_data: Option<&'slice [u8]>,
|
||||
raw_data: Option<&'app_data [u8]>,
|
||||
app_data: Option<&'app_data [u8]>,
|
||||
crc16: Option<u16>,
|
||||
}
|
||||
|
||||
impl<'slice> PusTc<'slice> {
|
||||
impl<'app_data> PusTc<'app_data> {
|
||||
/// Generates a new struct instance.
|
||||
///
|
||||
/// # Arguments
|
||||
@ -243,7 +243,7 @@ impl<'slice> PusTc<'slice> {
|
||||
pub fn new(
|
||||
sp_header: &mut SpHeader,
|
||||
sec_header: PusTcSecondaryHeader,
|
||||
app_data: Option<&'slice [u8]>,
|
||||
app_data: Option<&'app_data [u8]>,
|
||||
set_ccsds_len: bool,
|
||||
) -> Self {
|
||||
sp_header.set_packet_type(PacketType::Tc);
|
||||
@ -268,7 +268,7 @@ impl<'slice> PusTc<'slice> {
|
||||
sph: &mut SpHeader,
|
||||
service: u8,
|
||||
subservice: u8,
|
||||
app_data: Option<&'slice [u8]>,
|
||||
app_data: Option<&'app_data [u8]>,
|
||||
set_ccsds_len: bool,
|
||||
) -> Self {
|
||||
Self::new(
|
||||
@ -279,6 +279,10 @@ impl<'slice> PusTc<'slice> {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn sp_header(&self) -> &SpHeader {
|
||||
&self.sp_header
|
||||
}
|
||||
|
||||
pub fn len_packed(&self) -> usize {
|
||||
let mut length = PUS_TC_MIN_LEN_WITHOUT_APP_DATA;
|
||||
if let Some(app_data) = self.app_data {
|
||||
@ -401,7 +405,7 @@ impl<'slice> PusTc<'slice> {
|
||||
|
||||
/// Create a [PusTc] instance from a raw slice. On success, it returns a tuple containing
|
||||
/// the instance and the found byte length of the packet.
|
||||
pub fn from_bytes(slice: &'slice [u8]) -> Result<(Self, usize), PusError> {
|
||||
pub fn from_bytes(slice: &'app_data [u8]) -> Result<(Self, usize), PusError> {
|
||||
let raw_data_len = slice.len();
|
||||
if raw_data_len < PUS_TC_MIN_LEN_WITHOUT_APP_DATA {
|
||||
return Err(PusError::RawDataTooShort(raw_data_len));
|
||||
@ -431,7 +435,7 @@ impl<'slice> PusTc<'slice> {
|
||||
Ok((pus_tc, total_len))
|
||||
}
|
||||
|
||||
pub fn raw(&self) -> Option<&'slice [u8]> {
|
||||
pub fn raw(&self) -> Option<&'app_data [u8]> {
|
||||
self.raw_data
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,10 @@
|
||||
//! See [chrono::DateTime::format] for a usage example of the generated
|
||||
//! [chrono::format::DelayedFormat] structs.
|
||||
#[cfg(feature = "alloc")]
|
||||
use chrono::format::{DelayedFormat, StrftimeItems};
|
||||
use chrono::{DateTime, Utc};
|
||||
use chrono::{
|
||||
format::{DelayedFormat, StrftimeItems},
|
||||
DateTime, Utc,
|
||||
};
|
||||
|
||||
/// Tuple of format string and formatted size for time code A.
|
||||
///
|
||||
|
@ -6,7 +6,8 @@ use super::*;
|
||||
use crate::private::Sealed;
|
||||
use core::fmt::Debug;
|
||||
|
||||
const CDS_SHORT_P_FIELD: u8 = (CcsdsTimeCodes::Cds as u8) << 4;
|
||||
/// Base value for the preamble field for a time field parser to determine the time field type.
|
||||
pub const P_FIELD_BASE: u8 = (CcsdsTimeCodes::Cds as u8) << 4;
|
||||
pub const MIN_CDS_FIELD_LEN: usize = 7;
|
||||
|
||||
/// Generic trait implemented by token structs to specify the length of day field at type
|
||||
@ -124,7 +125,7 @@ pub fn precision_from_pfield(pfield: u8) -> SubmillisPrecision {
|
||||
/// assert_eq!(stamp_deserialized.len_as_bytes(), 7);
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct TimeProvider<DaysLen: ProvidesDaysLength = DaysLen16Bits> {
|
||||
pfield: u8,
|
||||
@ -391,7 +392,7 @@ impl<ProvidesDaysLen: ProvidesDaysLength> TimeProvider<ProvidesDaysLen> {
|
||||
day_seg_len: LengthOfDaySegment,
|
||||
submillis_prec: Option<SubmillisPrecision>,
|
||||
) -> u8 {
|
||||
let mut pfield = CDS_SHORT_P_FIELD | ((day_seg_len as u8) << 2);
|
||||
let mut pfield = P_FIELD_BASE | ((day_seg_len as u8) << 2);
|
||||
if let Some(submillis_prec) = submillis_prec {
|
||||
match submillis_prec {
|
||||
SubmillisPrecision::Microseconds(_) => pfield |= 0b01,
|
||||
|
@ -6,6 +6,9 @@ use super::*;
|
||||
use core::fmt::Debug;
|
||||
|
||||
const MIN_CUC_LEN: usize = 2;
|
||||
|
||||
/// Base value for the preamble field for a time field parser to determine the time field type.
|
||||
pub const P_FIELD_BASE: u8 = (CcsdsTimeCodes::CucCcsdsEpoch as u8) << 4;
|
||||
/// Maximum length if the preamble field is not extended.
|
||||
pub const MAX_CUC_LEN_SMALL_PREAMBLE: usize = 8;
|
||||
|
||||
@ -64,10 +67,20 @@ pub fn fractional_part_from_subsec_ns(
|
||||
if ns > sec_as_ns {
|
||||
panic!("passed nanosecond value larger than 1 second");
|
||||
}
|
||||
let resolution = fractional_res_to_div(res) as u64;
|
||||
// Use integer division because this can reduce code size of really small systems.
|
||||
// First determine the nanoseconds for the smallest segment given the resolution.
|
||||
// Then divide by that to find out the fractional part. An integer division floors
|
||||
// which is what we want here.
|
||||
let fractional_part = ns / (sec_as_ns / fractional_res_to_div(res) as u64);
|
||||
// Then divide by that to find out the fractional part. For the calculation of the smallest
|
||||
// fraction, we perform a ceiling division. This is because if we would use the default
|
||||
// flooring division, we would divide by a smaller value, thereby allowing the calculation to
|
||||
// invalid fractional parts which are too large. For the division of the nanoseconds by the
|
||||
// smallest fraction, a flooring division is correct.
|
||||
// The multiplication with 100000 is necessary to avoid precision loss during integer division.
|
||||
// TODO: Floating point division might actually be faster option, but requires additional
|
||||
// code on small embedded systems..
|
||||
let fractional_part = ns * 100000 / ((sec_as_ns * 100000 + resolution) / resolution);
|
||||
// Floating point division.
|
||||
//let fractional_part = (ns as f64 / ((sec_as_ns as f64) / resolution as f64)).floor() as u32;
|
||||
Some(FractionalPart(res, fractional_part as u32))
|
||||
}
|
||||
|
||||
@ -300,7 +313,7 @@ impl TimeProviderCcsdsEpoch {
|
||||
}
|
||||
|
||||
fn build_p_field(counter_width: u8, fractions_width: Option<FractionalResolution>) -> u8 {
|
||||
let mut pfield = (CcsdsTimeCodes::CucCcsdsEpoch as u8) << 4;
|
||||
let mut pfield = P_FIELD_BASE;
|
||||
if !(1..=4).contains(&counter_width) {
|
||||
// Okay to panic here, this function is private and all input values should
|
||||
// have been sanitized
|
||||
@ -867,29 +880,39 @@ mod tests {
|
||||
#[test]
|
||||
fn fractional_part_formula() {
|
||||
let fractional_part =
|
||||
7843137 / (10_u64.pow(9) / fractional_res_to_div(FractionalResolution::FourMs) as u64);
|
||||
assert_eq!(fractional_part, 2);
|
||||
fractional_part_from_subsec_ns(FractionalResolution::FourMs, 7843138).unwrap();
|
||||
assert_eq!(fractional_part.1, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fractional_part_formula_2() {
|
||||
let fractional_part =
|
||||
12000000 / (10_u64.pow(9) / fractional_res_to_div(FractionalResolution::FourMs) as u64);
|
||||
assert_eq!(fractional_part, 3);
|
||||
fractional_part_from_subsec_ns(FractionalResolution::FourMs, 12000000).unwrap();
|
||||
assert_eq!(fractional_part.1, 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fractional_part_formula_3() {
|
||||
let one_fraction_with_width_two_in_ns = 10_u64.pow(9) / (2_u32.pow(8 * 2) - 1) as u64;
|
||||
assert_eq!(one_fraction_with_width_two_in_ns, 15259);
|
||||
let hundred_fractions_and_some = 100 * one_fraction_with_width_two_in_ns + 7000;
|
||||
let fractional_part = hundred_fractions_and_some
|
||||
/ (10_u64.pow(9) / fractional_res_to_div(FractionalResolution::FifteenUs) as u64);
|
||||
assert_eq!(fractional_part, 100);
|
||||
let hundred_and_one_fractions = 101 * one_fraction_with_width_two_in_ns;
|
||||
let fractional_part = hundred_and_one_fractions
|
||||
/ (10_u64.pow(9) / fractional_res_to_div(FractionalResolution::FifteenUs) as u64);
|
||||
assert_eq!(fractional_part, 101);
|
||||
let one_fraction_with_width_two_in_ns =
|
||||
10_u64.pow(9) as f64 / (2_u32.pow(8 * 2) - 1) as f64;
|
||||
assert_eq!(one_fraction_with_width_two_in_ns.ceil(), 15260.0);
|
||||
let hundred_fractions_and_some =
|
||||
(100.0 * one_fraction_with_width_two_in_ns).floor() as u64 + 7000;
|
||||
let fractional_part = fractional_part_from_subsec_ns(
|
||||
FractionalResolution::FifteenUs,
|
||||
hundred_fractions_and_some,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(fractional_part.1, 100);
|
||||
// Using exactly 101.0 can yield values which will later be rounded down to 100
|
||||
let hundred_and_one_fractions =
|
||||
(101.001 * one_fraction_with_width_two_in_ns).floor() as u64;
|
||||
let fractional_part = fractional_part_from_subsec_ns(
|
||||
FractionalResolution::FifteenUs,
|
||||
hundred_and_one_fractions,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(fractional_part.1, 101);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -914,4 +937,14 @@ mod tests {
|
||||
let res = stamp.update_from_now();
|
||||
assert!(res.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn assert_largest_fractions() {
|
||||
let fractions =
|
||||
fractional_part_from_subsec_ns(FractionalResolution::SixtyNs, 10u64.pow(9) - 1)
|
||||
.unwrap();
|
||||
// The value can not be larger than representable by 3 bytes
|
||||
// Assert that the maximum resolution can be reached
|
||||
assert_eq!(fractions.1, 2_u32.pow(3 * 8) - 2);
|
||||
}
|
||||
}
|
||||
|
35
src/tm.rs
35
src/tm.rs
@ -108,18 +108,18 @@ pub mod zc {
|
||||
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct PusTmSecondaryHeader<'slice> {
|
||||
pub struct PusTmSecondaryHeader<'stamp> {
|
||||
pus_version: PusVersion,
|
||||
pub sc_time_ref_status: u8,
|
||||
pub service: u8,
|
||||
pub subservice: u8,
|
||||
pub msg_counter: u16,
|
||||
pub dest_id: u16,
|
||||
pub time_stamp: &'slice [u8],
|
||||
pub time_stamp: &'stamp [u8],
|
||||
}
|
||||
|
||||
impl<'slice> PusTmSecondaryHeader<'slice> {
|
||||
pub fn new_simple(service: u8, subservice: u8, time_stamp: &'slice [u8]) -> Self {
|
||||
impl<'stamp> PusTmSecondaryHeader<'stamp> {
|
||||
pub fn new_simple(service: u8, subservice: u8, time_stamp: &'stamp [u8]) -> Self {
|
||||
PusTmSecondaryHeader {
|
||||
pus_version: PusVersion::PusC,
|
||||
sc_time_ref_status: 0,
|
||||
@ -136,7 +136,7 @@ impl<'slice> PusTmSecondaryHeader<'slice> {
|
||||
subservice: u8,
|
||||
msg_counter: u16,
|
||||
dest_id: u16,
|
||||
time_stamp: &'slice [u8],
|
||||
time_stamp: &'stamp [u8],
|
||||
) -> Self {
|
||||
PusTmSecondaryHeader {
|
||||
pus_version: PusVersion::PusC,
|
||||
@ -201,21 +201,26 @@ impl<'slice> TryFrom<zc::PusTmSecHeader<'slice>> for PusTmSecondaryHeader<'slice
|
||||
/// provider like [postcard](https://docs.rs/postcard/latest/postcard/).
|
||||
///
|
||||
/// There is no spare bytes support yet.
|
||||
///
|
||||
/// # Lifetimes
|
||||
///
|
||||
/// * `'src_data` - Life time of a buffer where the user provided time stamp and source data will
|
||||
/// be serialized into.
|
||||
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct PusTm<'slice> {
|
||||
pub struct PusTm<'src_data> {
|
||||
pub sp_header: SpHeader,
|
||||
pub sec_header: PusTmSecondaryHeader<'slice>,
|
||||
pub sec_header: PusTmSecondaryHeader<'src_data>,
|
||||
/// If this is set to false, a manual call to [PusTm::calc_own_crc16] or
|
||||
/// [PusTm::update_packet_fields] is necessary for the serialized or cached CRC16 to be valid.
|
||||
pub calc_crc_on_serialization: bool,
|
||||
#[cfg_attr(feature = "serde", serde(skip))]
|
||||
raw_data: Option<&'slice [u8]>,
|
||||
source_data: Option<&'slice [u8]>,
|
||||
raw_data: Option<&'src_data [u8]>,
|
||||
source_data: Option<&'src_data [u8]>,
|
||||
crc16: Option<u16>,
|
||||
}
|
||||
|
||||
impl<'slice> PusTm<'slice> {
|
||||
impl<'src_data> PusTm<'src_data> {
|
||||
/// Generates a new struct instance.
|
||||
///
|
||||
/// # Arguments
|
||||
@ -230,8 +235,8 @@ impl<'slice> PusTm<'slice> {
|
||||
/// the correct value to this field manually
|
||||
pub fn new(
|
||||
sp_header: &mut SpHeader,
|
||||
sec_header: PusTmSecondaryHeader<'slice>,
|
||||
source_data: Option<&'slice [u8]>,
|
||||
sec_header: PusTmSecondaryHeader<'src_data>,
|
||||
source_data: Option<&'src_data [u8]>,
|
||||
set_ccsds_len: bool,
|
||||
) -> Self {
|
||||
sp_header.set_packet_type(PacketType::Tm);
|
||||
@ -259,11 +264,11 @@ impl<'slice> PusTm<'slice> {
|
||||
length
|
||||
}
|
||||
|
||||
pub fn time_stamp(&self) -> &'slice [u8] {
|
||||
pub fn time_stamp(&self) -> &'src_data [u8] {
|
||||
self.sec_header.time_stamp
|
||||
}
|
||||
|
||||
pub fn source_data(&self) -> Option<&'slice [u8]> {
|
||||
pub fn source_data(&self) -> Option<&'src_data [u8]> {
|
||||
self.source_data
|
||||
}
|
||||
|
||||
@ -390,7 +395,7 @@ impl<'slice> PusTm<'slice> {
|
||||
/// the instance and the found byte length of the packet. The timestamp length needs to be
|
||||
/// known beforehand.
|
||||
pub fn from_bytes(
|
||||
slice: &'slice [u8],
|
||||
slice: &'src_data [u8],
|
||||
timestamp_len: usize,
|
||||
) -> Result<(Self, usize), PusError> {
|
||||
let raw_data_len = slice.len();
|
||||
|
Reference in New Issue
Block a user