digest-crc 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.md +4 -0
- data/LICENSE.txt +1 -1
- data/README.md +4 -3
- data/Rakefile +5 -5
- data/digest-crc.gemspec +38 -105
- data/gemspec.yml +4 -4
- data/lib/digest/crc16_qt.rb +65 -0
- data/spec/crc16_qt_spec.rb +10 -0
- metadata +31 -30
data/ChangeLog.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Digest CRC
|
2
2
|
|
3
|
-
* [Source](
|
4
|
-
* [Issues](
|
3
|
+
* [Source](https://github.com/postmodern/digest-crc)
|
4
|
+
* [Issues](https://github.com/postmodern/digest-crc/issues)
|
5
5
|
* [Documentation](http://rubydoc.info/gems/digest-crc/frames)
|
6
6
|
* [Email](mailto:postmodern.mod3 at gmail.com)
|
7
7
|
|
@@ -24,6 +24,7 @@ module.
|
|
24
24
|
* {Digest::CRC16USB CRC16 USB}
|
25
25
|
* {Digest::CRC16XModem CRC16 XModem}
|
26
26
|
* {Digest::CRC16ZModem CRC16 ZModem}
|
27
|
+
* {Digest::CRC16QT CRC16 QT}
|
27
28
|
* {Digest::CRC24 CRC24}
|
28
29
|
* {Digest::CRC32 CRC32}
|
29
30
|
* {Digest::CRC32c CRC32c}
|
@@ -72,6 +73,6 @@ including their CRC Tables.
|
|
72
73
|
|
73
74
|
## License
|
74
75
|
|
75
|
-
Copyright (c) 2010-
|
76
|
+
Copyright (c) 2010-2013 Hal Brodigan
|
76
77
|
|
77
78
|
See {file:LICENSE.txt} for license information.
|
data/Rakefile
CHANGED
@@ -2,13 +2,13 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
|
4
4
|
begin
|
5
|
-
gem '
|
6
|
-
require '
|
5
|
+
gem 'rubygems-tasks', '~> 0.1'
|
6
|
+
require 'rubygems/tasks'
|
7
7
|
|
8
|
-
|
8
|
+
Gem::Tasks.new
|
9
9
|
rescue LoadError => e
|
10
10
|
warn e.message
|
11
|
-
warn "Run `gem install
|
11
|
+
warn "Run `gem install rubygems-tasks` to install 'rubygems/tasks'."
|
12
12
|
end
|
13
13
|
|
14
14
|
begin
|
@@ -25,7 +25,7 @@ task :test => :spec
|
|
25
25
|
task :default => :spec
|
26
26
|
|
27
27
|
begin
|
28
|
-
gem 'yard', '~> 0.
|
28
|
+
gem 'yard', '~> 0.8'
|
29
29
|
require 'yard'
|
30
30
|
|
31
31
|
YARD::Rake::YardocTask.new
|
data/digest-crc.gemspec
CHANGED
@@ -2,126 +2,59 @@
|
|
2
2
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
`git ls-files`.split($/)
|
8
|
-
elsif File.directory?('.hg')
|
9
|
-
`hg manifest`.split($/)
|
10
|
-
elsif File.directory?('.svn')
|
11
|
-
`svn ls -R`.split($/).select { |path| File.file?(path) }
|
12
|
-
else
|
13
|
-
Dir['{**/}{.*,*}'].select { |path| File.file?(path) }
|
14
|
-
end
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gemspec = YAML.load_file('gemspec.yml')
|
15
7
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
when String
|
21
|
-
(files & Dir[paths])
|
22
|
-
end
|
23
|
-
}
|
24
|
-
|
25
|
-
version = {
|
26
|
-
:file => 'lib/digest/crc/version.rb',
|
27
|
-
:constant => 'Digest::CRC::VERSION'
|
28
|
-
}
|
29
|
-
|
30
|
-
defaults = {
|
31
|
-
'name' => File.basename(File.dirname(__FILE__)),
|
32
|
-
'files' => files,
|
33
|
-
'executables' => filter_files['bin/*'].map { |path| File.basename(path) },
|
34
|
-
'test_files' => filter_files['{test/{**/}*_test.rb,spec/{**/}*_spec.rb}'],
|
35
|
-
'extra_doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}'],
|
36
|
-
}
|
37
|
-
|
38
|
-
metadata = defaults.merge(YAML.load_file('gemspec.yml'))
|
39
|
-
|
40
|
-
gemspec.name = metadata.fetch('name',defaults[:name])
|
41
|
-
gemspec.version = if metadata['version']
|
42
|
-
metadata['version']
|
43
|
-
elsif File.file?(version[:file])
|
44
|
-
require File.join('.',version[:file])
|
45
|
-
eval(version[:constant])
|
46
|
-
end
|
47
|
-
|
48
|
-
gemspec.summary = metadata.fetch('summary',metadata['description'])
|
49
|
-
gemspec.description = metadata.fetch('description',metadata['summary'])
|
50
|
-
|
51
|
-
case metadata['license']
|
52
|
-
when Array
|
53
|
-
gemspec.licenses = metadata['license']
|
54
|
-
when String
|
55
|
-
gemspec.license = metadata['license']
|
56
|
-
end
|
57
|
-
|
58
|
-
case metadata['authors']
|
59
|
-
when Array
|
60
|
-
gemspec.authors = metadata['authors']
|
61
|
-
when String
|
62
|
-
gemspec.author = metadata['authors']
|
63
|
-
end
|
8
|
+
gem.name = gemspec.fetch('name')
|
9
|
+
gem.version = gemspec.fetch('version') do
|
10
|
+
lib_dir = File.join(File.dirname(__FILE__),'lib')
|
11
|
+
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
64
12
|
|
65
|
-
|
66
|
-
|
13
|
+
require 'digest/crc/version'
|
14
|
+
Digest::Crc::VERSION
|
15
|
+
end
|
67
16
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
17
|
+
gem.summary = gemspec['summary']
|
18
|
+
gem.description = gemspec['description']
|
19
|
+
gem.licenses = Array(gemspec['license'])
|
20
|
+
gem.authors = Array(gemspec['authors'])
|
21
|
+
gem.email = gemspec['email']
|
22
|
+
gem.homepage = gemspec['homepage']
|
74
23
|
|
75
|
-
|
24
|
+
glob = lambda { |patterns| gem.files & Dir[*patterns] }
|
76
25
|
|
77
|
-
|
78
|
-
|
26
|
+
gem.files = `git ls-files`.split($/)
|
27
|
+
gem.files = glob[gemspec['files']] if gemspec['files']
|
79
28
|
|
80
|
-
|
81
|
-
|
29
|
+
gem.executables = gemspec.fetch('executables') do
|
30
|
+
glob['bin/*'].map { |path| File.basename(path) }
|
82
31
|
end
|
32
|
+
gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
|
83
33
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
gemspec.extra_rdoc_files = metadata['extra_doc_files']
|
88
|
-
end
|
89
|
-
|
90
|
-
gemspec.post_install_message = metadata['post_install_message']
|
91
|
-
gemspec.requirements = metadata['requirements']
|
92
|
-
|
93
|
-
if gemspec.respond_to?(:required_ruby_version=)
|
94
|
-
gemspec.required_ruby_version = metadata['required_ruby_version']
|
95
|
-
end
|
34
|
+
gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
|
35
|
+
gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
|
36
|
+
gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
|
96
37
|
|
97
|
-
|
98
|
-
|
99
|
-
|
38
|
+
gem.require_paths = Array(gemspec.fetch('require_paths') {
|
39
|
+
%w[ext lib].select { |dir| File.directory?(dir) }
|
40
|
+
})
|
100
41
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
when String
|
106
|
-
versions.split(/,\s*/)
|
107
|
-
end
|
108
|
-
}
|
42
|
+
gem.requirements = gemspec['requirements']
|
43
|
+
gem.required_ruby_version = gemspec['required_ruby_version']
|
44
|
+
gem.required_rubygems_version = gemspec['required_rubygems_version']
|
45
|
+
gem.post_install_message = gemspec['post_install_message']
|
109
46
|
|
110
|
-
|
111
|
-
metadata['dependencies'].each do |name,versions|
|
112
|
-
gemspec.add_dependency(name,parse_versions[versions])
|
113
|
-
end
|
114
|
-
end
|
47
|
+
split = lambda { |string| string.split(/,\s*/) }
|
115
48
|
|
116
|
-
if
|
117
|
-
|
118
|
-
|
49
|
+
if gemspec['dependencies']
|
50
|
+
gemspec['dependencies'].each do |name,versions|
|
51
|
+
gem.add_dependency(name,split[versions])
|
119
52
|
end
|
120
53
|
end
|
121
54
|
|
122
|
-
if
|
123
|
-
|
124
|
-
|
55
|
+
if gemspec['development_dependencies']
|
56
|
+
gemspec['development_dependencies'].each do |name,versions|
|
57
|
+
gem.add_development_dependency(name,split[versions])
|
125
58
|
end
|
126
59
|
end
|
127
60
|
end
|
data/gemspec.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
name: digest-crc
|
2
|
-
version: 0.
|
2
|
+
version: 0.4.0
|
3
3
|
summary: A Cyclic Redundancy Check (CRC) library for Ruby.
|
4
4
|
description:
|
5
5
|
Adds support for calculating Cyclic Redundancy Check (CRC) to the
|
@@ -8,10 +8,10 @@ description:
|
|
8
8
|
license: MIT
|
9
9
|
authors: Postmodern
|
10
10
|
email: postmodern.mod3@gmail.com
|
11
|
-
homepage:
|
11
|
+
homepage: https://github.com/postmodern/digest-crc#readme
|
12
12
|
has_yard: true
|
13
13
|
|
14
14
|
development_dependencies:
|
15
|
-
|
15
|
+
rubygems-tasks: ~> 0.2
|
16
16
|
rspec: ~> 2.4
|
17
|
-
yard: ~> 0.
|
17
|
+
yard: ~> 0.8
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'digest/crc16_ccitt'
|
2
|
+
|
3
|
+
module Digest
|
4
|
+
#
|
5
|
+
# Implements the CRC16_CCITT algorithm used in QT algorithms.
|
6
|
+
#
|
7
|
+
# @author Matthew Bednarski
|
8
|
+
#
|
9
|
+
class CRC16QT < CRC16CCITT
|
10
|
+
|
11
|
+
FINAL_XOR = 0xffff
|
12
|
+
|
13
|
+
REVERSE_CRC_RESULT = true
|
14
|
+
|
15
|
+
REVERSE_DATA = true
|
16
|
+
|
17
|
+
# Updates the CRC16 checksum.
|
18
|
+
#
|
19
|
+
# @param [String] data
|
20
|
+
# The data to update the checksum with.
|
21
|
+
#
|
22
|
+
def update(data)
|
23
|
+
data.each_byte do |b|
|
24
|
+
b = revert_byte(b) if REVERSE_DATA
|
25
|
+
@crc = ((TABLE[((@crc >> 8) ^ b) & 0xff] ^ (@crc << 8)) & 0xffff)
|
26
|
+
end
|
27
|
+
|
28
|
+
return self
|
29
|
+
end
|
30
|
+
|
31
|
+
def checksum
|
32
|
+
crc = @crc + 0
|
33
|
+
crc ^= FINAL_XOR if FINAL_XOR
|
34
|
+
crc = revert_bits crc if REVERSE_CRC_RESULT
|
35
|
+
return crc
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def revert_bits(cc)
|
41
|
+
ob = 0
|
42
|
+
b = (1 << 15)
|
43
|
+
|
44
|
+
16.times do |t|
|
45
|
+
ob |= (1 << t) if (cc & b) != 0
|
46
|
+
b >>= 1
|
47
|
+
end
|
48
|
+
|
49
|
+
return ob
|
50
|
+
end
|
51
|
+
|
52
|
+
def revert_byte(cc)
|
53
|
+
ob = 0
|
54
|
+
b = (1 << 7)
|
55
|
+
|
56
|
+
8.times do |t|
|
57
|
+
ob |= (1 << t) if (cc & b) != 0
|
58
|
+
b >>= 1
|
59
|
+
end
|
60
|
+
|
61
|
+
return ob
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: digest-crc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,27 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement:
|
15
|
+
name: rubygems-tasks
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0.
|
21
|
+
version: '0.2'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.2'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rspec
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,18 +37,28 @@ dependencies:
|
|
32
37
|
version: '2.4'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.4'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: yard
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
42
52
|
- !ruby/object:Gem::Version
|
43
|
-
version: 0.
|
53
|
+
version: '0.8'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.8'
|
47
62
|
description: Adds support for calculating Cyclic Redundancy Check (CRC) to the Digest
|
48
63
|
module.
|
49
64
|
email: postmodern.mod3@gmail.com
|
@@ -70,6 +85,7 @@ files:
|
|
70
85
|
- lib/digest/crc16_ccitt.rb
|
71
86
|
- lib/digest/crc16_dnp.rb
|
72
87
|
- lib/digest/crc16_modbus.rb
|
88
|
+
- lib/digest/crc16_qt.rb
|
73
89
|
- lib/digest/crc16_usb.rb
|
74
90
|
- lib/digest/crc16_xmodem.rb
|
75
91
|
- lib/digest/crc16_zmodem.rb
|
@@ -83,6 +99,7 @@ files:
|
|
83
99
|
- lib/digest/crc8_1wire.rb
|
84
100
|
- spec/crc16_ccitt_spec.rb
|
85
101
|
- spec/crc16_modbus_spec.rb
|
102
|
+
- spec/crc16_qt_spec.rb
|
86
103
|
- spec/crc16_spec.rb
|
87
104
|
- spec/crc16_usb_spec.rb
|
88
105
|
- spec/crc16_xmodem_spec.rb
|
@@ -99,7 +116,7 @@ files:
|
|
99
116
|
- spec/crc_examples.rb
|
100
117
|
- spec/crc_spec.rb
|
101
118
|
- spec/spec_helper.rb
|
102
|
-
homepage:
|
119
|
+
homepage: https://github.com/postmodern/digest-crc#readme
|
103
120
|
licenses:
|
104
121
|
- MIT
|
105
122
|
post_install_message:
|
@@ -120,24 +137,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
137
|
version: '0'
|
121
138
|
requirements: []
|
122
139
|
rubyforge_project:
|
123
|
-
rubygems_version: 1.8.
|
140
|
+
rubygems_version: 1.8.24
|
124
141
|
signing_key:
|
125
142
|
specification_version: 3
|
126
143
|
summary: A Cyclic Redundancy Check (CRC) library for Ruby.
|
127
|
-
test_files:
|
128
|
-
- spec/crc16_ccitt_spec.rb
|
129
|
-
- spec/crc16_modbus_spec.rb
|
130
|
-
- spec/crc16_spec.rb
|
131
|
-
- spec/crc16_usb_spec.rb
|
132
|
-
- spec/crc16_xmodem_spec.rb
|
133
|
-
- spec/crc16_zmodem_spec.rb
|
134
|
-
- spec/crc1_spec.rb
|
135
|
-
- spec/crc24_spec.rb
|
136
|
-
- spec/crc32_mpeg_spec.rb
|
137
|
-
- spec/crc32_spec.rb
|
138
|
-
- spec/crc32c_spec.rb
|
139
|
-
- spec/crc5_spec.rb
|
140
|
-
- spec/crc64_spec.rb
|
141
|
-
- spec/crc8_1wire_spec.rb
|
142
|
-
- spec/crc8_spec.rb
|
143
|
-
- spec/crc_spec.rb
|
144
|
+
test_files: []
|