X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2FBiblio%2FRFID%2FReader%2F3M810.pm;h=467b4e7036d9d192604277a5f2f9c69a54fd3ae9;hb=821fd03150ccc8e8802e6b5507e61480aa7552ef;hp=ad28fec2a62b548f5b17033aeb9576f3db7badba;hpb=48764d1207ef06ad96b937bd2365227f78090109;p=Biblio-RFID.git diff --git a/lib/Biblio/RFID/Reader/3M810.pm b/lib/Biblio/RFID/Reader/3M810.pm index ad28fec..467b4e7 100644 --- a/lib/Biblio/RFID/Reader/3M810.pm +++ b/lib/Biblio/RFID/Reader/3M810.pm @@ -208,9 +208,9 @@ sub read_blocks { } elsif ( $rest = _matched $data => 'FE 00 00 05 01' ) { warn "FIXME ready? ",as_hex $rest; } elsif ( $rest = _matched $data => '02 06' ) { - die "ERROR ",as_hex($rest); + die "ERROR ",as_hex($data); } else { - die "FIXME unsuported ",as_hex($rest); + die "FIXME unsuported ",as_hex($data); } }); @@ -235,6 +235,9 @@ sub write_blocks { my $hex_data = as_hex $data; my $blocks = sprintf('%02x', length($data) / 4 ); + my $retry = 0; +retry_write: + cmd( "04 $tag 00 $blocks 00 $hex_data", "write_blocks $tag [$blocks] $hex_data", sub { my $data = shift; @@ -243,13 +246,23 @@ sub write_blocks { my $blocks = substr($rest,8,1); warn "# WRITE ",as_hex($tag), " [$blocks]\n"; } elsif ( $rest = _matched $data => '04 06' ) { - die "ERROR ",as_hex($rest); + die "ERROR ",as_hex($data); } else { - die "UNSUPPORTED"; + die "UNSUPPORTED ", as_hex($data); } } ); + my $verify_blocks = read_blocks($tag); + die "can't find data from tag $tag" unless exists $verify_blocks->{$tag}; + + if ( join('', @{ $verify_blocks->{$tag} }) ne $data ) { + $retry++; + warn "ERROR reading data back from tag, retry $retry\n"; + die "ABORTED" if $retry == 10; + goto retry_write; + } + } sub read_afi { @@ -279,6 +292,16 @@ sub read_afi { return $afi; } +=head2 afi_retry + +This specified how many times will driver try to write afi to tag + + Biblio::RFID::Reader::3M810::afi_retry = 100; + +=cut + +our $afi_retry = 100; + sub write_afi { my $tag = shift; $tag = shift if ref $tag; @@ -298,7 +321,7 @@ retry: die "write_afi got $tag_back expected $tag" if $tag_back ne $tag; warn "# SECURITY ", hex_tag($tag), " AFI: $afi"; } elsif ( $rest = _matched $data => '09 06' ) { - if ( $retry++ <= 30 ) { # FIXME lover this number? + if ( $retry++ <= $afi_retry ) { # warn "ERROR writing AFI $afi to $tag retry $retry\n"; goto retry; }