document limitations
[Biblio-RFID.git] / lib / RFID / Biblio / librfid.pm
index 50e05e8..a8044ee 100644 (file)
@@ -18,9 +18,11 @@ This is wrapper around C<librfid-tool> from
 
 L<http://openmrtd.org/projects/librfid/>
 
-=head2 SYOPSYS
-
+Due to limitation of C<librfid-tool> only C<inventory> and
+C<read_blocks> is supported.
 
+However, this code might provide template for integration
+with any command-line utilities for different RFID readers.
 
 =cut
 
@@ -41,7 +43,15 @@ sub _grep_tool {
        while(<$s>) {
                chomp;
                warn "## $_\n";
-               $coderef->( $_ );
+
+               my $sid;
+               if ( m/success.+:\s+(.+)/ ) {
+                       $sid = $1;
+                       $sid =~ s/\s*'\s*//g;
+                       $sid = uc join('', reverse split(/\s+/, $sid));
+               }
+
+               $coderef->( $sid );
        }
 
 
@@ -51,9 +61,8 @@ sub inventory {
 
        my @tags; 
        _grep_tool '--scan' => sub {
-               if ( m/success.+:\s+(.+)/ ) {
-                       push @tags, $1;
-               }
+               my $sid = shift;
+               push @tags, $sid if $sid;
        };
        warn "# invetory ",dump(@tags);
        return @tags;
@@ -61,10 +70,13 @@ sub inventory {
 
 sub read_blocks {
 
+       my $sid;
        my $blocks;
        _grep_tool '--read -1' => sub {
-               $blocks->[$1] = hex2bytes($2)
+               $sid ||= shift;
+               $blocks->{$sid}->[$1] = hex2bytes($2)
                if m/block\[\s*(\d+):.+data.+:\s*(.+)/;
+
        };
        warn "# read_blocks ",dump($blocks);
        return $blocks;