Compare commits

..

1 Commits

Author SHA1 Message Date
72077505b7 Re-worked TMTC modules
All checks were successful
Rust/sat-rs/pipeline/pr-main This commit looks good
2024-04-15 23:48:10 +02:00
18 changed files with 85 additions and 76 deletions

View File

@@ -7,7 +7,7 @@ use std::{
use log::{info, warn};
use satrs::{
encoding::ccsds::{SpValidity, SpacePacketValidator},
encoding::ccsds::{SpacePacketValidation, SpacePacketValidator},
hal::std::tcp_server::{HandledConnectionHandler, ServerConfig, TcpSpacepacketsServer},
spacepackets::{CcsdsPacket, PacketId},
tmtc::{PacketSenderRaw, PacketSource},
@@ -25,14 +25,14 @@ impl SpacePacketValidator for SimplePacketValidator {
&self,
sp_header: &satrs::spacepackets::SpHeader,
_raw_buf: &[u8],
) -> satrs::encoding::ccsds::SpValidity {
) -> satrs::encoding::ccsds::SpacePacketValidation {
if self.valid_ids.contains(&sp_header.packet_id()) {
return SpValidity::Valid;
return SpacePacketValidation::Valid;
}
log::warn!("ignoring space packet with header {:?}", sp_header);
// We could perform a CRC check.. but lets keep this simple and assume that TCP ensures
// data integrity.
SpValidity::Skip
SpacePacketValidation::Ignore
}
}

View File

@@ -8,10 +8,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
# [unreleased]
# [v0.1.2] 2024-04-17
Allow `satrs-shared` from `v0.1.3` to `<v0.2`.
# [v0.1.1] 2024-02-17
- Bumped `spacepackets` to v0.10.0

View File

@@ -1,6 +1,6 @@
[package]
name = "satrs-mib"
version = "0.1.2"
version = "0.1.1"
edition = "2021"
rust-version = "1.61"
authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]
@@ -23,12 +23,13 @@ version = "1"
optional = true
[dependencies.satrs-shared]
version = ">=0.1.3, <0.2"
path = "../satrs-shared"
version = "0.1.3"
features = ["serde"]
[dependencies.satrs-mib-codegen]
path = "codegen"
version = "0.1.2"
version = "0.1.1"
[dependencies.serde]
version = "1"

View File

@@ -1,6 +1,6 @@
[package]
name = "satrs-mib-codegen"
version = "0.1.2"
version = "0.1.1"
edition = "2021"
description = "satrs-mib proc macro implementation"
homepage = "https://egit.irs.uni-stuttgart.de/rust/sat-rs"
@@ -28,7 +28,8 @@ features = ["full"]
trybuild = { version = "1", features = ["diff"] }
[dev-dependencies.satrs-shared]
version = ">=0.1.3, <0.2"
version = "0.1.3"
path = "../../satrs-shared"
[dev-dependencies.satrs-mib]
path = ".."

View File

@@ -8,10 +8,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
# [unreleased]
# [v0.1.3] 2024-04-16
Allow `spacepackets` range starting with v0.10 and v0.11.
# [v0.1.2] 2024-02-17
- Bumped `spacepackets` to v0.10.0 for `UnsignedEnum` trait change.

View File

@@ -18,7 +18,7 @@ default-features = false
optional = true
[dependencies.spacepackets]
version = ">0.9, <=0.11"
version = "0.11.0-rc.2"
default-features = false
[features]

View File

@@ -8,17 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
# [unreleased]
# [v0.2.0-rc.3] 2024-04-17
docs-rs hotfix 2
# [v0.2.0-rc.2] 2024-04-17
docs-rs hotfix
# [v0.2.0-rc.1] 2024-04-17
- `spacepackets` v0.11
- `spacepackets` v0.11.0
## Added

View File

