From d169ba986d391d6168299f0f7a2678fc6f5a8c43 Mon Sep 17 00:00:00 2001 From: wu <2468489804@qq.com> Date: Wed, 31 Aug 2022 17:51:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0node=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=B1=BB=E5=9E=8B=E8=BD=AC=E5=8F=91=E8=87=B3?= =?UTF-8?q?MES=E6=8E=A5=E5=8F=A3&relay=5Fdevice=5Fstatus=E6=A8=A1=20?= =?UTF-8?q?=E5=BC=8F,=E6=8E=A7=E5=88=B6=E6=98=AF=E5=90=A6=E8=BD=AC?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EdgeManager.php | 16 +++++++++-- EdgeManager/EDataCapture/EDataCapture.php | 35 ++++++++++++++++++++--- README.md | 32 ++++++++++++++++++++- 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/EdgeManager.php b/EdgeManager.php index 9d85985..6b6f593 100644 --- a/EdgeManager.php +++ b/EdgeManager.php @@ -9,13 +9,14 @@ require_once __DIR__ . '/vendor/autoload.php'; use EdgeManager\EDataCapture\{ EDataCapture, ENodeConfigure }; use EdgeManager\EController\{ EConfigure, ECommand }; -$options = getopt('h::', ['no_dup_code', 'server_name:', 'port::', 'user:', 'password:', 'help::']); +$options = getopt('h::', ['no_dup_code', 'relay_device_status', 'server_name:', 'port::', 'user:', 'password:', 'help::']); if (array_key_exists('h', $options) or array_key_exists('help', $options)) { print_r( "EdgeManager使用说明: --no_dup_code 禁止code在不同的working subclass间复用 + --relay_device_status 不判断是否是设备状态并转发到MES接口 --server_name pg实例的FQDN --user pg实例的用户名 --port pg实例的端口号 @@ -156,7 +157,7 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) { } } } else if ($post -> action === 'set_node_data') { - $data_capture = new EDataCapture($dbconn, no_dup_code: $options['no_dup_code'] ?? true, post: $post); + $data_capture = new EDataCapture($dbconn, no_dup_code: $options['no_dup_code'] ?? true, relay_device_status: $options['relay_device_status'] ?? true, post: $post); if ($data_capture -> check_res === 'WRONG_WORKING_SUBCLASS') { $response = new Response(200, [ 'Content-Type' => 'application/json;charset=utf-8', @@ -406,6 +407,17 @@ $consumer -> onMessage = function(TcpConnection $connection, $task_data) { 'code' => 0, 'msg' => 'Success' ))); + } else if ($task_data -> action === 'set_device_status') { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, 'http://8.sctmes.com:22347'); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); + curl_setopt($ch, CURLOPT_HEADER, 1); + curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($task_data) ); + curl_setopt($ch, CURLOPT_TIMEOUT, 10); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $return = curl_exec($ch); + curl_close($ch); } }; diff --git a/EdgeManager/EDataCapture/EDataCapture.php b/EdgeManager/EDataCapture/EDataCapture.php index 22248a3..de67447 100644 --- a/EdgeManager/EDataCapture/EDataCapture.php +++ b/EdgeManager/EDataCapture/EDataCapture.php @@ -1,10 +1,12 @@ dbconn, sprintf( - "SELECT code, type + "SELECT code, type, category FROM hf_mes_scada_data_capture_node_configure WHERE working_subclass = '%s'", $this -> working_subclass @@ -41,13 +43,13 @@ class EDataCapture { $code_type = &$this -> code_type; array_walk($res, function($v, $k) use (&$code_type) { - $code_type[$v['code']] = $v['type']; + $code_type[$v['code']] = array('type' => $v['type'], 'category' => $v['category']); }); foreach ($this -> post -> param -> data as &$row) { - if (($code_type[$row -> code]) === 'float' and is_int($row -> value)) + if (($code_type[$row -> code]['type']) === 'float' and is_int($row -> value)) $row -> value = (float) number_format((float) $row -> value, 1, '.', ''); - $check_func = 'is_' . $code_type[$row -> code]; + $check_func = 'is_' . $code_type[$row -> code['type']]; if (!$check_func($row -> value)) { $this -> check_res = 'MISMATCH_TYPE'; return; @@ -57,6 +59,31 @@ class EDataCapture { $this -> check_res = 'NO_DEVICE_CODE'; return; } + if($this -> relay_device_status && $code_type[$row -> code]['category'] === 'DEVICE_STATUS'){ + $status = array(1 => 'IDLE', 2 => 'RUN', 3 => 'FINISH', 4 => 'TROUBLE', 5 => 'PAUSE', 6 => 'OFFLINE'); + if(!is_int($row -> value) && !in_array($row -> value , $status)){ + $this -> check_res = 'MISMATCH_TYPE'; + return; + } + $task_data = array( + 'action' => 'set_device_status', + 'param' => array( + "device_code" => $row -> parent_device_code, + "status" => is_int($row -> value) ? $status[$row -> value] : $row -> value, + "errcode" => $row -> errcode ?? NULL, + "msg" => $row -> msg ?? NULL, + ), + ); + $task_connection = new AsyncTcpConnection('Text://127.0.0.1:19998'); + + $task_connection -> send(json_encode($task_data)); + $task_connection -> onMessage = function(AsyncTcpConnection $task_connection, $task_result){ + $task_connection -> close(); + }; + // 执行异步连接 + $task_connection->connect(); + } + $this -> data[$row -> code][] = [ 'value' => $row -> value, 'device_code' => $row -> device_code, diff --git a/README.md b/README.md index edf437e..531609c 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,24 @@ > > 无需指定数值类型,服务端会自动根据已添加的节点信息检查,若不符则会报错。 + +**上传设备状态** + +> 数据节点的数据类型在后台设定为设备状态时,该节点上传的值只能上传int或string两种类型。 +> +> 并且int或string这两种类型,只能上传下方表格中int或string指定的值,若不符则会报错。 +> +> 上传对应的设备状态parent_device_code为必传字段 + +| int类型 | string类型 | 描述 | +| ----- | ----- | ----- | +| 1 | IDLE | 设备已经初始化,再等待工作 | +| 2 | RUN | 设备在工作 | +| 3 | FINISH | 工序结束后,托盘还没取出时,设备为FINISH,取出后变为IDLE状态 | +| 4 | TROUBLE | 设备有问题,需要维修,这时msg有相应的关键字 | +| 5 | PAUSE | 设备通过手工操作变成暂停状态 | +| 6 | OFFLINE | 设备处于离线状态 | + ```json { "action": "set_node_data", @@ -42,6 +60,15 @@ "parent_device_code": [string], // 可选字段,对应MES中的code "batch": [string] // 可选字段 }, + { + //code的值在后台的数据类别为设备状态类型时 + "code": , + // value的类型需与type对应 + "value": , + "device_code": [string], // 必需字段 + "parent_device_code": [string], // 必需字段,对应MES中的code + "batch": [string] // 可选字段 + }, { "code": , "value": , @@ -97,6 +124,7 @@ } ``` + ## 使用指北 本项目可独立运行,也可作为MES的插件使用。 @@ -274,7 +302,9 @@ docker exec -it edge_manager bash ```bash # In container -php EdgeManager.php --no_dup_code --server_name=GPU-server-01 --user=postgres --password=big_dick start +# --no_dup_code:禁止code在不同的working subclass间复用 +# --relay_device_status:不判断是否是设备状态并转发到MES接口 +php EdgeManager.php --no_dup_code --relay_device_status --server_name=GPU-server-01 --user=postgres --password=big_dick start ``` 前端调试: