1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! The decoded `RESP(VERSION)` payload.
use core::fmt;
/// The decoded `RESP(VERSION)` payload.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Version {
/// Protocol version; [`PROTO_VER`](crate::PROTO_VER) is the only value this build accepts.
pub proto_ver: u8,
pub fw_major: u8,
pub fw_minor: u8,
pub fw_patch: u8,
/// The device chip's factory base MAC, a stable per-box identity that survives port renumbering.
pub mac: [u8; 6],
/// The box's human-readable name, never empty (firmware synthesises a `Medius-XXXX` default from the MAC).
pub name: String,
}
impl Version {
/// The base MAC as 12 lowercase hex digits, no separators; the canonical box id.
pub fn mac_hex(&self) -> String {
let mut s = String::with_capacity(12);
for b in self.mac {
s.push(char::from_digit((b >> 4) as u32, 16).unwrap());
s.push(char::from_digit((b & 0xF) as u32, 16).unwrap());
}
s
}
}
impl fmt::Display for Version {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"fw {}.{}.{}",
self.fw_major, self.fw_minor, self.fw_patch
)
}
}