Commit 68275847 authored by 冯超鹏's avatar 冯超鹏

no message

parent 7fc61b65
<?php
namespace App\Console\Commands;
use App\Http\Controllers\Auth\ZehongTcpController;
use Illuminate\Support\Facades\Log;
use Illuminate\Console\Command;
class zehongTcp extends Command
{
public $tcp;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'zehongTcp {action?}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'zehongTcp';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$action = $this->argument('action');
switch ($action) {
case 'close':
break;
default:
$this->start();//开启tcp服务
break;
}
}
//开启
public function start()
{
$url = config('public.swooletcpurl');
$this->tcp = new \swoole_server('0.0.0.0', 9503, SWOOLE_PROCESS);
$this->tcp->set([
'worker_num' => 2,//设置启动的 Worker 进程数
'max_request' => 30,//最大任务数
'max_connection' => 50,
'daemonize' => 0,//守护进程
'backlog' => 128,
'heartbeat_check_interval' => 30,
'heartbeat_idle_time' => 65,
]);
//监听连接进入事件
$this->tcp->on('Connect', function ($serv, $fd) {
$data = [
'stats[得到当前 Server 的活动 TCP 连接数]' => $this->tcp->stats(),
'getClientInfo[获取连接的信息]' => $this->tcp->getClientInfo($fd, 1, true)
];//链接信息写入.log
Log::channel('slack')->info($data);
$serv->send($fd, '连接成功' . ',' . 'id=>' . $fd);
});
//监听数据接收事件
$this->tcp->on('Receive', function ($serv, $fd, $from_id, $data) {
//验证数据格式
$swooletcp = new ZehongTcpController();
// $swooletcp->swooletcplist($data);
$serv->send($fd,$swooletcp->swooletcplist($data));
});
//监听连接关闭事件
$this->tcp->on('Close', function ($serv, $fd) {
Log::channel('slack')->info('连接已断开' . ',' . 'id=>' . $fd);
});
//启动服务器
$this->tcp->start();
}
public function formatData($str)
{
$str = preg_replace("/[^a-z,A-Z,0-9,\/,\.,-]/", '', $str);
$str = rtrim(trim($str), '/');
$str = str_replace('null', -1, $str);
preg_match("/^[a-z,A-Z,0-9,\-]{6,32}\/(\d{1,2})\/(\-?)([0-9,\.]{1,8})$/", $str, $out);
if (count($out) > 0) {
return $str;
} else {
return false;
}
}
}
\ No newline at end of file
<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Support\Facades\DB;
use App\Laravue\Models\Users;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redis;
use App\Http\Controllers\DevicesController;
use Illuminate\Support\Facades\Config;
class ZehongTcpController extends Controller
{
//获取 tcp 上传数据
public function swooletcplist($data = '')
{
if ($data != '') {
return $this->substrdata($data);
}
}
protected function substrdata($data)
{
$deviceId = substr($data, 0, 36); // 设备编号
$cmd = substr($data, 40, 2); // 命令:01:开机 02: 正常交互
$deviceStatus = substr($data, 42, 2); // 状态
$value = substr($data, 44, 4); // 浓度值
$reserved = substr($data, 48, 20); // 预留
$battery = substr($data, 68, 2); // 电池
$signal = substr($data, 70, 2); // 信号强度
$control = substr($data, 72, 2); // 监测控制
$time = substr($data, 74, 12); // 测量时间
$alarmLow = substr($data, 86, 4); // 低报阈值
$alarmHight = substr($data, 90, 4); // 高报阈值
$cycle = substr($data, 94, 4); // 检测周期
$timeSampling = substr(98, 4); // 采样时间
$reserved1 = substr($data, 102, 20); // 预留
// 设备状态对照表
/**
* 1- 正常
* 2- 检测中
* 3- 低报
* 4- 高报
* 5- 电池欠压
* 6- 水位报警
* 7- 传感器故障
* 8- 泵故障
* 9- 设备故障
*/
switch (base_convert($deviceStatus, 16, 10)) {
case '1':
case '2':
$status = 1;
break;
case '3':
$status = 5;
break;
case '4':
$status = 6;
break;
case '5':
$status = 14;
break;
case '6':
$status = 4;
break;
case '7':
$status = 3;
break;
default:
$status = 15;
}
// return explode('0',$deviceId);
return hexdec($deviceId);
}
}
\ No newline at end of file
const baseURL = 'ws://127.0.0.:9502';
const chemicalsUrl = 'ws://127.0.0.1:9507';
const fireUrl = 'ws://127.0.0.1:9508';
const alarmUrl = 'ws://127.0.0.1:9601';
const mapkey = '2719fe261fee06a08dcb4980990879da';
const mapurl = 'https://webapi.amap.com/maps?v=1.4.15&key=';
export default {
baseURL,
mapkey,
mapurl,
chemicalsUrl,
fireUrl,
alarmUrl,
};
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1599788886331" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2341" data-spm-anchor-id="a313x.7781069.0.i3" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M834.1 469.2c-19.5-43.8-47.4-82.6-82.9-115.2l-29.1-26.7c-4.3-3.8-11.1-2.1-13 3.3l-13 37.3c-8.1 23.4-23 47.3-44.1 70.8-1.4 1.5-3 1.9-4.1 2-1.1 0.1-2.8-0.1-4.3-1.5-1.4-1.2-2.1-3-2-4.8 3.7-60.2-14.3-128.1-53.7-202C555.3 171 510 123.1 453.4 89.7l-41.3-24.3c-5.4-3.2-12.3 1-12 7.3l2.2 48c1.5 32.8-2.3 61.8-11.3 85.9-11 29.5-26.8 56.9-47 81.5-14.2 17.2-30.1 32.7-47.5 46.1-42.1 32.3-76.8 74.4-100.3 121.5C172.5 503.3 160 556.6 160 610c0 47.2 9.3 92.9 27.7 136 17.8 41.5 43.2 78.9 75.5 110.9 32.4 32 70 57.2 111.9 74.7C418.5 949.8 464.5 959 512 959s93.5-9.2 136.9-27.3c41.9-17.5 79.6-42.6 111.9-74.7 32.4-32 57.8-69.4 75.5-110.9 18.4-43.1 27.7-88.8 27.7-136 0-48.8-10-96.2-29.9-140.9zM713 808.5c-53.7 53.2-125 82.4-201 82.4s-147.3-29.2-201-82.4c-53.5-53.1-83-123.5-83-198.4 0-43.5 9.8-85.2 29.1-124 18.8-37.9 46.8-71.8 80.8-97.9 21.5-16.4 41.2-35.5 58.6-56.8 25-30.5 44.6-64.5 58.2-101 5.4-14.5 9.5-30 12.1-46.5 24.1 22.2 44.3 49 61.2 80.4 33.4 62.6 48.8 118.3 45.8 165.7-1.4 22.8 7.5 44.5 24.4 59.8 14.7 13.2 33.7 19.9 53.4 18.8 19.7-1 37.8-9.7 51-24.4 13.3-14.9 24.8-30.1 34.4-45.6 14 17.9 25.7 37.4 35 58.4 15.9 35.8 24 73.9 24 113.1 0 74.9-29.5 145.4-83 198.4zM512 825c22.091 0 40-17.909 40-40s-17.909-40-40-40-40 17.909-40 40 17.909 40 40 40z" fill="#ffffff" p-id="2342"></path></svg>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment