some more dependency cleanup
Rust/spacepackets/pipeline/head This commit looks good Details

This commit is contained in:
Robin Müller 2022-08-16 10:11:49 +02:00
parent 933230126e
commit 388a8ba616
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
5 changed files with 70 additions and 32 deletions

View File

@ -5,12 +5,25 @@ name: ci
jobs:
check:
name: Check
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- uses: actions-rs/cargo@v1
with:
command: check
args: --release
cross-check:
name: Check Cross
runs-on: ubuntu-latest
strategy:
matrix:
target:
- armv7-unknown-linux-gnueabihf
- x86_64-unknown-linux-gnu
- thumbv7em-none-eabihf
steps:
- uses: actions/checkout@v2
@ -23,8 +36,8 @@ jobs:
- uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --release --target=${{ matrix.target }}
command: check
args: --release --target=${{ matrix.target }} --no-default-features
fmt:
name: Rustfmt

View File

@ -12,17 +12,28 @@ categories = ["aerospace", "aerospace::space-protocols", "no-std", "hardware-sup
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
num = { version = "0.4", default-features = false }
serde = { version = "1.0.142", default-features = false, features = ["derive"] }
zerocopy = "0.6.1"
crc = "3.0.0"
delegate = "0.7.0"
chrono = { version = "0.4.20", default-features = false }
[dependencies.serde]
version = "1.0.142"
default-features = false
features = ["derive"]
[dependencies.chrono]
version = "0.4.20"
default-features = false
features = ["serde"]
[dependencies.num-traits]
version = "0.2"
default-features = false
[dev-dependencies.postcard]
version = "1.0.1"
[features]
default = ["alloc"]
std = ["chrono/std", "chrono/clock", "postcard/use-std"]
alloc = ["serde/alloc", "chrono/alloc", "postcard/alloc"]
default = ["std"]
std = ["chrono/std", "chrono/clock", "alloc"]
alloc = ["postcard/alloc"]

View File

@ -13,11 +13,21 @@ Currently, this includes the following components:
[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 implementations according to
[CCSDS CCSDS 301.0-B-4](https://public.ccsds.org/Pubs/301x0b4e1.pdf)
# Features
This package is suitable for `no_std` environments.
`spacepackets` supports various runtime environments and is also suitable
for suitable for `no_std` environments. It has several features which may be enabled
for disabled.
It features optional support for the [`alloc`](https://doc.rust-lang.org/alloc/) crate
and also offers support for [`serde`](https://serde.rs/). The Space Paccket, PUS TM and TC implementations
derive the `serde` `Serialize` and `Deserialize` trait. This allows serializing and
It also offers support for [`serde`](https://serde.rs/). The Space Paccket, PUS TM and TC
implementations derive the `serde` `Serialize` and `Deserialize` trait. This allows serializing and
deserializing them with an appropriate `serde` provider like
[`postcard`](https://github.com/jamesmunns/postcard).
Default features:
- [`std`] : Enables functionality relying on the standard library.
- [`alloc`] : (https://doc.rust-lang.org/alloc/): Enables features which operate on containers
like [`alloc::vec::Vec`](https://doc.rust-lang.org/beta/alloc/vec/struct.Vec.html).
Enabled by the `std` features.

View File

@ -24,13 +24,14 @@
//! println!("{:?}", sp_header);
//! ```
#![no_std]
#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
use crate::ecss::CCSDS_HEADER_LEN;
use delegate::delegate;
use serde::{Deserialize, Serialize};
pub mod ecss;
@ -121,7 +122,7 @@ impl PacketId {
/// not be set and false will be returned. The maximum allowed value for the 11-bit field is
/// 2047
pub fn set_apid(&mut self, apid: u16) -> bool {
if apid > num::pow(2, 11) - 1 {
if apid > 2u16.pow(11) - 1 {
return false;
}
self.apid = apid;
@ -168,7 +169,7 @@ impl PacketSequenceCtrl {
/// Set a new sequence count. If the passed number is invalid, the sequence count will not be
/// set and false will be returned. The maximum allowed value for the 14-bit field is 16383
pub fn set_seq_count(&mut self, ssc: u16) -> bool {
if ssc > num::pow(2, 14) - 1 {
if ssc > 2u16.pow(14) - 1 {
return false;
}
self.seq_count = ssc;
@ -325,7 +326,7 @@ impl SpHeader {
ssc: u16,
data_len: u16,
) -> Option<Self> {
if ssc > num::pow(2, 14) - 1 || apid > num::pow(2, 11) - 1 {
if ssc > 2u16.pow(14) - 1 || apid > 2u16.pow(11) - 1 {
return None;
}
let mut header = SpHeader::default();
@ -510,17 +511,21 @@ pub mod zc {
#[cfg(test)]
mod tests {
use crate::SpHeader;
use crate::{
packet_type_in_raw_packet_id, zc, CcsdsPacket, PacketId,
PacketSequenceCtrl, PacketType, SequenceFlags,
};
use alloc::vec;
use postcard::from_bytes;
#[cfg(feature = "std")]
use postcard::to_stdvec;
#[cfg(feature = "std")]
use crate::CcsdsPrimaryHeader;
use crate::SpHeader;
use crate::{
packet_type_in_raw_packet_id, zc, CcsdsPacket, PacketId, PacketSequenceCtrl, PacketType,
SequenceFlags,
};
use alloc::vec;
#[cfg(not(feature = "std"))]
use num::pow;
#[cfg(feature = "std")]
use num_traits::pow;
use postcard::from_bytes;
#[cfg(feature = "alloc")]
use postcard::to_allocvec;
#[test]
fn test_seq_flag_helpers() {
@ -593,7 +598,7 @@ mod tests {
let psc_from_raw = PacketSequenceCtrl::from(psc.raw());
assert_eq!(psc_from_raw, psc);
// Fails because SSC is limited to 14 bits
assert!(!psc.set_seq_count(num::pow(2, 15)));
assert!(!psc.set_seq_count(2u16.pow(15)));
assert_eq!(psc.raw(), 77);
let psc_invalid = PacketSequenceCtrl::new(SequenceFlags::FirstSegment, 0xFFFF);
@ -614,7 +619,7 @@ mod tests {
assert_eq!(sp_header.apid(), 0x42);
assert_eq!(sp_header.sequence_flags(), SequenceFlags::Unsegmented);
assert_eq!(sp_header.data_len(), 0);
let output = to_stdvec(&sp_header).unwrap();
let output = to_allocvec(&sp_header).unwrap();
let sp_header: SpHeader = from_bytes(&output).unwrap();
assert_eq!(sp_header.version, 0b000);
assert!(!sp_header.packet_id.sec_header_flag);
@ -679,8 +684,7 @@ mod tests {
fn test_zc_sph() {
use zerocopy::AsBytes;
let sp_header =
SpHeader::tc(0x7FF, num::pow(2, 14) - 1, 0).expect("Error creating SP header");
let sp_header = SpHeader::tc(0x7FF, pow(2, 14) - 1, 0).expect("Error creating SP header");
assert_eq!(sp_header.ptype(), PacketType::Tc);
assert_eq!(sp_header.apid(), 0x7FF);
assert_eq!(sp_header.data_len(), 0);

View File

@ -4,7 +4,7 @@ use chrono::{DateTime, TimeZone, Utc};
#[allow(unused_imports)]
#[cfg(not(feature = "std"))]
use num::traits::float::FloatCore;
use num_traits::float::FloatCore;
use crate::time::CcsdsTimeCodes::Cds;
#[cfg(feature = "std")]
@ -132,7 +132,7 @@ impl CdsShortTimeProvider {
unix_seconds: 0,
date_time: None,
};
Ok(provider.setup(unix_days_seconds as i64, ms_of_day.into()))
Ok(provider.setup(unix_days_seconds as i64, ms_of_day))
}
fn setup(mut self, unix_days_seconds: i64, ms_of_day: u64) -> Self {