Skip to main content

DeviceAddress

Struct DeviceAddress 

Source
#[non_exhaustive]
pub struct DeviceAddress { pub can_id: Option<u8>, pub uuid: Option<Vec<u8>>, pub transport_device: Option<usize>, }
Expand description

Address for a moteus device.

A device address can include a CAN ID, a UUID (or UUID prefix), and a transport device index. All fields are optional, and both can_id and uuid can be set simultaneously so that clients can see both identifiers.

The transport_device field specifies which transport device to route commands through, bypassing automatic device discovery.

§Examples

use moteus::DeviceAddress;

// Address by CAN ID (most common)
let addr = DeviceAddress::can_id(1);
assert_eq!(addr.as_can_id(), Some(1));

// Using From trait
let addr: DeviceAddress = 1.into();

// Address by UUID
let uuid_bytes = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                  0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10];
let addr = DeviceAddress::uuid(uuid_bytes);

// UUID prefix (for matching)
let addr = DeviceAddress::uuid([0x01, 0x02, 0x03, 0x04]);

// With transport device routing
let addr = DeviceAddress::can_id(1).with_transport_device(0);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§can_id: Option<u8>

CAN bus ID (1-127), if known.

§uuid: Option<Vec<u8>>

UUID or UUID prefix, if known.

§transport_device: Option<usize>

Index of the transport device to route through, if known.

Implementations§

Source§

impl DeviceAddress

Source

pub fn can_id(id: u8) -> Self

Create an address from a CAN ID.

§Arguments
  • id - CAN bus ID (typically 1-127)
Source

pub fn uuid(uuid: impl Into<Vec<u8>>) -> Self

Create an address from a UUID or UUID prefix.

§Arguments
  • uuid - Full 16-byte UUID or a prefix for matching
Source

pub fn with_transport_device(self, idx: usize) -> Self

Set the transport device index (builder pattern).

Source

pub fn as_can_id(&self) -> Option<u8>

Returns the CAN ID if set.

Source

pub fn as_uuid(&self) -> Option<&[u8]>

Returns the UUID bytes if set.

Source

pub fn is_can_id(&self) -> bool

Returns true if this address has a CAN ID.

Source

pub fn is_uuid(&self) -> bool

Returns true if this address has a UUID.

Source

pub fn matches(&self, can_id: u8, uuid: Option<&[u8]>) -> bool

Check if this address matches a device with the given CAN ID and UUID.

All set fields must match. A CAN ID address matches by exact ID, a UUID address matches by prefix. If both are set, both must match.

Trait Implementations§

Source§

impl Clone for DeviceAddress

Source§

fn clone(&self) -> DeviceAddress

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DeviceAddress

Source§

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

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

impl Display for DeviceAddress

Source§

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

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

impl Eq for DeviceAddress

Source§

impl From<&[u8]> for DeviceAddress

Source§

fn from(uuid: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for DeviceAddress

Source§

fn from(uuid: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<[u8; N]> for DeviceAddress

Source§

fn from(uuid: [u8; N]) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for DeviceAddress

Source§

fn from(id: i32) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for DeviceAddress

Source§

fn from(id: u8) -> Self

Converts to this type from the input type.
Source§

impl FromStr for DeviceAddress

Parse a device address from a string.

Supports:

  • Integer CAN IDs: “1”, “15”, “127”
  • Hex UUID or prefix: “01:02:03:04” or “01020304”
Source§

type Err = String

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

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

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

impl Hash for DeviceAddress

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 DeviceAddress

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DeviceAddress

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> CommandExt for T

Source§

fn with_query(self, format: QueryFormat) -> WithQuery<Self>

Attaches a query format override to this command.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.