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).
| Field | Size | Description |
|---|---|---|
header | 2 | Must be REPLY_HEADER. |
cmd | 1 | A CDC command opcode, typically USER_CDC (for a brain) or CON_CDC (for a controller). |
size | 1–2 | Number of remaining bytes in the packet (starting at ecmd through crc16), encoded as a VarU16. |
ecmd | 1 | A CDC2 extended command opcode. |
ack | 1 | A CDC2 packet acknowledgement code. |
payload | n | Encoded payload; potentially optional if a NACK occurs |
crc16 | 2 | CRC16 checksum of the whole packet, computed with the VEX_CRC16 algorithm. |
Fields§
§size: u16Total 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: u16CRC16 calculated from the entire packet contents.
Implementations§
Trait Implementations§
Source§impl<const CMD: u8, const ECMD: u8, P: Clone + Decode> Clone for Cdc2ReplyPacket<CMD, ECMD, P>
impl<const CMD: u8, const ECMD: u8, P: Clone + Decode> Clone for Cdc2ReplyPacket<CMD, ECMD, P>
Source§fn clone(&self) -> Cdc2ReplyPacket<CMD, ECMD, P>
fn clone(&self) -> Cdc2ReplyPacket<CMD, ECMD, P>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const CMD: u8, const ECMD: u8, P: PartialEq + Decode> PartialEq for Cdc2ReplyPacket<CMD, ECMD, P>
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
fn eq(&self, other: &Cdc2ReplyPacket<CMD, ECMD, P>) -> bool
self and other values to be equal, and is used by ==.