Тайлбар байхгүй

Juraj Ďuďák e231555d87 fix encode 2B integer to buffer 2 жил өмнө
src e231555d87 fix encode 2B integer to buffer 2 жил өмнө
.gitignore cba359ffb0 add appolo support, plus doxycumentation 2 жил өмнө
.gitlab-ci.yml e231555d87 fix encode 2B integer to buffer 2 жил өмнө
Doxyfile cba359ffb0 add appolo support, plus doxycumentation 2 жил өмнө
LICENSE cba359ffb0 add appolo support, plus doxycumentation 2 жил өмнө
apollo.json cba359ffb0 add appolo support, plus doxycumentation 2 жил өмнө
readme.md 340d7aaea7 create PLAIN dataframe format (for NRF packets) 2 жил өмнө

readme.md

Simple wrapper for DataFrame

Create formatted frame from basic types:

  • uint8_t, int8_t => 1Byte
  • uint16_t, int16_t => 2Bytes
  • uint32_t, int32_t => 4Bytes
  • float => 4Bytes

Support modes:

  • Plain (TYPE_PLAIN): construct simple dataframe,
  • Basic (TYPE_HEADER_CRC): construct dataframe with header byte as irst byte and CRC checksum as last byte.

Data are stored in Little Endian format.

Structure of data frame (TYPE_HEADER_CRC):

  • data[0] - starting byte (0xCC)
  • data[1] - length of frame: count of bytes in payload. The first 2 bytes is not included to overal length. Maximum length: 254 (0xFE)
  • payload
  • CRC8

Structure of data frame (TYPE_PLAIN):

  • data[0] - length of frame: count of bytes in payload. The first bytee is not included to overal length. Maximum length: 254 (0xFE)
  • payload

The library contans universal function:

  • uint8_t crc8(uint8_t crc, uint8_t Size, uint8_t *Buffer);
    • crc - inital value for CRC computig. For new frame, use 0x0
    • Size - size of data Buffer

Basic usage


    void main(){
    uint8_t data[128];

    DataFrame packet(data_packet, sizeof(data_packet), TYPE_HEADER_CRC);

    packet.AddUint8(0xAB);
    packet.AddUint16(65874);
    packet.AddInt8(-45874);
    packet.AddUint32(0x12345678);
    packet.AddInt32(-0xA2345678);
    
    packet.AddFloat(0.265);
    packet.AddFloat(-3.1415);

    int data_length = packet.Commit();
    uint8_t* frame = packet.GetFrame();
    }

CRC8 Computation

  • Generator polynome: 0x97 -> 0x197 = x^8 + x^7 + x^4 + x^2 + x^1 +1
  • CRC is implemented as fast computation with prepared CrcTable. Algorithm complexity is O(n)