read_blocks from librfid-tool
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 29 Jul 2010 16:13:29 +0000 (18:13 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 29 Jul 2010 16:13:29 +0000 (18:13 +0200)
lib/RFID/Biblio/librfid.pm

index 286eb24..50e05e8 100644 (file)
@@ -6,6 +6,8 @@ use strict;
 use base 'RFID::Biblio';
 use RFID::Biblio;
 
+use Data::Dump qw(dump);
+
 =head1 NAME
 
 RFID::Biblio::librfid - execute librfid-tool
@@ -16,33 +18,58 @@ This is wrapper around C<librfid-tool> from
 
 L<http://openmrtd.org/projects/librfid/>
 
+=head2 SYOPSYS
+
+
+
 =cut
 
 sub serial_settings {} # don't open serial
 
-our $tool = '/rest/cvs/librfid/utils/librfid-tool';
+our $bin = '/rest/cvs/librfid/utils/librfid-tool';
 
 sub init {
-       warn "# no $tool found\n" if ! -e $tool;
+       my $self = shift;
+       warn "# no $bin found\n" if ! -e $bin;
 }
 
-sub inventory {
-
-       my @tags; 
+sub _grep_tool {
+       my ( $param, $coderef ) = @_;
 
-       open(my $s, '-|', "$tool --scan") || die $!;
+       warn "# _grep_tool $bin $param\n";
+       open(my $s, '-|', "$bin $param") || die $!;
        while(<$s>) {
                chomp;
                warn "## $_\n";
+               $coderef->( $_ );
+       }
+
+
+}
+
+sub inventory {
+
+       my @tags; 
+       _grep_tool '--scan' => sub {
                if ( m/success.+:\s+(.+)/ ) {
                        push @tags, $1;
                }
-       }
-
+       };
+       warn "# invetory ",dump(@tags);
        return @tags;
 }
 
-sub read_blocks {}
+sub read_blocks {
+
+       my $blocks;
+       _grep_tool '--read -1' => sub {
+               $blocks->[$1] = hex2bytes($2)
+               if m/block\[\s*(\d+):.+data.+:\s*(.+)/;
+       };
+       warn "# read_blocks ",dump($blocks);
+       return $blocks;
+}
+
 sub write_blocks {}
 sub read_afi {}
 sub write_afi {}