lammertb / libcrc Goto Github PK
View Code? Open in Web Editor NEWMulti platform CRC library
License: MIT License
Multi platform CRC library
License: MIT License
At least on your website I cannot find the CRC-16 result matching the result calculated by Xmodem CRC function found in "official" XMODEM/YMODEM documentation file from http://pauillac.inria.fr/~doligez/zmodem/ymodem.txt, page 25.
E.g. result for ASCII 123456789 is 0xBEEF.
Hello,
I have a string of hex numbers (in Hex representation; like "AB12F1") for which I would like to calculate (and check) the CRC sum with crc16 (the hex-string is read from a transmitted file). However, I'm unsure how to use it properly. Should I feed the function with the entire hex-string, as raw string? In the sense of, interpreting every single character of the string as byte. Or should I rather convert every hex-representation (2 hex digits) into bytes?
I tested both without any success.
I'm also unsure where I have to put the checksum - I actually tested to place it in the back of the string (as usual), but this doesn't work (results in a new CRC value, which isn't 0). Furthermore, I also tried to convert the checksum first to an ASCII representation, but this also doesn't work.
Thank you!
To compile sources in C++ or mixing C/C++ projects, the <extern "C"> could surround function declarations in header-files, as well as implementations in source-files.
#ifdef __cplusplus
extern "C" {
#endif
{FUNCTION DEFINITIONS}
#ifdef __cplusplus
}
#endif
Background: https://www.oracle.com/technical-resources/articles/it-infrastructure/mixing-c-and-cplusplus.html (section "Creating Mixed-Language Headers")
https://github.com/lammertb/libcrc/blob/master/include/checksum.h
needs the line:
#include <stddef.h>
...for the "size_t" parameters in the function calls. I think it's included by default in a lot of cases, but I've got a stripped-down bootloader that threw an error without this inclusion.
Your website https://www.lammertbies.nl/comm/info/crc-calculation.html states that the polynomial function for CRC-16 is 0x8005, but in fact checksum.h defines CRC_POLY_16 as 0xA001. Hence, crc_16() does not give the same value as your online CRC calculator for "123456789", 0xBB3D.
I made some modifications for an embedded project where the memory footprint is critical but the calculation time of the crc is not. I modified the calculation function so that no lookup table is used or the lookup table is read from flash memory but this is very platform specific. Is there any interest to merge that into this project?
Hello.
How i can use crc_ccitt_ffff(,) for calculation crc from hexa data? My data for crc is 890249780003A0015370C70119004FFB700039FC9FFFF4FE1EFFFFFFDDFFED00000526402A5A193DF87D50.
I need crc value 0xA9B6, but i have 0x1E66 (data calculated as ASCII). How i can fix it?
Compilation fails under gcc 5.4.0 due to fgets() return value not being used. This generates a compilation warning, which is treated as an error. PR #2 addresses this issue.
I am using MPLAB X IDE with device dspic33fj32mc304 which has inbuilt crc generator but it not gives me appropriate results for poly=0X8005; i tried all the documents provided by microchip but i don't get what i want.
in the code of crc16 modbus which i want from your site is want lookup table but there is nothing in c file or inc file.
please help me with this small issue. i uses XC16 compiler in MPLAB.
for data 01 04 00 04 00 02 crc16 modbus is 0A 30 is not achive
Hi,
when using gcc-7, the lib fail to build:
$ CC=gcc-7 LINK=gcc-7 make
gcc-7 -c -Wall -Wextra -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wredundant-decls -Wnested-externs -Werror -O3 -funsigned-char -Iinclude/ -oobj/crc8.o src/crc8.c
gcc-7 -c -Wall -Wextra -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wredundant-decls -Wnested-externs -Werror -O3 -funsigned-char -Iinclude/ -oobj/crc16.o src/crc16.c
gcc-7 -c -Wall -Wextra -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wredundant-decls -Wnested-externs -Werror -O3 -funsigned-char -Iinclude/ -oobj/crc32.o src/crc32.c
gcc-7 -c -Wall -Wextra -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wredundant-decls -Wnested-externs -Werror -O3 -funsigned-char -Iinclude/ -oobj/crcccitt.o src/crcccitt.c
gcc-7 -c -Wall -Wextra -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wredundant-decls -Wnested-externs -Werror -O3 -funsigned-char -Iinclude/ -oobj/crcdnp.o src/crcdnp.c
gcc-7 -c -Wall -Wextra -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wredundant-decls -Wnested-externs -Werror -O3 -funsigned-char -Iinclude/ -oobj/crckrmit.o src/crckrmit.c
gcc-7 -c -Wall -Wextra -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wredundant-decls -Wnested-externs -Werror -O3 -funsigned-char -Iinclude/ -oobj/crcsick.o src/crcsick.c
gcc-7 -c -Wall -Wextra -Wstrict-prototypes -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wredundant-decls -Wnested-externs -Werror -O3 -funsigned-char -Iinclude/ -oobj/nmea-chk.o src/nmea-chk.c
src/nmea-chk.c: In function ‘checksum_NMEA’:
src/nmea-chk.c:72:33: error: ‘%02X’ directive output may be truncated writing between 2 and 8 bytes into a region of size 3 [-Werror=format-truncation=]
snprintf( (char *) result, 3, "%02X", checksum );
^~~~
src/nmea-chk.c:72:32: note: directive argument in the range [0, 2147483647]
snprintf( (char *) result, 3, "%02X", checksum );
^~~~~~
In file included from /usr/include/stdio.h:936:0,
from src/nmea-chk.c:34:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: ‘__builtin___snprintf_chk’ output between 3 and 9 bytes into a destination of size 3
return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
Makefile:117: recipe for target 'obj/nmea-chk.o' failed
make: *** [obj/nmea-chk.o] Error 1
Could you add the information that CRC-16 Sick only checks the most significant byte to the git documentation and also to your site? I was under the impression for a few days that it was a real CRC because this information is missing.
Hi @lammertb,
I am using your lib and I got found different values for CRC-16 CRC-CCITT (Kermit) algorithm.
On your calcutation site (https://www.lammertbies.nl/comm/info/crc-calculation) for the value 123456789 I got 0x8921
In other way at site (https://crccalc.com/) for same valeu and algorithm got 0x2189
Is there any way to get the same value ?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.