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
sub init {
my $self = shift;
- warn "# no $bin found\n" if ! -e $bin;
+ if ( -e $bin ) {
+ warn "# using $bin";
+ return 1;
+ } else {
+ warn "# no $bin found\n";
+ return 0;
+ }
}
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 );
}
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;
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;