tag-it 0.1.0
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/.bundle/config +3 -0
- data/.document +5 -0
- data/.gitignore +1 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +28 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/lib/tag_it/tag_tracker.rb +78 -0
- data/lib/tag_it.rb +12 -0
- data/test/helper.rb +12 -0
- data/test/mock_serial_port.rb +34 -0
- data/test/test_tag_tracker.rb +60 -0
- metadata +96 -0
data/.bundle/config
ADDED
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-serialport/**/*.*
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
gemcutter (0.6.1)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.4.0)
|
7
|
+
gemcutter (>= 0.1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rubyforge (>= 2.0.0)
|
10
|
+
json_pure (1.4.6)
|
11
|
+
mocha (0.9.8)
|
12
|
+
rake
|
13
|
+
rake (0.8.7)
|
14
|
+
ruby-serialport (0.7.0)
|
15
|
+
rubyforge (2.0.4)
|
16
|
+
json_pure (>= 1.1.7)
|
17
|
+
test-unit (2.1.1)
|
18
|
+
thoughtbot-shoulda (2.11.1)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
jeweler
|
25
|
+
mocha
|
26
|
+
ruby-serialport
|
27
|
+
test-unit
|
28
|
+
thoughtbot-shoulda
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 evizitei
|
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.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= tag-it
|
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 bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 evizitei. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "tag-it"
|
9
|
+
gem.summary = %Q{interaction with RFID receiver through a serial port.}
|
10
|
+
gem.description = %Q{Interacting with RFID receivers through serial ports is not much fun. This makes it a little better. tag-it provides a class that will monitor a serial port for you, and will dispatch events through ruby's standard "observer" functionality when a tag comes into range and leaves.}
|
11
|
+
gem.email = "ethan.vizitei@gmail.com"
|
12
|
+
gem.homepage = "http://github.com/evizitei/tag-it"
|
13
|
+
gem.authors = ["evizitei"]
|
14
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "tag-it #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require "observer"
|
2
|
+
require "timeout"
|
3
|
+
|
4
|
+
module TagIt
|
5
|
+
class TagTracker
|
6
|
+
include Observable
|
7
|
+
include Timeout
|
8
|
+
|
9
|
+
def initialize(port)
|
10
|
+
@port = port
|
11
|
+
@tag_map ||= {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def start!
|
15
|
+
char = nil
|
16
|
+
tag_name = ""
|
17
|
+
|
18
|
+
#dont start reporting until after the first space,
|
19
|
+
#so we don't have to deal with partial tagnames
|
20
|
+
clean_start_flag = false
|
21
|
+
|
22
|
+
#128 is the stop character we're adding so the tests can cutoff the loop.
|
23
|
+
#Production will loop infinitely until shutdown
|
24
|
+
while char != 128
|
25
|
+
begin
|
26
|
+
# Don't take longer than 3 seconds to find a char, or there aren't any
|
27
|
+
Timeout::timeout(3) do
|
28
|
+
char = @port.getc
|
29
|
+
end
|
30
|
+
if char == 32
|
31
|
+
flush_tag!(tag_name) if clean_start_flag #don't send until after first space
|
32
|
+
depart_dormant_tags!
|
33
|
+
tag_name = ""
|
34
|
+
clean_start_flag = true #here's a space, start sending tags
|
35
|
+
else
|
36
|
+
tag_name = "#{tag_name}#{char.chr}"
|
37
|
+
end
|
38
|
+
rescue Timeout::Error
|
39
|
+
depart_all_tags!
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def flush_tag!(tag_name)
|
45
|
+
tag_name,strength = split_tag_data(tag_name)
|
46
|
+
if @tag_map[tag_name].nil?
|
47
|
+
changed
|
48
|
+
notify_observers(tag_name,strength,:tag_arrived)
|
49
|
+
end
|
50
|
+
@tag_map[tag_name] = Time.now
|
51
|
+
end
|
52
|
+
|
53
|
+
def depart_all_tags!
|
54
|
+
@tag_map.keys.each do |tag_name|
|
55
|
+
changed
|
56
|
+
notify_observers(tag_name,0,:tag_departed)
|
57
|
+
end
|
58
|
+
@tag_map.clear
|
59
|
+
end
|
60
|
+
|
61
|
+
def depart_dormant_tags!
|
62
|
+
tags_to_depart = []
|
63
|
+
@tag_map.each do |tag_name,last_time|
|
64
|
+
tags_to_depart << tag_name if((Time.now - last_time) > 8)
|
65
|
+
end
|
66
|
+
|
67
|
+
tags_to_depart.each do |tag_name|
|
68
|
+
changed
|
69
|
+
notify_observers(tag_name,0,:tag_departed)
|
70
|
+
@tag_map.delete(tag_name)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def split_tag_data(tag_name)
|
75
|
+
[tag_name[0,4],tag_name[4,tag_name.size - 4].to_i]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/tag_it.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'serialport'
|
4
|
+
require 'tag_it/tag_tracker'
|
5
|
+
|
6
|
+
# port = SerialPort.new("/dev/tty.usbserial",:baud=>9600,:data_bits=>8,:stop_bits=>1)
|
7
|
+
#
|
8
|
+
# count = 0
|
9
|
+
# while count < 1000
|
10
|
+
# printf("%c",port.getc)
|
11
|
+
# count += 1
|
12
|
+
# end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'mocha'
|
5
|
+
require 'mock_serial_port'
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
|
+
require 'tag_it'
|
10
|
+
|
11
|
+
class Test::Unit::TestCase
|
12
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class MockSerialPort
|
2
|
+
def initialize(data)
|
3
|
+
@data = []
|
4
|
+
data.each_byte{|b| @data << b}
|
5
|
+
@data << 128
|
6
|
+
end
|
7
|
+
|
8
|
+
def getc
|
9
|
+
char = @data.delete_at 0
|
10
|
+
char_hook(char)
|
11
|
+
char = 128 if char.nil?
|
12
|
+
return char
|
13
|
+
end
|
14
|
+
|
15
|
+
def char_hook(char)
|
16
|
+
#do nothing
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class TimeoutSerialPort < MockSerialPort
|
21
|
+
def char_hook(char)
|
22
|
+
if char == 128
|
23
|
+
sleep(5)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class PacingSerialPort < MockSerialPort
|
29
|
+
def char_hook(char)
|
30
|
+
if char == 32
|
31
|
+
sleep(1)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestTagTracker < Test::Unit::TestCase
|
4
|
+
context "TagTracker" do
|
5
|
+
should "report full tag names" do
|
6
|
+
data = " 1nri85 1nwP79 "
|
7
|
+
watcher = TagObserver.new
|
8
|
+
watcher.expects(:update).with("1nri",85,:tag_arrived).times(1)
|
9
|
+
watcher.expects(:update).with("1nwP",79,:tag_arrived).times(1)
|
10
|
+
check_data_extract(data,watcher)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "only report tags after the first space" do
|
14
|
+
data = "P79 1m2342 1ksR81 "
|
15
|
+
watcher = TagObserver.new
|
16
|
+
watcher.expects(:update).with("1m23",42,:tag_arrived).times(1)
|
17
|
+
watcher.expects(:update).with("1ksR",81,:tag_arrived).times(1)
|
18
|
+
check_data_extract(data,watcher)
|
19
|
+
end
|
20
|
+
|
21
|
+
should "only report each individual tag the first time" do
|
22
|
+
data = " 1nri85 1nwP79 1nri85 1nwP79 1nri85 1nwP79 "
|
23
|
+
watcher = TagObserver.new
|
24
|
+
watcher.expects(:update).with("1nri",85,:tag_arrived).times(1)
|
25
|
+
watcher.expects(:update).with("1nwP",79,:tag_arrived).times(1)
|
26
|
+
check_data_extract(data,watcher)
|
27
|
+
end
|
28
|
+
|
29
|
+
should "clear send out departing events when no tags in range" do
|
30
|
+
data = " 1nri85 1nwP79 1nri85 1nwP79 1nri85 1nwP79 "
|
31
|
+
watcher = TagObserver.new
|
32
|
+
watcher.expects(:update).with("1nri",85,:tag_arrived).times(1)
|
33
|
+
watcher.expects(:update).with("1nwP",79,:tag_arrived).times(1)
|
34
|
+
watcher.expects(:update).with("1nri",0,:tag_departed).times(1)
|
35
|
+
watcher.expects(:update).with("1nwP",0,:tag_departed).times(1)
|
36
|
+
check_data_extract(data,watcher,TimeoutSerialPort)
|
37
|
+
end
|
38
|
+
|
39
|
+
should "dispatch a departing event when one tag leaves" do
|
40
|
+
data = " 1nri85 1nwP79 1nwP79 1nwP79 1nwP79 1nwP79 1nwP79 1nwP79 1nwP79 1nwP79 "
|
41
|
+
watcher = TagObserver.new
|
42
|
+
watcher.expects(:update).with("1nri",85,:tag_arrived).times(1)
|
43
|
+
watcher.expects(:update).with("1nwP",79,:tag_arrived).times(1)
|
44
|
+
watcher.expects(:update).with("1nri",0,:tag_departed).times(1)
|
45
|
+
check_data_extract(data,watcher,PacingSerialPort)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def check_data_extract(data,watcher,port_mocker = MockSerialPort)
|
50
|
+
port = port_mocker.new(data)
|
51
|
+
tracker = TagIt::TagTracker.new(port)
|
52
|
+
tracker.add_observer(watcher)
|
53
|
+
tracker.start!
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class TagObserver
|
58
|
+
def update(tag_id,strength,event)
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tag-it
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- evizitei
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-17 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
name: thoughtbot-shoulda
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
version: "0"
|
34
|
+
requirement: *id001
|
35
|
+
description: Interacting with RFID receivers through serial ports is not much fun. This makes it a little better. tag-it provides a class that will monitor a serial port for you, and will dispatch events through ruby's standard "observer" functionality when a tag comes into range and leaves.
|
36
|
+
email: ethan.vizitei@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .bundle/config
|
46
|
+
- .document
|
47
|
+
- .gitignore
|
48
|
+
- Gemfile
|
49
|
+
- Gemfile.lock
|
50
|
+
- LICENSE
|
51
|
+
- README.rdoc
|
52
|
+
- Rakefile
|
53
|
+
- VERSION
|
54
|
+
- lib/tag_it.rb
|
55
|
+
- lib/tag_it/tag_tracker.rb
|
56
|
+
- test/helper.rb
|
57
|
+
- test/mock_serial_port.rb
|
58
|
+
- test/test_tag_tracker.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/evizitei/tag-it
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options:
|
65
|
+
- --charset=UTF-8
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.3.7
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: interaction with RFID receiver through a serial port.
|
93
|
+
test_files:
|
94
|
+
- test/helper.rb
|
95
|
+
- test/mock_serial_port.rb
|
96
|
+
- test/test_tag_tracker.rb
|