Tiny protocol  0.11.0
Tiny communication protocol for microcontrollers
Public Member Functions | Protected Member Functions | Friends | List of all members
Tiny::IProtoFd Class Reference

#include <TinyProtocolFd.h>

Inheritance diagram for Tiny::IProtoFd:
Inheritance graph
[legend]

Public Member Functions

 IProtoFd (void *buffer, int bufferSize)
 
void begin (write_block_cb_t writecb, read_block_cb_t readcb)
 
void begin ()
 
void beginToSerial ()
 
void beginToSerial1 ()
 
void beginToSerial2 ()
 
void beginToSerial3 ()
 
void end ()
 
int write (char *buf, int size)
 
int write (IPacket &pkt)
 
int run_rx (uint16_t timeout=0)
 
int run_rx (const void *data, int len)
 
int run_tx (uint16_t timeout=0)
 
int run_tx (void *data, int max_size)
 
void disableCrc ()
 
void enableCrc (hdlc_crc_t crc)
 
bool enableCheckSum ()
 
bool enableCrc16 ()
 
bool enableCrc32 ()
 
void setReceiveCallback (void(*on_receive)(IPacket &pkt)=nullptr)
 
void setSendCallback (void(*on_send)(IPacket &pkt)=nullptr)
 
void setWindowSize (uint8_t window)
 
void setSendTimeout (uint16_t timeout)
 

Protected Member Functions

virtual void onReceive (uint8_t *pdata, int size)
 
virtual void onSend (uint8_t *pdata, int size)
 

Friends

class ProtoFdD
 

Detailed Description

IProtoFd class incapsulates Full Duplex Protocol functionality. Full Duplex version of the Protocol allows to send messages with confirmation. Remember that you may use always C-style API functions instead C++. Please refer to documentation.

Constructor & Destructor Documentation

◆ IProtoFd()

Tiny::IProtoFd::IProtoFd ( void *  buffer,
int  bufferSize 
)
inline

Initializes IProtoFd object

Parameters
buffer- buffer to store the frames being received.
bufferSize- size of the buffer

Member Function Documentation

◆ begin() [1/2]

void Tiny::IProtoFd::begin ( write_block_cb_t  writecb,
read_block_cb_t  readcb 
)

Initializes protocol internal variables. If you need to switch communication with other destination point, you can call this method one again after calling end().

Parameters
writecb- write function to some physical channel
readcb- read function from some physical channel
Returns
None

◆ begin() [2/2]

void Tiny::IProtoFd::begin ( )

Initializes protocol internal variables. If you need to switch communication with other destination point, you can call this method one again after calling end(). Use this method if you want to control write and read data by yourself

Returns
None

◆ beginToSerial()

void Tiny::IProtoFd::beginToSerial ( )
inline

Initializes protocol internal variables and redirects communication through Arduino Serial connection (Serial).

Returns
None

◆ beginToSerial1()

void Tiny::IProtoFd::beginToSerial1 ( )
inline

Initializes protocol internal variables and redirects communication through Arduino Serial1 connection (Serial1).

Returns
None

◆ beginToSerial2()

void Tiny::IProtoFd::beginToSerial2 ( )
inline

Initializes protocol internal variables and redirects communication through Arduino Serial2 connection (Serial2).

Returns
None

◆ beginToSerial3()

void Tiny::IProtoFd::beginToSerial3 ( )
inline

Initializes protocol internal variables and redirects communication through Arduino Serial3 connection (Serial3).

Returns
None

◆ disableCrc()

void Tiny::IProtoFd::disableCrc ( )

Disable CRC field in the protocol. If CRC field is OFF, then the frame looks like this: 0x7E databytes 0x7E.

◆ enableCheckSum()

bool Tiny::IProtoFd::enableCheckSum ( )

Enables CRC 8-bit field in the protocol. This field contains sum of all data bytes in the packet. 8-bit field is supported by Nano version of Tiny library.

Returns
true if successful false in case of error.

◆ enableCrc()

void Tiny::IProtoFd::enableCrc ( hdlc_crc_t  crc)

