split RFID::Bibio::Reader::Serial as base class
[Biblio-RFID.git] / lib / RFID / Biblio.pm
1 package RFID::Biblio;
2
3 use warnings;
4 use strict;
5
6 use base 'Exporter';
7 our @EXPORT = qw( hex2bytes as_hex hex_tag );
8
9 use Data::Dump qw(dump);
10
11 =head1 NAME
12
13 RFID::Biblio - easy to use API for writing RFID enabled appliaction
14
15 =cut
16
17 our $VERSION = '0.02';
18
19 my $debug = 0;
20
21
22 =head1 SYNOPSIS
23
24 This module tries to support USB serial RFID readers wsing simple API
25 which is sutable for direct mapping to REST JSONP service.
26
27 For implementing application take a look at L<RFID::Biblio::Reader>
28
29 =head1 READER IMPLEMENTATION
30
31 Each reader must implement following hooks as sub-classes.
32
33 =head2 init
34
35   $self->init;
36
37 =head2 inventory
38
39   my @tags = $self->invetory;
40
41 =head2 read_blocks
42
43   my $hash = $self->read_blocks( $tag );
44
45 All blocks are under key which is tag UID with array of blocks returned from reader
46
47   $hash = { 'E000000123456789' => [ 'blk1', 'blk2', ... ] };
48
49 L<RFID::Biblio::Reader::3M810> sends tag UID with data payload, so we might expect
50 to receive response from other tags from protocol specification, 
51
52 =head2 write_blocks
53
54   $self->write_blocks( $tag => $bytes );
55
56   $self->write_blocks( $tag => [ 'blk1', 'blk2', ... ] );
57
58 =head2 read_afi
59
60   my $afi = $self->read_afi( $tag );
61
62 =head2 write_afi
63
64   $self->write_afi( $tag => $afi );
65
66
67
68 =head1 EXPORT
69
70 Formatting functions are exported
71
72 =head2 hex2bytes
73
74   my $bytes = hex2bytes($hex);
75
76 =cut
77
78 sub hex2bytes {
79         my $str = shift || die "no str?";
80         my $b = $str;
81         $b =~ s/\s+//g;
82         $b =~ s/(..)/\\x$1/g;
83         $b = "\"$b\"";
84         my $bytes = eval $b;
85         die $@ if $@;
86         warn "## str2bytes( $str ) => $b => ",as_hex($bytes) if $debug;
87         return $bytes;
88 }
89
90 =head2 as_hex
91
92   print as_hex( $bytes );
93
94 =cut
95
96 sub as_hex {
97         my @out;
98         foreach my $str ( @_ ) {
99                 my $hex = uc unpack( 'H*', $str );
100                 $hex =~ s/(..)/$1 /g if length( $str ) > 2;
101                 $hex =~ s/\s+$//;
102                 push @out, $hex;
103         }
104         return join(' | ', @out);
105 }
106
107 =head2 hex_tag
108
109   print hex_tag $8bytes;
110
111 =cut
112
113 sub hex_tag { uc(unpack('H16', shift)) }
114
115
116 =head1 SUPPORTED READERS
117
118 Support for different RFID readers is implemented in subclasses:
119
120 =head2 3M 810
121
122 L<RFID::Biblio::Reader::3M810>
123
124 =head2 CPR-M02
125
126 L<RFID::Biblio::Reader::CPRM02>
127
128 =head2 librfid
129
130 L<RFID::Biblio::Reader::librfid>
131
132 =head1 AUTHOR
133
134 Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>
135
136 =head1 BUGS
137
138 Please report any bugs or feature requests to C<bug-rfid-serial at rt.cpan.org>, or through
139 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=RFID-Biblio>.  I will be notified, and then you'll
140 automatically be notified of progress on your bug as I make changes.
141
142
143
144
145 =head1 SUPPORT
146
147 You can find documentation for this module with the perldoc command.
148
149     perldoc RFID::Biblio
150
151
152 You can also look for information at:
153
154 =over 4
155
156 =item * RT: CPAN's request tracker
157
158 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=RFID-Biblio>
159
160 =item * AnnoCPAN: Annotated CPAN documentation
161
162 L<http://annocpan.org/dist/RFID-Biblio>
163
164 =item * CPAN Ratings
165
166 L<http://cpanratings.perl.org/d/RFID-Biblio>
167
168 =item * Search CPAN
169
170 L<http://search.cpan.org/dist/RFID-Biblio/>
171
172 =back
173
174
175 =head1 ACKNOWLEDGEMENTS
176
177
178 =head1 LICENSE AND COPYRIGHT
179
180 Copyright 2010 Dobrica Pavlinusic.
181
182 This program is free software; you can redistribute it and/or modify
183 it under the terms of the GNU General Public License as published by
184 the Free Software Foundation; version 2 dated June, 1991 or at your option
185 any later version.
186
187 This program is distributed in the hope that it will be useful,
188 but WITHOUT ANY WARRANTY; without even the implied warranty of
189 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
190 GNU General Public License for more details.
191
192 A copy of the GNU General Public License is available in the source tree;
193 if not, write to the Free Software Foundation, Inc.,
194 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
195
196
197 =cut
198
199 1; # End of RFID::Biblio