fixes for switching #262
@@ -43,6 +43,11 @@ impl PcduModel {
|
||||
}
|
||||
|
||||
pub async fn switch_device(&mut self, switch_and_target_state: (SwitchId, SwitchStateBinary)) {
|
||||
log::info!(
|
||||
"switching {:?} to {:?}",
|
||||
switch_and_target_state.0,
|
||||
switch_and_target_state.1
|
||||
);
|
||||
let val = self
|
||||
.switcher_map
|
||||
.0
|
||||
|
||||
@@ -183,6 +183,15 @@ impl<ComInterface: SpiInterface> MgmHandlerLis3Mdl<ComInterface> {
|
||||
self.mode_helpers.current
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn switch_id(&self) -> SwitchId {
|
||||
match self.id {
|
||||
ComponentId::AcsMgm0 => SwitchId::Mgm0,
|
||||
ComponentId::AcsMgm1 => SwitchId::Mgm1,
|
||||
_ => panic!("unexpected component id"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn periodic_operation(&mut self) {
|
||||
// Update current time.
|
||||
self.stamp_helper.update_from_now();
|
||||
@@ -364,9 +373,10 @@ impl<ComInterface: SpiInterface> MgmHandlerLis3Mdl<ComInterface> {
|
||||
let target_mode = self.mode_helpers.target.unwrap();
|
||||
if target_mode == DeviceMode::On || target_mode == DeviceMode::Normal {
|
||||
if self.mode_helpers.transition_state == TransitionState::Idle {
|
||||
// TODO: Switch ID for MGM1..
|
||||
let result = self
|
||||
.switch_helper
|
||||
.send_switch_on_cmd(MessageMetadata::new(0, self.id as u32), SwitchId::Mgm0);
|
||||
.send_switch_on_cmd(MessageMetadata::new(0, self.id as u32), self.switch_id());
|
||||
if result.is_err() {
|
||||
// Could not send switch command.. still continue with transition.
|
||||
log::error!("failed to send switch on command");
|
||||
@@ -374,7 +384,7 @@ impl<ComInterface: SpiInterface> MgmHandlerLis3Mdl<ComInterface> {
|
||||
self.mode_helpers.transition_state = TransitionState::PowerSwitching;
|
||||
}
|
||||
if self.mode_helpers.transition_state == TransitionState::PowerSwitching
|
||||
&& self.switch_helper.is_switch_on(SwitchId::Mgm0)
|
||||
&& self.switch_helper.is_switch_on(self.switch_id())
|
||||
{
|
||||
self.mode_helpers.transition_state = TransitionState::Done;
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ pub enum ModeReport {
|
||||
|
||||
/// Helper component for communication with a parent component, which is usually as assembly.
|
||||
pub struct QueueHelper {
|
||||
pub request_tx: [mpsc::SyncSender<super::mgm_assembly::ModeRequest>; 2],
|
||||
pub report_rx: [mpsc::Receiver<super::mgm_assembly::ModeReport>; 2],
|
||||
pub request_tx_queues: [mpsc::SyncSender<super::mgm_assembly::ModeRequest>; 2],
|
||||
pub report_rx_queues: [mpsc::Receiver<super::mgm_assembly::ModeReport>; 2],
|
||||
}
|
||||
|
||||
pub struct Assembly {
|
||||
@@ -31,8 +31,8 @@ impl Assembly {
|
||||
}
|
||||
|
||||
pub fn handle_mode_queue(&mut self) {
|
||||
loop {
|
||||
for rx in &mut self.helper.report_rx {
|
||||
for rx in &mut self.helper.report_rx_queues {
|
||||
loop {
|
||||
match rx.try_recv() {
|
||||
// TODO: Do something with the report.
|
||||
Ok(report) => match report {
|
||||
|
||||
@@ -280,17 +280,18 @@ impl<ComInterface: SerialInterface> PcduHandler<ComInterface> {
|
||||
switch_request_rx: mpsc::Receiver<GenericMessage<SwitchRequest>>,
|
||||
com_interface: ComInterface,
|
||||
shared_switch_map: Arc<Mutex<SwitchSet>>,
|
||||
init_mode: DeviceMode,
|
||||
) -> Self {
|
||||
Self {
|
||||
dev_str: "PCDU",
|
||||
//mode_node,
|
||||
tc_rx,
|
||||
switch_request_rx,
|
||||
tm_tx,
|
||||
com_interface,
|
||||
shared_switch_map,
|
||||
stamp_helper: TimestampHelper::default(),
|
||||
mode: DeviceMode::Off,
|
||||
// Start in normal mode by default. Assume that the PCDU itself is on by default.
|
||||
mode: init_mode,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +301,6 @@ impl<ComInterface: SerialInterface> PcduHandler<ComInterface> {
|
||||
self.stamp_helper.update_from_now();
|
||||
// Handle requests.
|
||||
self.handle_telecommands();
|
||||
//self.handle_mode_requests();
|
||||
self.handle_switch_requests();
|
||||
// Poll the switch states and/or telemetry regularly here.
|
||||
if self.mode() == DeviceMode::Normal || self.mode() == DeviceMode::On {
|
||||
@@ -608,12 +608,12 @@ mod tests {
|
||||
let shared_switch_map =
|
||||
Arc::new(Mutex::new(SwitchSet::new_with_init_switches_unknown()));
|
||||
let handler = PcduHandler::new(
|
||||
//mode_node,
|
||||
tc_rx,
|
||||
tm_tx.clone(),
|
||||
switch_reqest_rx,
|
||||
SerialInterfaceTest::default(),
|
||||
shared_switch_map,
|
||||
DeviceMode::Off,
|
||||
);
|
||||
Self {
|
||||
mode_request_tx,
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
use std::str::FromStr as _;
|
||||
|
||||
pub fn setup_logger() -> Result<(), fern::InitError> {
|
||||
// Read the RUST_LOG environment variable and parse it.
|
||||
// If the variable is not set or is invalid, default to Debug.
|
||||
let mut log_level = log::LevelFilter::Info;
|
||||
if let Ok(log_level_str) = std::env::var("RUST_LOG") {
|
||||
log_level = log::LevelFilter::from_str(&log_level_str).unwrap_or(log::LevelFilter::Info);
|
||||
}
|
||||
|
||||
fern::Dispatch::new()
|
||||
.format(|out, message, record| {
|
||||
out.finish(format_args!(
|
||||
@@ -9,7 +18,7 @@ pub fn setup_logger() -> Result<(), fern::InitError> {
|
||||
message
|
||||
))
|
||||
})
|
||||
.level(log::LevelFilter::Info)
|
||||
.level(log_level)
|
||||
.chain(std::io::stdout())
|
||||
.chain(fern::log_file("output.log")?)
|
||||
.apply()?;
|
||||
|
||||
@@ -190,25 +190,10 @@ fn main() {
|
||||
);
|
||||
let mut mgm_assembly = mgm_assembly::Assembly {
|
||||
helper: mgm_assembly::QueueHelper {
|
||||
request_tx: [mgm_0_mode_request_tx, mgm_1_mode_request_tx],
|
||||
report_rx: [mgm_0_mode_report_rx, mgm_1_mode_report_rx],
|
||||
request_tx_queues: [mgm_0_mode_request_tx, mgm_1_mode_request_tx],
|
||||
report_rx_queues: [mgm_0_mode_report_rx, mgm_1_mode_report_rx],
|
||||
},
|
||||
};
|
||||
// Connect PUS service to device handlers.
|
||||
/*
|
||||
connect_mode_nodes(
|
||||
&mut pus_stack.mode_srv,
|
||||
mgm_0_handler_mode_tx,
|
||||
&mut mgm_0_handler,
|
||||
pus_mode_reply_tx.clone(),
|
||||
);
|
||||
connect_mode_nodes(
|
||||
&mut pus_stack.mode_srv,
|
||||
mgm_1_handler_mode_tx,
|
||||
&mut mgm_1_handler,
|
||||
pus_mode_reply_tx.clone(),
|
||||
);
|
||||
*/
|
||||
|
||||
let pcdu_serial_interface = if let Some(sim_client) = opt_sim_client.as_mut() {
|
||||
sim_client.add_reply_recipient(satrs_minisim::SimComponent::Pcdu, pcdu_sim_reply_tx);
|
||||
@@ -219,23 +204,14 @@ fn main() {
|
||||
} else {
|
||||
SerialSimInterfaceWrapper::Dummy(SerialInterfaceDummy::default())
|
||||
};
|
||||
//let pcdu_mode_node =
|
||||
//ModeRequestHandlerMpscBounded::new(ComponentId::EpsPcdu as u32, pcdu_handler_mode_rx);
|
||||
let mut pcdu_handler = PcduHandler::new(
|
||||
pcdu_handler_tc_rx,
|
||||
tm_sink_tx.clone(),
|
||||
switch_request_rx,
|
||||
pcdu_serial_interface,
|
||||
shared_switch_set,
|
||||
DeviceMode::Normal,
|
||||
);
|
||||
/*
|
||||
connect_mode_nodes(
|
||||
&mut pus_stack.mode_srv,
|
||||
pcdu_handler_mode_tx.clone(),
|
||||
&mut pcdu_handler,
|
||||
pus_mode_reply_tx,
|
||||
);
|
||||
*/
|
||||
|
||||
// The PCDU is a critical component which should be in normal mode immediately.
|
||||
pcdu_handler_mode_tx
|
||||
|
||||
Reference in New Issue
Block a user