diff --git a/barcodeScanner.php b/barcodeScanner.php index 5ce8ee1..a3f4a41 100644 --- a/barcodeScanner.php +++ b/barcodeScanner.php @@ -22,16 +22,16 @@ $connection=null; $channel=null; -while(1) { +while (1) { try { - $connection=rabbitConnect($rabbitHost,$rabbitPort,$rabbitLogin,$rabbitPass,$rabbitUseSSL); + $connection=rabbitConnect($rabbitHost, $rabbitPort, $rabbitLogin, $rabbitPass, $rabbitUseSSL); $channel=$connection->channel(); - scanner($channel,$port); + scanner($channel, $port); } catch (Exception $e) { print "Exception ".$e->getMessage()."\n"; $channel->close(); $connection->close(); - $s=rand(5,15); + $s=rand(5, 15); print "Sleep $s seconds.."; sleep($s); print "Ok\n"; @@ -47,9 +47,9 @@ function rabbitConnect($rabbitHost, $rabbitPort, $rabbitLogin, $rabbitPass, $rab 'allow_self_signed' => false ]; - $connection = new AMQPSSLConnection($rabbitHost, $rabbitPort, $rabbitLogin, $rabbitPass,$rabbitVirtualHost,$ssl_opts); + $connection = new AMQPSSLConnection($rabbitHost, $rabbitPort, $rabbitLogin, $rabbitPass, $rabbitVirtualHost, $ssl_opts); } else { - $connection = new AMQPStreamConnection($rabbitHost, $rabbitPort, $rabbitLogin, $rabbitPass,$rabbitVirtualHost); + $connection = new AMQPStreamConnection($rabbitHost, $rabbitPort, $rabbitLogin, $rabbitPass, $rabbitVirtualHost); } return $connection; } @@ -68,9 +68,9 @@ function scanner($channel, $port) { } } - while(1) { - $buffer = fgets($fp,4096); - $rv=explode("\n",$buffer); + while (1) { + $buffer = fgets($fp, 4096); + $rv=explode("\n", $buffer); if ($buffer === false) { if (!empty($routingTag)) { $msg = new AMQPMessage(json_encode(["type"=>"service","data"=>"scannerFailed"])); @@ -79,7 +79,7 @@ function scanner($channel, $port) { throw new Exception("Stream read failed. Scanner disconnected?"); } - if (preg_match('/^fxc([0-9a-f]{20})xf$/',$buffer,$ref)) { + if (preg_match('/^fxc([0-9a-f]{20})xf$/', $buffer, $ref)) { print "Pairing request. Routing tag: $ref[1]\n"; $routingTag=$ref[1]; $msg = new AMQPMessage(json_encode(["type"=>"service","data"=>"scannerRegistered"])); @@ -91,11 +91,11 @@ function scanner($channel, $port) { $msg = new AMQPMessage(json_encode(["type"=>"code","data"=>$rv[0]])); $channel->basic_publish($msg, 'fox.barcode', $routingTag); - print " [S]"; + print " [S]"; } else { print " [-]"; } print "\n"; } } -} \ No newline at end of file +}