digest-crc 0.5.1 → 0.6.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/.travis.yml +8 -0
- data/ChangeLog.md +69 -0
- data/README.md +3 -0
- data/Rakefile +25 -1
- data/benchmarks.rb +8 -4
- data/ext/digest/Rakefile +51 -0
- data/ext/digest/compat/ruby.h +11 -0
- data/ext/digest/crc12_3gpp/crc12_3gpp.c +66 -0
- data/ext/digest/crc12_3gpp/crc12_3gpp.h +11 -0
- data/ext/digest/crc12_3gpp/crc12_3gpp_ext.c +27 -0
- data/ext/digest/crc12_3gpp/extconf.rb +7 -0
- data/ext/digest/crc15/crc15.c +53 -0
- data/ext/digest/crc15/crc15.h +11 -0
- data/ext/digest/crc15/crc15_ext.c +28 -0
- data/ext/digest/crc15/extconf.rb +7 -0
- data/ext/digest/crc16/crc16.c +69 -0
- data/ext/digest/crc16/crc16.h +11 -0
- data/ext/digest/crc16/crc16_ext.c +28 -0
- data/ext/digest/crc16/extconf.rb +7 -0
- data/ext/digest/crc16_ccitt/crc16_ccitt.c +69 -0
- data/ext/digest/crc16_ccitt/crc16_ccitt.h +8 -0
- data/ext/digest/crc16_ccitt/crc16_ccitt_ext.c +28 -0
- data/ext/digest/crc16_ccitt/extconf.rb +7 -0
- data/ext/digest/crc16_dnp/crc16_dnp.c +53 -0
- data/ext/digest/crc16_dnp/crc16_dnp.h +8 -0
- data/ext/digest/crc16_dnp/crc16_dnp_ext.c +28 -0
- data/ext/digest/crc16_dnp/extconf.rb +7 -0
- data/ext/digest/crc16_genibus/crc16_genibus.c +69 -0
- data/ext/digest/crc16_genibus/crc16_genibus.h +8 -0
- data/ext/digest/crc16_genibus/crc16_genibus_ext.c +28 -0
- data/ext/digest/crc16_genibus/extconf.rb +7 -0
- data/ext/digest/crc16_kermit/crc16_kermit.c +69 -0
- data/ext/digest/crc16_kermit/crc16_kermit.h +8 -0
- data/ext/digest/crc16_kermit/crc16_kermit_ext.c +28 -0
- data/ext/digest/crc16_kermit/extconf.rb +7 -0
- data/ext/digest/crc16_modbus/crc16_modbus.c +69 -0
- data/ext/digest/crc16_modbus/crc16_modbus.h +8 -0
- data/ext/digest/crc16_modbus/crc16_modbus_ext.c +28 -0
- data/ext/digest/crc16_modbus/extconf.rb +7 -0
- data/ext/digest/crc16_usb/crc16_usb.c +69 -0
- data/ext/digest/crc16_usb/crc16_usb.h +8 -0
- data/ext/digest/crc16_usb/crc16_usb_ext.c +28 -0
- data/ext/digest/crc16_usb/extconf.rb +7 -0
- data/ext/digest/crc16_x_25/crc16_x_25.c +69 -0
- data/ext/digest/crc16_x_25/crc16_x_25.h +8 -0
- data/ext/digest/crc16_x_25/crc16_x_25_ext.c +28 -0
- data/ext/digest/crc16_x_25/extconf.rb +7 -0
- data/ext/digest/crc16_xmodem/crc16_xmodem.c +69 -0
- data/ext/digest/crc16_xmodem/crc16_xmodem.h +8 -0
- data/ext/digest/crc16_xmodem/crc16_xmodem_ext.c +28 -0
- data/ext/digest/crc16_xmodem/extconf.rb +7 -0
- data/ext/digest/crc16_zmodem/crc16_zmodem.c +69 -0
- data/ext/digest/crc16_zmodem/crc16_zmodem.h +8 -0
- data/ext/digest/crc16_zmodem/crc16_zmodem_ext.c +28 -0
- data/ext/digest/crc16_zmodem/extconf.rb +7 -0
- data/ext/digest/crc24/crc24.c +69 -0
- data/ext/digest/crc24/crc24.h +11 -0
- data/ext/digest/crc24/crc24_ext.c +27 -0
- data/ext/digest/crc24/extconf.rb +7 -0
- data/ext/digest/crc32/crc32.c +68 -0
- data/ext/digest/crc32/crc32.h +11 -0
- data/ext/digest/crc32/crc32_ext.c +27 -0
- data/ext/digest/crc32/extconf.rb +7 -0
- data/ext/digest/crc32_bzip2/crc32_bzip2.c +69 -0
- data/ext/digest/crc32_bzip2/crc32_bzip2.h +8 -0
- data/ext/digest/crc32_bzip2/crc32_bzip2_ext.c +27 -0
- data/ext/digest/crc32_bzip2/extconf.rb +7 -0
- data/ext/digest/crc32_jam/crc32_jam.c +69 -0
- data/ext/digest/crc32_jam/crc32_jam.h +8 -0
- data/ext/digest/crc32_jam/crc32_jam_ext.c +27 -0
- data/ext/digest/crc32_jam/extconf.rb +7 -0
- data/ext/digest/crc32_mpeg/crc32_mpeg.c +69 -0
- data/ext/digest/crc32_mpeg/crc32_mpeg.h +8 -0
- data/ext/digest/crc32_mpeg/crc32_mpeg_ext.c +27 -0
- data/ext/digest/crc32_mpeg/extconf.rb +7 -0
- data/ext/digest/crc32_posix/crc32_posix.c +69 -0
- data/ext/digest/crc32_posix/crc32_posix.h +8 -0
- data/ext/digest/crc32_posix/crc32_posix_ext.c +27 -0
- data/ext/digest/crc32_posix/extconf.rb +7 -0
- data/ext/digest/crc32_xfer/crc32_xfer.c +69 -0
- data/ext/digest/crc32_xfer/crc32_xfer.h +8 -0
- data/ext/digest/crc32_xfer/crc32_xfer_ext.c +27 -0
- data/ext/digest/crc32_xfer/extconf.rb +7 -0
- data/ext/digest/crc32c/crc32c.c +69 -0
- data/ext/digest/crc32c/crc32c.h +8 -0
- data/ext/digest/crc32c/crc32c_ext.c +27 -0
- data/ext/digest/crc32c/extconf.rb +7 -0
- data/ext/digest/crc5/crc5.c +53 -0
- data/ext/digest/crc5/crc5.h +11 -0
- data/ext/digest/crc5/crc5_ext.c +27 -0
- data/ext/digest/crc5/extconf.rb +7 -0
- data/ext/digest/crc64/crc64.c +102 -0
- data/ext/digest/crc64/crc64.h +11 -0
- data/ext/digest/crc64/crc64_ext.c +27 -0
- data/ext/digest/crc64/extconf.rb +7 -0
- data/ext/digest/crc64_jones/crc64_jones.c +102 -0
- data/ext/digest/crc64_jones/crc64_jones.h +8 -0
- data/ext/digest/crc64_jones/crc64_jones_ext.c +27 -0
- data/ext/digest/crc64_jones/extconf.rb +7 -0
- data/ext/digest/crc64_xz/crc64_xz.c +102 -0
- data/ext/digest/crc64_xz/crc64_xz.h +8 -0
- data/ext/digest/crc64_xz/crc64_xz_ext.c +27 -0
- data/ext/digest/crc64_xz/extconf.rb +7 -0
- data/ext/digest/crc8/crc8.c +53 -0
- data/ext/digest/crc8/crc8.h +11 -0
- data/ext/digest/crc8/crc8_ext.c +27 -0
- data/ext/digest/crc8/extconf.rb +7 -0
- data/ext/digest/crc8_1wire/crc8_1wire.c +53 -0
- data/ext/digest/crc8_1wire/crc8_1wire.h +8 -0
- data/ext/digest/crc8_1wire/crc8_1wire_ext.c +27 -0
- data/ext/digest/crc8_1wire/extconf.rb +7 -0
- data/gemspec.yml +4 -1
- data/lib/digest/crc15.rb +4 -0
- data/lib/digest/crc16.rb +4 -0
- data/lib/digest/crc16_ccitt.rb +4 -0
- data/lib/digest/crc16_dnp.rb +4 -0
- data/lib/digest/crc16_genibus.rb +4 -0
- data/lib/digest/crc16_kermit.rb +4 -0
- data/lib/digest/crc16_modbus.rb +4 -0
- data/lib/digest/crc16_usb.rb +4 -0
- data/lib/digest/crc16_x_25.rb +4 -0
- data/lib/digest/crc16_xmodem.rb +4 -0
- data/lib/digest/crc16_zmodem.rb +4 -0
- data/lib/digest/crc24.rb +4 -0
- data/lib/digest/crc32.rb +4 -0
- data/lib/digest/crc32_bzip2.rb +4 -0
- data/lib/digest/crc32_mpeg.rb +4 -0
- data/lib/digest/crc32_posix.rb +4 -0
- data/lib/digest/crc32_xfer.rb +4 -0
- data/lib/digest/crc32c.rb +4 -0
- data/lib/digest/crc5.rb +4 -0
- data/lib/digest/crc64.rb +4 -0
- data/lib/digest/crc64_jones.rb +4 -0
- data/lib/digest/crc64_xz.rb +4 -0
- data/lib/digest/crc8.rb +4 -0
- data/lib/digest/crc8_1wire.rb +4 -0
- metadata +110 -3
@@ -0,0 +1,69 @@
|
|
1
|
+
/**
|
2
|
+
* \file
|
3
|
+
* Functions and types for CRC checks.
|
4
|
+
*
|
5
|
+
* Generated on Sat Feb 29 02:31:50 2020
|
6
|
+
* by pycrc v0.9.2, https://pycrc.org
|
7
|
+
* using the configuration:
|
8
|
+
* - Width = 16
|
9
|
+
* - Poly = 0x1021
|
10
|
+
* - XorIn = 0x0000
|
11
|
+
* - ReflectIn = True
|
12
|
+
* - XorOut = 0x0000
|
13
|
+
* - ReflectOut = True
|
14
|
+
* - Algorithm = table-driven
|
15
|
+
*/
|
16
|
+
|
17
|
+
#include "crc16_kermit.h"
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Static table used for the table_driven implementation.
|
21
|
+
*/
|
22
|
+
static const crc16_t crc_table[256] = {
|
23
|
+
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
|
24
|
+
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
|
25
|
+
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
|
26
|
+
0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
|
27
|
+
0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
|
28
|
+
0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
|
29
|
+
0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
|
30
|
+
0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
|
31
|
+
0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
|
32
|
+
0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
|
33
|
+
0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
|
34
|
+
0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
|
35
|
+
0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
|
36
|
+
0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
|
37
|
+
0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
|
38
|
+
0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
|
39
|
+
0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
|
40
|
+
0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
|
41
|
+
0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
|
42
|
+
0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
|
43
|
+
0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
|
44
|
+
0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
|
45
|
+
0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
|
46
|
+
0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
|
47
|
+
0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
|
48
|
+
0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
|
49
|
+
0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
|
50
|
+
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
|
51
|
+
0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
|
52
|
+
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
|
53
|
+
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
|
54
|
+
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
|
55
|
+
};
|
56
|
+
|
57
|
+
|
58
|
+
crc16_t crc16_kermit_update(crc16_t crc, const void *data, size_t data_len)
|
59
|
+
{
|
60
|
+
const unsigned char *d = (const unsigned char *)data;
|
61
|
+
unsigned int tbl_idx;
|
62
|
+
|
63
|
+
while (data_len--) {
|
64
|
+
tbl_idx = (crc ^ *d) & 0xff;
|
65
|
+
crc = (crc_table[tbl_idx] ^ (crc >> 8)) & 0xffff;
|
66
|
+
d++;
|
67
|
+
}
|
68
|
+
return crc & 0xffff;
|
69
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include "../compat/ruby.h"
|
3
|
+
|
4
|
+
#include "extconf.h"
|
5
|
+
#include "crc16_kermit.h"
|
6
|
+
|
7
|
+
VALUE Digest_CRC16Kermit_update(VALUE self, VALUE data)
|
8
|
+
{
|
9
|
+
VALUE crc_ivar_name = rb_intern("@crc");
|
10
|
+
VALUE crc_ivar = rb_ivar_get(self, crc_ivar_name);
|
11
|
+
crc16_t crc = NUM2USHORT(crc_ivar);
|
12
|
+
|
13
|
+
const char *data_ptr = StringValuePtr(data);
|
14
|
+
size_t length = RSTRING_LEN(data);
|
15
|
+
|
16
|
+
crc = crc16_kermit_update(crc,data_ptr,length);
|
17
|
+
|
18
|
+
rb_ivar_set(self, crc_ivar_name, USHORT2NUM(crc));
|
19
|
+
return self;
|
20
|
+
}
|
21
|
+
|
22
|
+
void Init_crc16_kermit_ext()
|
23
|
+
{
|
24
|
+
VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
|
25
|
+
VALUE cCRC16Kermit = rb_const_get(mDigest, rb_intern("CRC16Kermit"));
|
26
|
+
|
27
|
+
rb_define_method(cCRC16Kermit, "update", Digest_CRC16Kermit_update, 1);
|
28
|
+
}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
/**
|
2
|
+
* \file
|
3
|
+
* Functions and types for CRC checks.
|
4
|
+
*
|
5
|
+
* Generated on Sat Feb 29 02:04:54 2020
|
6
|
+
* by pycrc v0.9.2, https://pycrc.org
|
7
|
+
* using the configuration:
|
8
|
+
* - Width = 16
|
9
|
+
* - Poly = 0x8005
|
10
|
+
* - XorIn = 0xffff
|
11
|
+
* - ReflectIn = True
|
12
|
+
* - XorOut = 0x0000
|
13
|
+
* - ReflectOut = True
|
14
|
+
* - Algorithm = table-driven
|
15
|
+
*/
|
16
|
+
|
17
|
+
#include "crc16_modbus.h"
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Static table used for the table_driven implementation.
|
21
|
+
*/
|
22
|
+
static const crc16_t crc_table[256] = {
|
23
|
+
0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
|
24
|
+
0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
|
25
|
+
0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
|
26
|
+
0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
|
27
|
+
0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
|
28
|
+
0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
|
29
|
+
0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
|
30
|
+
0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
|
31
|
+
0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
|
32
|
+
0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
|
33
|
+
0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
|
34
|
+
0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
|
35
|
+
0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
|
36
|
+
0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
|
37
|
+
0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
|
38
|
+
0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
|
39
|
+
0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
|
40
|
+
0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
|
41
|
+
0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
|
42
|
+
0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
|
43
|
+
0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
|
44
|
+
0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
|
45
|
+
0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
|
46
|
+
0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
|
47
|
+
0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
|
48
|
+
0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
|
49
|
+
0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
|
50
|
+
0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
|
51
|
+
0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
|
52
|
+
0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
|
53
|
+
0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
|
54
|
+
0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
|
55
|
+
};
|
56
|
+
|
57
|
+
|
58
|
+
crc16_t crc16_modbus_update(crc16_t crc, const void *data, size_t data_len)
|
59
|
+
{
|
60
|
+
const unsigned char *d = (const unsigned char *)data;
|
61
|
+
unsigned int tbl_idx;
|
62
|
+
|
63
|
+
while (data_len--) {
|
64
|
+
tbl_idx = (crc ^ *d) & 0xff;
|
65
|
+
crc = (crc_table[tbl_idx] ^ (crc >> 8)) & 0xffff;
|
66
|
+
d++;
|
67
|
+
}
|
68
|
+
return crc & 0xffff;
|
69
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include "../compat/ruby.h"
|
3
|
+
|
4
|
+
#include "extconf.h"
|
5
|
+
#include "crc16_modbus.h"
|
6
|
+
|
7
|
+
VALUE Digest_CRC16Modbus_update(VALUE self, VALUE data)
|
8
|
+
{
|
9
|
+
VALUE crc_ivar_name = rb_intern("@crc");
|
10
|
+
VALUE crc_ivar = rb_ivar_get(self, crc_ivar_name);
|
11
|
+
crc16_t crc = NUM2USHORT(crc_ivar);
|
12
|
+
|
13
|
+
const char *data_ptr = StringValuePtr(data);
|
14
|
+
size_t length = RSTRING_LEN(data);
|
15
|
+
|
16
|
+
crc = crc16_modbus_update(crc,data_ptr,length);
|
17
|
+
|
18
|
+
rb_ivar_set(self, crc_ivar_name, USHORT2NUM(crc));
|
19
|
+
return self;
|
20
|
+
}
|
21
|
+
|
22
|
+
void Init_crc16_modbus_ext()
|
23
|
+
{
|
24
|
+
VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
|
25
|
+
VALUE cCRC16Modbus = rb_const_get(mDigest, rb_intern("CRC16Modbus"));
|
26
|
+
|
27
|
+
rb_define_method(cCRC16Modbus, "update", Digest_CRC16Modbus_update, 1);
|
28
|
+
}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
/**
|
2
|
+
* \file
|
3
|
+
* Functions and types for CRC checks.
|
4
|
+
*
|
5
|
+
* Generated on Sat Feb 29 02:05:41 2020
|
6
|
+
* by pycrc v0.9.2, https://pycrc.org
|
7
|
+
* using the configuration:
|
8
|
+
* - Width = 16
|
9
|
+
* - Poly = 0x8005
|
10
|
+
* - XorIn = 0xffff
|
11
|
+
* - ReflectIn = True
|
12
|
+
* - XorOut = 0xffff
|
13
|
+
* - ReflectOut = True
|
14
|
+
* - Algorithm = table-driven
|
15
|
+
*/
|
16
|
+
|
17
|
+
#include "crc16_usb.h"
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Static table used for the table_driven implementation.
|
21
|
+
*/
|
22
|
+
static const crc16_t crc_table[256] = {
|
23
|
+
0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
|
24
|
+
0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
|
25
|
+
0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
|
26
|
+
0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
|
27
|
+
0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
|
28
|
+
0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
|
29
|
+
0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
|
30
|
+
0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
|
31
|
+
0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
|
32
|
+
0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
|
33
|
+
0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
|
34
|
+
0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
|
35
|
+
0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
|
36
|
+
0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
|
37
|
+
0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
|
38
|
+
0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
|
39
|
+
0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
|
40
|
+
0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
|
41
|
+
0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
|
42
|
+
0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
|
43
|
+
0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
|
44
|
+
0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
|
45
|
+
0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
|
46
|
+
0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
|
47
|
+
0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
|
48
|
+
0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
|
49
|
+
0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
|
50
|
+
0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
|
51
|
+
0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
|
52
|
+
0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
|
53
|
+
0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
|
54
|
+
0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
|
55
|
+
};
|
56
|
+
|
57
|
+
|
58
|
+
crc16_t crc16_usb_update(crc16_t crc, const void *data, size_t data_len)
|
59
|
+
{
|
60
|
+
const unsigned char *d = (const unsigned char *)data;
|
61
|
+
unsigned int tbl_idx;
|
62
|
+
|
63
|
+
while (data_len--) {
|
64
|
+
tbl_idx = (crc ^ *d) & 0xff;
|
65
|
+
crc = (crc_table[tbl_idx] ^ (crc >> 8)) & 0xffff;
|
66
|
+
d++;
|
67
|
+
}
|
68
|
+
return crc & 0xffff;
|
69
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include "../compat/ruby.h"
|
3
|
+
|
4
|
+
#include "extconf.h"
|
5
|
+
#include "crc16_usb.h"
|
6
|
+
|
7
|
+
VALUE Digest_CRC16USB_update(VALUE self, VALUE data)
|
8
|
+
{
|
9
|
+
VALUE crc_ivar_name = rb_intern("@crc");
|
10
|
+
VALUE crc_ivar = rb_ivar_get(self, crc_ivar_name);
|
11
|
+
crc16_t crc = NUM2USHORT(crc_ivar);
|
12
|
+
|
13
|
+
const char *data_ptr = StringValuePtr(data);
|
14
|
+
size_t length = RSTRING_LEN(data);
|
15
|
+
|
16
|
+
crc = crc16_usb_update(crc,data_ptr,length);
|
17
|
+
|
18
|
+
rb_ivar_set(self, crc_ivar_name, USHORT2NUM(crc));
|
19
|
+
return self;
|
20
|
+
}
|
21
|
+
|
22
|
+
void Init_crc16_usb_ext()
|
23
|
+
{
|
24
|
+
VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
|
25
|
+
VALUE cCRC16USB = rb_const_get(mDigest, rb_intern("CRC16USB"));
|
26
|
+
|
27
|
+
rb_define_method(cCRC16USB, "update", Digest_CRC16USB_update, 1);
|
28
|
+
}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
/**
|
2
|
+
* \file
|
3
|
+
* Functions and types for CRC checks.
|
4
|
+
*
|
5
|
+
* Generated on Sat Feb 29 02:32:07 2020
|
6
|
+
* by pycrc v0.9.2, https://pycrc.org
|
7
|
+
* using the configuration:
|
8
|
+
* - Width = 16
|
9
|
+
* - Poly = 0x1021
|
10
|
+
* - XorIn = 0xffff
|
11
|
+
* - ReflectIn = True
|
12
|
+
* - XorOut = 0xffff
|
13
|
+
* - ReflectOut = True
|
14
|
+
* - Algorithm = table-driven
|
15
|
+
*/
|
16
|
+
|
17
|
+
#include "crc16_x_25.h"
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Static table used for the table_driven implementation.
|
21
|
+
*/
|
22
|
+
static const crc16_t crc_table[256] = {
|
23
|
+
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
|
24
|
+
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
|
25
|
+
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
|
26
|
+
0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
|
27
|
+
0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
|
28
|
+
0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
|
29
|
+
0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
|
30
|
+
0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
|
31
|
+
0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
|
32
|
+
0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
|
33
|
+
0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
|
34
|
+
0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
|
35
|
+
0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
|
36
|
+
0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
|
37
|
+
0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
|
38
|
+
0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
|
39
|
+
0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
|
40
|
+
0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
|
41
|
+
0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
|
42
|
+
0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
|
43
|
+
0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
|
44
|
+
0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
|
45
|
+
0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
|
46
|
+
0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
|
47
|
+
0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
|
48
|
+
0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
|
49
|
+
0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
|
50
|
+
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
|
51
|
+
0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
|
52
|
+
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
|
53
|
+
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
|
54
|
+
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
|
55
|
+
};
|
56
|
+
|
57
|
+
|
58
|
+
crc16_t crc16_x_25_update(crc16_t crc, const void *data, size_t data_len)
|
59
|
+
{
|
60
|
+
const unsigned char *d = (const unsigned char *)data;
|
61
|
+
unsigned int tbl_idx;
|
62
|
+
|
63
|
+
while (data_len--) {
|
64
|
+
tbl_idx = (crc ^ *d) & 0xff;
|
65
|
+
crc = (crc_table[tbl_idx] ^ (crc >> 8)) & 0xffff;
|
66
|
+
d++;
|
67
|
+
}
|
68
|
+
return crc & 0xffff;
|
69
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include "../compat/ruby.h"
|
3
|
+
|
4
|
+
#include "extconf.h"
|
5
|
+
#include "crc16_x_25.h"
|
6
|
+
|
7
|
+
VALUE Digest_CRC16X25_update(VALUE self, VALUE data)
|
8
|
+
{
|
9
|
+
VALUE crc_ivar_name = rb_intern("@crc");
|
10
|
+
VALUE crc_ivar = rb_ivar_get(self, crc_ivar_name);
|
11
|
+
crc16_t crc = NUM2USHORT(crc_ivar);
|
12
|
+
|
13
|
+
const char *data_ptr = StringValuePtr(data);
|
14
|
+
size_t length = RSTRING_LEN(data);
|
15
|
+
|
16
|
+
crc = crc16_x_25_update(crc,data_ptr,length);
|
17
|
+
|
18
|
+
rb_ivar_set(self, crc_ivar_name, USHORT2NUM(crc));
|
19
|
+
return self;
|
20
|
+
}
|
21
|
+
|
22
|
+
void Init_crc16_x_25_ext()
|
23
|
+
{
|
24
|
+
VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
|
25
|
+
VALUE cCRC16X25 = rb_const_get(mDigest, rb_intern("CRC16X25"));
|
26
|
+
|
27
|
+
rb_define_method(cCRC16X25, "update", Digest_CRC16X25_update, 1);
|
28
|
+
}
|