some fixes

This commit is contained in:
Robin Mueller
2025-10-16 19:18:58 +02:00
parent dc8b582aad
commit 45676fa192
4 changed files with 54 additions and 20 deletions

View File

@@ -1,7 +1,7 @@
use crate::pus::create_verification_reporter;
use crate::tmtc::sender::TmTcSender;
use log::info;
use satrs::event_man::{EventMessage, EventMessageU32};
use satrs::event_man_legacy::{EventMessage, EventMessageU32};
use satrs::pus::test::PusService17TestHandler;
use satrs::pus::verification::{FailParams, VerificationReporter, VerificationReportingProvider};
use satrs::pus::PartialPusHandlingError;

View File

@@ -70,7 +70,8 @@ pub enum ListenerKey {
All,
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct EventMessage<EventInstance> {
sender_id: ComponentId,
@@ -133,7 +134,7 @@ pub trait SenderMap<EventSenderInstance: EventSender<EventInstance>, EventInstan
/// * `SenderMapInstance`: [SenderMap] which maps channel IDs to send providers.
/// * `ListenerMapInstance`: [ListenerMap] which maps listener keys to channel IDs.
/// * `EventSenderInstance`: [EventSender] contained within the sender map which sends the events.
/// * `Event`: The event type. This type must implement the [Event] trait.
/// * `Event`: The event type. This type must implement the [Event] trait.
pub struct EventManager<
EventReceiverInstance: EventReceiver<EventInstance>,
SenderMapInstance: SenderMap<EventSenderInstance, EventInstance>,
@@ -279,9 +280,10 @@ impl<
if let Some(ids) = self.listener_map.get_listener_ids(key) {
for id in ids {
if let Some(sender) = self.sender_map.get_send_event_provider(id) {
if let Err(e) = sender
.send(EventMessage::new(event_msg.sender_id, event_msg.event.clone()))
{
if let Err(e) = sender.send(EventMessage::new(
event_msg.sender_id,
event_msg.event.clone(),
)) {
error_handler(event_msg, EventRoutingError::Send(e));
} else {
num_recipients += 1;
@@ -776,7 +778,10 @@ mod tests {
let event_0_erased = EventErasedAlloc::new(&event_0);
let event_1_erased = EventErasedAlloc::new(&event_1);
event_sender
.send(EventMessage::new(TEST_COMPONENT_ID_0.id(), event_0_erased.clone()))
.send(EventMessage::new(
TEST_COMPONENT_ID_0.id(),
event_0_erased.clone(),
))
.expect("Triggering Event 0 failed");
let res = event_man.try_event_handling(error_handler);
check_handled_event(res, &event_0_erased, 2, TEST_COMPONENT_ID_0.id());
@@ -784,10 +789,16 @@ mod tests {
check_next_event(event_0, &event_0_rx_1);
event_man.subscribe_group(event_1.id().group_id(), event_listener_0_sender_id);
event_sender
.send(EventMessage::new(TEST_COMPONENT_ID_0.id(), event_0_erased.clone()))
.send(EventMessage::new(
TEST_COMPONENT_ID_0.id(),
event_0_erased.clone(),
))
.expect("Triggering Event 0 failed");
event_sender
.send(EventMessage::new(TEST_COMPONENT_ID_1.id(), event_1_erased.clone()))
.send(EventMessage::new(
TEST_COMPONENT_ID_1.id(),
event_1_erased.clone(),
))
.expect("Triggering Event 1 failed");
// 3 Events messages will be sent now
@@ -803,7 +814,10 @@ mod tests {
event_man.subscribe_group(event_1.id().group_id(), event_listener_0_sender_id);
event_man.remove_duplicates(&ListenerKey::Group(event_1.id().group_id()));
event_sender
.send(EventMessage::new(TEST_COMPONENT_ID_0.id(), event_1_erased.clone()))
.send(EventMessage::new(
TEST_COMPONENT_ID_0.id(),
event_1_erased.clone(),
))
.expect("Triggering Event 1 failed");
let res = event_man.try_event_handling(error_handler);
check_handled_event(res, &event_1_erased, 1, TEST_COMPONENT_ID_0.id());
@@ -842,15 +856,27 @@ mod tests {
let test_event = TestEvent::Info;
let event_sender = EventSenderMpscBounded::<EventErasedAlloc>::new(1, event_sender, 3);
event_sender
.send(EventMessage::new(TEST_COMPONENT_ID_0.id(), test_event.into()))
.send(EventMessage::new(
TEST_COMPONENT_ID_0.id(),
test_event.into(),
))
.expect("sending test event failed");
event_sender
.send(EventMessage::new(TEST_COMPONENT_ID_0.id(), test_event.into()))
.send(EventMessage::new(
TEST_COMPONENT_ID_0.id(),
test_event.into(),
))
.expect("sending test event failed");
event_sender
.send(EventMessage::new(TEST_COMPONENT_ID_0.id(), test_event.into()))
.send(EventMessage::new(
TEST_COMPONENT_ID_0.id(),
test_event.into(),
))
.expect("sending test event failed");
let error = event_sender.send(EventMessage::new(TEST_COMPONENT_ID_0.id(), test_event.into()));
let error = event_sender.send(EventMessage::new(
TEST_COMPONENT_ID_0.id(),
test_event.into(),
));
if let Err(e) = error {
assert!(matches!(e, GenericSendError::QueueFull(Some(3))));
} else {
@@ -863,7 +889,10 @@ mod tests {
let test_event = TestEvent::Info;
let event_sender = EventSenderMpscBounded::<EventErasedAlloc>::new(1, event_sender, 3);
drop(event_receiver);
if let Err(e) = event_sender.send(EventMessage::new(TEST_COMPONENT_ID_0.id(), test_event.into())) {
if let Err(e) = event_sender.send(EventMessage::new(
TEST_COMPONENT_ID_0.id(),
test_event.into(),
)) {
assert!(matches!(e, GenericSendError::RxDisconnected));
} else {
panic!("Expected error");

View File

@@ -26,6 +26,7 @@ use core::fmt::Debug;
use core::hash::Hash;
use arbitrary_int::{prelude::*, u14};
#[cfg(feature = "heapless")]
use spacepackets::ByteConversionError;
/// Using a type definition allows to change this to u64 in the future more easily
@@ -61,7 +62,8 @@ pub type GroupId = u14;
/// Unique event identifier.
///
/// Consists of a group ID, a unique ID and the severity.
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, serde::Serialize, serde::Deserialize)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct EventId {
group_id: GroupId,
@@ -160,17 +162,20 @@ impl Event for EventErasedAlloc {
/// Event which was type erased and serialized into a [heapless::vec::Vec].
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg(feature = "heapless")]
pub struct EventErasedHeapless<const N: usize> {
id: EventId,
event_raw: heapless::vec::Vec<u8, N>,
}
#[cfg(feature = "heapless")]
impl<const N: usize> Event for EventErasedHeapless<N> {
fn id(&self) -> EventId {
self.id
}
}
#[cfg(feature = "heapless")]
impl<const N: usize> EventErasedHeapless<N> {
#[cfg(feature = "serde")]
/// Creates a new event by serializing the given event using [postcard].

View File

@@ -15,21 +15,21 @@
//! the [ECSS PUS C standard](https://ecss.nl/standard/ecss-e-st-70-41c-space-engineering-telemetry-and-telecommand-packet-utilization-15-april-2016/).
#![no_std]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#[cfg(any(feature = "alloc", test))]
extern crate alloc;
#[cfg(feature = "alloc")]
extern crate downcast_rs;
#[cfg(any(feature = "std", test))]
extern crate std;
#[cfg(any(feature = "alloc", test))]
extern crate alloc;
pub mod action;
#[cfg(feature = "alloc")]
pub mod dev_mgmt;
pub mod encoding;
pub mod event_man_legacy;
pub mod event_man;
pub mod events_legacy;
pub mod event_man_legacy;
pub mod events;
pub mod events_legacy;
#[cfg(feature = "std")]
pub mod executable;
pub mod hal;