rfid-usb-gom-sensor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.mkd +18 -0
- data/Rakefile +59 -0
- data/VERSION +1 -0
- data/bin/rfid-usb-gom-sensor.rb +43 -0
- data/lib/rfid-usb-gom-sensor.rb +3 -0
- data/lib/rfid-usb-gom-sensor/node.rb +108 -0
- data/lib/rfid_usb_reader.rb +29 -0
- data/spec/rfid-usb-gom-sensor/node_spec.rb +57 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +45 -0
- metadata +98 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 dirk luesebrink
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.mkd
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= rfid-usb-gom-sensor
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 art+com/dirk luesebrink. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rfid-usb-gom-sensor"
|
8
|
+
gem.summary = %Q{USB RFID to GOM sensor node gateway}
|
9
|
+
gem.description = %Q{
|
10
|
+
As an alternative to the gesture driven content selection on the wall
|
11
|
+
guests may use an tablet-PC version of the content load application.
|
12
|
+
After content selection the android handset must by adssociated with
|
13
|
+
the selection for which the tablet PC has an USB RFID sensor installed.
|
14
|
+
This gem now implements the RFID GOM sensor node mapping code which runs
|
15
|
+
on the tablet PC.
|
16
|
+
}.gsub /\n\n/, ''
|
17
|
+
gem.email = "dirk.luesebrink@gmail.com"
|
18
|
+
gem.homepage = "http://github.com/crux/rfid-usb-gom-sensor"
|
19
|
+
gem.authors = ["art+com/dirk luesebrink"]
|
20
|
+
|
21
|
+
gem.add_runtime_dependency "ruby-serialport"
|
22
|
+
gem.add_runtime_dependency "gom-script"
|
23
|
+
|
24
|
+
gem.add_development_dependency "rspec"
|
25
|
+
end
|
26
|
+
Jeweler::GemcutterTasks.new
|
27
|
+
rescue LoadError
|
28
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
29
|
+
end
|
30
|
+
|
31
|
+
require 'spec/rake/spectask'
|
32
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
33
|
+
spec.libs << 'lib' << 'spec'
|
34
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
35
|
+
end
|
36
|
+
|
37
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
38
|
+
spec.libs << 'lib' << 'spec'
|
39
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
40
|
+
spec.rcov = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :spec => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :spec
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
if File.exist?('VERSION')
|
50
|
+
version = File.read('VERSION')
|
51
|
+
else
|
52
|
+
version = ""
|
53
|
+
end
|
54
|
+
|
55
|
+
rdoc.rdoc_dir = 'rdoc'
|
56
|
+
rdoc.title = "rfid-usb-gom-sensor #{version}"
|
57
|
+
rdoc.rdoc_files.include('README*')
|
58
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
59
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'applix'
|
5
|
+
|
6
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
7
|
+
require 'rfid-usb-gom-sensor'
|
8
|
+
|
9
|
+
#Thread.abort_on_exception = true
|
10
|
+
$stderr.sync = true
|
11
|
+
$stdout.sync = true
|
12
|
+
|
13
|
+
class Usage < ArgumentError; end
|
14
|
+
|
15
|
+
def main argv
|
16
|
+
options = Hash.from_argv argv
|
17
|
+
args = (options.delete :args)
|
18
|
+
#options[:callback_port] ||= 32119
|
19
|
+
|
20
|
+
sensor_url = args.shift
|
21
|
+
sensor_url or (raise Usage, "no <sensor_url>")
|
22
|
+
puts " -- starting RFID sensor: #{Time.now}"
|
23
|
+
|
24
|
+
daemon = Gom::Remote::Daemon.new(sensor_url, options) do |daemon, _|
|
25
|
+
daemon.check_in
|
26
|
+
end
|
27
|
+
sensor = RfidUsbGomSensor::Node.new daemon.service_path, options
|
28
|
+
sensor.preroll
|
29
|
+
daemon.forever { sensor.detect }
|
30
|
+
|
31
|
+
rescue Usage => e
|
32
|
+
puts <<-TXT
|
33
|
+
|
34
|
+
usage: #{__FILE__} <GOM Sensor URL>
|
35
|
+
|
36
|
+
## #{e}
|
37
|
+
TXT
|
38
|
+
rescue => e
|
39
|
+
puts " ## #{e}\n -> #{e.backtrace.join "\n "}"
|
40
|
+
end
|
41
|
+
|
42
|
+
main ARGV
|
43
|
+
# vim: syntax=ruby
|
@@ -0,0 +1,108 @@
|
|
1
|
+
begin
|
2
|
+
Kernel::require 'serialport'
|
3
|
+
rescue Exception
|
4
|
+
require 'serialport'
|
5
|
+
end
|
6
|
+
|
7
|
+
module RfidUsbGomSensor
|
8
|
+
class Node < Gom::Remote::Entry
|
9
|
+
|
10
|
+
Defaults = {
|
11
|
+
:device => "/dev/ttyUSB0",
|
12
|
+
:baudrate => 9600,
|
13
|
+
}
|
14
|
+
|
15
|
+
include OAttr
|
16
|
+
oattr :device, :baudrate
|
17
|
+
|
18
|
+
def initialize path, options = {}
|
19
|
+
@path = path
|
20
|
+
@options = Defaults.merge(gnode @path).merge(options)
|
21
|
+
puts "options: #{@options.inspect}"
|
22
|
+
|
23
|
+
@ip = connection.callback_server.host
|
24
|
+
@sp = SerialPort.new device, baudrate
|
25
|
+
end
|
26
|
+
|
27
|
+
# reader commands
|
28
|
+
STX = 0x02
|
29
|
+
ETX = 0x03
|
30
|
+
GetInfo = [STX, 0x01, 0x47, 0x46, ETX].pack "c*"
|
31
|
+
GoContinuous = [STX, 0x01, 0x43, 0x04, 0x46, ETX].pack "c*"
|
32
|
+
|
33
|
+
def preroll
|
34
|
+
#info = [0x02, 0x01, 0x47, 0x46, 0x03]
|
35
|
+
#info.each {|c| @sp.putc c.to_i}
|
36
|
+
@sp.puts GetInfo
|
37
|
+
2.times {@sp.getc}
|
38
|
+
print "Detected reader: "
|
39
|
+
37.times {putc(@sp.getc)}
|
40
|
+
print "\n"
|
41
|
+
6.times {@sp.getc}
|
42
|
+
|
43
|
+
#continuous = [0x02, 0x01, 0x43, 0x04, 0x46, 0x03]
|
44
|
+
#continuous.each {|c| @sp.putc c.to_i}
|
45
|
+
@sp.puts GoContinuous
|
46
|
+
6.times {@sp.getc}
|
47
|
+
end
|
48
|
+
|
49
|
+
class << self
|
50
|
+
def checksum buf, expected
|
51
|
+
cc = (buf.unpack "C*").inject(0) { |cc, c| cc ^ c }
|
52
|
+
(cc != expected) and raise "checksum missmatch: #{cc} != #{expected}"
|
53
|
+
cc
|
54
|
+
end
|
55
|
+
|
56
|
+
def decode blk
|
57
|
+
#validate
|
58
|
+
rec = (blk.unpack 'c2Qc*')
|
59
|
+
checksum blk[1..10], rec[4]
|
60
|
+
puts "-#{rec.inspect}-"
|
61
|
+
rec
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def detect
|
66
|
+
buf = ""
|
67
|
+
loop do
|
68
|
+
buf << (blk = @sp.read(13))
|
69
|
+
stx, adx, uid, err, bcc, etx = (Node.decode buf)
|
70
|
+
buf = ""
|
71
|
+
end
|
72
|
+
rescue SignalException => e
|
73
|
+
:stop # if (e.signm == "INT")
|
74
|
+
end
|
75
|
+
|
76
|
+
def _detect
|
77
|
+
=begin
|
78
|
+
Format:
|
79
|
+
0 STX 0x02
|
80
|
+
1 ADR 0x01
|
81
|
+
2 UID7 0xE0
|
82
|
+
3 UID6
|
83
|
+
4 UID5
|
84
|
+
5 UID4
|
85
|
+
6 UID3
|
86
|
+
7 UID2
|
87
|
+
8 UID1
|
88
|
+
9 UID0
|
89
|
+
10 ERR 0x00
|
90
|
+
11 BCC XOR[1..10]
|
91
|
+
12 ETX 0x03
|
92
|
+
=end
|
93
|
+
while @sp.getc!=0x02 do end # STX
|
94
|
+
while @sp.getc!=0x01 do end # ADR
|
95
|
+
v = 0
|
96
|
+
0.upto(7) do |i|
|
97
|
+
v += @sp.getc*2**((7-i)*8) # UID
|
98
|
+
end
|
99
|
+
while @sp.getc!=0x00 do end # ERR
|
100
|
+
puts "Detected tag: #{v}"
|
101
|
+
connection.write "#{@path}/tags/#{v}:sensor_ip", @ip
|
102
|
+
puts "-#{@sp.getc}-" # BCC
|
103
|
+
while @sp.getc!=0x03 do end # ETX
|
104
|
+
rescue SignalException => e
|
105
|
+
:stop # if (e.signm == "INT")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'serialport'
|
3
|
+
#require 'rest_fs/client'
|
4
|
+
|
5
|
+
sp=SerialPort.new "/dev/ttyUSB0", 9600
|
6
|
+
#r=RestFs::Client.new
|
7
|
+
|
8
|
+
info=[0x02, 0x01, 0x47, 0x46, 0x03]
|
9
|
+
info.each {|c| sp.putc c.to_i}
|
10
|
+
2.times {sp.getc}
|
11
|
+
print "Detected reader: "
|
12
|
+
37.times {putc(sp.getc)}
|
13
|
+
print "\n"
|
14
|
+
6.times {sp.getc}
|
15
|
+
|
16
|
+
continuous=[0x02, 0x01, 0x43, 0x04, 0x46, 0x03]
|
17
|
+
continuous.each {|c| sp.putc c.to_i}
|
18
|
+
6.times {sp.getc}
|
19
|
+
|
20
|
+
while true
|
21
|
+
2.times {sp.getc}
|
22
|
+
v=0
|
23
|
+
0.upto(7) do |i|
|
24
|
+
v+=sp.getc*2**((7-i)*8)
|
25
|
+
end
|
26
|
+
print "Detected tag: ", v, "\n"
|
27
|
+
#r.create!("/sensors/rfid-readers/usb/tags/#{v}")
|
28
|
+
3.times {sp.getc}
|
29
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/../spec_helper'
|
2
|
+
|
3
|
+
include RfidUsbGomSensor
|
4
|
+
|
5
|
+
describe RfidUsbGomSensor::Node do
|
6
|
+
it "should find the class at least" do
|
7
|
+
Node.should_not == nil
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should fail on a wronk checksum" do
|
11
|
+
ref_rec = [2, 1, 12616128551217792992, 0, 77, 3]
|
12
|
+
blk = ref_rec.pack "ccQccc"
|
13
|
+
lambda { rec = (Node.decode blk) }.should raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should decode a record" do
|
17
|
+
ref_rec = [2, 1, 12616128551217792992, 0, 49, 3]
|
18
|
+
blk = ref_rec.pack "ccQccc"
|
19
|
+
rec = (Node.decode blk)
|
20
|
+
rec.should == ref_rec
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should calc a xor checksum" do
|
24
|
+
buf = [0x01, 0x02, 0x04, 0x08].pack "c*"
|
25
|
+
lambda { Node.checksum buf, 0x0f }.should_not raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "with a node it" do
|
29
|
+
RFID_NODE = <<-JSON
|
30
|
+
{
|
31
|
+
"node": {
|
32
|
+
"uri": "/sensors/rfid-readers/preshow-tablet-1",
|
33
|
+
"entries": [
|
34
|
+
{
|
35
|
+
"attribute": {
|
36
|
+
"name": "device",
|
37
|
+
"node": "/sensors/rfid-readers/preshow-tablet-1",
|
38
|
+
"value": "/dev/ttyS3",
|
39
|
+
"type": "string"
|
40
|
+
}
|
41
|
+
}
|
42
|
+
]
|
43
|
+
}
|
44
|
+
}
|
45
|
+
JSON
|
46
|
+
|
47
|
+
before :each do
|
48
|
+
node_path = "/sensor/rfid/usb-reader"
|
49
|
+
$c.should_receive(:read).with("#{node_path}.json").and_return(RFID_NODE)
|
50
|
+
@sensor = (Node.new node_path)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should pull its config from GOM" do
|
54
|
+
@sensor.device.should == "/dev/ttyS3"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--backtrace --debugger
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# figure out where we are being loaded from
|
2
|
+
if $LOADED_FEATURES.grep(/spec\/spec_helper\.rb/).any?
|
3
|
+
begin
|
4
|
+
raise "foo"
|
5
|
+
rescue => e
|
6
|
+
puts <<-MSG
|
7
|
+
===================================================
|
8
|
+
It looks like spec_helper.rb has been loaded
|
9
|
+
multiple times. Normalize the require to:
|
10
|
+
|
11
|
+
require "spec/spec_helper"
|
12
|
+
|
13
|
+
Things like File.join and File.expand_path will
|
14
|
+
cause it to be loaded multiple times.
|
15
|
+
|
16
|
+
Loaded this time from:
|
17
|
+
|
18
|
+
#{e.backtrace.join("\n ")}
|
19
|
+
===================================================
|
20
|
+
MSG
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
25
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
26
|
+
require 'spec'
|
27
|
+
require 'spec/autorun'
|
28
|
+
require 'fakeweb'
|
29
|
+
require 'rfid-usb-gom-sensor'
|
30
|
+
|
31
|
+
Spec::Runner.configure do |config|
|
32
|
+
config.before :each do
|
33
|
+
FakeWeb.register_uri(
|
34
|
+
:get, "http://gom:345/gom/config/connection.txt",
|
35
|
+
:body => "client_ip: 10.0.0.23"
|
36
|
+
)
|
37
|
+
$c = (Gom::Remote::Connection.new "http://gom:345/sensor/rfid/usb-reader")
|
38
|
+
|
39
|
+
$sp = Object.new
|
40
|
+
SerialPort.stub!(:new).and_return($sp)
|
41
|
+
end
|
42
|
+
|
43
|
+
config.after :each do
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rfid-usb-gom-sensor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- art+com/dirk luesebrink
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-30 00:00:00 +01:00
|
13
|
+
default_executable: rfid-usb-gom-sensor.rb
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ruby-serialport
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: gom-script
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
description: "\n As an alternative to the gesture driven content selection on the wall\n guests may use an tablet-PC version of the content load application.\n After content selection the android handset must by adssociated with\n the selection for which the tablet PC has an USB RFID sensor installed.\n This gem now implements the RFID GOM sensor node mapping code which runs\n on the tablet PC.\n "
|
46
|
+
email: dirk.luesebrink@gmail.com
|
47
|
+
executables:
|
48
|
+
- rfid-usb-gom-sensor.rb
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE
|
53
|
+
- README.mkd
|
54
|
+
files:
|
55
|
+
- .document
|
56
|
+
- .gitignore
|
57
|
+
- LICENSE
|
58
|
+
- README.mkd
|
59
|
+
- Rakefile
|
60
|
+
- VERSION
|
61
|
+
- bin/rfid-usb-gom-sensor.rb
|
62
|
+
- lib/rfid-usb-gom-sensor.rb
|
63
|
+
- lib/rfid-usb-gom-sensor/node.rb
|
64
|
+
- lib/rfid_usb_reader.rb
|
65
|
+
- spec/rfid-usb-gom-sensor/node_spec.rb
|
66
|
+
- spec/spec.opts
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: http://github.com/crux/rfid-usb-gom-sensor
|
70
|
+
licenses: []
|
71
|
+
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options:
|
74
|
+
- --charset=UTF-8
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: "0"
|
82
|
+
version:
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: "0"
|
88
|
+
version:
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.3.5
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: USB RFID to GOM sensor node gateway
|
96
|
+
test_files:
|
97
|
+
- spec/rfid-usb-gom-sensor/node_spec.rb
|
98
|
+
- spec/spec_helper.rb
|