-
Notifications
You must be signed in to change notification settings - Fork 102
feat(orb-mcu-util): print new diamond evt version #381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,28 +1,77 @@ | ||||||
| use std::fmt::{Display, Formatter}; | ||||||
|
|
||||||
| use orb_mcu_interface::orb_messages; | ||||||
| use std::fmt::{Display, Formatter}; | ||||||
|
|
||||||
| #[derive(Clone, Debug, Default)] | ||||||
| pub struct OrbRevision(pub orb_messages::Hardware); | ||||||
|
|
||||||
| trait OrbVersionFromInt { | ||||||
| fn from_version_i32(value: i32) -> Self; | ||||||
| } | ||||||
| impl OrbVersionFromInt for orb_messages::hardware::OrbVersion { | ||||||
| fn from_version_i32(value: i32) -> Self { | ||||||
| match value { | ||||||
| 1 => orb_messages::hardware::OrbVersion::HwVersionPearlEv1, | ||||||
| 2 => orb_messages::hardware::OrbVersion::HwVersionPearlEv2, | ||||||
| 3 => orb_messages::hardware::OrbVersion::HwVersionPearlEv3, | ||||||
| 4 => orb_messages::hardware::OrbVersion::HwVersionPearlEv4, | ||||||
| 5 => orb_messages::hardware::OrbVersion::HwVersionPearlEv5, | ||||||
| 6 => orb_messages::hardware::OrbVersion::HwVersionDiamondPoc1, | ||||||
| 7 => orb_messages::hardware::OrbVersion::HwVersionDiamondPoc2, | ||||||
| 8 => orb_messages::hardware::OrbVersion::HwVersionDiamondB3, | ||||||
| 9 => orb_messages::hardware::OrbVersion::HwVersionDiamondEvt, | ||||||
| _ => orb_messages::hardware::OrbVersion::HwVersionUnknown, | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| impl Display for OrbRevision { | ||||||
| fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||||||
| if self.0.version | ||||||
| == i32::from(orb_messages::hardware::OrbVersion::HwVersionUnknown) | ||||||
| { | ||||||
| write!(f, "unknown") | ||||||
| } else if self.0.version | ||||||
| < orb_messages::hardware::OrbVersion::HwVersionDiamondPoc1 as i32 | ||||||
| { | ||||||
| write!(f, "EVT{:?}", self.0.version) | ||||||
| } else { | ||||||
| write!( | ||||||
| f, | ||||||
| "Diamond_B{:?}", | ||||||
| self.0.version | ||||||
| - orb_messages::hardware::OrbVersion::HwVersionDiamondPoc1 as i32 | ||||||
| + 1 | ||||||
| ) | ||||||
| match orb_messages::hardware::OrbVersion::from_version_i32(self.0.version) { | ||||||
| orb_messages::hardware::OrbVersion::HwVersionUnknown => { | ||||||
| // from_version_i32 returned unknown but the version might not be 0 | ||||||
| // meaning it's known by the firmware but not by the current binary | ||||||
| if self.0.version | ||||||
| == orb_messages::hardware::OrbVersion::HwVersionUnknown as i32 | ||||||
| { | ||||||
| return write!(f, "unknown"); | ||||||
| } | ||||||
|
|
||||||
| tracing::error!( | ||||||
| "A new orb revision might not be implemented by that binary: {:?}.", | ||||||
| self.0.version | ||||||
| ); | ||||||
|
|
||||||
| // let's write if it's a pearl or diamond orb, guessing by the version number | ||||||
| if self.0.version | ||||||
| < orb_messages::hardware::OrbVersion::HwVersionDiamondPoc1 as i32 | ||||||
| { | ||||||
| write!(f, "Pearl_unknown") | ||||||
| } else { | ||||||
| write!(f, "Diamond_unknown") | ||||||
| } | ||||||
| } | ||||||
| orb_messages::hardware::OrbVersion::HwVersionPearlEv1 | ||||||
| | orb_messages::hardware::OrbVersion::HwVersionPearlEv2 | ||||||
| | orb_messages::hardware::OrbVersion::HwVersionPearlEv3 | ||||||
| | orb_messages::hardware::OrbVersion::HwVersionPearlEv4 | ||||||
| | orb_messages::hardware::OrbVersion::HwVersionPearlEv5 => { | ||||||
| write!(f, "EVT{:?}", self.0.version) | ||||||
|
||||||
| write!(f, "EVT{:?}", self.0.version) | |
| write!(f, "Pearl EV{:?}", self.0.version) |
I'd prefer verbose unless any tools depend on it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would prefer too but indeed, this would break things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting... is this
consta new thing?what does it bring?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its like constexpr in c++ - evaluation is done at compile-time. Const functions have been around for a long time (possibly since 1.0?). But they are more useful nowadays, and especially after the
inline_constfeature was stabilized last year: rust-lang/rust#104087.constmostly gets used in places where assignment to aconstor astaticvariable is necessary.