增加node节点状态类型转发至MES接口&relay_device_status模 式,控制是否转发
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<?php
|
||||
namespace EdgeManager\EDataCapture;
|
||||
use \Workerman\Connection\AsyncTcpConnection;
|
||||
|
||||
class EDataCapture {
|
||||
function __construct(
|
||||
protected $dbconn,
|
||||
protected $no_dup_code,
|
||||
protected $relay_device_status,
|
||||
protected $post = NULL,
|
||||
protected $get = NULL,
|
||||
public $check_res = NULL,
|
||||
@@ -33,7 +35,7 @@ class EDataCapture {
|
||||
}
|
||||
|
||||
$res = pg_fetch_all(pg_query($this -> 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,
|
||||
|
||||
32
README.md
32
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": <string>,
|
||||
// value的类型需与type对应
|
||||
"value": <string | int >,
|
||||
"device_code": [string], // 必需字段
|
||||
"parent_device_code": [string], // 必需字段,对应MES中的code
|
||||
"batch": [string] // 可选字段
|
||||
},
|
||||
{
|
||||
"code": <string>,
|
||||
"value": <string | int | float | bool>,
|
||||
@@ -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
|
||||
```
|
||||
|
||||
前端调试:
|
||||
|
||||
Reference in New Issue
Block a user