ReadResponse

Struct ReadResponse 

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

Read response datagram (8 bytes).

Format: [SYNC, master_addr (0xFF), reg_addr, data[3], data[2], data[1], data[0], CRC]

Implementations§

Source§

impl ReadResponse

Source

pub const LEN: usize = 8

Length of a read response in bytes.

Source

pub const SYNC_IDX: usize = 0

Index of the sync byte.

Source

pub const MASTER_ADDR_IDX: usize = 1

Index of the master address byte.

Source

pub const REG_ADDR_IDX: usize = 2

Index of the register address byte.

Source

pub const DATA_START_IDX: usize = 3

Start index of data bytes.

Source

pub const DATA_END_IDX: usize = 7

End index of data bytes (exclusive).

Source

pub const CRC_IDX: usize = 7

Index of the CRC byte.

Source

pub fn from_bytes<E>(bytes: [u8; 8]) -> Result<Self, Error<E>>

Parse a read response from a byte buffer.

§Arguments
  • bytes - 8-byte buffer containing the response
§Returns

The parsed response, or an error if validation fails.

Source

pub fn from_slice<E>(slice: &[u8]) -> Result<Self, Error<E>>

Parse a response from a slice, copying the data.

§Errors

Returns Error::BufferTooSmall if the slice is less than 8 bytes.

Source

pub fn reg_addr(&self) -> u8

Get the register address from the response.

Source

pub fn address(&self) -> Option<Address>

Get the typed register address if known.

Source

pub fn data(&self) -> u32

Get the 32-bit data value.

Source

pub fn as_bytes(&self) -> &[u8; 8]

Get the raw bytes of the response.

Source

pub fn crc_valid(&self) -> bool

Check if the CRC is valid.

Trait Implementations§

Source§

impl AsRef<[u8]> for ReadResponse

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for ReadResponse

Source§

fn clone(&self) -> ReadResponse

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 ReadResponse

Source§

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

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

impl Format for ReadResponse
where [u8; 8]: Format,

Source§

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

Writes the defmt representation of self to fmt.
Source§

impl PartialEq for ReadResponse

Source§

fn eq(&self, other: &ReadResponse) -> 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 ReadResponse

Source§

impl Eq for ReadResponse

Source§

impl StructuralPartialEq for ReadResponse

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.