Cleanup example

This commit is contained in:
Chris 2023-12-19 03:14:16 +01:00
parent 4fd5bc05c9
commit 6703a07e0f
2 changed files with 21 additions and 26 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# TinyCRC
This is a library for calculating CRC32, CRC16 and CRC8.

View File

@ -4,41 +4,33 @@
#include <cstring> #include <cstring>
#include "src/tinycrc.h" #include "src/tinycrc.h"
void test(const uint8_t* buffer)
{
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));
printf("%-32s | crc32 | %08x\n", (char*)buffer, crc32);
printf("%-32s | crc16 | %04x\n", (char*)buffer, crc16);
printf("%-32s | crc8 | %02x\n", (char*)buffer, crc8);
}
int main() int main()
{ {
uint8_t* buffer = (uint8_t*)malloc(32); uint8_t* buffer = (uint8_t*)malloc(32);
sprintf((char*)buffer, "Hello %s!", "World"); strcpy((char*)buffer, "Hello World\0");
test(buffer);
uint32_t crc32 = tinycrc_crc32(buffer, 32); strcpy((char*)buffer, "Hello World!\0");
uint16_t crc16 = tinycrc_crc16(buffer, 32); test(buffer);
uint8_t crc8 = tinycrc_crc8(buffer, 32);
printf("%-32s | crc32 | %08x\n", (char*)buffer, crc32); strcpy((char*)buffer, "Hello Worlds\0");
printf("%-32s | crc16 | %04x\n", (char*)buffer, crc16); test(buffer);
printf("%-32s | crc8 | %02x\n", (char*)buffer, crc8);
sprintf((char*)buffer, "Hello %s!", "Worlds"); strcpy((char*)buffer, "Testing\0");
test(buffer);
crc32 = tinycrc_crc32(buffer, 32);
crc16 = tinycrc_crc16(buffer, 32);
crc8 = tinycrc_crc8(buffer, 32);
printf("%-32s | crc32 | %08x\n", (char*)buffer, crc32);
printf("%-32s | crc16 | %04x\n", (char*)buffer, crc16);
printf("%-32s | crc8 | %02x\n", (char*)buffer, crc8);
sprintf((char*)buffer, "%s %d", "foobarxyzzy", 42);
crc32 = tinycrc_crc32(buffer, 32);
crc16 = tinycrc_crc16(buffer, 32);
crc8 = tinycrc_crc8(buffer, 32);
printf("%-32s | crc32 | %08x\n", (char*)buffer, crc32);
printf("%-32s | crc16 | %04x\n", (char*)buffer, crc16);
printf("%-32s | crc8 | %02x\n", (char*)buffer, crc8);
free(buffer); free(buffer);