rfid-usb-gom-sensor 0.1.3 → 0.1.4

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -81,6 +81,7 @@ module RfidUsbGomSensor
81
81
  Defaults = {
82
82
  :device => "/dev/ttyUSB0",
83
83
  :baudrate => 9600,
84
+ :hex_id => false,
84
85
  }
85
86
 
86
87
  include OAttr
@@ -98,6 +99,10 @@ module RfidUsbGomSensor
98
99
  @gom_tags = find_tags
99
100
  end
100
101
 
102
+ def hex_id
103
+ @hex_id ||= @options[:hex_id]
104
+ end
105
+
101
106
  def find_tags
102
107
  tag_node = X::Entry.find "#{@path}/tags"
103
108
  #puts "-->#{tag_node.inspect}<---"
@@ -151,18 +156,24 @@ module RfidUsbGomSensor
151
156
  # 11 BCC XOR[1..10]
152
157
  # 12 ETX 0x03
153
158
  #
154
- def decode blk
159
+ def decode blk, hex_id = false
155
160
  #validate
156
161
  rec = (blk.unpack 'c2Qc*')
157
- id = rec[2]
158
- rec[2] = "0x#{([id].pack 'Q').unpack 'H*'}"
162
+ if hex_id
163
+ id = rec[2]
164
+ rec[2] = "0x#{([id].pack 'Q').unpack 'H*'}"
165
+ end
159
166
  expected = rec[4]
160
- cc = (blk[1..10].unpack "C*").inject(0) {|cc, c| cc^c}
167
+ cc = (calc_checksum blk[1..10]) # (blk[1..10].unpack "C*").inject(0) {|cc, c| cc^c}
161
168
  (cc == expected) or (raise_broken_read cc, expected, blk)
162
169
  #checksum blk[1..10], rec[4]
163
170
  #puts "-#{rec.inspect}-"
164
171
  rec
165
172
  end
173
+
174
+ def calc_checksum blk
175
+ (blk.unpack "C*").inject(0) {|cc, c| cc^c}
176
+ end
166
177
  end
167
178
 
168
179
  def detect
@@ -210,7 +221,7 @@ module RfidUsbGomSensor
210
221
 
211
222
  def next_tag
212
223
  (blk = @sp.read(13))
213
- stx, adx, uid, err, bcc, etx = (Node.decode blk)
224
+ stx, adx, uid, err, bcc, etx = (Node.decode blk, hex_id)
214
225
  uid
215
226
  end
216
227
  end
@@ -22,7 +22,7 @@ describe RfidUsbGomSensor::Node do
22
22
 
23
23
  it "should calc a xor checksum" do
24
24
  buf = [0x01, 0x02, 0x04, 0x08].pack "c*"
25
- lambda { Node.checksum buf, 0x0f }.should_not raise_error
25
+ lambda { Node.calc_checksum buf }.should_not raise_error
26
26
  end
27
27
 
28
28
  describe "with a node it" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rfid-usb-gom-sensor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - art+com/dirk luesebrink
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-08 00:00:00 +01:00
12
+ date: 2010-01-11 00:00:00 +01:00
13
13
  default_executable: rfid-usb-gom-sensor
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency