Framing Protocols¶
COBS¶
This is an implementation of Consistent-Overhead Byte Stuffing.
This uses a null byte as an end of packet marker, and uses a clever technique to encode null bytes within the packet with minimal overhead. See the link above for more information.
-
class
packetio::COBSPrint: public packetio::PacketPrint¶
-
class
packetio::COBSStream: public packetio::PacketStream¶
Escaped¶
This packet framer uses a special character to indicate end-of-frame, and an escape character to allow this to appear within a message. In the worst-case, this causes the packet to be twice the data size.
The choice of these special characters is parameterizable through template
arguments. encoded/codes.h contains some example choices of values, including
an implementation of SLIP. To define your own, you can use code like the
following:
#include <escaped/Print.h>
#include <escaped/Stream.h>
#include <escaped/codes.h>
using namespace packetio;
// end, escape, escaped end, escaped escape
typedef EscapeCodes<'A','/','a','\\'> MyCodes;
EscapedPrint<MyCodes> printer(Serial);
EscapedStream<MyCodes> reader(Serial);
In this example, we use A to end a packet. So the packet ABCD/EFGH is
encoded to /aBCD/\EFGHA. Here, the first A is replaced by the escape
sequence /a, and the / is replaced with /\. Finally, an A is
appended to end the packet.
-
template <uint8_t pEND, uint8_t pESC, uint8_t pESC_END, uint8_t pESC_ESC>
structpacketio::EscapeCodes¶ A trait type for indicating which markers to use in an EscapedStream or EscapedPrint. This type should be used as the type argument.
- Template Parameters
pEND: The byte indicating end of framepESC: The byte indicating that the following byte is an escape codepESC_END: The escape code for encoding an in-data END valuepESC_ESC: The escape code for encoding an in-data ESC value
-
template <typename EscapeCodes>
classpacketio::EscapedPrint: public packetio::PacketPrint¶
-
template <typename EscapeCodes>
classpacketio::EscapedStream: public packetio::PacketStream¶
SLIP¶
These is just a convenience aliases for escaped streams with the appropriate EscapeCodes.
-
typedef EscapeCodes<0xC0, 0xDB, 0xDC, 0xDD>
packetio::SLIPEscapeCodes¶
-
typedef EscapedPrint<SLIPEscapeCodes>
packetio::SLIPPrint¶
-
typedef EscapedStream<SLIPEscapeCodes>
packetio::SLIPStream¶