continue mode tree feature

This commit is contained in:
Robin Müller 2024-12-02 16:37:28 +01:00
parent 5d8787b7fa
commit ba5c7d4a2f
Signed by: muellerr
GPG Key ID: A649FB78196E3849
5 changed files with 288 additions and 152 deletions

View File

@ -336,26 +336,51 @@ pub mod alloc_mod {
}
impl<
REQUEST,
S0: MessageSenderProvider<REQUEST>,
R0: MessageReceiverProvider<ModeReply>,
S1: MessageSenderProvider<ModeReply>,
R1: MessageReceiverProvider<REQUEST>,
> RequestAndReplySenderAndReceiver<REQUEST, ModeReply, S0, R0, S1, R1>
Request,
ReqSender: MessageSenderProvider<Request>,
ReqReceiver: MessageReceiverProvider<Request>,
ReqSenderStore: MessageSenderStoreProvider<Request, ReqSender>,
Reply,
ReplySender: MessageSenderProvider<Reply>,
ReplyReceiver: MessageReceiverProvider<Reply>,
ReplySenderStore: MessageSenderStoreProvider<Reply, ReplySender>,
>
RequestAndReplySenderAndReceiver<
Request,
ReqSender,
ReqReceiver,
ReqSenderStore,
Reply,
ReplySender,
ReplyReceiver,
ReplySenderStore,
>
{
pub fn add_reply_target(&mut self, target_id: ComponentId, reply_sender: S1) {
self.reply_sender_map
pub fn add_reply_target(&mut self, target_id: ComponentId, reply_sender: ReplySender) {
self.reply_sender_store
.add_message_target(target_id, reply_sender)
}
}
impl<
REQUEST,
S0: MessageSenderProvider<REQUEST>,
R0: MessageReceiverProvider<ModeReply>,
S1: MessageSenderProvider<ModeReply>,
R1: MessageReceiverProvider<REQUEST>,
> ModeReplySender for RequestAndReplySenderAndReceiver<REQUEST, ModeReply, S0, R0, S1, R1>
Request,
ReqSender: MessageSenderProvider<Request>,
ReqReceiver: MessageReceiverProvider<Request>,
ReqSenderStore: MessageSenderStoreProvider<Request, ReqSender>,
ReplySender: MessageSenderProvider<ModeReply>,
ReplyReceiver: MessageReceiverProvider<ModeReply>,
ReplySenderStore: MessageSenderStoreProvider<ModeReply, ReplySender>,
> ModeReplySender
for RequestAndReplySenderAndReceiver<
Request,
ReqSender,
ReqReceiver,
ReqSenderStore,
ModeReply,
ReplySender,
ReplyReceiver,
ReplySenderStore,
>
{
fn local_channel_id(&self) -> ComponentId {
self.local_channel_id_generic()
@ -364,24 +389,35 @@ pub mod alloc_mod {
fn send_mode_reply(
&self,
requestor_info: MessageMetadata,
request: ModeReply,
reply: ModeReply,
) -> Result<(), GenericTargetedMessagingError> {
self.reply_sender_map.send_mode_reply(
self.reply_sender_store.send_message(
MessageMetadata::new(requestor_info.request_id(), self.local_channel_id()),
requestor_info.sender_id(),
request,
reply,
)
}
}
impl<
REQUEST,
S0: MessageSenderProvider<REQUEST>,
R0: MessageReceiverProvider<ModeReply>,
S1: MessageSenderProvider<ModeReply>,
R1: MessageReceiverProvider<REQUEST>,
Request,
ReqSender: MessageSenderProvider<Request>,
ReqReceiver: MessageReceiverProvider<Request>,
ReqSenderStore: MessageSenderStoreProvider<Request, ReqSender>,
ReplySender: MessageSenderProvider<ModeReply>,
ReplyReceiver: MessageReceiverProvider<ModeReply>,
ReplySenderStore: MessageSenderStoreProvider<ModeReply, ReplySender>,
> ModeReplyReceiver
for RequestAndReplySenderAndReceiver<REQUEST, ModeReply, S0, R0, S1, R1>
for RequestAndReplySenderAndReceiver<
Request,
ReqSender,
ReqReceiver,
ReqSenderStore,
ModeReply,
ReplySender,
ReplyReceiver,
ReplySenderStore,
>
{
fn try_recv_mode_reply(
&self,
@ -448,8 +484,23 @@ pub mod alloc_mod {
/// Helper type defintion for a mode handler object which can both send mode requests and
/// process mode requests.
pub type ModeInterface<S0, R0, S1, R1> =
RequestAndReplySenderAndReceiver<ModeRequest, ModeReply, S0, R0, S1, R1>;
pub type ModeInterface<
ReqSender,
ReqReceiver,
ReqSenderStore,
ReplySender,
ReplyReceiver,
ReplySenderStore,
> = RequestAndReplySenderAndReceiver<
ModeRequest,
ReqSender,
ReqReceiver,
ReqSenderStore,
ModeReply,
ReplySender,
ReplyReceiver,
ReplySenderStore,
>;
impl<S: MessageSenderProvider<ModeRequest>> MessageSenderMap<ModeRequest, S> {
pub fn send_mode_request(
@ -508,27 +559,50 @@ pub mod alloc_mod {
}
impl<
REPLY,
S0: MessageSenderProvider<ModeRequest>,
R0: MessageReceiverProvider<REPLY>,
S1: MessageSenderProvider<REPLY>,
R1: MessageReceiverProvider<ModeRequest>,
> RequestAndReplySenderAndReceiver<ModeRequest, REPLY, S0, R0, S1, R1>
ReqSender: MessageSenderProvider<ModeRequest>,
ReqReceiver: MessageReceiverProvider<ModeRequest>,
ReqSenderStore: MessageSenderStoreProvider<ModeRequest, ReqSender>,
Reply,
ReplySender: MessageSenderProvider<Reply>,
ReplyReceiver: MessageReceiverProvider<Reply>,
ReplySenderStore: MessageSenderStoreProvider<Reply, ReplySender>,
>
RequestAndReplySenderAndReceiver<
ModeRequest,
ReqSender,
ReqReceiver,
ReqSenderStore,
Reply,
ReplySender,
ReplyReceiver,
ReplySenderStore,
>
{
pub fn add_request_target(&mut self, target_id: ComponentId, request_sender: S0) {
self.request_sender_map
pub fn add_request_target(&mut self, target_id: ComponentId, request_sender: ReqSender) {
self.request_sender_store
.add_message_target(target_id, request_sender)
}
}
impl<
REPLY,
S0: MessageSenderProvider<ModeRequest>,
R0: MessageReceiverProvider<REPLY>,
S1: MessageSenderProvider<REPLY>,
R1: MessageReceiverProvider<ModeRequest>,
ReqSender: MessageSenderProvider<ModeRequest>,
ReqReceiver: MessageReceiverProvider<ModeRequest>,
ReqSenderStore: MessageSenderStoreProvider<ModeRequest, ReqSender>,
Reply,
ReplySender: MessageSenderProvider<Reply>,
ReplyReceiver: MessageReceiverProvider<Reply>,
ReplySenderStore: MessageSenderStoreProvider<Reply, ReplySender>,
> ModeRequestSender
for RequestAndReplySenderAndReceiver<ModeRequest, REPLY, S0, R0, S1, R1>
for RequestAndReplySenderAndReceiver<
ModeRequest,
ReqSender,
ReqReceiver,
ReqSenderStore,
Reply,
ReplySender,
ReplyReceiver,
ReplySenderStore,
>
{
fn local_channel_id(&self) -> ComponentId {
self.local_channel_id_generic()
@ -540,7 +614,7 @@ pub mod alloc_mod {
target_id: ComponentId,
request: ModeRequest,
) -> Result<(), GenericTargetedMessagingError> {
self.request_sender_map.send_mode_request(
self.request_sender_store.send_message(
MessageMetadata::new(request_id, self.local_channel_id()),
target_id,
request,
@ -549,13 +623,24 @@ pub mod alloc_mod {
}
impl<
REPLY,
S0: MessageSenderProvider<ModeRequest>,
R0: MessageReceiverProvider<REPLY>,
S1: MessageSenderProvider<REPLY>,
R1: MessageReceiverProvider<ModeRequest>,
ReqSender: MessageSenderProvider<ModeRequest>,
ReqReceiver: MessageReceiverProvider<ModeRequest>,
ReqSenderStore: MessageSenderStoreProvider<ModeRequest, ReqSender>,
Reply,
ReplySender: MessageSenderProvider<Reply>,
ReplyReceiver: MessageReceiverProvider<Reply>,
ReplySenderStore: MessageSenderStoreProvider<Reply, ReplySender>,
> ModeRequestReceiver
for RequestAndReplySenderAndReceiver<ModeRequest, REPLY, S0, R0, S1, R1>
for RequestAndReplySenderAndReceiver<
ModeRequest,
ReqSender,
ReqReceiver,
ReqSenderStore,
Reply,
ReplySender,
ReplyReceiver,
ReplySenderStore,
>
{
fn try_recv_mode_request(
&self,
@ -573,15 +658,15 @@ pub mod std_mod {
use super::*;
pub type ModeRequestHandlerOneParentMpsc = ModeRequestHandlerInterface<
pub type ModeRequestHandlerMpsc = ModeRequestHandlerInterface<
mpsc::Sender<GenericMessage<ModeReply>>,
mpsc::Receiver<GenericMessage<ModeRequest>>,
OneMessageSender<ModeReply, mpsc::Sender<GenericMessage<ModeReply>>>,
MessageSenderList<ModeReply, mpsc::Sender<GenericMessage<ModeReply>>>,
>;
pub type ModeRequestHandlerOneParentMpscBounded = ModeRequestHandlerInterface<
pub type ModeRequestHandlerMpscBounded = ModeRequestHandlerInterface<
mpsc::SyncSender<GenericMessage<ModeReply>>,
mpsc::Receiver<GenericMessage<ModeRequest>>,
OneMessageSender<ModeReply, mpsc::SyncSender<GenericMessage<ModeReply>>>,
MessageSenderList<ModeReply, mpsc::SyncSender<GenericMessage<ModeReply>>>,
>;
pub type ModeRequestorOneChildMpsc = ModeRequestorInterface<
@ -592,36 +677,34 @@ pub mod std_mod {
pub type ModeRequestorOneChildBoundedMpsc = ModeRequestorInterface<
mpsc::SyncSender<GenericMessage<ModeRequest>>,
mpsc::Receiver<GenericMessage<ModeReply>>,
OneMessageSender<
ModeRequest,
mpsc::SyncSender<GenericMessage<ModeRequest>>,
>,
OneMessageSender<ModeRequest, mpsc::SyncSender<GenericMessage<ModeRequest>>>,
>;
pub type ModeRequestorMultiChildListMpsc = ModeRequestorInterface<
pub type ModeRequestorChildListMpsc = ModeRequestorInterface<
mpsc::Sender<GenericMessage<ModeRequest>>,
mpsc::Receiver<GenericMessage<ModeReply>>,
MessageSenderList<ModeRequest, mpsc::Sender<GenericMessage<ModeRequest>>>,
>;
pub type ModeRequestorMultiChildListBoundedMpsc = ModeRequestorInterface<
pub type ModeRequestorChildListBoundedMpsc = ModeRequestorInterface<
mpsc::SyncSender<GenericMessage<ModeRequest>>,
mpsc::Receiver<GenericMessage<ModeReply>>,
MessageSenderList<
ModeRequest,
mpsc::SyncSender<GenericMessage<ModeRequest>>,
>,
MessageSenderList<ModeRequest, mpsc::SyncSender<GenericMessage<ModeRequest>>>,
>;
pub type ModeRequestorAndHandlerOneParentMpsc = ModeInterface<
pub type ModeRequestorAndHandlerMpsc = ModeInterface<
mpsc::Sender<GenericMessage<ModeRequest>>,
mpsc::Receiver<GenericMessage<ModeReply>>,
mpsc::Receiver<GenericMessage<ModeRequest>>,
MessageSenderList<ModeRequest, mpsc::Sender<GenericMessage<ModeRequest>>>,
mpsc::Sender<GenericMessage<ModeReply>>,
mpsc::Receiver<GenericMessage<ModeRequest>>,
>;
pub type ModeRequestorAndHandlerOneParentMpscBounded = ModeInterface<
mpsc::SyncSender<GenericMessage<ModeRequest>>,
mpsc::Receiver<GenericMessage<ModeReply>>,
mpsc::SyncSender<GenericMessage<ModeReply>>,
MessageSenderList<ModeReply, mpsc::Sender<GenericMessage<ModeReply>>>,
>;
pub type ModeRequestorAndHandlerMpscBounded = ModeInterface<
mpsc::SyncSender<GenericMessage<ModeRequest>>,
mpsc::Receiver<GenericMessage<ModeRequest>>,
MessageSenderList<ModeRequest, mpsc::SyncSender<GenericMessage<ModeRequest>>>,
mpsc::SyncSender<GenericMessage<ModeReply>>,
mpsc::Receiver<GenericMessage<ModeReply>>,
MessageSenderList<ModeReply, mpsc::SyncSender<GenericMessage<ModeReply>>>,
>;
}

View File

@ -52,7 +52,8 @@ mod tests {
fn test_simple_mode_requestor() {
let (reply_sender, reply_receiver) = mpsc::channel();
let (request_sender, request_receiver) = mpsc::channel();
let mut mode_requestor = ModeRequestorOneChildMpsc::new(TEST_COMPONENT_ID_0, reply_receiver);
let mut mode_requestor =
ModeRequestorOneChildMpsc::new(TEST_COMPONENT_ID_0, reply_receiver);
mode_requestor.add_message_target(TEST_COMPONENT_ID_1, request_sender);
// Send a request and verify it arrives at the receiver.

View File

@ -149,9 +149,9 @@ pub trait MessageReceiverProvider<MSG> {
fn try_recv(&self) -> Result<Option<GenericMessage<MSG>>, GenericTargetedMessagingError>;
}
pub struct MessageWithSenderIdReceiver<MSG, R: MessageReceiverProvider<MSG>>(
pub R,
PhantomData<MSG>,
pub struct MessageWithSenderIdReceiver<Msg, Receiver: MessageReceiverProvider<Msg>>(
pub Receiver,
PhantomData<Msg>,
);
impl<MSG, R: MessageReceiverProvider<MSG>> From<R> for MessageWithSenderIdReceiver<MSG, R> {
@ -208,6 +208,7 @@ pub trait MessageSenderStoreProvider<Message, Sender>: Default {
#[cfg(feature = "alloc")]
pub mod alloc_mod {
use crate::queue::GenericSendError;
use std::convert::From;
use super::*;
use hashbrown::HashMap;
@ -226,10 +227,10 @@ pub mod alloc_mod {
}
}
impl<Msg, S: MessageSenderProvider<Msg>> MessageSenderStoreProvider<Msg, S>
for OneMessageSender<Msg, S>
impl<Msg, Sender: MessageSenderProvider<Msg>> MessageSenderStoreProvider<Msg, Sender>
for OneMessageSender<Msg, Sender>
{
fn add_message_target(&mut self, target_id: ComponentId, message_sender: S) {
fn add_message_target(&mut self, target_id: ComponentId, message_sender: Sender) {
if self.id_and_sender.is_some() {
return;
}
@ -263,10 +264,10 @@ pub mod alloc_mod {
}
}
impl<MSG, S: MessageSenderProvider<MSG>> MessageSenderStoreProvider<MSG, S>
for MessageSenderList<MSG, S>
impl<Msg, Sender: MessageSenderProvider<Msg>> MessageSenderStoreProvider<Msg, Sender>
for MessageSenderList<Msg, Sender>
{
fn add_message_target(&mut self, target_id: ComponentId, message_sender: S) {
fn add_message_target(&mut self, target_id: ComponentId, message_sender: Sender) {
self.0.push((target_id, message_sender));
}
@ -274,7 +275,7 @@ pub mod alloc_mod {
&self,
requestor_info: MessageMetadata,
target_channel_id: ComponentId,
message: MSG,
message: Msg,
) -> Result<(), GenericTargetedMessagingError> {
for (current_id, sender) in &self.0 {
if *current_id == target_channel_id {
@ -297,10 +298,10 @@ pub mod alloc_mod {
}
}
impl<MSG, S: MessageSenderProvider<MSG>> MessageSenderStoreProvider<MSG, S>
for MessageSenderMap<MSG, S>
impl<Msg, Sender: MessageSenderProvider<Msg>> MessageSenderStoreProvider<Msg, Sender>
for MessageSenderMap<Msg, Sender>
{
fn add_message_target(&mut self, target_id: ComponentId, message_sender: S) {
fn add_message_target(&mut self, target_id: ComponentId, message_sender: Sender) {
self.0.insert(target_id, message_sender);
}
@ -308,7 +309,7 @@ pub mod alloc_mod {
&self,
requestor_info: MessageMetadata,
target_channel_id: ComponentId,
message: MSG,
message: Msg,
) -> Result<(), GenericTargetedMessagingError> {
if self.0.contains_key(&target_channel_id) {
return self
@ -383,42 +384,58 @@ pub mod alloc_mod {
}
pub struct RequestAndReplySenderAndReceiver<
REQUEST,
REPLY,
S0: MessageSenderProvider<REQUEST>,
R0: MessageReceiverProvider<REPLY>,
S1: MessageSenderProvider<REPLY>,
R1: MessageReceiverProvider<REQUEST>,
Request,
ReqSender: MessageSenderProvider<Request>,
ReqReceiver: MessageReceiverProvider<Request>,
ReqSenderStore: MessageSenderStoreProvider<Request, ReqSender>,
Reply,
ReplySender: MessageSenderProvider<Reply>,
ReplyReceiver: MessageReceiverProvider<Reply>,
ReplySenderStore: MessageSenderStoreProvider<Reply, ReplySender>,
> {
pub local_channel_id: ComponentId,
// These 2 are a functional group.
pub request_sender_map: MessageSenderMap<REQUEST, S0>,
pub reply_receiver: MessageWithSenderIdReceiver<REPLY, R0>,
pub request_sender_store: ReqSenderStore,
pub reply_receiver: MessageWithSenderIdReceiver<Reply, ReplyReceiver>,
// These 2 are a functional group.
pub request_receiver: MessageWithSenderIdReceiver<REQUEST, R1>,
pub reply_sender_map: MessageSenderMap<REPLY, S1>,
pub request_receiver: MessageWithSenderIdReceiver<Request, ReqReceiver>,
pub reply_sender_store: ReplySenderStore,
phantom: PhantomData<(ReqSender, ReplySender)>,
}
impl<
REQUEST,
REPLY,
S0: MessageSenderProvider<REQUEST>,
R0: MessageReceiverProvider<REPLY>,
S1: MessageSenderProvider<REPLY>,
R1: MessageReceiverProvider<REQUEST>,
> RequestAndReplySenderAndReceiver<REQUEST, REPLY, S0, R0, S1, R1>
Request,
ReqSender: MessageSenderProvider<Request>,
ReqReceiver: MessageReceiverProvider<Request>,
ReqSenderStore: MessageSenderStoreProvider<Request, ReqSender>,
Reply,
ReplySender: MessageSenderProvider<Reply>,
ReplyReceiver: MessageReceiverProvider<Reply>,
ReplySenderStore: MessageSenderStoreProvider<Reply, ReplySender>,
>
RequestAndReplySenderAndReceiver<
Request,
ReqSender,
ReqReceiver,
ReqSenderStore,
Reply,
ReplySender,
ReplyReceiver,
ReplySenderStore,
>
{
pub fn new(
local_channel_id: ComponentId,
request_receiver: R1,
reply_receiver: R0,
request_receiver: ReqReceiver,
reply_receiver: ReplyReceiver,
) -> Self {
Self {
local_channel_id,
request_receiver: request_receiver.into(),
reply_receiver: reply_receiver.into(),
request_sender_map: Default::default(),
reply_sender_map: Default::default(),
request_sender_store: Default::default(),
reply_sender_store: Default::default(),
phantom: PhantomData,
}
}

View File

@ -17,37 +17,37 @@ impl PusTmWithCdsShortHelper {
}
#[cfg(feature = "std")]
pub fn create_pus_tm_timestamp_now<'a>(
&'a mut self,
pub fn create_pus_tm_timestamp_now<'time, 'src_data>(
&'time mut self,
service: u8,
subservice: u8,
source_data: &'a [u8],
source_data: &'src_data [u8],
seq_count: u16,
) -> PusTmCreator {
) -> PusTmCreator<'time, 'src_data> {
let time_stamp = CdsTime::now_with_u16_days().unwrap();
time_stamp.write_to_bytes(&mut self.cds_short_buf).unwrap();
self.create_pus_tm_common(service, subservice, source_data, seq_count)
}
pub fn create_pus_tm_with_stamper<'a>(
&'a mut self,
pub fn create_pus_tm_with_stamper<'time, 'src_data>(
&'time mut self,
service: u8,
subservice: u8,
source_data: &'a [u8],
source_data: &'src_data [u8],
stamper: &CdsTime,
seq_count: u16,
) -> PusTmCreator {
) -> PusTmCreator<'time, 'src_data> {
stamper.write_to_bytes(&mut self.cds_short_buf).unwrap();
self.create_pus_tm_common(service, subservice, source_data, seq_count)
}
fn create_pus_tm_common<'a>(
&'a self,
fn create_pus_tm_common<'time, 'src_data>(
&'time self,
service: u8,
subservice: u8,
source_data: &'a [u8],
source_data: &'src_data [u8],
seq_count: u16,
) -> PusTmCreator {
) -> PusTmCreator<'time, 'src_data> {
let reply_header = SpHeader::new_for_unseg_tm(self.apid, seq_count, 0);
let tc_header = PusTmSecondaryHeader::new_simple(service, subservice, &self.cds_short_buf);
PusTmCreator::new(reply_header, tc_header, source_data, true)

View File

@ -1,8 +1,12 @@
use core::cell::Cell;
use satrs::mode::{Mode, ModeError, ModeProvider, ModeReplyReceiver, ModeReplySender, ModeRequestHandler, ModeRequestHandlerOneParentMpscBounded, ModeRequestReceiver, ModeRequestSender, ModeRequestorAndHandlerOneParentMpscBounded, ModeRequestorOneChildBoundedMpsc};
use satrs::mode::{
Mode, ModeError, ModeProvider, ModeReplyReceiver, ModeReplySender, ModeRequestHandler,
ModeRequestHandlerMpscBounded, ModeRequestReceiver, ModeRequestorAndHandlerMpscBounded,
ModeRequestorOneChildBoundedMpsc,
};
use satrs::mode_tree::{
connect_mode_nodes, ModeChild, ModeNode, ModeParent, ModeStoreProvider, SequenceTableMapTable,
TargetTableEntry,
connect_mode_nodes, ModeChild, ModeNode, ModeParent, ModeStoreProvider, SequenceTableEntry,
SequenceTableMapTable, TargetTableEntry,
};
use satrs::mode_tree::{
ModeStoreVec, SequenceModeTables, SequenceTablesMapValue, TargetModeTables,
@ -187,17 +191,17 @@ impl ModeParent for PusModeService {
}
struct AcsSubsystem {
pub mode_node: ModeRequestorAndHandlerOneParentMpscBounded,
pub mode_node: ModeRequestorAndHandlerMpscBounded,
pub mode_requestor_info: Option<MessageMetadata>,
pub mode_and_submode: ModeAndSubmode,
pub target_mode_and_submode: Option<ModeAndSubmode>,
pub subsystem_helper: SubsystemHelper,
pub mode_req_handler_mock: ModeRequestHandlerMock,
pub mode_msgs_recvd: u32,
pub mode_req_recvd: u32,
}
impl AcsSubsystem {
pub fn new(mode_node: ModeRequestorAndHandlerOneParentMpscBounded) -> Self {
pub fn new(mode_node: ModeRequestorAndHandlerMpscBounded) -> Self {
Self {
mode_node,
mode_requestor_info: None,
@ -205,19 +209,19 @@ impl AcsSubsystem {
target_mode_and_submode: None,
subsystem_helper: Default::default(),
mode_req_handler_mock: Default::default(),
mode_msgs_recvd: 0,
mode_req_recvd: 0,
}
}
pub fn get_and_clear_num_mode_msgs(&mut self) -> u32 {
let tmp = self.mode_msgs_recvd;
self.mode_msgs_recvd = 0;
pub fn get_and_clear_num_mode_requests(&mut self) -> u32 {
let tmp = self.mode_req_recvd;
self.mode_req_recvd = 0;
tmp
}
pub fn run(&mut self) {
if let Some(request) = self.mode_node.try_recv_mode_request().unwrap() {
self.mode_msgs_recvd += 1;
self.mode_req_recvd += 1;
self.handle_mode_request(request)
.expect("mode messaging error");
}
@ -298,7 +302,7 @@ impl ModeRequestHandler for AcsSubsystem {
}
let request_id = requestor_info.map_or(0, |info| info.request_id());
self.mode_node
.request_sender_map
.request_sender_store
.0
.iter()
.for_each(|(_, sender)| {
@ -354,7 +358,7 @@ impl ModeRequestHandler for AcsSubsystem {
}
struct MgmAssembly {
pub mode_node: ModeRequestorAndHandlerOneParentMpscBounded,
pub mode_node: ModeRequestorAndHandlerMpscBounded,
pub mode_requestor_info: Option<MessageMetadata>,
pub mode_and_submode: ModeAndSubmode,
pub target_mode_and_submode: Option<ModeAndSubmode>,
@ -363,7 +367,7 @@ struct MgmAssembly {
}
impl MgmAssembly {
pub fn new(mode_node: ModeRequestorAndHandlerOneParentMpscBounded) -> Self {
pub fn new(mode_node: ModeRequestorAndHandlerMpscBounded) -> Self {
Self {
mode_node,
mode_requestor_info: None,
@ -386,6 +390,7 @@ impl MgmAssembly {
pub fn check_mode_requests(&mut self) -> Result<(), GenericTargetedMessagingError> {
if let Some(request) = self.mode_node.try_recv_mode_request()? {
self.mode_msgs_recvd += 1;
self.handle_mode_request(request).unwrap();
}
Ok(())
@ -469,7 +474,7 @@ impl ModeRequestHandler for MgmAssembly {
}
let request_id = requestor_info.map_or(0, |info| info.request_id());
self.mode_node
.request_sender_map
.request_sender_store
.0
.iter()
.for_each(|(_, sender)| {
@ -524,17 +529,17 @@ impl ModeRequestHandler for MgmAssembly {
struct DeviceManager {
name: &'static str,
pub id: ComponentId,
pub mode_node: ModeRequestorAndHandlerOneParentMpscBounded,
pub mode_node: ModeRequestorAndHandlerMpscBounded,
pub mode_and_submode: ModeAndSubmode,
pub mode_req_mock: ModeRequestHandlerMock,
pub mode_msgs_recvd: u32,
pub mode_req_recvd: u32,
}
impl DeviceManager {
pub fn new(
name: &'static str,
id: ComponentId,
mode_node: ModeRequestorAndHandlerOneParentMpscBounded,
mode_node: ModeRequestorAndHandlerMpscBounded,
) -> Self {
Self {
name,
@ -542,13 +547,13 @@ impl DeviceManager {
mode_node,
mode_and_submode: UNKNOWN_MODE,
mode_req_mock: Default::default(),
mode_msgs_recvd: 0,
mode_req_recvd: 0,
}
}
pub fn get_and_clear_num_mode_msgs(&mut self) -> u32 {
let tmp = self.mode_msgs_recvd;
self.mode_msgs_recvd = 0;
pub fn get_and_clear_num_mode_requests(&mut self) -> u32 {
let tmp = self.mode_req_recvd;
self.mode_req_recvd = 0;
tmp
}
@ -558,6 +563,7 @@ impl DeviceManager {
pub fn check_mode_requests(&mut self) -> Result<(), ModeError> {
if let Some(request) = self.mode_node.try_recv_mode_request()? {
self.mode_req_recvd += 1;
self.handle_mode_request(request)?
}
Ok(())
@ -619,7 +625,7 @@ impl ModeRequestHandler for DeviceManager {
}
let request_id = requestor_info.map_or(0, |info| info.request_id());
self.mode_node
.request_sender_map
.request_sender_store
.0
.iter()
.for_each(|(_, sender)| {
@ -674,7 +680,7 @@ impl ModeRequestHandler for DeviceManager {
struct CommonDevice {
name: &'static str,
pub id: ComponentId,
pub mode_node: ModeRequestHandlerOneParentMpscBounded,
pub mode_node: ModeRequestHandlerMpscBounded,
pub mode_and_submode: ModeAndSubmode,
pub mode_req_mock: ModeRequestHandlerMock,
pub num_mode_msgs_recvd: u32,
@ -684,7 +690,7 @@ impl CommonDevice {
pub fn new(
name: &'static str,
id: ComponentId,
mode_node: ModeRequestHandlerOneParentMpscBounded,
mode_node: ModeRequestHandlerMpscBounded,
) -> Self {
Self {
name,
@ -804,7 +810,7 @@ pub struct AnnounceModeInfo {
}
pub struct AcsController {
pub mode_node: ModeRequestHandlerOneParentMpscBounded,
pub mode_node: ModeRequestHandlerMpscBounded,
pub mode_and_submode: ModeAndSubmode,
pub announce_mode_queue: RefCell<VecDeque<AnnounceModeInfo>>,
pub mode_req_mock: ModeRequestHandlerMock,
@ -953,36 +959,36 @@ impl TreeTestbench {
);
// Mode requestors and handlers.
let mgm_assy_node = ModeRequestorAndHandlerOneParentMpscBounded::new(
let mgm_assy_node = ModeRequestorAndHandlerMpscBounded::new(
TestComponentId::MagnetometerAssembly as ComponentId,
request_receiver_mgm_assy,
reply_receiver_mgm_assy,
);
let mgt_dev_mgmt_node = ModeRequestorAndHandlerOneParentMpscBounded::new(
let mgt_dev_mgmt_node = ModeRequestorAndHandlerMpscBounded::new(
TestComponentId::MgtDevManager as ComponentId,
request_receiver_mgt_man,
reply_receiver_mgt_man,
);
let acs_subsystem_node = ModeRequestorAndHandlerOneParentMpscBounded::new(
let acs_subsystem_node = ModeRequestorAndHandlerMpscBounded::new(
TestComponentId::AcsSubsystem as ComponentId,
request_receiver_acs_subsystem,
reply_receiver_acs_subsystem,
);
// Request handlers only.
let mgm_dev_node_0 = ModeRequestHandlerOneParentMpscBounded::new(
let mgm_dev_node_0 = ModeRequestHandlerMpscBounded::new(
TestComponentId::MagnetometerDevice0 as ComponentId,
request_receiver_mgm_dev_0,
);
let mgm_dev_node_1 = ModeRequestHandlerOneParentMpscBounded::new(
let mgm_dev_node_1 = ModeRequestHandlerMpscBounded::new(
TestComponentId::MagnetometerDevice1 as ComponentId,
request_receiver_mgm_dev_1,
);
let mgt_dev_node = ModeRequestHandlerOneParentMpscBounded::new(
let mgt_dev_node = ModeRequestHandlerMpscBounded::new(
TestComponentId::MagnetorquerDevice as ComponentId,
request_receiver_mgt_dev,
);
let acs_ctrl_node = ModeRequestHandlerOneParentMpscBounded::new(
let acs_ctrl_node = ModeRequestHandlerMpscBounded::new(
TestComponentId::AcsController as ComponentId,
request_receiver_acs_ctrl,
);
@ -1036,9 +1042,35 @@ impl TreeTestbench {
ModeAndSubmode::new(DefaultMode::NORMAL as u32, 0),
true,
));
let sequence_tbl_safe_0 = SequenceTableMapTable::new("SAFE_SEQ_0_TBL");
let sequence_tbl_safe_1 = SequenceTableMapTable::new("SAFE_SEQ_1_TBL");
let sequence_tbl_safe = SequenceTablesMapValue::new("SAFE_SEQ_TBL");
target_table_safe.add_entry(TargetTableEntry::new_with_precise_submode(
"MGT_MAN_NML",
TestComponentId::MgtDevManager as u64,
ModeAndSubmode::new(DefaultMode::NORMAL as u32, 0),
true,
));
let mut sequence_tbl_safe_0 = SequenceTableMapTable::new("SAFE_SEQ_0_TBL");
sequence_tbl_safe_0.add_entry(SequenceTableEntry::new(
"SAFE_SEQ_0_MGM_A",
TestComponentId::MagnetometerAssembly as u64,
ModeAndSubmode::new(DefaultMode::NORMAL as Mode, 0),
false,
));
sequence_tbl_safe_0.add_entry(SequenceTableEntry::new(
"SAFE_SEQ_0_MGT_MAN",
TestComponentId::MgtDevManager as u64,
ModeAndSubmode::new(DefaultMode::NORMAL as Mode, 0),
false,
));
let mut sequence_tbl_safe_1 = SequenceTableMapTable::new("SAFE_SEQ_1_TBL");
sequence_tbl_safe_1.add_entry(SequenceTableEntry::new(
"SAFE_SEQ_1_ACS_CTRL",
TestComponentId::AcsController as u64,
ModeAndSubmode::new(AcsMode::IDLE as Mode, 0),
false,
));
let mut sequence_tbl_safe = SequenceTablesMapValue::new("SAFE_SEQ_TBL");
sequence_tbl_safe.add_sequence_table(sequence_tbl_safe_0);
sequence_tbl_safe.add_sequence_table(sequence_tbl_safe_1);
acs_subsystem.add_target_and_sequence_table(
AcsMode::SAFE as u32,
target_table_safe,
@ -1154,6 +1186,7 @@ fn announce_recursively() {
tb.mgm_devs[1].run();
tb.mgt_dev.run();
}
assert_eq!(tb.subsystem.get_and_clear_num_mode_requests(), 1);
let mut announces = tb
.subsystem
.mode_req_handler_mock
@ -1164,6 +1197,7 @@ fn announce_recursively() {
assert_eq!(tb.ctrl.mode_req_mock.start_transition_calls.len(), 0);
assert_eq!(tb.ctrl.mode_and_submode(), UNKNOWN_MODE);
assert_eq!(announces.len(), 1);
assert_eq!(tb.mgm_assy.get_and_clear_num_mode_msgs(), 1);
announces = tb.mgm_assy.mode_req_mock.announce_mode_calls.borrow_mut();
assert_eq!(tb.mgm_assy.mode_req_mock.start_transition_calls.len(), 0);
assert_eq!(tb.mgm_assy.mode_and_submode(), UNKNOWN_MODE);
@ -1181,6 +1215,7 @@ fn announce_recursively() {
assert_eq!(tb.mgt_dev.mode_req_mock.start_transition_calls.len(), 0);
assert_eq!(tb.mgt_dev.mode_and_submode(), UNKNOWN_MODE);
assert_eq!(announces.len(), 1);
assert_eq!(tb.mgt_manager.get_and_clear_num_mode_requests(), 1);
announces = tb
.mgt_manager
.mode_req_mock