-package RFID::Biblio;
+package Biblio::RFID;
use warnings;
use strict;
use base 'Exporter';
-our @EXPORT = qw( hex2bytes as_hex hex_tag );
+our @EXPORT = qw( hex2bytes as_hex hex_tag $debug );
-use Device::SerialPort qw(:STAT);
use Data::Dump qw(dump);
=head1 NAME
-RFID::Biblio - support serial RFID devices
+Biblio::RFID - perl tools to use different RFID readers for library use
=cut
-our $VERSION = '0.01';
+our $VERSION = '0.02';
-my $debug = 0;
+our $debug = 0;
-=head1 SYNOPSIS
+=head1 DESCRIPTION
-This module tries to support USB serial RFID readers wsing simple API
-which is sutable for direct mapping to REST JSONP service.
+Main idea is to develop simple API to reader, and than provide useful
+abstractions on top of it to quickly write applications to respond on
+tags which come in range of RFID reader using L<Biblio::RFID::Reader>.
-Perhaps a little code snippet.
+Writing support for new RFID readers should be easy.
+L<Biblio::RFID::Reader::API> provides documentation on writing support
+for different readers.
- use RFID::Biblio;
+Currently, two serial RFID readers based on L<Biblio::RFID::Reader::Serial>
+are implemented:
- my $rfid = RFID::Biblio->new(
- device => '/dev/ttyUSB0', # with fallback to RFID_DEVICE
- );
- my $visible = $rfid->scan;
-
-=head1 SUBROUTINES/METHODS
-
-=head2 new
-
-=cut
-
-sub new {
- my $class = shift;
- my $self = {@_};
- bless $self, $class;
-
- $self->port;
-
- $self->init;
-
- return $self;
-}
-
-=head2 port
-
- my $serial_obj = $self->port;
-
-=cut
-
-sub port {
- my $self = shift;
-
- return $self->{port} if defined $self->{port};
-
- my $settings = $self->serial_settings;
- $settings->{device} ||= $ENV{RFID_DEVICE};
- warn "# settings ",dump $settings;
-
- $self->{port} = Device::SerialPort->new( $settings->{device} )
- || die "can't open serial port: $!\n";
-
- $self->{port}->$_( $settings->{$_} )
- foreach ( qw/handshake baudrate databits parity stopbits/ );
-
-}
-
-=head2 scan
-
- my $visible = $rfid->scan;
-
-Returns hash with keys which match tag UID and values with blocks
-
-=cut
-
-sub scan {
- my $self = shift;
-
- warn "# scan tags in reader range\n";
- my @tags = $self->inventory;
-
- my $visible;
- # FIXME this is naive implementation which just discards other tags
- foreach my $tag ( @tags ) {
- my $blocks = $self->read_blocks( $tag );
- if ( ! $blocks ) {
- warn "ERROR: can't read tag $tag\n";
- delete $visible->{$tag};
- } else {
- $visible->{$tag} = $blocks->{$tag};
- }
- }
-
- return $visible;
-}
-
-
-=head1 MANDATORY IMPLEMENTATIONS
-
-Each reader must implement following hooks as sub-classes.
-
-=head2 init
-
- $self->init;
-
-=head2 inventory
-
- my @tags = $self->invetory;
-
-=head2 read_blocks
-
- my $hash = $self->read_blocks( $tag );
-
-All blocks are under key which is tag UID with array of blocks returned from reader
+=over 4
- $hash = { 'E000000123456789' => [ 'blk1', 'blk2', ... ] };
+=item *
-L<RFID::Biblio::3M810> sends tag UID with data payload, so we might expect
-to receive response from other tags from protocol specification,
+L<Biblio::RFID::Reader::3M810>
-=head2 write_blocks
+=item *
- $self->write_blocks( $tag => $bytes );
+L<Biblio::RFID::Reader::CPRM02>
- $self->write_blocks( $tag => [ 'blk1', 'blk2', ... ] );
+=back
-=head2 read_afi
+There is also simple read-only reader using shell commands in
+L<Biblio::RFID::Reader::librfid>.
- my $afi = $self->read_afi( $tag );
+For implementing application take a look at L<Biblio::RFID::Reader>
-=head2 write_afi
+C<scripts/RFID-JSONP-server.pl> is example of such application. It's local
+interface to RFID reader and JSONP REST server.
- $self->write_afi( $tag => $afi );
+C<examples/koha-rfid.js> is jQuery based JavaScript code which can be inserted
+in Koha Library System to provide overlay with tags in range and
+check-in/check-out form-fill functionality.
+Applications can use L<Biblio::RFID::RFID501> which is some kind of
+semi-standard 3M layout or blocks on RFID tags.
+=for readme stop
=head1 EXPORT
sub hex_tag { uc(unpack('H16', shift)) }
+=head1 WARN
+
+We are installing L<perldoc/warn> handler to controll debug output
+based on C<$Biblio::RFID::debug> level
+
+=cut
+
+BEGIN {
+ $SIG{'__WARN__'} = sub {
+ my $msg = join(' ', @_);
+ if ( $msg =~ m/^(#+)/ ) {
+ my $l = length $1;
+ return if $l > $debug;
+ }
+ warn join(' ', @_);
+ }
+}
+
+=for readme continue
+
+=head1 HARDWARE SUPPORT
+
+=head2 3M 810
+
+L<Biblio::RFID::Reader::3M810>
+
+=head2 CPR-M02
+
+L<Biblio::RFID::Reader::CPRM02>
+
+=head2 librfid
+
+L<Biblio::RFID::Reader::librfid>
+
=head1 AUTHOR
Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>
+L<http://blog.rot13.org/>
+
=head1 BUGS
-Please report any bugs or feature requests to C<bug-rfid-serial at rt.cpan.org>, or through
-the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=RFID-Biblio>. I will be notified, and then you'll
+Please report any bugs or feature requests to C<bug-rfid-biblio at rt.cpan.org>, or through
+the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Biblio-RFID>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
- perldoc RFID::Biblio
+ perldoc Biblio::RFID
+ perldoc Biblio::RFID::Reader
+ perldoc Biblio::RFID::Reader::API
You can also look for information at:
=item * RT: CPAN's request tracker
-L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=RFID-Biblio>
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Biblio-RFID>
=item * AnnoCPAN: Annotated CPAN documentation
-L<http://annocpan.org/dist/RFID-Biblio>
+L<http://annocpan.org/dist/Biblio-RFID>
=item * CPAN Ratings
-L<http://cpanratings.perl.org/d/RFID-Biblio>
+L<http://cpanratings.perl.org/d/Biblio-RFID>
=item * Search CPAN
-L<http://search.cpan.org/dist/RFID-Biblio/>
+L<http://search.cpan.org/dist/Biblio-RFID/>
=back
=cut
-1; # End of RFID::Biblio
+1; # End of Biblio::RFID