Compare commits
7 Commits
v0.4.2
...
db471e313c
Author | SHA1 | Date | |
---|---|---|---|
db471e313c | |||
6154ce6299 | |||
2756670efe | |||
eb5ace0658 | |||
b9cd08cefe | |||
0073db95f9 | |||
251fcdd6c8 |
30
.github/workflows/ci.yml
vendored
30
.github/workflows/ci.yml
vendored
@ -20,21 +20,6 @@ jobs:
|
||||
command: check
|
||||
args: --release
|
||||
|
||||
msrv:
|
||||
name: Check with MSRV
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: 1.60.0
|
||||
override: true
|
||||
profile: minimal
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: check
|
||||
args: --release
|
||||
|
||||
cross-check:
|
||||
name: Check Cross
|
||||
runs-on: ubuntu-latest
|
||||
@ -73,21 +58,6 @@ jobs:
|
||||
command: fmt
|
||||
args: --all -- --check
|
||||
|
||||
check-doc:
|
||||
name: Check Documentation Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: nightly
|
||||
override: true
|
||||
profile: minimal
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: doc
|
||||
args: --all-features
|
||||
|
||||
clippy:
|
||||
name: Clippy
|
||||
runs-on: ubuntu-latest
|
||||
|
28
CHANGELOG.md
28
CHANGELOG.md
@ -8,29 +8,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
# [unreleased]
|
||||
|
||||
# [v0.4.2] 14.01.2023
|
||||
|
||||
## Fixed
|
||||
|
||||
- CDS timestamp: Fixed another small logic error for stamp creation from the current
|
||||
time with picosecond precision.
|
||||
PR: https://egit.irs.uni-stuttgart.de/rust/spacepackets/pulls/8
|
||||
|
||||
# [v0.4.1] 14.01.2023
|
||||
|
||||
## Fixed
|
||||
|
||||
- CDS timestamp: The conversion function from the current time were buggy
|
||||
when specifying picoseconds precision, which could lead to overflow
|
||||
multiplications and/or incorrect precision fields.
|
||||
PR: https://egit.irs.uni-stuttgart.de/rust/spacepackets/pulls/7
|
||||
|
||||
# [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.
|
||||
@ -46,14 +23,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## Added
|
||||
|
||||
- `SpHeader` getter function `sp_header` added for `PusTc`
|
||||
PR: https://egit.irs.uni-stuttgart.de/rust/spacepackets/pulls/6
|
||||
CUC PR: https://egit.irs.uni-stuttgart.de/rust/spacepackets/pulls/4/files
|
||||
|
||||
- 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.4.2"
|
||||
version = "0.3.1"
|
||||
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"
|
||||
crc = "3.0"
|
||||
delegate = "0.8"
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1"
|
||||
version = "1.0"
|
||||
optional = true
|
||||
default-features = false
|
||||
features = ["derive"]
|
||||
|
@ -15,9 +15,7 @@ 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/).
|
||||
- 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
|
||||
- CDS Short 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)
|
||||
|
@ -10,6 +10,6 @@ ARG DEBIAN_FRONTEND=noninteractive
|
||||
# set CROSS_CONTAINER_IN_CONTAINER to inform `cross` that it is executed from within a container
|
||||
ENV CROSS_CONTAINER_IN_CONTAINER=true
|
||||
|
||||
RUN rustup install nightly && \
|
||||
rustup target add thumbv7em-none-eabihf armv7-unknown-linux-gnueabihf && \
|
||||
# TODO: installing cross is problematic, permission issues
|
||||
RUN rustup target add thumbv7em-none-eabihf armv7-unknown-linux-gnueabihf && \
|
||||
rustup component add rustfmt clippy
|
||||
|
18
automation/Jenkinsfile
vendored
18
automation/Jenkinsfile
vendored
@ -13,29 +13,19 @@ pipeline {
|
||||
sh 'cargo clippy'
|
||||
}
|
||||
}
|
||||
stage('Docs') {
|
||||
steps {
|
||||
sh 'cargo +nightly doc --all-features'
|
||||
}
|
||||
}
|
||||
stage('Rustfmt') {
|
||||
steps {
|
||||
sh 'cargo fmt --all --check'
|
||||
sh 'cargo fmt'
|
||||
}
|
||||
}
|
||||
stage('Test') {
|
||||
steps {
|
||||
sh 'cargo test --all-features'
|
||||
sh 'cargo test'
|
||||
}
|
||||
}
|
||||
stage('Check with all features') {
|
||||
stage('Check') {
|
||||
steps {
|
||||
sh 'cargo check --all-features'
|
||||
}
|
||||
}
|
||||
stage('Check with no features') {
|
||||
steps {
|
||||
sh 'cargo check --no-default-features'
|
||||
sh 'cargo check'
|
||||
}
|
||||
}
|
||||
stage('Check Cross Embedded Bare Metal') {
|
||||
|
10
src/ecss.rs
10
src/ecss.rs
@ -18,15 +18,10 @@ 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,
|
||||
}
|
||||
|
||||
@ -53,7 +48,6 @@ 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 {
|
||||
@ -73,7 +67,6 @@ 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 {
|
||||
@ -89,7 +82,6 @@ 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 {
|
||||
@ -160,8 +152,6 @@ 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,11 +9,9 @@
|
||||
//! [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/).
|
||||
//! - 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
|
||||
//! - 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
|
||||
//! [CCSDS 301.0-B-4 3.5](https://public.ccsds.org/Pubs/301x0b4e1.pdf)
|
||||
//!
|
||||
//! ## Features
|
||||
@ -129,7 +127,6 @@ 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 {
|
||||
@ -178,8 +175,6 @@ 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 {
|
||||
@ -263,8 +258,6 @@ 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<'app_data> {
|
||||
pub struct PusTc<'slice> {
|
||||
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<&'app_data [u8]>,
|
||||
app_data: Option<&'app_data [u8]>,
|
||||
raw_data: Option<&'slice [u8]>,
|
||||
app_data: Option<&'slice [u8]>,
|
||||
crc16: Option<u16>,
|
||||
}
|
||||
|
||||
impl<'app_data> PusTc<'app_data> {
|
||||
impl<'slice> PusTc<'slice> {
|
||||
/// Generates a new struct instance.
|
||||
///
|
||||
/// # Arguments
|
||||
@ -243,7 +243,7 @@ impl<'app_data> PusTc<'app_data> {
|
||||
pub fn new(
|
||||
sp_header: &mut SpHeader,
|
||||
sec_header: PusTcSecondaryHeader,
|
||||
app_data: Option<&'app_data [u8]>,
|
||||
app_data: Option<&'slice [u8]>,
|
||||
set_ccsds_len: bool,
|
||||
) -> Self {
|
||||
sp_header.set_packet_type(PacketType::Tc);
|
||||
@ -268,7 +268,7 @@ impl<'app_data> PusTc<'app_data> {
|
||||
sph: &mut SpHeader,
|
||||
service: u8,
|
||||
subservice: u8,
|
||||
app_data: Option<&'app_data [u8]>,
|
||||
app_data: Option<&'slice [u8]>,
|
||||
set_ccsds_len: bool,
|
||||
) -> Self {
|
||||
Self::new(
|
||||
@ -279,10 +279,6 @@ impl<'app_data> PusTc<'app_data> {
|
||||
)
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -405,7 +401,7 @@ impl<'app_data> PusTc<'app_data> {
|
||||
|
||||
/// 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: &'app_data [u8]) -> Result<(Self, usize), PusError> {
|
||||
pub fn from_bytes(slice: &'slice [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));
|
||||
@ -435,7 +431,7 @@ impl<'app_data> PusTc<'app_data> {
|
||||
Ok((pus_tc, total_len))
|
||||
}
|
||||
|
||||
pub fn raw(&self) -> Option<&'app_data [u8]> {
|
||||
pub fn raw(&self) -> Option<&'slice [u8]> {
|
||||
self.raw_data
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,8 @@
|
||||
//! See [chrono::DateTime::format] for a usage example of the generated
|
||||
//! [chrono::format::DelayedFormat] structs.
|
||||
#[cfg(feature = "alloc")]
|
||||
use chrono::{
|
||||
format::{DelayedFormat, StrftimeItems},
|
||||
DateTime, Utc,
|
||||
};
|
||||
use chrono::format::{DelayedFormat, StrftimeItems};
|
||||
use chrono::{DateTime, Utc};
|
||||
|
||||
/// Tuple of format string and formatted size for time code A.
|
||||
///
|
||||
|
@ -6,8 +6,7 @@ use super::*;
|
||||
use crate::private::Sealed;
|
||||
use core::fmt::Debug;
|
||||
|
||||
/// 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;
|
||||
const CDS_SHORT_P_FIELD: 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
|
||||
@ -125,7 +124,7 @@ pub fn precision_from_pfield(pfield: u8) -> SubmillisPrecision {
|
||||
/// assert_eq!(stamp_deserialized.len_as_bytes(), 7);
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct TimeProvider<DaysLen: ProvidesDaysLength = DaysLen16Bits> {
|
||||
pfield: u8,
|
||||
@ -170,8 +169,8 @@ impl ConversionFromNow {
|
||||
));
|
||||
}
|
||||
SubmillisPrecision::Picoseconds(_) => {
|
||||
prec = Some(SubmillisPrecision::Picoseconds(
|
||||
(now.subsec_nanos() % 10_u32.pow(6)) * 1000,
|
||||
prec = Some(SubmillisPrecision::Microseconds(
|
||||
(now.subsec_nanos() * 1000) as u16,
|
||||
));
|
||||
}
|
||||
_ => (),
|
||||
@ -392,7 +391,7 @@ impl<ProvidesDaysLen: ProvidesDaysLength> TimeProvider<ProvidesDaysLen> {
|
||||
day_seg_len: LengthOfDaySegment,
|
||||
submillis_prec: Option<SubmillisPrecision>,
|
||||
) -> u8 {
|
||||
let mut pfield = P_FIELD_BASE | ((day_seg_len as u8) << 2);
|
||||
let mut pfield = CDS_SHORT_P_FIELD | ((day_seg_len as u8) << 2);
|
||||
if let Some(submillis_prec) = submillis_prec {
|
||||
match submillis_prec {
|
||||
SubmillisPrecision::Microseconds(_) => pfield |= 0b01,
|
||||
|
@ -6,9 +6,6 @@ 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;
|
||||
|
||||
@ -67,20 +64,10 @@ 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. 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;
|
||||
// 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);
|
||||
Some(FractionalPart(res, fractional_part as u32))
|
||||
}
|
||||
|
||||
@ -313,7 +300,7 @@ impl TimeProviderCcsdsEpoch {
|
||||
}
|
||||
|
||||
fn build_p_field(counter_width: u8, fractions_width: Option<FractionalResolution>) -> u8 {
|
||||
let mut pfield = P_FIELD_BASE;
|
||||
let mut pfield = (CcsdsTimeCodes::CucCcsdsEpoch as u8) << 4;
|
||||
if !(1..=4).contains(&counter_width) {
|
||||
// Okay to panic here, this function is private and all input values should
|
||||
// have been sanitized
|
||||
@ -880,39 +867,29 @@ mod tests {
|
||||
#[test]
|
||||
fn fractional_part_formula() {
|
||||
let fractional_part =
|
||||
fractional_part_from_subsec_ns(FractionalResolution::FourMs, 7843138).unwrap();
|
||||
assert_eq!(fractional_part.1, 2);
|
||||
7843137 / (10_u64.pow(9) / fractional_res_to_div(FractionalResolution::FourMs) as u64);
|
||||
assert_eq!(fractional_part, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fractional_part_formula_2() {
|
||||
let fractional_part =
|
||||
fractional_part_from_subsec_ns(FractionalResolution::FourMs, 12000000).unwrap();
|
||||
assert_eq!(fractional_part.1, 3);
|
||||
12000000 / (10_u64.pow(9) / fractional_res_to_div(FractionalResolution::FourMs) as u64);
|
||||
assert_eq!(fractional_part, 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fractional_part_formula_3() {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -937,14 +914,4 @@ 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<'stamp> {
|
||||
pub struct PusTmSecondaryHeader<'slice> {
|
||||
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: &'stamp [u8],
|
||||
pub time_stamp: &'slice [u8],
|
||||
}
|
||||
|
||||
impl<'stamp> PusTmSecondaryHeader<'stamp> {
|
||||
pub fn new_simple(service: u8, subservice: u8, time_stamp: &'stamp [u8]) -> Self {
|
||||
impl<'slice> PusTmSecondaryHeader<'slice> {
|
||||
pub fn new_simple(service: u8, subservice: u8, time_stamp: &'slice [u8]) -> Self {
|
||||
PusTmSecondaryHeader {
|
||||
pus_version: PusVersion::PusC,
|
||||
sc_time_ref_status: 0,
|
||||
@ -136,7 +136,7 @@ impl<'stamp> PusTmSecondaryHeader<'stamp> {
|
||||
subservice: u8,
|
||||
msg_counter: u16,
|
||||
dest_id: u16,
|
||||
time_stamp: &'stamp [u8],
|
||||
time_stamp: &'slice [u8],
|
||||
) -> Self {
|
||||
PusTmSecondaryHeader {
|
||||
pus_version: PusVersion::PusC,
|
||||
@ -201,26 +201,21 @@ 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<'src_data> {
|
||||
pub struct PusTm<'slice> {
|
||||
pub sp_header: SpHeader,
|
||||
pub sec_header: PusTmSecondaryHeader<'src_data>,
|
||||
pub sec_header: PusTmSecondaryHeader<'slice>,
|
||||
/// 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<&'src_data [u8]>,
|
||||
source_data: Option<&'src_data [u8]>,
|
||||
raw_data: Option<&'slice [u8]>,
|
||||
source_data: Option<&'slice [u8]>,
|
||||
crc16: Option<u16>,
|
||||
}
|
||||
|
||||
impl<'src_data> PusTm<'src_data> {
|
||||
impl<'slice> PusTm<'slice> {
|
||||
/// Generates a new struct instance.
|
||||
///
|
||||
/// # Arguments
|
||||
@ -235,8 +230,8 @@ impl<'src_data> PusTm<'src_data> {
|
||||
/// the correct value to this field manually
|
||||
pub fn new(
|
||||
sp_header: &mut SpHeader,
|
||||
sec_header: PusTmSecondaryHeader<'src_data>,
|
||||
source_data: Option<&'src_data [u8]>,
|
||||
sec_header: PusTmSecondaryHeader<'slice>,
|
||||
source_data: Option<&'slice [u8]>,
|
||||
set_ccsds_len: bool,
|
||||
) -> Self {
|
||||
sp_header.set_packet_type(PacketType::Tm);
|
||||
@ -264,11 +259,11 @@ impl<'src_data> PusTm<'src_data> {
|
||||
length
|
||||
}
|
||||
|
||||
pub fn time_stamp(&self) -> &'src_data [u8] {
|
||||
pub fn time_stamp(&self) -> &'slice [u8] {
|
||||
self.sec_header.time_stamp
|
||||
}
|
||||
|
||||
pub fn source_data(&self) -> Option<&'src_data [u8]> {
|
||||
pub fn source_data(&self) -> Option<&'slice [u8]> {
|
||||
self.source_data
|
||||
}
|
||||
|
||||
@ -395,7 +390,7 @@ impl<'src_data> PusTm<'src_data> {
|
||||
/// the instance and the found byte length of the packet. The timestamp length needs to be
|
||||
/// known beforehand.
|
||||
pub fn from_bytes(
|
||||
slice: &'src_data [u8],
|
||||
slice: &'slice [u8],
|
||||
timestamp_len: usize,
|
||||
) -> Result<(Self, usize), PusError> {
|
||||
let raw_data_len = slice.len();
|
||||
|
Reference in New Issue
Block a user