OpenCyphal / pycyphal

Python implementation of the Cyphal protocol stack.
https://pycyphal.readthedocs.io/
MIT License
124 stars 106 forks source link

Harmonize the Cyphal/serial header format with Cyphal/UDP #266

Closed pavel-kirienko closed 1 year ago

pavel-kirienko commented 1 year ago

This is a very simple change intended to eliminate the unnecessary minor difference between the Cyphal/serial frame format and the new Cyphal/UDP frame format. The current Cyphal/serial frame format is as follows:

uint8   version              # Always zero. Discard the frame if not.
uint8   priority             # 0 = highest, 7 = lowest; the rest are unused.
uint16  source node ID       # 0xFFFF = anonymous.
uint16  destination node ID  # 0xFFFF = broadcast.
uint16  data specifier

void64                       # Reserved; later may be leveraged for runtime type identification.
uint64  transfer-ID

uint32  frame index EOT      # MSB set if last frame of the transfer; i.e., 0x8000_0000 if single-frame transfer.
uint32  header CRC           # CRC-32C (Castagnoli) of the header (all fields above).

The new format, shared for Cyphal/serial and Cyphal/UDP, is as follows:

uint4 version                      # <- 1
void4

@assert _offset_ == {8}
uint3 priority                     # Duplicates QoS for ease of access; 0 -- highest, 7 -- lowest.
void5

@assert _offset_ == {16}
uint16 source_node_id
uint16 destination_node_id
uint16 data_specifier              # Like in Cyphal/serial: subject-ID | (service-ID + request/response discriminator).

@assert _offset_ == {64}
uint64 transfer_id

@assert _offset_ == {128}
uint31 frame_index
bool end_of_transfer

uint16 user_data
# Opaque application-specific data with user-defined semantics. Generic implementations should ignore

@assert _offset_ % 16 == {0}
uint8[2] header_crc_be             # Most significant byte first.

@assert _offset_ / 8 == {24}       # Fixed-size 24-byte header with natural alignment for each field ensured.
@sealed

The same layout may well be used in other transports in the future, such as Cyphal/TSN.

Changes:

Related: #253

FYI @maksimdrachov

pavel-kirienko commented 1 year ago

Fixed in #283