/[RFID]/3m-810.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 /3m-810.pl

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

revision 50 by dpavlin, Wed Jun 24 09:30:28 2009 UTC revision 58 by dpavlin, Sat Jul 4 08:33:56 2009 UTC
# Line 14  use IO::Socket::INET; Line 14  use IO::Socket::INET;
14    
15  my $debug = 0;  my $debug = 0;
16    
17  my $meteor_server = '192.168.1.13:4671';  my $tags_data;
18    my $tags_security;
19    my $visible_tags;
20    
21    my $meteor_server; # = '192.168.1.13:4671';
22  my $meteor_fh;  my $meteor_fh;
23    
24  sub meteor {  sub meteor {
# Line 59  sub http_server { Line 63  sub http_server {
63                  my ($client,$path) = @_;                  my ($client,$path) = @_;
64    
65                  $path = "www/$path";                  $path = "www/$path";
66                    $path .= 'rfid.html' if $path =~ m{/$};
67    
68                  return unless -e $path;                  return unless -e $path;
69    
# Line 96  sub http_server { Line 101  sub http_server {
101                                  warn "WEB >> $path" if $debug;                                  warn "WEB >> $path" if $debug;
102                          } elsif ( $method =~ m{/scan} ) {                          } elsif ( $method =~ m{/scan} ) {
103                                  my $tags = scan_for_tags();                                  my $tags = scan_for_tags();
104                                  my $json = {};                                  my $json = { time => time() };
105                                  map {                                  map {
106                                          my $d = decode_tag($_);                                          my $d = decode_tag($_);
107                                          $d->{sid} = $_;                                          $d->{sid} = $_;
108                                            $d->{security} = $tags_security->{$_};
109                                          push @{ $json->{tags} },  $d;                                          push @{ $json->{tags} },  $d;
110                                  } keys %$tags;                                  } keys %$tags;
111                                  print $client "HTTP/1.0 200 OK\r\nContent-Type: application/x-javascript\r\n\r\n",                                  print $client "HTTP/1.0 200 OK\r\nContent-Type: application/x-javascript\r\n\r\n",
# Line 205  it under the same terms ans Perl itself. Line 211  it under the same terms ans Perl itself.
211    
212  =cut  =cut
213    
 my $tags_data;  
 my $visible_tags;  
   
214  my $item_type = {  my $item_type = {
215          1 => 'Book',          1 => 'Book',
216          6 => 'CD/CD ROM',          6 => 'CD/CD ROM',
# Line 297  sub scan_for_tags { Line 300  sub scan_for_tags {
300  if ( $http_server ) {  if ( $http_server ) {
301          http_server;          http_server;
302  } else {  } else {
303          scan_for_tags while 1;          while (1) {
304                    scan_for_tags;
305                    sleep 1;
306            }
307  }  }
308    
309  die "over and out";  die "over and out";
# Line 309  sub update_visible_tags { Line 315  sub update_visible_tags {
315          $visible_tags = {};          $visible_tags = {};
316    
317          foreach my $tag ( @tags ) {          foreach my $tag ( @tags ) {
318                    $visible_tags->{$tag}++;
319                  if ( ! defined $last_visible_tags->{$tag} ) {                  if ( ! defined $last_visible_tags->{$tag} ) {
320                          if ( defined $tags_data->{$tag} ) {                          if ( defined $tags_data->{$tag} ) {
321  #                               meteor( 'in-range', $tag );  #                               meteor( 'in-range', $tag );
# Line 316  sub update_visible_tags { Line 323  sub update_visible_tags {
323                                  meteor( 'read', $tag );                                  meteor( 'read', $tag );
324                                  read_tag( $tag );                                  read_tag( $tag );
325                          }                          }
                         $visible_tags->{$tag}++;  
326                  } else {                  } else {
327                          warn "## using cached data for $tag" if $debug;                          warn "## using cached data for $tag" if $debug;
328                  }                  }
# Line 432  sub read_tag { Line 438  sub read_tag {
438                          ( $from_tag, $security ) = ( substr($rest,0,8), substr($rest,8,1) );                          ( $from_tag, $security ) = ( substr($rest,0,8), substr($rest,8,1) );
439                          die "security from other tag: ",as_hex( $from_tag ) if $from_tag ne str2bytes( $tag );                          die "security from other tag: ",as_hex( $from_tag ) if $from_tag ne str2bytes( $tag );
440                          $security = as_hex( $security );                          $security = as_hex( $security );
441                            $tags_security->{$tag} = $security;
442                          warn "# SECURITY $tag = $security\n";                          warn "# SECURITY $tag = $security\n";
443                  }                  }
444          );          );
# Line 657  sub readchunk { Line 664  sub readchunk {
664                  warn "## DISPATCH payload to with rest", dump( $payload, $to, $rest ) if $debug;                  warn "## DISPATCH payload to with rest", dump( $payload, $to, $rest ) if $debug;
665                  $dispatch->{ $to }->( $rest );                  $dispatch->{ $to }->( $rest );
666          } else {          } else {
667                  print "NO DISPATCH for ",dump( $full ),"\n";                  print "NO DISPATCH for ",as_hex( $full ),"\n";
668          }          }
669    
670          return $data;          return $data;

Legend:
Removed from v.50  
changed lines
  Added in v.58

  ViewVC Help
Powered by ViewVC 1.1.26