tag-it 0.2.2 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +9 -1
- data/VERSION +1 -1
- data/lib/tag_it.rb +6 -1
- data/lib/tag_it/monitor.rb +45 -0
- data/lib/tag_it/tag_snapshot.rb +17 -0
- data/lib/tag_it/tag_tracker.rb +9 -37
- data/pkg/tag-it-0.2.2.gem +0 -0
- data/tag-it.gemspec +7 -2
- data/test/test_tag_snapshot.rb +22 -0
- metadata +15 -10
data/README.rdoc
CHANGED
@@ -47,10 +47,18 @@ And then attaching it to a tag-it tag_tracker like this:
|
|
47
47
|
tracher.add_observer(watcher)
|
48
48
|
tracker.start!
|
49
49
|
|
50
|
-
the tracker will run
|
50
|
+
the tracker will run indefinitely, pulling in tag ids as they come into range and leave the area, and dispatch the necessary events. It also will dispatch a "pulse" event every 3 minutes so you know that the client is still running. Right now there are 3 events -- :tag_arrived when the tag comes into range, :tag_departed when it leaves, and the :pulse event every three minutes. The other parameters to the update method are the tag id ("1nrw") and the Relative Signal Strength (an integer: 34, 86, etc) indicating how close to the source the tag is.
|
51
51
|
|
52
52
|
ATTENTION!: In the "pulse" event, the tag parameter will actually be an array of currently in-range tags
|
53
53
|
|
54
|
+
As of version 0.3.0, you don't have to use the tracker. If you just want to fetch a quick snapshot of all tags currently in range, the TagIt TagSnapshot will do the trick:
|
55
|
+
|
56
|
+
require "tag_it"
|
57
|
+
port = SerialPort.new("/dev/tty.yourport",{:baud=>9600})
|
58
|
+
snapshot = TagIt::TagSnapshot.new(port)
|
59
|
+
tags = snapshot.shoot!
|
60
|
+
# tags => ["1nri","1okD","1nrP"]
|
61
|
+
|
54
62
|
Happy Tagging!
|
55
63
|
|
56
64
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.1
|
data/lib/tag_it.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
3
|
require 'serialport'
|
4
|
-
|
4
|
+
|
5
|
+
module TagIt
|
6
|
+
autoload :TagTracker,"tag_it/tag_tracker.rb"
|
7
|
+
autoload :TagSnapshot,"tag_it/tag_snapshot.rb"
|
8
|
+
autoload :Monitor,"tag_it/monitor.rb"
|
9
|
+
end
|
5
10
|
|
6
11
|
# port = SerialPort.new("/dev/tty.usbserial",:baud=>9600,:data_bits=>8,:stop_bits=>1)
|
7
12
|
#
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module TagIt
|
2
|
+
class Monitor
|
3
|
+
attr_accessor :port
|
4
|
+
|
5
|
+
def initialize(local_port)
|
6
|
+
self.port = local_port
|
7
|
+
@last_pulse = Time.now
|
8
|
+
end
|
9
|
+
|
10
|
+
def monitor_tags
|
11
|
+
char = nil
|
12
|
+
tag_name = ""
|
13
|
+
#dont start reporting until after the first space,
|
14
|
+
#so we don't have to deal with partial tagnames
|
15
|
+
clean_start_flag = false
|
16
|
+
|
17
|
+
#128 is the stop character we're adding so the tests can cutoff the loop.
|
18
|
+
while char != 128
|
19
|
+
# Don't take longer than 3 seconds to find a char, or there aren't any
|
20
|
+
Timeout::timeout(3) do
|
21
|
+
char = @port.getc
|
22
|
+
end
|
23
|
+
if char == 32
|
24
|
+
name,strength = split_tag_data(tag_name)
|
25
|
+
yield(name,strength) if clean_start_flag
|
26
|
+
tag_name = ""
|
27
|
+
clean_start_flag = true #here's a space, start sending tags
|
28
|
+
else
|
29
|
+
tag_name = "#{tag_name}#{char.chr}"
|
30
|
+
end
|
31
|
+
if ((Time.now - 180) > @last_pulse)
|
32
|
+
self.pulse!
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def split_tag_data(tag_name)
|
38
|
+
[tag_name[0,4],tag_name[4,tag_name.size - 4].to_i]
|
39
|
+
end
|
40
|
+
|
41
|
+
def pulse!
|
42
|
+
#do nothing, you can override in a subclass if you want to fire an event or something
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module TagIt
|
2
|
+
class TagSnapshot < TagIt::Monitor
|
3
|
+
|
4
|
+
def shoot!
|
5
|
+
tags = []
|
6
|
+
begin
|
7
|
+
monitor_tags do |tag_name,strength|
|
8
|
+
return tags if !tags.index(tag_name).nil?
|
9
|
+
tags << tag_name
|
10
|
+
end
|
11
|
+
rescue Timeout::Error
|
12
|
+
#do nothing, let tags return
|
13
|
+
end
|
14
|
+
tags
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/tag_it/tag_tracker.rb
CHANGED
@@ -2,51 +2,27 @@ require "observer"
|
|
2
2
|
require "timeout"
|
3
3
|
|
4
4
|
module TagIt
|
5
|
-
class TagTracker
|
5
|
+
class TagTracker < TagIt::Monitor
|
6
6
|
include Observable
|
7
7
|
include Timeout
|
8
8
|
|
9
9
|
def initialize(port)
|
10
|
-
|
10
|
+
super(port)
|
11
11
|
@tag_map ||= {}
|
12
|
-
@last_pulse = Time.now
|
13
12
|
end
|
14
13
|
|
15
14
|
def start!
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
#so we don't have to deal with partial tagnames
|
21
|
-
clean_start_flag = false
|
22
|
-
|
23
|
-
#128 is the stop character we're adding so the tests can cutoff the loop.
|
24
|
-
#Production will loop infinitely until shutdown
|
25
|
-
while char != 128
|
26
|
-
begin
|
27
|
-
# Don't take longer than 3 seconds to find a char, or there aren't any
|
28
|
-
Timeout::timeout(3) do
|
29
|
-
char = @port.getc
|
30
|
-
end
|
31
|
-
if char == 32
|
32
|
-
flush_tag!(tag_name) if clean_start_flag #don't send until after first space
|
33
|
-
depart_dormant_tags!
|
34
|
-
tag_name = ""
|
35
|
-
clean_start_flag = true #here's a space, start sending tags
|
36
|
-
else
|
37
|
-
tag_name = "#{tag_name}#{char.chr}"
|
38
|
-
end
|
39
|
-
rescue Timeout::Error
|
40
|
-
depart_all_tags!
|
15
|
+
begin
|
16
|
+
monitor_tags do |tag_name,strength|
|
17
|
+
flush_tag!(tag_name,strength)
|
18
|
+
depart_dormant_tags!
|
41
19
|
end
|
42
|
-
|
43
|
-
|
44
|
-
end
|
20
|
+
rescue Timeout::Error
|
21
|
+
depart_all_tags!
|
45
22
|
end
|
46
23
|
end
|
47
24
|
|
48
|
-
def flush_tag!(tag_name)
|
49
|
-
tag_name,strength = split_tag_data(tag_name)
|
25
|
+
def flush_tag!(tag_name,strength)
|
50
26
|
if @tag_map[tag_name].nil?
|
51
27
|
changed
|
52
28
|
notify_observers(tag_name,strength,:tag_arrived)
|
@@ -75,10 +51,6 @@ module TagIt
|
|
75
51
|
end
|
76
52
|
end
|
77
53
|
|
78
|
-
def split_tag_data(tag_name)
|
79
|
-
[tag_name[0,4],tag_name[4,tag_name.size - 4].to_i]
|
80
|
-
end
|
81
|
-
|
82
54
|
def pulse!
|
83
55
|
changed
|
84
56
|
notify_observers(@tag_map.keys.sort,0,:pulse)
|
Binary file
|
data/tag-it.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{tag-it}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["evizitei"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-22}
|
13
13
|
s.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.}
|
14
14
|
s.email = %q{ethan.vizitei@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,12 +27,16 @@ Gem::Specification.new do |s|
|
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
29
|
"lib/tag_it.rb",
|
30
|
+
"lib/tag_it/monitor.rb",
|
31
|
+
"lib/tag_it/tag_snapshot.rb",
|
30
32
|
"lib/tag_it/tag_tracker.rb",
|
31
33
|
"pkg/tag-it-0.1.0.gem",
|
32
34
|
"pkg/tag-it-0.2.1.gem",
|
35
|
+
"pkg/tag-it-0.2.2.gem",
|
33
36
|
"tag-it.gemspec",
|
34
37
|
"test/helper.rb",
|
35
38
|
"test/mock_serial_port.rb",
|
39
|
+
"test/test_tag_snapshot.rb",
|
36
40
|
"test/test_tag_tracker.rb"
|
37
41
|
]
|
38
42
|
s.homepage = %q{http://github.com/evizitei/tag-it}
|
@@ -43,6 +47,7 @@ Gem::Specification.new do |s|
|
|
43
47
|
s.test_files = [
|
44
48
|
"test/helper.rb",
|
45
49
|
"test/mock_serial_port.rb",
|
50
|
+
"test/test_tag_snapshot.rb",
|
46
51
|
"test/test_tag_tracker.rb"
|
47
52
|
]
|
48
53
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestTagSnapshot < Test::Unit::TestCase
|
4
|
+
context "TagSnapshot" do
|
5
|
+
should "report all tag names in range" do
|
6
|
+
data = " 1nri85 1nwP79 1okD01 "
|
7
|
+
snapshot = TagIt::TagSnapshot.new(MockSerialPort.new(data))
|
8
|
+
assert_equal ["1nri","1nwP","1okD"],snapshot.shoot!
|
9
|
+
end
|
10
|
+
|
11
|
+
should "return on repeat" do
|
12
|
+
data = " 1nri85 1nwP79 1okD01 1nri72 1nwP79 1okD01 "
|
13
|
+
snapshot = TagIt::TagSnapshot.new(MockSerialPort.new(data))
|
14
|
+
assert_equal ["1nri","1nwP","1okD"],snapshot.shoot!
|
15
|
+
end
|
16
|
+
|
17
|
+
should "return empty if no tags" do
|
18
|
+
snapshot = TagIt::TagSnapshot.new(TimeoutSerialPort.new(""))
|
19
|
+
assert_equal [],snapshot.shoot!
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tag-it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- evizitei
|
@@ -15,12 +15,12 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-22 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
type: :development
|
23
22
|
prerelease: false
|
23
|
+
type: :development
|
24
24
|
name: thoughtbot-shoulda
|
25
25
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
26
|
none: false
|
@@ -33,8 +33,8 @@ dependencies:
|
|
33
33
|
version: "0"
|
34
34
|
requirement: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
type: :development
|
37
36
|
prerelease: false
|
37
|
+
type: :development
|
38
38
|
name: test-unit
|
39
39
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
@@ -47,8 +47,8 @@ dependencies:
|
|
47
47
|
version: "0"
|
48
48
|
requirement: *id002
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
|
-
type: :development
|
51
50
|
prerelease: false
|
51
|
+
type: :development
|
52
52
|
name: mocha
|
53
53
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
54
|
none: false
|
@@ -61,8 +61,8 @@ dependencies:
|
|
61
61
|
version: "0"
|
62
62
|
requirement: *id003
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
|
-
type: :development
|
65
64
|
prerelease: false
|
65
|
+
type: :development
|
66
66
|
name: timecop
|
67
67
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
68
68
|
none: false
|
@@ -75,8 +75,8 @@ dependencies:
|
|
75
75
|
version: "0"
|
76
76
|
requirement: *id004
|
77
77
|
- !ruby/object:Gem::Dependency
|
78
|
-
type: :runtime
|
79
78
|
prerelease: false
|
79
|
+
type: :runtime
|
80
80
|
name: ruby-serialport
|
81
81
|
version_requirements: &id005 !ruby/object:Gem::Requirement
|
82
82
|
none: false
|
@@ -108,12 +108,16 @@ files:
|
|
108
108
|
- Rakefile
|
109
109
|
- VERSION
|
110
110
|
- lib/tag_it.rb
|
111
|
+
- lib/tag_it/monitor.rb
|
112
|
+
- lib/tag_it/tag_snapshot.rb
|
111
113
|
- lib/tag_it/tag_tracker.rb
|
112
114
|
- pkg/tag-it-0.1.0.gem
|
113
115
|
- pkg/tag-it-0.2.1.gem
|
116
|
+
- pkg/tag-it-0.2.2.gem
|
114
117
|
- tag-it.gemspec
|
115
118
|
- test/helper.rb
|
116
119
|
- test/mock_serial_port.rb
|
120
|
+
- test/test_tag_snapshot.rb
|
117
121
|
- test/test_tag_tracker.rb
|
118
122
|
has_rdoc: true
|
119
123
|
homepage: http://github.com/evizitei/tag-it
|
@@ -152,4 +156,5 @@ summary: interaction with RFID receiver through a serial port.
|
|
152
156
|
test_files:
|
153
157
|
- test/helper.rb
|
154
158
|
- test/mock_serial_port.rb
|
159
|
+
- test/test_tag_snapshot.rb
|
155
160
|
- test/test_tag_tracker.rb
|