mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-13 07:43:33 +08:00
Transport CRC will not use table in UAVCAN_TINY builds
This commit is contained in:
@@ -26,7 +26,10 @@ namespace uavcan
|
||||
*/
|
||||
class UAVCAN_EXPORT TransferCRC
|
||||
{
|
||||
#if !UAVCAN_TINY
|
||||
static const uint16_t Table[256];
|
||||
#endif
|
||||
|
||||
uint16_t value_;
|
||||
|
||||
public:
|
||||
@@ -36,10 +39,28 @@ public:
|
||||
: value_(0xFFFF)
|
||||
{ }
|
||||
|
||||
#if UAVCAN_TINY
|
||||
void add(uint8_t byte)
|
||||
{
|
||||
value_ ^= byte << 8;
|
||||
for (uint8_t bit = 8; bit > 0; --bit)
|
||||
{
|
||||
if (value_ & 0x8000)
|
||||
{
|
||||
value_ = (value_ << 1) ^ 0x1021;
|
||||
}
|
||||
else
|
||||
{
|
||||
value_ = (value_ << 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
void add(uint8_t byte)
|
||||
{
|
||||
value_ = ((value_ << 8) ^ Table[((value_ >> 8) ^ byte) & 0xFF]) & 0xFFFF;
|
||||
}
|
||||
#endif
|
||||
|
||||
void add(const uint8_t* bytes, unsigned len)
|
||||
{
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <uavcan/transport/crc.hpp>
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
#if !UAVCAN_TINY
|
||||
|
||||
// print ', '.join(map(lambda x: '%04x' % x, map(lambda x: int(x, 0), c.crc_ccitt_tab)))
|
||||
const uint16_t TransferCRC::Table[256] =
|
||||
{
|
||||
@@ -45,4 +46,6 @@ const uint16_t TransferCRC::Table[256] =
|
||||
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user