Labor-Octet-Protocol/en

Aus LaborWiki
Wechseln zu: Navigation, Suche

Throughout this document a byte is considered an bit-octed, a dataword of 8 bit length.

LOP-Logo.png

About[Bearbeiten]

The Labor-Octet-Protocol (LOP) allows you to communicate in a message and stream oriented way.

The protocol builds upon a deeper communication layer which is able to transmit bytes.

Structure[Bearbeiten]

Overview[Bearbeiten]

Escape-Layer[Bearbeiten]

In order to allow (atomic) commands it is necessary to assign some byte values special meaning. In order to allow this values also appear in normal dataflow we use a technique called escaping.

command byte meaning
0x42 reset
0x23 escape


escape-sequences payload data
0x23 0x01 0x42
0x23 0x02 0x23
0x23 0x03 0x11
0x23 0x04 0x13

The two additional escape sequences allow usage of regular software flowcontrol (XON/XOFF) which is often used.

commands[Bearbeiten]

0x42 reset[Bearbeiten]

0x23 0x14 message[Bearbeiten]

The sequence 0x23 0x14 starts a new message. The following two bytes represent the length of the message (not including 0x23 0x14 and the length bytes). The length is encoded in big endian, which means that the first byte is the most significant. The messages follows the two length bytes.

0x23 0x15 stream sync[Bearbeiten]

The sequence 0x23 0x15 is a special marker in the data stream which is useful for synchronization.

Implementation[Bearbeiten]

AVR-Microcontroller[Bearbeiten]

An implementation of LOP is available for AVR-microcontrollers [1].

LOP-Kontext[Bearbeiten]

typedef struct lop_ctx {
	lopstates_t rxstate, txstate, msgretstate;
	uint32_t msgidx;
	uint16_t msglength;
	uint8_t* msgbuffer;
	uint8_t escaped;
	void (*sendrawbyte)(uint8_t);           /* pointer to the writing function */
	void (*on_msgrx)(uint16_t, uint8_t*);   /* function called on message recieve */
	void (*on_streamrx)(uint8_t);           /* function called on recieve of a stream byte*/
	void (*on_streamsync)(void);            /* function called on recieve of streamsync */
} lop_ctx_t;