From 3f730a8a94b4f759ae64fb96b183aa94947cd922 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 27 Jun 2023 00:02:15 +1000 Subject: [PATCH] AP_Math: add crc_sum_of_bytes sums the values of the bytes in a buffer and returns that sum modulus 256 --- libraries/AP_Math/crc.cpp | 11 +++++++++++ libraries/AP_Math/crc.h | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/libraries/AP_Math/crc.cpp b/libraries/AP_Math/crc.cpp index ff320588ff..0b283b0515 100644 --- a/libraries/AP_Math/crc.cpp +++ b/libraries/AP_Math/crc.cpp @@ -598,3 +598,14 @@ uint8_t parity(uint8_t byte) return p; } + +// sums the bytes in the supplied buffer, returns that sum mod 256 +// (i.e. shoved into a uint8_t) +uint8_t crc_sum_of_bytes(uint8_t *data, uint16_t count) +{ + uint8_t ret = 0; + for (uint32_t i=0; i