line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Biblio::RFID::Reader::librfid; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
38481
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
63
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
59
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
12
|
use base 'Biblio::RFID::Reader::API'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
521
|
|
7
|
2
|
|
|
2
|
|
321
|
use Biblio::RFID; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
262
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
14
|
use Data::Dump qw(dump); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1248
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Biblio::RFID::Reader::librfid - execute librfid-tool |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
This is wrapper around C from |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
L |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Due to limitation of L only |
22
|
|
|
|
|
|
|
L and |
23
|
|
|
|
|
|
|
L is supported. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
However, this code might provide template for integration |
26
|
|
|
|
|
|
|
with any command-line utilities for different RFID readers. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Currently tested with only with Omnikey CardMan 5321 which |
29
|
|
|
|
|
|
|
has problems. After a while it stops responding to commands |
30
|
|
|
|
|
|
|
by C so I provided small C program to reset it: |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
C |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
0
|
0
|
0
|
sub serial_settings {} # don't open serial |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
our $bin = '/rest/cvs/librfid/utils/librfid-tool'; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub init { |
41
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
42
|
1
|
50
|
|
|
|
21
|
if ( -e $bin ) { |
43
|
0
|
|
|
|
|
0
|
warn "# using $bin"; |
44
|
0
|
|
|
|
|
0
|
return 1; |
45
|
|
|
|
|
|
|
} else { |
46
|
1
|
|
|
|
|
8
|
warn "# no $bin found\n"; |
47
|
1
|
|
|
|
|
17
|
return 0; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _grep_tool { |
52
|
0
|
|
|
0
|
|
|
my ( $param, $coderef ) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
warn "# _grep_tool $bin $param\n"; |
55
|
0
|
0
|
|
|
|
|
open(my $s, '-|', "$bin $param") || die $!; |
56
|
0
|
|
|
|
|
|
while(<$s>) { |
57
|
0
|
|
|
|
|
|
chomp; |
58
|
0
|
|
|
|
|
|
warn "## $_\n"; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $sid; |
61
|
0
|
0
|
|
|
|
|
if ( m/success.+:\s+(.+)/ ) { |
62
|
0
|
|
|
|
|
|
$sid = $1; |
63
|
0
|
|
|
|
|
|
$sid =~ s/\s*'\s*//g; |
64
|
0
|
|
|
|
|
|
$sid = uc join('', reverse split(/\s+/, $sid)); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$coderef->( $sid ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub inventory { |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
0
|
1
|
|
my @tags; |
76
|
|
|
|
|
|
|
_grep_tool '--scan' => sub { |
77
|
0
|
|
|
0
|
|
|
my $sid = shift; |
78
|
0
|
0
|
|
|
|
|
push @tags, $sid if $sid; |
79
|
0
|
|
|
|
|
|
}; |
80
|
0
|
|
|
|
|
|
warn "# invetory ",dump(@tags); |
81
|
0
|
|
|
|
|
|
return @tags; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub read_blocks { |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
0
|
1
|
|
my $sid; |
87
|
|
|
|
|
|
|
my $blocks; |
88
|
|
|
|
|
|
|
_grep_tool '--read -1' => sub { |
89
|
0
|
|
0
|
0
|
|
|
$sid ||= shift; |
90
|
0
|
0
|
|
|
|
|
$blocks->{$sid}->[$1] = hex2bytes($2) |
91
|
|
|
|
|
|
|
if m/block\[\s*(\d+):.+data.+:\s*(.+)/; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
}; |
94
|
0
|
|
|
|
|
|
warn "# read_blocks ",dump($blocks); |
95
|
0
|
|
|
|
|
|
return $blocks; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
0
|
1
|
|
sub write_blocks {} |
99
|
0
|
|
|
0
|
1
|
|
sub read_afi { -1 } |
100
|
0
|
|
|
0
|
1
|
|
sub write_afi {} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1 |