Cdc2ReplyPacket

Struct Cdc2ReplyPacket 

Source
pub struct Cdc2ReplyPacket<const CMD: u8, const ECMD: u8, P: Decode> {
    pub size: u16,
    pub payload: Result<P, Cdc2Ack>,
    pub crc16: u16,
}
Expand description

CDC2 (Extended) Reply Packet

This type decodes a device-to-host reply packet used in the extended CDC2 protocol. The payload type P must implement Decode.

All CDC2 replies are sent in response to a corresponding Cdc2CommandPacket from the host. For example, a SystemFlagsPacket command corresponds to a SystemFlagsReplyPacket reply.

Reply packets encode an acknowledgement code in the form of a Cdc2Ack, which will either acknowledge the command as valid and successful (Cdc2Ack::Ack) or return a negative acknowledgement if there was a problem processing or servicing the command.

§Encoding

This is an extension of the standard CdcReplyPacket encoding that adds:

  • An extended command opcode (ecmd).
  • A packet acknowledgement code (Cdc2Ack).
  • A CRC16 checksum covering the entire packet (including header).
FieldSizeDescription
header2Must be REPLY_HEADER.
cmd1A CDC command opcode, typically USER_CDC (for a brain) or CON_CDC (for a controller).
size1–2Number of remaining bytes in the packet (starting at ecmd through crc16), encoded as a VarU16.
ecmd1A CDC2 extended command opcode.
ack1A CDC2 packet acknowledgement code.
payloadnEncoded payload; potentially optional if a NACK occurs
crc162CRC16 checksum of the whole packet, computed with the VEX_CRC16 algorithm.

Fields§

§size: u16

Total payload size. This includes the size taken by the ecmd, ack, and crc fields.

§payload: Result<P, Cdc2Ack>

Payload. Only decoded if the packet is acknowledged.

§crc16: u16

CRC16 calculated from the entire packet contents.

Implementations§

Source§

impl<const CMD: u8, const ECMD: u8, P: Decode> Cdc2ReplyPacket<CMD, ECMD, P>

Source

pub const HEADER: [u8; 2] = REPLY_HEADER

Source

pub fn ack(&self) -> Cdc2Ack

Trait Implementations§

Source§

impl<const CMD: u8, const ECMD: u8, P: Clone + Decode> Clone for Cdc2ReplyPacket<CMD, ECMD, P>

Source§

fn clone(&self) -> Cdc2ReplyPacket<CMD, ECMD, P>

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<const CMD: u8, const ECMD: u8, P: Decode> Decode for Cdc2ReplyPacket<CMD, ECMD, P>

Source§

fn decode(data: &mut &[u8]) -> Result<Self, DecodeError>

Attempts to decode Self from the beginning of the provided byte slice. Read more
Source§

impl<const CMD: u8, const ECMD: u8, P: PartialEq + Decode> PartialEq for Cdc2ReplyPacket<CMD, ECMD, P>

Source§

fn eq(&self, other: &Cdc2ReplyPacket<CMD, ECMD, P>) -> 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<const CMD: u8, const ECMD: u8, P: Copy + Decode> Copy for Cdc2ReplyPacket<CMD, ECMD, P>

Source§

impl<const CMD: u8, const ECMD: u8, P: Eq + Decode> Eq for Cdc2ReplyPacket<CMD, ECMD, P>

Source§

impl<const CMD: u8, const ECMD: u8, P: Decode> StructuralPartialEq for Cdc2ReplyPacket<CMD, ECMD, P>

Auto Trait Implementations§

§

impl<const CMD: u8, const ECMD: u8, P> Freeze for Cdc2ReplyPacket<CMD, ECMD, P>
where P: Freeze,

§

impl<const CMD: u8, const ECMD: u8, P> RefUnwindSafe for Cdc2ReplyPacket<CMD, ECMD, P>
where P: RefUnwindSafe,

§

impl<const CMD: u8, const ECMD: u8, P> Send for Cdc2ReplyPacket<CMD, ECMD, P>
where P: Send,

§

impl<const CMD: u8, const ECMD: u8, P> Sync for Cdc2ReplyPacket<CMD, ECMD, P>
where P: Sync,

§

impl<const CMD: u8, const ECMD: u8, P> Unpin for Cdc2ReplyPacket<CMD, ECMD, P>
where P: Unpin,

§

impl<const CMD: u8, const ECMD: u8, P> UnwindSafe for Cdc2ReplyPacket<CMD, ECMD, P>
where P: UnwindSafe,

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