split RFID::Bibio::Reader::Serial as base class
[Biblio-RFID.git] / lib / RFID / Biblio.pm
index b3723fe..1139a0c 100644 (file)
@@ -6,16 +6,15 @@ use strict;
 use base 'Exporter';
 our @EXPORT = qw( hex2bytes as_hex hex_tag );
 
-use Device::SerialPort qw(:STAT);
 use Data::Dump qw(dump);
 
 =head1 NAME
 
-RFID::Biblio - support serial RFID devices
+RFID::Biblio - easy to use API for writing RFID enabled appliaction
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 
 my $debug = 0;
 
@@ -25,108 +24,45 @@ my $debug = 0;
 This module tries to support USB serial RFID readers wsing simple API
 which is sutable for direct mapping to REST JSONP service.
 
-Perhaps a little code snippet.
+For implementing application take a look at L<RFID::Biblio::Reader>
 
-    use RFID::Biblio;
+=head1 READER IMPLEMENTATION
 
-    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
+Each reader must implement following hooks as sub-classes.
 
-  my $visible = $rfid->scan;
+=head2 init
 
-Returns hash with keys which match tag UID and values with blocks
+  $self->init;
 
-=cut
+=head2 inventory
 
-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};
-               }
-       }
+  my @tags = $self->invetory;
 
-       return $visible;
-}
+=head2 read_blocks
 
+  my $hash = $self->read_blocks( $tag );
 
-=head1 MANDATORY IMPLEMENTATIONS
+All blocks are under key which is tag UID with array of blocks returned from reader
 
-Each reader must implement following hooks as sub-classes.
+  $hash = { 'E000000123456789' => [ 'blk1', 'blk2', ... ] };
 
-=head2 init
+L<RFID::Biblio::Reader::3M810> sends tag UID with data payload, so we might expect
+to receive response from other tags from protocol specification, 
 
-  $self->init;
+=head2 write_blocks
 
-=head2 inventory
+  $self->write_blocks( $tag => $bytes );
 
-  my @tags = $self->invetory;
+  $self->write_blocks( $tag => [ 'blk1', 'blk2', ... ] );
 
-=head2 read_blocks
+=head2 read_afi
 
-  my $hash = $self->read_blocks $tag;
+  my $afi = $self->read_afi( $tag );
 
-All blocks are under key which is tag UID
+=head2 write_afi
 
-  $hash = { 'E000000123456789' => [ undef, 'block1', 'block2', ... ] };
+  $self->write_afi( $tag => $afi );
 
-L<RFID::Biblio::3M810> sends tag UID with data payload, so we might expect
-to receive response from other tags from protocol specification, 
 
 
 =head1 EXPORT
@@ -177,6 +113,22 @@ sub as_hex {
 sub hex_tag { uc(unpack('H16', shift)) }
 
 
+=head1 SUPPORTED READERS
+
+Support for different RFID readers is implemented in subclasses:
+
+=head2 3M 810
+
+L<RFID::Biblio::Reader::3M810>
+
+=head2 CPR-M02
+
+L<RFID::Biblio::Reader::CPRM02>
+
+=head2 librfid
+
+L<RFID::Biblio::Reader::librfid>
+
 =head1 AUTHOR
 
 Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>