rename module

This commit is contained in:
Robin Müller 2022-11-02 11:33:59 +01:00
parent 6768af8f17
commit 575fb0e64b
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
4 changed files with 48 additions and 23 deletions

View File

@ -28,7 +28,7 @@
//! Other components might only be interested in certain events. For example, a thermal system //! Other components might only be interested in certain events. For example, a thermal system
//! handler might only be interested in temperature events generated by a thermal sensor component. //! handler might only be interested in temperature events generated by a thermal sensor component.
use crate::events::{EventU16, EventU32, GenericEvent, LargestEventRaw, LargestGroupIdRaw}; use crate::events::{EventU16, EventU32, GenericEvent, LargestEventRaw, LargestGroupIdRaw};
use crate::util::{Params, ParamsHeapless}; use crate::params::{Params, ParamsHeapless};
use alloc::boxed::Box; use alloc::boxed::Box;
use alloc::vec; use alloc::vec;
use alloc::vec::Vec; use alloc::vec::Vec;
@ -240,7 +240,7 @@ pub mod stdmod {
use super::*; use super::*;
use crate::event_man::{EventReceiver, EventWithAuxData}; use crate::event_man::{EventReceiver, EventWithAuxData};
use crate::events::{EventU16, EventU32, GenericEvent}; use crate::events::{EventU16, EventU32, GenericEvent};
use crate::util::Params; use crate::params::Params;
use std::sync::mpsc::{Receiver, SendError, Sender}; use std::sync::mpsc::{Receiver, SendError, Sender};
pub struct MpscEventReceiver<Event: GenericEvent + Send = EventU32> { pub struct MpscEventReceiver<Event: GenericEvent + Send = EventU32> {
@ -301,7 +301,7 @@ mod tests {
use super::*; use super::*;
use crate::event_man::EventManager; use crate::event_man::EventManager;
use crate::events::{EventU32, GenericEvent, Severity}; use crate::events::{EventU32, GenericEvent, Severity};
use crate::util::ParamsRaw; use crate::params::ParamsRaw;
use alloc::boxed::Box; use alloc::boxed::Box;
use std::format; use std::format;
use std::sync::mpsc::{channel, Receiver, SendError, Sender}; use std::sync::mpsc::{channel, Receiver, SendError, Sender};

View File

@ -29,4 +29,4 @@ pub mod objects;
pub mod pool; pub mod pool;
pub mod pus; pub mod pus;
pub mod tmtc; pub mod tmtc;
pub mod util; pub mod params;

View File

@ -1,26 +1,48 @@
//! Utility types and enums. //! Parameter types and enums.
//! //!
//! This module contains various helper types. This includes wrapper for primitive rust types //! This module contains various helper types.
//! using the newtype pattern. This was also done for pairs and triplets of these primitive types.
//! The [ToBeBytes] was implemented for those types as well, which allows to easily convert them
//! into a network friendly raw byte format.
//! //!
//! The module also contains generic parameter enumerations. //! # Primtive Parameter Wrappers and Enumeration
//! //!
//! # Example for primitive type wrapper //! This module includes wrapper for primitive rust types using the newtype pattern.
//! This was also done for pairs and triplets of these primitive types.
//! The [WritableToBeBytes] was implemented for all those types as well, which allows to easily
//! convert them into a network friendly raw byte format. The [ParamsRaw] enumeration groups
//! all newtypes and implements the [WritableToBeBytes] trait itself.
//!
//! ## Example for primitive type wrapper
//! //!
//! ``` //! ```
//! use fsrc_core::util::{ParamsRaw, ToBeBytes, U32Pair}; //! use fsrc_core::params::{ParamsRaw, ToBeBytes, U32Pair, WritableToBeBytes};
//! //!
//! let u32_pair = U32Pair(0x1010, 25); //! let u32_pair = U32Pair(0x1010, 25);
//! assert_eq!(u32_pair.0, 0x1010); //! assert_eq!(u32_pair.0, 0x1010);
//! assert_eq!(u32_pair.1, 25); //! assert_eq!(u32_pair.1, 25);
//! // Convert to raw stream
//! let raw_buf = u32_pair.to_be_bytes(); //! let raw_buf = u32_pair.to_be_bytes();
//! assert_eq!(raw_buf, [0, 0, 0x10, 0x10, 0, 0, 0, 25]); //! assert_eq!(raw_buf, [0, 0, 0x10, 0x10, 0, 0, 0, 25]);
//! //!
//! // Convert to enum variant
//! let params_raw: ParamsRaw = u32_pair.into(); //! let params_raw: ParamsRaw = u32_pair.into();
//! assert_eq!(params_raw, (0x1010_u32, 25_u32).into()); //! assert_eq!(params_raw, (0x1010_u32, 25_u32).into());
//!
//! // Convert to stream using the enum variant
//! let mut other_raw_buf: [u8; 8] = [0; 8];
//! params_raw.write_to_be_bytes(&mut other_raw_buf).expect("Writing parameter to buffer failed");
//! assert_eq!(other_raw_buf, [0, 0, 0x10, 0x10, 0, 0, 0, 25]);
//!
//! // Create a pair from a raw stream
//! let u32_pair_from_stream: U32Pair = raw_buf.as_slice().try_into().unwrap();
//! assert_eq!(u32_pair_from_stream.0, 0x1010);
//! assert_eq!(u32_pair_from_stream.1, 25);
//! ``` //! ```
//!
//! # Generic Parameter Enumeration
//!
//! The module also contains generic parameter enumerations.
//! This includes the [ParamsHeapless] enumeration for contained values which do not require heap
//! allocation, and the [Params] which enumerates [ParamsHeapless] and some additional types which
//! require [alloc] support but allow for more flexbility.
use crate::pool::StoreAddr; use crate::pool::StoreAddr;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use alloc::string::String; use alloc::string::String;
@ -38,7 +60,7 @@ use spacepackets::SizeMissmatch;
/// Generic trait which is used for objects which can be converted into a raw network (big) endian /// Generic trait which is used for objects which can be converted into a raw network (big) endian
/// byte format. /// byte format.
pub trait WritableAsBeBytes { pub trait WritableToBeBytes {
fn raw_len(&self) -> usize; fn raw_len(&self) -> usize;
/// Writes the object to a raw buffer in network endianness (big) /// Writes the object to a raw buffer in network endianness (big)
fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<usize, ByteConversionError>; fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<usize, ByteConversionError>;
@ -46,7 +68,7 @@ pub trait WritableAsBeBytes {
macro_rules! param_to_be_bytes_impl { macro_rules! param_to_be_bytes_impl {
($Newtype: ident) => { ($Newtype: ident) => {
impl WritableAsBeBytes for $Newtype { impl WritableToBeBytes for $Newtype {
#[inline] #[inline]
fn raw_len(&self) -> usize { fn raw_len(&self) -> usize {
size_of::<<Self as ToBeBytes>::ByteArray>() size_of::<<Self as ToBeBytes>::ByteArray>()
@ -298,6 +320,9 @@ pair_byte_conversions_impl!(u16, u32, u64, i16, i32, i64, f32, f64,);
triplet_to_be_bytes_impl!(u16, u32, u64, i16, i32, i64, f32, f64,); triplet_to_be_bytes_impl!(u16, u32, u64, i16, i32, i64, f32, f64,);
/// Generic enumeration for additonal parameters only consisting of primitive data types. /// Generic enumeration for additonal parameters only consisting of primitive data types.
///
/// All contained variants and the enum itself implement the [WritableToBeBytes] trait, which
/// allows to easily convert them into a network-friendly format.
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq)]
pub enum ParamsRaw { pub enum ParamsRaw {
U8(U8), U8(U8),
@ -326,7 +351,7 @@ pub enum ParamsRaw {
F64(F64), F64(F64),
} }
impl WritableAsBeBytes for ParamsRaw { impl WritableToBeBytes for ParamsRaw {
fn raw_len(&self) -> usize { fn raw_len(&self) -> usize {
match self { match self {
ParamsRaw::U8(v) => v.raw_len(), ParamsRaw::U8(v) => v.raw_len(),
@ -414,7 +439,7 @@ pub enum EcssEnumParams {
macro_rules! writable_as_be_bytes_ecss_enum_impl { macro_rules! writable_as_be_bytes_ecss_enum_impl {
($EnumIdent: ident) => { ($EnumIdent: ident) => {
impl WritableAsBeBytes for $EnumIdent { impl WritableToBeBytes for $EnumIdent {
fn raw_len(&self) -> usize { fn raw_len(&self) -> usize {
self.byte_width() self.byte_width()
} }
@ -431,7 +456,7 @@ writable_as_be_bytes_ecss_enum_impl!(EcssEnumU16);
writable_as_be_bytes_ecss_enum_impl!(EcssEnumU32); writable_as_be_bytes_ecss_enum_impl!(EcssEnumU32);
writable_as_be_bytes_ecss_enum_impl!(EcssEnumU64); writable_as_be_bytes_ecss_enum_impl!(EcssEnumU64);
impl WritableAsBeBytes for EcssEnumParams { impl WritableToBeBytes for EcssEnumParams {
fn raw_len(&self) -> usize { fn raw_len(&self) -> usize {
match self { match self {
EcssEnumParams::U8(e) => e.byte_width(), EcssEnumParams::U8(e) => e.byte_width(),
@ -443,10 +468,10 @@ impl WritableAsBeBytes for EcssEnumParams {
fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<usize, ByteConversionError> { fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<usize, ByteConversionError> {
match self { match self {
EcssEnumParams::U8(e) => WritableAsBeBytes::write_to_be_bytes(e, buf), EcssEnumParams::U8(e) => WritableToBeBytes::write_to_be_bytes(e, buf),
EcssEnumParams::U16(e) => WritableAsBeBytes::write_to_be_bytes(e, buf), EcssEnumParams::U16(e) => WritableToBeBytes::write_to_be_bytes(e, buf),
EcssEnumParams::U32(e) => WritableAsBeBytes::write_to_be_bytes(e, buf), EcssEnumParams::U32(e) => WritableToBeBytes::write_to_be_bytes(e, buf),
EcssEnumParams::U64(e) => WritableAsBeBytes::write_to_be_bytes(e, buf), EcssEnumParams::U64(e) => WritableToBeBytes::write_to_be_bytes(e, buf),
} }
} }
} }

View File

@ -2,8 +2,8 @@ use fsrc_core::event_man::{EventManager, MpscEventReceiver, MpscEventU32SendProv
use fsrc_core::events::{EventU32, EventU32TypedSev, Severity, SeverityInfo}; use fsrc_core::events::{EventU32, EventU32TypedSev, Severity, SeverityInfo};
use fsrc_core::pus::event_man::{DefaultPusMgmtBackendProvider, EventReporter, PusEventTmManager}; use fsrc_core::pus::event_man::{DefaultPusMgmtBackendProvider, EventReporter, PusEventTmManager};
use fsrc_core::pus::{EcssTmError, EcssTmSender}; use fsrc_core::pus::{EcssTmError, EcssTmSender};
use fsrc_core::util::U32Pair; use fsrc_core::params::U32Pair;
use fsrc_core::util::{Params, ParamsHeapless, WritableAsBeBytes}; use fsrc_core::params::{Params, ParamsHeapless, WritableToBeBytes};
use spacepackets::ecss::PusPacket; use spacepackets::ecss::PusPacket;
use spacepackets::tm::PusTm; use spacepackets::tm::PusTm;
use std::sync::mpsc::{channel, SendError, TryRecvError}; use std::sync::mpsc::{channel, SendError, TryRecvError};