I don't think channel IDs are required anymore
Some checks failed
Rust/sat-rs/pipeline/pr-main There was a failure building this commit

This commit is contained in:
2024-03-21 17:12:30 +01:00
parent f5e56c5bf8
commit 73291908f6
22 changed files with 310 additions and 252 deletions

View File

@ -11,7 +11,7 @@
//! about events first:
//!
//! The event manager has a listener table abstracted by the [ListenerMapProvider], which maps
//! listener groups identified by [ListenerKey]s to a [sender ID][ChannelId].
//! listener groups identified by [ListenerKey]s to a [sender ID][ComponentId].
//! It also contains a sender table abstracted by the [SenderMapProvider] which maps these sender
//! IDs to concrete [EventSendProvider]s. A simple approach would be to use one send event provider
//! for each OBSW thread and then subscribe for all interesting events for a particular thread
@ -50,7 +50,7 @@ use crate::queue::GenericSendError;
use core::marker::PhantomData;
use core::slice::Iter;
use crate::ChannelId;
use crate::ComponentId;
#[cfg(feature = "alloc")]
pub use alloc_mod::*;
@ -74,7 +74,7 @@ pub type EventU32WithAuxData = EventWithAuxData<EventU32>;
pub type EventU16WithAuxData = EventWithAuxData<EventU16>;
pub trait EventSendProvider<EV: GenericEvent, AuxDataProvider = Params> {
fn channel_id(&self) -> ChannelId;
fn target_id(&self) -> ComponentId;
fn send_no_data(&self, event: EV) -> Result<(), GenericSendError> {
self.send(event, None)
@ -95,8 +95,8 @@ pub trait ListenerMapProvider {
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
fn get_listeners(&self) -> alloc::vec::Vec<ListenerKey>;
fn contains_listener(&self, key: &ListenerKey) -> bool;
fn get_listener_ids(&self, key: &ListenerKey) -> Option<Iter<ChannelId>>;
fn add_listener(&mut self, key: ListenerKey, sender_id: ChannelId) -> bool;
fn get_listener_ids(&self, key: &ListenerKey) -> Option<Iter<ComponentId>>;
fn add_listener(&mut self, key: ListenerKey, sender_id: ComponentId) -> bool;
fn remove_duplicates(&mut self, key: &ListenerKey);
}
@ -106,9 +106,9 @@ pub trait SenderMapProvider<
Data = Params,
>
{
fn contains_send_event_provider(&self, id: &ChannelId) -> bool;
fn contains_send_event_provider(&self, target_id: &ComponentId) -> bool;
fn get_send_event_provider(&self, id: &ChannelId) -> Option<&EventSender>;
fn get_send_event_provider(&self, target_id: &ComponentId) -> Option<&EventSender>;
fn add_send_event_provider(&mut self, send_provider: EventSender) -> bool;
}
@ -153,7 +153,7 @@ pub enum EventRoutingResult<EV: GenericEvent, AUX> {
pub enum EventRoutingError {
Send(GenericSendError),
NoSendersForKey(ListenerKey),
NoSenderForId(ChannelId),
NoSenderForId(ComponentId),
}
#[derive(Debug)]
@ -176,12 +176,12 @@ impl<
}
/// Subscribe for a unique event.
pub fn subscribe_single(&mut self, event: &Ev, sender_id: ChannelId) {
pub fn subscribe_single(&mut self, event: &Ev, sender_id: ComponentId) {
self.update_listeners(ListenerKey::Single(event.raw_as_largest_type()), sender_id);
}
/// Subscribe for an event group.
pub fn subscribe_group(&mut self, group_id: LargestGroupIdRaw, sender_id: ChannelId) {
pub fn subscribe_group(&mut self, group_id: LargestGroupIdRaw, sender_id: ComponentId) {
self.update_listeners(ListenerKey::Group(group_id), sender_id);
}
@ -189,7 +189,7 @@ impl<
///
/// For example, this can be useful for a handler component which sends every event as
/// a telemetry packet.
pub fn subscribe_all(&mut self, sender_id: ChannelId) {
pub fn subscribe_all(&mut self, sender_id: ComponentId) {
self.update_listeners(ListenerKey::All, sender_id);
}
}
@ -216,14 +216,14 @@ impl<
pub fn add_sender(&mut self, send_provider: SP) {
if !self
.sender_map
.contains_send_event_provider(&send_provider.channel_id())
.contains_send_event_provider(&send_provider.target_id())
{
self.sender_map.add_send_event_provider(send_provider);
}
}
/// Generic function to update the event subscribers.
fn update_listeners(&mut self, key: ListenerKey, sender_id: ChannelId) {
fn update_listeners(&mut self, key: ListenerKey, sender_id: ComponentId) {
self.listener_map.add_listener(key, sender_id);
}
@ -342,7 +342,7 @@ pub mod alloc_mod {
/// Simple implementation which uses a [HashMap] and a [Vec] internally.
#[derive(Default)]
pub struct DefaultListenerMap {
listeners: HashMap<ListenerKey, Vec<ChannelId>>,
listeners: HashMap<ListenerKey, Vec<ComponentId>>,
}
impl ListenerMapProvider for DefaultListenerMap {
@ -358,11 +358,11 @@ pub mod alloc_mod {
self.listeners.contains_key(key)
}
fn get_listener_ids(&self, key: &ListenerKey) -> Option<Iter<ChannelId>> {
fn get_listener_ids(&self, key: &ListenerKey) -> Option<Iter<ComponentId>> {
self.listeners.get(key).map(|vec| vec.iter())
}
fn add_listener(&mut self, key: ListenerKey, sender_id: ChannelId) -> bool {
fn add_listener(&mut self, key: ListenerKey, sender_id: ComponentId) -> bool {
if let Some(existing_list) = self.listeners.get_mut(&key) {
existing_list.push(sender_id);
} else {
@ -388,7 +388,7 @@ pub mod alloc_mod {
EV: GenericEvent = EventU32,
AUX = Params,
> {
senders: HashMap<ChannelId, SP>,
senders: HashMap<ComponentId, SP>,
phantom: PhantomData<(EV, AUX)>,
}
@ -406,18 +406,18 @@ pub mod alloc_mod {
impl<SP: EventSendProvider<EV, AUX>, EV: GenericEvent, AUX> SenderMapProvider<SP, EV, AUX>
for DefaultSenderMap<SP, EV, AUX>
{
fn contains_send_event_provider(&self, id: &ChannelId) -> bool {
fn contains_send_event_provider(&self, id: &ComponentId) -> bool {
self.senders.contains_key(id)
}
fn get_send_event_provider(&self, id: &ChannelId) -> Option<&SP> {
fn get_send_event_provider(&self, id: &ComponentId) -> Option<&SP> {
self.senders
.get(id)
.filter(|sender| sender.channel_id() == *id)
.filter(|sender| sender.target_id() == *id)
}
fn add_send_event_provider(&mut self, send_provider: SP) -> bool {
let id = send_provider.channel_id();
let id = send_provider.target_id();
if self.senders.contains_key(&id) {
return false;
}
@ -458,19 +458,19 @@ pub mod std_mod {
/// send events.
#[derive(Clone)]
pub struct EventSenderMpsc<Event: GenericEvent + Send> {
id: u32,
target_id: ComponentId,
sender: mpsc::Sender<(Event, Option<Params>)>,
}
impl<Event: GenericEvent + Send> EventSenderMpsc<Event> {
pub fn new(id: u32, sender: mpsc::Sender<(Event, Option<Params>)>) -> Self {
Self { id, sender }
pub fn new(target_id: ComponentId, sender: mpsc::Sender<(Event, Option<Params>)>) -> Self {
Self { target_id, sender }
}
}
impl<Event: GenericEvent + Send> EventSendProvider<Event> for EventSenderMpsc<Event> {
fn channel_id(&self) -> u32 {
self.id
fn target_id(&self) -> ComponentId {
self.target_id
}
fn send(&self, event: Event, aux_data: Option<Params>) -> Result<(), GenericSendError> {
self.sender
@ -483,19 +483,19 @@ pub mod std_mod {
/// events. This has the advantage that the channel is bounded and thus more deterministic.
#[derive(Clone)]
pub struct EventSenderMpscBounded<Event: GenericEvent + Send> {
channel_id: u32,
target_id: ComponentId,
sender: mpsc::SyncSender<(Event, Option<Params>)>,
capacity: usize,
}
impl<Event: GenericEvent + Send> EventSenderMpscBounded<Event> {
pub fn new(
channel_id: u32,
target_id: ComponentId,
sender: mpsc::SyncSender<(Event, Option<Params>)>,
capacity: usize,
) -> Self {
Self {
channel_id,
target_id,
sender,
capacity,
}
@ -503,8 +503,8 @@ pub mod std_mod {
}
impl<Event: GenericEvent + Send> EventSendProvider<Event> for EventSenderMpscBounded<Event> {
fn channel_id(&self) -> u32 {
self.channel_id
fn target_id(&self) -> ComponentId {
self.target_id
}
fn send(&self, event: Event, aux_data: Option<Params>) -> Result<(), GenericSendError> {
if let Err(e) = self.sender.try_send((event, aux_data)) {
@ -577,11 +577,11 @@ mod tests {
let event_grp_1_0 = EventU32::new(Severity::HIGH, 1, 0).unwrap();
let (single_event_sender, single_event_receiver) = channel();
let single_event_listener = EventSenderMpsc::new(0, single_event_sender);
event_man.subscribe_single(&event_grp_0, single_event_listener.channel_id());
event_man.subscribe_single(&event_grp_0, single_event_listener.target_id());
event_man.add_sender(single_event_listener);
let (group_event_sender_0, group_event_receiver_0) = channel();
let group_event_listener = EventU32SenderMpsc::new(1, group_event_sender_0);
event_man.subscribe_group(event_grp_1_0.group_id(), group_event_listener.channel_id());
event_man.subscribe_group(event_grp_1_0.group_id(), group_event_listener.target_id());
event_man.add_sender(group_event_listener);
// Test event with one listener
@ -609,7 +609,7 @@ mod tests {
let event_grp_0 = EventU32::new(Severity::INFO, 0, 0).unwrap();
let (single_event_sender, single_event_receiver) = channel();
let single_event_listener = EventSenderMpsc::new(0, single_event_sender);
event_man.subscribe_single(&event_grp_0, single_event_listener.channel_id());
event_man.subscribe_single(&event_grp_0, single_event_listener.target_id());
event_man.add_sender(single_event_listener);
event_sender
.send((event_grp_0, Some(Params::Heapless((2_u32, 3_u32).into()))))
@ -643,11 +643,11 @@ mod tests {
let event_grp_0_and_1_listener = EventU32SenderMpsc::new(0, event_grp_0_sender);
event_man.subscribe_group(
event_grp_0.group_id(),
event_grp_0_and_1_listener.channel_id(),
event_grp_0_and_1_listener.target_id(),
);
event_man.subscribe_group(
event_grp_1_0.group_id(),
event_grp_0_and_1_listener.channel_id(),
event_grp_0_and_1_listener.target_id(),
);
event_man.add_sender(event_grp_0_and_1_listener);
@ -679,10 +679,10 @@ mod tests {
let (event_0_tx_1, event_0_rx_1) = channel();
let event_listener_0 = EventU32SenderMpsc::new(0, event_0_tx_0);
let event_listener_1 = EventU32SenderMpsc::new(1, event_0_tx_1);
let event_listener_0_sender_id = event_listener_0.channel_id();
let event_listener_0_sender_id = event_listener_0.target_id();
event_man.subscribe_single(&event_0, event_listener_0_sender_id);
event_man.add_sender(event_listener_0);
let event_listener_1_sender_id = event_listener_1.channel_id();
let event_listener_1_sender_id = event_listener_1.target_id();
event_man.subscribe_single(&event_0, event_listener_1_sender_id);
event_man.add_sender(event_listener_1);
event_sender
@ -732,7 +732,7 @@ mod tests {
let event_1 = EventU32::new(Severity::HIGH, 1, 0).unwrap();
let (event_0_tx_0, all_events_rx) = channel();
let all_events_listener = EventU32SenderMpsc::new(0, event_0_tx_0);
event_man.subscribe_all(all_events_listener.channel_id());
event_man.subscribe_all(all_events_listener.target_id());
event_man.add_sender(all_events_listener);
event_sender
.send((event_0, None))

View File

@ -13,7 +13,7 @@ pub use std_mod::*;
use crate::{
queue::GenericTargetedMessagingError,
request::{GenericMessage, MessageReceiver, MessageReceiverWithId, RequestId},
ChannelId, ComponentId,
ComponentId,
};
pub type Mode = u32;
@ -140,11 +140,11 @@ pub enum ModeReply {
pub type GenericModeReply = GenericMessage<ModeReply>;
pub trait ModeRequestSender {
fn local_channel_id(&self) -> ChannelId;
fn local_channel_id(&self) -> ComponentId;
fn send_mode_request(
&self,
request_id: RequestId,
target_id: ChannelId,
target_id: ComponentId,
request: ModeRequest,
) -> Result<(), GenericTargetedMessagingError>;
}
@ -184,11 +184,11 @@ pub trait ModeRequestHandler: ModeProvider {
fn start_transition(
&mut self,
request_id: RequestId,
sender_id: ChannelId,
sender_id: ComponentId,
mode_and_submode: ModeAndSubmode,
) -> Result<(), ModeError>;
fn announce_mode(&self, request_id: RequestId, sender_id: ChannelId, recursive: bool);
fn announce_mode(&self, request_id: RequestId, sender_id: ComponentId, recursive: bool);
fn handle_mode_reached(&mut self) -> Result<(), GenericTargetedMessagingError>;
}
@ -207,12 +207,12 @@ impl<R: MessageReceiver<ModeReply>> ModeReplyReceiver for MessageReceiverWithId<
}
pub trait ModeReplySender {
fn local_channel_id(&self) -> ChannelId;
fn local_channel_id(&self) -> ComponentId;
fn send_mode_reply(
&self,
request_id: RequestId,
target_id: ChannelId,
target_id: ComponentId,
reply: ModeReply,
) -> Result<(), GenericTargetedMessagingError>;
}
@ -227,7 +227,7 @@ pub mod alloc_mod {
MessageSender, MessageSenderAndReceiver, MessageSenderMap, MessageSenderMapWithId,
RequestAndReplySenderAndReceiver, RequestId,
},
ChannelId,
ComponentId,
};
use super::*;
@ -236,14 +236,14 @@ pub mod alloc_mod {
pub fn send_mode_reply(
&self,
request_id: RequestId,
local_id: ChannelId,
target_id: ChannelId,
local_id: ComponentId,
target_id: ComponentId,
request: ModeReply,
) -> Result<(), GenericTargetedMessagingError> {
self.send_message(request_id, local_id, target_id, request)
}
pub fn add_reply_target(&mut self, target_id: ChannelId, request_sender: S) {
pub fn add_reply_target(&mut self, target_id: ComponentId, request_sender: S) {
self.add_message_target(target_id, request_sender)
}
}
@ -252,13 +252,13 @@ pub mod alloc_mod {
fn send_mode_reply(
&self,
request_id: RequestId,
target_channel_id: ChannelId,
target_channel_id: ComponentId,
reply: ModeReply,
) -> Result<(), GenericTargetedMessagingError> {
self.send_message(request_id, target_channel_id, reply)
}
fn local_channel_id(&self) -> ChannelId {
fn local_channel_id(&self) -> ComponentId {
self.local_channel_id
}
}
@ -266,14 +266,14 @@ pub mod alloc_mod {
impl<FROM, S: MessageSender<ModeReply>, R: MessageReceiver<FROM>> ModeReplySender
for MessageSenderAndReceiver<ModeReply, FROM, S, R>
{
fn local_channel_id(&self) -> ChannelId {
fn local_channel_id(&self) -> ComponentId {
self.local_channel_id_generic()
}
fn send_mode_reply(
&self,
request_id: RequestId,
target_id: ChannelId,
target_id: ComponentId,
request: ModeReply,
) -> Result<(), GenericTargetedMessagingError> {
self.message_sender_map.send_mode_reply(
@ -303,7 +303,7 @@ pub mod alloc_mod {
R1: MessageReceiver<REQUEST>,
> RequestAndReplySenderAndReceiver<REQUEST, ModeReply, S0, R0, S1, R1>
{
pub fn add_reply_target(&mut self, target_id: ChannelId, reply_sender: S1) {
pub fn add_reply_target(&mut self, target_id: ComponentId, reply_sender: S1) {
self.reply_sender_map
.add_message_target(target_id, reply_sender)
}
@ -317,14 +317,14 @@ pub mod alloc_mod {
R1: MessageReceiver<REQUEST>,
> ModeReplySender for RequestAndReplySenderAndReceiver<REQUEST, ModeReply, S0, R0, S1, R1>
{
fn local_channel_id(&self) -> ChannelId {
fn local_channel_id(&self) -> ComponentId {
self.local_channel_id_generic()
}
fn send_mode_reply(
&self,
request_id: RequestId,
target_id: ChannelId,
target_id: ComponentId,
request: ModeReply,
) -> Result<(), GenericTargetedMessagingError> {
self.reply_sender_map.send_mode_reply(
@ -368,7 +368,7 @@ pub mod alloc_mod {
pub fn send_mode_reply(
&self,
request_id: RequestId,
target_id: ChannelId,
target_id: ComponentId,
reply: ModeReply,
) -> Result<(), GenericTargetedMessagingError> {
self.send_message(request_id, target_id, reply)
@ -389,7 +389,7 @@ pub mod alloc_mod {
pub fn send_mode_request(
&self,
request_id: RequestId,
target_id: ChannelId,
target_id: ComponentId,
reply: ModeRequest,
) -> Result<(), GenericTargetedMessagingError> {
self.send_message(request_id, target_id, reply)
@ -405,27 +405,27 @@ pub mod alloc_mod {
pub fn send_mode_request(
&self,
request_id: RequestId,
local_id: ChannelId,
target_id: ChannelId,
local_id: ComponentId,
target_id: ComponentId,
request: ModeRequest,
) -> Result<(), GenericTargetedMessagingError> {
self.send_message(request_id, local_id, target_id, request)
}
pub fn add_request_target(&mut self, target_id: ChannelId, request_sender: S) {
pub fn add_request_target(&mut self, target_id: ComponentId, request_sender: S) {
self.add_message_target(target_id, request_sender)
}
}
impl<S: MessageSender<ModeRequest>> ModeRequestSender for MessageSenderMapWithId<ModeRequest, S> {
fn local_channel_id(&self) -> ChannelId {
fn local_channel_id(&self) -> ComponentId {
self.local_channel_id
}
fn send_mode_request(
&self,
request_id: RequestId,
target_id: ChannelId,
target_id: ComponentId,
request: ModeRequest,
) -> Result<(), GenericTargetedMessagingError> {
self.send_message(request_id, target_id, request)
@ -445,14 +445,14 @@ pub mod alloc_mod {
impl<FROM, S: MessageSender<ModeRequest>, R: MessageReceiver<FROM>> ModeRequestSender
for MessageSenderAndReceiver<ModeRequest, FROM, S, R>
{
fn local_channel_id(&self) -> ChannelId {
fn local_channel_id(&self) -> ComponentId {
self.local_channel_id_generic()
}
fn send_mode_request(
&self,
request_id: RequestId,
target_id: ChannelId,
target_id: ComponentId,
request: ModeRequest,
) -> Result<(), GenericTargetedMessagingError> {
self.message_sender_map.send_mode_request(
@ -472,7 +472,7 @@ pub mod alloc_mod {
R1: MessageReceiver<ModeRequest>,
> RequestAndReplySenderAndReceiver<ModeRequest, REPLY, S0, R0, S1, R1>
{
pub fn add_request_target(&mut self, target_id: ChannelId, request_sender: S0) {
pub fn add_request_target(&mut self, target_id: ComponentId, request_sender: S0) {
self.request_sender_map
.add_message_target(target_id, request_sender)
}
@ -487,14 +487,14 @@ pub mod alloc_mod {
> ModeRequestSender
for RequestAndReplySenderAndReceiver<ModeRequest, REPLY, S0, R0, S1, R1>
{
fn local_channel_id(&self) -> ChannelId {
fn local_channel_id(&self) -> ComponentId {
self.local_channel_id_generic()
}
fn send_mode_request(
&self,
request_id: RequestId,
target_id: ChannelId,
target_id: ComponentId,
request: ModeRequest,
) -> Result<(), GenericTargetedMessagingError> {
self.request_sender_map.send_mode_request(

View File

@ -3,7 +3,7 @@ use hashbrown::HashMap;
use crate::{
mode::{Mode, ModeAndSubmode, Submode},
ChannelId,
ComponentId,
};
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
@ -19,7 +19,7 @@ pub struct ModeTableEntry {
/// Name of respective table entry.
pub name: &'static str,
/// Target channel ID.
pub channel_id: ChannelId,
pub channel_id: ComponentId,
pub mode_submode: ModeAndSubmode,
pub allowed_submode_mask: Option<Submode>,
pub check_success: bool,

View File

@ -2,7 +2,7 @@ use crate::{
action::{ActionId, ActionRequest},
params::Params,
request::{GenericMessage, RequestId},
ChannelId,
ComponentId,
};
use super::{verification::VerificationToken, ActivePusRequestStd, ActiveRequestProvider};
@ -61,7 +61,7 @@ pub type GenericActionReplyPus = GenericMessage<ActionReplyPusWithActionId>;
impl GenericActionReplyPus {
pub fn new_action_reply(
request_id: RequestId,
sender_id: ChannelId,
sender_id: ComponentId,
action_id: ActionId,
reply: ActionReplyPus,
) -> Self {
@ -82,7 +82,7 @@ pub mod alloc_mod {
request::{
GenericMessage, MessageReceiver, MessageSender, MessageSenderAndReceiver, RequestId,
},
ChannelId,
ComponentId,
};
use super::ActionReplyPusWithActionId;
@ -103,7 +103,7 @@ pub mod alloc_mod {
pub fn send_action_reply(
&self,
request_id: RequestId,
target_id: ChannelId,
target_id: ComponentId,
reply: ActionReplyPusWithActionId,
) -> Result<(), GenericTargetedMessagingError> {
self.send_message(request_id, target_id, reply)
@ -128,7 +128,7 @@ pub mod alloc_mod {
pub fn send_action_request(
&self,
request_id: RequestId,
target_id: ChannelId,
target_id: ComponentId,
request: ActionRequest,
) -> Result<(), GenericTargetedMessagingError> {
self.send_message(request_id, target_id, request)

View File

@ -244,7 +244,7 @@ mod tests {
use crate::events::{EventU32, Severity};
use crate::pus::tests::CommonTmInfo;
use crate::pus::{EcssChannel, PusTmWrapper};
use crate::ChannelId;
use crate::ComponentId;
use spacepackets::ByteConversionError;
use std::cell::RefCell;
use std::collections::VecDeque;
@ -269,7 +269,7 @@ mod tests {
}
impl EcssChannel for TestSender {
fn channel_id(&self) -> ChannelId {
fn channel_id(&self) -> ComponentId {
0
}
}

View File

@ -6,7 +6,7 @@ use crate::pool::{StoreAddr, StoreError};
use crate::pus::verification::{TcStateAccepted, TcStateToken, VerificationToken};
use crate::queue::{GenericReceiveError, GenericSendError};
use crate::request::{GenericMessage, RequestId};
use crate::{ChannelId, ComponentId};
use crate::ComponentId;
use core::fmt::{Display, Formatter};
use core::time::Duration;
#[cfg(feature = "alloc")]
@ -144,7 +144,7 @@ impl Error for EcssTmtcError {
}
pub trait EcssChannel: Send {
/// Each sender can have an ID associated with it
fn channel_id(&self) -> ChannelId;
fn channel_id(&self) -> ComponentId;
fn name(&self) -> &'static str {
"unset"
}
@ -301,6 +301,7 @@ pub trait PusRequestRouter<Request> {
fn route(
&self,
target_id: ComponentId,
request_id: RequestId,
request: Request,
token: VerificationToken<TcStateStarted>,
) -> Result<(), Self::Error>;
@ -649,7 +650,7 @@ pub mod std_mod {
GenericReceiveError, GenericSendError, PusTmWrapper, TryRecvTmtcError,
};
use crate::tmtc::tm_helper::SharedTmPool;
use crate::{ChannelId, ComponentId};
use crate::ComponentId;
use alloc::vec::Vec;
use core::time::Duration;
use spacepackets::ecss::tc::PusTcReader;
@ -724,14 +725,14 @@ pub mod std_mod {
#[derive(Clone)]
pub struct TmInSharedPoolSenderWithId<Sender: EcssTmSenderCore> {
channel_id: ChannelId,
channel_id: ComponentId,
name: &'static str,
shared_tm_store: SharedTmPool,
sender: Sender,
}
impl<Sender: EcssTmSenderCore> EcssChannel for TmInSharedPoolSenderWithId<Sender> {
fn channel_id(&self) -> ChannelId {
fn channel_id(&self) -> ComponentId {
self.channel_id
}
@ -758,7 +759,7 @@ pub mod std_mod {
impl<Sender: EcssTmSenderCore> TmInSharedPoolSenderWithId<Sender> {
pub fn new(
id: ChannelId,
id: ComponentId,
name: &'static str,
shared_tm_store: SharedTmPool,
sender: Sender,
@ -782,7 +783,7 @@ pub mod std_mod {
/// going to be called with direct packets.
#[derive(Clone)]
pub struct TmAsVecSenderWithId<Sender: EcssTmSenderCore> {
id: ChannelId,
id: ComponentId,
name: &'static str,
sender: Sender,
}
@ -794,13 +795,13 @@ pub mod std_mod {
}
impl<Sender: EcssTmSenderCore> TmAsVecSenderWithId<Sender> {
pub fn new(id: u32, name: &'static str, sender: Sender) -> Self {
pub fn new(id: ComponentId, name: &'static str, sender: Sender) -> Self {
Self { id, sender, name }
}
}
impl<Sender: EcssTmSenderCore> EcssChannel for TmAsVecSenderWithId<Sender> {
fn channel_id(&self) -> ChannelId {
fn channel_id(&self) -> ComponentId {
self.id
}
fn name(&self) -> &'static str {
@ -818,13 +819,13 @@ pub mod std_mod {
pub type TmAsVecSenderWithBoundedMpsc = TmAsVecSenderWithId<mpsc::SyncSender<Vec<u8>>>;
pub struct MpscTcReceiver {
id: ChannelId,
id: ComponentId,
name: &'static str,
receiver: mpsc::Receiver<EcssTcAndToken>,
}
impl EcssChannel for MpscTcReceiver {
fn channel_id(&self) -> ChannelId {
fn channel_id(&self) -> ComponentId {
self.id
}
@ -846,7 +847,7 @@ pub mod std_mod {
impl MpscTcReceiver {
pub fn new(
id: ChannelId,
id: ComponentId,
name: &'static str,
receiver: mpsc::Receiver<EcssTcAndToken>,
) -> Self {
@ -903,14 +904,14 @@ pub mod std_mod {
}
pub struct CrossbeamTcReceiver {
id: ChannelId,
id: ComponentId,
name: &'static str,
receiver: cb::Receiver<EcssTcAndToken>,
}
impl CrossbeamTcReceiver {
pub fn new(
id: ChannelId,
id: ComponentId,
name: &'static str,
receiver: cb::Receiver<EcssTcAndToken>,
) -> Self {
@ -919,7 +920,7 @@ pub mod std_mod {
}
impl EcssChannel for CrossbeamTcReceiver {
fn channel_id(&self) -> ChannelId {
fn channel_id(&self) -> ComponentId {
self.id
}

View File

@ -1443,7 +1443,7 @@ pub mod tests {
EcssChannel, PusTmWrapper, TmInSharedPoolSenderWithId, TmInSharedPoolSenderWithMpsc,
};
use crate::tmtc::tm_helper::SharedTmPool;
use crate::ChannelId;
use crate::ComponentId;
use alloc::format;
use alloc::sync::Arc;
use hashbrown::HashMap;
@ -1708,7 +1708,7 @@ pub mod tests {
}
impl EcssChannel for TestSender {
fn channel_id(&self) -> ChannelId {
fn channel_id(&self) -> ComponentId {
0
}
fn name(&self) -> &'static str {

View File

@ -4,6 +4,8 @@ use std::error::Error;
#[cfg(feature = "std")]
use std::sync::mpsc;
use crate::ComponentId;
/// Generic channel ID type.
pub type ChannelId = u32;
@ -12,7 +14,7 @@ pub type ChannelId = u32;
pub enum GenericSendError {
RxDisconnected,
QueueFull(Option<u32>),
TargetDoesNotExist(ChannelId),
TargetDoesNotExist(ComponentId),
}
impl Display for GenericSendError {
@ -38,7 +40,7 @@ impl Error for GenericSendError {}
#[derive(Debug, Copy, Clone)]
pub enum GenericReceiveError {
Empty,
TxDisconnected(Option<ChannelId>),
TxDisconnected(Option<ComponentId>),
}
impl Display for GenericReceiveError {

View File

@ -15,7 +15,7 @@ use spacepackets::{
ByteConversionError, CcsdsPacket,
};
use crate::{queue::GenericTargetedMessagingError, ChannelId, ComponentId};
use crate::{queue::GenericTargetedMessagingError, ComponentId};
/// Generic request ID type. Requests can be associated with an ID to have a unique identifier
/// for them. This can be useful for tasks like tracking their progress.
@ -91,13 +91,13 @@ impl fmt::Display for TargetAndApidId {
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct GenericMessage<MSG> {
pub sender_id: ChannelId,
pub request_id: RequestId,
pub sender_id: ComponentId,
pub message: MSG,
}
impl<MSG> GenericMessage<MSG> {
pub fn new(request_id: RequestId, sender_id: ChannelId, message: MSG) -> Self {
pub fn new(request_id: RequestId, sender_id: ComponentId, message: MSG) -> Self {
Self {
request_id,
sender_id,
@ -133,19 +133,19 @@ impl<MSG, R: MessageReceiver<MSG>> MessageWithSenderIdReceiver<MSG, R> {
}
pub struct MessageReceiverWithId<MSG, R: MessageReceiver<MSG>> {
local_channel_id: ChannelId,
local_channel_id: ComponentId,
reply_receiver: MessageWithSenderIdReceiver<MSG, R>,
}
impl<MSG, R: MessageReceiver<MSG>> MessageReceiverWithId<MSG, R> {
pub fn new(local_channel_id: ChannelId, reply_receiver: R) -> Self {
pub fn new(local_channel_id: ComponentId, reply_receiver: R) -> Self {
Self {
local_channel_id,
reply_receiver: MessageWithSenderIdReceiver::from(reply_receiver),
}
}
pub fn local_channel_id(&self) -> ChannelId {
pub fn local_channel_id(&self) -> ComponentId {
self.local_channel_id
}
}
@ -169,7 +169,7 @@ pub mod alloc_mod {
use hashbrown::HashMap;
pub struct MessageSenderMap<MSG, S: MessageSender<MSG>>(
pub HashMap<ChannelId, S>,
pub HashMap<ComponentId, S>,
pub(crate) PhantomData<MSG>,
);
@ -180,15 +180,15 @@ pub mod alloc_mod {
}
impl<MSG, S: MessageSender<MSG>> MessageSenderMap<MSG, S> {
pub fn add_message_target(&mut self, target_id: ChannelId, message_sender: S) {
pub fn add_message_target(&mut self, target_id: ComponentId, message_sender: S) {
self.0.insert(target_id, message_sender);
}
pub fn send_message(
&self,
request_id: RequestId,
local_channel_id: ChannelId,
target_channel_id: ChannelId,
local_channel_id: ComponentId,
target_channel_id: ComponentId,
message: MSG,
) -> Result<(), GenericTargetedMessagingError> {
if self.0.contains_key(&target_channel_id) {
@ -203,12 +203,12 @@ pub mod alloc_mod {
}
pub struct MessageSenderMapWithId<MSG, S: MessageSender<MSG>> {
pub local_channel_id: ChannelId,
pub local_channel_id: ComponentId,
pub message_sender_map: MessageSenderMap<MSG, S>,
}
impl<MSG, S: MessageSender<MSG>> MessageSenderMapWithId<MSG, S> {
pub fn new(local_channel_id: ChannelId) -> Self {
pub fn new(local_channel_id: ComponentId) -> Self {
Self {
local_channel_id,
message_sender_map: Default::default(),
@ -218,7 +218,7 @@ pub mod alloc_mod {
pub fn send_message(
&self,
request_id: RequestId,
target_channel_id: ChannelId,
target_channel_id: ComponentId,
message: MSG,
) -> Result<(), GenericTargetedMessagingError> {
self.message_sender_map.send_message(
@ -229,14 +229,14 @@ pub mod alloc_mod {
)
}
pub fn add_message_target(&mut self, target_id: ChannelId, message_sender: S) {
pub fn add_message_target(&mut self, target_id: ComponentId, message_sender: S) {
self.message_sender_map
.add_message_target(target_id, message_sender)
}
}
pub struct MessageSenderAndReceiver<TO, FROM, S: MessageSender<TO>, R: MessageReceiver<FROM>> {
pub local_channel_id: ChannelId,
pub local_channel_id: ComponentId,
pub message_sender_map: MessageSenderMap<TO, S>,
pub message_receiver: MessageWithSenderIdReceiver<FROM, R>,
}
@ -244,7 +244,7 @@ pub mod alloc_mod {
impl<TO, FROM, S: MessageSender<TO>, R: MessageReceiver<FROM>>
MessageSenderAndReceiver<TO, FROM, S, R>
{
pub fn new(local_channel_id: ChannelId, message_receiver: R) -> Self {
pub fn new(local_channel_id: ComponentId, message_receiver: R) -> Self {
Self {
local_channel_id,
message_sender_map: Default::default(),
@ -252,12 +252,12 @@ pub mod alloc_mod {
}
}
pub fn add_message_target(&mut self, target_id: ChannelId, message_sender: S) {
pub fn add_message_target(&mut self, target_id: ComponentId, message_sender: S) {
self.message_sender_map
.add_message_target(target_id, message_sender)
}
pub fn local_channel_id_generic(&self) -> ChannelId {
pub fn local_channel_id_generic(&self) -> ComponentId {
self.local_channel_id
}
@ -265,7 +265,7 @@ pub mod alloc_mod {
pub fn send_message(
&self,
request_id: RequestId,
target_channel_id: ChannelId,
target_channel_id: ComponentId,
message: TO,
) -> Result<(), GenericTargetedMessagingError> {
self.message_sender_map.send_message(
@ -292,7 +292,7 @@ pub mod alloc_mod {
S1: MessageSender<REPLY>,
R1: MessageReceiver<REQUEST>,
> {
pub local_channel_id: ChannelId,
pub local_channel_id: ComponentId,
// These 2 are a functional group.
pub request_sender_map: MessageSenderMap<REQUEST, S0>,
pub reply_receiver: MessageWithSenderIdReceiver<REPLY, R0>,
@ -310,7 +310,11 @@ pub mod alloc_mod {
R1: MessageReceiver<REQUEST>,
> RequestAndReplySenderAndReceiver<REQUEST, REPLY, S0, R0, S1, R1>
{
pub fn new(local_channel_id: ChannelId, request_receiver: R1, reply_receiver: R0) -> Self {
pub fn new(
local_channel_id: ComponentId,
request_receiver: R1,
reply_receiver: R0,
) -> Self {
Self {
local_channel_id,
request_receiver: request_receiver.into(),
@ -320,7 +324,7 @@ pub mod alloc_mod {
}
}
pub fn local_channel_id_generic(&self) -> ChannelId {
pub fn local_channel_id_generic(&self) -> ComponentId {
self.local_channel_id
}
}
@ -390,9 +394,9 @@ mod tests {
use super::{GenericMessage, MessageReceiverWithId, MessageSenderMapWithId, TargetAndApidId};
const TEST_CHANNEL_ID_0: u32 = 1;
const TEST_CHANNEL_ID_1: u32 = 2;
const TEST_CHANNEL_ID_2: u32 = 3;
const TEST_CHANNEL_ID_0: u64 = 1;
const TEST_CHANNEL_ID_1: u64 = 2;
const TEST_CHANNEL_ID_2: u64 = 3;
#[test]
fn test_basic_target_id_with_apid() {