Skip to content

Commit

Permalink
Create Bonezegei_Compute.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
bonezegei authored Sep 5, 2023
1 parent aa71e83 commit 4c894ce
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Bonezegei_Compute.cpp
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 4c894ce

Please sign in to comment.