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 CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.4.0 / 2013-02-13
2
+
3
+ * Added {Digest::CRC16QT}.
4
+
1
5
  ### 0.3.0 / 2011-09-24
2
6
 
3
7
  * Added {Digest::CRC81Wire} (Henry Garner).
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2011 Hal Brodigan
1
+ Copyright (c) 2010-2013 Hal Brodigan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Digest CRC
2
2
 
3
- * [Source](http://github.com/postmodern/digest-crc)
4
- * [Issues](http://github.com/postmodern/digest-crc/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-2011 Hal Brodigan
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 'ore-tasks', '~> 0.4'
6
- require 'ore/tasks'
5
+ gem 'rubygems-tasks', '~> 0.1'
6
+ require 'rubygems/tasks'
7
7
 
8
- Ore::Tasks.new
8
+ Gem::Tasks.new
9
9
  rescue LoadError => e
10
10
  warn e.message
11
- warn "Run `gem install ore-tasks` to install 'ore/tasks'."
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.6.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 |gemspec|
6
- files = if File.directory?('.git')
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
- filter_files = lambda { |paths|
17
- case paths
18
- when Array
19
- (files & paths)
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
- gemspec.email = metadata['email']
66
- gemspec.homepage = metadata['homepage']
13
+ require 'digest/crc/version'
14
+ Digest::Crc::VERSION
15
+ end
67
16
 
68
- case metadata['require_paths']
69
- when Array
70
- gemspec.require_paths = metadata['require_paths']
71
- when String
72
- gemspec.require_path = metadata['require_paths']
73
- end
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
- gemspec.files = filter_files[metadata['files']]
24
+ glob = lambda { |patterns| gem.files & Dir[*patterns] }
76
25
 
77
- gemspec.executables = metadata['executables']
78
- gemspec.extensions = metadata['extensions']
26
+ gem.files = `git ls-files`.split($/)
27
+ gem.files = glob[gemspec['files']] if gemspec['files']
79
28
 
80
- if Gem::VERSION < '1.7.'
81
- gemspec.default_executable = gemspec.executables.first
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
- gemspec.test_files = filter_files[metadata['test_files']]
85
-
86
- unless gemspec.files.include?('.document')
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
- if gemspec.respond_to?(:required_rubygems_version=)
98
- gemspec.required_rubygems_version = metadata['required_ruby_version']
99
- end
38
+ gem.require_paths = Array(gemspec.fetch('require_paths') {
39
+ %w[ext lib].select { |dir| File.directory?(dir) }
40
+ })
100
41
 
101
- parse_versions = lambda { |versions|
102
- case versions
103
- when Array
104
- versions.map { |v| v.to_s }
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
- if metadata['dependencies']
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 metadata['runtime_dependencies']
117
- metadata['runtime_dependencies'].each do |name,versions|
118
- gemspec.add_runtime_dependency(name,parse_versions[versions])
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 metadata['development_dependencies']
123
- metadata['development_dependencies'].each do |name,versions|
124
- gemspec.add_development_dependency(name,parse_versions[versions])
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.3.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: http://github.com/postmodern/digest-crc
11
+ homepage: https://github.com/postmodern/digest-crc#readme
12
12
  has_yard: true
13
13
 
14
14
  development_dependencies:
15
- ore-tasks: ~> 0.4
15
+ rubygems-tasks: ~> 0.2
16
16
  rspec: ~> 2.4
17
- yard: ~> 0.6.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
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'crc_examples'
3
+ require 'digest/crc16_qt'
4
+
5
+ describe Digest::CRC16QT do
6
+ let(:string) { '1234567890' }
7
+ let(:expected) { '4b13' }
8
+
9
+ it_should_behave_like "CRC"
10
+ 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.3.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: 2011-09-24 00:00:00.000000000Z
12
+ date: 2013-02-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: ore-tasks
16
- requirement: &22462380 !ruby/object:Gem::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.4'
21
+ version: '0.2'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *22462380
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: &22461360 !ruby/object:Gem::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: *22461360
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: &22459440 !ruby/object:Gem::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.6.0
53
+ version: '0.8'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *22459440
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: http://github.com/postmodern/digest-crc
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.10
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: []