Morse Micro IoT SDK  2.6.4-esp32
Serial Line Internet Protocol (SLIP) implementation.

Detailed Description

SLIP was originally designed as an encapsulation for IP over serial ports, but can be used for framing of any packet-based data for transmission over a serial port.

Data Structures

struct  slip_rx_state
 Structure used to contain the current state for the SLIP receiver. More...
 

Macros

#define SLIP_RX_BUFFER_SIZE   (2000)
 Recommended RX buffer size. More...
 
#define SLIP_RX_STATE_INIT(_buffer, _buffer_length)   { _buffer, _buffer_length, 0, false }
 Static initializer for slip_rx_state. More...
 

Typedefs

typedef int(* slip_transport_tx_fn) (uint8_t c, void *arg)
 Function to send a character on the SLIP transport. More...
 

Enumerations

enum  slip_rx_status { SLIP_RX_COMPLETE , SLIP_RX_IN_PROGRESS , SLIP_RX_BUFFER_LIMIT , SLIP_RX_ERROR }
 Enumeration of SLIP status codes. More...
 

Functions

static void slip_rx_state_reinit (struct slip_rx_state *state, uint8_t *buffer, size_t buffer_length)
 Dynamic (re)initializer for slip_rx_state. More...
 
enum slip_rx_status slip_rx (struct slip_rx_state *state, uint8_t c)
 Handle reception of a character in a SLIP stream. More...
 
int slip_tx (slip_transport_tx_fn transport_tx_fn, void *transport_tx_arg, const uint8_t *packet, size_t packet_len)
 Transmit a packet with SLIP framing. More...
 

Macro Definition Documentation

◆ SLIP_RX_BUFFER_SIZE

#define SLIP_RX_BUFFER_SIZE   (2000)

Recommended RX buffer size.

Definition at line 25 of file slip.h.

◆ SLIP_RX_STATE_INIT

#define SLIP_RX_STATE_INIT (   _buffer,
  _buffer_length 
)    { _buffer, _buffer_length, 0, false }

Static initializer for slip_rx_state.

See slip_rx_state for an example of usage.

Parameters
_bufferPointer to a buffer to be used by SLIP (should be a uint8_t array).
_buffer_lengthThe size of _buffer.

Definition at line 58 of file slip.h.

Typedef Documentation

◆ slip_transport_tx_fn

typedef int(* slip_transport_tx_fn) (uint8_t c, void *arg)

Function to send a character on the SLIP transport.

Parameters
cThe character to transmit
argOpaque argument, as passed to slip_tx().
Returns
0 on success, otherwise a negative error code.

Definition at line 108 of file slip.h.

Enumeration Type Documentation

◆ slip_rx_status

Enumeration of SLIP status codes.

Enumerator
SLIP_RX_COMPLETE 

A complete packet with length > 0 has been received.

SLIP_RX_IN_PROGRESS 

Receive is still in progress.

SLIP_RX_BUFFER_LIMIT 

Receive buffer limit has been reached.

SLIP_RX_ERROR 

An erroneous packet has been received.

Definition at line 79 of file slip.h.

Function Documentation

◆ slip_rx()

enum slip_rx_status slip_rx ( struct slip_rx_state state,
uint8_t  c 
)

Handle reception of a character in a SLIP stream.

When reception of a packet is successful, this will return SLIP_RX_COMPLETE and the packet can be found in state->buffer with length state->length.

Parameters
stateCurrent slip state. Will be updated by this function.
cThe received character.
Returns
an appropriate value of slip_rx_status.

◆ slip_rx_state_reinit()

static void slip_rx_state_reinit ( struct slip_rx_state state,
uint8_t *  buffer,
size_t  buffer_length 
)
inlinestatic

Dynamic (re)initializer for slip_rx_state.

This can be used as an alternative to SLIP_RX_STATE_INIT when static initialization is not possible.

Parameters
stateThe slip state structure to init.
bufferPointer to the buffer to be used by SLIP.
buffer_lengthLength of buffer.

Definition at line 69 of file slip.h.

◆ slip_tx()

int slip_tx ( slip_transport_tx_fn  transport_tx_fn,
void *  transport_tx_arg,
const uint8_t *  packet,
size_t  packet_len 
)

Transmit a packet with SLIP framing.

Parameters
transport_tx_fnFunction to invoke to send characters on the transport.
transport_tx_argArgument to pass to transport_tx_fn.
packetThe packet to transmit.
packet_lenThe length of the packet.
Returns
0 on success, otherwise an error code as returned by transport_tx_fn.