diff --git a/satrs-example/src/acs/mgm.rs b/satrs-example/src/acs/mgm.rs new file mode 100644 index 0000000..2e55987 --- /dev/null +++ b/satrs-example/src/acs/mgm.rs @@ -0,0 +1,74 @@ +use std::sync::mpsc::{self}; +use std::sync::{Arc, Mutex}; + +use satrs::mode::{ModeAndSubmode, ModeProvider, ModeReply, ModeRequest, ModeRequestHandler}; +use satrs::pus::EcssTmSenderCore; +use satrs::request::GenericMessage; +use satrs::ComponentId; + +use crate::pus::hk::HkReply; +use crate::requests::RequestWithToken; + +pub trait SpiInterface { + type Error; + fn transfer(&mut self, data: &mut [u8]) -> Result<(), Self::Error>; +} + +#[derive(Debug, Copy, Clone)] +pub struct MgmData { + pub x: f32, + pub y: f32, + pub z: f32, +} + +pub struct MgmHandler { + id: ComponentId, + dev_str: &'static str, + mode_request_receiver: mpsc::Receiver>, + mode_reply_sender_to_pus: mpsc::Sender>, + mode_reply_sender_to_parent: mpsc::Sender>, + composite_request_receiver: mpsc::Receiver, + hk_reply_sender: mpsc::Sender>, + hk_tm_sender: TmSender, + mode: ModeAndSubmode, + spi_interface: ComInterface, + shared_mgm_set: Arc>, +} + +impl MgmHandler { + pub fn perform_operation(&mut self) {} +} + +impl ModeProvider + for MgmHandler +{ + fn mode_and_submode(&self) -> ModeAndSubmode { + self.mode + } +} + +impl ModeRequestHandler + for MgmHandler +{ + fn start_transition( + &mut self, + request_id: satrs::request::RequestId, + sender_id: ComponentId, + mode_and_submode: ModeAndSubmode, + ) -> Result<(), satrs::mode::ModeError> { + todo!() + } + + fn announce_mode( + &self, + request_id: satrs::request::RequestId, + sender_id: satrs::ComponentId, + recursive: bool, + ) { + log::info!("{} announcing mode: {:?}", self.dev_str, self.mode); + } + + fn handle_mode_reached(&mut self) -> Result<(), satrs::queue::GenericTargetedMessagingError> { + todo!() + } +} diff --git a/satrs-example/src/acs.rs b/satrs-example/src/acs/mod.rs similarity index 84% rename from satrs-example/src/acs.rs rename to satrs-example/src/acs/mod.rs index 20bd75f..719fbe7 100644 --- a/satrs-example/src/acs.rs +++ b/satrs-example/src/acs/mod.rs @@ -1,26 +1,6 @@ -use std::sync::mpsc::{self, TryRecvError}; - -use log::{info, warn}; -use satrs::pus::verification::VerificationReportingProvider; -use satrs::pus::{EcssTmSender, PusTmWrapper}; -use satrs::request::TargetAndApidId; -use satrs::spacepackets::ecss::hk::Subservice as HkSubservice; -use satrs::{ - hk::HkRequest, - spacepackets::{ - ecss::tm::{PusTmCreator, PusTmSecondaryHeader}, - time::cds::{DaysLen16Bits, TimeProvider}, - SequenceFlags, SpHeader, - }, -}; -use satrs_example::config::{RequestTargetId, PUS_APID}; - -use crate::{ - hk::{AcsHkIds, HkUniqueId}, - requests::{Request, RequestWithToken}, - update_time, -}; +mod mgm; +/* pub struct AcsTask { timestamp: [u8; 7], time_provider: TimeProvider, @@ -112,3 +92,4 @@ impl AcsTask (StaticMemoryPool, StaticMemoryPool) { diff --git a/satrs-example/src/events.rs b/satrs-example/src/events.rs index a6a0d86..ecd2b1c 100644 --- a/satrs-example/src/events.rs +++ b/satrs-example/src/events.rs @@ -14,9 +14,9 @@ use satrs::{ verification::{TcStateStarted, VerificationReportingProvider, VerificationToken}, EcssTmSender, }, - spacepackets::time::cds::{self, TimeProvider}, + spacepackets::time::cds::{self, TimeProvider}, ComponentId, }; -use satrs_example::config::PUS_APID; +use satrs_example::config::{PUS_APID, ComponentIdList}; use crate::update_time; @@ -48,9 +48,9 @@ impl PusEventHandler for #[derive(Default)] pub struct ExampleActionRequestConverter {} -impl PusTcToRequestConverter +impl PusTcToRequestConverter for ExampleActionRequestConverter { type Error = GenericConversionError; @@ -146,7 +146,7 @@ impl PusTcToRequestConverter tc: &PusTcReader, time_stamp: &[u8], verif_reporter: &impl VerificationReportingProvider, - ) -> Result<(ActivePusActionRequestStd, ActionRequestWithId), Self::Error> { + ) -> Result<(ActivePusActionRequestStd, ActionRequest), Self::Error> { let subservice = tc.subservice(); let user_data = tc.user_data(); if user_data.len() < 8 { @@ -174,13 +174,10 @@ impl PusTcToRequestConverter token, Duration::from_secs(30), ), - ActionRequestWithId { - request_id: verification::RequestId::new(tc).into(), - request: ActionRequest::new( - action_id, - ActionRequestVariant::VecData(user_data[8..].to_vec()), - ), - }, + ActionRequest::new( + action_id, + ActionRequestVariant::VecData(user_data[8..].to_vec()), + ), )) } else { verif_reporter @@ -209,13 +206,13 @@ pub fn create_action_service_static( VerificationReporterWithSharedPoolMpscBoundedSender, > { let action_srv_tm_sender = TmInSharedPoolSenderWithId::new( - TmSenderId::PusAction as ChannelId, + ComponentIdList::PusAction as ComponentId, "PUS_8_TM_SENDER", shared_tm_store.clone(), tm_funnel_tx.clone(), ); let action_srv_receiver = MpscTcReceiver::new( - TcReceiverId::PusAction as ChannelId, + ComponentIdList::PusAction as ComponentId, "PUS_8_TC_RECV", pus_action_rx, ); @@ -253,12 +250,12 @@ pub fn create_action_service_dynamic( VerificationReporterWithVecMpscSender, > { let action_srv_tm_sender = TmAsVecSenderWithId::new( - TmSenderId::PusAction as ChannelId, + ComponentIdList::PusAction as ComponentId, "PUS_8_TM_SENDER", tm_funnel_tx.clone(), ); let action_srv_receiver = MpscTcReceiver::new( - TcReceiverId::PusAction as ChannelId, + ComponentIdList::PusAction as ComponentId, "PUS_8_TC_RECV", pus_action_rx, ); @@ -296,7 +293,7 @@ pub struct Pus8Wrapper< ActionReplyHandler, DefaultActiveActionRequestMap, ActivePusActionRequestStd, - ActionRequestWithId, + ActionRequest, ActionReplyPusWithActionId, >, } diff --git a/satrs-example/src/pus/event.rs b/satrs-example/src/pus/event.rs index 388cc3c..25eb230 100644 --- a/satrs-example/src/pus/event.rs +++ b/satrs-example/src/pus/event.rs @@ -15,8 +15,8 @@ use satrs::pus::{ TmInSharedPoolSenderWithId, }; use satrs::tmtc::tm_helper::SharedTmPool; -use satrs::ChannelId; -use satrs_example::config::{TcReceiverId, TmSenderId, PUS_APID}; +use satrs::ComponentId; +use satrs_example::config::{ComponentIdList, PUS_APID}; pub fn create_event_service_static( shared_tm_store: SharedTmPool, @@ -32,13 +32,13 @@ pub fn create_event_service_static( VerificationReporterWithSharedPoolMpscBoundedSender, > { let event_srv_tm_sender = TmInSharedPoolSenderWithId::new( - TmSenderId::PusEvent as ChannelId, + ComponentIdList::EventManagement as ComponentId, "PUS_5_TM_SENDER", shared_tm_store.clone(), tm_funnel_tx.clone(), ); let event_srv_receiver = MpscTcReceiver::new( - TcReceiverId::PusEvent as ChannelId, + ComponentIdList::EventManagement as ComponentId, "PUS_5_TC_RECV", pus_event_rx, ); @@ -69,12 +69,12 @@ pub fn create_event_service_dynamic( VerificationReporterWithVecMpscSender, > { let event_srv_tm_sender = TmAsVecSenderWithId::new( - TmSenderId::PusEvent as ChannelId, + ComponentIdList::EventManagement as ComponentId, "PUS_5_TM_SENDER", tm_funnel_tx, ); let event_srv_receiver = MpscTcReceiver::new( - TcReceiverId::PusEvent as ChannelId, + ComponentIdList::EventManagement as ComponentId, "PUS_5_TC_RECV", pus_event_rx, ); diff --git a/satrs-example/src/pus/hk.rs b/satrs-example/src/pus/hk.rs index 49874b0..5abf03d 100644 --- a/satrs-example/src/pus/hk.rs +++ b/satrs-example/src/pus/hk.rs @@ -17,8 +17,8 @@ use satrs::request::{GenericMessage, TargetAndApidId}; use satrs::spacepackets::ecss::tc::PusTcReader; use satrs::spacepackets::ecss::{hk, PusPacket}; use satrs::tmtc::tm_helper::SharedTmPool; -use satrs::ChannelId; -use satrs_example::config::{hk_err, tmtc_err, TcReceiverId, TmSenderId, PUS_APID}; +use satrs::ComponentId; +use satrs_example::config::{hk_err, tmtc_err, ComponentIdList, PUS_APID}; use std::sync::mpsc::{self}; use std::time::Duration; @@ -227,13 +227,16 @@ pub fn create_hk_service_static( VerificationReporterWithSharedPoolMpscBoundedSender, > { let hk_srv_tm_sender = TmInSharedPoolSenderWithId::new( - TmSenderId::PusHk as ChannelId, + ComponentIdList::PusHk as ComponentId, "PUS_3_TM_SENDER", shared_tm_store.clone(), tm_funnel_tx.clone(), ); - let hk_srv_receiver = - MpscTcReceiver::new(TcReceiverId::PusHk as ChannelId, "PUS_8_TC_RECV", pus_hk_rx); + let hk_srv_receiver = MpscTcReceiver::new( + ComponentIdList::PusHk as ComponentId, + "PUS_8_TC_RECV", + pus_hk_rx, + ); let pus_3_handler = PusTargetedRequestService::new( PusServiceHelper::new( hk_srv_receiver, @@ -266,12 +269,15 @@ pub fn create_hk_service_dynamic( VerificationReporterWithVecMpscSender, > { let hk_srv_tm_sender = TmAsVecSenderWithId::new( - TmSenderId::PusHk as ChannelId, + ComponentIdList::PusHk as ComponentId, "PUS_3_TM_SENDER", tm_funnel_tx.clone(), ); - let hk_srv_receiver = - MpscTcReceiver::new(TcReceiverId::PusHk as ChannelId, "PUS_8_TC_RECV", pus_hk_rx); + let hk_srv_receiver = MpscTcReceiver::new( + ComponentIdList::PusHk as ComponentId, + "PUS_8_TC_RECV", + pus_hk_rx, + ); let pus_3_handler = PusTargetedRequestService::new( PusServiceHelper::new( hk_srv_receiver, diff --git a/satrs-example/src/pus/mod.rs b/satrs-example/src/pus/mod.rs index 1649bf5..b841c94 100644 --- a/satrs-example/src/pus/mod.rs +++ b/satrs-example/src/pus/mod.rs @@ -199,15 +199,17 @@ where return Err(e.into()); } }; - let verif_request_id = verification::RequestId::new(&tc); + let verif_request_id = verification::RequestId::new(&tc).raw(); //if let Err(e) = - match self - .request_router - .route(request_info.target_id(), request, request_info.token()) - { + match self.request_router.route( + request_info.target_id(), + verif_request_id, + request, + request_info.token(), + ) { Ok(()) => { self.active_request_map - .insert(&verif_request_id.into(), request_info); + .insert(&verif_request_id, request_info); } Err(e) => { self.request_router.handle_error_generic( diff --git a/satrs-example/src/pus/scheduler.rs b/satrs-example/src/pus/scheduler.rs index 4af9167..c47849a 100644 --- a/satrs-example/src/pus/scheduler.rs +++ b/satrs-example/src/pus/scheduler.rs @@ -16,8 +16,8 @@ use satrs::pus::{ TmInSharedPoolSenderWithId, }; use satrs::tmtc::tm_helper::SharedTmPool; -use satrs::ChannelId; -use satrs_example::config::{TcReceiverId, TmSenderId, PUS_APID}; +use satrs::ComponentId; +use satrs_example::config::{ComponentIdList, PUS_APID}; use crate::tmtc::PusTcSourceProviderSharedPool; @@ -145,13 +145,13 @@ pub fn create_scheduler_service_static( VerificationReporterWithSharedPoolMpscBoundedSender, > { let sched_srv_tm_sender = TmInSharedPoolSenderWithId::new( - TmSenderId::PusSched as ChannelId, + ComponentIdList::PusSched as ComponentId, "PUS_11_TM_SENDER", shared_tm_store.clone(), tm_funnel_tx.clone(), ); let sched_srv_receiver = MpscTcReceiver::new( - TcReceiverId::PusSched as ChannelId, + ComponentIdList::PusSched as ComponentId, "PUS_11_TC_RECV", pus_sched_rx, ); @@ -188,12 +188,12 @@ pub fn create_scheduler_service_dynamic( VerificationReporterWithVecMpscSender, > { let sched_srv_tm_sender = TmAsVecSenderWithId::new( - TmSenderId::PusSched as ChannelId, + ComponentIdList::PusSched as ComponentId, "PUS_11_TM_SENDER", tm_funnel_tx, ); let sched_srv_receiver = MpscTcReceiver::new( - TcReceiverId::PusSched as ChannelId, + ComponentIdList::PusSched as ComponentId, "PUS_11_TC_RECV", pus_sched_rx, ); diff --git a/satrs-example/src/pus/test.rs b/satrs-example/src/pus/test.rs index 7c9e7aa..ea2eb89 100644 --- a/satrs-example/src/pus/test.rs +++ b/satrs-example/src/pus/test.rs @@ -17,9 +17,9 @@ use satrs::spacepackets::ecss::PusPacket; use satrs::spacepackets::time::cds::TimeProvider; use satrs::spacepackets::time::TimeWriter; use satrs::tmtc::tm_helper::SharedTmPool; -use satrs::ChannelId; +use satrs::ComponentId; use satrs::{events::EventU32, pus::EcssTcInSharedStoreConverter}; -use satrs_example::config::{tmtc_err, TcReceiverId, TmSenderId, PUS_APID, TEST_EVENT}; +use satrs_example::config::{tmtc_err, ComponentIdList, PUS_APID, TEST_EVENT}; use std::sync::mpsc::{self, Sender}; pub fn create_test_service_static( @@ -36,13 +36,13 @@ pub fn create_test_service_static( VerificationReporterWithSharedPoolMpscBoundedSender, > { let test_srv_tm_sender = TmInSharedPoolSenderWithId::new( - TmSenderId::PusTest as ChannelId, + ComponentIdList::PusTest as ComponentId, "PUS_17_TM_SENDER", shared_tm_store.clone(), tm_funnel_tx.clone(), ); let test_srv_receiver = MpscTcReceiver::new( - TcReceiverId::PusTest as ChannelId, + ComponentIdList::PusTest as ComponentId, "PUS_17_TC_RECV", pus_test_rx, ); @@ -71,12 +71,12 @@ pub fn create_test_service_dynamic( VerificationReporterWithVecMpscSender, > { let test_srv_tm_sender = TmAsVecSenderWithId::new( - TmSenderId::PusTest as ChannelId, + ComponentIdList::PusTest as ComponentId, "PUS_17_TM_SENDER", tm_funnel_tx.clone(), ); let test_srv_receiver = MpscTcReceiver::new( - TcReceiverId::PusTest as ChannelId, + ComponentIdList::PusTest as ComponentId, "PUS_17_TC_RECV", pus_test_rx, ); diff --git a/satrs-example/src/requests.rs b/satrs-example/src/requests.rs index b210739..db9370b 100644 --- a/satrs-example/src/requests.rs +++ b/satrs-example/src/requests.rs @@ -1,50 +1,42 @@ use std::collections::HashMap; use std::sync::mpsc; -use derive_new::new; use log::warn; +use satrs::action::ActionRequest; use satrs::hk::HkRequest; -use satrs::mode::ModeRequest; -use satrs::pus::action::ActionRequestWithId; use satrs::pus::verification::{ FailParams, TcStateStarted, VerificationReportingProvider, VerificationToken, }; use satrs::pus::{ActiveRequestProvider, GenericRoutingError, PusRequestRouter}; use satrs::queue::GenericSendError; +use satrs::request::{GenericMessage, RequestId}; use satrs::spacepackets::ecss::tc::PusTcReader; use satrs::spacepackets::ecss::PusPacket; use satrs::ComponentId; use satrs_example::config::tmtc_err; -#[allow(dead_code)] #[derive(Clone, Debug)] #[non_exhaustive] -pub enum Request { +pub enum CompositeRequest { Hk(HkRequest), - Mode(ModeRequest), - Action(ActionRequestWithId), -} - -#[derive(Clone, Debug, new)] -pub struct TargetedRequest { - pub(crate) target_id: ComponentId, - pub(crate) request: Request, + Action(ActionRequest), } #[derive(Clone, Debug)] pub struct RequestWithToken { - pub(crate) targeted_request: TargetedRequest, + pub(crate) targeted_request: GenericMessage, pub(crate) token: VerificationToken, } impl RequestWithToken { pub fn new( target_id: ComponentId, - request: Request, + request_id: RequestId, + request: CompositeRequest, token: VerificationToken, ) -> Self { Self { - targeted_request: TargetedRequest::new(target_id, request), + targeted_request: GenericMessage::new(request_id, target_id, request), token, } } @@ -96,6 +88,7 @@ impl PusRequestRouter for GenericRequestRouter { fn route( &self, target_id: ComponentId, + request_id: RequestId, hk_request: HkRequest, token: VerificationToken, ) -> Result<(), Self::Error> { @@ -103,7 +96,8 @@ impl PusRequestRouter for GenericRequestRouter { sender .send(RequestWithToken::new( target_id, - Request::Hk(hk_request), + request_id, + CompositeRequest::Hk(hk_request), token, )) .map_err(|_| GenericRoutingError::Send(GenericSendError::RxDisconnected))?; @@ -112,20 +106,22 @@ impl PusRequestRouter for GenericRequestRouter { } } -impl PusRequestRouter for GenericRequestRouter { +impl PusRequestRouter for GenericRequestRouter { type Error = GenericRoutingError; fn route( &self, target_id: ComponentId, - action_request: ActionRequestWithId, + request_id: RequestId, + action_request: ActionRequest, token: VerificationToken, ) -> Result<(), Self::Error> { if let Some(sender) = self.0.get(&target_id) { sender .send(RequestWithToken::new( target_id, - Request::Action(action_request), + request_id, + CompositeRequest::Action(action_request), token, )) .map_err(|_| GenericRoutingError::Send(GenericSendError::RxDisconnected))?; diff --git a/satrs/src/event_man.rs b/satrs/src/event_man.rs index 70870e7..2b5a37b 100644 --- a/satrs/src/event_man.rs +++ b/satrs/src/event_man.rs @@ -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; pub type EventU16WithAuxData = EventWithAuxData; pub trait EventSendProvider { - 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; fn contains_listener(&self, key: &ListenerKey) -> bool; - fn get_listener_ids(&self, key: &ListenerKey) -> Option>; - fn add_listener(&mut self, key: ListenerKey, sender_id: ChannelId) -> bool; + fn get_listener_ids(&self, key: &ListenerKey) -> Option>; + 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 { 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>, + listeners: HashMap>, } 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> { + fn get_listener_ids(&self, key: &ListenerKey) -> Option> { 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, + senders: HashMap, phantom: PhantomData<(EV, AUX)>, } @@ -406,18 +406,18 @@ pub mod alloc_mod { impl, EV: GenericEvent, AUX> SenderMapProvider for DefaultSenderMap { - 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 { - id: u32, + target_id: ComponentId, sender: mpsc::Sender<(Event, Option)>, } impl EventSenderMpsc { - pub fn new(id: u32, sender: mpsc::Sender<(Event, Option)>) -> Self { - Self { id, sender } + pub fn new(target_id: ComponentId, sender: mpsc::Sender<(Event, Option)>) -> Self { + Self { target_id, sender } } } impl EventSendProvider for EventSenderMpsc { - fn channel_id(&self) -> u32 { - self.id + fn target_id(&self) -> ComponentId { + self.target_id } fn send(&self, event: Event, aux_data: Option) -> 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 { - channel_id: u32, + target_id: ComponentId, sender: mpsc::SyncSender<(Event, Option)>, capacity: usize, } impl EventSenderMpscBounded { pub fn new( - channel_id: u32, + target_id: ComponentId, sender: mpsc::SyncSender<(Event, Option)>, capacity: usize, ) -> Self { Self { - channel_id, + target_id, sender, capacity, } @@ -503,8 +503,8 @@ pub mod std_mod { } impl EventSendProvider for EventSenderMpscBounded { - fn channel_id(&self) -> u32 { - self.channel_id + fn target_id(&self) -> ComponentId { + self.target_id } fn send(&self, event: Event, aux_data: Option) -> 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)) diff --git a/satrs/src/mode.rs b/satrs/src/mode.rs index 8a5167d..7e6f1da 100644 --- a/satrs/src/mode.rs +++ b/satrs/src/mode.rs @@ -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; 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> 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, R: MessageReceiver> ModeReplySender for MessageSenderAndReceiver { - 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, > RequestAndReplySenderAndReceiver { - 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, > ModeReplySender for RequestAndReplySenderAndReceiver { - 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> ModeRequestSender for MessageSenderMapWithId { - 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, R: MessageReceiver> ModeRequestSender for MessageSenderAndReceiver { - 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, > RequestAndReplySenderAndReceiver { - 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 { - 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( diff --git a/satrs/src/mode_tree.rs b/satrs/src/mode_tree.rs index 58bfe27..1cddd32 100644 --- a/satrs/src/mode_tree.rs +++ b/satrs/src/mode_tree.rs @@ -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, pub check_success: bool, diff --git a/satrs/src/pus/action.rs b/satrs/src/pus/action.rs index 8313d08..a0ce217 100644 --- a/satrs/src/pus/action.rs +++ b/satrs/src/pus/action.rs @@ -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; 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) diff --git a/satrs/src/pus/event.rs b/satrs/src/pus/event.rs index 5cde422..2c37272 100644 --- a/satrs/src/pus/event.rs +++ b/satrs/src/pus/event.rs @@ -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 } } diff --git a/satrs/src/pus/mod.rs b/satrs/src/pus/mod.rs index 1b3f69a..94bec2a 100644 --- a/satrs/src/pus/mod.rs +++ b/satrs/src/pus/mod.rs @@ -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 { fn route( &self, target_id: ComponentId, + request_id: RequestId, request: Request, token: VerificationToken, ) -> 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 { - channel_id: ChannelId, + channel_id: ComponentId, name: &'static str, shared_tm_store: SharedTmPool, sender: Sender, } impl EcssChannel for TmInSharedPoolSenderWithId { - fn channel_id(&self) -> ChannelId { + fn channel_id(&self) -> ComponentId { self.channel_id } @@ -758,7 +759,7 @@ pub mod std_mod { impl TmInSharedPoolSenderWithId { 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 { - id: ChannelId, + id: ComponentId, name: &'static str, sender: Sender, } @@ -794,13 +795,13 @@ pub mod std_mod { } impl TmAsVecSenderWithId { - 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 EcssChannel for TmAsVecSenderWithId { - 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>>; pub struct MpscTcReceiver { - id: ChannelId, + id: ComponentId, name: &'static str, receiver: mpsc::Receiver, } 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, ) -> Self { @@ -903,14 +904,14 @@ pub mod std_mod { } pub struct CrossbeamTcReceiver { - id: ChannelId, + id: ComponentId, name: &'static str, receiver: cb::Receiver, } impl CrossbeamTcReceiver { pub fn new( - id: ChannelId, + id: ComponentId, name: &'static str, receiver: cb::Receiver, ) -> 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 } diff --git a/satrs/src/pus/verification.rs b/satrs/src/pus/verification.rs index 659bb03..bd21049 100644 --- a/satrs/src/pus/verification.rs +++ b/satrs/src/pus/verification.rs @@ -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 { diff --git a/satrs/src/queue.rs b/satrs/src/queue.rs index b49714b..2ad4f32 100644 --- a/satrs/src/queue.rs +++ b/satrs/src/queue.rs @@ -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), - 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), + TxDisconnected(Option), } impl Display for GenericReceiveError { diff --git a/satrs/src/request.rs b/satrs/src/request.rs index 04b5ba5..03d0690 100644 --- a/satrs/src/request.rs +++ b/satrs/src/request.rs @@ -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 { - pub sender_id: ChannelId, pub request_id: RequestId, + pub sender_id: ComponentId, pub message: MSG, } impl GenericMessage { - 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> MessageWithSenderIdReceiver { } pub struct MessageReceiverWithId> { - local_channel_id: ChannelId, + local_channel_id: ComponentId, reply_receiver: MessageWithSenderIdReceiver, } impl> MessageReceiverWithId { - 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>( - pub HashMap, + pub HashMap, pub(crate) PhantomData, ); @@ -180,15 +180,15 @@ pub mod alloc_mod { } impl> MessageSenderMap { - 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> { - pub local_channel_id: ChannelId, + pub local_channel_id: ComponentId, pub message_sender_map: MessageSenderMap, } impl> MessageSenderMapWithId { - 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, R: MessageReceiver> { - pub local_channel_id: ChannelId, + pub local_channel_id: ComponentId, pub message_sender_map: MessageSenderMap, pub message_receiver: MessageWithSenderIdReceiver, } @@ -244,7 +244,7 @@ pub mod alloc_mod { impl, R: MessageReceiver> MessageSenderAndReceiver { - 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, R1: MessageReceiver, > { - pub local_channel_id: ChannelId, + pub local_channel_id: ComponentId, // These 2 are a functional group. pub request_sender_map: MessageSenderMap, pub reply_receiver: MessageWithSenderIdReceiver, @@ -310,7 +310,11 @@ pub mod alloc_mod { R1: MessageReceiver, > RequestAndReplySenderAndReceiver { - 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() { diff --git a/satrs/tests/mode_tree.rs b/satrs/tests/mode_tree.rs index ee1737a..5ab130f 100644 --- a/satrs/tests/mode_tree.rs +++ b/satrs/tests/mode_tree.rs @@ -13,7 +13,7 @@ use satrs::{ mode::{ModeAndSubmode, ModeReply, ModeRequest}, queue::GenericTargetedMessagingError, request::GenericMessage, - ChannelId, + ComponentId, }; use std::string::{String, ToString}; @@ -47,7 +47,7 @@ struct TestDevice { pub name: String, pub mode_node: ModeRequestHandlerMpscBounded, pub mode_and_submode: ModeAndSubmode, - pub mode_requestor_info: Option<(RequestId, ChannelId)>, + pub mode_requestor_info: Option<(RequestId, ComponentId)>, pub action_queue: mpsc::Receiver>, } @@ -95,7 +95,7 @@ impl ModeRequestHandler for TestDevice { fn start_transition( &mut self, _request_id: RequestId, - _sender_id: ChannelId, + _sender_id: ComponentId, mode_and_submode: ModeAndSubmode, ) -> Result<(), ModeError> { self.mode_and_submode = mode_and_submode; @@ -103,7 +103,7 @@ impl ModeRequestHandler for TestDevice { Ok(()) } - fn announce_mode(&self, _request_id: RequestId, _sender_id: ChannelId, _recursive: bool) { + fn announce_mode(&self, _request_id: RequestId, _sender_id: ComponentId, _recursive: bool) { println!( "{}: announcing mode: {:?}", self.name, self.mode_and_submode @@ -123,7 +123,7 @@ impl ModeRequestHandler for TestDevice { struct TestAssembly { pub mode_node: ModeRequestorAndHandlerMpscBounded, - pub mode_requestor_info: Option<(RequestId, ChannelId)>, + pub mode_requestor_info: Option<(RequestId, ComponentId)>, pub mode_and_submode: ModeAndSubmode, pub target_mode_and_submode: Option, } @@ -193,7 +193,7 @@ impl ModeRequestHandler for TestAssembly { fn start_transition( &mut self, request_id: RequestId, - sender_id: ChannelId, + sender_id: ComponentId, mode_and_submode: ModeAndSubmode, ) -> Result<(), ModeError> { self.mode_requestor_info = Some((request_id, sender_id)); @@ -201,7 +201,7 @@ impl ModeRequestHandler for TestAssembly { Ok(()) } - fn announce_mode(&self, request_id: RequestId, _sender_id: ChannelId, recursive: bool) { + fn announce_mode(&self, request_id: RequestId, _sender_id: ComponentId, recursive: bool) { println!( "TestAssembly: Announcing mode (recursively: {}): {:?}", recursive, self.mode_and_submode