--- 3m-810.pl 2009/04/06 13:10:40 29 +++ 3m-810.pl 2009/04/08 14:48:22 33 @@ -101,6 +101,23 @@ my $tags_data; my $visible_tags; +my $item_type = { + 1 => 'Book', + 6 => 'CD/CD ROM', + 2 => 'Magazine', + 13 => 'Book with Audio Tape', + 9 => 'Book with CD/CD ROM', + 0 => 'Other', + + 5 => 'Video', + 4 => 'Audio Tape', + 3 => 'Bound Journal', + 8 => 'Book with Diskette', + 7 => 'Diskette', +}; + +warn "## known item type: ",dump( $item_type ) if $debug; + my $port=new Device::SerialPort($device) || die "can't open serial port $device: $!\n"; warn "using $device $handshake $baudrate $databits $parity $stopbits" if $debug; $handshake=$port->handshake($handshake); @@ -222,7 +239,9 @@ $tag_data_block->{$tag}->[ $ord ] = $data; } $tags_data->{ $tag } = join('', @{ $tag_data_block->{$tag} }); - print "DATA $tag ",dump( $tags_data ), "\n"; + + my $item_type_nr = ord(substr( $tags_data->{$tag}, 3, 1 )); + print "DATA $tag ",dump( $tags_data ), " item type: ", ( $item_type->{ $item_type_nr } || "UNKWOWN '$item_type_nr' in " . dump( $item_type ) ), "\n"; } sub read_tag { @@ -249,6 +268,28 @@ } ); + my $security; + + cmd( + "D6 00 0B 0A $tag 1234", "check security $tag", + "D6 00 0D 0A 00", sub { + my $rest = shift; + my $from_tag; + ( $from_tag, $security ) = ( substr($rest,0,8), substr($rest,8,1) ); + die "security from other tag: ",as_hex( $from_tag ) if $from_tag ne str2bytes( $tag ); + $security = as_hex( $security ); + warn "# SECURITY $tag = $security\n"; + } + ); + + my $data = $tags_data->{$tag} || die "no data for $tag"; + my ( $u1, $set_item, $u2, $type, $content, $br_lib, $custom ) = unpack('C4Z16Nl>',$data); + my $set = ( $set_item & 0xf0 ) >> 4; + my $total = ( $set_item & 0x0f ); + my $branch = $br_lib >> 20; + my $library = $br_lib & 0x000fffff; + print "TAG $tag [$u1] set: $set/$total [$u2] type: $type '$content' branch: $branch library: $library custom: $custom security: $security\n"; + } sub write_tag { @@ -258,10 +299,14 @@ my $data = read_file( $path ); - print "write_tag $tag = $data\n"; + $data = substr($data,0,16); + + my $hex_data = unpack('H*', $data) . ' 00' x ( 16 - length($data) ); + + print "write_tag $tag = $data ",dump( $hex_data ); cmd( - "D6 00 26 04 $tag 00 06 00 04 11 00 01 61 61 61 61 62 62 62 62 63 63 63 63 64 64 64 64 00 00 00 00 FD3B", "write $tag", + "D6 00 26 04 $tag 00 06 00 04 11 00 01 $hex_data 00 00 00 00 FD3B", "write $tag", "D6 00 0D 04 00 $tag 06 AFB1", sub { assert() }, ) foreach ( 1 .. 3 ); # XXX 3M software does this three times! @@ -271,6 +316,7 @@ rename $path, $to; print ">> $to\n"; + delete $tags_data->{$tag}; # force re-read of tag } exit;