From 4c894ce2d13e2691525d1f4bb81664a4f60c8e7f Mon Sep 17 00:00:00 2001 From: Bonezegei <93502321+bonezegei@users.noreply.github.com> Date: Tue, 5 Sep 2023 11:18:26 +0800 Subject: [PATCH] Create Bonezegei_Compute.cpp --- src/Bonezegei_Compute.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/Bonezegei_Compute.cpp diff --git a/src/Bonezegei_Compute.cpp b/src/Bonezegei_Compute.cpp new file mode 100644 index 0000000..040a903 --- /dev/null +++ b/src/Bonezegei_Compute.cpp @@ -0,0 +1,27 @@ +/* + This Library is written for Bonezegei Compute + Author: Bonezegei (Jofel Batutay) + Date: September 2023 +*/ +#include "Bonezegei_Compute.h" + +Bonezegei_Compute::Bonezegei_Compute() {} + +uint8_t Bonezegei_Compute::checkSum8(char *data) { + uint8_t crc1 = 0x00; + for (int a = 0; a < strlen(data); a++) { + crc1 = (crc1 + data[a]) % 256; + } + return crc1; +} + +uint16_t Bonezegei_Compute::checkSum16(char *data) { + uint16_t CRC = 0x0000; + uint8_t crc1 = (uint8_t)CRC; + uint8_t crc2 = (uint8_t)(CRC >> 8); + for (int a = 0; a < strlen(data); a++) { + crc1 = (crc1 + data[a]) % 256; + crc2 = (crc2 + crc1) % 256; + } + return (crc2 << 8) | crc1; +}