/[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 82 by dpavlin, Fri Jul 9 23:10:05 2010 UTC revision 85 by dpavlin, Mon Jul 12 12:00:39 2010 UTC
# Line 10  use Getopt::Long; Line 10  use Getopt::Long;
10  use File::Slurp;  use File::Slurp;
11  use JSON;  use JSON;
12  use POSIX qw(strftime);  use POSIX qw(strftime);
13    use Time::HiRes;
14    
15  use IO::Socket::INET;  use IO::Socket::INET;
16    
17  my $debug = 2;  my $debug = 0;
18    
19  my $tags_data;  my $tags_data;
20  my $tags_security;  my $tags_security;
# Line 280  sub cpr_m02_checksum { Line 281  sub cpr_m02_checksum {
281                                  $crc = $crc >> 1;                                  $crc = $crc >> 1;
282                          }                          }
283                  }                  }
284                  warn sprintf('%d %04x', $i, $crc & 0xffff);  #               warn sprintf('%d %04x', $i, $crc & 0xffff);
285          }          }
286    
287          return pack('v', $crc);          return pack('v', $crc);
288  }  }
289    
290  sub cpr {  sub cpr {
291          my $hex = shift;          my ( $hex, $description ) = @_;
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;
295          my $checksum = cpr_m02_checksum($send);          my $checksum = cpr_m02_checksum($send);
296          $send .= $checksum;          $send .= $checksum;
297    
298          warn ">> ", as_hex( $send );          warn ">> ", as_hex( $send ), "\t\t[$description]\n";
299          writechunk( $send );          $port->write( $send );
300          my $r_len = read_bytes( 1, 'response length' );  
301            my $r_len = $port->read(1);
302    
303            while ( ! $r_len ) {
304                    warn "# wait for response length 0.050\n";
305                    Time::HiRes::sleep 0.050;
306                    $r_len = $port->read(1);
307            }
308    
309            warn "<< response len: ", as_hex($r_len), "\n";
310          $r_len = ord($r_len) - 1;          $r_len = ord($r_len) - 1;
311          my $data = read_bytes( $r_len, 'data' );          my $data = $port->read( $r_len );
312          warn "<< ", as_hex( $data );          warn "<< ", as_hex( $data );
313    
314            Time::HiRes::sleep 0.050;
315  }  }
316    
317  cpr( '00  52 00' );  # FF = COM-ADDR any
318    
319    cpr( 'FF  52 00',       'Boud Rate Detection' );
320    
321    cpr( 'FF  65',          'Get Software Version' );
322    
323    cpr( 'FF  66 00',       'Get Reader Info - General hard and firware' );
324    
325    cpr( 'FF  69',          'RF Reset' );
326    
327    cpr( 'FF  B0  01 00', 'ISO - Inventory' );
328    
329    #cpr( '', '?' );
330    
331  exit;  exit;
332  # initial hand-shake with device  # initial hand-shake with device
# Line 654  sub read_bytes { Line 678  sub read_bytes {
678                  my ( $c, $b ) = $port->read(1);                  my ( $c, $b ) = $port->read(1);
679                  die "no bytes on port: $!" unless defined $b;                  die "no bytes on port: $!" unless defined $b;
680                  warn "## got $c bytes: ", as_hex($b), "\n";                  warn "## got $c bytes: ", as_hex($b), "\n";
681                    last if $c == 0;
682                  $data .= $b;                  $data .= $b;
683          }          }
684          $desc ||= '?';          $desc ||= '?';

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

  ViewVC Help
Powered by ViewVC 1.1.26