Merge pull request 'v0.1' (#2) from develop into master
Reviewed-on: #2
This commit is contained in:
commit
61074c61c5
|
@ -0,0 +1,13 @@
|
||||||
|
/.git
|
||||||
|
/.settings
|
||||||
|
README.*
|
||||||
|
LICENSE
|
||||||
|
CHANGELOG.*
|
||||||
|
/docs
|
||||||
|
*.md
|
||||||
|
/.buildpath
|
||||||
|
/.project
|
||||||
|
/.gitignore
|
||||||
|
/.dockerignore
|
||||||
|
/temp-test
|
||||||
|
/build.sh
|
|
@ -0,0 +1,98 @@
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
name: SonarQube check
|
||||||
|
|
||||||
|
image_pull_secrets:
|
||||||
|
- dockerconfig
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
branch:
|
||||||
|
- develop
|
||||||
|
- ci-test
|
||||||
|
event:
|
||||||
|
- push
|
||||||
|
- custom
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: SonarQube check
|
||||||
|
image: sonarsource/sonar-scanner-cli
|
||||||
|
environment:
|
||||||
|
SONAR_PROJECT:
|
||||||
|
from_secret: sonarProjectId
|
||||||
|
SONAR_TOKEN:
|
||||||
|
from_secret: sonarToken
|
||||||
|
SONAR_HOST:
|
||||||
|
from_secret: sonarHost
|
||||||
|
TEST: test
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- sonar-scanner -Dsonar.projectKey=$${SONAR_PROJECT} -Dsonar.sources=. -Dsonar.host.url=$${SONAR_HOST} -Dsonar.login=$${SONAR_TOKEN}
|
||||||
|
depends_on:
|
||||||
|
- clone
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
name: Build image
|
||||||
|
|
||||||
|
image_pull_secrets:
|
||||||
|
- dockerconfig
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
ref:
|
||||||
|
- refs/heads/ci-test
|
||||||
|
- refs/heads/testing
|
||||||
|
- refs/heads/master
|
||||||
|
- refs/tags/*
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Prepare image
|
||||||
|
image: mxfox.ru/mxfox/fox-web-basic:latest
|
||||||
|
commands:
|
||||||
|
- |
|
||||||
|
apt-get update -y
|
||||||
|
apt-get install curl -y
|
||||||
|
cd /tmp
|
||||||
|
curl -sS https://getcomposer.org/installer -o composer-setup.php
|
||||||
|
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
|
||||||
|
DEBIAN_FRONTEND=noninteractive TZ=Europe/Moscow apt-get -y install tzdata
|
||||||
|
cd -
|
||||||
|
- composer install
|
||||||
|
- |
|
||||||
|
find . -name "*~" -prune -exec rm -rf '{}' \;
|
||||||
|
find . -name "*.bak" -prune -exec rm -rf '{}' \;
|
||||||
|
find . -name "*.old" -prune -exec rm -rf '{}' \;
|
||||||
|
find . -name ".git" -prune -exec rm -rf '{}' \;
|
||||||
|
find . -name ".settings" -prune -exec rm -rf '{}' \;
|
||||||
|
find . -name ".buildpath" -prune -exec rm -rf '{}' \;
|
||||||
|
find . -name ".project" -prune -exec rm -rf '{}' \;
|
||||||
|
find . -name "README.*" -prune -exec rm -rf '{}' \;
|
||||||
|
find . -name "*.md" -prune -exec rm -rf '{}' \;
|
||||||
|
find . -name "composer.*" -prune -exec rm -rf '{}' \;
|
||||||
|
find . -name ".travis*" -prune -exec rm -rf '{}' \;
|
||||||
|
find . -name "installed.json" -prune -exec rm -rf '{}' \;
|
||||||
|
find . -name "*.sample" -prune -exec rm -rf '{}' \;
|
||||||
|
rm -f composer.*
|
||||||
|
|
||||||
|
- name: Build docker image
|
||||||
|
image: mxfox.ru/mxfox/docker-dind.buildx:latest
|
||||||
|
privileged: true
|
||||||
|
environment:
|
||||||
|
DOCKER_AUTH:
|
||||||
|
from_secret: dockerconfig
|
||||||
|
IMAGE_PREFIX: mxfox.ru/mxfox/barcode-scanner-client
|
||||||
|
|
||||||
|
commands:
|
||||||
|
- buildx-bgstart.sh
|
||||||
|
- echo $${DOCKER_AUTH} > ~/.docker/config.json
|
||||||
|
- echo "CB ${CI_COMMIT_BRANCH}"
|
||||||
|
- echo "DT ${DRONE_TAG}"
|
||||||
|
- |
|
||||||
|
if [ -n "${DRONE_TAG}" ]
|
||||||
|
then
|
||||||
|
export xBuildSuffix=" -t $${IMAGE_PREFIX}:${DRONE_TAG} -t $${IMAGE_PREFIX}:latest --push"
|
||||||
|
else
|
||||||
|
export xBuildSuffix=" -t $${IMAGE_PREFIX}:${CI_COMMIT_BRANCH}-${CI_BUILD_NUMBER}-${DRONE_COMMIT_SHA:0:10} -t $${IMAGE_PREFIX}:${CI_COMMIT_BRANCH} --push"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- docker buildx build --platform linux/arm,linux/amd64,linux/arm64 . $${xBuildSuffix}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
/modules/*
|
||||||
|
!/modules/README.md
|
||||||
|
/storage/*
|
||||||
|
!/storage/README.md
|
||||||
|
/temp-test
|
||||||
|
/composer.lock
|
||||||
|
/vendor
|
||||||
|
.scannerwork
|
||||||
|
.vscode
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM php:8.1
|
||||||
|
COPY . /foxScanner
|
||||||
|
CMD ["php","/foxScanner/barcodeScanner.php"]
|
|
@ -1,2 +1,10 @@
|
||||||
# foxBarcodeScannerClient
|
# foxBarcodeScannerClient
|
||||||
|
|
||||||
|
Клиент для работы со сканером штрих-кода через последовательный порт. Клиент получает данные со сканера и отправляет в очередь RabbitMQ, указанную при регистрации. Регистрация происходит через считывания специального штрих-кода.
|
||||||
|
|
||||||
|
## Параметры конфигурации
|
||||||
|
* SCANNER_PORT - /dev/ttyACM0
|
||||||
|
* RABBITMQ_HOST
|
||||||
|
* RABBITMQ_USER
|
||||||
|
* RABBITMQ_PASSWORD
|
||||||
|
* RABBITMQ_USE_SSL
|
||||||
|
|
|
@ -0,0 +1,101 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once(__DIR__.'/vendor/autoload.php');
|
||||||
|
use PhpAmqpLib\Connection\AMQPStreamConnection;
|
||||||
|
use PhpAmqpLib\Connection\AMQPSSLConnection;
|
||||||
|
use PhpAmqpLib\Message\AMQPMessage;
|
||||||
|
|
||||||
|
|
||||||
|
$lineReadTimeout=1;
|
||||||
|
|
||||||
|
$port=getenv("SCANNER_PORT");
|
||||||
|
$rabbitHost=getenv("RABBITMQ_HOST");
|
||||||
|
$rabbitPort=getenv("RABBITMQ_PORT")?getenv("RABBITMQ_PORT"):5672;
|
||||||
|
$rabbitLogin=getenv("RABBITMQ_USER");
|
||||||
|
$rabbitPass=getenv("RABBITMQ_PASSWORD");
|
||||||
|
$rabbitUseSSL=getenv("RABBITMQ_USE_SSL")==="true";
|
||||||
|
$rabbitVirtualHost=getenv("RABBITMQ_VIRTUAL_HOST")?getenv("RABBITMQ_VIRTUAL_HOST"):"/";
|
||||||
|
|
||||||
|
|
||||||
|
$routingTag=null;
|
||||||
|
$connection=null;
|
||||||
|
$channel=null;
|
||||||
|
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
try {
|
||||||
|
$connection=rabbitConnect($rabbitHost, $rabbitPort, $rabbitLogin, $rabbitPass, $rabbitUseSSL);
|
||||||
|
$channel=$connection->channel();
|
||||||
|
scanner($channel, $port);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
print "Exception ".$e->getMessage()."\n";
|
||||||
|
$channel->close();
|
||||||
|
$connection->close();
|
||||||
|
$s=rand(5, 15);
|
||||||
|
print "Sleep $s seconds..";
|
||||||
|
sleep($s);
|
||||||
|
print "Ok\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function rabbitConnect($rabbitHost, $rabbitPort, $rabbitLogin, $rabbitPass, $rabbitUseSSL=false, $rabbitVirtualHost="/") {
|
||||||
|
if ($rabbitUseSSL) {
|
||||||
|
$ssl_opts=[
|
||||||
|
// set some SSL/TLS specific options
|
||||||
|
'verify_peer' => true,
|
||||||
|
'verify_peer_name' => true,
|
||||||
|
'allow_self_signed' => false
|
||||||
|
];
|
||||||
|
|
||||||
|
$connection = new AMQPSSLConnection($rabbitHost, $rabbitPort, $rabbitLogin, $rabbitPass, $rabbitVirtualHost, $ssl_opts);
|
||||||
|
} else {
|
||||||
|
$connection = new AMQPStreamConnection($rabbitHost, $rabbitPort, $rabbitLogin, $rabbitPass, $rabbitVirtualHost);
|
||||||
|
}
|
||||||
|
return $connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
function scanner($channel, $port) {
|
||||||
|
global $routingTag;
|
||||||
|
|
||||||
|
$fp = @fopen($port, "rb+");
|
||||||
|
if ($fp==null) {
|
||||||
|
throw new Exception("Scanner failed. Is it connected?");
|
||||||
|
} else {
|
||||||
|
print "Scanner connected\n";
|
||||||
|
if (!empty($routingTag)) {
|
||||||
|
$msg = new AMQPMessage(json_encode(["type"=>"service","data"=>"scannerReady"]));
|
||||||
|
$channel->basic_publish($msg, 'fox.barcode', $routingTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
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"]));
|
||||||
|
$channel->basic_publish($msg, 'fox.barcode', $routingTag);
|
||||||
|
}
|
||||||
|
throw new Exception("Stream read failed. Scanner disconnected?");
|
||||||
|
}
|
||||||
|
|
||||||
|
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"]));
|
||||||
|
$channel->basic_publish($msg, 'fox.barcode', $routingTag);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
print "Read: $rv[0]";
|
||||||
|
if (!empty($routingTag)) {
|
||||||
|
$msg = new AMQPMessage(json_encode(["type"=>"code","data"=>$rv[0]]));
|
||||||
|
$channel->basic_publish($msg, 'fox.barcode', $routingTag);
|
||||||
|
|
||||||
|
print " [S]";
|
||||||
|
} else {
|
||||||
|
print " [-]";
|
||||||
|
}
|
||||||
|
print "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"require" : {
|
||||||
|
"php-amqplib/php-amqplib": ">=3.0"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue