Arduino KVComm  master
Key-Value pair communication library for Arduino
Public Types | Public Member Functions | Private Attributes | List of all members
SLIPStreamCRC< CRC > Class Template Reference

Class that implements SLIP, a simple packet framing protocol, and that uses cyclic redundancy checks (CRCs) on transmitted and received packets. More...

#include <SLIPStream/SLIPStream.hpp>

Collaboration diagram for SLIPStreamCRC< CRC >:

Public Types

using StreamSender = SLIPStream::StreamSender
 
using checksum_t = typename SLIPParserCRC< CRC >::checksum_t
 The integer type of the checksum. More...
 

Public Member Functions

 SLIPStreamCRC (Stream &stream, CRC &&senderCRC, const SLIPParser &parser, CRC &&parserCRC)
 
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...
 
checksum_t checksum () const
 Get the checksum of the previous packet. More...
 

Private Attributes

Stream * stream
 
SLIPSenderCRC< StreamSender, CRC > sender
 
SLIPParserCRC< CRC > parser
 

Detailed Description

template<class CRC>
class SLIPStreamCRC< CRC >

Class that implements SLIP, a simple packet framing protocol, and that uses cyclic redundancy checks (CRCs) on transmitted and received packets.

See also
RFC 1055
Boost::CRC
Examples
KVComm-Receive.ino, KVComm-Send.ino, SLIP-Receive-CRC.ino, and SLIP-Send-CRC.ino.

Definition at line 84 of file SLIPStream.hpp.

Member Typedef Documentation

◆ StreamSender

Definition at line 86 of file SLIPStream.hpp.

◆ checksum_t

using checksum_t = typename SLIPParserCRC<CRC>::checksum_t

The integer type of the checksum.

Definition at line 122 of file SLIPStream.hpp.

Constructor & Destructor Documentation

◆ SLIPStreamCRC()

SLIPStreamCRC ( Stream &  stream,
CRC &&  senderCRC,
const SLIPParser parser,
CRC &&  parserCRC 
)
inline

Definition at line 88 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, checksums and stuffing bytes.

Definition at line 6 of file SLIPStream.ipp.

◆ 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 20 of file SLIPStream.ipp.

◆ 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 15 of file SLIPStream.ipp.

◆ endPacket()

size_t endPacket ( )

Finish the packet.

Encodes and sends the checksum of all data sent using the write function, followed by a SLIP END character.

Returns
The number of bytes sent by the Sender.

Definition at line 25 of file SLIPStream.ipp.

◆ 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.

Definition at line 30 of file SLIPStream.ipp.

◆ 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.

Definition at line 117 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 119 of file SLIPStream.hpp.

◆ checksum()

checksum_t checksum ( ) const
inline

Get the checksum of the previous packet.

A checksum of zero indicates that the packet was received correctly.

Definition at line 125 of file SLIPStream.hpp.

Member Data Documentation

◆ stream

Stream* stream
private

Definition at line 128 of file SLIPStream.hpp.

◆ sender

SLIPSenderCRC<StreamSender, CRC> sender
private

Definition at line 129 of file SLIPStream.hpp.

◆ parser

SLIPParserCRC<CRC> parser
private

Definition at line 130 of file SLIPStream.hpp.


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