Enables CRC by specified bit-size. 8-bit is supported by Nano version of Tiny library.

Parameters
crccrc type

◆ enableCrc16()

bool Tiny::IProtoFd::enableCrc16 ( )

Enables CRC 16-bit field in the protocol. This field contains FCS 16-bit CCITT like defined in RFC 1662. 16-bit field is not supported by Nano version of Tiny library.

Returns
true if successful false in case of error.

◆ enableCrc32()

bool Tiny::IProtoFd::enableCrc32 ( )

Enables CRC 32-bit field in the protocol. This field contains FCS 32-bit CCITT like defined in RFC 1662. 32-bit field is not supported by Nano version of Tiny library.

Returns
true if successful false in case of error.

◆ end()

void Tiny::IProtoFd::end ( )

Resets protocol state.

◆ onReceive()

virtual void Tiny::IProtoFd::onReceive ( uint8_t *  pdata,
int  size 
)
inlineprotectedvirtual

Method called by hdlc protocol upon receiving new frame. Can be redefined in derived classes.

Parameters
pdatapointer to received data
sizesize of received payload in bytes

◆ onSend()

virtual void Tiny::IProtoFd::onSend ( uint8_t *  pdata,
int  size 
)
inlineprotectedvirtual

Method called by hdlc protocol upon sending next frame. Can be redefined in derived classes.

Parameters
pdatapointer to sent data
sizesize of sent payload in bytes

◆ run_rx() [1/2]

int Tiny::IProtoFd::run_rx ( uint16_t  timeout = 0)

Checks communcation channel for incoming messages.

Returns
negative value in case of error zero if nothing is read positive - Packet is successfully received
Remarks
if Packet is receive during run execution callback is called.

◆ run_rx() [2/2]

int Tiny::IProtoFd::run_rx ( const void *  data,
int  len 
)

Processes incoming rx data, specified by a user.

Returns
TINY_SUCCESS
Remarks
if Packet is receive during run execution callback is called.

◆ run_tx() [1/2]

int Tiny::IProtoFd::run_tx ( uint16_t  timeout = 0)

Sends data to communcation channel.

Returns
negative value in case of error

◆ run_tx() [2/2]

int Tiny::IProtoFd::run_tx ( void *  data,
int  max_size 
)

Force protocol to generate tx data for you. In this case you will need to send data to remote side by yourself.

Parameters
databuffer to fill with tx data
max_sizemaximum size of the buffer
Returns
number of bytes written to buffer

◆ setReceiveCallback()

void Tiny::IProtoFd::setReceiveCallback ( void(*)(IPacket &pkt)  on_receive = nullptr)
inline

Sets receive callback for incoming messages

Parameters
on_receiveuser callback to process incoming messages. The processing must be non-blocking

◆ setSendCallback()

void Tiny::IProtoFd::setSendCallback ( void(*)(IPacket &pkt)  on_send = nullptr)
inline

Sets send callback for outgoing messages

Parameters
on_senduser callback to process outgoing messages. The processing must be non-blocking

◆ setSendTimeout()

void Tiny::IProtoFd::setSendTimeout ( uint16_t  timeout)
inline

Sets send timeout in milliseconds.

Parameters
timeouttimeout in milliseconds,

◆ setWindowSize()

void Tiny::IProtoFd::setWindowSize ( uint8_t  window)
inline

Sets desired window size. Use this function only before begin() call. window size is number of frames, which confirmation may be deferred for.

Parameters
windowwindow size, valid between 1 - 7 inclusively
Warning
if you use smallest window size, this can reduce throughput of the channel.

◆ write() [1/2]

int Tiny::IProtoFd::write ( char *  buf,
int  size 
)

Sends data block over communication channel.

Parameters
buf- data to send
size- length of the data in bytes
Returns
negative value in case of error zero if nothing is sent positive - should be equal to size parameter

◆ write() [2/2]

int Tiny::IProtoFd::write ( IPacket pkt)

Sends packet over communication channel.

Parameters
pkt- Packet to send
See also
Packet
Returns
negative value in case of error zero if nothing is sent positive - Packet is successfully sent

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