pub struct GroupAddress(/* private fields */);Expand description
Where a telegram is addressed: 16 bits naming a group, not a device.
How those 16 bits divide into levels is an installation’s convention and
not something the frame states, so the same address reads 2 ways. The
3-level split - 5 bits of main, 3 of middle, 8 of sub - is this type’s
fmt::Display and what FromStr parses. The 2-level split reads the
low 11 bits as 1 sub group and has its own named surface:
Self::new_two_level, Self::parse_two_level,
Self::two_level_sub, and Self::to_two_level_display.
Implementations§
Source§impl GroupAddress
impl GroupAddress
Sourcepub const fn new_three_level(main: u8, middle: u8, sub: u8) -> Result<Self>
pub const fn new_three_level(main: u8, middle: u8, sub: u8) -> Result<Self>
Builds an address from 3 levels, refusing a main past 31 (it has 5 bits) or a middle past 7 (3 bits). Every sub value fits its 8 bits.
Sourcepub const fn new_two_level(main: u8, sub: u16) -> Result<Self>
pub const fn new_two_level(main: u8, sub: u16) -> Result<Self>
Builds an address as an installation that addresses in 2 levels states it: a main group and 1 sub group under it.
The main is the same top 5 bits either convention uses, and the sub
takes the remaining 11 - which is why it is refused past 2047 rather
than 255. The result is an ordinary GroupAddress and prints in the
3-level form unless asked for Self::to_two_level_display; the
bits, not the convention, are what a telegram carries.
Sourcepub const fn from_raw(raw: u16) -> Self
pub const fn from_raw(raw: u16) -> Self
The address the given 2 octets state, as a telegram carries them.
Infallible: every u16 maps to a structurally valid group address (5-bit main + 3-bit middle + 8-bit sub, or 5-bit main + 11-bit sub, both covering the full 16-bit space), so a checked constructor would have no invalid input to reject.
Sourcepub const fn raw(self) -> u16
pub const fn raw(self) -> u16
The address as the 16-bit value a telegram carries, most significant octet first on the wire.
Sourcepub const fn main(self) -> u8
pub const fn main(self) -> u8
The main group: the top 5 bits, which both level conventions read the same way.
Sourcepub const fn middle(self) -> u8
pub const fn middle(self) -> u8
The middle group of the 3-level convention: the 3 bits under the main.
Sourcepub const fn two_level_sub(self) -> u16
pub const fn two_level_sub(self) -> u16
The sub group of the 2-level convention: the low 11 bits, which is the 3-level middle and sub read as 1 number.
Sourcepub fn parse_two_level(value: &str) -> Result<Self>
pub fn parse_two_level(value: &str) -> Result<Self>
Parses main/sub, the form an installation that addresses in 2 levels writes.
FromStr parses the 3-level form; this is a second named entry
point rather than a fallback, so a string with 3 parts is refused here
instead of being reinterpreted as one convention or the other.
Sourcepub fn to_two_level_display(self) -> TwoLevelGroupAddressDisplay
pub fn to_two_level_display(self) -> TwoLevelGroupAddressDisplay
A wrapper that writes this address as main/sub.
The 3-level form stays this type’s own fmt::Display, so the
2-level form is asked for here rather than changing what every
existing caller prints.
Trait Implementations§
Source§impl Clone for GroupAddress
impl Clone for GroupAddress
Source§fn clone(&self) -> GroupAddress
fn clone(&self) -> GroupAddress
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more