tinyproto
Public Member Functions | Protected Member Functions | Friends | List of all members
tinyproto::IFd Class Reference

IFd class incapsulates Full Duplex Protocol functionality. More...

#include <TinyProtocolFd.h>

Inheritance diagram for tinyproto::IFd:
Inheritance graph
[legend]

Public Member Functions

 IFd (void *buffer, int bufferSize)
 Initializes IFd object. More...
 
void begin ()
 Initializes protocol internal variables. More...
 
void end ()
 Resets protocol state.
 
int write (const char *buf, int size)
 Sends data block over communication channel. More...
 
int write (const IPacket &pkt)
 Sends packet over communication channel. More...
 
int run_rx (const void *data, int len)
 Processes incoming rx data, specified by a user. More...
 
int run_rx (read_block_cb_t read_func)
 Read data from communication channel using read_func and parses bytes to find hdlc messages. More...
 
int run_tx (write_block_cb_t write_func)
 Attempts to send out data via write_func function. More...
 
int run_tx (void *data, int max_size)
 Force protocol to generate tx data for you. More...
 
void disableCrc ()
 Disable CRC field in the protocol. More...
 
void enableCrc (hdlc_crc_t crc)
 Enables CRC by specified bit-size. More...
 
bool enableCheckSum ()
 Enables CRC 8-bit field in the protocol. More...
 
bool enableCrc16 ()
 Enables CRC 16-bit field in the protocol. More...
 
bool enableCrc32 ()
 Enables CRC 32-bit field in the protocol. More...
 
void setReceiveCallback (void(*on_receive)(void *userData, uint8_t addr, IPacket &pkt)=nullptr)
 Sets receive callback for incoming messages. More...
 
void setSendCallback (void(*on_send)(void *userData, uint8_t addr, IPacket &pkt)=nullptr)
 Sets send callback for outgoing messages. More...
 
void setConnectEventCallback (void(*on_connect)(void *userData, uint8_t addr, bool connected)=nullptr)
 Sets connect/disconnect callback. More...
 
void setWindowSize (uint8_t window)
 Sets desired window size. More...
 
void setSendTimeout (uint16_t timeout)
 Sets send timeout in milliseconds. More...
 
void setUserData (void *userData)
 Sets user data to pass to callbacks. More...
 
tiny_fd_handle_t getHandle ()
 Returns low-level handle for full duplex protocol.
 
int getStatus ()
 Returns status of the protocol.
 

Protected Member Functions

virtual void onReceive (uint8_t addr, uint8_t *pdata, int size)
 Method called by hdlc protocol upon receiving new frame. More...
 
virtual void onSend (uint8_t addr, const uint8_t *pdata, int size)
 Method called by hdlc protocol upon sending next frame. More...
 
virtual void onConnectEvent (uint8_t addr, bool connected)
 Method called by fd protocol when connect/disconnect event takes place. More...
 

Friends

class FdD
 

Detailed Description

IFd 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

◆ IFd()

tinyproto::IFd::IFd ( void *  buffer,
int  bufferSize 
)
inline

Initializes IFd object.

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

Member Function Documentation

◆ begin()

void tinyproto::IFd::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

◆ disableCrc()

void tinyproto::IFd::disableCrc ( )

Disable CRC field in the protocol.

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

◆ enableCheckSum()

bool tinyproto::IFd::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 tinyproto::IFd::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 tinyproto::IFd::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 tinyproto::IFd::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.

◆ onConnectEvent()

virtual void tinyproto::IFd::onConnectEvent ( uint8_t  addr,
bool  connected 
)
inlineprotectedvirtual

Method called by fd protocol when connect/disconnect event takes place.

Can be redefined in derived classes.

Parameters
addrremote client address. Has meaning only in master mode.
connectedconnection status

◆ onReceive()

virtual void tinyproto::IFd::onReceive ( uint8_t  addr,
uint8_t *  pdata,
int  size 
)
inlineprotectedvirtual

Method called by hdlc protocol upon receiving new frame.

Can be redefined in derived classes.

Parameters
addraddress of peer station
pdatapointer to received data
sizesize of received payload in bytes

◆ onSend()

virtual void tinyproto::IFd::onSend ( uint8_t  addr,
const uint8_t *  pdata,
int  size 
)
inlineprotectedvirtual

Method called by hdlc protocol upon sending next frame.

Can be redefined in derived classes.

Parameters
addraddress of peer station
pdatapointer to sent data
sizesize of sent payload in bytes

◆ run_rx() [1/2]

int tinyproto::IFd::run_rx ( const void *  data,
int  len 
)

Processes incoming rx data, specified by a user.

Parameters
datapointer to the buffer with incoming data
lensize of the buffer in bytes
Returns
TINY_SUCCESS
Remarks
if Packet is receive during run execution callback is called.

◆ run_rx() [2/2]

int tinyproto::IFd::run_rx ( read_block_cb_t  read_func)

Read data from communication channel using read_func and parses bytes to find hdlc messages.

Parameters
read_funcfunction to read data from communication channel
Returns
TINY_SUCCESS

◆ run_tx() [1/2]

int tinyproto::IFd::run_tx ( write_block_cb_t  write_func)

Attempts to send out data via write_func function.

Parameters
write_funcpointer to function for sending bytes to the channel
Returns
TINY_SUCCESS

◆ run_tx() [2/2]

int tinyproto::IFd::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

◆ setConnectEventCallback()

void tinyproto::IFd::setConnectEventCallback ( void(*)(void *userData, uint8_t addr, bool connected)  on_connect = nullptr)
inline

Sets connect/disconnect callback.

Parameters
on_connectuser callback to process connect/disconnect events. The processing must be non-blocking

◆ setReceiveCallback()

void tinyproto::IFd::setReceiveCallback ( void(*)(void *userData, uint8_t addr, 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 tinyproto::IFd::setSendCallback ( void(*)(void *userData, uint8_t addr, 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 tinyproto::IFd::setSendTimeout ( uint16_t  timeout)
inline

Sets send timeout in milliseconds.

Parameters
timeouttimeout in milliseconds,

◆ setUserData()

void tinyproto::IFd::setUserData ( void *  userData)
inline

Sets user data to pass to callbacks.

Parameters
userDatauser data to pass to callback

◆ setWindowSize()

void tinyproto::IFd::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 tinyproto::IFd::write ( const 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 tinyproto::IFd::write ( const 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 files: