checksum.h 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Library: libcrc
  3. * File: include/checksum.h
  4. * Author: Lammert Bies
  5. *
  6. * This file is licensed under the MIT License as stated below
  7. *
  8. * Copyright (c) 1999-2016 Lammert Bies
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a copy
  11. * of this software and associated documentation files (the "Software"), to deal
  12. * in the Software without restriction, including without limitation the rights
  13. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. * copies of the Software, and to permit persons to whom the Software is
  15. * furnished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be included in all
  18. * copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26. * SOFTWARE.
  27. *
  28. * Description
  29. * -----------
  30. * The headerfile include/checksum.h contains the definitions and prototypes
  31. * for routines that can be used to calculate several kinds of checksums.
  32. */
  33. #ifndef DEF_LIBCRC_CHECKSUM_H
  34. #define DEF_LIBCRC_CHECKSUM_H
  35. #include <stdint.h>
  36. /*
  37. * #define CRC_POLY_xxxx
  38. *
  39. * The constants of the form CRC_POLY_xxxx define the polynomials for some well
  40. * known CRC calculations.
  41. */
  42. #define CRC_POLY_16 0xA001
  43. #define CRC_POLY_32 0xEDB88320L
  44. #define CRC_POLY_CCITT 0x1021
  45. #define CRC_POLY_DNP 0xA6BC
  46. #define CRC_POLY_KERMIT 0x8408
  47. #define CRC_POLY_SICK 0x8005
  48. /*
  49. * #define CRC_START_xxxx
  50. *
  51. * The constants of the form CRC_START_xxxx define the values that are used for
  52. * initialization of a CRC value for common used calculation methods.
  53. */
  54. #define CRC_START_8 0x00
  55. #define CRC_START_16 0x0000
  56. #define CRC_START_MODBUS 0xFFFF
  57. #define CRC_START_XMODEM 0x0000
  58. #define CRC_START_CCITT_1D0F 0x1D0F
  59. #define CRC_START_CCITT_FFFF 0xFFFF
  60. #define CRC_START_KERMIT 0x0000
  61. #define CRC_START_SICK 0x0000
  62. #define CRC_START_DNP 0x0000
  63. #define CRC_START_32 0xFFFFFFFFL
  64. /*
  65. * Prototype list of global functions
  66. */
  67. unsigned char * checksum_NMEA( const unsigned char *input_str, unsigned char *result );
  68. uint8_t crc_8( const unsigned char *input_str, size_t num_bytes );
  69. uint16_t crc_16( const unsigned char *input_str, size_t num_bytes );
  70. uint32_t crc_32( const unsigned char *input_str, size_t num_bytes );
  71. uint16_t crc_ccitt_1d0f( const unsigned char *input_str, size_t num_bytes );
  72. uint16_t crc_ccitt_ffff( const unsigned char *input_str, size_t num_bytes );
  73. uint16_t crc_dnp( const unsigned char *input_str, size_t num_bytes );
  74. uint16_t crc_kermit( const unsigned char *input_str, size_t num_bytes );
  75. uint16_t crc_modbus( const unsigned char *input_str, size_t num_bytes );
  76. uint16_t crc_sick( const unsigned char *input_str, size_t num_bytes );
  77. uint16_t crc_xmodem( const unsigned char *input_str, size_t num_bytes );
  78. uint8_t update_crc_8( uint8_t crc, unsigned char c );
  79. uint16_t update_crc_16( uint16_t crc, unsigned char c );
  80. uint32_t update_crc_32( uint32_t crc, unsigned char c );
  81. uint16_t update_crc_ccitt( uint16_t crc, unsigned char c );
  82. uint16_t update_crc_dnp( uint16_t crc, unsigned char c );
  83. uint16_t update_crc_kermit( uint16_t crc, unsigned char c );
  84. uint16_t update_crc_sick( uint16_t crc, unsigned char c, unsigned char prev_byte );
  85. #endif // DEF_LIBCRC_CHECKSUM_H