crc16-xmodem.c

Simple implementation of crc16-xmodem
git clone git://git.finwo.net/lib/crc16-xmodem.c
Log | Files | Refs | README | LICENSE

README.md (1730B)


      1 crc16-xmodem
      2 =============
      3 
      4 Generate CRC-16/XMODEM codes consistently
      5 
      6 Why
      7 ---
      8 
      9 While a fairly simple task, I was implementing this throughout multiple projects
     10 of mine. Now if there's a bug, speed improvement to be had, or simple because
     11 the C standard changes, I want to be able to update it in 1 location
     12 instead of having to fix it in every individual project.
     13 
     14 TL;DR; I'm lazy, and want a single version of the code
     15 
     16 Installation
     17 ------------
     18 
     19 ```sh
     20 dep add finwo/crc16-xmodem
     21 dep install
     22 ```
     23 
     24 After that, simply add `include lib/.dep/config.mk` in your makefile and include
     25 the header file by adding `#include "finwo/crc16-xmodem.h"`.
     26 
     27 Usage
     28 -----
     29 
     30 ```c
     31 #include "finwo/crc16-xmodem.h"
     32 
     33 uint8_t message[] = "Hi!\0\0";
     34 
     35 // Output 12797 (0x31FD)
     36 uint16_t crc = crc16_xmodem(message, 4);
     37 crc16_xmodem_b(message, 4, &message[4]);
     38 
     39 // Now if you want to check if your message has travelled the network without errors:
     40 if (crc16_xmodem(message, 6) != 0) {
     41   printf("Message got corrupted in transit\n");
     42 }
     43 ```
     44 
     45 Features
     46 --------
     47 
     48 - Consistent CRC-16/XMODEM implementation
     49 - ANSI C (C99)
     50 - Fast lookup-table based calculation
     51 
     52 API
     53 ---
     54 
     55 ### crc16_xmodem(data, length)
     56 
     57 Calculate the CRC-16/XMODEM checksum of the given data
     58 
     59 ```c
     60 uint16_t crc16_xmodem(const uint8_t *data, size_t length);
     61 ```
     62 
     63 ### crc16_xmodem_b(data, length, out)
     64 
     65 Calculate the CRC-16/XMODEM checksum and write it as big-endian bytes
     66 
     67 ```c
     68 void crc16_xmodem_b(const uint8_t *data, size_t length, uint8_t *out);
     69 ```
     70 
     71 Testing
     72 -------
     73 
     74 If you want to run the library's tests, simply run `make test` to compile
     75 the testing binary, and then `./test` to run the actual tests.
     76 
     77 License
     78 -------
     79 
     80 crc16-xmodem source code is available under the [FGPL license](LICENSE.md)