OpenCyphal / libcanard

A compact implementation of the Cyphal/CAN protocol in C for high-integrity real-time embedded systems
http://opencyphal.org
MIT License
327 stars 192 forks source link

Enhance `canardTxPush` to support scattered transfer payload buffers. #223

Open serges147 opened 4 months ago

serges147 commented 4 months ago

@pavel-kirienko ... if we support scattered buffers, DSDL serialization could be sped up considerably in cases where there are large byte arrays present in the message (like imagery data) because the serializer would be able to serialize only non-trivial parts of the message and keep references to the blobs:

uavcan.time.SynchronizedTimestamp.1.0 timestamp  # NON ZERO-COPY
uint16 IMAGE_WIDTH  = 1280
uint16 IMAGE_HEIGHT = 800
uint8 BITS_PER_PIXEL = 24
uint8[IMAGE_WIDTH * IMAGE_HEIGHT * BITS_PER_PIXEL / 8] pixel_data  # ZERO-COPY!

If we go this way, to support full end-to-end low-copy operation, the application would need to allocate the message object itself from the media memory resource.

One side effect of scattered input buffers is that an output frame may end up straddling multiple fragments; to support this we will need to allow a tx queue item to reference not just one but an arbitrary number of fragments from the input buffer.

See https://github.com/OpenCyphal-Garage/libcyphal/pull/343