11 Commits

30 changed files with 265 additions and 251 deletions

View File

@ -1,7 +1,7 @@
<p align="center"> <img src="misc/satrs-logo-v2.png" width="40%"> </p> <p align="center"> <img src="misc/satrs-logo-v2.png" width="40%"> </p>
[![sat-rs website](https://img.shields.io/badge/sat--rs-website-darkgreen?style=flat)](https://absatsw.irs.uni-stuttgart.de/projects/sat-rs/) [![sat-rs website](https://img.shields.io/badge/sat--rs-website-darkgreen?style=flat)](https://absatsw.irs.uni-stuttgart.de/projects/sat-rs/)
[![sat-rs book](https://img.shields.io/badge/sat--rs-book-darkgreen?style=flat)](https://absatsw.irs.uni-stuttgart.de/projects/sat-rs/book/) [![sat-rs book](https://img.shields.io/badge/sat--rs-book-darkgreen?style=flat)](https://robamu.github.io/sat-rs/book/)
[![Crates.io](https://img.shields.io/crates/v/satrs)](https://crates.io/crates/satrs) [![Crates.io](https://img.shields.io/crates/v/satrs)](https://crates.io/crates/satrs)
[![docs.rs](https://img.shields.io/docsrs/satrs)](https://docs.rs/satrs) [![docs.rs](https://img.shields.io/docsrs/satrs)](https://docs.rs/satrs)
@ -11,7 +11,7 @@ sat-rs
This is the repository of the sat-rs library. Its primary goal is to provide re-usable components This is the repository of the sat-rs library. Its primary goal is to provide re-usable components
to write on-board software for remote systems like rovers or satellites. It is specifically written to write on-board software for remote systems like rovers or satellites. It is specifically written
for the special requirements for these systems. You can find an overview of the project and the for the special requirements for these systems. You can find an overview of the project and the
link to the [more high-level sat-rs book](https://absatsw.irs.uni-stuttgart.de/projects/sat-rs/) link to the [more high-level sat-rs book](https://robamu.github.io/sat-rs/book/)
at the [IRS software projects website](https://absatsw.irs.uni-stuttgart.de/projects/sat-rs/). at the [IRS software projects website](https://absatsw.irs.uni-stuttgart.de/projects/sat-rs/).
This is early-stage software. Important features are missing. New releases This is early-stage software. Important features are missing. New releases
@ -38,7 +38,7 @@ This project currently contains following crates:
Example of a simple example on-board software using various sat-rs components which can be run Example of a simple example on-board software using various sat-rs components which can be run
on a host computer or on any system with a standard runtime like a Raspberry Pi. on a host computer or on any system with a standard runtime like a Raspberry Pi.
* [`satrs-minisim`](https://egit.irs.uni-stuttgart.de/rust/sat-rs/src/branch/main/satrs-minisim): * [`satrs-minisim`](https://egit.irs.uni-stuttgart.de/rust/sat-rs/src/branch/main/satrs-minisim):
Mini-Simulator based on [asynchronix](https://github.com/asynchronics/asynchronix) which Mini-Simulator based on [nexosim](https://github.com/asynchronics/nexosim) which
simulates some physical devices for the `satrs-example` application device handlers. simulates some physical devices for the `satrs-example` application device handlers.
* [`satrs-mib`](https://egit.irs.uni-stuttgart.de/rust/sat-rs/src/branch/main/satrs-mib): * [`satrs-mib`](https://egit.irs.uni-stuttgart.de/rust/sat-rs/src/branch/main/satrs-mib):
Components to build a mission information base from the on-board software directly. Components to build a mission information base from the on-board software directly.

View File

@ -3,20 +3,20 @@
Software for space systems oftentimes has different requirements than the software for host Software for space systems oftentimes has different requirements than the software for host
systems or servers. Currently, most space systems are considered embedded systems. systems or servers. Currently, most space systems are considered embedded systems.
For these systems, the computation power and the available heap are the most important resources For these systems, the computation power and the available heap are important resources
which are constrained. This might make completeley heap based memory management schemes which which are also constrained. This might make completeley heap based memory management schemes which
are oftentimes used on host and server based systems unfeasable. Still, completely forbidding are oftentimes used on host and server based systems unfeasable. Still, completely forbidding
heap allocations might make software development unnecessarilly difficult, especially in a heap allocations might make software development unnecessarilly difficult, especially in a
time where the OBSW might be running on Linux based systems with hundreds of MBs of RAM. time where the OBSW might be running on Linux based systems with hundreds of MBs of RAM.
A useful pattern used commonly in space systems is to limit heap allocations to program A useful pattern commonly used in space systems is to limit heap allocations to program
initialization time and avoid frequent run-time allocations. This prevents issues like initialization time and avoid frequent run-time allocations. This prevents issues like
running out of memory (something even Rust can not protect from) or heap fragmentation on systems running out of memory (something even Rust can not protect from) or heap fragmentation on systems
without a MMU. without a MMU.
# Using pre-allocated pool structures # Using pre-allocated pool structures
A huge candidate for heap allocations is the TMTC and handling. TC, TMs and IPC data are all A candidate for heap allocations is the TMTC and handling. TC, TMs and IPC data are all
candidates where the data size might vary greatly. The regular solution for host systems candidates where the data size might vary greatly. The regular solution for host systems
might be to send around this data as a `Vec<u8>` until it is dropped. `sat-rs` provides might be to send around this data as a `Vec<u8>` until it is dropped. `sat-rs` provides
another solution to avoid run-time allocations by offering pre-allocated static another solution to avoid run-time allocations by offering pre-allocated static

View File

@ -29,7 +29,7 @@ fn main() {
let res = client.recv(&mut buf); let res = client.recv(&mut buf);
match res { match res {
Ok(_len) => { Ok(_len) => {
let (pus_tm, size) = PusTmReader::new(&buf, 7).expect("Parsing PUS TM failed"); let pus_tm = PusTmReader::new(&buf, 7).expect("Parsing PUS TM failed");
if pus_tm.service() == 17 && pus_tm.subservice() == 2 { if pus_tm.service() == 17 && pus_tm.subservice() == 2 {
println!("Received PUS Ping Reply TM[17,2]") println!("Received PUS Ping Reply TM[17,2]")
} else if pus_tm.service() == 1 { } else if pus_tm.service() == 1 {

View File

@ -281,9 +281,7 @@ mod tests {
.try_recv() .try_recv()
.expect("failed to receive TM packet"); .expect("failed to receive TM packet");
assert_eq!(tm_packet.sender_id, PUS_EVENT_MANAGEMENT.id()); assert_eq!(tm_packet.sender_id, PUS_EVENT_MANAGEMENT.id());
let tm_reader = PusTmReader::new(&tm_packet.packet, 7) let tm_reader = PusTmReader::new(&tm_packet.packet, 7).expect("failed to create TM reader");
.expect("failed to create TM reader")
.0;
assert_eq!(tm_reader.apid(), TEST_CREATOR_ID.apid); assert_eq!(tm_reader.apid(), TEST_CREATOR_ID.apid);
assert_eq!(tm_reader.user_data().len(), 4); assert_eq!(tm_reader.user_data().len(), 4);
let event_read_back = EventU32::from_be_bytes(tm_reader.user_data().try_into().unwrap()); let event_read_back = EventU32::from_be_bytes(tm_reader.user_data().try_into().unwrap());

View File

@ -367,7 +367,7 @@ mod tests {
if let Err(mpsc::TryRecvError::Empty) = packet { if let Err(mpsc::TryRecvError::Empty) = packet {
} else { } else {
let tm = packet.unwrap(); let tm = packet.unwrap();
let unexpected_tm = PusTmReader::new(&tm.packet, 7).unwrap().0; let unexpected_tm = PusTmReader::new(&tm.packet, 7).unwrap();
panic!("unexpected TM packet {unexpected_tm:?}"); panic!("unexpected TM packet {unexpected_tm:?}");
} }
} }
@ -410,7 +410,11 @@ mod tests {
pub fn add_tc(&mut self, tc: &PusTcCreator) { pub fn add_tc(&mut self, tc: &PusTcCreator) {
self.request_id = Some(verification::RequestId::new(tc).into()); self.request_id = Some(verification::RequestId::new(tc).into());
let token = self.service.service_helper.verif_reporter_mut().add_tc(tc); let token = self
.service
.service_helper
.verif_reporter_mut()
.start_verification(tc);
let accepted_token = self let accepted_token = self
.service .service
.service_helper .service_helper

View File

@ -109,8 +109,8 @@ impl PusTcDistributor {
// TODO: Shouldn't this be an error? // TODO: Shouldn't this be an error?
return Ok(HandlingStatus::HandledOne); return Ok(HandlingStatus::HandledOne);
} }
let pus_tc = pus_tc_result.unwrap().0; let pus_tc = pus_tc_result.unwrap();
let init_token = self.verif_reporter.add_tc(&pus_tc); let init_token = self.verif_reporter.start_verification(&pus_tc);
self.stamp_helper.update_from_now(); self.stamp_helper.update_from_now();
let accepted_token = self let accepted_token = self
.verif_reporter .verif_reporter
@ -599,7 +599,7 @@ pub(crate) mod tests {
) -> (verification::RequestId, ActivePusRequestStd) { ) -> (verification::RequestId, ActivePusRequestStd) {
let sp_header = SpHeader::new_from_apid(apid); let sp_header = SpHeader::new_from_apid(apid);
let sec_header_dummy = PusTcSecondaryHeader::new_simple(0, 0); let sec_header_dummy = PusTcSecondaryHeader::new_simple(0, 0);
let init = self.verif_reporter.add_tc(&PusTcCreator::new( let init = self.verif_reporter.start_verification(&PusTcCreator::new(
sp_header, sp_header,
sec_header_dummy, sec_header_dummy,
&[], &[],
@ -706,7 +706,7 @@ pub(crate) mod tests {
} }
pub fn add_tc(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted> { pub fn add_tc(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted> {
let token = self.verif_reporter.add_tc(tc); let token = self.verif_reporter.start_verification(tc);
self.current_request_id = Some(verification::RequestId::new(tc)); self.current_request_id = Some(verification::RequestId::new(tc));
self.current_packet = Some(tc.to_vec().unwrap()); self.current_packet = Some(tc.to_vec().unwrap());
self.verif_reporter self.verif_reporter
@ -734,7 +734,7 @@ pub(crate) mod tests {
let tc_reader = PusTcReader::new(&current_packet).unwrap(); let tc_reader = PusTcReader::new(&current_packet).unwrap();
let (active_info, request) = self.converter.convert( let (active_info, request) = self.converter.convert(
token, token,
&tc_reader.0, &tc_reader,
&self.dummy_sender, &self.dummy_sender,
&self.verif_reporter, &self.verif_reporter,
time_stamp, time_stamp,

View File

@ -90,7 +90,7 @@ impl DirectPusService for TestCustomServiceWrapper {
); );
} }
DirectPusPacketHandlerResult::CustomSubservice(subservice, token) => { DirectPusPacketHandlerResult::CustomSubservice(subservice, token) => {
let (tc, _) = PusTcReader::new( let tc = PusTcReader::new(
self.handler self.handler
.service_helper .service_helper
.tc_in_mem_converter .tc_in_mem_converter

View File

@ -24,6 +24,7 @@ optional = true
[dependencies.satrs-shared] [dependencies.satrs-shared]
version = ">=0.1.3, <=0.2" version = ">=0.1.3, <=0.2"
path = "../satrs-shared"
features = ["serde"] features = ["serde"]
[dependencies.satrs-mib-codegen] [dependencies.satrs-mib-codegen]

View File

@ -28,6 +28,7 @@ features = ["full"]
trybuild = { version = "1", features = ["diff"] } trybuild = { version = "1", features = ["diff"] }
[dev-dependencies.satrs-shared] [dev-dependencies.satrs-shared]
path = "../../satrs-shared"
version = ">=0.1.3, <=0.2" version = ">=0.1.3, <=0.2"
[dev-dependencies.satrs-mib] [dev-dependencies.satrs-mib]

View File

@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
# [unreleased] # [unreleased]
# [v0.2.2] 2025-05-10
- Bump to `spacepackests` v0.14
# [v0.2.1] 2024-11-15 # [v0.2.1] 2024-11-15
Increased allowed spacepackets to v0.13 Increased allowed spacepackets to v0.13
@ -41,3 +45,6 @@ Allow `spacepackets` range starting with v0.10 and v0.11.
# [v0.1.0] 2024-02-12 # [v0.1.0] 2024-02-12
Initial release. Initial release.
[unreleased]: https://egit.irs.uni-stuttgart.de/rust/sat-rs/compare/satrs-shared-v0.2.2...HEAD
[v0.2.2]: https://egit.irs.uni-stuttgart.de/rust/sat-rs/compare/satrs-shared-v0.2.1...satrs-shared-v0.2.2

View File

@ -1,7 +1,7 @@
[package] [package]
name = "satrs-shared" name = "satrs-shared"
description = "Components shared by multiple sat-rs crates" description = "Components shared by multiple sat-rs crates"
version = "0.2.1" version = "0.2.2"
edition = "2021" edition = "2021"
authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"] authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]
homepage = "https://absatsw.irs.uni-stuttgart.de/projects/sat-rs/" homepage = "https://absatsw.irs.uni-stuttgart.de/projects/sat-rs/"
@ -18,11 +18,11 @@ default-features = false
optional = true optional = true
[dependencies.defmt] [dependencies.defmt]
version = "0.3" version = "1"
optional = true optional = true
[dependencies.spacepackets] [dependencies.spacepackets]
version = ">0.9, <=0.13" version = "0.14"
default-features = false default-features = false
[features] [features]

View File

@ -13,16 +13,13 @@ keywords = ["no-std", "space", "aerospace"]
categories = ["aerospace", "aerospace::space-protocols", "no-std", "hardware-support", "embedded"] categories = ["aerospace", "aerospace::space-protocols", "no-std", "hardware-support", "embedded"]
[dependencies] [dependencies]
satrs-shared = ">=0.1.3, <=0.2" satrs-shared = { version = ">=0.1.3, <=0.2", path = "../satrs-shared" }
delegate = ">0.7, <=0.13" delegate = ">0.7, <=0.13"
paste = "1" paste = "1"
derive-new = ">=0.6, <=0.7" derive-new = ">=0.6, <=0.7"
smallvec = "1"
crc = "3"
num_enum = { version = ">0.5, <=0.7", default-features = false } num_enum = { version = ">0.5, <=0.7", default-features = false }
spacepackets = { version = "0.13", default-features = false } spacepackets = { version = "0.14", default-features = false }
cobs = { version = "0.3", default-features = false } cobs = { version = "0.4", default-features = false, git = "https://github.com/jamesmunns/cobs.rs.git", branch = "main" }
num-traits = { version = "0.2", default-features = false }
thiserror = { version = "2", default-features = false } thiserror = { version = "2", default-features = false }
hashbrown = { version = ">=0.14, <=0.15", optional = true } hashbrown = { version = ">=0.14, <=0.15", optional = true }

View File

@ -24,8 +24,8 @@ use cobs::{decode_in_place, encode, max_encoding_length};
/// assert!(encode_packet_with_cobs(&INVERTED_PACKET, &mut encoding_buf, &mut current_idx)); /// assert!(encode_packet_with_cobs(&INVERTED_PACKET, &mut encoding_buf, &mut current_idx));
/// assert_eq!(encoding_buf[0], 0); /// assert_eq!(encoding_buf[0], 0);
/// let dec_report = decode_in_place_report(&mut encoding_buf[1..]).expect("decoding failed"); /// let dec_report = decode_in_place_report(&mut encoding_buf[1..]).expect("decoding failed");
/// assert_eq!(encoding_buf[1 + dec_report.src_used], 0); /// assert_eq!(encoding_buf[1 + dec_report.parsed_size()], 0);
/// assert_eq!(dec_report.dst_used, 5); /// assert_eq!(dec_report.frame_size(), 5);
/// assert_eq!(current_idx, 16); /// assert_eq!(current_idx, 16);
/// ``` /// ```
pub fn encode_packet_with_cobs( pub fn encode_packet_with_cobs(

View File

@ -162,7 +162,7 @@ pub trait SenderMapProvider<
/// * `ListenerMap`: [ListenerMapProvider] which maps listener keys to channel IDs. /// * `ListenerMap`: [ListenerMapProvider] which maps listener keys to channel IDs.
/// * `EventSender`: [EventSendProvider] contained within the sender map which sends the events. /// * `EventSender`: [EventSendProvider] contained within the sender map which sends the events.
/// * `Event`: The event type. This type must implement the [GenericEvent]. Currently only [EventU32] /// * `Event`: The event type. This type must implement the [GenericEvent]. Currently only [EventU32]
/// and [EventU16] are supported. /// and [EventU16] are supported.
/// * `ParamProvider`: Auxiliary data which is sent with the event to provide optional context /// * `ParamProvider`: Auxiliary data which is sent with the event to provide optional context
/// information /// information
pub struct EventManager< pub struct EventManager<

View File

@ -312,11 +312,11 @@ impl EventU32 {
/// # Parameter /// # Parameter
/// ///
/// * `severity`: Each event has a [severity][Severity]. The raw value of the severity will /// * `severity`: Each event has a [severity][Severity]. The raw value of the severity will
/// be stored inside the uppermost 2 bits of the raw event ID /// be stored inside the uppermost 2 bits of the raw event ID
/// * `group_id`: Related events can be grouped using a group ID. The group ID will occupy the /// * `group_id`: Related events can be grouped using a group ID. The group ID will occupy the
/// next 14 bits after the severity. Therefore, the size is limited by dec 16383 hex 0x3FFF. /// next 14 bits after the severity. Therefore, the size is limited by dec 16383 hex 0x3FFF.
/// * `unique_id`: Each event has a unique 16 bit ID occupying the last 16 bits of the /// * `unique_id`: Each event has a unique 16 bit ID occupying the last 16 bits of the
/// raw event ID /// raw event ID
pub fn new_checked( pub fn new_checked(
severity: Severity, severity: Severity,
group_id: <Self as GenericEvent>::GroupId, group_id: <Self as GenericEvent>::GroupId,
@ -486,11 +486,11 @@ impl EventU16 {
/// # Parameter /// # Parameter
/// ///
/// * `severity`: Each event has a [severity][Severity]. The raw value of the severity will /// * `severity`: Each event has a [severity][Severity]. The raw value of the severity will
/// be stored inside the uppermost 2 bits of the raw event ID /// be stored inside the uppermost 2 bits of the raw event ID
/// * `group_id`: Related events can be grouped using a group ID. The group ID will occupy the /// * `group_id`: Related events can be grouped using a group ID. The group ID will occupy the
/// next 6 bits after the severity. Therefore, the size is limited by dec 63 hex 0x3F. /// next 6 bits after the severity. Therefore, the size is limited by dec 63 hex 0x3F.
/// * `unique_id`: Each event has a unique 8 bit ID occupying the last 8 bits of the /// * `unique_id`: Each event has a unique 8 bit ID occupying the last 8 bits of the
/// raw event ID /// raw event ID
pub fn new_checked( pub fn new_checked(
severity: Severity, severity: Severity,
group_id: <Self as GenericEvent>::GroupId, group_id: <Self as GenericEvent>::GroupId,

View File

@ -39,9 +39,9 @@ pub trait ExecutableWithType: Executable {
/// ///
/// * `executable`: Executable task /// * `executable`: Executable task
/// * `task_freq`: Optional frequency of task. Required for periodic and fixed cycle tasks. /// * `task_freq`: Optional frequency of task. Required for periodic and fixed cycle tasks.
/// If [None] is passed, no sleeping will be performed. /// If [None] is passed, no sleeping will be performed.
/// * `op_code`: Operation code which is passed to the executable task /// * `op_code`: Operation code which is passed to the executable task
/// [operation call][Executable::periodic_op] /// [operation call][Executable::periodic_op]
/// * `termination`: Optional termination handler which can cancel threads with a broadcast /// * `termination`: Optional termination handler which can cancel threads with a broadcast
pub fn exec_sched_single< pub fn exec_sched_single<
T: ExecutableWithType<Error = E> + Send + 'static + ?Sized, T: ExecutableWithType<Error = E> + Send + 'static + ?Sized,

View File

@ -150,9 +150,9 @@ impl<
/// ///
/// * `cfg` - Configuration of the server. /// * `cfg` - Configuration of the server.
/// * `tm_source` - Generic TM source used by the server to pull telemetry packets which are /// * `tm_source` - Generic TM source used by the server to pull telemetry packets which are
/// then sent back to the client. /// then sent back to the client.
/// * `tc_receiver` - Any received telecommands which were decoded successfully will be /// * `tc_receiver` - Any received telecommands which were decoded successfully will be
/// forwarded to this TC receiver. /// forwarded to this TC receiver.
pub fn new( pub fn new(
cfg: ServerConfig, cfg: ServerConfig,
tm_source: TmSource, tm_source: TmSource,
@ -377,13 +377,13 @@ mod tests {
current_idx += 1; current_idx += 1;
let mut dec_report = cobs::decode_in_place_report(&mut read_buf[current_idx..]) let mut dec_report = cobs::decode_in_place_report(&mut read_buf[current_idx..])
.expect("COBS decoding failed"); .expect("COBS decoding failed");
assert_eq!(dec_report.dst_used, 5); assert_eq!(dec_report.frame_size(), 5);
// Skip first sentinel byte. // Skip first sentinel byte.
assert_eq!( assert_eq!(
&read_buf[current_idx..current_idx + INVERTED_PACKET.len()], &read_buf[current_idx..current_idx + INVERTED_PACKET.len()],
&INVERTED_PACKET &INVERTED_PACKET
); );
current_idx += dec_report.src_used; current_idx += dec_report.parsed_size();
// End sentinel. // End sentinel.
assert_eq!(read_buf[current_idx], 0, "invalid sentinel end byte"); assert_eq!(read_buf[current_idx], 0, "invalid sentinel end byte");
current_idx += 1; current_idx += 1;
@ -393,13 +393,13 @@ mod tests {
current_idx += 1; current_idx += 1;
dec_report = cobs::decode_in_place_report(&mut read_buf[current_idx..]) dec_report = cobs::decode_in_place_report(&mut read_buf[current_idx..])
.expect("COBS decoding failed"); .expect("COBS decoding failed");
assert_eq!(dec_report.dst_used, 5); assert_eq!(dec_report.frame_size(), 5);
// Skip first sentinel byte. // Skip first sentinel byte.
assert_eq!( assert_eq!(
&read_buf[current_idx..current_idx + SIMPLE_PACKET.len()], &read_buf[current_idx..current_idx + SIMPLE_PACKET.len()],
&SIMPLE_PACKET &SIMPLE_PACKET
); );
current_idx += dec_report.src_used; current_idx += dec_report.parsed_size();
// End sentinel. // End sentinel.
assert_eq!(read_buf[current_idx], 0); assert_eq!(read_buf[current_idx], 0);
break; break;

View File

@ -25,22 +25,22 @@ pub use crate::hal::std::tcp_spacepackets_server::{SpacepacketsTmSender, TcpSpac
/// ///
/// * `addr` - Address of the TCP server. /// * `addr` - Address of the TCP server.
/// * `inner_loop_delay` - If a client connects for a longer period, but no TC is received or /// * `inner_loop_delay` - If a client connects for a longer period, but no TC is received or
/// no TM needs to be sent, the TCP server will delay for the specified amount of time /// no TM needs to be sent, the TCP server will delay for the specified amount of time
/// to reduce CPU load. /// to reduce CPU load.
/// * `tm_buffer_size` - Size of the TM buffer used to read TM from the [PacketSource] and /// * `tm_buffer_size` - Size of the TM buffer used to read TM from the [PacketSource] and
/// encoding of that data. This buffer should at large enough to hold the maximum expected /// encoding of that data. This buffer should at large enough to hold the maximum expected
/// TM size read from the packet source. /// TM size read from the packet source.
/// * `tc_buffer_size` - Size of the TC buffer used to read encoded telecommands sent from /// * `tc_buffer_size` - Size of the TC buffer used to read encoded telecommands sent from
/// the client. It is recommended to make this buffer larger to allow reading multiple /// the client. It is recommended to make this buffer larger to allow reading multiple
/// consecutive packets as well, for example by using common buffer sizes like 4096 or 8192 /// consecutive packets as well, for example by using common buffer sizes like 4096 or 8192
/// byte. The buffer should at the very least be large enough to hold the maximum expected /// byte. The buffer should at the very least be large enough to hold the maximum expected
/// telecommand size. /// telecommand size.
/// * `reuse_addr` - Can be used to set the `SO_REUSEADDR` option on the raw socket. This is /// * `reuse_addr` - Can be used to set the `SO_REUSEADDR` option on the raw socket. This is
/// especially useful if the address and port are static for the server. Set to false by /// especially useful if the address and port are static for the server. Set to false by
/// default. /// default.
/// * `reuse_port` - Can be used to set the `SO_REUSEPORT` option on the raw socket. This is /// * `reuse_port` - Can be used to set the `SO_REUSEPORT` option on the raw socket. This is
/// especially useful if the address and port are static for the server. Set to false by /// especially useful if the address and port are static for the server. Set to false by
/// default. /// default.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct ServerConfig { pub struct ServerConfig {
pub id: ComponentId, pub id: ComponentId,
@ -211,12 +211,12 @@ impl<
/// ///
/// * `cfg` - Configuration of the server. /// * `cfg` - Configuration of the server.
/// * `tc_parser` - Parser which extracts telecommands from the raw bytestream received from /// * `tc_parser` - Parser which extracts telecommands from the raw bytestream received from
/// the client. /// the client.
/// * `tm_sender` - Sends back telemetry to the client using the specified TM source. /// * `tm_sender` - Sends back telemetry to the client using the specified TM source.
/// * `tm_source` - Generic TM source used by the server to pull telemetry packets which are /// * `tm_source` - Generic TM source used by the server to pull telemetry packets which are
/// then sent back to the client. /// then sent back to the client.
/// * `tc_sender` - Any received telecommand which was decoded successfully will be forwarded /// * `tc_sender` - Any received telecommand which was decoded successfully will be forwarded
/// using this TC sender. /// using this TC sender.
/// * `stop_signal` - Can be used to stop the server even if a connection is ongoing. /// * `stop_signal` - Can be used to stop the server even if a connection is ongoing.
pub fn new( pub fn new(
cfg: ServerConfig, cfg: ServerConfig,

View File

@ -120,15 +120,15 @@ impl<
/// ///
/// * `cfg` - Configuration of the server. /// * `cfg` - Configuration of the server.
/// * `tm_source` - Generic TM source used by the server to pull telemetry packets which are /// * `tm_source` - Generic TM source used by the server to pull telemetry packets which are
/// then sent back to the client. /// then sent back to the client.
/// * `tc_sender` - Any received telecommands which were decoded successfully will be /// * `tc_sender` - Any received telecommands which were decoded successfully will be
/// forwarded using this [PacketSenderRaw]. /// forwarded using this [PacketSenderRaw].
/// * `validator` - Used to determine the space packets relevant for further processing and /// * `validator` - Used to determine the space packets relevant for further processing and
/// to detect broken space packets. /// to detect broken space packets.
/// * `handled_connection_hook` - Called to notify the user about a succesfully handled /// * `handled_connection_hook` - Called to notify the user about a succesfully handled
/// connection. /// connection.
/// * `stop_signal` - Can be used to shut down the TCP server even for longer running /// * `stop_signal` - Can be used to shut down the TCP server even for longer running
/// connections. /// connections.
pub fn new( pub fn new(
cfg: ServerConfig, cfg: ServerConfig,
tm_source: TmSource, tm_source: TmSource,

View File

@ -770,11 +770,11 @@ mod alloc_mod {
/// # Parameters /// # Parameters
/// ///
/// * `cfg` - Vector of tuples which represent a subpool. The first entry in the tuple specifies /// * `cfg` - Vector of tuples which represent a subpool. The first entry in the tuple specifies
/// the number of memory blocks in the subpool, the second entry the size of the blocks /// the number of memory blocks in the subpool, the second entry the size of the blocks
/// * `spill_to_higher_subpools` - Specifies whether data will be spilled to higher subpools /// * `spill_to_higher_subpools` - Specifies whether data will be spilled to higher subpools
/// if the next fitting subpool is full. This is useful to ensure the pool remains useful /// if the next fitting subpool is full. This is useful to ensure the pool remains useful
/// for all data sizes as long as possible. However, an undesirable side-effect might be /// for all data sizes as long as possible. However, an undesirable side-effect might be
/// the chocking of larger subpools by underdimensioned smaller subpools. /// the chocking of larger subpools by underdimensioned smaller subpools.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct StaticPoolConfig { pub struct StaticPoolConfig {
cfg: Vec<SubpoolConfig>, cfg: Vec<SubpoolConfig>,

View File

@ -409,7 +409,7 @@ mod tests {
assert!(res.event_was_enabled); assert!(res.event_was_enabled);
assert!(res.params_were_propagated); assert!(res.params_were_propagated);
let event_tm = event_rx.try_recv().expect("no event received"); let event_tm = event_rx.try_recv().expect("no event received");
let (tm, _) = PusTmReader::new(&event_tm.packet, 7).expect("reading TM failed"); let tm = PusTmReader::new(&event_tm.packet, 7).expect("reading TM failed");
assert_eq!(tm.service(), 5); assert_eq!(tm.service(), 5);
assert_eq!(tm.subservice(), Subservice::TmInfoReport as u8); assert_eq!(tm.subservice(), Subservice::TmInfoReport as u8);
assert_eq!(tm.user_data().len(), 4 + param_data.len()); assert_eq!(tm.user_data().len(), 4 + param_data.len());
@ -437,7 +437,7 @@ mod tests {
assert!(res.event_was_enabled); assert!(res.event_was_enabled);
assert!(res.params_were_propagated); assert!(res.params_were_propagated);
let event_tm = event_rx.try_recv().expect("no event received"); let event_tm = event_rx.try_recv().expect("no event received");
let (tm, _) = PusTmReader::new(&event_tm.packet, 7).expect("reading TM failed"); let tm = PusTmReader::new(&event_tm.packet, 7).expect("reading TM failed");
assert_eq!(tm.service(), 5); assert_eq!(tm.service(), 5);
assert_eq!(tm.subservice(), Subservice::TmInfoReport as u8); assert_eq!(tm.subservice(), Subservice::TmInfoReport as u8);
assert_eq!(tm.user_data().len(), 4 + param_data.len()); assert_eq!(tm.user_data().len(), 4 + param_data.len());

View File

@ -199,8 +199,12 @@ mod tests {
} }
impl PusTestHarness for Pus5HandlerWithStoreTester { impl PusTestHarness for Pus5HandlerWithStoreTester {
fn init_verification(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted> { fn start_verification(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted> {
let init_token = self.handler.service_helper.verif_reporter_mut().add_tc(tc); let init_token = self
.handler
.service_helper
.verif_reporter_mut()
.start_verification(tc);
self.handler self.handler
.service_helper .service_helper
.verif_reporter() .verif_reporter()
@ -245,7 +249,7 @@ mod tests {
.write_to_be_bytes(&mut app_data) .write_to_be_bytes(&mut app_data)
.expect("writing test event failed"); .expect("writing test event failed");
let ping_tc = PusTcCreator::new(sp_header, sec_header, &app_data, true); let ping_tc = PusTcCreator::new(sp_header, sec_header, &app_data, true);
let token = test_harness.init_verification(&ping_tc); let token = test_harness.start_verification(&ping_tc);
test_harness.send_tc(&token, &ping_tc); test_harness.send_tc(&token, &ping_tc);
let request_id = token.request_id(); let request_id = token.request_id();
test_harness.handle_one_tc().unwrap(); test_harness.handle_one_tc().unwrap();
@ -306,7 +310,7 @@ mod tests {
let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, 0, 0); let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, 0, 0);
let sec_header = PusTcSecondaryHeader::new_simple(5, 200); let sec_header = PusTcSecondaryHeader::new_simple(5, 200);
let ping_tc = PusTcCreator::new_no_app_data(sp_header, sec_header, true); let ping_tc = PusTcCreator::new_no_app_data(sp_header, sec_header, true);
let token = test_harness.init_verification(&ping_tc); let token = test_harness.start_verification(&ping_tc);
test_harness.send_tc(&token, &ping_tc); test_harness.send_tc(&token, &ping_tc);
let result = test_harness.handle_one_tc(); let result = test_harness.handle_one_tc();
assert!(result.is_ok()); assert!(result.is_ok());
@ -326,7 +330,7 @@ mod tests {
let sec_header = let sec_header =
PusTcSecondaryHeader::new_simple(5, Subservice::TcEnableEventGeneration as u8); PusTcSecondaryHeader::new_simple(5, Subservice::TcEnableEventGeneration as u8);
let ping_tc = PusTcCreator::new(sp_header, sec_header, &[0, 1, 2], true); let ping_tc = PusTcCreator::new(sp_header, sec_header, &[0, 1, 2], true);
let token = test_harness.init_verification(&ping_tc); let token = test_harness.start_verification(&ping_tc);
test_harness.send_tc(&token, &ping_tc); test_harness.send_tc(&token, &ping_tc);
let result = test_harness.handle_one_tc(); let result = test_harness.handle_one_tc();
assert!(result.is_err()); assert!(result.is_err());

View File

@ -959,15 +959,11 @@ pub mod std_mod {
possible_packet: &TcInMemory, possible_packet: &TcInMemory,
) -> Result<PusTcReader<'_>, PusTcFromMemError> { ) -> Result<PusTcReader<'_>, PusTcFromMemError> {
self.cache(possible_packet)?; self.cache(possible_packet)?;
Ok(PusTcReader::new(self.tc_slice_raw()) Ok(PusTcReader::new(self.tc_slice_raw()).map_err(EcssTmtcError::Pus)?)
.map_err(EcssTmtcError::Pus)?
.0)
} }
fn convert(&self) -> Result<PusTcReader<'_>, PusTcFromMemError> { fn convert(&self) -> Result<PusTcReader<'_>, PusTcFromMemError> {
Ok(PusTcReader::new(self.tc_slice_raw()) Ok(PusTcReader::new(self.tc_slice_raw()).map_err(EcssTmtcError::Pus)?)
.map_err(EcssTmtcError::Pus)?
.0)
} }
} }
@ -1279,7 +1275,7 @@ pub mod test_util {
UniqueApidTargetId::new(TEST_APID, TEST_UNIQUE_ID_1); UniqueApidTargetId::new(TEST_APID, TEST_UNIQUE_ID_1);
pub trait PusTestHarness { pub trait PusTestHarness {
fn init_verification(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted>; fn start_verification(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted>;
fn send_tc(&self, token: &VerificationToken<TcStateAccepted>, tc: &PusTcCreator); fn send_tc(&self, token: &VerificationToken<TcStateAccepted>, tc: &PusTcCreator);
fn read_next_tm(&mut self) -> PusTmReader<'_>; fn read_next_tm(&mut self) -> PusTmReader<'_>;
fn check_no_tm_available(&self) -> bool; fn check_no_tm_available(&self) -> bool;
@ -1459,7 +1455,7 @@ pub mod tests {
let tm_pool = self.tm_pool.0.read().unwrap(); let tm_pool = self.tm_pool.0.read().unwrap();
let tm_raw = tm_pool.read_as_vec(&tm_in_pool.store_addr).unwrap(); let tm_raw = tm_pool.read_as_vec(&tm_in_pool.store_addr).unwrap();
self.tm_buf[0..tm_raw.len()].copy_from_slice(&tm_raw); self.tm_buf[0..tm_raw.len()].copy_from_slice(&tm_raw);
PusTmReader::new(&self.tm_buf, 7).unwrap().0 PusTmReader::new(&self.tm_buf, 7).unwrap()
} }
pub fn check_no_tm_available(&self) -> bool { pub fn check_no_tm_available(&self) -> bool {
@ -1476,7 +1472,7 @@ pub mod tests {
let tm_in_pool = next_msg.unwrap(); let tm_in_pool = next_msg.unwrap();
let tm_pool = self.tm_pool.0.read().unwrap(); let tm_pool = self.tm_pool.0.read().unwrap();
let tm_raw = tm_pool.read_as_vec(&tm_in_pool.store_addr).unwrap(); let tm_raw = tm_pool.read_as_vec(&tm_in_pool.store_addr).unwrap();
let tm = PusTmReader::new(&tm_raw, 7).unwrap().0; let tm = PusTmReader::new(&tm_raw, 7).unwrap();
assert_eq!(PusPacket::service(&tm), 1); assert_eq!(PusPacket::service(&tm), 1);
assert_eq!(PusPacket::subservice(&tm), subservice); assert_eq!(PusPacket::subservice(&tm), subservice);
assert_eq!(tm.apid(), TEST_APID); assert_eq!(tm.apid(), TEST_APID);
@ -1584,9 +1580,7 @@ pub mod tests {
let next_msg = self.tm_receiver.try_recv(); let next_msg = self.tm_receiver.try_recv();
assert!(next_msg.is_ok()); assert!(next_msg.is_ok());
self.current_tm = Some(next_msg.unwrap().packet); self.current_tm = Some(next_msg.unwrap().packet);
PusTmReader::new(self.current_tm.as_ref().unwrap(), 7) PusTmReader::new(self.current_tm.as_ref().unwrap(), 7).unwrap()
.unwrap()
.0
} }
pub fn check_no_tm_available(&self) -> bool { pub fn check_no_tm_available(&self) -> bool {
@ -1601,7 +1595,7 @@ pub mod tests {
let next_msg = self.tm_receiver.try_recv(); let next_msg = self.tm_receiver.try_recv();
assert!(next_msg.is_ok()); assert!(next_msg.is_ok());
let next_msg = next_msg.unwrap(); let next_msg = next_msg.unwrap();
let tm = PusTmReader::new(next_msg.packet.as_slice(), 7).unwrap().0; let tm = PusTmReader::new(next_msg.packet.as_slice(), 7).unwrap();
assert_eq!(PusPacket::service(&tm), 1); assert_eq!(PusPacket::service(&tm), 1);
assert_eq!(PusPacket::subservice(&tm), subservice); assert_eq!(PusPacket::subservice(&tm), subservice);
assert_eq!(tm.apid(), TEST_APID); assert_eq!(tm.apid(), TEST_APID);

View File

@ -292,10 +292,10 @@ pub trait PusSchedulerProvider {
pool: &mut (impl PoolProvider + ?Sized), pool: &mut (impl PoolProvider + ?Sized),
) -> Result<TcInfo, ScheduleError> { ) -> Result<TcInfo, ScheduleError> {
let check_tc = PusTcReader::new(tc)?; let check_tc = PusTcReader::new(tc)?;
if PusPacket::service(&check_tc.0) == 11 && PusPacket::subservice(&check_tc.0) == 4 { if PusPacket::service(&check_tc) == 11 && PusPacket::subservice(&check_tc) == 4 {
return Err(ScheduleError::NestedScheduledTc); return Err(ScheduleError::NestedScheduledTc);
} }
let req_id = RequestId::from_tc(&check_tc.0); let req_id = RequestId::from_tc(&check_tc);
match pool.add(tc) { match pool.add(tc) {
Ok(addr) => { Ok(addr) => {
@ -411,10 +411,10 @@ pub mod alloc_mod {
/// ///
/// * `init_current_time` - The time to initialize the scheduler with. /// * `init_current_time` - The time to initialize the scheduler with.
/// * `time_margin` - This time margin is used when inserting new telecommands into the /// * `time_margin` - This time margin is used when inserting new telecommands into the
/// schedule. If the release time of a new telecommand is earlier than the time margin /// schedule. If the release time of a new telecommand is earlier than the time margin
/// added to the current time, it will not be inserted into the schedule. /// added to the current time, it will not be inserted into the schedule.
/// * `tc_buf_size` - Buffer for temporary storage of telecommand packets. This buffer /// * `tc_buf_size` - Buffer for temporary storage of telecommand packets. This buffer
/// should be large enough to accomodate the largest expected TC packets. /// should be large enough to accomodate the largest expected TC packets.
pub fn new(init_current_time: UnixTime, time_margin: Duration) -> Self { pub fn new(init_current_time: UnixTime, time_margin: Duration) -> Self {
PusScheduler { PusScheduler {
tc_map: Default::default(), tc_map: Default::default(),
@ -480,10 +480,10 @@ pub mod alloc_mod {
pool: &mut (impl PoolProvider + ?Sized), pool: &mut (impl PoolProvider + ?Sized),
) -> Result<TcInfo, ScheduleError> { ) -> Result<TcInfo, ScheduleError> {
let check_tc = PusTcReader::new(tc)?; let check_tc = PusTcReader::new(tc)?;
if PusPacket::service(&check_tc.0) == 11 && PusPacket::subservice(&check_tc.0) == 4 { if PusPacket::service(&check_tc) == 11 && PusPacket::subservice(&check_tc) == 4 {
return Err(ScheduleError::NestedScheduledTc); return Err(ScheduleError::NestedScheduledTc);
} }
let req_id = RequestId::from_tc(&check_tc.0); let req_id = RequestId::from_tc(&check_tc);
match pool.add(tc) { match pool.add(tc) {
Ok(addr) => { Ok(addr) => {
@ -683,10 +683,10 @@ pub mod alloc_mod {
/// # Arguments /// # Arguments
/// ///
/// * `releaser` - Closure where the first argument is whether the scheduler is enabled and /// * `releaser` - Closure where the first argument is whether the scheduler is enabled and
/// the second argument is the telecommand information also containing the store /// the second argument is the telecommand information also containing the store
/// address. This closure should return whether the command should be deleted. Please /// address. This closure should return whether the command should be deleted. Please
/// note that returning false might lead to memory leaks if the TC is not cleared from /// note that returning false might lead to memory leaks if the TC is not cleared from
/// the store in some other way. /// the store in some other way.
/// * `tc_store` - The holding store of the telecommands. /// * `tc_store` - The holding store of the telecommands.
/// * `tc_buf` - Buffer to hold each telecommand being released. /// * `tc_buf` - Buffer to hold each telecommand being released.
pub fn release_telecommands_with_buffer<R: FnMut(bool, &TcInfo, &[u8]) -> bool>( pub fn release_telecommands_with_buffer<R: FnMut(bool, &TcInfo, &[u8]) -> bool>(
@ -1313,7 +1313,7 @@ mod tests {
let mut read_buf: [u8; 64] = [0; 64]; let mut read_buf: [u8; 64] = [0; 64];
pool.read(&tc_info_0.addr(), &mut read_buf).unwrap(); pool.read(&tc_info_0.addr(), &mut read_buf).unwrap();
let check_tc = PusTcReader::new(&read_buf).expect("incorrect Pus tc raw data"); let check_tc = PusTcReader::new(&read_buf).expect("incorrect Pus tc raw data");
assert_eq!(check_tc.0, base_ping_tc_simple_ctor(0, &[])); assert_eq!(check_tc, base_ping_tc_simple_ctor(0, &[]));
assert_eq!(scheduler.num_scheduled_telecommands(), 1); assert_eq!(scheduler.num_scheduled_telecommands(), 1);
@ -1335,8 +1335,8 @@ mod tests {
let read_len = pool.read(&addr_vec[0], &mut read_buf).unwrap(); let read_len = pool.read(&addr_vec[0], &mut read_buf).unwrap();
let check_tc = PusTcReader::new(&read_buf).expect("incorrect Pus tc raw data"); let check_tc = PusTcReader::new(&read_buf).expect("incorrect Pus tc raw data");
assert_eq!(read_len, check_tc.1); assert_eq!(read_len, check_tc.total_len());
assert_eq!(check_tc.0, base_ping_tc_simple_ctor(0, &[])); assert_eq!(check_tc, base_ping_tc_simple_ctor(0, &[]));
} }
#[test] #[test]
@ -1362,8 +1362,8 @@ mod tests {
let read_len = pool.read(&info.addr, &mut buf).unwrap(); let read_len = pool.read(&info.addr, &mut buf).unwrap();
let check_tc = PusTcReader::new(&buf).expect("incorrect Pus tc raw data"); let check_tc = PusTcReader::new(&buf).expect("incorrect Pus tc raw data");
assert_eq!(read_len, check_tc.1); assert_eq!(read_len, check_tc.total_len());
assert_eq!(check_tc.0, base_ping_tc_simple_ctor(0, &[])); assert_eq!(check_tc, base_ping_tc_simple_ctor(0, &[]));
assert_eq!(scheduler.num_scheduled_telecommands(), 1); assert_eq!(scheduler.num_scheduled_telecommands(), 1);
@ -1387,8 +1387,8 @@ mod tests {
let read_len = pool.read(&addr_vec[0], &mut buf).unwrap(); let read_len = pool.read(&addr_vec[0], &mut buf).unwrap();
let check_tc = PusTcReader::new(&buf).expect("incorrect PUS tc raw data"); let check_tc = PusTcReader::new(&buf).expect("incorrect PUS tc raw data");
assert_eq!(read_len, check_tc.1); assert_eq!(read_len, check_tc.total_len());
assert_eq!(check_tc.0, base_ping_tc_simple_ctor(0, &[])); assert_eq!(check_tc, base_ping_tc_simple_ctor(0, &[]));
} }
#[test] #[test]
@ -2031,7 +2031,7 @@ mod tests {
assert_eq!(n, 1); assert_eq!(n, 1);
let time_reader = cds::CdsTime::from_bytes_with_u16_days(&buf[2..2 + 7]).unwrap(); let time_reader = cds::CdsTime::from_bytes_with_u16_days(&buf[2..2 + 7]).unwrap();
assert_eq!(time_reader, time_writer); assert_eq!(time_reader, time_writer);
let pus_tc_reader = PusTcReader::new(&buf[9..]).unwrap().0; let pus_tc_reader = PusTcReader::new(&buf[9..]).unwrap();
assert_eq!(pus_tc_reader, ping_tc); assert_eq!(pus_tc_reader, ping_tc);
} }

View File

@ -309,8 +309,12 @@ mod tests {
} }
impl PusTestHarness for Pus11HandlerWithStoreTester { impl PusTestHarness for Pus11HandlerWithStoreTester {
fn init_verification(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted> { fn start_verification(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted> {
let init_token = self.handler.service_helper.verif_reporter_mut().add_tc(tc); let init_token = self
.handler
.service_helper
.verif_reporter_mut()
.start_verification(tc);
self.handler self.handler
.service_helper .service_helper
.verif_reporter() .verif_reporter()
@ -383,7 +387,7 @@ mod tests {
let reply_header = SpHeader::new_for_unseg_tm(TEST_APID, 0, 0); let reply_header = SpHeader::new_for_unseg_tm(TEST_APID, 0, 0);
let tc_header = PusTcSecondaryHeader::new_simple(11, subservice as u8); let tc_header = PusTcSecondaryHeader::new_simple(11, subservice as u8);
let enable_scheduling = PusTcCreator::new(reply_header, tc_header, &[0; 7], true); let enable_scheduling = PusTcCreator::new(reply_header, tc_header, &[0; 7], true);
let token = test_harness.init_verification(&enable_scheduling); let token = test_harness.start_verification(&enable_scheduling);
test_harness.send_tc(&token, &enable_scheduling); test_harness.send_tc(&token, &enable_scheduling);
let request_id = token.request_id(); let request_id = token.request_id();
@ -445,7 +449,7 @@ mod tests {
&sched_app_data[..written_len], &sched_app_data[..written_len],
true, true,
); );
let token = test_harness.init_verification(&enable_scheduling); let token = test_harness.start_verification(&enable_scheduling);
test_harness.send_tc(&token, &enable_scheduling); test_harness.send_tc(&token, &enable_scheduling);
let request_id = token.request_id(); let request_id = token.request_id();

View File

@ -180,8 +180,12 @@ mod tests {
} }
impl PusTestHarness for Pus17HandlerWithStoreTester { impl PusTestHarness for Pus17HandlerWithStoreTester {
fn init_verification(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted> { fn start_verification(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted> {
let init_token = self.handler.service_helper.verif_reporter_mut().add_tc(tc); let init_token = self
.handler
.service_helper
.verif_reporter_mut()
.start_verification(tc);
self.handler self.handler
.service_helper .service_helper
.verif_reporter() .verif_reporter()
@ -238,8 +242,12 @@ mod tests {
} }
impl PusTestHarness for Pus17HandlerWithVecTester { impl PusTestHarness for Pus17HandlerWithVecTester {
fn init_verification(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted> { fn start_verification(&mut self, tc: &PusTcCreator) -> VerificationToken<TcStateAccepted> {
let init_token = self.handler.service_helper.verif_reporter_mut().add_tc(tc); let init_token = self
.handler
.service_helper
.verif_reporter_mut()
.start_verification(tc);
self.handler self.handler
.service_helper .service_helper
.verif_reporter() .verif_reporter()
@ -279,7 +287,7 @@ mod tests {
let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, 0, 0); let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, 0, 0);
let sec_header = PusTcSecondaryHeader::new_simple(17, 1); let sec_header = PusTcSecondaryHeader::new_simple(17, 1);
let ping_tc = PusTcCreator::new_no_app_data(sp_header, sec_header, true); let ping_tc = PusTcCreator::new_no_app_data(sp_header, sec_header, true);
let token = test_harness.init_verification(&ping_tc); let token = test_harness.start_verification(&ping_tc);
test_harness.send_tc(&token, &ping_tc); test_harness.send_tc(&token, &ping_tc);
let request_id = token.request_id(); let request_id = token.request_id();
let result = test_harness.handle_one_tc(); let result = test_harness.handle_one_tc();
@ -334,7 +342,7 @@ mod tests {
let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, 0, 0); let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, 0, 0);
let sec_header = PusTcSecondaryHeader::new_simple(3, 1); let sec_header = PusTcSecondaryHeader::new_simple(3, 1);
let ping_tc = PusTcCreator::new_no_app_data(sp_header, sec_header, true); let ping_tc = PusTcCreator::new_no_app_data(sp_header, sec_header, true);
let token = test_harness.init_verification(&ping_tc); let token = test_harness.start_verification(&ping_tc);
test_harness.send_tc(&token, &ping_tc); test_harness.send_tc(&token, &ping_tc);
let result = test_harness.handle_one_tc(); let result = test_harness.handle_one_tc();
assert!(result.is_err()); assert!(result.is_err());
@ -355,7 +363,7 @@ mod tests {
let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, 0, 0); let sp_header = SpHeader::new_for_unseg_tc(TEST_APID, 0, 0);
let sec_header = PusTcSecondaryHeader::new_simple(17, 200); let sec_header = PusTcSecondaryHeader::new_simple(17, 200);
let ping_tc = PusTcCreator::new_no_app_data(sp_header, sec_header, true); let ping_tc = PusTcCreator::new_no_app_data(sp_header, sec_header, true);
let token = test_harness.init_verification(&ping_tc); let token = test_harness.start_verification(&ping_tc);
test_harness.send_tc(&token, &ping_tc); test_harness.send_tc(&token, &ping_tc);
let result = test_harness.handle_one_tc(); let result = test_harness.handle_one_tc();
assert!(result.is_ok()); assert!(result.is_ok());

View File

@ -47,7 +47,7 @@
//! tc_header, //! tc_header,
//! true //! true
//! ); //! );
//! let init_token = reporter.add_tc(&pus_tc_0); //! let init_token = reporter.start_verification(&pus_tc_0);
//! //!
//! // Complete success sequence for a telecommand //! // Complete success sequence for a telecommand
//! let accepted_token = reporter.acceptance_success(&sender, init_token, &EMPTY_STAMP).unwrap(); //! let accepted_token = reporter.acceptance_success(&sender, init_token, &EMPTY_STAMP).unwrap();
@ -65,8 +65,7 @@
//! let store_guard = rg.read_with_guard(tm_in_store.store_addr); //! let store_guard = rg.read_with_guard(tm_in_store.store_addr);
//! tm_len = store_guard.read(&mut tm_buf).expect("Error reading TM slice"); //! tm_len = store_guard.read(&mut tm_buf).expect("Error reading TM slice");
//! } //! }
//! let (pus_tm, _) = PusTmReader::new(&tm_buf[0..tm_len], 7) //! let pus_tm = PusTmReader::new(&tm_buf[0..tm_len], 7).expect("Error reading verification TM");
//! .expect("Error reading verification TM");
//! if packet_idx == 0 { //! if packet_idx == 0 {
//! assert_eq!(pus_tm.subservice(), 1); //! assert_eq!(pus_tm.subservice(), 1);
//! } else if packet_idx == 1 { //! } else if packet_idx == 1 {
@ -228,7 +227,7 @@ pub struct VerificationToken<STATE> {
} }
impl<STATE> VerificationToken<STATE> { impl<STATE> VerificationToken<STATE> {
fn new(req_id: RequestId) -> VerificationToken<TcStateNone> { pub fn new(req_id: RequestId) -> VerificationToken<TcStateNone> {
VerificationToken { VerificationToken {
state: PhantomData, state: PhantomData,
request_id: req_id, request_id: req_id,
@ -408,14 +407,10 @@ pub trait VerificationReportingProvider {
fn set_apid(&mut self, apid: Apid); fn set_apid(&mut self, apid: Apid);
fn apid(&self) -> Apid; fn apid(&self) -> Apid;
fn add_tc( fn start_verification(
&mut self, &self,
pus_tc: &(impl CcsdsPacket + IsPusTelecommand), pus_tc: &(impl CcsdsPacket + IsPusTelecommand),
) -> VerificationToken<TcStateNone> { ) -> VerificationToken<TcStateNone>;
self.add_tc_with_req_id(RequestId::new(pus_tc))
}
fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone>;
fn acceptance_success( fn acceptance_success(
&self, &self,
@ -482,7 +477,7 @@ pub trait VerificationReportingProvider {
/// the buffer passed to the API exposes by this struct will be used to serialize the source data. /// the buffer passed to the API exposes by this struct will be used to serialize the source data.
/// This buffer may not be re-used to serialize the whole telemetry because that would overwrite /// This buffer may not be re-used to serialize the whole telemetry because that would overwrite
/// the source data itself. /// the source data itself.
#[derive(Clone)] #[derive(Debug, Clone)]
pub struct VerificationReportCreator { pub struct VerificationReportCreator {
pub dest_id: u16, pub dest_id: u16,
apid: u16, apid: u16,
@ -518,24 +513,15 @@ impl VerificationReportCreator {
/// Initialize verification handling by passing a TC reference. This returns a token required /// Initialize verification handling by passing a TC reference. This returns a token required
/// to call the acceptance functions /// to call the acceptance functions
pub fn add_tc( pub fn read_request_id_from_tc(pus_tc: &(impl CcsdsPacket + IsPusTelecommand)) -> RequestId {
&mut self, RequestId::new(pus_tc)
pus_tc: &(impl CcsdsPacket + IsPusTelecommand),
) -> VerificationToken<TcStateNone> {
self.add_tc_with_req_id(RequestId::new(pus_tc))
} }
/// Same as [Self::add_tc] but pass a request ID instead of the direct telecommand. fn success_verification_no_step<'time, 'src_data>(
/// This can be useful if the executing thread does not have full access to the telecommand.
pub fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone> {
VerificationToken::<TcStateNone>::new(req_id)
}
fn success_verification_no_step<'time, 'src_data, State: Copy>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
subservice: u8, subservice: u8,
token: VerificationToken<State>, request_id: &RequestId,
seq_count: u16, seq_count: u16,
msg_count: u16, msg_count: u16,
time_stamp: &'time [u8], time_stamp: &'time [u8],
@ -545,7 +531,7 @@ impl VerificationReportCreator {
subservice, subservice,
seq_count, seq_count,
msg_count, msg_count,
&token.request_id(), request_id,
time_stamp, time_stamp,
None::<&dyn EcssEnumeration>, None::<&dyn EcssEnumeration>,
)?; )?;
@ -554,11 +540,11 @@ impl VerificationReportCreator {
// Internal helper function, too many arguments is acceptable for this case. // Internal helper function, too many arguments is acceptable for this case.
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn failure_verification_no_step<'time, 'src_data, State: Copy>( fn failure_verification_no_step<'time, 'src_data>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
subservice: u8, subservice: u8,
token: VerificationToken<State>, request_id: &RequestId,
seq_count: u16, seq_count: u16,
msg_count: u16, msg_count: u16,
step: Option<&(impl EcssEnumeration + ?Sized)>, step: Option<&(impl EcssEnumeration + ?Sized)>,
@ -569,7 +555,7 @@ impl VerificationReportCreator {
subservice, subservice,
seq_count, seq_count,
msg_count, msg_count,
&token.request_id(), request_id,
step, step,
params, params,
)?; )?;
@ -580,39 +566,27 @@ impl VerificationReportCreator {
pub fn acceptance_success<'time, 'src_data>( pub fn acceptance_success<'time, 'src_data>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
token: VerificationToken<TcStateNone>, request_id: &RequestId,
seq_count: u16, seq_count: u16,
msg_count: u16, msg_count: u16,
time_stamp: &'time [u8], time_stamp: &'time [u8],
) -> Result< ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
(
PusTmCreator<'time, 'src_data>,
VerificationToken<TcStateAccepted>,
),
ByteConversionError,
> {
let tm_creator = self.success_verification_no_step( let tm_creator = self.success_verification_no_step(
src_data_buf, src_data_buf,
Subservice::TmAcceptanceSuccess.into(), Subservice::TmAcceptanceSuccess.into(),
token, request_id,
seq_count, seq_count,
msg_count, msg_count,
time_stamp, time_stamp,
)?; )?;
Ok(( Ok(tm_creator)
tm_creator,
VerificationToken {
state: PhantomData,
request_id: token.request_id(),
},
))
} }
/// Package a PUS TM\[1, 2\] packet, see 8.1.2.2 of the PUS standard. /// Package a PUS TM\[1, 2\] packet, see 8.1.2.2 of the PUS standard.
pub fn acceptance_failure<'time, 'src_data>( pub fn acceptance_failure<'time, 'src_data>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
token: VerificationToken<TcStateNone>, request_id: &RequestId,
seq_count: u16, seq_count: u16,
msg_count: u16, msg_count: u16,
params: FailParams<'time, '_>, params: FailParams<'time, '_>,
@ -620,7 +594,7 @@ impl VerificationReportCreator {
self.failure_verification_no_step( self.failure_verification_no_step(
src_data_buf, src_data_buf,
Subservice::TmAcceptanceFailure.into(), Subservice::TmAcceptanceFailure.into(),
token, request_id,
seq_count, seq_count,
msg_count, msg_count,
None::<&dyn EcssEnumeration>, None::<&dyn EcssEnumeration>,
@ -634,32 +608,20 @@ impl VerificationReportCreator {
pub fn start_success<'time, 'src_data>( pub fn start_success<'time, 'src_data>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
token: VerificationToken<TcStateAccepted>, request_id: &RequestId,
seq_count: u16, seq_count: u16,
msg_count: u16, msg_count: u16,
time_stamp: &'time [u8], time_stamp: &'time [u8],
) -> Result< ) -> Result<PusTmCreator<'time, 'src_data>, ByteConversionError> {
(
PusTmCreator<'time, 'src_data>,
VerificationToken<TcStateStarted>,
),
ByteConversionError,
> {
let tm_creator = self.success_verification_no_step( let tm_creator = self.success_verification_no_step(
src_data_buf, src_data_buf,
Subservice::TmStartSuccess.into(), Subservice::TmStartSuccess.into(),
token, request_id,
seq_count, seq_count,
msg_count, msg_count,
time_stamp, time_stamp,
)?; )?;
Ok(( Ok(tm_creator)
tm_creator,
VerificationToken {
state: PhantomData,
request_id: token.request_id(),
},
))
} }
/// Package and send a PUS TM\[1, 4\] packet, see 8.1.2.4 of the PUS standard. /// Package and send a PUS TM\[1, 4\] packet, see 8.1.2.4 of the PUS standard.
@ -669,7 +631,7 @@ impl VerificationReportCreator {
pub fn start_failure<'time, 'src_data>( pub fn start_failure<'time, 'src_data>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
token: VerificationToken<TcStateAccepted>, request_id: &RequestId,
seq_count: u16, seq_count: u16,
msg_count: u16, msg_count: u16,
params: FailParams<'time, '_>, params: FailParams<'time, '_>,
@ -677,7 +639,7 @@ impl VerificationReportCreator {
self.failure_verification_no_step( self.failure_verification_no_step(
src_data_buf, src_data_buf,
Subservice::TmStartFailure.into(), Subservice::TmStartFailure.into(),
token, request_id,
seq_count, seq_count,
msg_count, msg_count,
None::<&dyn EcssEnumeration>, None::<&dyn EcssEnumeration>,
@ -691,7 +653,7 @@ impl VerificationReportCreator {
pub fn step_success<'time, 'src_data>( pub fn step_success<'time, 'src_data>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
token: &VerificationToken<TcStateStarted>, request_id: &RequestId,
seq_count: u16, seq_count: u16,
msg_count: u16, msg_count: u16,
time_stamp: &'time [u8], time_stamp: &'time [u8],
@ -702,7 +664,7 @@ impl VerificationReportCreator {
Subservice::TmStepSuccess.into(), Subservice::TmStepSuccess.into(),
seq_count, seq_count,
msg_count, msg_count,
&token.request_id(), request_id,
time_stamp, time_stamp,
Some(&step), Some(&step),
) )
@ -735,10 +697,10 @@ impl VerificationReportCreator {
/// ///
/// Requires a token previously acquired by calling [Self::start_success]. It consumes the /// Requires a token previously acquired by calling [Self::start_success]. It consumes the
/// token because verification handling is done. /// token because verification handling is done.
pub fn completion_success<'time, 'src_data, TcState: WasAtLeastAccepted + Copy>( pub fn completion_success<'time, 'src_data>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
token: VerificationToken<TcState>, request_id: &RequestId,
seq_counter: u16, seq_counter: u16,
msg_counter: u16, msg_counter: u16,
time_stamp: &'time [u8], time_stamp: &'time [u8],
@ -746,7 +708,7 @@ impl VerificationReportCreator {
self.success_verification_no_step( self.success_verification_no_step(
src_data_buf, src_data_buf,
Subservice::TmCompletionSuccess.into(), Subservice::TmCompletionSuccess.into(),
token, request_id,
seq_counter, seq_counter,
msg_counter, msg_counter,
time_stamp, time_stamp,
@ -757,10 +719,10 @@ impl VerificationReportCreator {
/// ///
/// Requires a token previously acquired by calling [Self::start_success]. It consumes the /// Requires a token previously acquired by calling [Self::start_success]. It consumes the
/// token because verification handling is done. /// token because verification handling is done.
pub fn completion_failure<'time, 'src_data, TcState: WasAtLeastAccepted + Copy>( pub fn completion_failure<'time, 'src_data>(
&self, &self,
src_data_buf: &'src_data mut [u8], src_data_buf: &'src_data mut [u8],
token: VerificationToken<TcState>, request_id: &RequestId,
seq_count: u16, seq_count: u16,
msg_count: u16, msg_count: u16,
params: FailParams<'time, '_>, params: FailParams<'time, '_>,
@ -768,7 +730,7 @@ impl VerificationReportCreator {
self.failure_verification_no_step( self.failure_verification_no_step(
src_data_buf, src_data_buf,
Subservice::TmCompletionFailure.into(), Subservice::TmCompletionFailure.into(),
token, request_id,
seq_count, seq_count,
msg_count, msg_count,
None::<&dyn EcssEnumeration>, None::<&dyn EcssEnumeration>,
@ -986,12 +948,26 @@ pub mod alloc_mod {
} }
} }
pub fn start_verification(
&self,
pus_tc: &(impl CcsdsPacket + IsPusTelecommand),
) -> VerificationToken<TcStateNone> {
VerificationToken::<TcStateNone>::new(
VerificationReportCreator::read_request_id_from_tc(pus_tc),
)
}
pub fn start_verification_with_req_id(
&self,
request_id: RequestId,
) -> VerificationToken<TcStateNone> {
VerificationToken::<TcStateNone>::new(request_id)
}
delegate!( delegate!(
to self.reporter_creator { to self.reporter_creator {
pub fn set_apid(&mut self, apid: u16) -> bool; pub fn set_apid(&mut self, apid: u16) -> bool;
pub fn apid(&self) -> u16; pub fn apid(&self) -> u16;
pub fn add_tc(&mut self, pus_tc: &(impl CcsdsPacket + IsPusTelecommand)) -> VerificationToken<TcStateNone>;
pub fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone>;
pub fn dest_id(&self) -> u16; pub fn dest_id(&self) -> u16;
pub fn set_dest_id(&mut self, dest_id: u16); pub fn set_dest_id(&mut self, dest_id: u16);
} }
@ -1009,11 +985,16 @@ pub mod alloc_mod {
to self.reporter_creator { to self.reporter_creator {
fn set_apid(&mut self, apid: Apid); fn set_apid(&mut self, apid: Apid);
fn apid(&self) -> Apid; fn apid(&self) -> Apid;
fn add_tc(&mut self, pus_tc: &(impl CcsdsPacket + IsPusTelecommand)) -> VerificationToken<TcStateNone>;
fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone>;
} }
); );
fn start_verification(
&self,
pus_tc: &(impl CcsdsPacket + IsPusTelecommand),
) -> VerificationToken<TcStateNone> {
VerificationToken::<TcStateNone>::new(RequestId::new(pus_tc))
}
fn owner_id(&self) -> ComponentId { fn owner_id(&self) -> ComponentId {
self.owner_id self.owner_id
} }
@ -1026,13 +1007,19 @@ pub mod alloc_mod {
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<TcStateAccepted>, EcssTmtcError> { ) -> Result<VerificationToken<TcStateAccepted>, EcssTmtcError> {
let mut source_data_buf = self.source_data_buf.borrow_mut(); let mut source_data_buf = self.source_data_buf.borrow_mut();
let (mut tm_creator, token) = self let mut tm_creator = self
.reporter_creator .reporter_creator
.acceptance_success(source_data_buf.as_mut_slice(), token, 0, 0, time_stamp) .acceptance_success(
source_data_buf.as_mut_slice(),
&token.request_id(),
0,
0,
time_stamp,
)
.map_err(PusError::ByteConversion)?; .map_err(PusError::ByteConversion)?;
self.tm_hook.modify_tm(&mut tm_creator); self.tm_hook.modify_tm(&mut tm_creator);
sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?; sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?;
Ok(token) Ok(VerificationToken::new_accepted_state(token.request_id()))
} }
/// Package and send a PUS TM\[1, 2\] packet, see 8.1.2.2 of the PUS standard /// Package and send a PUS TM\[1, 2\] packet, see 8.1.2.2 of the PUS standard
@ -1045,7 +1032,7 @@ pub mod alloc_mod {
let mut buf = self.source_data_buf.borrow_mut(); let mut buf = self.source_data_buf.borrow_mut();
let mut tm_creator = self let mut tm_creator = self
.reporter_creator .reporter_creator
.acceptance_failure(buf.as_mut_slice(), token, 0, 0, params) .acceptance_failure(buf.as_mut_slice(), &token.request_id(), 0, 0, params)
.map_err(PusError::ByteConversion)?; .map_err(PusError::ByteConversion)?;
self.tm_hook.modify_tm(&mut tm_creator); self.tm_hook.modify_tm(&mut tm_creator);
sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?; sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?;
@ -1062,13 +1049,13 @@ pub mod alloc_mod {
time_stamp: &[u8], time_stamp: &[u8],
) -> Result<VerificationToken<TcStateStarted>, EcssTmtcError> { ) -> Result<VerificationToken<TcStateStarted>, EcssTmtcError> {
let mut buf = self.source_data_buf.borrow_mut(); let mut buf = self.source_data_buf.borrow_mut();
let (mut tm_creator, started_token) = self let mut tm_creator = self
.reporter_creator .reporter_creator
.start_success(buf.as_mut_slice(), token, 0, 0, time_stamp) .start_success(buf.as_mut_slice(), &token.request_id(), 0, 0, time_stamp)
.map_err(PusError::ByteConversion)?; .map_err(PusError::ByteConversion)?;
self.tm_hook.modify_tm(&mut tm_creator); self.tm_hook.modify_tm(&mut tm_creator);
sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?; sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?;
Ok(started_token) Ok(VerificationToken::new_started_state(token.request_id()))
} }
/// Package and send a PUS TM\[1, 4\] packet, see 8.1.2.4 of the PUS standard. /// Package and send a PUS TM\[1, 4\] packet, see 8.1.2.4 of the PUS standard.
@ -1084,7 +1071,7 @@ pub mod alloc_mod {
let mut buf = self.source_data_buf.borrow_mut(); let mut buf = self.source_data_buf.borrow_mut();
let mut tm_creator = self let mut tm_creator = self
.reporter_creator .reporter_creator
.start_failure(buf.as_mut_slice(), token, 0, 0, params) .start_failure(buf.as_mut_slice(), &token.request_id(), 0, 0, params)
.map_err(PusError::ByteConversion)?; .map_err(PusError::ByteConversion)?;
self.tm_hook.modify_tm(&mut tm_creator); self.tm_hook.modify_tm(&mut tm_creator);
sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?; sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?;
@ -1104,7 +1091,14 @@ pub mod alloc_mod {
let mut buf = self.source_data_buf.borrow_mut(); let mut buf = self.source_data_buf.borrow_mut();
let mut tm_creator = self let mut tm_creator = self
.reporter_creator .reporter_creator
.step_success(buf.as_mut_slice(), token, 0, 0, time_stamp, step) .step_success(
buf.as_mut_slice(),
&token.request_id(),
0,
0,
time_stamp,
step,
)
.map_err(PusError::ByteConversion)?; .map_err(PusError::ByteConversion)?;
self.tm_hook.modify_tm(&mut tm_creator); self.tm_hook.modify_tm(&mut tm_creator);
sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?; sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?;
@ -1145,7 +1139,7 @@ pub mod alloc_mod {
let mut buf = self.source_data_buf.borrow_mut(); let mut buf = self.source_data_buf.borrow_mut();
let mut tm_creator = self let mut tm_creator = self
.reporter_creator .reporter_creator
.completion_success(buf.as_mut_slice(), token, 0, 0, time_stamp) .completion_success(buf.as_mut_slice(), &token.request_id(), 0, 0, time_stamp)
.map_err(PusError::ByteConversion)?; .map_err(PusError::ByteConversion)?;
self.tm_hook.modify_tm(&mut tm_creator); self.tm_hook.modify_tm(&mut tm_creator);
sender.send_tm(self.owner_id, PusTmVariant::Direct(tm_creator))?; sender.send_tm(self.owner_id, PusTmVariant::Direct(tm_creator))?;
@ -1165,7 +1159,7 @@ pub mod alloc_mod {
let mut buf = self.source_data_buf.borrow_mut(); let mut buf = self.source_data_buf.borrow_mut();
let mut tm_creator = self let mut tm_creator = self
.reporter_creator .reporter_creator
.completion_failure(buf.as_mut_slice(), token, 0, 00, params) .completion_failure(buf.as_mut_slice(), &token.request_id(), 0, 00, params)
.map_err(PusError::ByteConversion)?; .map_err(PusError::ByteConversion)?;
self.tm_hook.modify_tm(&mut tm_creator); self.tm_hook.modify_tm(&mut tm_creator);
sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?; sender.send_tm(self.owner_id(), PusTmVariant::Direct(tm_creator))?;
@ -1362,22 +1356,23 @@ pub mod test_util {
} }
impl VerificationReportingProvider for TestVerificationReporter { impl VerificationReportingProvider for TestVerificationReporter {
fn start_verification(
&self,
pus_tc: &(impl CcsdsPacket + IsPusTelecommand),
) -> VerificationToken<TcStateNone> {
let request_id = RequestId::new(pus_tc);
self.report_queue
.borrow_mut()
.push_back((request_id, VerificationReportInfo::Added));
VerificationToken::<TcStateNone>::new(RequestId::new(pus_tc))
}
fn set_apid(&mut self, _apid: Apid) {} fn set_apid(&mut self, _apid: Apid) {}
fn apid(&self) -> Apid { fn apid(&self) -> Apid {
0 0
} }
fn add_tc_with_req_id(&mut self, req_id: RequestId) -> VerificationToken<TcStateNone> {
self.report_queue
.borrow_mut()
.push_back((req_id, VerificationReportInfo::Added));
VerificationToken {
state: PhantomData,
request_id: req_id,
}
}
fn acceptance_success( fn acceptance_success(
&self, &self,
_sender: &(impl EcssTmSender + ?Sized), _sender: &(impl EcssTmSender + ?Sized),
@ -1834,15 +1829,16 @@ pub mod tests {
} }
} }
pub fn start_verification(&self) -> VerificationToken<TcStateNone> {
let tc_reader = PusTcReader::new(&self.tc).unwrap();
self.reporter.start_verification(&tc_reader)
}
#[allow(dead_code)] #[allow(dead_code)]
fn set_dest_id(&mut self, dest_id: u16) { fn set_dest_id(&mut self, dest_id: u16) {
self.reporter.set_dest_id(dest_id); self.reporter.set_dest_id(dest_id);
} }
fn init(&mut self) -> VerificationToken<TcStateNone> {
self.reporter.add_tc(&PusTcReader::new(&self.tc).unwrap().0)
}
fn acceptance_success( fn acceptance_success(
&self, &self,
token: VerificationToken<TcStateNone>, token: VerificationToken<TcStateNone>,
@ -1920,7 +1916,7 @@ pub mod tests {
additional_data: None, additional_data: None,
}; };
let mut service_queue = self.sender.service_queue.borrow_mut(); let mut service_queue = self.sender.service_queue.borrow_mut();
assert!(service_queue.len() >= 1); assert!(!service_queue.is_empty());
let info = service_queue.pop_front().unwrap(); let info = service_queue.pop_front().unwrap();
assert_eq!(info, cmp_info); assert_eq!(info, cmp_info);
} }
@ -2092,8 +2088,8 @@ pub mod tests {
#[test] #[test]
fn test_basic_acceptance_success() { fn test_basic_acceptance_success() {
let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16); let testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16);
let token = testbench.init(); let token = testbench.start_verification();
testbench testbench
.acceptance_success(token, &EMPTY_STAMP) .acceptance_success(token, &EMPTY_STAMP)
.expect("sending acceptance success failed"); .expect("sending acceptance success failed");
@ -2103,7 +2099,7 @@ pub mod tests {
#[test] #[test]
fn test_basic_acceptance_failure() { fn test_basic_acceptance_failure() {
let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16); let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16);
let init_token = testbench.init(); let init_token = testbench.start_verification();
let timestamp = [1, 2, 3, 4, 5, 6, 7]; let timestamp = [1, 2, 3, 4, 5, 6, 7];
let fail_code = EcssEnumU16::new(2); let fail_code = EcssEnumU16::new(2);
let fail_params = FailParams::new_no_fail_data(timestamp.as_slice(), &fail_code); let fail_params = FailParams::new_no_fail_data(timestamp.as_slice(), &fail_code);
@ -2116,7 +2112,7 @@ pub mod tests {
#[test] #[test]
fn test_basic_acceptance_failure_with_helper() { fn test_basic_acceptance_failure_with_helper() {
let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16); let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16);
let init_token = testbench.init(); let init_token = testbench.start_verification();
let timestamp = [1, 2, 3, 4, 5, 6, 7]; let timestamp = [1, 2, 3, 4, 5, 6, 7];
let fail_code = EcssEnumU16::new(2); let fail_code = EcssEnumU16::new(2);
let fail_params = FailParams::new_no_fail_data(timestamp.as_slice(), &fail_code); let fail_params = FailParams::new_no_fail_data(timestamp.as_slice(), &fail_code);
@ -2128,8 +2124,8 @@ pub mod tests {
#[test] #[test]
fn test_acceptance_fail_data_too_large() { fn test_acceptance_fail_data_too_large() {
let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 8); let testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 8);
let init_token = testbench.init(); let init_token = testbench.start_verification();
let stamp_buf = [1, 2, 3, 4, 5, 6, 7]; let stamp_buf = [1, 2, 3, 4, 5, 6, 7];
let fail_code = EcssEnumU16::new(2); let fail_code = EcssEnumU16::new(2);
let fail_data: [u8; 16] = [0; 16]; let fail_data: [u8; 16] = [0; 16];
@ -2160,13 +2156,13 @@ pub mod tests {
#[test] #[test]
fn test_basic_acceptance_failure_with_fail_data() { fn test_basic_acceptance_failure_with_fail_data() {
let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16); let testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16);
let fail_code = EcssEnumU8::new(10); let fail_code = EcssEnumU8::new(10);
let fail_data = EcssEnumU32::new(12); let fail_data = EcssEnumU32::new(12);
let mut fail_data_raw = [0; 4]; let mut fail_data_raw = [0; 4];
fail_data.write_to_be_bytes(&mut fail_data_raw).unwrap(); fail_data.write_to_be_bytes(&mut fail_data_raw).unwrap();
let fail_params = FailParams::new(&EMPTY_STAMP, &fail_code, fail_data_raw.as_slice()); let fail_params = FailParams::new(&EMPTY_STAMP, &fail_code, fail_data_raw.as_slice());
let init_token = testbench.init(); let init_token = testbench.start_verification();
testbench testbench
.acceptance_failure(init_token, fail_params) .acceptance_failure(init_token, fail_params)
.expect("sending acceptance failure failed"); .expect("sending acceptance failure failed");
@ -2184,7 +2180,7 @@ pub mod tests {
#[test] #[test]
fn test_start_failure() { fn test_start_failure() {
let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16); let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16);
let init_token = testbench.init(); let init_token = testbench.start_verification();
let fail_code = EcssEnumU8::new(22); let fail_code = EcssEnumU8::new(22);
let fail_data: i32 = -12; let fail_data: i32 = -12;
let mut fail_data_raw = [0; 4]; let mut fail_data_raw = [0; 4];
@ -2203,7 +2199,7 @@ pub mod tests {
#[test] #[test]
fn test_start_failure_with_helper() { fn test_start_failure_with_helper() {
let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16); let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16);
let token = testbench.init(); let token = testbench.start_verification();
let fail_code = EcssEnumU8::new(22); let fail_code = EcssEnumU8::new(22);
let fail_data: i32 = -12; let fail_data: i32 = -12;
let mut fail_data_raw = [0; 4]; let mut fail_data_raw = [0; 4];
@ -2222,7 +2218,7 @@ pub mod tests {
#[test] #[test]
fn test_steps_success() { fn test_steps_success() {
let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16); let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16);
let token = testbench.init(); let token = testbench.start_verification();
let accepted_token = testbench let accepted_token = testbench
.acceptance_success(token, &EMPTY_STAMP) .acceptance_success(token, &EMPTY_STAMP)
.expect("acceptance failed"); .expect("acceptance failed");
@ -2245,7 +2241,7 @@ pub mod tests {
#[test] #[test]
fn test_step_failure() { fn test_step_failure() {
let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16); let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16);
let token = testbench.init(); let token = testbench.start_verification();
let fail_code = EcssEnumU32::new(0x1020); let fail_code = EcssEnumU32::new(0x1020);
let fail_data: f32 = -22.3232; let fail_data: f32 = -22.3232;
let mut fail_data_raw = [0; 4]; let mut fail_data_raw = [0; 4];
@ -2279,7 +2275,7 @@ pub mod tests {
#[test] #[test]
fn test_completion_failure() { fn test_completion_failure() {
let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16); let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 16);
let token = testbench.init(); let token = testbench.start_verification();
let fail_code = EcssEnumU32::new(0x1020); let fail_code = EcssEnumU32::new(0x1020);
let fail_params = FailParams::new_no_fail_data(&EMPTY_STAMP, &fail_code); let fail_params = FailParams::new_no_fail_data(&EMPTY_STAMP, &fail_code);
@ -2302,7 +2298,7 @@ pub mod tests {
fn test_complete_success_sequence() { fn test_complete_success_sequence() {
let mut testbench = let mut testbench =
VerificationReporterTestbench::new(TEST_COMPONENT_ID_0.id(), create_generic_ping(), 16); VerificationReporterTestbench::new(TEST_COMPONENT_ID_0.id(), create_generic_ping(), 16);
let token = testbench.init(); let token = testbench.start_verification();
let accepted_token = testbench let accepted_token = testbench
.acceptance_success(token, &EMPTY_STAMP) .acceptance_success(token, &EMPTY_STAMP)
.expect("Sending acceptance success failed"); .expect("Sending acceptance success failed");
@ -2324,7 +2320,7 @@ pub mod tests {
create_generic_ping(), create_generic_ping(),
SequenceCounterHook::default(), SequenceCounterHook::default(),
); );
let token = testbench.init(); let token = testbench.start_verification();
let accepted_token = testbench let accepted_token = testbench
.acceptance_success(token, &EMPTY_STAMP) .acceptance_success(token, &EMPTY_STAMP)
.expect("Sending acceptance success failed"); .expect("Sending acceptance success failed");
@ -2342,7 +2338,7 @@ pub mod tests {
#[test] #[test]
fn test_completion_failure_helper_string_param() { fn test_completion_failure_helper_string_param() {
let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 32); let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 32);
let token = testbench.init(); let token = testbench.start_verification();
let accepted_token = testbench let accepted_token = testbench
.acceptance_success(token, &EMPTY_STAMP) .acceptance_success(token, &EMPTY_STAMP)
.expect("Sending acceptance success failed"); .expect("Sending acceptance success failed");
@ -2369,7 +2365,7 @@ pub mod tests {
#[test] #[test]
fn test_step_failure_helper_string_param() { fn test_step_failure_helper_string_param() {
let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 32); let mut testbench = VerificationReporterTestbench::new(0, create_generic_ping(), 32);
let token = testbench.init(); let token = testbench.start_verification();
let accepted_token = testbench let accepted_token = testbench
.acceptance_success(token, &EMPTY_STAMP) .acceptance_success(token, &EMPTY_STAMP)
.expect("Sending acceptance success failed"); .expect("Sending acceptance success failed");

View File

@ -136,7 +136,7 @@ impl SequenceExecutionHelper {
/// with [Self::load] /// with [Self::load]
/// * `sender` - The sender to send mode requests to the components /// * `sender` - The sender to send mode requests to the components
/// * `children_mode_store` - The mode store vector to keep track of the mode states of /// * `children_mode_store` - The mode store vector to keep track of the mode states of
/// children components /// children components
pub fn run( pub fn run(
&mut self, &mut self,
table: &SequenceModeTables, table: &SequenceModeTables,

View File

@ -107,9 +107,9 @@ fn test_threaded_usage() {
Ok(event_tm) => { Ok(event_tm) => {
let tm = PusTmReader::new(event_tm.packet.as_slice(), 7) let tm = PusTmReader::new(event_tm.packet.as_slice(), 7)
.expect("Deserializing TM failed"); .expect("Deserializing TM failed");
assert_eq!(tm.0.service(), 5); assert_eq!(tm.service(), 5);
assert_eq!(tm.0.subservice(), 1); assert_eq!(tm.subservice(), 1);
let src_data = tm.0.source_data(); let src_data = tm.source_data();
assert!(!src_data.is_empty()); assert!(!src_data.is_empty());
assert_eq!(src_data.len(), 4); assert_eq!(src_data.len(), 4);
let event = let event =
@ -137,9 +137,9 @@ fn test_threaded_usage() {
Ok(event_tm) => { Ok(event_tm) => {
let tm = PusTmReader::new(event_tm.packet.as_slice(), 7) let tm = PusTmReader::new(event_tm.packet.as_slice(), 7)
.expect("Deserializing TM failed"); .expect("Deserializing TM failed");
assert_eq!(tm.0.service(), 5); assert_eq!(tm.service(), 5);
assert_eq!(tm.0.subservice(), 2); assert_eq!(tm.subservice(), 2);
let src_data = tm.0.source_data(); let src_data = tm.source_data();
assert!(!src_data.is_empty()); assert!(!src_data.is_empty());
assert_eq!(src_data.len(), 12); assert_eq!(src_data.len(), 12);
let event = let event =

View File

@ -89,9 +89,9 @@ pub mod crossbeam_test {
let pg = tc_guard.read_with_guard(tc_addr); let pg = tc_guard.read_with_guard(tc_addr);
tc_len = pg.read(&mut tc_buf).unwrap(); tc_len = pg.read(&mut tc_buf).unwrap();
} }
let (_tc, _) = PusTcReader::new(&tc_buf[0..tc_len]).unwrap(); let _tc = PusTcReader::new(&tc_buf[0..tc_len]).unwrap();
let token = reporter_with_sender_0.add_tc_with_req_id(req_id_0); let token = reporter_with_sender_0.start_verification_with_req_id(req_id_0);
let accepted_token = reporter_with_sender_0 let accepted_token = reporter_with_sender_0
.acceptance_success(&sender, token, &FIXED_STAMP) .acceptance_success(&sender, token, &FIXED_STAMP)
.expect("Acceptance success failed"); .expect("Acceptance success failed");
@ -125,8 +125,8 @@ pub mod crossbeam_test {
let pg = tc_guard.read_with_guard(tc_addr); let pg = tc_guard.read_with_guard(tc_addr);
tc_len = pg.read(&mut tc_buf).unwrap(); tc_len = pg.read(&mut tc_buf).unwrap();
} }
let (tc, _) = PusTcReader::new(&tc_buf[0..tc_len]).unwrap(); let tc = PusTcReader::new(&tc_buf[0..tc_len]).unwrap();
let token = reporter_with_sender_1.add_tc(&tc); let token = reporter_with_sender_1.start_verification(&tc);
let accepted_token = reporter_with_sender_1 let accepted_token = reporter_with_sender_1
.acceptance_success(&sender_1, token, &FIXED_STAMP) .acceptance_success(&sender_1, token, &FIXED_STAMP)
.expect("Acceptance success failed"); .expect("Acceptance success failed");
@ -156,7 +156,7 @@ pub mod crossbeam_test {
.read(&mut tm_buf) .read(&mut tm_buf)
.expect("Error reading TM slice"); .expect("Error reading TM slice");
} }
let (pus_tm, _) = let pus_tm =
PusTmReader::new(&tm_buf[0..tm_len], 7).expect("Error reading verification TM"); PusTmReader::new(&tm_buf[0..tm_len], 7).expect("Error reading verification TM");
let req_id = let req_id =
RequestId::from_bytes(&pus_tm.source_data()[0..RequestId::SIZE_AS_BYTES]) RequestId::from_bytes(&pus_tm.source_data()[0..RequestId::SIZE_AS_BYTES])