From: Dobrica Pavlinusic Date: Thu, 29 Jul 2010 15:48:34 +0000 (+0200) Subject: librfid inventory X-Git-Tag: RFID-Biblio-0.02~115 X-Git-Url: http://git.rot13.org/?p=Biblio-RFID.git;a=commitdiff_plain;h=f2745331e3de510b2cc814217578774a7b5a6d17 librfid inventory --- diff --git a/lib/RFID/Biblio.pm b/lib/RFID/Biblio.pm index 4f3499d..df44707 100644 --- a/lib/RFID/Biblio.pm +++ b/lib/RFID/Biblio.pm @@ -64,9 +64,14 @@ sub port { return $self->{port} if defined $self->{port}; my $settings = $self->serial_settings; - $settings->{device} ||= $ENV{RFID_DEVICE}; + my $device = $settings->{device} ||= $ENV{RFID_DEVICE}; warn "# settings ",dump $settings; + if ( ! $device ) { + warn "# no device, serial port not opened\n"; + return; + } + $self->{port} = Device::SerialPort->new( $settings->{device} ) || die "can't open serial port: $!\n"; diff --git a/lib/RFID/Biblio/librfid.pm b/lib/RFID/Biblio/librfid.pm new file mode 100644 index 0000000..2dbe62c --- /dev/null +++ b/lib/RFID/Biblio/librfid.pm @@ -0,0 +1,46 @@ +package RFID::Biblio::librfid; + +use warnings; +use strict; + +use base 'RFID::Biblio'; +use RFID::Biblio; + +=head1 NAME + +RFID::Biblio::librfid - execute librfid-tool + +=head2 DESCRIPTION + +This is wrapper around C from + +L + +=cut + +sub serial_settings {} # don't open serial + +our $tool = '/rest/cvs/librfid/utils/librfid-tool'; + +sub init { + warn "# no $tool found\n" if ! -e $tool; +} + +sub inventory { + + my @tags; + + open(my $s, '-|', "$tool --scan") || die $!; + while(<$s>) { + chomp; + warn "## $_\n"; + if ( m/success.+:\s+(.+)/ ) { + push @tags, $1; + } + } + + return @tags; +} + + +1 diff --git a/t/30-librfid.t b/t/30-librfid.t new file mode 100755 index 0000000..12e3e6a --- /dev/null +++ b/t/30-librfid.t @@ -0,0 +1,41 @@ +#!/usr/bin/perl + +use Test::More tests => 3; +use Data::Dump qw(dump); + +use lib 'lib'; + +BEGIN { + use_ok( 'RFID::Biblio::librfid' ); +} + +ok( my $o = RFID::Biblio::librfid->new( tool => '/rest/cvs/librfid/utils/librfid-tool' ), 'new' ); + +ok( my @tags = $o->inventory, 'inventory' ); +diag dump @tags; + +__END__ + +my $old_afi; + +foreach my $tag ( @tags ) { + + ok( my $blocks = $o->read_blocks( $tag ), "read_blocks $tag" ); + + ok( my $afi = $o->read_afi( $tag ), "read_afi $tag" ); + + ok( $o->write_blocks( $tag, $blocks ), "write_blocks $tag" ); + + my $new_afi = "\x42"; + + ok( $o->write_afi( $tag, $new_afi ), sprintf( "write_afi %s %x", $tag, $new_afi ) ); + + cmp_ok( $o->read_afi( $tag ), 'eq', $new_afi, 'AFI check' ); + + ok( $o->write_afi( $tag, $afi ), sprintf( "write_afi %s %x", $tag, $afi ) ); + +} + +ok( my $visible = $o->scan, 'scan' ); +diag dump $visible; +