Skip to content

Commit

Permalink
periodic MGM data looks good
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Jun 3, 2024
1 parent 49733c8 commit 067c731
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 16 deletions.
7 changes: 5 additions & 2 deletions satrs-example/src/acs/mgm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use satrs::mode::{
};
use satrs::pus::{EcssTmSender, PusTmVariant};
use satrs::request::{GenericMessage, MessageMetadata, UniqueApidTargetId};
use satrs_example::config::components::PUS_MODE_SERVICE;
use satrs_example::config::components::{NO_SENDER, PUS_MODE_SERVICE};

use crate::hk::PusHkHelper;
use crate::pus::hk::{HkReply, HkReplyVariant};
Expand Down Expand Up @@ -421,9 +421,12 @@ impl<
self.mode_helpers.target = None;
self.announce_mode(requestor, false);
if let Some(requestor) = requestor {
if requestor.sender_id() == NO_SENDER {
return Ok(());
}
if requestor.sender_id() != PUS_MODE_SERVICE.id() {
log::warn!(
"can not send back mode reply to sender {}",
"can not send back mode reply to sender {:x}",
requestor.sender_id()
);
} else {
Expand Down
3 changes: 2 additions & 1 deletion satrs-example/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub mod mode_err {
}

pub mod components {
use satrs::request::UniqueApidTargetId;
use satrs::{request::UniqueApidTargetId, ComponentId};
use strum::EnumIter;

#[derive(Copy, Clone, PartialEq, Eq, EnumIter)]
Expand Down Expand Up @@ -184,6 +184,7 @@ pub mod components {
UniqueApidTargetId::new(Apid::Tmtc as u16, TmtcId::UdpServer as u32);
pub const TCP_SERVER: UniqueApidTargetId =
UniqueApidTargetId::new(Apid::Tmtc as u16, TmtcId::TcpServer as u32);
pub const NO_SENDER: ComponentId = ComponentId::MAX;
}

pub mod pool {
Expand Down
12 changes: 9 additions & 3 deletions satrs-example/src/eps/pcdu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use satrs::{
request::{GenericMessage, MessageMetadata, UniqueApidTargetId},
spacepackets::ByteConversionError,
};
use satrs_example::{config::components::PUS_MODE_SERVICE, DeviceMode, TimestampHelper};
use satrs_example::{
config::components::{NO_SENDER, PUS_MODE_SERVICE},
DeviceMode, TimestampHelper,
};
use satrs_minisim::{
eps::{
PcduReply, PcduRequest, PcduSwitch, SwitchMap, SwitchMapBinaryWrapper, SwitchMapWrapper,
Expand Down Expand Up @@ -60,9 +63,9 @@ impl SerialInterface for SerialInterfaceToSim {
type Error = ();

fn send(&self, data: &[u8]) -> Result<(), Self::Error> {
let request: SimRequest = serde_json::from_slice(data).unwrap();
let request: PcduRequest = serde_json::from_slice(data).expect("expected a PCDU request");
self.sim_request_tx
.send(request)
.send(SimRequest::new_with_epoch_time(request))
.expect("failed to send request to simulation");
Ok(())
}
Expand Down Expand Up @@ -437,6 +440,9 @@ impl<ComInterface: SerialInterface, TmSender: EcssTmSender> ModeRequestHandler
) -> Result<(), Self::Error> {
self.announce_mode(requestor, false);
if let Some(requestor) = requestor {
if requestor.sender_id() == NO_SENDER {
return Ok(());
}
if requestor.sender_id() != PUS_MODE_SERVICE.id() {
log::warn!(
"can not send back mode reply to sender {}",
Expand Down
28 changes: 23 additions & 5 deletions satrs-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ use pus::test::create_test_service_dynamic;
use satrs::hal::std::tcp_server::ServerConfig;
use satrs::hal::std::udp_server::UdpTcServer;
use satrs::pus::HandlingStatus;
use satrs::request::GenericMessage;
use satrs::request::{GenericMessage, MessageMetadata};
use satrs::tmtc::{PacketSenderWithSharedPool, SharedPacketPool};
use satrs_example::config::pool::{create_sched_tc_pool, create_static_pools};
use satrs_example::config::tasks::{
FREQ_MS_AOCS, FREQ_MS_PUS_STACK, FREQ_MS_UDP_TMTC, SIM_CLIENT_IDLE_DELAY_MS,
};
use satrs_example::config::{OBSW_SERVER_ADDR, PACKET_ID_VALIDATOR, SERVER_PORT};
use satrs_example::DeviceMode;

use crate::acs::mgm::{
MgmHandlerLis3Mdl, MpscModeLeafInterface, SpiDummyInterface, SpiSimInterface,
Expand All @@ -46,10 +47,12 @@ use crate::pus::scheduler::{create_scheduler_service_dynamic, create_scheduler_s
use crate::pus::test::create_test_service_static;
use crate::pus::{PusTcDistributor, PusTcMpscRouter};
use crate::requests::{CompositeRequest, GenericRequestRouter};
use satrs::mode::ModeRequest;
use satrs::mode::{Mode, ModeAndSubmode, ModeRequest};
use satrs::pus::event_man::EventRequestWithToken;
use satrs::spacepackets::{time::cds::CdsTime, time::TimeWriter};
use satrs_example::config::components::{MGM_HANDLER_0, PCDU_HANDLER, TCP_SERVER, UDP_SERVER};
use satrs_example::config::components::{
MGM_HANDLER_0, NO_SENDER, PCDU_HANDLER, TCP_SERVER, UDP_SERVER,
};
use std::net::{IpAddr, SocketAddr};
use std::sync::{mpsc, Mutex};
use std::sync::{Arc, RwLock};
Expand Down Expand Up @@ -98,7 +101,7 @@ fn static_tmtc_pool_main() {
.insert(PCDU_HANDLER.id(), pcdu_handler_composite_tx);
request_map
.mode_router_map
.insert(PCDU_HANDLER.id(), pcdu_handler_mode_tx);
.insert(PCDU_HANDLER.id(), pcdu_handler_mode_tx.clone());

// This helper structure is used by all telecommand providers which need to send telecommands
// to the TC source.
Expand Down Expand Up @@ -272,6 +275,7 @@ fn static_tmtc_pool_main() {
} else {
SerialSimInterfaceWrapper::Dummy(SerialInterfaceDummy::default())
};

let mut pcdu_handler = PcduHandler::new(
PCDU_HANDLER,
"PCDU",
Expand All @@ -283,6 +287,13 @@ fn static_tmtc_pool_main() {
pcdu_serial_interface,
shared_switch_set,
);
// The PCDU is a critical component which should be in normal mode immediately.
pcdu_handler_mode_tx
.send(GenericMessage::new(
MessageMetadata::new(0, NO_SENDER),
ModeRequest::SetMode(ModeAndSubmode::new(DeviceMode::Normal as Mode, 0)),
))
.expect("sending initial mode request failed");

info!("Starting TMTC and UDP task");
let jh_udp_tmtc = thread::Builder::new()
Expand Down Expand Up @@ -420,7 +431,7 @@ fn dyn_tmtc_pool_main() {
.insert(PCDU_HANDLER.id(), pcdu_handler_composite_tx);
request_map
.mode_router_map
.insert(PCDU_HANDLER.id(), pcdu_handler_mode_tx);
.insert(PCDU_HANDLER.id(), pcdu_handler_mode_tx.clone());

// Create event handling components
// These sender handles are used to send event requests, for example to enable or disable
Expand Down Expand Up @@ -583,6 +594,13 @@ fn dyn_tmtc_pool_main() {
pcdu_serial_interface,
shared_switch_set,
);
// The PCDU is a critical component which should be in normal mode immediately.
pcdu_handler_mode_tx
.send(GenericMessage::new(
MessageMetadata::new(0, NO_SENDER),
ModeRequest::SetMode(ModeAndSubmode::new(DeviceMode::Normal as Mode, 0)),
))
.expect("sending initial mode request failed");

info!("Starting TMTC and UDP task");
let jh_udp_tmtc = thread::Builder::new()
Expand Down
1 change: 1 addition & 0 deletions satrs-example/src/pus/hk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct HkReply {
}

#[derive(Clone, PartialEq, Debug)]
#[allow(dead_code)]
pub enum HkReplyVariant {
Ack,
Failed(ResultU16),
Expand Down
12 changes: 7 additions & 5 deletions satrs-minisim/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ use crate::{
eps::PcduModel,
};

const SIM_CTRL_REQ_WIRETAPPING: bool = true;
const MGM_REQ_WIRETAPPING: bool = true;
const PCDU_REQ_WIRETAPPING: bool = true;
const MGT_REQ_WIRETAPPING: bool = true;
const WARNING_FOR_STALE_DATA: bool = false;

const SIM_CTRL_REQ_WIRETAPPING: bool = false;
const MGM_REQ_WIRETAPPING: bool = false;
const PCDU_REQ_WIRETAPPING: bool = false;
const MGT_REQ_WIRETAPPING: bool = false;

// The simulation controller processes requests and drives the simulation.
pub struct SimController {
Expand Down Expand Up @@ -72,7 +74,7 @@ impl SimController {
loop {
match self.request_receiver.try_recv() {
Ok(request) => {
if request.timestamp < old_timestamp {
if request.timestamp < old_timestamp && WARNING_FOR_STALE_DATA {
log::warn!("stale data with timestamp {:?} received", request.timestamp);
}
if let Err(e) = match request.component() {
Expand Down

0 comments on commit 067c731

Please sign in to comment.