@@ -1,8 +1,8 @@
[package]
name = "satrs"
version = "0.2.0-rc.3"
version = "0.2.0-rc.0"
edition = "2021"
rust-version = "1.71.1"
rust-version = "1.61"
authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]
description = "A framework to build software for remote systems"
homepage = "https://absatsw.irs.uni-stuttgart.de/projects/sat-rs/"
@@ -19,26 +19,13 @@ smallvec = "1"
crc = "3"
[dependencies.satrs-shared]
version = ">=0.1.3, <0.2"
version = "0.1.3"
path = "../satrs-shared"
[dependencies.num_enum]
version = ">0.5, <=0.7"
default-features = false
[dependencies.spacepackets]
version = "0.11"
default-features = false
[dependencies.cobs]
git = "https://github.com/robamu/cobs.rs.git"
version = "0.2.3"
branch = "all_features"
default-features = false
[dependencies.num-traits]
version = "0.2"
default-features = false
[dependencies.dyn-clone]
version = "1"
optional = true
@@ -51,6 +38,10 @@ optional = true
version = "0.7"
optional = true
[dependencies.num-traits]
version = "0.2"
default-features = false
[dependencies.downcast-rs]
version = "1.2"
default-features = false
@@ -84,6 +75,17 @@ version = "0.8"
features = ["os-poll", "net"]
optional = true
[dependencies.spacepackets]
# git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git"
version = "0.11.0-rc.2"
default-features = false
[dependencies.cobs]
git = "https://github.com/robamu/cobs.rs.git"
version = "0.2.3"
branch = "all_features"
default-features = false
[dev-dependencies]
serde = "1"
zerocopy = "0.7"
@@ -126,4 +128,4 @@ doc-images = []
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docs_rs", "--generate-link-to-definition"]
rustdoc-args = ["--cfg", "doc_cfg", "--generate-link-to-definition"]

View File

