2023-12-19 02:01:07 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <cstring>
|
|
|
|
#include "src/tinycrc.h"
|
|
|
|
|
2023-12-19 02:14:16 +00:00
|
|
|
void test(const uint8_t* buffer)
|
2023-12-19 02:01:07 +00:00
|
|
|
{
|
2023-12-19 02:14:16 +00:00
|
|
|
uint32_t crc32 = tinycrc_crc32(buffer, strlen((char*)buffer));
|
|
|
|
uint16_t crc16 = tinycrc_crc16(buffer, strlen((char*)buffer));
|
|
|
|
uint8_t crc8 = tinycrc_crc8(buffer, strlen((char*)buffer));
|
2023-12-19 02:01:07 +00:00
|
|
|
|
|
|
|
printf("%-32s | crc32 | %08x\n", (char*)buffer, crc32);
|
|
|
|
printf("%-32s | crc16 | %04x\n", (char*)buffer, crc16);
|
|
|
|
printf("%-32s | crc8 | %02x\n", (char*)buffer, crc8);
|
|
|
|
|
2023-12-19 02:14:16 +00:00
|
|
|
}
|
2023-12-19 02:01:07 +00:00
|
|
|
|
2023-12-19 02:14:16 +00:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
uint8_t* buffer = (uint8_t*)malloc(32);
|
2023-12-19 02:01:07 +00:00
|
|
|
|
2023-12-19 02:14:16 +00:00
|
|
|
strcpy((char*)buffer, "Hello World\0");
|
|
|
|
test(buffer);
|
2023-12-19 02:01:07 +00:00
|
|
|
|
2023-12-19 02:14:16 +00:00
|
|
|
strcpy((char*)buffer, "Hello World!\0");
|
|
|
|
test(buffer);
|
2023-12-19 02:01:07 +00:00
|
|
|
|
2023-12-19 02:14:16 +00:00
|
|
|
strcpy((char*)buffer, "Hello Worlds\0");
|
|
|
|
test(buffer);
|
2023-12-19 02:01:07 +00:00
|
|
|
|
2023-12-19 02:14:16 +00:00
|
|
|
strcpy((char*)buffer, "Testing\0");
|
|
|
|
test(buffer);
|
2023-12-19 02:01:07 +00:00
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
|
|
|
|
|
|
|
|
}
|