Skip to content

Latest commit

 

History

History
106 lines (81 loc) · 7.22 KB

TriceMessagesEncoding.md

File metadata and controls

106 lines (81 loc) · 7.22 KB

Trice message encoding

(Read only you are interested in)

    1. COBS encoding and user protocols
    1. [COBS encoding for re-sync after data disruption](#COBShttps:en.wikipedia.orgwikiConsistent_Overhead_Byte_Stuffingencodingforre-syncafterdatadisruption)
    1. 32-bit transfer chunks
    • 3.1. Example: zero-delimited 7-bytes COBS package
    • 3.2. Example: zero-delimited 8-bytes COBS package:
    1. Package mode prefix
    • 4.1. Example: 12 byte trice message buffer prefixed with mode 0 (no time stamps):
    • 4.2. Example: 16 byte trice message buffer prefixed with mode 1 (time stamps)
    • 4.3. Example: 12-bytes user packet - will be ignored by the trice tool:

1. COBS encoding and user protocols

  • The Consistent Overhead Byte Stuffing technique is a very powerful and simple way for re-syncing.
  • Just in case, wait for the next package delimiter.
  • Several Trice message can occur within one single COBS package.
  • Each COBS package starts with a 32-bit descriptor:
Descriptor Meaning
0x00000000 Trice message(s) without prefix
0x00000001 Trice message(s) with 32-bit target timestamp
0x00000002 Trice message(s) with 32-bit target location
0x00000003 Trice message(s) with 64-bit target timestamp and location
0x00000004...0x000000FF Reserved for Trice encodings
0x00000100...0xFFFFFFFF User protocol data, the trice tool ignores them
  • This allows intermixing of several data streams with Trice data.
  • After the 4 COBS package descriptor bytes start several full Trice messages.
  • In dependence of the COBS package descriptor each Trice message is prefixed with 0, 32 or 64 bit additional information: target code location and target timestamp.
  • The detailed Trice encoding is derivable from trice.h and not repeated here to avoid unnecessary errors.

2. COBS encoding for re-sync after data disruption

  • After a data transmission disruption, reliable re-sync should be possible.
  • The COBS techique gives this possibility in an easy way: simply wait for the next packet delimiter byte (usually 0).
  • Therefore all Trice transfers are COBS encoded.

3. 32-bit transfer chunks

  • A Trice data stream comes always in a multiple-of-4 length for effective transfer.
    • After COBS encoding the length is the same or 1.04 times longer.
    • Therefore after COBS encoding the packages are delimited by 1 to 4 zeroes.
    • After the first zero delimiter, 0 to 3 padding zeroes are ignored as len-0 packages.

3.1. Example: zero-delimited 7-bytes COBS package

cobs cobs cobs cobs cobs cobs cobs delimiter
x x x x x x x 0
0 1 2 3 4 5 6 7

3.2. Example: zero-delimited 8-bytes COBS package:

cobs cobs cobs cobs cobs cobs cobs cobs delimiter padding padding padding
x x x x x x x x 0 0 0 0
0 1 2 3 4 5 6 7 8 9 10 11

4. Package mode prefix

  • Trice messages are always multiple-of-4-bytes messages.
  • A Trice buffer can contain several trice messages.
    • Each single trice carries its own length information.
  • Just before buffer encoding takes part, a 32-bit buffer mode value is prefixed:
    • buffer mode 0: Trice messages are without embedded device timestamps.
    • buffer mode 1: Trice messages are prefixed with 32-bit embedded device timestamps.
    • buffer mode 2: Trice messages are prefixed with 32-bit embedded device source location information.
    • buffer mode 3: Trice messages are prefixed with 64-bit embedded device source location information and timestamp.
    • buffer mode 4-15: Reserved. The trice tool ignores such package.
    • buffer mode 16-0xFFFFFFFF: user mode values. The trice tool ignores such package. This way any user protocols transferable over the same line.

4.1. Example: 12 byte trice message buffer prefixed with mode 0 (no time stamps):

  • The 12 trice bytes could be 1, 2 or 3 trice messages consisting of 3, 2 or 1 32-Bit values.
mode mode mode mode data data data data data data data data data data data data
0 0 0 0 x x x x x x x x x x x x
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

4.2. Example: 16 byte trice message buffer prefixed with mode 1 (time stamps)

  • The 16 trice bytes could be 1 or 2 trice messages consisting of 3 or 1 32-bit values, each prefixed by a target timestamp.
mode mode mode mode data data data data data data data data data data data data data data data data
1 0 0 0 t t t t x x x x t|x t|x t|x t|x x x x x
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

4.3. Example: 12-bytes user packet - will be ignored by the trice tool:

mode mode mode mode data data data data data data data data data data data data
0 1 0 0 x x x x x x x x x x x x
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15