/[RFID]/cpr-m02.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /cpr-m02.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 38 by dpavlin, Mon Jun 1 18:36:42 2009 UTC revision 40 by dpavlin, Mon Jun 1 21:17:12 2009 UTC
# Line 247  sub read_tag_data { Line 247  sub read_tag_data {
247                  die "got block $ord, expected block $expected_ord from ",dump( $block ) if $ord != $expected_ord;                  die "got block $ord, expected block $expected_ord from ",dump( $block ) if $ord != $expected_ord;
248                  my $data  = substr( $block, 2 );                  my $data  = substr( $block, 2 );
249                  die "data payload should be 4 bytes" if length($data) != 4;                  die "data payload should be 4 bytes" if length($data) != 4;
250                  warn sprintf "## tag %9s %02d %s |%-4s|\n", $tag, $ord, as_hex( $data ), $data;                  warn sprintf "## tag %9s %02d: %s |%-4s|\n", $tag, $ord, as_hex( $data ), $data;
251                  $tag_data_block->{$tag}->[ $ord ] = $data;                  $tag_data_block->{$tag}->[ $ord ] = $data;
252          }          }
253          $tags_data->{ $tag } = join('', @{ $tag_data_block->{$tag} });          $tags_data->{ $tag } = join('', @{ $tag_data_block->{$tag} });
# Line 317  sub write_tag { Line 317  sub write_tag {
317                  $hex_data =~ s{\s+}{}g;                  $hex_data =~ s{\s+}{}g;
318          } else {          } else {
319    
                 # pad to block size  
320                  $data .= "\0" x ( 4 - ( length($data) % 4 ) );                  $data .= "\0" x ( 4 - ( length($data) % 4 ) );
321    
322                  my $max_len = 7 * 4;                  my $max_len = 7 * 4;
# Line 331  sub write_tag { Line 330  sub write_tag {
330          }          }
331    
332          my $len = length($hex_data) / 2;          my $len = length($hex_data) / 2;
333          my $blocks = sprintf('%02x', $len / 4);          # pad to block size
334            $hex_data .= '00' x ( 4 - $len % 4 );
335            my $blocks = sprintf('%02x', length($hex_data) / 4);
336    
337          print "write_tag $tag = ",dump( $data ), " [$len/$blocks] == $hex_data\n";          print "write_tag $tag = ",dump( $data ), " [$len/$blocks] == $hex_data\n";
338    
339          cmd(          cmd(
340                  "d6 00  ff  04  $tag  00 $blocks 00  $hex_data  ffff", "write $tag",                  "d6 00  ff  04  $tag  00 $blocks 00  $hex_data  ffff", "write $tag",
341                  "d6 00  0d  04 00  $tag  $blocks  afb1", sub { assert() },                  "d6 00  0d  04 00  $tag  $blocks  afb1", sub { assert() },
342          ) foreach ( 1 .. 3 ); # xxx 3m software does this three times!          ); # foreach ( 1 .. 3 ); # XXX 3m software does this three times!
343    
344          my $to = $path;          my $to = $path;
345          $to .= '.' . time();          $to .= '.' . time();
# Line 398  print "Port closed\n"; Line 399  print "Port closed\n";
399  sub writechunk  sub writechunk
400  {  {
401          my $str=shift;          my $str=shift;
 warn "DEBUG: ", as_hex($str);  
402          my $count = $port->write($str);          my $count = $port->write($str);
403          my $len = length($str);          my $len = length($str);
404          die "wrong write length $count != $len in ",as_hex( $str ) if $count != $len;          die "wrong write length $count != $len in ",as_hex( $str ) if $count != $len;
# Line 440  sub skip_assert { Line 440  sub skip_assert {
440  sub assert {  sub assert {
441          my ( $from, $to ) = @_;          my ( $from, $to ) = @_;
442    
443            return unless $assert->{expect};
444    
445          $from ||= 0;          $from ||= 0;
446          $to = length( $assert->{expect} ) if ! defined $to;          $to = length( $assert->{expect} ) if ! defined $to;
447    
# Line 517  sub readchunk { Line 519  sub readchunk {
519          } sort { length($a) <=> length($b) } keys %$dispatch;          } sort { length($a) <=> length($b) } keys %$dispatch;
520          warn "?? payload dispatch to ",dump( $payload, $dispatch, $to ) if $debug;          warn "?? payload dispatch to ",dump( $payload, $dispatch, $to ) if $debug;
521    
522          if ( defined $to ) {          if ( defined $to && $payload ) {
523                  my $rest = substr( $payload, length($to) );                  my $rest = substr( $payload, length($to) );
524                  warn "## DISPATCH payload to with rest", dump( $payload, $to, $rest ) if $debug;                  warn "## DISPATCH payload to with rest", dump( $payload, $to, $rest ) if $debug;
525                  $dispatch->{ $to }->( $rest );                  $dispatch->{ $to }->( $rest );

Legend:
Removed from v.38  
changed lines
  Added in v.40

  ViewVC Help
Powered by ViewVC 1.1.26