daccc32b43e483eca76141eacd63c98d23c7e411
[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 - perl tools to use different RFID readers for library use 
14
15 =cut
16
17 our $VERSION = '0.02';
18
19 my $debug = 0;
20
21
22 =head1 DESCRIPTION
23
24 Main idea is to develop simple API to reader, and than provide useful
25 abstractions on top of it to quickly write applications to respond on
26 tags which come in range of RFID reader using L<RFID::Biblio::Reader>.
27
28 Writing support for new RFID readers should be easy.
29 L<RFID::Biblio::Reader::API> provides documentation on writing support
30 for different readers.
31
32 Currently, two serial RFID readers based on L<RFID::Biblio::Reader::Serial>
33 are implemented:
34
35 =over 4
36
37 =item *
38
39 L<RFID::Biblio::Reader::3M810>
40
41 =item *
42
43 L<RFID::Biblio::Reader::CPRM02>
44
45 =back
46
47 There is also simple read-only reader using shell commands in
48 L<RFID::Biblio::Reader::librfid>.
49
50 For implementing application take a look at L<RFID::Biblio::Reader>
51
52 C<scripts/RFID-JSONP-server.pl> is example of such application. It's local
53 interface to RFID reader and JSONP REST server.
54
55 C<examples/koha-rfid.js> is jQuery based JavaScript code which can be inserted
56 in Koha Library System to provide overlay with tags in range and
57 check-in/check-out form-fill functionality.
58
59 =for readme stop
60
61 =head1 EXPORT
62
63 Formatting functions are exported
64
65 =head2 hex2bytes
66
67   my $bytes = hex2bytes($hex);
68
69 =cut
70
71 sub hex2bytes {
72         my $str = shift || die "no str?";
73         my $b = $str;
74         $b =~ s/\s+//g;
75         $b =~ s/(..)/\\x$1/g;
76         $b = "\"$b\"";
77         my $bytes = eval $b;
78         die $@ if $@;
79         warn "## str2bytes( $str ) => $b => ",as_hex($bytes) if $debug;
80         return $bytes;
81 }
82
83 =head2 as_hex
84
85   print as_hex( $bytes );
86
87 =cut
88
89 sub as_hex {
90         my @out;
91         foreach my $str ( @_ ) {
92                 my $hex = uc unpack( 'H*', $str );
93                 $hex =~ s/(..)/$1 /g if length( $str ) > 2;
94                 $hex =~ s/\s+$//;
95                 push @out, $hex;
96         }
97         return join(' | ', @out);
98 }
99
100 =head2 hex_tag
101
102   print hex_tag $8bytes;
103
104 =cut
105
106 sub hex_tag { uc(unpack('H16', shift)) }
107
108 =for readme continue
109
110 =head1 HARDWARE SUPPORT
111
112 =head2 3M 810
113
114 L<RFID::Biblio::Reader::3M810>
115
116 =head2 CPR-M02
117
118 L<RFID::Biblio::Reader::CPRM02>
119
120 =head2 librfid
121
122 L<RFID::Biblio::Reader::librfid>
123
124
125 =head1 AUTHOR
126
127 Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>
128
129 =head1 BUGS
130
131 Please report any bugs or feature requests to C<bug-rfid-biblio at rt.cpan.org>, or through
132 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=RFID-Biblio>.  I will be notified, and then you'll
133 automatically be notified of progress on your bug as I make changes.
134
135
136
137
138 =head1 SUPPORT
139
140 You can find documentation for this module with the perldoc command.
141
142     perldoc RFID::Biblio
143     perldoc RFID::Biblio::Reader
144     perldoc RFID::Biblio::Reader::API
145
146
147 You can also look for information at:
148
149 =over 4
150
151 =item * RT: CPAN's request tracker
152
153 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=RFID-Biblio>
154
155 =item * AnnoCPAN: Annotated CPAN documentation
156
157 L<http://annocpan.org/dist/RFID-Biblio>
158
159 =item * CPAN Ratings
160
161 L<http://cpanratings.perl.org/d/RFID-Biblio>
162
163 =item * Search CPAN
164
165 L<http://search.cpan.org/dist/RFID-Biblio/>
166
167 =back
168
169
170 =head1 ACKNOWLEDGEMENTS
171
172
173 =head1 LICENSE AND COPYRIGHT
174
175 Copyright 2010 Dobrica Pavlinusic.
176
177 This program is free software; you can redistribute it and/or modify
178 it under the terms of the GNU General Public License as published by
179 the Free Software Foundation; version 2 dated June, 1991 or at your option
180 any later version.
181
182 This program is distributed in the hope that it will be useful,
183 but WITHOUT ANY WARRANTY; without even the implied warranty of
184 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
185 GNU General Public License for more details.
186
187 A copy of the GNU General Public License is available in the source tree;
188 if not, write to the Free Software Foundation, Inc.,
189 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
190
191
192 =cut
193
194 1; # End of RFID::Biblio