annoying_crc_16 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/annoying_crc_16.gemspec +13 -0
- data/ext/annoying_crc_16.c +75 -0
- data/ext/extconf.rb +7 -0
- metadata +49 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "annoying_crc_16"
|
3
|
+
s.version = "0.1.1"
|
4
|
+
s.date = "2011-11-09"
|
5
|
+
s.summary = "A very annoyingly specifc implementation of CRC-16"
|
6
|
+
s.require_paths = ["lib"]
|
7
|
+
s.email = "jlewis73@jhu.edu"
|
8
|
+
s.authors = ["Jason Lewis"]
|
9
|
+
s.description = "C extension to provide a specific implementation of CRC-16 for a very picky application"
|
10
|
+
s.required_ruby_version = Gem::Version::Requirement.new(">=1.9.1")
|
11
|
+
s.files = ["ext/extconf.rb", "ext/annoying_crc_16.c", "annoying_crc_16.gemspec"]
|
12
|
+
s.extensions = ["ext/extconf.rb"]
|
13
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#include <stdlib.h>
|
2
|
+
#include "ruby.h"
|
3
|
+
|
4
|
+
|
5
|
+
typedef unsigned short WORD;
|
6
|
+
typedef unsigned char BYTE;
|
7
|
+
|
8
|
+
VALUE rb_mAnnoyingCRC16;
|
9
|
+
VALUE rb_mAnnoyingCRC16_Ext;
|
10
|
+
|
11
|
+
void Init_annoying_crc_16_ext();
|
12
|
+
|
13
|
+
VALUE method_calc_crc16(VALUE self, VALUE rb_str);
|
14
|
+
VALUE method_calc_lrc(VALUE self, VALUE rb_str);
|
15
|
+
WORD CalcCrc16(const BYTE *Data, WORD DataLen);
|
16
|
+
BYTE CalcLrc(const BYTE *Data, WORD DataLen);
|
17
|
+
|
18
|
+
void Init_annoying_crc_16() {
|
19
|
+
rb_mAnnoyingCRC16 = rb_define_module("AnnoyingCRC16");
|
20
|
+
rb_define_method(rb_mAnnoyingCRC16, "calc_crc16", method_calc_crc16, 1);
|
21
|
+
rb_define_method(rb_mAnnoyingCRC16, "calc_lrc", method_calc_lrc, 1);
|
22
|
+
}
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
VALUE method_calc_crc16(VALUE self, VALUE rb_str) {
|
27
|
+
const BYTE *str;
|
28
|
+
VALUE s = StringValue(rb_str);
|
29
|
+
str = RSTRING_PTR(s);
|
30
|
+
|
31
|
+
WORD len = RSTRING_LEN(s);
|
32
|
+
WORD crc = CalcCrc16(str, len);
|
33
|
+
|
34
|
+
return INT2FIX(crc);
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
VALUE method_calc_lrc(VALUE self, VALUE rb_str) {
|
40
|
+
const BYTE *str;
|
41
|
+
VALUE s = StringValue(rb_str);
|
42
|
+
|
43
|
+
str = RSTRING_PTR(s);
|
44
|
+
|
45
|
+
WORD len = RSTRING_LEN(s);
|
46
|
+
BYTE lrc = CalcLrc(str, len);
|
47
|
+
|
48
|
+
return INT2FIX(lrc);
|
49
|
+
}
|
50
|
+
|
51
|
+
WORD CalcCrc16( const BYTE *data, WORD dataLen) {
|
52
|
+
WORD Temp;
|
53
|
+
WORD Crc;
|
54
|
+
|
55
|
+
Crc = 0;
|
56
|
+
|
57
|
+
while(dataLen--) {
|
58
|
+
Temp = (WORD)(*data++) ^ (Crc >> 8);
|
59
|
+
Temp ^= (Temp >> 4);
|
60
|
+
Temp ^= (Temp >> 2);
|
61
|
+
Temp ^= (Temp >> 1);
|
62
|
+
Crc = (Crc << 8) ^ (Temp << 15) ^ (Temp << 2) ^ Temp;
|
63
|
+
}
|
64
|
+
return Crc;
|
65
|
+
}
|
66
|
+
|
67
|
+
BYTE CalcLrc(const BYTE *data, WORD dataLen) {
|
68
|
+
BYTE lrc;
|
69
|
+
|
70
|
+
lrc = 0;
|
71
|
+
while (dataLen--) {
|
72
|
+
lrc ^= *data++;
|
73
|
+
}
|
74
|
+
return lrc;
|
75
|
+
}
|
data/ext/extconf.rb
ADDED
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: annoying_crc_16
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jason Lewis
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-09 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: C extension to provide a specific implementation of CRC-16 for a very
|
15
|
+
picky application
|
16
|
+
email: jlewis73@jhu.edu
|
17
|
+
executables: []
|
18
|
+
extensions:
|
19
|
+
- ext/extconf.rb
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- ext/extconf.rb
|
23
|
+
- ext/annoying_crc_16.c
|
24
|
+
- annoying_crc_16.gemspec
|
25
|
+
homepage:
|
26
|
+
licenses: []
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
none: false
|
33
|
+
requirements:
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.9.1
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 1.8.24
|
46
|
+
signing_key:
|
47
|
+
specification_version: 3
|
48
|
+
summary: A very annoyingly specifc implementation of CRC-16
|
49
|
+
test_files: []
|