Skip to content

SerialTransfer

Latest

Choose a tag to compare

@PowerBroker2 PowerBroker2 released this 06 Nov 01:03

SerialTransfer transport and examples overhaul

Summary

This release replaces the previous packet framing with a simpler length-based frame, repairs I²C transmission and receive handling, clarifies callback behavior, and reorganizes the examples into a curated Serial and I²C suite.

Packet format

The packet format is now:

START | ID | LENGTH | PAYLOAD | CRC-8(ID, LENGTH, PAYLOAD)

Payloads can contain 0 to 255 bytes. The CRC covers the packet ID, payload length, and payload. The previous COBS encoding and stop-byte framing are removed.

I²C improvements

  • Both I2CTransfer.begin() overloads now register the Wire receive handler.
  • Large frames are split across Wire transactions, using 32-byte chunks by default. Define SERIALTRANSFER_I2C_CHUNK_SIZE to match a different Wire buffer capacity.
  • sendDatum() now writes its value at payload offset zero.
  • sendData() checks Wire write and transmission results. The new transmissionStatus field exposes failures.
  • I²C callbacks and debug messages are dispatched when available() or tick() is called, outside the Wire receive interrupt.

I²C usage note: poll the receiver regularly and consume each completed packet before the peer sends another. The receiver has a single packet buffer; additional incoming transactions while a packet is pending are discarded. The current implementation supports one active I2CTransfer instance per MCU.

Callback and API changes

Callbacks are selected by packet ID: callbacks[id] handles packets with that ID. Null callback entries are skipped, and callbacksLen is now wide enough to describe all 256 packet IDs. The callback array must remain valid for the lifetime of the configured transfer object.

Public methods and attributes in the active API headers now have Doxygen documentation covering parameters, results, status values, buffer limits, timeouts, and callback configuration. The object helpers are documented as raw byte copies: they do not normalize structure padding, endianness, or floating-point representation.

The CRC-8 lookup table now uses fixed storage instead of heap allocation. The existing crcLen constructor parameter remains for source compatibility; this implementation uses an 8-bit CRC.

Examples

The flat examples were moved under examples/Legacy/. The curated examples use Serial_ and I2C_ prefixes, with each sketch in a folder matching its filename. The examples guide explains wiring, roles, and expected behavior.

The new Serial examples include a minimal loopback with a SoftwareSerial fallback, an ID-based callback demo, a 255-byte throughput and latency benchmark, and an acknowledged multi-packet file-transfer pair.

The new I²C examples include a master/slave quickstart, an ID-based callback demo, a two-board 255-byte benchmark with round-trip acknowledgements, and an acknowledged multi-packet file-transfer pair. The file-transfer examples send a generated 512-byte test file in chunks and verify a whole-file FNV-1a checksum. The I²C file-transfer acknowledgements use a short master-requested response with its own CRC.

Full Changelog: 3.1.5...4.0.0