Skip to content

Commit

Permalink
blahx
Browse files Browse the repository at this point in the history
  • Loading branch information
tpwrules committed Jun 21, 2024
1 parent af86bb1 commit 6bc5706
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Tools/AP_Periph/esc_apd_telem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ bool ESC_APD_Telem::update() {
if ((size_t)len >= sizeof(received.packet)) {
// we have a full packet, check the stop byte
if (received.packet.stop == 65535) {
// valid stop byte, check the CRC
if (crc_fletcher16(received.bytes, 18) == received.packet.checksum) {
// valid stop byte, check the checksum
if (cksum_fletcher16(received.bytes, 18) == received.packet.checksum) {
// valid packet, copy the data we need and reset length
decoded.voltage = le16toh(received.packet.voltage) * 1e-2f;
decoded.temperature = convert_temperature(le16toh(received.packet.temperature));
Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_DroneCAN/AP_DroneCAN_DNA_Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ We return it packed inside the referenced NodeData structure */
void AP_DroneCAN_DNA_Server::getHash(NodeData &node_data, const uint8_t unique_id[], uint8_t size) const
{
uint64_t hash = FNV_1_OFFSET_BASIS_64;
hash_fnv_1a(size, unique_id, &hash);
cksum_fnv_1a(size, unique_id, &hash);

// xor-folding per http://www.isthe.com/chongo/tech/comp/fnv/
hash = (hash>>56) ^ (hash&(((uint64_t)1<<56)-1));
Expand Down
6 changes: 3 additions & 3 deletions libraries/AP_Math/checksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <AP_HAL/AP_HAL_Boards.h>

// fletcher 16 implementation
uint16_t crc_fletcher16(const uint8_t *buffer, uint32_t len) {
uint16_t cksum_fletcher16(const uint8_t *buffer, uint32_t len) {
uint16_t c0 = 0;
uint16_t c1 = 0;
for (uint32_t i = 0; i < len; i++) {
Expand All @@ -35,7 +35,7 @@ uint16_t crc_fletcher16(const uint8_t *buffer, uint32_t len) {

// FNV-1a implementation
#define FNV_1_PRIME_64 1099511628211UL
void hash_fnv_1a(uint32_t len, const uint8_t* buf, uint64_t* hash)
void cksum_fnv_1a(uint32_t len, const uint8_t* buf, uint64_t* hash)
{
uint32_t i;
for (i=0; i<len; i++) {
Expand All @@ -45,7 +45,7 @@ void hash_fnv_1a(uint32_t len, const uint8_t* buf, uint64_t* hash)
}

// simple 8 bit checksum used by FPort
uint8_t crc_sum8_with_carry(const uint8_t *p, uint8_t len)
uint8_t cksum_fport(const uint8_t *p, uint8_t len)
{
uint16_t sum = 0;
for (uint8_t i=0; i<len; i++) {
Expand Down
14 changes: 7 additions & 7 deletions libraries/AP_Math/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@

#include <stdint.h>

// checksum used by SPORT/FPort. For each byte, adds it to a 16-bit
// sum, then adds those two bytes together. Returns the complement of
// the final sum.
uint8_t crc_sum8_with_carry(const uint8_t *p, uint8_t len);

uint16_t crc_fletcher16(const uint8_t * buffer, uint32_t len);
uint16_t cksum_fletcher16(const uint8_t * buffer, uint32_t len);

// generate 64bit FNV1a hash from buffer
#define FNV_1_OFFSET_BASIS_64 14695981039346656037UL
void hash_fnv_1a(uint32_t len, const uint8_t* buf, uint64_t* hash);
void cksum_fnv_1a(uint32_t len, const uint8_t* buf, uint64_t* hash);

// checksum used by SPORT/FPort. For each byte, adds it to a 16-bit
// sum, then adds those two bytes together. Returns the complement of
// the final sum.
uint8_t cksum_fport(const uint8_t *p, uint8_t len);

// return the parity of byte - "1" if there is an odd number of bits
// set, "0" if there is an even number of bits set
Expand Down
4 changes: 2 additions & 2 deletions libraries/AP_RCProtocol/AP_RCProtocol_FPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void AP_RCProtocol_FPort::decode_downlink(const FPort_Frame &frame)
buf[3] = telem_data.packet.appid & 0xFF;
buf[4] = telem_data.packet.appid >> 8;
memcpy(&buf[5], &telem_data.packet.data, 4);
buf[9] = crc_sum8_with_carry(&buf[0], 9);
buf[9] = cksum_fport(&buf[0], 9);

// perform byte stuffing per FPort spec
uint8_t len = 0;
Expand Down Expand Up @@ -307,7 +307,7 @@ void AP_RCProtocol_FPort::_process_byte(uint32_t timestamp_us, uint8_t b)
bool AP_RCProtocol_FPort::check_checksum(void)
{
const uint8_t len = byte_input.buf[1]+2;
return crc_sum8_with_carry(&byte_input.buf[1], len) == 0x00;
return cksum_fport(&byte_input.buf[1], len) == 0x00;
}

// support byte input
Expand Down
4 changes: 2 additions & 2 deletions libraries/AP_RCProtocol/AP_RCProtocol_FPort2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void AP_RCProtocol_FPort2::decode_downlink(const FPort2_Frame &frame)
// get fresh telem_data in the next call
telem_data.available = false;
}
buf[9] = crc_sum8_with_carry(&buf[1], 8);
buf[9] = cksum_fport(&buf[1], 8);

uart->write(buf, sizeof(buf));
#endif
Expand Down Expand Up @@ -286,7 +286,7 @@ void AP_RCProtocol_FPort2::_process_byte(uint32_t timestamp_us, uint8_t b)
// check checksum byte
bool AP_RCProtocol_FPort2::check_checksum(void)
{
return crc_sum8_with_carry(&byte_input.buf[1], byte_input.control_len-1) == 0;
return cksum_fport(&byte_input.buf[1], byte_input.control_len-1) == 0;
}

// support byte input
Expand Down

0 comments on commit 6bc5706

Please sign in to comment.