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

View File

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

View File

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

View File

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

View File

@ -43,21 +43,23 @@
//! 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.
#[cfg(feature = "alloc")]
use crate::pool::StoreAddr;
#[cfg(feature = "alloc")]
use alloc::string::String;
#[cfg(feature = "alloc")]
use alloc::string::ToString;
use alloc::string::{String, ToString};
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
use core::fmt::Debug;
use core::mem::size_of;
use paste::paste;
pub use spacepackets::ecss::ToBeBytes;
use spacepackets::ecss::{EcssEnumU16, EcssEnumU32, EcssEnumU64, EcssEnumU8, EcssEnumeration};
use spacepackets::ByteConversionError;
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
/// byte format.
pub trait WritableToBeBytes {
@ -481,13 +483,6 @@ impl WritableToBeBytes for EcssEnumParams {
pub enum ParamsHeapless {
Raw(ParamsRaw),
EcssEnum(EcssEnumParams),
Store(StoreAddr),
}
impl From<StoreAddr> for ParamsHeapless {
fn from(x: StoreAddr) -> Self {
Self::Store(x)
}
}
macro_rules! from_conversions_for_raw {
@ -534,47 +529,57 @@ from_conversions_for_raw!(
(f64, Self::F64),
);
/// Generic enumeration for additional parameters, including parameters which rely on heap
/// allocations.
#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
#[derive(Debug, Clone)]
pub enum Params {
mod alloc_mod {
use super::*;
/// 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),
Store(StoreAddr),
Vec(Vec<u8>),
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 {
Self::Heapless(x)
}
}
}
impl From<Vec<u8>> for Params {
impl From<Vec<u8>> for Params {
fn from(val: Vec<u8>) -> Self {
Self::Vec(val)
}
}
}
/// Converts a byte slice into the [Params::Vec] variant
impl From<&[u8]> for Params {
/// Converts a byte slice into the [Params::Vec] variant
impl From<&[u8]> for Params {
fn from(val: &[u8]) -> Self {
Self::Vec(val.to_vec())
}
}
}
impl From<String> for Params {
impl From<String> for Params {
fn from(val: String) -> Self {
Self::String(val)
}
}
}
/// Converts a string slice into the [Params::String] variant
impl From<&str> for Params {
/// Converts a string slice into the [Params::String] variant
impl From<&str> for Params {
fn from(val: &str) -> Self {
Self::String(val.to_string())
}
}
}
#[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 core::hash::Hash;
use hashbrown::HashSet;
@ -6,7 +9,12 @@ use hashbrown::HashSet;
#[cfg(feature = "alloc")]
pub use crate::pus::event::EventReporter;
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_attr(doc_cfg, doc(cfg(feature = "heapless")))]
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,
backend: Box<dyn PusEventMgmtBackendProvider<Provider, Error = BackendError>>,
}
}
/// Safety: All contained fields are send as well.
unsafe impl<E: Send, Event: GenericEvent + Send> Send for PusEventDispatcher<E, Event> {}
/// Safety: All contained fields are send as well.
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(
reporter: EventReporter,
backend: Box<dyn PusEventMgmtBackendProvider<Provider, Error = BackendError>>,
) -> Self {
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> {
self.backend.enable_event_reporting(event)
}
@ -192,9 +204,9 @@ impl<BackendError, Event: GenericEvent> PusEventDispatcher<BackendError, Event>
.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>(
&mut self,
event: &EventU32TypedSev<Severity>,
@ -218,8 +230,8 @@ impl<BackendError> PusEventDispatcher<BackendError, EventU32> {
) -> Result<bool, EventManError<E>> {
self.generate_pus_event_tm_generic(sender, time_stamp, event.into(), aux_data)
}
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

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

View File

@ -1,8 +1,10 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use spacepackets::ecss::{EcssEnumU16, EcssEnumeration};
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 {
group_id: u8,
unique_id: u8,

View File

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

View File

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

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