|
tinyproto
|
Hdlc class encapsulates HDLC low-level framing functionality. More...
#include <TinyProtocolHdlc.h>
Public Member Functions | |
| Hdlc (void *buffer, int bufferSize) | |
| Initializes Hdlc object. More... | |
| void | begin (write_block_cb_t writecb, read_block_cb_t readcb) |
| Initializes protocol internal variables. 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_tx (void *data, int max_len) |
| Generates data for tx channel. 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)(IPacket &pkt)=nullptr) |
| Sets receive callback for incoming messages. More... | |
| void | setSendCallback (void(*on_send)(IPacket &pkt)=nullptr) |
| Sets send callback for outgoing messages. More... | |
Protected Member Functions | |
| virtual void | onReceive (uint8_t *pdata, int size) |
| Method called by hdlc protocol upon receiving new frame. More... | |
| virtual void | onSend (const uint8_t *pdata, int size) |
| Method called by hdlc protocol upon sending next frame. More... | |
Hdlc class encapsulates HDLC low-level framing functionality.
It handles flag bytes (0x7E), byte stuffing, and CRC validation. This class provides raw HDLC framing — it does not perform acknowledgments or retransmission. For reliable delivery, use the Full Duplex protocol (IFd / Fd<N> / FdD).
You may also use the C-style API functions (hdlc_*) directly.
|
inline |
Initializes Hdlc object.
| buffer | - buffer to store the frames being received. |
| bufferSize | - size of the buffer |
| void Hdlc::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().
| writecb | - write function to some physical channel |
| readcb | - read function from some physical channel |
| void Hdlc::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().
| void Hdlc::disableCrc | ( | ) |
Disable CRC field in the protocol.
If CRC field is OFF, then the frame looks like this: 0x7E databytes 0x7E.
| bool Hdlc::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 Hdlc::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 Hdlc::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 Hdlc::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 hdlc protocol upon receiving new frame.
Can be redefined in derived classes.
| 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.
| pdata | pointer to sent data |
| size | size of sent payload in bytes |
| int Hdlc::run_rx | ( | const void * | data, |
| int | len | ||
| ) |
Processes incoming rx data, specified by a user.
| int Hdlc::run_tx | ( | void * | data, |
| int | max_len | ||
| ) |
Generates data for tx channel.
| data | buffer to fill |
| max_len | length of buffer |
|
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 |
| int Hdlc::write | ( | const char * | buf, |
| int | size | ||
| ) |
Sends data block over communication channel.
| buf | - data to send |
| size | - length of the data in bytes |
| int Hdlc::write | ( | const IPacket & | pkt | ) |
Sends packet over communication channel.
| pkt | - Packet to send |
1.8.13