|
8 | 8 |
|
9 | 9 | use super::HostStartupOptions; |
10 | 10 | use super::IgnitionCommand; |
| 11 | +use super::ImageVersion; |
11 | 12 | use super::PowerState; |
| 13 | +use super::RotImageDetails; |
| 14 | +use super::RotSlot; |
| 15 | +use super::RotState; |
12 | 16 | use super::SpComponentInfo; |
13 | 17 | use super::SpComponentList; |
14 | 18 | use super::SpComponentPresence; |
@@ -94,28 +98,78 @@ impl From<PowerState> for gateway_messages::PowerState { |
94 | 98 | } |
95 | 99 | } |
96 | 100 |
|
97 | | -fn stringify_serial_number(serial: &[u8]) -> String { |
98 | | - // We expect serial numbers to be ASCII and 0-padded: find the first 0 byte |
99 | | - // and convert to a string. If that fails, hexlify the entire slice. |
100 | | - let first_zero = |
101 | | - serial.iter().position(|&b| b == 0).unwrap_or(serial.len()); |
| 101 | +impl From<gateway_messages::ImageVersion> for ImageVersion { |
| 102 | + fn from(v: gateway_messages::ImageVersion) -> Self { |
| 103 | + Self { epoch: v.epoch, version: v.version } |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +// We expect serial and model numbers to be ASCII and 0-padded: find the first 0 |
| 108 | +// byte and convert to a string. If that fails, hexlify the entire slice. |
| 109 | +fn stringify_byte_string(bytes: &[u8]) -> String { |
| 110 | + let first_zero = bytes.iter().position(|&b| b == 0).unwrap_or(bytes.len()); |
102 | 111 |
|
103 | | - str::from_utf8(&serial[..first_zero]) |
| 112 | + str::from_utf8(&bytes[..first_zero]) |
104 | 113 | .map(|s| s.to_string()) |
105 | | - .unwrap_or_else(|_err| hex::encode(serial)) |
| 114 | + .unwrap_or_else(|_err| hex::encode(bytes)) |
106 | 115 | } |
107 | 116 |
|
108 | 117 | impl From<Result<gateway_messages::SpState, SpCommsError>> for SpState { |
109 | 118 | fn from(result: Result<gateway_messages::SpState, SpCommsError>) -> Self { |
110 | 119 | match result { |
111 | 120 | Ok(state) => Self::Enabled { |
112 | | - serial_number: stringify_serial_number(&state.serial_number), |
| 121 | + serial_number: stringify_byte_string(&state.serial_number), |
| 122 | + model: stringify_byte_string(&state.model), |
| 123 | + revision: state.revision, |
| 124 | + hubris_archive_id: hex::encode(&state.hubris_archive_id), |
| 125 | + base_mac_address: state.base_mac_address, |
| 126 | + version: ImageVersion::from(state.version), |
| 127 | + power_state: PowerState::from(state.power_state), |
| 128 | + rot: RotState::from(state.rot), |
113 | 129 | }, |
114 | 130 | Err(err) => Self::CommunicationFailed { message: err.to_string() }, |
115 | 131 | } |
116 | 132 | } |
117 | 133 | } |
118 | 134 |
|
| 135 | +impl From<Result<gateway_messages::RotState, gateway_messages::RotError>> |
| 136 | + for RotState |
| 137 | +{ |
| 138 | + fn from( |
| 139 | + result: Result<gateway_messages::RotState, gateway_messages::RotError>, |
| 140 | + ) -> Self { |
| 141 | + match result { |
| 142 | + Ok(state) => { |
| 143 | + let boot_state = state.rot_updates.boot_state; |
| 144 | + Self::Enabled { |
| 145 | + active: boot_state.active.into(), |
| 146 | + slot_a: boot_state.slot_a.map(Into::into), |
| 147 | + slot_b: boot_state.slot_b.map(Into::into), |
| 148 | + } |
| 149 | + } |
| 150 | + Err(err) => Self::CommunicationFailed { message: err.to_string() }, |
| 151 | + } |
| 152 | + } |
| 153 | +} |
| 154 | + |
| 155 | +impl From<gateway_messages::RotSlot> for RotSlot { |
| 156 | + fn from(slot: gateway_messages::RotSlot) -> Self { |
| 157 | + match slot { |
| 158 | + gateway_messages::RotSlot::A => Self::A, |
| 159 | + gateway_messages::RotSlot::B => Self::B, |
| 160 | + } |
| 161 | + } |
| 162 | +} |
| 163 | + |
| 164 | +impl From<gateway_messages::RotImageDetails> for RotImageDetails { |
| 165 | + fn from(details: gateway_messages::RotImageDetails) -> Self { |
| 166 | + Self { |
| 167 | + digest: hex::encode(&details.digest), |
| 168 | + version: details.version.into(), |
| 169 | + } |
| 170 | + } |
| 171 | +} |
| 172 | + |
119 | 173 | impl From<Result<gateway_messages::SpState, CommunicationError>> for SpState { |
120 | 174 | fn from( |
121 | 175 | result: Result<gateway_messages::SpState, CommunicationError>, |
|
0 commit comments