Skip to main content

Frame

Struct Frame 

Source
pub struct Frame {
    pub cmd: Cmd,
    pub status: Status,
    pub addr: u32,
    pub len: u16,
    pub data: Data,
    pub crc: [u8; 2],
    /* private fields */
}
Expand description

Wire frame: SYNC(2) + CMD(1) + STATUS(1) + ADDR(4) + LEN(2) + DATA(len) + CRC(2)

Used for both requests and responses. For requests, status is Status::Request. For responses, cmd and addr echo the request.

Single instance, reused each iteration of the protocol loop.

Fields§

§cmd: Cmd

Command code.

§status: Status

Response status (always Status::Request for requests).

§addr: u32

Flash address (for Write/Erase) or mode selector (for Reset).

§len: u16

Data payload length in bytes (0..64).

§data: Data

Payload data (union-typed).

§crc: [u8; 2]

CRC16 over the frame body (little-endian).

Implementations§

Source§

impl Frame

Source

pub fn send<W: Write>(&mut self, w: &mut W) -> Result<(), W::Error>

Send the frame. Two write_all calls: body, then CRC.

Source

pub fn read<R: Read>(&mut self, r: &mut R) -> Result<Status, ReadError>

Read one frame from the transport.

Syncs on preamble, reads header + payload, validates CRC. Returns Ok(Status::Ok) on success, Ok(Status::*) for protocol errors (CRC, invalid frame, overflow), Err only for transport IO.

Source

pub async fn send_async<W: Write>(&mut self, w: &mut W) -> Result<(), W::Error>

Async version of send.

Source

pub async fn read_async<R: Read>( &mut self, r: &mut R, ) -> Result<Status, ReadError>

Async version of read.

Trait Implementations§

Source§

impl Default for Frame

Source§

fn default() -> Self

Create a default frame. Data buffer is uninitialized — read() or caller writes populate it before use.

Auto Trait Implementations§

§

impl Freeze for Frame

§

impl RefUnwindSafe for Frame

§

impl Send for Frame

§

impl Sync for Frame

§

impl Unpin for Frame

§

impl UnsafeUnpin for Frame

§

impl UnwindSafe for Frame

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> 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.