-package RFID::Biblio::3M810;
+package RFID::Biblio::Reader::3M810;
=head1 NAME
-RFID::Biblio::3M810 - support for 3M 810 RFID reader
+RFID::Biblio::Reader::3M810 - support for 3M 810 RFID reader
=head1 DESCRIPTION
-This module implement serial protocol (over USB/serial adapter) with 3M 810 RFID
-reader, often used in library applications.
+This module uses L<RFID::Biblio::Reader::Serial> over USB/serial adapter
+with 3M 810 RFID reader, often used in library applications.
-This is most complete implementation which supports full API defined
-in L<RFID::Biblio>. This include scanning for all tags in reader
+This is most mature implementation which supports full API defined
+in L<RFID::Biblio::Reader::API>. This include scanning for all tags in reader
range, reading and writing of data, and AFI security manipulation.
This implementation is developed using Portmon on Windows to capture serial traffic
Checksum for this reader is developed using help from C<selwyn>
L<http://stackoverflow.com/questions/149617/how-could-i-guess-a-checksum-algorithm>
+More inforation about process of reverse engeeniring protocol with
+this reader is available at L<http://blog.rot13.org/rfid/>
+
=cut
use warnings;
use strict;
-use base 'RFID::Biblio';
+use base 'RFID::Biblio::Reader::Serial';
use RFID::Biblio;
use Data::Dump qw(dump);
use Digest::CRC;
sub serial_settings {{
- device => "/dev/ttyUSB1", # FIXME comment out before shipping
baudrate => "19200",
databits => "8",
parity => "none",
handshake => "none",
}}
+sub assert;
+
my $port;
sub init {
my $self = shift;
$port->read_char_time(100); # 0.1 s char timeout
$port->read_const_time(500); # 0.5 s read timeout
- setup();
+ $port->write( hex2bytes( 'D5 00 05 04 00 11 8C66' ) );
+ # hw-version expect: 'D5 00 09 04 00 11 0A 05 00 02 7250'
+ my $data = $port->read( 12 );
+ return unless $data;
+
+ warn "# probe response: ",as_hex($data);
+ if ( my $rest = assert $data => 'D5 00 09 04 00 11' ) {
+ my $hw_ver = join('.', unpack('CCCC', $rest));
+ warn "# 3M 810 hardware version $hw_ver\n";
+
+ cmd(
+'13 04 01 00 02 00 03 00 04 00','FIXME: stats? rf-on?', sub { assert(shift,
+'13 00 02 01 01 03 02 02 03 00'
+ )});
+
+ return $hw_ver;
+ }
+ return;
}
sub checksum {
pack('n', $crc->digest);
}
-sub wait_device {
- Time::HiRes::sleep 0.015;
-}
-
sub cmd {
my ( $hex, $description, $coderef ) = @_;
my $bytes = hex2bytes($hex);
warn ">> ", as_hex( $bytes ), "\t\t[$description]\n";
$port->write( $bytes );
- wait_device;
-
my $r_len = $port->read(3);
while ( length($r_len) < 3 ) {
- wait_device;
$r_len = $port->read( 3 - length($r_len) );
}
- wait_device;
-
my $len = ord( substr($r_len,2,1) );
my $data = $port->read( $len );
- while ( length($data) < $len ) {
- warn "# short read ", length($data), " < $len\n";
- wait_device;
- $data .= $port->read( $len - length($data) );
- }
-
warn "<< ", as_hex($r_len,$data),
' | ',
substr($data,-2,2) eq checksum(substr($r_len,1).substr($data,0,-2)) ? 'OK' : 'ERROR',
return substr($got,$len);
}
-sub setup {
-
-cmd(
-'D5 00 05 04 00 11 8C66', 'hw version', sub {
- my $data = shift;
- my $rest = assert $data => '04 00 11';
- my $hw_ver = join('.', unpack('CCCC', $rest));
- warn "# 3M 810 hardware version $hw_ver\n";
-});
-
-cmd(
-'13 04 01 00 02 00 03 00 04 00','FIXME: stats? rf-on?', sub { assert(shift,
-'13 00 02 01 01 03 02 02 03 00'
-)});
-}
-
-=head2 inventory
-
- my @tags = inventory;
-
-=cut
sub inventory {
}
1
+
+__END__
+
+=head1 SEE ALSO
+
+L<RFID::Biblio::Reader::API>