GroupAddress

Struct GroupAddress 

Source
pub struct GroupAddress { /* private fields */ }
Expand description

KNX Group Address

Used for logical grouping of devices and functions.

§Examples

use knx_pico::GroupAddress;

// Create 3-level address
let addr = GroupAddress::new(1, 2, 3).unwrap();
assert_eq!(addr.to_string(), "1/2/3");

// Create 2-level address
let addr = GroupAddress::new_2level(1, 234).unwrap();
assert_eq!(addr.to_string_2level(), "1/234");

// Create from raw u16
let addr = GroupAddress::from(0x0A03u16);
assert_eq!(addr.main(), 1);
assert_eq!(addr.middle(), 2);
assert_eq!(addr.sub(), 3);

// Parse from string (auto-detects format)
let addr: GroupAddress = "1/2/3".parse().unwrap();
assert_eq!(u16::from(addr), 0x0A03);

Implementations§

Source§

impl GroupAddress

Source

pub const MAX_MAIN: u8 = 31u8

Maximum main group value (5 bits)

Source

pub const MAX_MIDDLE: u8 = 7u8

Maximum middle group value (3 bits)

Source

pub const MAX_SUB: u8 = 255u8

Maximum sub group value (8 bits)

Source

pub const MAX_SUB_2LEVEL: u16 = 2_047u16

Maximum sub value for 2-level format (11 bits)

Source

pub fn new(main: u8, middle: u8, sub: u8) -> Result<Self>

Create a new 3-level Group Address (Main/Middle/Sub).

§Arguments
  • main - Main group (0-31)
  • middle - Middle group (0-7)
  • sub - Sub group (0-255)
§Errors

Returns KnxError::AddressOutOfRange if any component is out of range.

Source

pub fn new_2level(main: u8, sub: u16) -> Result<Self>

Create a new 2-level Group Address (Main/Sub).

§Arguments
  • main - Main group (0-31)
  • sub - Sub group (0-2047)
§Errors

Returns KnxError::AddressOutOfRange if any component is out of range.

Source

pub fn from_array(parts: [u8; 3]) -> Result<Self>

Create from a 3-element array [main, middle, sub].

Convenient for creating 3-level addresses from array literals.

§Examples
use knx_pico::GroupAddress;

let addr = GroupAddress::from_array([1, 2, 3])?;
assert_eq!(addr.to_string(), "1/2/3");
Source

pub const fn raw(self) -> u16

Get the raw u16 representation of the address.

Source

pub const fn main(self) -> u8

Get the main group component (0-31).

Source

pub const fn middle(self) -> u8

Get the middle group component for 3-level format (0-7).

Source

pub const fn sub(self) -> u8

Get the sub group component for 3-level format (0-255).

Source

pub const fn sub_2level(self) -> u16

Get the sub group component for 2-level format (0-2047).

Source

pub fn to_string_3level(&self) -> String<16>

Format as 3-level string (Main/Middle/Sub).

§Panics

May panic if the formatted string exceeds 16 bytes capacity, though this should never occur in practice as the maximum length is “31/7/255” (9 bytes).

Source

pub fn to_string_2level(&self) -> String<16>

Format as 2-level string (Main/Sub).

§Panics

May panic if the formatted string exceeds 16 bytes capacity, though this should never occur in practice as the maximum length is “31/2047” (8 bytes).

Source

pub fn encode(&self, buf: &mut [u8]) -> Result<usize>

Encode the address into a byte buffer (big-endian).

§Arguments
  • buf - Buffer to write to (must be at least 2 bytes)
§Errors

Returns KnxError::BufferTooSmall if buffer is too small.

Source

pub fn decode(buf: &[u8]) -> Result<Self>

Decode an address from a byte buffer (big-endian).

§Arguments
  • buf - Buffer to read from (must be at least 2 bytes)
§Errors

Returns KnxError::BufferTooSmall if buffer is too small.

Trait Implementations§

Source§

impl Clone for GroupAddress

Source§

fn clone(&self) -> GroupAddress

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GroupAddress

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for GroupAddress

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Format as 3-level address by default

Source§

impl Format for GroupAddress

Source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.
Source§

impl From<GroupAddress> for u16

Source§

fn from(addr: GroupAddress) -> u16

Converts to this type from the input type.
Source§

impl From<u16> for GroupAddress

Source§

fn from(raw: u16) -> Self

Converts to this type from the input type.
Source§

impl FromStr for GroupAddress

Source§

type Err = KnxError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for GroupAddress

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for GroupAddress

Source§

fn eq(&self, other: &GroupAddress) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for GroupAddress

Source§

impl Eq for GroupAddress

Source§

impl StructuralPartialEq for GroupAddress

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.