Skip to content

A header-only C++11 framing protocol optimized for embedded communication

License

Notifications You must be signed in to change notification settings

hansbinderup/hdlcpp

 
 

Repository files navigation

hdlcpp

Build Status codecov Total alerts License

Hdlcpp is a header-only C++11 framing protocol optimized for embedded communication. It uses the HDLC asynchronous framing format for handling data integrity and retransmissions. Hdlcpp is the successor of the yahdlc implementation written in C.

Usage

Hdlcpp requires that a transport read and write function is supplied as e.g. a lambda expression for the actual data transport. Hereby Hdlcpp can easily be integrated e.g. with different UART implementations. It is also possible to increase the buffer size for encoding/decoding data, write timeout and number of write retries when constructing the instance.

hdlcpp = std::make_shared<Hdlcpp::Hdlcpp>(
    [this](uint8_t *data, uint16_t length) { return serial->read(data, length); },
    [this](const uint8_t *data, uint16_t length) { return serial->write(data, length); },
    bufferSize, writeTimeout, writeRetries);

To read and write data using Hdlcpp the read and write functions are used. These could again e.g. be used as lambdas expressions to a protocol implementation (layered architecture). The protocol could e.g. be nanopb.

protocol = std::make_shared<Protocol>(
    [this](uint8_t *data, uint16_t length) { return hdlcpp->read(data, length); },
    [this](const uint8_t *data, uint16_t length) { return hdlcpp->write(data, length); });

Python binding

A python binding made using pybind11 can be found under the python folder which can be used e.g. for automated testing.

HDLC implementation

The supported HDLC frames are limited to DATA (I-frame with Poll bit), ACK (S-frame Receive Ready with Final bit) and NACK (S-frame Reject with Final bit). All DATA frames are acknowledged or negative acknowledged. The Address and Control fields uses the 8-bit format which means that the highest sequence number is 7. The FCS field is 16-bit.

Acknowledge of frame Negative acknowledge of frame Acknowledge of frame lost

About

A header-only C++11 framing protocol optimized for embedded communication

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 87.0%
  • CMake 7.6%
  • Python 3.2%
  • Shell 2.2%