/[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 85 by dpavlin, Mon Jul 12 12:00:39 2010 UTC revision 86 by dpavlin, Fri Jul 16 09:31:56 2010 UTC
# Line 288  sub cpr_m02_checksum { Line 288  sub cpr_m02_checksum {
288  }  }
289    
290  sub cpr {  sub cpr {
291          my ( $hex, $description ) = @_;          my ( $hex, $description, $coderef ) = @_;
292          my $bytes = str2bytes($hex);          my $bytes = str2bytes($hex);
293          my $len = pack( 'c', length( $bytes ) + 3 );          my $len = pack( 'c', length( $bytes ) + 3 );
294          my $send = $len . $bytes;          my $send = $len . $bytes;
# Line 310  sub cpr { Line 310  sub cpr {
310          $r_len = ord($r_len) - 1;          $r_len = ord($r_len) - 1;
311          my $data = $port->read( $r_len );          my $data = $port->read( $r_len );
312          warn "<< ", as_hex( $data );          warn "<< ", as_hex( $data );
313            
314            my $t = Time::HiRes::time;
315    
316          Time::HiRes::sleep 0.050;          $coderef->( $data ) if $coderef;
317    
318            my $dt = Time::HiRes::time - $t;
319            if ( $dt < 0.050 ) {
320                    my $s = 0.050 - $dt;
321                    warn "# sleep for more $s\n";
322                    Time::HiRes::sleep $s;
323            }
324  }  }
325    
326  # FF = COM-ADDR any  # FF = COM-ADDR any
# Line 324  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  cpr( 'FF  B0  01 00', 'ISO - Inventory' );  my $inventory;
337    
338    while(1) {
339    
340    cpr( 'FF  B0  01 00', 'ISO - Inventory', sub {
341            my $data = shift;
342            my $data_sets = ord(substr($data,3,1));
343            $data = substr($data,4);
344            foreach ( 1 .. $data_sets ) {
345                    my $tr_type = substr($data,0,1);
346                    my $dsfid   = substr($data,1,1);
347                    my $uid     = substr($data,2,8);
348                    $inventory->{$uid}++;
349                    $data = substr($data,10);
350                    warn "# TAG $_ ",as_hex( $tr_type, $dsfid, $uid ),$/;
351            }
352            warn "inventory: ",dump($inventory);
353    });
354    
355    }
356    
357  #cpr( '', '?' );  #cpr( '', '?' );
358    

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

  ViewVC Help
Powered by ViewVC 1.1.26