read_blocks from librfid-tool
[Biblio-RFID.git] / lib / RFID / Biblio / librfid.pm
1 package RFID::Biblio::librfid;
2
3 use warnings;
4 use strict;
5
6 use base 'RFID::Biblio';
7 use RFID::Biblio;
8
9 use Data::Dump qw(dump);
10
11 =head1 NAME
12
13 RFID::Biblio::librfid - execute librfid-tool
14
15 =head2 DESCRIPTION
16
17 This is wrapper around C<librfid-tool> from
18
19 L<http://openmrtd.org/projects/librfid/>
20
21 =head2 SYOPSYS
22
23
24
25 =cut
26
27 sub serial_settings {} # don't open serial
28
29 our $bin = '/rest/cvs/librfid/utils/librfid-tool';
30
31 sub init {
32         my $self = shift;
33         warn "# no $bin found\n" if ! -e $bin;
34 }
35
36 sub _grep_tool {
37         my ( $param, $coderef ) = @_;
38
39         warn "# _grep_tool $bin $param\n";
40         open(my $s, '-|', "$bin $param") || die $!;
41         while(<$s>) {
42                 chomp;
43                 warn "## $_\n";
44                 $coderef->( $_ );
45         }
46
47
48 }
49
50 sub inventory {
51
52         my @tags; 
53         _grep_tool '--scan' => sub {
54                 if ( m/success.+:\s+(.+)/ ) {
55                         push @tags, $1;
56                 }
57         };
58         warn "# invetory ",dump(@tags);
59         return @tags;
60 }
61
62 sub read_blocks {
63
64         my $blocks;
65         _grep_tool '--read -1' => sub {
66                 $blocks->[$1] = hex2bytes($2)
67                 if m/block\[\s*(\d+):.+data.+:\s*(.+)/;
68         };
69         warn "# read_blocks ",dump($blocks);
70         return $blocks;
71 }
72
73 sub write_blocks {}
74 sub read_afi {}
75 sub write_afi {}
76
77 1