/[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 86 by dpavlin, Fri Jul 16 09:31:56 2010 UTC revision 89 by dpavlin, Fri Jul 16 13:50:52 2010 UTC
# Line 287  sub cpr_m02_checksum { Line 287  sub cpr_m02_checksum {
287          return pack('v', $crc);          return pack('v', $crc);
288  }  }
289    
290    sub cpr_psst_wait {
291            # Protocol Start Synchronization Time (PSST): 5ms < data timeout 12 ms
292            Time::HiRes::sleep 0.005;
293    }
294    
295  sub cpr {  sub cpr {
296          my ( $hex, $description, $coderef ) = @_;          my ( $hex, $description, $coderef ) = @_;
297          my $bytes = str2bytes($hex);          my $bytes = str2bytes($hex);
# Line 298  sub cpr { Line 303  sub cpr {
303          warn ">> ", as_hex( $send ), "\t\t[$description]\n";          warn ">> ", as_hex( $send ), "\t\t[$description]\n";
304          $port->write( $send );          $port->write( $send );
305    
306            cpr_psst_wait;
307    
308          my $r_len = $port->read(1);          my $r_len = $port->read(1);
309    
310          while ( ! $r_len ) {          while ( ! $r_len ) {
311                  warn "# wait for response length 0.050\n";                  warn "# wait for response length 5ms\n";
312                  Time::HiRes::sleep 0.050;                  cpr_psst_wait;
313                  $r_len = $port->read(1);                  $r_len = $port->read(1);
314          }          }
315    
316          warn "<< response len: ", as_hex($r_len), "\n";          my $data_len = ord($r_len) - 1;
317          $r_len = ord($r_len) - 1;          my $data = $port->read( $data_len );
318          my $data = $port->read( $r_len );          warn "<< ", as_hex( $r_len . $data ),"\n";
319          warn "<< ", as_hex( $data );  
320                    cpr_psst_wait;
         my $t = Time::HiRes::time;  
321    
322          $coderef->( $data ) if $coderef;          $coderef->( $data ) if $coderef;
323    
         my $dt = Time::HiRes::time - $t;  
         if ( $dt < 0.050 ) {  
                 my $s = 0.050 - $dt;  
                 warn "# sleep for more $s\n";  
                 Time::HiRes::sleep $s;  
         }  
324  }  }
325    
326  # FF = COM-ADDR any  # FF = COM-ADDR any
# Line 333  cpr( 'FF  66 00',      'Get Reader Info - Gen Line 333  cpr( 'FF  66 00',      'Get Reader Info - Gen
333    
334  cpr( 'FF  69',          'RF Reset' );  cpr( 'FF  69',          'RF Reset' );
335    
336    
337    sub cpr_read {
338            my $uid = shift;
339            my $hex_uid = as_hex($uid);
340    
341            cpr( "FF  B0 23  01  $hex_uid 00 04", "Read Multiple Blocks $hex_uid" );
342            cpr( "FF  B0 2B  01  $hex_uid", "Get System Information $hex_uid", sub {
343                    my $data = shift;
344    
345                    warn "# data ",as_hex($data);
346    
347                    my $DSFID    = substr($data,5-2,1);
348                    my $UID      = substr($data,6-2,8);
349                    my $AFI      = substr($data,14-2,1);
350                    my $MEM_SIZE = substr($data,15-2,2);
351                    my $IC_REF   = substr($data,17-2,1);
352    
353                    warn "# split ",as_hex( $DSFID, $UID, $AFI, $MEM_SIZE, $IC_REF );
354    
355            });
356    }
357    
358    
359  my $inventory;  my $inventory;
360    
361  while(1) {  while(1) {
362    
363  cpr( 'FF  B0  01 00', 'ISO - Inventory', sub {  cpr( 'FF  B0  01 00', 'ISO - Inventory', sub {
364          my $data = shift;          my $data = shift;
365            if (length($data) < 5 + 2 ) {
366                    warn "# no tags in range\n";
367                    return;
368            }
369          my $data_sets = ord(substr($data,3,1));          my $data_sets = ord(substr($data,3,1));
370          $data = substr($data,4);          $data = substr($data,4);
371          foreach ( 1 .. $data_sets ) {          foreach ( 1 .. $data_sets ) {
372                  my $tr_type = substr($data,0,1);                  my $tr_type = substr($data,0,1);
373                    die "FIXME only TR-TYPE=3 ISO 15693 supported" unless $tr_type eq "\x03";
374                  my $dsfid   = substr($data,1,1);                  my $dsfid   = substr($data,1,1);
375                  my $uid     = substr($data,2,8);                  my $uid     = substr($data,2,8);
376                  $inventory->{$uid}++;                  $inventory->{$uid}++;
377                  $data = substr($data,10);                  $data = substr($data,10);
378                  warn "# TAG $_ ",as_hex( $tr_type, $dsfid, $uid ),$/;                  warn "# TAG $_ ",as_hex( $tr_type, $dsfid, $uid ),$/;
379    
380                    cpr_read( $uid );
381          }          }
382          warn "inventory: ",dump($inventory);          warn "inventory: ",dump($inventory);
383  });  });

Legend:
Removed from v.86  
changed lines
  Added in v.89

  ViewVC Help
Powered by ViewVC 1.1.26