line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RFID::Tag; |
2
|
3
|
|
|
3
|
|
56717
|
use RFID::Reader; $VERSION=$RFID::Reader::VERSION; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
260
|
|
3
|
|
|
|
|
|
|
@ISA=qw(Exporter); |
4
|
|
|
|
|
|
|
@EXPORT_OK = qw(tagcmp); |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# Written by Scott Gifford |
7
|
|
|
|
|
|
|
# Copyright (C) 2004-2006 The Regents of the University of Michigan. |
8
|
|
|
|
|
|
|
# See the file LICENSE included with the distribution for license |
9
|
|
|
|
|
|
|
# information. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
RFID::Tag - Abstract base class for an RFID tag object |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
This abstract base class provides a general framework for an abstract |
18
|
|
|
|
|
|
|
RFID tag. These objects are usually returned by an |
19
|
|
|
|
|
|
|
L object: |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use RFID::SchmoozeMatic::Reader; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $reader = |
24
|
|
|
|
|
|
|
RFID::SchmoozeMatic::Reader::TCP->new(PeerAddr => 'schmooze.example.com', |
25
|
|
|
|
|
|
|
PeerPort => 4001, |
26
|
|
|
|
|
|
|
) |
27
|
|
|
|
|
|
|
or die "Couldn't create reader object"; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my @tags = RFID::SchmoozeMatic::Reader->new->readtags(); |
30
|
|
|
|
|
|
|
foreach my $tag (@tags) |
31
|
|
|
|
|
|
|
{ |
32
|
|
|
|
|
|
|
my %t = $tag->get(qw(id Type Location)) |
33
|
|
|
|
|
|
|
print "I see tag $t{Type}.$t{id} at $t{Location}\n"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Tags don't support changing their properties; if you need to do that, |
37
|
|
|
|
|
|
|
create a new tag using some of the properties of the tag you want to |
38
|
|
|
|
|
|
|
change. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
3
|
|
|
3
|
|
26
|
use strict; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
113
|
|
43
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
82
|
|
44
|
|
|
|
|
|
|
|
45
|
3
|
|
|
3
|
|
14
|
use Carp; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
190
|
|
46
|
3
|
|
|
3
|
|
15
|
use Exporter; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
145
|
|
47
|
|
|
|
|
|
|
|
48
|
3
|
|
|
3
|
|
16
|
use constant TAGTYPE => 'unknown'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1423
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 DESCRIPTION |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 Methods |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# A simple initializer function that will just set the id and the |
57
|
|
|
|
|
|
|
# antenna |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _init |
60
|
|
|
|
|
|
|
{ |
61
|
8
|
|
|
8
|
|
654
|
my $self = shift; |
62
|
8
|
|
|
|
|
29
|
my(%p) = @_; |
63
|
|
|
|
|
|
|
|
64
|
8
|
|
|
|
|
20
|
foreach my $param (keys %p) |
65
|
|
|
|
|
|
|
{ |
66
|
11
|
50
|
|
|
|
18
|
if (grep { lc $param eq $_ } qw(id antenna time location)) |
|
44
|
|
|
|
|
92
|
|
67
|
|
|
|
|
|
|
{ |
68
|
11
|
50
|
|
|
|
57
|
$self->{lc $param} = $p{$param} |
69
|
|
|
|
|
|
|
unless defined($self->{lc $param}); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
8
|
|
|
|
|
48
|
$self; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head3 get |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Get various properties of the tag. This method takes a list of |
79
|
|
|
|
|
|
|
parameters whose values you'd like to get. In a list context, it |
80
|
|
|
|
|
|
|
returns a hash with the parameters you asked for as the keys, and |
81
|
|
|
|
|
|
|
their values as the values. In a scalar context, it returns the value |
82
|
|
|
|
|
|
|
of the last property requested. If an error occurs or a value for the |
83
|
|
|
|
|
|
|
requested property can't be found, it is set to C. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
For example: |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $tagtype = $tag->get('Type'); |
88
|
|
|
|
|
|
|
my %tag_properties = $tag->get(qw(Type ID Location)); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
See L for the properties that can be retreived |
91
|
|
|
|
|
|
|
with I. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub get |
96
|
|
|
|
|
|
|
{ |
97
|
3
|
|
|
3
|
1
|
8
|
my $self = shift; |
98
|
3
|
|
|
|
|
2
|
my %ret; |
99
|
|
|
|
|
|
|
|
100
|
3
|
|
|
|
|
7
|
foreach my $var (@_) |
101
|
|
|
|
|
|
|
{ |
102
|
6
|
100
|
|
|
|
15
|
if (lc $var eq 'type') |
|
|
100
|
|
|
|
|
|
103
|
20
|
|
|
|
|
34
|
{ |
104
|
1
|
|
|
|
|
4
|
$ret{$var} = $self->type; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
elsif (grep {lc $var eq $_} qw(id antenna time location)) |
107
|
|
|
|
|
|
|
{ |
108
|
4
|
|
|
|
|
10
|
$ret{$var}=$self->{lc $var}; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
3
|
100
|
|
|
|
7
|
if (wantarray) |
113
|
|
|
|
|
|
|
{ |
114
|
1
|
|
|
|
|
7
|
return %ret; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
else |
117
|
|
|
|
|
|
|
{ |
118
|
|
|
|
|
|
|
# Return last value |
119
|
2
|
|
|
|
|
10
|
return $ret{$_[$#_]}; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head3 id method |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Returns the tag's ID as a string. This is a shortcut for using the |
126
|
|
|
|
|
|
|
L method. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub id |
131
|
|
|
|
|
|
|
{ |
132
|
39
|
|
|
39
|
1
|
2230
|
my $self = shift; |
133
|
39
|
|
|
|
|
120
|
$self->{id}; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head3 type |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Returns the tag's type as a string. This is a shortcut for using the |
139
|
|
|
|
|
|
|
L method. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub type |
144
|
|
|
|
|
|
|
{ |
145
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
146
|
1
|
|
|
|
|
4
|
TAGTYPE; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head3 tagcmp |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Compares another tag to this one, returning a value like C: -1 if |
153
|
|
|
|
|
|
|
this tag is smaller, 0 if the tags are the same, or 1 if the other tag |
154
|
|
|
|
|
|
|
is smaller. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
You can use this method in a call to C: |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
@sorted_tags = sort { $a->tagcmp($b) } @tags; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
The implementation in the abstract base class does an alphabetic |
161
|
|
|
|
|
|
|
comparison of the tags IDs converted to strings. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# This is a fallback method that just compares tags as strings. Most |
166
|
|
|
|
|
|
|
# tag types should implement a better method than this if the tag |
167
|
|
|
|
|
|
|
# types are the same, and if the types are different then fall back on |
168
|
|
|
|
|
|
|
# this. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub tagcmp |
171
|
|
|
|
|
|
|
{ |
172
|
17
|
|
|
17
|
1
|
33
|
my $self = shift; |
173
|
17
|
|
|
|
|
23
|
my($other) = @_; |
174
|
|
|
|
|
|
|
|
175
|
17
|
|
|
|
|
583
|
$self->id cmp $other->id; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 Properties |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
These are the properties you can retreive with L. Properties |
182
|
|
|
|
|
|
|
which must be available with all types of tags are marked with I
|
183
|
|
|
|
|
|
|
Tags>; properties which may or may not be available are marked with |
184
|
|
|
|
|
|
|
I. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head3 Antenna |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
I. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Which antenna this tag was detected from. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head3 id |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
I. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
The identifier for this tag as a string. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head3 Location |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
I. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
The location where this tag was detected as a string. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head3 Time |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
I. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
The time when this tag was detected, in the format returned by C |
209
|
|
|
|
|
|
|
(Unix epoch time). |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head3 Type |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
A string describing the type of this tag. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 SEE ALSO |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
L, |
218
|
|
|
|
|
|
|
L, The manual for |
219
|
|
|
|
|
|
|
your particular RFID driver class, The manual for your RFID driver's |
220
|
|
|
|
|
|
|
tag class. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head1 AUTHOR |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Scott Gifford Egifford@umich.eduE, Esgifford@suspectclass.comE |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Copyright (C) 2004-2006 The Regents of the University of Michigan. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
See the file LICENSE included with the distribution for license |
229
|
|
|
|
|
|
|
information. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=cut |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
1; |