AP_Math: add method for generating hash

This commit is contained in:
Siddharth Purohit 2019-10-06 11:06:19 +05:30 committed by Andrew Tridgell
parent e266188963
commit 3c1e99cc6b
4 changed files with 17 additions and 0 deletions

View File

@ -338,6 +338,7 @@ bool rotation_equal(enum Rotation r1, enum Rotation r2)
return (v1 - v2).length() < 0.001; return (v1 - v2).length() < 0.001;
} }
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL #if CONFIG_HAL_BOARD == HAL_BOARD_SITL
// fill an array of float with NaN, used to invalidate memory in SITL // fill an array of float with NaN, used to invalidate memory in SITL
void fill_nanf(float *f, uint16_t count) void fill_nanf(float *f, uint16_t count)

View File

@ -281,3 +281,4 @@ bool rotation_equal(enum Rotation r1, enum Rotation r2) WARN_IF_UNUSED;
// fill an array of float with NaN, used to invalidate memory in SITL // fill an array of float with NaN, used to invalidate memory in SITL
void fill_nanf(float *f, uint16_t count); void fill_nanf(float *f, uint16_t count);
#endif #endif

View File

@ -255,3 +255,14 @@ uint16_t calc_crc_modbus(uint8_t *buf, uint16_t len)
} }
return crc; return crc;
} }
// FNV-1a implementation
#define FNV_1_PRIME_64 1099511628211UL
void hash_fnv_1a(uint32_t len, const uint8_t* buf, uint64_t* hash)
{
uint32_t i;
for (i=0; i<len; i++) {
*hash ^= (uint64_t)buf[i];
*hash *= FNV_1_PRIME_64;
}
}

View File

@ -29,3 +29,7 @@ uint16_t crc16_ccitt(const uint8_t *buf, uint32_t len, uint16_t crc);
uint16_t calc_crc_modbus(uint8_t *buf, uint16_t len); uint16_t calc_crc_modbus(uint8_t *buf, uint16_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);