Arduino KVComm  master
Key-Value pair communication library for Arduino
Classes | Public Member Functions | Private Attributes | List of all members
SLIPStream Class Reference

Class that implements SLIP, a simple packet framing protocol. More...

#include <SLIPStream/SLIPStream.hpp>

Collaboration diagram for SLIPStream:

Classes

struct  StreamSender
 Functor that sends bytes over an Arduino Stream. More...
 

Public Member Functions

 SLIPStream (Stream &stream, const SLIPParser &parser)
 
 SLIPStream (Stream &stream)
 
size_t writePacket (const uint8_t *data, size_t len)
 Sends a packet. More...
 
size_t beginPacket ()
 Start a packet. More...
 
size_t write (const uint8_t *data, size_t len)
 Write some data as the body of a packet. More...
 
size_t endPacket ()
 Finish the packet. More...
 
size_t readPacket ()
 Receives a packet into the read buffer. More...
 
bool wasTruncated () const
 Check if the previous packet was truncated. More...
 
size_t numTruncated () const
 Get the number of bytes that were truncated due to the previous packet being too large for the buffer. More...
 

Private Attributes

Stream * stream
 
SLIPParser parser
 

Detailed Description

Class that implements SLIP, a simple packet framing protocol.

RFC 1055

Examples
SLIP-Receive.ino, and SLIP-Send.ino.

Definition at line 15 of file SLIPStream.hpp.

Constructor & Destructor Documentation

◆ SLIPStream() [1/2]

SLIPStream ( Stream &  stream,
const SLIPParser parser 
)
inline

Definition at line 26 of file SLIPStream.hpp.

◆ SLIPStream() [2/2]

SLIPStream ( Stream &  stream)
inline

Definition at line 28 of file SLIPStream.hpp.

Member Function Documentation

◆ writePacket()

size_t writePacket ( const uint8_t *  data,
size_t  len 
)

Sends a packet.

Parameters
dataA pointer to the start of the data.
lenThe length of the data.
Returns
The number of bytes transmitted over the Stream. If no write errors occur, this number will be larger than len, because of the delimiters and stuffing bytes.
Examples
SLIP-Send.ino.

Definition at line 5 of file SLIPStream.cpp.

◆ beginPacket()

size_t beginPacket ( )

Start a packet.

Sends a SLIP END character to flush the buffer of the receiver.

Returns
The number of bytes sent by the Sender.

Definition at line 17 of file SLIPStream.cpp.

◆ write()

size_t write ( const uint8_t *  data,
size_t  len 
)

Write some data as the body of a packet.

The data is encoded by SLIP before sending, so arbitrary binary data can be sent.

Parameters
dataA pointer to the data to send.
lenThe number of bytes to send.
Returns
The number of bytes sent by the Sender.

Definition at line 13 of file SLIPStream.cpp.

◆ endPacket()

size_t endPacket ( )

Finish the packet.

Sends a SLIP END character.

Returns
The number of bytes sent by the Sender.

Definition at line 21 of file SLIPStream.cpp.

◆ readPacket()

size_t readPacket ( )

Receives a packet into the read buffer.

If more than len bytes are received, the packet will be truncated.

Returns
The number of bytes stored in the buffer.
Examples
SLIP-Receive.ino.

Definition at line 25 of file SLIPStream.cpp.

◆ wasTruncated()

bool wasTruncated ( ) const
inline

Check if the previous packet was truncated.

Return values
trueThe previous packet didn't fit the buffer. The size returned by SLIPParser::parse was smaller than the actual size of the packet.
falseThe buffer was large enough to store the previous packet.
Examples
SLIP-Receive.ino.

Definition at line 60 of file SLIPStream.hpp.

◆ numTruncated()

size_t numTruncated ( ) const
inline

Get the number of bytes that were truncated due to the previous packet being too large for the buffer.

Definition at line 63 of file SLIPStream.hpp.

Member Data Documentation

◆ stream

Stream* stream
private

Definition at line 66 of file SLIPStream.hpp.

◆ parser

SLIPParser parser
private

Definition at line 67 of file SLIPStream.hpp.


The documentation for this class was generated from the following files: