Cleanup example
This commit is contained in:
parent
4fd5bc05c9
commit
6703a07e0f
3
README.md
Normal file
3
README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# TinyCRC
|
||||||
|
|
||||||
|
This is a library for calculating CRC32, CRC16 and CRC8.
|
44
crctest.cpp
44
crctest.cpp
@ -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);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user