now it compiles for no_std

This commit is contained in:
Robin Müller 2022-12-30 23:09:58 +01:00
parent f109d59d56
commit 743a2c7611
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
11 changed files with 159 additions and 134 deletions

View File

@ -36,7 +36,7 @@ optional = true
[dependencies.spacepackets] [dependencies.spacepackets]
path = "../spacepackets" path = "../spacepackets"
features = ["serde"] default-features = false
[dev-dependencies] [dev-dependencies]
serde = "1.0" serde = "1.0"
@ -49,9 +49,9 @@ version = "1.0"
[features] [features]
default = ["std"] default = ["std"]
std = ["downcast-rs/std", "alloc", "bus", "postcard/use-std", "crossbeam-channel/std", "serde/std"] std = ["downcast-rs/std", "alloc", "bus", "postcard/use-std", "crossbeam-channel/std", "serde/std", "spacepackets/std"]
alloc = ["serde/alloc"] alloc = ["serde/alloc", "spacepackets/alloc"]
serde = ["dep:serde"] serde = ["dep:serde", "spacepackets/serde"]
heapless = [] heapless = []
doc-images = [] doc-images = []

View File

@ -56,8 +56,11 @@ doc = ::embed_doc_image::embed_image!("event_man_arch", "images/event_man_arch.p
//! different threads. //! different threads.
use crate::events::{EventU16, EventU32, GenericEvent, LargestEventRaw, LargestGroupIdRaw}; use crate::events::{EventU16, EventU32, GenericEvent, LargestEventRaw, LargestGroupIdRaw};
use crate::params::{Params, ParamsHeapless}; use crate::params::{Params, ParamsHeapless};
#[cfg(feature = "alloc")]
use alloc::boxed::Box; use alloc::boxed::Box;
#[cfg(feature = "alloc")]
use alloc::vec; use alloc::vec;
#[cfg(feature = "alloc")]
use alloc::vec::Vec; use alloc::vec::Vec;
use core::slice::Iter; use core::slice::Iter;
use hashbrown::HashMap; use hashbrown::HashMap;

View File

@ -29,10 +29,10 @@
//! ``` //! ```
use core::fmt::Debug; use core::fmt::Debug;
use core::hash::Hash; use core::hash::Hash;
use core::marker::PhantomData;
use delegate::delegate; use delegate::delegate;
use spacepackets::ecss::{EcssEnumeration, ToBeBytes}; use spacepackets::ecss::{EcssEnumeration, ToBeBytes};
use spacepackets::{ByteConversionError, SizeMissmatch}; use spacepackets::{ByteConversionError, SizeMissmatch};
use std::marker::PhantomData;
/// Using a type definition allows to change this to u64 in the future more easily /// Using a type definition allows to change this to u64 in the future more easily
pub type LargestEventRaw = u32; pub type LargestEventRaw = u32;

View File

@ -51,10 +51,10 @@
//! assert_eq!(example_obj.id, obj_id); //! assert_eq!(example_obj.id, obj_id);
//! assert_eq!(example_obj.dummy, 42); //! assert_eq!(example_obj.dummy, 42);
//! ``` //! ```
#[cfg(feature = "alloc")]
use alloc::boxed::Box; use alloc::boxed::Box;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use downcast_rs::Downcast; use downcast_rs::Downcast;
#[cfg(feature = "alloc")]
use hashbrown::HashMap; use hashbrown::HashMap;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::error::Error; use std::error::Error;

View File

@ -43,21 +43,23 @@
//! This includes the [ParamsHeapless] enumeration for contained values which do not require heap //! 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 //! allocation, and the [Params] which enumerates [ParamsHeapless] and some additional types which
//! require [alloc] support but allow for more flexbility. //! require [alloc] support but allow for more flexbility.
#[cfg(feature = "alloc")]
use crate::pool::StoreAddr; use crate::pool::StoreAddr;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use alloc::string::String; use alloc::string::{String, ToString};
#[cfg(feature = "alloc")]
use alloc::string::ToString;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
use alloc::vec::Vec; use alloc::vec::Vec;
use core::fmt::Debug; use core::fmt::Debug;
use core::mem::size_of; use core::mem::size_of;
use paste::paste; use paste::paste;
pub use spacepackets::ecss::ToBeBytes;
use spacepackets::ecss::{EcssEnumU16, EcssEnumU32, EcssEnumU64, EcssEnumU8, EcssEnumeration}; use spacepackets::ecss::{EcssEnumU16, EcssEnumU32, EcssEnumU64, EcssEnumU8, EcssEnumeration};
use spacepackets::ByteConversionError; use spacepackets::ByteConversionError;
use spacepackets::SizeMissmatch; use spacepackets::SizeMissmatch;
#[cfg(feature = "alloc")]
pub use alloc_mod::*;
pub use spacepackets::ecss::ToBeBytes;
/// 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 WritableToBeBytes { pub trait WritableToBeBytes {
@ -481,13 +483,6 @@ impl WritableToBeBytes for EcssEnumParams {
pub enum ParamsHeapless { pub enum ParamsHeapless {
Raw(ParamsRaw), Raw(ParamsRaw),
EcssEnum(EcssEnumParams), EcssEnum(EcssEnumParams),
Store(StoreAddr),
}
impl From<StoreAddr> for ParamsHeapless {
fn from(x: StoreAddr) -> Self {
Self::Store(x)
}
} }
macro_rules! from_conversions_for_raw { macro_rules! from_conversions_for_raw {
@ -534,47 +529,57 @@ from_conversions_for_raw!(
(f64, Self::F64), (f64, Self::F64),
); );
/// Generic enumeration for additional parameters, including parameters which rely on heap
/// allocations.
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] mod alloc_mod {
#[derive(Debug, Clone)] use super::*;
pub enum Params { /// Generic enumeration for additional parameters, including parameters which rely on heap
/// allocations.
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
#[derive(Debug, Clone)]
pub enum Params {
Heapless(ParamsHeapless), Heapless(ParamsHeapless),
Store(StoreAddr),
Vec(Vec<u8>), Vec(Vec<u8>),
String(String), String(String),
} }
impl From<ParamsHeapless> for Params { impl From<StoreAddr> for Params {
fn from(x: StoreAddr) -> Self {
Self::Store(x)
}
}
impl From<ParamsHeapless> for Params {
fn from(x: ParamsHeapless) -> Self { fn from(x: ParamsHeapless) -> Self {
Self::Heapless(x) Self::Heapless(x)
} }
} }
impl From<Vec<u8>> for Params { impl From<Vec<u8>> for Params {
fn from(val: Vec<u8>) -> Self { fn from(val: Vec<u8>) -> Self {
Self::Vec(val) Self::Vec(val)
} }
} }
/// Converts a byte slice into the [Params::Vec] variant /// Converts a byte slice into the [Params::Vec] variant
impl From<&[u8]> for Params { impl From<&[u8]> for Params {
fn from(val: &[u8]) -> Self { fn from(val: &[u8]) -> Self {
Self::Vec(val.to_vec()) Self::Vec(val.to_vec())
} }
} }
impl From<String> for Params { impl From<String> for Params {
fn from(val: String) -> Self { fn from(val: String) -> Self {
Self::String(val) Self::String(val)
} }
} }
/// Converts a string slice into the [Params::String] variant /// Converts a string slice into the [Params::String] variant
impl From<&str> for Params { impl From<&str> for Params {
fn from(val: &str) -> Self { fn from(val: &str) -> Self {
Self::String(val.to_string()) Self::String(val.to_string())
} }
}
} }
#[cfg(test)] #[cfg(test)]

View File

@ -1,4 +1,7 @@
use crate::events::{EventU32, EventU32TypedSev, GenericEvent, HasSeverity, Severity}; use crate::events::{EventU32, GenericEvent, Severity};
#[cfg(feature = "alloc")]
use crate::events::{EventU32TypedSev, HasSeverity};
#[cfg(feature = "alloc")]
use alloc::boxed::Box; use alloc::boxed::Box;
use core::hash::Hash; use core::hash::Hash;
use hashbrown::HashSet; use hashbrown::HashSet;
@ -6,7 +9,12 @@ use hashbrown::HashSet;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
pub use crate::pus::event::EventReporter; pub use crate::pus::event::EventReporter;
use crate::pus::verification::{TcStateStarted, VerificationToken}; use crate::pus::verification::{TcStateStarted, VerificationToken};
use crate::pus::{EcssTmError, EcssTmSender}; use crate::pus::EcssTmError;
#[cfg(feature = "alloc")]
use crate::pus::EcssTmSender;
#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
pub use alloc_mod::*;
#[cfg(feature = "heapless")] #[cfg(feature = "heapless")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "heapless")))] #[cfg_attr(doc_cfg, doc(cfg(feature = "heapless")))]
pub use heapless_mod::*; pub use heapless_mod::*;
@ -133,24 +141,28 @@ impl<SenderE> From<EcssTmError<SenderE>> for EventManError<SenderE> {
} }
} }
pub struct PusEventDispatcher<BackendError, Provider: GenericEvent> { #[cfg(feature = "alloc")]
pub mod alloc_mod {
use super::*;
pub struct PusEventDispatcher<BackendError, Provider: GenericEvent> {
reporter: EventReporter, reporter: EventReporter,
backend: Box<dyn PusEventMgmtBackendProvider<Provider, Error = BackendError>>, backend: Box<dyn PusEventMgmtBackendProvider<Provider, Error = BackendError>>,
} }
/// Safety: All contained fields are send as well. /// Safety: All contained fields are send as well.
unsafe impl<E: Send, Event: GenericEvent + Send> Send for PusEventDispatcher<E, Event> {} unsafe impl<E: Send, Event: GenericEvent + Send> Send for PusEventDispatcher<E, Event> {}
impl<BackendError, Provider: GenericEvent> PusEventDispatcher<BackendError, Provider> { impl<BackendError, Provider: GenericEvent> PusEventDispatcher<BackendError, Provider> {
pub fn new( pub fn new(
reporter: EventReporter, reporter: EventReporter,
backend: Box<dyn PusEventMgmtBackendProvider<Provider, Error = BackendError>>, backend: Box<dyn PusEventMgmtBackendProvider<Provider, Error = BackendError>>,
) -> Self { ) -> Self {
Self { reporter, backend } Self { reporter, backend }
} }
} }
impl<BackendError, Event: GenericEvent> PusEventDispatcher<BackendError, Event> { impl<BackendError, Event: GenericEvent> PusEventDispatcher<BackendError, Event> {
pub fn enable_tm_for_event(&mut self, event: &Event) -> Result<bool, BackendError> { pub fn enable_tm_for_event(&mut self, event: &Event) -> Result<bool, BackendError> {
self.backend.enable_event_reporting(event) self.backend.enable_event_reporting(event)
} }
@ -192,9 +204,9 @@ impl<BackendError, Event: GenericEvent> PusEventDispatcher<BackendError, Event>
.map_err(|e| e.into()), .map_err(|e| e.into()),
} }
} }
} }
impl<BackendError> PusEventDispatcher<BackendError, EventU32> { impl<BackendError> PusEventDispatcher<BackendError, EventU32> {
pub fn enable_tm_for_event_with_sev<Severity: HasSeverity>( pub fn enable_tm_for_event_with_sev<Severity: HasSeverity>(
&mut self, &mut self,
event: &EventU32TypedSev<Severity>, event: &EventU32TypedSev<Severity>,
@ -218,8 +230,8 @@ impl<BackendError> PusEventDispatcher<BackendError, EventU32> {
) -> Result<bool, EventManError<E>> { ) -> Result<bool, EventManError<E>> {
self.generate_pus_event_tm_generic(sender, time_stamp, event.into(), aux_data) self.generate_pus_event_tm_generic(sender, time_stamp, event.into(), aux_data)
} }
}
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View File

@ -77,6 +77,7 @@ use core::fmt::{Display, Formatter};
use core::hash::{Hash, Hasher}; use core::hash::{Hash, Hasher};
use core::marker::PhantomData; use core::marker::PhantomData;
use core::mem::size_of; use core::mem::size_of;
#[cfg(feature = "alloc")]
use delegate::delegate; use delegate::delegate;
use spacepackets::ecss::EcssEnumeration; use spacepackets::ecss::EcssEnumeration;
use spacepackets::tc::PusTc; use spacepackets::tc::PusTc;
@ -87,7 +88,7 @@ use spacepackets::{SpHeader, MAX_APID};
pub use crate::seq_count::SimpleSeqCountProvider; pub use crate::seq_count::SimpleSeqCountProvider;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
pub use allocmod::{ pub use alloc_mod::{
VerificationReporterCfg, VerificationReporterWithBuf, VerificationReporterWithSender, VerificationReporterCfg, VerificationReporterWithBuf, VerificationReporterWithSender,
}; };
@ -656,7 +657,7 @@ impl VerificationReporterBasic {
} }
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
mod allocmod { mod alloc_mod {
use super::*; use super::*;
use alloc::boxed::Box; use alloc::boxed::Box;
use alloc::vec; use alloc::vec;
@ -995,7 +996,7 @@ mod allocmod {
#[cfg(feature = "std")] #[cfg(feature = "std")]
mod stdmod { mod stdmod {
use super::allocmod::VerificationReporterWithSender; use super::alloc_mod::VerificationReporterWithSender;
use super::*; use super::*;
use crate::pool::{ShareablePoolProvider, SharedPool, StoreAddr, StoreError}; use crate::pool::{ShareablePoolProvider, SharedPool, StoreAddr, StoreError};
use delegate::delegate; use delegate::delegate;

View File

@ -1,8 +1,10 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use spacepackets::ecss::{EcssEnumU16, EcssEnumeration}; use spacepackets::ecss::{EcssEnumU16, EcssEnumeration};
use spacepackets::{ByteConversionError, SizeMissmatch}; use spacepackets::{ByteConversionError, SizeMissmatch};
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ResultU16 { pub struct ResultU16 {
group_id: u8, group_id: u8,
unique_id: u8, unique_id: u8,

View File

@ -17,7 +17,9 @@ pub mod ccsds_distrib;
pub mod pus_distrib; pub mod pus_distrib;
pub mod tm_helper; pub mod tm_helper;
#[cfg(feature = "alloc")]
pub use ccsds_distrib::{CcsdsDistributor, CcsdsError, CcsdsPacketHandler}; pub use ccsds_distrib::{CcsdsDistributor, CcsdsError, CcsdsPacketHandler};
#[cfg(feature = "alloc")]
pub use pus_distrib::{PusDistributor, PusServiceProvider}; pub use pus_distrib::{PusDistributor, PusServiceProvider};
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]

View File

@ -78,10 +78,10 @@ fn test_threaded_usage() {
.expect("Writing ECSS enum failed"); .expect("Writing ECSS enum failed");
gen_event(Some(&params_array[0..e.raw_len()])) gen_event(Some(&params_array[0..e.raw_len()]))
} }
ParamsHeapless::Store(_) => gen_event(None),
}, },
Params::Vec(vec) => gen_event(Some(vec.as_slice())), Params::Vec(vec) => gen_event(Some(vec.as_slice())),
Params::String(str) => gen_event(Some(str.as_bytes())), Params::String(str) => gen_event(Some(str.as_bytes())),
Params::Store(_) => gen_event(None),
} }
} else { } else {
gen_event(None) gen_event(None)

@ -1 +1 @@
Subproject commit 9b091e3a3a6f599b093c96327751bcf1bc911ca1 Subproject commit ae55c394bb2455eed3b05a5b587048a931d27238