tinyproto
|
IFd class incapsulates Full Duplex Protocol functionality. More...
#include <TinyProtocolFd.h>
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 |
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.
|
inline |
Initializes IFd object.
buffer | - buffer to store the frames being received. |
bufferSize | - size of the buffer |
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
void tinyproto::IFd::disableCrc | ( | ) |
Disable CRC field in the protocol.
If CRC field is OFF, then the frame looks like this: 0x7E databytes 0x7E.
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.
void tinyproto::IFd::enableCrc | ( | hdlc_crc_t | crc | ) |
Enables CRC by specified bit-size.
8-bit is supported by Nano version of Tiny library.
crc | crc type |
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.
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.
|
inlineprotectedvirtual |
Method called by fd protocol when connect/disconnect event takes place.
Can be redefined in derived classes.
addr | remote client address. Has meaning only in master mode. |
connected | connection status |
|
inlineprotectedvirtual |
Method called by hdlc protocol upon receiving new frame.
Can be redefined in derived classes.
addr | address of peer station |
pdata | pointer to received data |
size | size of received payload in bytes |
|
inlineprotectedvirtual |
Method called by hdlc protocol upon sending next frame.
Can be redefined in derived classes.
addr | address of peer station |
pdata | pointer to sent data |
size | size of sent payload in bytes |
int tinyproto::IFd::run_rx | ( | const void * | data, |
int | len | ||
) |
Processes incoming rx data, specified by a user.
data | pointer to the buffer with incoming data |
len | size of the buffer in bytes |
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.
read_func | function to read data from communication channel |
int tinyproto::IFd::run_tx | ( | write_block_cb_t | write_func | ) |
Attempts to send out data via write_func function.
write_func | pointer to function for sending bytes to the channel |
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.
data | buffer to fill with tx data |
max_size | maximum size of the buffer |
|
inline |
Sets connect/disconnect callback.
on_connect | user callback to process connect/disconnect events. The processing must be non-blocking |
|
inline |
Sets receive callback for incoming messages.
on_receive | user callback to process incoming messages. The processing must be non-blocking |
|
inline |
Sets send callback for outgoing messages.
on_send | user callback to process outgoing messages. The processing must be non-blocking |
|
inline |
Sets send timeout in milliseconds.
timeout | timeout in milliseconds, |
|
inline |
Sets user data to pass to callbacks.
userData | user data to pass to callback |
|
inline |
Sets desired window size.
Use this function only before begin() call. window size is number of frames, which confirmation may be deferred for.
window | window size, valid between 1 - 7 inclusively |
int tinyproto::IFd::write | ( | const char * | buf, |
int | size | ||
) |
Sends data block over communication channel.
buf | - data to send |
size | - length of the data in bytes |
int tinyproto::IFd::write | ( | const IPacket & | pkt | ) |
Sends packet over communication channel.
pkt | - Packet to send |