From 4d21770b5ee90262aa747e5c9b4e3dea52304d1b Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Fri, 15 Nov 2024 10:16:20 -0500 Subject: [PATCH] MGS/wicket: Add support for PSC 1 (#6996) Need to test this on a rack with two PSCs before merging, but running wicket locally I think this updates all the spots where the UI needs to show PSC 1 and allow navigating to it. Closes #6993. --- smf/mgs/config.toml | 12 +++--- wicket/src/state/inventory.rs | 7 +--- wicket/src/state/rack.rs | 70 +++++++++++++++++++++++++++++------ wicket/src/ui/widgets/rack.rs | 3 +- 4 files changed, 66 insertions(+), 26 deletions(-) diff --git a/smf/mgs/config.toml b/smf/mgs/config.toml index 3c82ef183b..0f311e5b66 100644 --- a/smf/mgs/config.toml +++ b/smf/mgs/config.toml @@ -91,13 +91,11 @@ interface = "psc0" ignition-target = 32 location = { switch0 = ["power", 0], switch1 = ["power", 0] } -# We have an ignition-target set aside for PSC1, but do not create an -# interface for it since we don't have a second PSC. -#[[switch.port]] -#kind = "switch-zone-interface" -#interface = "psc1" -#ignition-target = 33 -#location = { switch0 = ["power", 1], switch1 = ["power", 1] } +[[switch.port]] +kind = "switch-zone-interface" +interface = "psc1" +ignition-target = 33 +location = { switch0 = ["power", 1], switch1 = ["power", 1] } [[switch.port]] kind = "switch-zone-interface" diff --git a/wicket/src/state/inventory.rs b/wicket/src/state/inventory.rs index cec8e46fd9..d200f597e8 100644 --- a/wicket/src/state/inventory.rs +++ b/wicket/src/state/inventory.rs @@ -20,8 +20,7 @@ pub static ALL_COMPONENT_IDS: Lazy> = Lazy::new(|| { (0..=31u8) .map(ComponentId::Sled) .chain((0..=1u8).map(ComponentId::Switch)) - // Currently shipping racks don't have PSC 1. - .chain(std::iter::once(ComponentId::Psc(0))) + .chain((0..=1u8).map(ComponentId::Psc)) .collect() }); @@ -239,9 +238,7 @@ impl ComponentId { pub const MAX_SWITCH_ID: u8 = 1; /// The maximum possible power shelf ID. - /// - /// Currently shipping racks don't have PSC 1. - pub const MAX_PSC_ID: u8 = 0; + pub const MAX_PSC_ID: u8 = 1; pub fn new_sled(slot: u8) -> Result { if slot > Self::MAX_SLED_ID { diff --git a/wicket/src/state/rack.rs b/wicket/src/state/rack.rs index 3fbe4f762b..d8a3505b52 100644 --- a/wicket/src/state/rack.rs +++ b/wicket/src/state/rack.rs @@ -73,9 +73,8 @@ impl RackState { ComponentId::Sled(17) } } - // Skip over Psc(1) because it is always empty in currently shipping - // racks. - ComponentId::Psc(0) => ComponentId::Switch(1), + ComponentId::Psc(0) => ComponentId::Psc(1), + ComponentId::Psc(1) => ComponentId::Switch(1), _ => unreachable!(), }; } @@ -84,9 +83,7 @@ impl RackState { self.selected = match self.selected { ComponentId::Sled(16 | 17) => ComponentId::Switch(1), ComponentId::Sled(i) => ComponentId::Sled((30 + i) % 32), - // Skip over Psc(1) because it is always empty in currently shipping - // racks. - ComponentId::Switch(1) => ComponentId::Psc(0), + ComponentId::Switch(1) => ComponentId::Psc(1), ComponentId::Switch(0) => { if self.left_column { ComponentId::Sled(14) @@ -95,6 +92,7 @@ impl RackState { } } ComponentId::Psc(0) => ComponentId::Switch(0), + ComponentId::Psc(1) => ComponentId::Psc(0), _ => unreachable!(), }; } @@ -114,9 +112,8 @@ impl RackState { ComponentId::Sled(15) => ComponentId::Switch(0), ComponentId::Sled(i) => ComponentId::Sled((i + 1) % 32), ComponentId::Switch(0) => ComponentId::Psc(0), - // Skip over Psc(1) because it is always empty in currently shipping - // racks. - ComponentId::Psc(0) => ComponentId::Switch(1), + ComponentId::Psc(0) => ComponentId::Psc(1), + ComponentId::Psc(1) => ComponentId::Switch(1), ComponentId::Switch(1) => ComponentId::Sled(16), _ => unreachable!(), }; @@ -128,9 +125,8 @@ impl RackState { ComponentId::Sled(16) => ComponentId::Switch(1), ComponentId::Sled(0) => ComponentId::Sled(31), ComponentId::Sled(i) => ComponentId::Sled(i - 1), - // Skip over Psc(1) because it is always empty in currently shipping - // racks. - ComponentId::Switch(1) => ComponentId::Psc(0), + ComponentId::Switch(1) => ComponentId::Psc(1), + ComponentId::Psc(1) => ComponentId::Psc(0), ComponentId::Psc(0) => ComponentId::Switch(0), ComponentId::Switch(0) => ComponentId::Sled(15), _ => unreachable!(), @@ -149,3 +145,53 @@ impl RackState { self.log = Some(log); } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::state::ALL_COMPONENT_IDS; + + #[test] + fn prev_next_are_opposites() { + let mut state = RackState::new(); + + for &id in ALL_COMPONENT_IDS.iter() { + state.selected = id; + state.next(); + state.prev(); + assert_eq!( + state.selected, id, + "prev is not inverse of next for {id:?}" + ); + state.prev(); + state.next(); + assert_eq!( + state.selected, id, + "next is not inverse of prev for {id:?}" + ); + } + } + + #[test] + fn up_down_are_opposites() { + let mut state = RackState::new(); + + for &id in ALL_COMPONENT_IDS.iter() { + state.selected = id; + state.set_column(); + + state.down(); + state.up(); + assert_eq!( + state.selected, id, + "up is not inverse of down for {id:?}" + ); + state.up(); + state.down(); + assert_eq!( + state.selected, id, + "down is not inverse of up for {id:?}" + ); + } + } +} diff --git a/wicket/src/ui/widgets/rack.rs b/wicket/src/ui/widgets/rack.rs index b393b63528..7a69f120c1 100644 --- a/wicket/src/ui/widgets/rack.rs +++ b/wicket/src/ui/widgets/rack.rs @@ -147,8 +147,7 @@ impl<'a> Rack<'a> { let inner = block.inner(power_shelf); block.render(power_shelf, buf); - if i == 0 && presence == ComponentPresence::Present { - // Shipping racks only have one power shelf -- only show that one. + if presence == ComponentPresence::Present { let width = inner.right() - inner.left(); let step = width / 6; let border = (width - step * 6) / 2;