File:  [ELWIX - Embedded LightWeight unIX -] / libelwix / example / test_crc.c
Revision 1.1.4.4: download - view: text, annotated - select for diffs - revision graph
Sat Oct 12 16:03:11 2024 UTC (5 weeks, 6 days ago) by misho
Branches: elwix6_2
Diff to: branchpoint 1.1: preferred, unified
adds UT for CRC8

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <elwix.h>


int
main(int argc, char **argv)
{
	FILE *f;
	char line[BUFSIZ] = { 0 };

	if(argc < 2)
		return 1;

	f = fopen(argv[1], "r");
	if (!f)
		return 1;

	while (fgets(line, sizeof line - 1, f)) {
		printf("crc16-ccitt %x init(0xFFFF) %x init(0x1d0f) %x\n", crc_16_ccitt(line, strlen(line)), 
				crcCalc(line, strlen(line), 161, 0, 0xFFFF, 0x0), 
				crcCalc(line, strlen(line), 161, 0, 0x1D0F, 0x0));
		printf("crc16 %x vs ccitt %x crc16_xy %x crc_16_xmodem %x\n", crc_16(line, strlen(line)), crc16_ccitt(line, strlen(line)), 
				crc16_xy(line, strlen(line)), crc_16_xmodem(line, strlen(line)));
		printf("crc32 %x vs %x, eth %x\n", crc_32(line, strlen(line)), crc32tbl(0, line, strlen(line)), crcEther(line, strlen(line)));
		printf("crc8 %x vs %x\n", crc_8(line, strlen(line)), crc8tbl(0, line, strlen(line)));
	}

	fclose(f);
	return 0;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>