scan only 3M reader in checkin/checkout
[Biblio-RFID.git] / scripts / RFID-JSONP-server.pl
index d8ee4f3..cc1d279 100755 (executable)
@@ -22,7 +22,7 @@ use URI;
 use POSIX qw(strftime);
 use Encode;
 
-my $debug = 1;
+my $debug = 0;
 my $listen = '127.0.0.1:9000';
 $listen = ':9000';
 my $reader;
@@ -193,8 +193,16 @@ sub http_server {
                                        }
                                        close($fh);
                                }
-                       } elsif ( $method =~ m{/scan} ) {
-                               my @tags = $rfid->tags;
+                       } elsif ( $method =~ m{/scan(/only/(.+))?} ) {
+                               my $only = $2;
+                               my @tags = $rfid->tags( reader => sub {
+                                       my $reader = shift;
+                                       return 1 unless $only;
+                                       if ( ref($reader) =~ m/$only/i ) {
+                                               return 1;
+                                       }
+                                       return 0;
+                               });
                                my $json = { time => time() };
                                foreach my $tag ( @tags ) {
                                        my $hash = $rfid->to_hash( $tag );
@@ -285,7 +293,8 @@ sub http_server {
                                                $rfid->write_afi( $sid => chr( $afi->{secure} ) );
                                        }
                                } else {
-                                       print $client "HTTP/1.0 500 $method not implemented\r\n\r\n";
+                                       print $client "HTTP/1.0 501 $method not implemented\r\n\r\n";
+                                       warn "ERROR 501 $request\n";
                                }
 
                                if ( $hash ) {
@@ -295,9 +304,11 @@ sub http_server {
 
                        } else {
                                print $client "HTTP/1.0 404 Unkown method\r\n\r\n";
+                               warn "ERROR 404 $request\n";
                        }
                } else {
                        print $client "HTTP/1.0 500 No method\r\n\r\n";
+                       warn "ERROR 500 $request\n";
                }
                close $client;