Compare commits
24 Commits
deb89362a4
...
v0.11.1
Author | SHA1 | Date | |
---|---|---|---|
e7b3ba9575 | |||
c515535ccd
|
|||
95158a8cd2 | |||
8b1ccb0cd0
|
|||
619b22e58f | |||
55222d92b3
|
|||
8e1934e604
|
|||
5f37978c56 | |||
97bbb14168 | |||
a65a98f43f | |||
e1a200e65b | |||
b55c7db3fc | |||
944bcf1320 | |||
8972dcbfc0
|
|||
04b671fa6f | |||
533afc33fa
|
|||
50c56f6504
|
|||
9e02e00d1a | |||
d8676ae711
|
|||
9711159969 | |||
57adb619b3
|
|||
fe52657d11 | |||
50b86939a1
|
|||
179984f258 |
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -27,7 +27,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: 1.61.0
|
||||
toolchain: 1.65.0
|
||||
override: true
|
||||
profile: minimal
|
||||
- uses: actions-rs/cargo@v1
|
||||
|
26
CHANGELOG.md
26
CHANGELOG.md
@@ -8,6 +8,30 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
# [unreleased]
|
||||
|
||||
# [v0.11.1] 2024-04-22
|
||||
|
||||
## Fixed
|
||||
|
||||
- The default data length for for `SpHeader` constructors where the data field length is not
|
||||
specified is now 0.
|
||||
- The `SpHeader::new_from_fields` is public now.
|
||||
|
||||
## Added
|
||||
|
||||
- `SpHeader::to_vec` method.
|
||||
|
||||
# [v0.11.0] 2024-04-16
|
||||
|
||||
## Changed
|
||||
|
||||
- Moved `CCSDS_HEADER_LEN` constant to the crate root.
|
||||
|
||||
## Added
|
||||
|
||||
- Added `SpacePacketHeader` type alias for `SpHeader` type.
|
||||
|
||||
# [v0.11.0-rc.2] 2024-04-04
|
||||
|
||||
## Changed
|
||||
|
||||
- Renamed `PacketId` and `PacketSequenceCtrl` `new` method to `new_checked` and former
|
||||
@@ -15,6 +39,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- Renamed `tc`, `tm`, `tc_unseg` and `tm_unseg` variants for `PacketId` and `SpHeader`
|
||||
to `new_for_tc_checked`, `new_for_tm_checked`, `new_for_unseg_tc_checked` and
|
||||
`new_for_unseg_tm_checked`.
|
||||
- `PusTmCreator` and `PusTcCreator` now expect a regular instance of `SpHeader` instead of
|
||||
a mutable reference.
|
||||
|
||||
## Added
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
[package]
|
||||
name = "spacepackets"
|
||||
version = "0.11.0-rc.1"
|
||||
version = "0.11.1"
|
||||
edition = "2021"
|
||||
rust-version = "1.61"
|
||||
rust-version = "1.65"
|
||||
authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]
|
||||
description = "Generic implementations for various CCSDS and ECSS packet standards"
|
||||
homepage = "https://egit.irs.uni-stuttgart.de/rust/spacepackets"
|
||||
|
@@ -29,10 +29,6 @@ Currently, this includes the following components:
|
||||
|
||||
`spacepackets` supports various runtime environments and is also suitable for `no_std` environments.
|
||||
|
||||
It also offers optional support for [`serde`](https://serde.rs/). This allows serializing and
|
||||
deserializing them with an appropriate `serde` provider like
|
||||
[`postcard`](https://github.com/jamesmunns/postcard).
|
||||
|
||||
## Default features
|
||||
|
||||
- [`std`](https://doc.rust-lang.org/std/): Enables functionality relying on the standard library.
|
||||
|
@@ -15,7 +15,10 @@ RUN rustup install nightly && \
|
||||
rustup target add thumbv7em-none-eabihf armv7-unknown-linux-gnueabihf && \
|
||||
rustup component add rustfmt clippy llvm-tools-preview
|
||||
|
||||
# Get grcov
|
||||
RUN curl -sSL https://github.com/mozilla/grcov/releases/download/v0.8.19/grcov-x86_64-unknown-linux-gnu.tar.bz2 | tar -xj --directory /usr/local/bin
|
||||
# Get nextest
|
||||
RUN curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin
|
||||
|
||||
# SSH stuff to allow deployment to doc server
|
||||
RUN adduser --uid 114 jenkins
|
||||
|
3
automation/Jenkinsfile
vendored
3
automation/Jenkinsfile
vendored
@@ -31,7 +31,8 @@ pipeline {
|
||||
}
|
||||
stage('Test') {
|
||||
steps {
|
||||
sh 'cargo test --all-features'
|
||||
sh 'cargo nextest r --all-features'
|
||||
sh 'cargo test --doc'
|
||||
}
|
||||
}
|
||||
stage('Check with all features') {
|
||||
|
@@ -8,7 +8,8 @@ Checklist for new releases
|
||||
2. Bump version specifier in `Cargo.toml`.
|
||||
3. Update `CHANGELOG.md`: Convert `unreleased` section into version section with date and add new
|
||||
`unreleased` section.
|
||||
4. Run `cargo test --all-features` or `cargo nextest r --all-features`.
|
||||
4. Run `cargo test --all-features` or `cargo nextest r --all-features` together with
|
||||
`cargo test --doc`.
|
||||
5. Run `cargo fmt` and `cargo clippy`. Check `cargo msrv` against MSRV in `Cargo.toml`.
|
||||
6. Wait for CI/CD results for EGit and Github. These also check cross-compilation for bare-metal
|
||||
targets.
|
||||
|
@@ -1,8 +1,8 @@
|
||||
//! Common definitions and helpers required to create PUS TMTC packets according to
|
||||
//! [ECSS-E-ST-70-41C](https://ecss.nl/standard/ecss-e-st-70-41c-space-engineering-telemetry-and-telecommand-packet-utilization-15-april-2016/)
|
||||
//!
|
||||
//! You can find the PUS telecommand definitions in the [tc] module and ithe PUS telemetry definitions
|
||||
//! inside the [tm] module.
|
||||
//! You can find the PUS telecommand types in the [tc] module and the the PUS telemetry
|
||||
//! types inside the [tm] module.
|
||||
use crate::{ByteConversionError, CcsdsPacket, CRC_CCITT_FALSE};
|
||||
#[cfg(feature = "alloc")]
|
||||
use alloc::vec::Vec;
|
||||
@@ -22,7 +22,6 @@ pub mod tm;
|
||||
pub mod verification;
|
||||
|
||||
pub type CrcType = u16;
|
||||
pub const CCSDS_HEADER_LEN: usize = size_of::<crate::zc::SpHeader>();
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
@@ -246,7 +245,7 @@ pub(crate) fn verify_crc16_ccitt_false_from_raw_to_pus_error(
|
||||
crc16: u16,
|
||||
) -> Result<(), PusError> {
|
||||
verify_crc16_ccitt_false_from_raw(raw_data)
|
||||
.then(|| ())
|
||||
.then_some(())
|
||||
.ok_or(PusError::ChecksumFailure(crc16))
|
||||
}
|
||||
|
||||
|
@@ -9,9 +9,11 @@
|
||||
//! use spacepackets::ecss::tc::{PusTcCreator, PusTcReader, PusTcSecondaryHeader};
|
||||
//!
|
||||
//! // Create a ping telecommand with no user application data
|
||||
//! let mut sph = SpHeader::new_for_unseg_tc_checked(0x02, 0x34, 0).unwrap();
|
||||
//! let tc_header = PusTcSecondaryHeader::new_simple(17, 1);
|
||||
//! let pus_tc = PusTcCreator::new_no_app_data(&mut sph, tc_header, true);
|
||||
//! let pus_tc = PusTcCreator::new_no_app_data(
|
||||
//! SpHeader::new_from_apid(0x02),
|
||||
//! PusTcSecondaryHeader::new_simple(17, 1),
|
||||
//! true
|
||||
//! );
|
||||
//! println!("{:?}", pus_tc);
|
||||
//! assert_eq!(pus_tc.service(), 17);
|
||||
//! assert_eq!(pus_tc.subservice(), 1);
|
||||
@@ -256,7 +258,7 @@ impl<'app_data> PusTcCreator<'app_data> {
|
||||
/// the correct value to this field manually
|
||||
#[inline]
|
||||
pub fn new(
|
||||
sp_header: &mut SpHeader,
|
||||
mut sp_header: SpHeader,
|
||||
sec_header: PusTcSecondaryHeader,
|
||||
app_data: &'app_data [u8],
|
||||
set_ccsds_len: bool,
|
||||
@@ -264,7 +266,7 @@ impl<'app_data> PusTcCreator<'app_data> {
|
||||
sp_header.set_packet_type(PacketType::Tc);
|
||||
sp_header.set_sec_header_flag();
|
||||
let mut pus_tc = Self {
|
||||
sp_header: *sp_header,
|
||||
sp_header,
|
||||
app_data,
|
||||
sec_header,
|
||||
};
|
||||
@@ -278,7 +280,7 @@ impl<'app_data> PusTcCreator<'app_data> {
|
||||
/// and subservice instead of the full PUS TC secondary header.
|
||||
#[inline]
|
||||
pub fn new_simple(
|
||||
sph: &mut SpHeader,
|
||||
sph: SpHeader,
|
||||
service: u8,
|
||||
subservice: u8,
|
||||
app_data: &'app_data [u8],
|
||||
@@ -294,7 +296,7 @@ impl<'app_data> PusTcCreator<'app_data> {
|
||||
|
||||
#[inline]
|
||||
pub fn new_no_app_data(
|
||||
sp_header: &mut SpHeader,
|
||||
sp_header: SpHeader,
|
||||
sec_header: PusTcSecondaryHeader,
|
||||
set_ccsds_len: bool,
|
||||
) -> Self {
|
||||
@@ -618,19 +620,19 @@ mod tests {
|
||||
use postcard::{from_bytes, to_allocvec};
|
||||
|
||||
fn base_ping_tc_full_ctor() -> PusTcCreator<'static> {
|
||||
let mut sph = SpHeader::new_for_unseg_tc_checked(0x02, 0x34, 0).unwrap();
|
||||
let sph = SpHeader::new_for_unseg_tc_checked(0x02, 0x34, 0).unwrap();
|
||||
let tc_header = PusTcSecondaryHeader::new_simple(17, 1);
|
||||
PusTcCreator::new_no_app_data(&mut sph, tc_header, true)
|
||||
PusTcCreator::new_no_app_data(sph, tc_header, true)
|
||||
}
|
||||
|
||||
fn base_ping_tc_simple_ctor() -> PusTcCreator<'static> {
|
||||
let mut sph = SpHeader::new_for_unseg_tc_checked(0x02, 0x34, 0).unwrap();
|
||||
PusTcCreator::new_simple(&mut sph, 17, 1, &[], true)
|
||||
let sph = SpHeader::new_for_unseg_tc_checked(0x02, 0x34, 0).unwrap();
|
||||
PusTcCreator::new_simple(sph, 17, 1, &[], true)
|
||||
}
|
||||
|
||||
fn base_ping_tc_simple_ctor_with_app_data(app_data: &'static [u8]) -> PusTcCreator<'static> {
|
||||
let mut sph = SpHeader::new_for_unseg_tc_checked(0x02, 0x34, 0).unwrap();
|
||||
PusTcCreator::new_simple(&mut sph, 17, 1, app_data, true)
|
||||
let sph = SpHeader::new_for_unseg_tc_checked(0x02, 0x34, 0).unwrap();
|
||||
PusTcCreator::new_simple(sph, 17, 1, app_data, true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -686,8 +688,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_update_func() {
|
||||
let mut sph = SpHeader::new_for_unseg_tc_checked(0x02, 0x34, 0).unwrap();
|
||||
let mut tc = PusTcCreator::new_simple(&mut sph, 17, 1, &[], false);
|
||||
let sph = SpHeader::new_for_unseg_tc_checked(0x02, 0x34, 0).unwrap();
|
||||
let mut tc = PusTcCreator::new_simple(sph, 17, 1, &[], false);
|
||||
assert_eq!(tc.data_len(), 0);
|
||||
tc.update_ccsds_data_len();
|
||||
assert_eq!(tc.data_len(), 6);
|
||||
|
@@ -1,5 +1,47 @@
|
||||
//! This module contains all components required to create a ECSS PUS C telemetry packets according
|
||||
//! to [ECSS-E-ST-70-41C](https://ecss.nl/standard/ecss-e-st-70-41c-space-engineering-telemetry-and-telecommand-packet-utilization-15-april-2016/).
|
||||
//!
|
||||
//! # Examples
|
||||
//!
|
||||
//! ```rust
|
||||
//! use spacepackets::time::TimeWriter;
|
||||
//! use spacepackets::time::cds::CdsTime;
|
||||
//! use spacepackets::{CcsdsPacket, SpHeader};
|
||||
//! use spacepackets::ecss::{PusPacket, WritablePusPacket};
|
||||
//! use spacepackets::ecss::tm::{PusTmCreator, PusTmReader, PusTmSecondaryHeader};
|
||||
//!
|
||||
//! let mut time_buf: [u8; 7] = [0; 7];
|
||||
//! let time_now = CdsTime::now_with_u16_days().expect("creating CDS timestamp failed");
|
||||
//! // This can definitely hold the timestamp, so it is okay to unwrap.
|
||||
//! time_now.write_to_bytes(&mut time_buf).unwrap();
|
||||
//!
|
||||
//! // Create a ping telemetry with no user source data
|
||||
//! let ping_tm = PusTmCreator::new_no_source_data(
|
||||
//! SpHeader::new_from_apid(0x02),
|
||||
//! PusTmSecondaryHeader::new_simple(17, 2, &time_buf),
|
||||
//! true
|
||||
//! );
|
||||
//! println!("{:?}", ping_tm);
|
||||
//! assert_eq!(ping_tm.service(), 17);
|
||||
//! assert_eq!(ping_tm.subservice(), 2);
|
||||
//! assert_eq!(ping_tm.apid(), 0x02);
|
||||
//!
|
||||
//! // Serialize TM into a raw buffer
|
||||
//! let mut test_buf: [u8; 32] = [0; 32];
|
||||
//! let written_size = ping_tm
|
||||
//! .write_to_bytes(test_buf.as_mut_slice())
|
||||
//! .expect("Error writing TC to buffer");
|
||||
//! assert_eq!(written_size, 22);
|
||||
//! println!("{:?}", &test_buf[0..written_size]);
|
||||
//!
|
||||
//! // Deserialize from the raw byte representation
|
||||
//! let (ping_tm_reader, read_size) = PusTmReader::new(&test_buf, 7).expect("Deserialization failed");
|
||||
//! assert_eq!(written_size, read_size);
|
||||
//! assert_eq!(ping_tm_reader.service(), 17);
|
||||
//! assert_eq!(ping_tm_reader.subservice(), 2);
|
||||
//! assert_eq!(ping_tm_reader.apid(), 0x02);
|
||||
//! assert_eq!(ping_tm_reader.timestamp(), &time_buf);
|
||||
//! ```
|
||||
use crate::ecss::{
|
||||
calc_pus_crc16, ccsds_impl, crc_from_raw_data, sp_header_impls, user_data_from_raw,
|
||||
verify_crc16_ccitt_false_from_raw_to_pus_error, CrcType, PusError, PusPacket, PusVersion,
|
||||
@@ -254,7 +296,7 @@ impl<'time, 'src_data> PusTmCreator<'time, 'src_data> {
|
||||
/// the correct value to this field manually
|
||||
#[inline]
|
||||
pub fn new(
|
||||
sp_header: &mut SpHeader,
|
||||
mut sp_header: SpHeader,
|
||||
sec_header: PusTmSecondaryHeader<'time>,
|
||||
source_data: &'src_data [u8],
|
||||
set_ccsds_len: bool,
|
||||
@@ -262,7 +304,7 @@ impl<'time, 'src_data> PusTmCreator<'time, 'src_data> {
|
||||
sp_header.set_packet_type(PacketType::Tm);
|
||||
sp_header.set_sec_header_flag();
|
||||
let mut pus_tm = Self {
|
||||
sp_header: *sp_header,
|
||||
sp_header,
|
||||
source_data,
|
||||
sec_header,
|
||||
calc_crc_on_serialization: true,
|
||||
@@ -275,7 +317,7 @@ impl<'time, 'src_data> PusTmCreator<'time, 'src_data> {
|
||||
|
||||
#[inline]
|
||||
pub fn new_simple(
|
||||
sp_header: &mut SpHeader,
|
||||
sp_header: SpHeader,
|
||||
service: u8,
|
||||
subservice: u8,
|
||||
time_provider: &impl TimeWriter,
|
||||
@@ -291,7 +333,7 @@ impl<'time, 'src_data> PusTmCreator<'time, 'src_data> {
|
||||
|
||||
#[inline]
|
||||
pub fn new_no_source_data(
|
||||
sp_header: &mut SpHeader,
|
||||
sp_header: SpHeader,
|
||||
sec_header: PusTmSecondaryHeader<'time>,
|
||||
set_ccsds_len: bool,
|
||||
) -> Self {
|
||||
@@ -840,20 +882,20 @@ mod tests {
|
||||
const DUMMY_DATA: &[u8] = &[0, 1, 2];
|
||||
|
||||
fn base_ping_reply_full_ctor(timestamp: &[u8]) -> PusTmCreator {
|
||||
let mut sph = SpHeader::new_for_unseg_tm_checked(0x123, 0x234, 0).unwrap();
|
||||
let sph = SpHeader::new_for_unseg_tm_checked(0x123, 0x234, 0).unwrap();
|
||||
let tm_header = PusTmSecondaryHeader::new_simple(17, 2, timestamp);
|
||||
PusTmCreator::new_no_source_data(&mut sph, tm_header, true)
|
||||
PusTmCreator::new_no_source_data(sph, tm_header, true)
|
||||
}
|
||||
fn ping_reply_with_data(timestamp: &[u8]) -> PusTmCreator {
|
||||
let mut sph = SpHeader::new_for_unseg_tm_checked(0x123, 0x234, 0).unwrap();
|
||||
let sph = SpHeader::new_for_unseg_tm_checked(0x123, 0x234, 0).unwrap();
|
||||
let tm_header = PusTmSecondaryHeader::new_simple(17, 2, timestamp);
|
||||
PusTmCreator::new(&mut sph, tm_header, DUMMY_DATA, true)
|
||||
PusTmCreator::new(sph, tm_header, DUMMY_DATA, true)
|
||||
}
|
||||
|
||||
fn base_hk_reply<'a, 'b>(timestamp: &'a [u8], src_data: &'b [u8]) -> PusTmCreator<'a, 'b> {
|
||||
let mut sph = SpHeader::new_for_unseg_tm_checked(0x123, 0x234, 0).unwrap();
|
||||
let sph = SpHeader::new_for_unseg_tm_checked(0x123, 0x234, 0).unwrap();
|
||||
let tc_header = PusTmSecondaryHeader::new_simple(3, 5, timestamp);
|
||||
PusTmCreator::new(&mut sph, tc_header, src_data, true)
|
||||
PusTmCreator::new(sph, tc_header, src_data, true)
|
||||
}
|
||||
|
||||
fn dummy_timestamp() -> &'static [u8] {
|
||||
@@ -868,11 +910,11 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn test_basic_simple_api() {
|
||||
let mut sph = SpHeader::new_for_unseg_tm_checked(0x123, 0x234, 0).unwrap();
|
||||
let sph = SpHeader::new_for_unseg_tm_checked(0x123, 0x234, 0).unwrap();
|
||||
let time_provider = CdsTime::new_with_u16_days(0, 0);
|
||||
let mut stamp_buf: [u8; 8] = [0; 8];
|
||||
let pus_tm =
|
||||
PusTmCreator::new_simple(&mut sph, 17, 2, &time_provider, &mut stamp_buf, &[], true)
|
||||
PusTmCreator::new_simple(sph, 17, 2, &time_provider, &mut stamp_buf, &[], true)
|
||||
.unwrap();
|
||||
verify_ping_reply(&pus_tm, false, 22, &[64, 0, 0, 0, 0, 0, 0]);
|
||||
}
|
||||
@@ -969,9 +1011,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_manual_field_update() {
|
||||
let mut sph = SpHeader::new_for_unseg_tm_checked(0x123, 0x234, 0).unwrap();
|
||||
let sph = SpHeader::new_for_unseg_tm_checked(0x123, 0x234, 0).unwrap();
|
||||
let tc_header = PusTmSecondaryHeader::new_simple(17, 2, dummy_timestamp());
|
||||
let mut tm = PusTmCreator::new_no_source_data(&mut sph, tc_header, false);
|
||||
let mut tm = PusTmCreator::new_no_source_data(sph, tc_header, false);
|
||||
tm.calc_crc_on_serialization = false;
|
||||
assert_eq!(tm.data_len(), 0x00);
|
||||
let mut buf: [u8; 32] = [0; 32];
|
||||
@@ -1259,11 +1301,11 @@ mod tests {
|
||||
#[test]
|
||||
#[cfg(feature = "serde")]
|
||||
fn test_serialization_creator_serde() {
|
||||
let mut sph = SpHeader::new_for_unseg_tm_checked(0x123, 0x234, 0).unwrap();
|
||||
let sph = SpHeader::new_for_unseg_tm_checked(0x123, 0x234, 0).unwrap();
|
||||
let time_provider = CdsTime::new_with_u16_days(0, 0);
|
||||
let mut stamp_buf: [u8; 8] = [0; 8];
|
||||
let pus_tm =
|
||||
PusTmCreator::new_simple(&mut sph, 17, 2, &time_provider, &mut stamp_buf, &[], true)
|
||||
PusTmCreator::new_simple(sph, 17, 2, &time_provider, &mut stamp_buf, &[], true)
|
||||
.unwrap();
|
||||
|
||||
let output = to_allocvec(&pus_tm).unwrap();
|
||||
@@ -1274,11 +1316,11 @@ mod tests {
|
||||
#[test]
|
||||
#[cfg(feature = "serde")]
|
||||
fn test_serialization_reader_serde() {
|
||||
let mut sph = SpHeader::new_for_unseg_tm_checked(0x123, 0x234, 0).unwrap();
|
||||
let sph = SpHeader::new_for_unseg_tm_checked(0x123, 0x234, 0).unwrap();
|
||||
let time_provider = CdsTime::new_with_u16_days(0, 0);
|
||||
let mut stamp_buf: [u8; 8] = [0; 8];
|
||||
let pus_tm =
|
||||
PusTmCreator::new_simple(&mut sph, 17, 2, &time_provider, &mut stamp_buf, &[], true)
|
||||
PusTmCreator::new_simple(sph, 17, 2, &time_provider, &mut stamp_buf, &[], true)
|
||||
.unwrap();
|
||||
let pus_tm_vec = pus_tm.to_vec().unwrap();
|
||||
let (tm_reader, _) = PusTmReader::new(&pus_tm_vec, time_provider.len_as_bytes()).unwrap();
|
||||
|
60
src/lib.rs
60
src/lib.rs
@@ -22,10 +22,6 @@
|
||||
//!
|
||||
//! `spacepackets` supports various runtime environments and is also suitable for `no_std` environments.
|
||||
//!
|
||||
//! It also offers optional support for [`serde`](https://serde.rs/). This allows serializing and
|
||||
//! deserializing them with an appropriate `serde` provider like
|
||||
//! [`postcard`](https://github.com/jamesmunns/postcard).
|
||||
//!
|
||||
//! ### Default features
|
||||
//!
|
||||
//! - [`std`](https://doc.rust-lang.org/std/): Enables functionality relying on the standard library.
|
||||
@@ -65,7 +61,6 @@ extern crate alloc;
|
||||
#[cfg(any(feature = "std", test))]
|
||||
extern crate std;
|
||||
|
||||
use crate::ecss::CCSDS_HEADER_LEN;
|
||||
use core::{
|
||||
fmt::{Debug, Display, Formatter},
|
||||
hash::Hash,
|
||||
@@ -88,6 +83,8 @@ mod private {
|
||||
pub trait Sealed {}
|
||||
}
|
||||
|
||||
pub const CCSDS_HEADER_LEN: usize = core::mem::size_of::<crate::zc::SpHeader>();
|
||||
|
||||
/// CRC algorithm used by the PUS standard, the CCSDS TC standard and the CFDP standard.
|
||||
pub const CRC_CCITT_FALSE: Crc<u16> = Crc::<u16>::new(&CRC_16_IBM_3740);
|
||||
|
||||
@@ -505,9 +502,11 @@ pub struct SpHeader {
|
||||
pub data_len: u16,
|
||||
}
|
||||
|
||||
pub type SpacePacketHeader = SpHeader;
|
||||
|
||||
impl Default for SpHeader {
|
||||
/// The default function sets the sequence flag field to [SequenceFlags::Unsegmented]. The data
|
||||
/// length field is set to 1, which denotes an empty space packets.
|
||||
/// The default function sets the sequence flag field to [SequenceFlags::Unsegmented] and the
|
||||
/// data length to 0.
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
SpHeader {
|
||||
@@ -517,7 +516,7 @@ impl Default for SpHeader {
|
||||
seq_flags: SequenceFlags::Unsegmented,
|
||||
seq_count: 0,
|
||||
},
|
||||
data_len: 1,
|
||||
data_len: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -533,8 +532,8 @@ impl SpHeader {
|
||||
}
|
||||
}
|
||||
|
||||
/// This constructor sets the sequence flag field to [SequenceFlags::Unsegmented]. The data
|
||||
/// length field is set to 1, which denotes an empty space packets.
|
||||
/// This constructor sets the sequence flag field to [SequenceFlags::Unsegmented] and the data
|
||||
/// length to 0.
|
||||
///
|
||||
/// This constructor will panic if the APID exceeds [MAX_APID].
|
||||
#[inline]
|
||||
@@ -546,7 +545,7 @@ impl SpHeader {
|
||||
seq_flags: SequenceFlags::Unsegmented,
|
||||
seq_count: 0,
|
||||
},
|
||||
data_len: 1,
|
||||
data_len: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -560,7 +559,7 @@ impl SpHeader {
|
||||
seq_flags: SequenceFlags::Unsegmented,
|
||||
seq_count: 0,
|
||||
},
|
||||
data_len: 1,
|
||||
data_len: 0,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -569,7 +568,7 @@ impl SpHeader {
|
||||
///
|
||||
/// The checked constructor variants can be used to avoid panics.
|
||||
#[inline]
|
||||
const fn new_from_fields(
|
||||
pub const fn new_from_fields(
|
||||
ptype: PacketType,
|
||||
sec_header: bool,
|
||||
apid: u16,
|
||||
@@ -756,6 +755,15 @@ impl SpHeader {
|
||||
.ok_or(ByteConversionError::ZeroCopyToError)?;
|
||||
Ok(&mut buf[CCSDS_HEADER_LEN..])
|
||||
}
|
||||
|
||||
/// Create a vector containing the CCSDS header.
|
||||
#[cfg(feature = "alloc")]
|
||||
pub fn to_vec(&self) -> alloc::vec::Vec<u8> {
|
||||
let mut vec = alloc::vec![0; CCSDS_HEADER_LEN];
|
||||
// This can not fail.
|
||||
self.write_to_be_bytes(&mut vec[..]).unwrap();
|
||||
vec
|
||||
}
|
||||
}
|
||||
|
||||
impl CcsdsPacket for SpHeader {
|
||||
@@ -893,6 +901,8 @@ pub mod zc {
|
||||
pub(crate) mod tests {
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use crate::ByteConversionError;
|
||||
#[cfg(feature = "serde")]
|
||||
use crate::CcsdsPrimaryHeader;
|
||||
use crate::{
|
||||
@@ -1259,11 +1269,35 @@ pub(crate) mod tests {
|
||||
fn sp_header_from_apid() {
|
||||
let sp_header = SpHeader::new_from_apid(0x03);
|
||||
assert_eq!(sp_header.apid(), 0x03);
|
||||
assert_eq!(sp_header.data_len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sp_header_from_apid_checked() {
|
||||
let sp_header = SpHeader::new_from_apid_checked(0x03).unwrap();
|
||||
assert_eq!(sp_header.apid(), 0x03);
|
||||
assert_eq!(sp_header.data_len(), 0);
|
||||
}
|
||||
|
||||
#[cfg(feature = "defmt")]
|
||||
fn is_defmt_format<T: defmt::Format>(_t: T) {}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "defmt")]
|
||||
fn test_defmt_format() {
|
||||
is_defmt_format(ByteConversionError::ToSliceTooSmall {
|
||||
found: 1,
|
||||
expected: 2,
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sp_header_as_vec() {
|
||||
let sp_header = SpHeader::new_for_unseg_tc(0x42, 25, 1);
|
||||
let sp_header_as_vec = sp_header.to_vec();
|
||||
let sp_header_read_back = SpHeader::from_be_bytes(&sp_header_as_vec)
|
||||
.expect("Error reading back SP header")
|
||||
.0;
|
||||
assert_eq!(sp_header, sp_header_read_back);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user