mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-29 20:33:35 +08:00
CRC16 class
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
/**
|
||||
* CRC-16-CCITT
|
||||
* Initial value: 0x0000
|
||||
* Coefficient: 0x1021
|
||||
*/
|
||||
class Crc16
|
||||
{
|
||||
static const uint16_t TABLE[256];
|
||||
uint_fast16_t value_;
|
||||
|
||||
public:
|
||||
Crc16()
|
||||
: value_(0x0000)
|
||||
{ }
|
||||
|
||||
uint16_t add(uint8_t byte);
|
||||
uint16_t add(const uint8_t* bytes, int len);
|
||||
|
||||
uint16_t get() const { return value_; }
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user