only poll when no transitions are active
This commit is contained in:
@@ -264,8 +264,10 @@ impl MgmHandlerLis3Mdl {
|
||||
}
|
||||
}
|
||||
|
||||
// Poll sensor before checking and generating HK.
|
||||
if self.mode() == DeviceMode::Normal {
|
||||
// Poll sensor before checking and generating HK. The device is not polled during mode
|
||||
// transitions, which includes all FDIR actions like power cycling or switching off a
|
||||
// faulty device. Faults are expected then, and polling would only add noise.
|
||||
if self.mode() == DeviceMode::Normal && self.switch_and_mode_helper.target().is_none() {
|
||||
log::trace!("polling LIS3MDL sensor {}", self.id.str());
|
||||
self.poll_sensor();
|
||||
}
|
||||
@@ -486,10 +488,8 @@ impl MgmHandlerLis3Mdl {
|
||||
}
|
||||
|
||||
fn switch_off_faulty_device(&mut self) {
|
||||
// Do not restart an already pending Off transition: poll_sensor still calls
|
||||
// this every cycle the fault persists, and current stays Normal until the
|
||||
// transition completes, so re-triggering here would keep resetting the
|
||||
// transition state machine before it can ever finish.
|
||||
// Do not restart an already pending Off transition, which would reset the transition
|
||||
// state machine before it can finish.
|
||||
if self.switch_and_mode_helper.target() != Some(DeviceMode::Off) {
|
||||
log::warn!("{}: commanding device off due to fault", self.id.str());
|
||||
self.start_transition(DeviceMode::Off, None);
|
||||
@@ -1095,9 +1095,12 @@ mod tests {
|
||||
testbench.mode_report_rx.try_iter().for_each(drop);
|
||||
testbench.exceed_spi_fault_threshold();
|
||||
testbench.test_spi_interface().next_mgm_data = MgmLis3RawValues::default();
|
||||
let call_count = testbench.test_spi_interface().call_count;
|
||||
|
||||
testbench.complete_power_cycle();
|
||||
|
||||
// The device is only polled again once the power cycle is done.
|
||||
assert_eq!(testbench.test_spi_interface().call_count, call_count + 1);
|
||||
// The power cycle is hidden from the parent.
|
||||
assert!(testbench.mode_report_rx.try_recv().is_err());
|
||||
|
||||
@@ -1144,15 +1147,17 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_faults_while_switching_off_keep_component_faulty() {
|
||||
fn test_faulty_device_is_not_polled_while_switching_off() {
|
||||
let mut testbench = MgmTestbench::new();
|
||||
testbench.switch_to_normal();
|
||||
testbench.recover_until_faulty();
|
||||
let call_count = testbench.test_spi_interface().call_count;
|
||||
|
||||
// The switch-off takes a while and the device is still polled in the meantime.
|
||||
// The switch-off takes a while.
|
||||
for _ in 0..SPI_FAULT_THRESHOLD + 1 {
|
||||
testbench.handler.periodic_operation();
|
||||
}
|
||||
assert_eq!(testbench.test_spi_interface().call_count, call_count);
|
||||
assert_eq!(testbench.health(), Some(HealthState::Faulty));
|
||||
testbench.set_switch_state(SwitchState::Off);
|
||||
testbench.handler.periodic_operation();
|
||||
|
||||
Reference in New Issue
Block a user