|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Admin\Services;
|
|
|
|
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
use Illuminate\Pagination\Paginator;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
|
|
|
class EquipInfoService
|
|
|
|
{
|
|
|
|
public static function getDatapoints($param)
|
|
|
|
{
|
|
|
|
if (empty($param['_search_'])){
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
$query = [];
|
|
|
|
if (!empty($param['at']['start'])){
|
|
|
|
$query['start'] = str_replace(' ', 'T', $param['at']['start']);
|
|
|
|
}
|
|
|
|
if (!empty($param['at']['end'])){
|
|
|
|
$query['end'] = str_replace(' ', 'T', $param['at']['end']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = http_build_query($query);
|
|
|
|
|
|
|
|
$client = new Client([
|
|
|
|
'base_uri' => config('onenet.api_host'),
|
|
|
|
'headers' => [
|
|
|
|
'api-key' => "l5KGPjSqQVuwSSjlUAuBohPNVrM=",
|
|
|
|
]
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
$response = $client->request('GET', 'devices/' . $param['_search_'] . '/datapoints?' . $query);
|
|
|
|
|
|
|
|
$res = json_decode($response->getBody()->getContents(), true);
|
|
|
|
|
|
|
|
$res = !empty($res['data']['datastreams'][0]['datapoints']) ? $res['data']['datastreams'][0]['datapoints'] : [];
|
|
|
|
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
foreach ($res as $re) {
|
|
|
|
$equip_data = $re['value'];
|
|
|
|
// $equip_data = '68C008669710390347698524015101FFFE0A01080000010000000000CFEB1601040400000992014B00010002000324200426151314020101009F017616';
|
|
|
|
|
|
|
|
$status_info = substr($equip_data, 62);
|
|
|
|
|
|
|
|
//阀门状态
|
|
|
|
$valve_status = substr($status_info, 0, 2);
|
|
|
|
$valve_status = base_convert($valve_status, 16, 2);
|
|
|
|
$valve_status = str_pad($valve_status, 8, '0', STR_PAD_LEFT);
|
|
|
|
|
|
|
|
$re['valve_status1'] = (substr($valve_status, -1, 1) == 1) ? '阀开' : '阀关';
|
|
|
|
$re['valve_status2'] = (substr($valve_status, -2, 1) == 1) ? '阀门堵转' : '阀门动作正常';
|
|
|
|
$re['valve_status3'] = (substr($valve_status, -3, 1) == 1) ? '行程开关异常' : '行程开关正常';
|
|
|
|
$re['valve_status4'] = (substr($valve_status, -4, 1) == 1) ? '电位器异常' : '电位器正常';
|
|
|
|
$re['valve_status5'] = (substr($valve_status, -5, 1) == 1) ? '电池电量低' : '电池电量正常';
|
|
|
|
$re['valve_status6'] = (substr($valve_status, -6, 1) == 1) ? '回水传感器异常' : '回水传感器正常';
|
|
|
|
$re['valve_status7'] = (substr($valve_status, -7, 1) == 1) ? '加速度传感器异常' : '加速度传感器正常';
|
|
|
|
$re['valve_status8'] = (substr($valve_status, -8, 1) == 1) ? '角度存在偏差' : '角度正常';
|
|
|
|
|
|
|
|
//设定开度
|
|
|
|
$re['set_opening'] = base_convert(substr($status_info, 2, 2), 16, 10) . '%';
|
|
|
|
//实际开度
|
|
|
|
$re['actual_opening'] = base_convert(substr($status_info, 4, 2), 16, 10) . '%';
|
|
|
|
//进水温度
|
|
|
|
$re['water_inlet_temperature'] = base_convert(substr($status_info, 6, 4), 16, 10) / 100 . '度';
|
|
|
|
//回水温度
|
|
|
|
$re['water_return_temperature'] = base_convert(substr($status_info, 10, 4), 16, 10) / 100 . '度';
|
|
|
|
//电池电量
|
|
|
|
$re['battery_power'] = base_convert(substr($status_info, 14, 4), 16, 10) / 100 . 'V';
|
|
|
|
//加速度X Y Z轴
|
|
|
|
$re['accelerated_x'] = substr($status_info, 18, 4);
|
|
|
|
$re['accelerated_y'] = substr($status_info, 22, 4);
|
|
|
|
$re['accelerated_z'] = substr($status_info, 26, 4);
|
|
|
|
//信号强度
|
|
|
|
$re['signal_strength'] = substr($status_info, 30, 2);
|
|
|
|
|
|
|
|
//阀门时间
|
|
|
|
$valve_time = substr($status_info, 32, 12);
|
|
|
|
$re['valve_time'] = date('Y-m-d H:i:s', strtotime('20'.$valve_time));
|
|
|
|
//上报间隔
|
|
|
|
$re['reporting_interval'] = substr($status_info, 44, 2);
|
|
|
|
//间隔单位
|
|
|
|
$interval_unit = substr($status_info, 46, 2);
|
|
|
|
|
|
|
|
switch ($interval_unit){
|
|
|
|
case '01':
|
|
|
|
$re['interval_unit'] = '分钟';
|
|
|
|
break;
|
|
|
|
case '02':
|
|
|
|
$re['interval_unit'] = '小时';
|
|
|
|
break;
|
|
|
|
case '03':
|
|
|
|
$re['interval_unit'] = '天';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//上报有效时长
|
|
|
|
$re['effective_time'] = substr($status_info, 48, 2);
|
|
|
|
//总上报次数
|
|
|
|
$re['total_number_reports'] = base_convert(substr($status_info, 50, 4), 16, 10);
|
|
|
|
//其他
|
|
|
|
$re['other'] = substr($status_info, 54, 2);
|
|
|
|
//累加校验和
|
|
|
|
$re['check'] = substr($status_info, 56, 2);
|
|
|
|
//结束符
|
|
|
|
$re['finish'] = substr($status_info, 58, 2);
|
|
|
|
|
|
|
|
array_unshift($data, $re);
|
|
|
|
}
|
|
|
|
|
|
|
|
// $res = new Paginator($res, 20, null, ['path' => url()->current(), 'query' => $param]);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|