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: CmdCommand code.
status: StatusResponse status (always Status::Request for requests).
addr: u32Flash address (for Write/Erase) or mode selector (for Reset).
len: u16Data payload length in bytes (0..64).
data: DataPayload data (union-typed).
crc: [u8; 2]CRC16 over the frame body (little-endian).
Implementations§
Source§impl Frame
impl Frame
Sourcepub fn send<W: Write>(&mut self, w: &mut W) -> Result<(), W::Error>
pub fn send<W: Write>(&mut self, w: &mut W) -> Result<(), W::Error>
Send the frame. Two write_all calls: body, then CRC.
Sourcepub fn read<R: Read>(&mut self, r: &mut R) -> Result<Status, ReadError>
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.