Class: Alien::AlienTag
- Inherits:
-
Object
- Object
- Alien::AlienTag
- Includes:
- Comparable
- Defined in:
- lib/alien/alientag.rb
Overview
A storage class for RFID tag data elements.
Instance Attribute Summary collapse
-
#ant ⇒ Object
Antenna on which the last read was made.
-
#count ⇒ Object
Number of times the tag has been read since discovery.
-
#disc ⇒ Object
Time of discovery.
-
#freq ⇒ Object
:nodoc:.
-
#id ⇒ Object
EPC code of the tag that was read.
-
#last ⇒ Object
Time of latest read.
-
#proto ⇒ Object
Protocol used to read the tag.
-
#rssi ⇒ Object
Returns the value of attribute rssi.
-
#speed ⇒ Object
Returns the value of attribute speed.
Instance Method Summary collapse
-
#<=>(s) ⇒ Object
The ‘spaceship’ operator allows us to compare tags for sorting, etc.
-
#create(taglist_entry) ⇒ Object
Try to parse a taglist entry into a set of Tag object variables.
-
#initialize(taglist_entry) ⇒ AlienTag
constructor
Populate the instance variables from a taglist entry string.
-
#inspect ⇒ Object
Return the contents of the tag object as a string (returns tag id as a string).
-
#tag ⇒ Object
(Deprecated) Returns tag id.
-
#tag=(val) ⇒ Object
(Deprecated) Sets tag id.
-
#to_s ⇒ Object
Returns a printable version of the tag object (returns tag id as a string).
-
#update(new_tag) ⇒ Object
Updates an existing tag object from the new one by incrementing the count and setting the new last time.
Constructor Details
#initialize(taglist_entry) ⇒ AlienTag
Populate the instance variables from a taglist entry string. The following field separators are supported in the taglist entry string:
'tag:', 'disc:', 'last:', 'count:', 'ant:', 'proto:', 'speed:', 'rssi:'
33 34 35 36 37 38 39 40 |
# File 'lib/alien/alientag.rb', line 33 def initialize(taglist_entry) @disc = @last = @last_last = 0 @ant = @count = @proto = @rssi = @speed = @freq = 0 @speed_smooth = @speed_last = 0 @pos_smooth = @pos_last = @pos_min = 0 create(taglist_entry) end |
Instance Attribute Details
#ant ⇒ Object
Antenna on which the last read was made
20 21 22 |
# File 'lib/alien/alientag.rb', line 20 def ant @ant end |
#count ⇒ Object
Number of times the tag has been read since discovery
21 22 23 |
# File 'lib/alien/alientag.rb', line 21 def count @count end |
#disc ⇒ Object
Time of discovery
22 23 24 |
# File 'lib/alien/alientag.rb', line 22 def disc @disc end |
#freq ⇒ Object
:nodoc:
28 29 30 |
# File 'lib/alien/alientag.rb', line 28 def freq @freq end |
#id ⇒ Object
EPC code of the tag that was read
19 20 21 |
# File 'lib/alien/alientag.rb', line 19 def id @id end |
#last ⇒ Object
Time of latest read
23 24 25 |
# File 'lib/alien/alientag.rb', line 23 def last @last end |
#proto ⇒ Object
Protocol used to read the tag. A bit map where Gen2 = 16.
24 25 26 |
# File 'lib/alien/alientag.rb', line 24 def proto @proto end |
#rssi ⇒ Object
Returns the value of attribute rssi.
26 27 28 |
# File 'lib/alien/alientag.rb', line 26 def rssi @rssi end |
#speed ⇒ Object
Returns the value of attribute speed.
27 28 29 |
# File 'lib/alien/alientag.rb', line 27 def speed @speed end |
Instance Method Details
#<=>(s) ⇒ Object
The ‘spaceship’ operator allows us to compare tags for sorting, etc.
64 65 66 |
# File 'lib/alien/alientag.rb', line 64 def <=>(s) @id <=> s.id end |
#create(taglist_entry) ⇒ Object
Try to parse a taglist entry into a set of Tag object variables.
Uses a simple mapping from Alien ‘text’ format:
Tag:0102 0304 0506 0708 0900 0A0B, Disc:2008/10/28 10:49:35, Last:2008/10/28 10:49:35, Count:1, Ant:3, Proto:2
rssi and speed attributes are not included in the default text format. In order to have them parsed correctly the TagListFormat must be set to custom and the TagListCustomFormat fields must be separated by the following text tokens:
'tag:', 'disc:', 'last:', 'count:', 'ant:', 'proto:', 'speed:', 'rssi:'
For example:
@rdr.taglistcustomformat("Tag:%i, Disc:${DATE1} ${TIME1}, Last:${DATE2} ${TIME2}, Count:${COUNT}, Ant:${TX}, Proto:${PROTO#}, Speed:${SPEED}, rssi:${RSSI})"
@rdr.taglistformat("custom")
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/alien/alientag.rb', line 89 def create(taglist_entry) @id = "" return self if (taglist_entry=="(No Tags)") tagline = taglist_entry.split("\r\n")[0] tagbits = Hash.new("0") tagline.split(", ").each do |keyval| key, val = keyval.split(":", 2) if key.nil? raise "Trouble parsing taglist string. Text format expected. This string was: #{taglist_entry}" end tagbits[key.downcase] = val end if (!tagbits.empty?) #zero length ids can cause funny behavior if tagbits['tag'] != nil @id = tagbits['tag'] end @ant = tagbits['ant'] @count = tagbits['count'] @disc = tagbits['disc'] @last = DateTime.parse(tagbits['last']) @last_last = @last @proto = tagbits['proto'] @rssi = tagbits['rssi'] @freq = tagbits['freq'] @speed = tagbits['speed'] end return self end |
#inspect ⇒ Object
Return the contents of the tag object as a string (returns tag id as a string)
59 60 61 |
# File 'lib/alien/alientag.rb', line 59 def inspect @id.to_s end |
#tag ⇒ Object
(Deprecated) Returns tag id.
This method is for backward compatibility with an earlier version of this API. Use id instead.
46 47 48 |
# File 'lib/alien/alientag.rb', line 46 def tag @id end |
#tag=(val) ⇒ Object
(Deprecated) Sets tag id.
This method is for backward compatibility with an earlier version of this API. Use id= instead.
54 55 56 |
# File 'lib/alien/alientag.rb', line 54 def tag=(val) @id = val end |
#to_s ⇒ Object
Returns a printable version of the tag object (returns tag id as a string)
69 70 71 |
# File 'lib/alien/alientag.rb', line 69 def to_s @id.to_s end |
#update(new_tag) ⇒ Object
Updates an existing tag object from the new one by incrementing the count and setting the new last time
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/alien/alientag.rb', line 124 def update(new_tag) # Copy the last timestamp and increment the counts @last = new_tag.last @count += new_tag.count @last_last = @last =begin # Update the speed, smooth it, calculate distance dt = (@last - @last_last) * 86400.0 smooth_coef = 5 smooth_factor = Math.exp(-smooth_coef*dt) thresh_zero1 = -0.01 # Any speeds between these thresholds are considered 0 thresh_zero2 = +0.01 puts #printf("\ndt=%0.000010f, smooth_factor(init)=%0.00005f\n", dt, smooth_factor) # Update the speed, smooth out jitter @speed = new_tag.speed if @speed.to_f > thresh_zero1 && @speed.to_f < thresh_zero2 # @speed = 0 end #printf("speed_smooth(initial)=%+0.003f\n", @speed_smooth) @speed_smooth = @speed_smooth*smooth_factor + @speed.to_f*(1 - smooth_factor) @pos_last = @pos_smooth @pos_smooth += @speed_last * dt/1000 @speed_last = @speed_smooth printf("speed=%+0.003f", @speed.to_s) printf(", speed_smooth=%+0.003f", @speed_smooth.to_s) printf(", pos=%+0.005f\n", @pos_smooth.to_s) # Update new pos_min, if needed @pos_min = @pos_smooth if (@pos_smooth < @pos_min) printf("pos_last=%+0.5f, pos_min=%0.5f\n", @pos_last.to_s, @pos_min.to_s) # If last position was the min and tag is moving away --> TopDeadCenter if @pos_last == @pos_min && @pos_smooth > @pos_last puts "********************************************" end =end end |