Full C++ and Python impl
This commit is contained in:
22
telemetry_common.cpp
Normal file
22
telemetry_common.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2026 Hector van der Aa <hector@h3cx.dev>
|
||||
// Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "telemetry_common.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
uint16_t crc16_ccitt(const uint8_t *data, uint16_t length) {
|
||||
uint16_t crc = 0xFFFF;
|
||||
|
||||
for (uint16_t i = 0; i < length; i++) {
|
||||
crc ^= (uint16_t)data[i] << 8;
|
||||
|
||||
for (uint8_t j = 0; j < 8; j++) {
|
||||
if (crc & 0x8000)
|
||||
crc = (crc << 1) ^ 0x1021;
|
||||
else
|
||||
crc <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
Reference in New Issue
Block a user