X-Git-Url: http://git.rot13.org/?p=Biblio-RFID.git;a=blobdiff_plain;f=lib%2FBiblio%2FRFID%2FReader%2F3M810.pm;h=467b4e7036d9d192604277a5f2f9c69a54fd3ae9;hp=0e2090b4c70c0b4378275d6f1aadcf1fb4593931;hb=821fd03150ccc8e8802e6b5507e61480aa7552ef;hpb=9e434049dc2b793e623e81ed51f1463f97d4ed6f diff --git a/lib/Biblio/RFID/Reader/3M810.pm b/lib/Biblio/RFID/Reader/3M810.pm index 0e2090b..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,12 +292,25 @@ 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; my $afi = shift || die "no afi?"; $afi = as_hex $afi; + my $retry = 0; + +retry: cmd( "09 $tag $afi", "write_afi $tag $afi", sub { @@ -293,13 +319,20 @@ sub write_afi { if ( my $rest = _matched $data => '09 00' ) { my $tag_back = hex_tag substr($rest,0,8); die "write_afi got $tag_back expected $tag" if $tag_back ne $tag; - warn "# SECURITY ", hex_tag($tag), " AFI: ", as_hex($afi); + warn "# SECURITY ", hex_tag($tag), " AFI: $afi"; } elsif ( $rest = _matched $data => '09 06' ) { - die "ERROR writing AFI ", as_hex($afi), " to $tag ", as_hex($data); + if ( $retry++ <= $afi_retry ) { +# warn "ERROR writing AFI $afi to $tag retry $retry\n"; + goto retry; + } + die "ERROR writing AFI $afi to $tag ", as_hex($data); } else { die "IGNORED ",as_hex($data); } }); + + warn "INFO: tag $tag AFI $afi retry: $retry\n"; + warn "## write_afi ", dump( $tag, $afi ); return $afi; }