Skip to content

Commit 64f5741

Browse files
authored
Add ComponentDetails::LastPostCode (#451)
1 parent 6bd2660 commit 64f5741

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

faux-mgs/src/main.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,9 +1344,31 @@ async fn run_command(
13441344
if json {
13451345
return Ok(Output::Json(component_details_to_json(details)));
13461346
}
1347+
1348+
/// Helper `struct` to pretty-print component details
1349+
///
1350+
/// This normally delegates to `Debug`, but prints `LastPostCode` as
1351+
/// a hex value for convenience.
1352+
struct ComponentDetailPrinter(gateway_messages::ComponentDetails);
1353+
impl std::fmt::Display for ComponentDetailPrinter {
1354+
fn fmt(
1355+
&self,
1356+
f: &mut std::fmt::Formatter<'_>,
1357+
) -> std::fmt::Result {
1358+
use gateway_messages::ComponentDetails;
1359+
match &self.0 {
1360+
ComponentDetails::LastPostCode(p) => {
1361+
write!(f, "LastPostCode({:#x})", p.0)
1362+
}
1363+
d => write!(f, "{d:?}"),
1364+
}
1365+
}
1366+
}
1367+
13471368
let mut lines = Vec::new();
13481369
for entry in details.entries {
1349-
lines.push(format!("{entry:?}"));
1370+
let d = ComponentDetailPrinter(entry);
1371+
lines.push(format!("{d}"));
13501372
}
13511373
Ok(Output::Lines(lines))
13521374
}
@@ -2240,6 +2262,7 @@ fn component_details_to_json(details: SpComponentDetails) -> serde_json::Value {
22402262
enum ComponentDetails {
22412263
PortStatus(Result<PortStatus, PortStatusError>),
22422264
Measurement(Measurement),
2265+
LastPostCode(u32),
22432266
}
22442267

22452268
#[derive(serde::Serialize)]
@@ -2263,6 +2286,9 @@ fn component_details_to_json(details: SpComponentDetails) -> serde_json::Value {
22632286
value: m.value,
22642287
})
22652288
}
2289+
gateway_messages::ComponentDetails::LastPostCode(code) => {
2290+
ComponentDetails::LastPostCode(code.0)
2291+
}
22662292
})
22672293
.collect::<Vec<_>>();
22682294

gateway-messages/src/sp_to_mgs.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ use serde_repr::Serialize_repr;
2525
pub mod ignition;
2626
pub mod measurement;
2727
pub mod monorail_port_status;
28+
pub mod sp5_details;
2829

2930
pub use ignition::IgnitionState;
3031
pub use measurement::Measurement;
32+
pub use sp5_details::LastPostCode;
3133

3234
use ignition::IgnitionError;
3335
use measurement::MeasurementHeader;
@@ -710,17 +712,21 @@ pub struct TlvPage {
710712
/// serialization traits; it only serves as an organizing collection of the
711713
/// possible types contained in a component details message. Each TLV-encoded
712714
/// struct corresponds to one of these cases.
715+
///
716+
/// As such, it is not part of the explicit message versioning scheme
713717
#[derive(Debug, Clone)]
714718
pub enum ComponentDetails {
715719
PortStatus(Result<PortStatus, PortStatusError>),
716720
Measurement(Measurement),
721+
LastPostCode(LastPostCode),
717722
}
718723

719724
impl ComponentDetails {
720725
pub fn tag(&self) -> tlv::Tag {
721726
match self {
722727
ComponentDetails::PortStatus(_) => PortStatus::TAG,
723728
ComponentDetails::Measurement(_) => MeasurementHeader::TAG,
729+
ComponentDetails::LastPostCode(_) => LastPostCode::TAG,
724730
}
725731
}
726732

@@ -742,6 +748,9 @@ impl ComponentDetails {
742748
Ok(n + m.name.len())
743749
}
744750
}
751+
ComponentDetails::LastPostCode(code) => {
752+
hubpack::serialize(buf, code)
753+
}
745754
}
746755
}
747756
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
use crate::tlv;
6+
use hubpack::SerializedSize;
7+
use serde::{Deserialize, Serialize};
8+
9+
/// Most recent POST code seen by the sequencer FPGA
10+
#[derive(Copy, Clone, Debug, Serialize, Deserialize, SerializedSize)]
11+
pub struct LastPostCode(pub u32);
12+
13+
impl LastPostCode {
14+
pub const TAG: tlv::Tag = tlv::Tag(*b"POST");
15+
}

gateway-sp-comms/src/single_sp.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,7 @@ impl TlvRpc for ComponentDetailsTlvRpc<'_> {
15761576
use gateway_messages::measurement::MeasurementHeader;
15771577
use gateway_messages::monorail_port_status::PortStatus;
15781578
use gateway_messages::monorail_port_status::PortStatusError;
1579+
use gateway_messages::sp5_details::LastPostCode;
15791580

15801581
match tag {
15811582
PortStatus::TAG => {
@@ -1622,6 +1623,23 @@ impl TlvRpc for ComponentDetailsTlvRpc<'_> {
16221623
value: header.value,
16231624
})))
16241625
}
1626+
LastPostCode::TAG => {
1627+
let (result, leftover) =
1628+
gateway_messages::deserialize::<LastPostCode>(value)
1629+
.map_err(|err| CommunicationError::TlvDeserialize {
1630+
tag,
1631+
err,
1632+
})?;
1633+
1634+
if !leftover.is_empty() {
1635+
info!(
1636+
self.log,
1637+
"ignoring unexpected data in LastPostCode TLV entry"
1638+
);
1639+
}
1640+
1641+
Ok(Some(ComponentDetails::LastPostCode(result)))
1642+
}
16251643
_ => {
16261644
info!(
16271645
self.log,

0 commit comments

Comments
 (0)