CrsfParser C++ lib. Decoding and encoding packets of CRSF FPV drone control protocol

€200.00

CrsfParser is C++ library designed for decoding and encoding packets of CRSF FPV drone control protocol.

We sell source code of this library as is, without future updates and technical support according to perpetual non-exclusive royalty-free license. You pay once and can use this library in your software and hardware products without limits. Please read the license agreement before purchasing: LICENSE.

CrsfParser is C++ library designed for decoding and encoding packets of CRSF FPV drone control protocol.

We sell source code of this library as is, without future updates and technical support according to perpetual non-exclusive royalty-free license. You pay once and can use this library in your software and hardware products without limits. Please read the license agreement before purchasing: LICENSE.

Overview

CrsfParser is C++ library designed for decoding and encoding packets of CRSF FPV drone control protocol. The library used for CRSF packets translation and extracts only CRSF_FRAMETYPE_RC_CHANNELS_PACKED packets. For other packets types the library just detects them in data buffer. The library doesn’t have third-party dependencies, but test application depends on SerialPort library (provides methods to work with serial ports, source code included, Apache 2.0 license).

Documentation

Documentation: GO TO DOCUMENTATION

Simple interface

class CrsfParser
{
public:
    /// Get library version.
    static std::string getVersion();

    /// Detect CRSF packet.
    CrsfPacket detect(uint8_t nextByte, uint8_t* packet, int& size);

    /// Get decoded RC channels.
    void getRcChannels(uint32_t channels[16]);

    /// Encode RC channels packet.
    bool encodeRcChannels(uint32_t channels[16], uint8_t* packet, int& size);
};

Encode CRSF command example

// Fill channels.
uint32_t channels[16];
for (int i = 0; i < 16; ++i)
    channels[i] = 992;

// Encoder RC channels.
uint8_t encodedPacket[64];
int encodedSize = 0;
parser.encodeRcChannels(channels, encodedPacket, encodedSize);

// Show data.
cout << "Encoded packet: ";
for (int i = 0; i < encodedSize; ++i)
    cout << hex << (int)encodedPacket[i] << " ";
cout << dec << endl;

Decode CRSF message example

// CRSF packet with additional data
uint8_t rfChannelPacket[] = { 
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xc8, 0x18, 0x16,
    0xe0, 0x03, 0x1f, 0xf8, 0xc0, 0x07, 0x3e, 0xf0, 0x81, 0x0f, 0x7c,
    0xe0, 0x03, 0x1f, 0xf8, 0xc0, 0x07, 0x3e, 0xf0, 0x81, 0x0f, 0x7c, 0xad,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};

// Detect byte-by-byte.
CrsfParser parser;
uint8_t packet[64];
int packetSize = 0;
for (int i = 0; i < sizeof(rfChannelPacket); ++i)
{
    CrsfPacket type = parser.detect(rfChannelPacket[i], packet, packetSize);
    if (type == CrsfPacket::RC_CHANNELS)
    {
        uint32_t channels[16];
        parser.getRcChannels(channels);
        cout << "RC channels: ";
        for (int i = 0; i < 16; ++i)
            cout << channels[i] << " ";
        cout << endl;
    }
}