@@ -3,11 +3,11 @@ use spacepackets::{CcsdsPacket, SpHeader};
use crate::{tmtc::PacketSenderRaw, ComponentId};
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum SpValidity {
pub enum SpacePacketValidation {
Valid,
/// The space packet can be assumed to have a valid format, but the packet should
/// be skipped.
Skip,
/// be ignored.
Ignore,
/// The space packet or space packet header has an invalid format, for example a CRC check
/// failed. In that case, the parser loses the packet synchronization and needs to check for
/// the start of a new space packet header start again. The space packet header
@@ -18,7 +18,7 @@ pub enum SpValidity {
/// Simple trait to allow user code to check the validity of a space packet.
pub trait SpacePacketValidator {
fn validate(&self, sp_header: &SpHeader, raw_buf: &[u8]) -> SpValidity;
fn validate(&self, sp_header: &SpHeader, raw_buf: &[u8]) -> SpacePacketValidation;
}
/// This function parses a given buffer for tightly packed CCSDS space packets. It uses the
@@ -30,16 +30,13 @@ pub trait SpacePacketValidator {
/// If broken tail packets are detected, they are moved to the front of the buffer, and the write
/// index for future write operations will be written to the `next_write_idx` argument.
///
/// The parses will behave differently based on the [SpValidity] returned from the user provided
/// [SpacePacketValidator]:
/// The parser will forward all packets for which the user provided [SpacePacketValidator] returned
/// [SpacePacketValidation::Valid] to the given `packet_sender` and return the number of packets
/// found. If the [PacketSenderRaw::send_packet] calls fails, the error will be returned.
///
/// 1. [SpValidity::Valid]: The parser will forward all packets to the given `packet_sender` and
/// return the number of packets found.If the [PacketSenderRaw::send_packet] calls fails, the
/// error will be returned.
/// 2. [SpValidity::Invalid]: The parser assumes that the synchronization is lost and tries to
/// find the start of a new space packet header by scanning all the following bytes.
/// 3. [SpValidity::Skip]: The parser skips the packet using the packet length determined from the
/// space packet header.
/// If the user provided [SpacePacketValidator] returns [SpacePacketValidation::Invalid], the
/// parser assumes that the synchronization is lost and tries to find the start of a new space
/// packet header by scanning all the following bytes.
pub fn parse_buffer_for_ccsds_space_packets<SendError>(
buf: &mut [u8],
packet_validator: &(impl SpacePacketValidator + ?Sized),
@@ -58,7 +55,7 @@ pub fn parse_buffer_for_ccsds_space_packets<SendError>(
let sp_header = SpHeader::from_be_bytes(&buf[current_idx..]).unwrap().0;
// let packet_id = u16::from_be_bytes(buf[current_idx..current_idx + 2].try_into().unwrap());
match packet_validator.validate(&sp_header, &buf[current_idx..]) {
SpValidity::Valid => {
SpacePacketValidation::Valid => {
let packet_size = sp_header.total_len();
if (current_idx + packet_size) <= buf_len {
packet_sender
@@ -74,11 +71,11 @@ pub fn parse_buffer_for_ccsds_space_packets<SendError>(
current_idx += packet_size;
continue;
}
SpValidity::Skip => {
SpacePacketValidation::Ignore => {
current_idx += sp_header.total_len();
}
// We might have lost sync. Try to find the start of a new space packet header.
SpValidity::Invalid => {
SpacePacketValidation::Invalid => {
current_idx += 1;
}
}
@@ -95,7 +92,9 @@ mod tests {
use crate::{encoding::tests::TcCacher, ComponentId};
use super::{parse_buffer_for_ccsds_space_packets, SpValidity, SpacePacketValidator};
use super::{
parse_buffer_for_ccsds_space_packets, SpacePacketValidation, SpacePacketValidator,
};
const PARSER_ID: ComponentId = 0x05;
const TEST_APID_0: u16 = 0x02;
@@ -117,13 +116,13 @@ mod tests {
}
impl SpacePacketValidator for SimpleVerificator {
fn validate(&self, sp_header: &SpHeader, _raw_buf: &[u8]) -> super::SpValidity {
fn validate(&self, sp_header: &SpHeader, _raw_buf: &[u8]) -> super::SpacePacketValidation {
if sp_header.packet_id() == TEST_PACKET_ID_0
|| (self.enable_second_id && sp_header.packet_id() == TEST_PACKET_ID_1)
{
return SpValidity::Valid;
return SpacePacketValidation::Valid;
}
SpValidity::Skip
SpacePacketValidation::Ignore
}
}

View File

@@ -185,7 +185,7 @@ mod tests {
};
use crate::{
encoding::ccsds::{SpValidity, SpacePacketValidator},
encoding::ccsds::{SpacePacketValidation, SpacePacketValidator},
hal::std::tcp_server::{
tests::{ConnectionFinishedHandler, SyncTmSource},
ConnectionResult, ServerConfig,
@@ -207,12 +207,12 @@ mod tests {
pub struct SimpleValidator(pub HashSet<PacketId>);
impl SpacePacketValidator for SimpleValidator {
fn validate(&self, sp_header: &SpHeader, _raw_buf: &[u8]) -> SpValidity {
fn validate(&self, sp_header: &SpHeader, _raw_buf: &[u8]) -> SpacePacketValidation {
if self.0.contains(&sp_header.packet_id()) {
return SpValidity::Valid;
return SpacePacketValidation::Valid;
}
// Simple case: Assume that the interface always contains valid space packets.
SpValidity::Skip
SpacePacketValidation::Ignore
}
}

View File

@@ -7,9 +7,11 @@ use crate::{
use satrs_shared::res_code::ResultU16;
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
pub use std_mod::*;
#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
#[allow(unused_imports)]
pub use alloc_mod::*;
@@ -63,6 +65,7 @@ impl GenericActionReplyPus {
}
#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
pub mod alloc_mod {
use crate::{
action::ActionRequest,
@@ -124,6 +127,7 @@ pub mod alloc_mod {
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
pub mod std_mod {
use std::sync::mpsc;

View File

@@ -13,8 +13,10 @@ use crate::pus::verification::TcStateToken;
use crate::pus::EcssTmSender;
use crate::pus::EcssTmtcError;
#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
pub use alloc_mod::*;
#[cfg(feature = "heapless")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "heapless")))]
pub use heapless_mod::*;
/// This trait allows the PUS event manager implementation to stay generic over various types
@@ -42,6 +44,7 @@ pub mod heapless_mod {
use crate::events::LargestEventRaw;
use core::marker::PhantomData;
#[cfg_attr(doc_cfg, doc(cfg(feature = "heapless")))]
// TODO: After a new version of heapless is released which uses hash32 version 0.3, try using
// regular Event type again.
#[derive(Default)]

View File

@@ -368,6 +368,7 @@ pub mod alloc_mod {
/// [DynClone] allows cloning the trait object as long as the boxed object implements
/// [Clone].
#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
pub trait EcssTmSenderExt: EcssTmSender + Downcast + DynClone {
// Remove this once trait upcasting coercion has been implemented.
// Tracking issue: https://github.com/rust-lang/rust/issues/65991
@@ -408,6 +409,7 @@ pub mod alloc_mod {
/// [DynClone] allows cloning the trait object as long as the boxed object implements
/// [Clone].
#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
pub trait EcssTcSenderExt: EcssTcSender + Downcast + DynClone {}
/// Blanket implementation for all types which implement [EcssTcSender] and are clonable.
@@ -427,6 +429,7 @@ pub mod alloc_mod {
/// [DynClone] allows cloning the trait object as long as the boxed object implements
/// [Clone].
#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
pub trait EcssTcReceiverExt: EcssTcReceiver + Downcast {}
/// Blanket implementation for all types which implement [EcssTcReceiver] and are clonable.
@@ -548,6 +551,7 @@ pub mod alloc_mod {
>
{
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
pub fn new_from_now(
active_request_map: ActiveRequestMap,
fail_data_buf_size: usize,
@@ -634,6 +638,7 @@ pub mod alloc_mod {
/// Update the current time used for timeout checks based on the current OS time.
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
pub fn update_time_from_now(&mut self) -> Result<(), std::time::SystemTimeError> {
self.current_time = UnixTimestamp::from_now()?;
Ok(())
@@ -648,6 +653,7 @@ pub mod alloc_mod {
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
pub mod std_mod {
use crate::pool::{
PoolAddr, PoolError, PoolProvider, PoolProviderWithGuards, SharedStaticMemoryPool,

View File

@@ -26,9 +26,11 @@ pub enum Subservice {
}
#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
pub mod alloc_mod {}
#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
pub mod std_mod {}
#[cfg(test)]

View File

@@ -423,6 +423,7 @@ pub mod alloc_mod {
/// Like [Self::new], but sets the `init_current_time` parameter to the current system time.
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
pub fn new_with_current_init_time(time_margin: Duration) -> Result<Self, SystemTimeError> {
Ok(Self::new(UnixTime::now()?, time_margin))
}
@@ -666,6 +667,7 @@ pub mod alloc_mod {
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
pub fn update_time_from_now(&mut self) -> Result<(), SystemTimeError> {
self.current_time = UnixTime::now()?;
Ok(())

View File

@@ -98,11 +98,18 @@ pub use crate::seq_count::SeqCountProviderSimple;
pub use spacepackets::ecss::verification::*;
#[cfg(feature = "alloc")]
#[cfg_attr(feature = "doc_cfg", doc(cfg(feature = "alloc")))]
pub use alloc_mod::*;
use crate::request::Apid;
use crate::ComponentId;
/*
#[cfg(feature = "std")]
#[cfg_attr(feature = "doc_cfg", doc(cfg(feature = "std")))]
pub use std_mod::*;
*/
/// This is a request identifier as specified in 5.4.11.2 c. of the PUS standard.
///
/// This field equivalent to the first two bytes of the CCSDS space packet header.

View File

@@ -20,6 +20,7 @@ use spacepackets::{
ecss::{
tc::PusTcReader,
tm::{PusTmCreator, PusTmReader},
WritablePusPacket,
},
SpHeader,
};
@@ -225,7 +226,6 @@ pub mod std_mod {
#[cfg(feature = "crossbeam")]
use crossbeam_channel as cb;
use spacepackets::ecss::WritablePusPacket;
use thiserror::Error;
use crate::pool::PoolProvider;

View File

@@ -24,7 +24,7 @@ use std::{
use hashbrown::HashSet;
use satrs::{
encoding::{
ccsds::{SpValidity, SpacePacketValidator},
ccsds::{SpacePacketValidation, SpacePacketValidator},
cobs::encode_packet_with_cobs,
},
hal::std::tcp_server::{
@@ -205,11 +205,11 @@ impl SpacePacketValidator for SimpleVerificator {
&self,
sp_header: &SpHeader,
_raw_buf: &[u8],
) -> satrs::encoding::ccsds::SpValidity {
) -> satrs::encoding::ccsds::SpacePacketValidation {
if self.valid_ids.contains(&sp_header.packet_id()) {
return SpValidity::Valid;
return SpacePacketValidation::Valid;
}
SpValidity::Skip
SpacePacketValidation::Ignore
}
}