TinyModem
Header-only software audio modem library
Loading...
Searching...
No Matches
tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES > Class Template Reference

Reliable data transfer over any Stream (e.g. a ModemStream, an MFSKStream or a Serial): the written data is sent in packets with CRC-16 and Reed-Solomon forward error correction, and only correct data can be read. Corrupted packets which can't be corrected are dropped. More...

#include <PacketStream.h>

Inheritance diagram for tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >:
Collaboration diagram for tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >:

Public Member Functions

 PacketStream ()
 PacketStream (Stream &io)
 send and receive
 PacketStream (Print &out)
 send only
void setStream (Stream &io)
 Defines the stream for sending and receiving.
void setOutput (Print &out)
 Defines the output (send only).
bool begin ()
 Resets the receive state and the statistics.
size_t write (uint8_t ch) override
size_t write (const uint8_t *data, size_t len) override
void flush () override
 Sends the buffered data as packet and flushes the underlying stream.
int available () override
int read () override
int peek () override
size_t readBytes (uint8_t *data, size_t len)
 Reads the available data (does not wait for more data).
size_t readBytes (char *data, size_t len)
void update ()
 Reads the available data from the underlying stream.
const PacketStatistics & statistics () const
 Statistics of the received packets.

Protected Attributes

Print * p_out = nullptr
Stream * p_in = nullptr
PacketEncoder< MAX_PAYLOAD, ECC_BYTES > encoder
PacketDecoder< MAX_PAYLOAD, ECC_BYTES > decoder
ByteQueue rx_queue

Detailed Description

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
class tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >

Reliable data transfer over any Stream (e.g. a ModemStream, an MFSKStream or a Serial): the written data is sent in packets with CRC-16 and Reed-Solomon forward error correction, and only correct data can be read. Corrupted packets which can't be corrected are dropped.

A packet is sent when MAX_PAYLOAD bytes were written or when you call flush(), which also calls flush() of the underlying stream (which ends the transmission of a modem). Both sides must use the same template parameters.

Template Parameters
MAX_PAYLOADmaximum number of data bytes per packet
ECC_BYTESnumber of Reed-Solomon parity bytes: up to ECC_BYTES / 2 wrong bytes per packet are corrected

Constructor & Destructor Documentation

◆ PacketStream() [1/3]

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::PacketStream ( )
inline

◆ PacketStream() [2/3]

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::PacketStream ( Stream & io)
inline

send and receive

◆ PacketStream() [3/3]

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::PacketStream ( Print & out)
inline

send only

Member Function Documentation

◆ available()

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
int tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::available ( )
inlineoverride

◆ begin()

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
bool tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::begin ( )
inline

Resets the receive state and the statistics.

◆ flush()

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
void tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::flush ( )
inlineoverride

Sends the buffered data as packet and flushes the underlying stream.

◆ peek()

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
int tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::peek ( )
inlineoverride

◆ read()

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
int tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::read ( )
inlineoverride

◆ readBytes() [1/2]

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
size_t tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::readBytes ( char * data,
size_t len )
inline

◆ readBytes() [2/2]

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
size_t tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::readBytes ( uint8_t * data,
size_t len )
inline

Reads the available data (does not wait for more data).

◆ setOutput()

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
void tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::setOutput ( Print & out)
inline

Defines the output (send only).

◆ setStream()

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
void tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::setStream ( Stream & io)
inline

Defines the stream for sending and receiving.

◆ statistics()

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
const PacketStatistics & tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::statistics ( ) const
inline

Statistics of the received packets.

◆ update()

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
void tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::update ( )
inline

Reads the available data from the underlying stream.

◆ write() [1/2]

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
size_t tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::write ( const uint8_t * data,
size_t len )
inlineoverride

◆ write() [2/2]

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
size_t tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::write ( uint8_t ch)
inlineoverride

Member Data Documentation

◆ decoder

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
PacketDecoder<MAX_PAYLOAD, ECC_BYTES> tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::decoder
protected

◆ encoder

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
PacketEncoder<MAX_PAYLOAD, ECC_BYTES> tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::encoder
protected

◆ p_in

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
Stream* tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::p_in = nullptr
protected

◆ p_out

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
Print* tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::p_out = nullptr
protected

◆ rx_queue

template<uint8_t MAX_PAYLOAD = 64, uint8_t ECC_BYTES = 16>
ByteQueue tinymodem::PacketStream< MAX_PAYLOAD, ECC_BYTES >::rx_queue
protected

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