You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
449 lines
12 KiB
449 lines
12 KiB
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
use App\Http\Services\CommonService;
|
|
use Illuminate\Routing\Controller as BaseController;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
class IndexController extends BaseController
|
|
{
|
|
/**
|
|
* 获得足底数据
|
|
* @return array[]
|
|
*/
|
|
public function getPelmaData()
|
|
{
|
|
$request_data = request()->all();
|
|
$timer_shaft = $request_data['timer_shaft'];
|
|
|
|
//足底压力图
|
|
$pelma_key = "pelma:" . $request_data['item'];
|
|
|
|
if ($timer_shaft == 0 ){
|
|
//获取最大时间
|
|
$data = Redis::ZREVRANGE($pelma_key, 0, 0);
|
|
} else {
|
|
//获得指定时间
|
|
$data = Redis::ZREVRANGEBYSCORE($pelma_key, $timer_shaft, $timer_shaft - 60);
|
|
}
|
|
|
|
if(!empty($data)){
|
|
$pelmaArr = str_split($data[0], 2);
|
|
|
|
|
|
|
|
//格式化成二维数组
|
|
for ($i = 0; $i < 1024; $i++){
|
|
$datas2[intval($i / 32)][$i % 32] = hexdec($pelmaArr[$i]);
|
|
}
|
|
|
|
|
|
$vague = 0;
|
|
|
|
if ($vague > 0){
|
|
//模糊扩大
|
|
foreach ($datas2 as $key1 => $data){
|
|
foreach ($data as $key2 => $datum){
|
|
if (isset($datas2[$key1][$key2 - 1])){
|
|
$num = $datum - $datas2[$key1][$key2 - 1];
|
|
$temp = $datum;
|
|
for ($i = $vague; $i >= 1; $i--) {
|
|
$chunk[$key1][] = $temp - ($num / ($vague + 1)) * $i;
|
|
}
|
|
}
|
|
$chunk[$key1][] = $datum;
|
|
}
|
|
}
|
|
|
|
$chunk2 = [];
|
|
$key3 = 0;
|
|
$number = 1;
|
|
foreach ($chunk as $key1 => $data){
|
|
foreach ($data as $key2 => $datum){
|
|
|
|
$number++;
|
|
if (isset($chunk[$key1 - 1][$key2])){
|
|
$num = $datum - $chunk[$key1 - 1][$key2];
|
|
$temp = $datum;
|
|
for ($i = $vague; $i >= 1; $i--) {
|
|
$chunk2[$key3 - $i][$key2] = $temp - ($num / ($vague + 1)) * $i;
|
|
}
|
|
}
|
|
$chunk2[$key3][$key2] = $datum;
|
|
}
|
|
$key3 = $key3 + ($vague + 1);
|
|
}
|
|
} else {
|
|
$chunk2 = $datas2;
|
|
|
|
// //直接扩大
|
|
// $expansion = 3;
|
|
// foreach ($datas2 as $key1 => $data){
|
|
// foreach ($data as $key2 => $datum){
|
|
// for ($i = 0; $i < $expansion; $i++) {
|
|
// for ($j = 0; $j < $expansion; $j++) {
|
|
// $chunk2[$key1 * $expansion + $i][$key2 * $expansion + $j] = $datum;
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
}
|
|
|
|
|
|
$chunk3 = [];
|
|
foreach ($chunk2 as $key1 => $value) {
|
|
foreach ($value as $key2 => $value2) {
|
|
$chunk3[] = [
|
|
$key2,
|
|
$key1,
|
|
$value2,
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
//足底温度图
|
|
$foot = [];
|
|
for ($i = 1; $i <= 4; $i++) {
|
|
$foot_key = "foot:" . $i;
|
|
|
|
if ($timer_shaft == 0 ){
|
|
//获取最大时间
|
|
$foot_data = Redis::ZREVRANGE($foot_key, 0, 0);
|
|
} else {
|
|
//获得指定时间
|
|
$foot_data = Redis::ZREVRANGEBYSCORE($foot_key, $timer_shaft, $timer_shaft - 60);
|
|
}
|
|
|
|
|
|
if (!empty($foot_data)){
|
|
$foot_data = $foot_data[0];
|
|
|
|
//体温36.1
|
|
$temperature = substr($foot_data, 4, 4);
|
|
$temperature1 = substr($temperature, 0, 2);
|
|
$temperature2 = substr($temperature, 2, 2);
|
|
|
|
$foot[] = hexdec($temperature2 . $temperature1) / 100;
|
|
//
|
|
//血氧80.1
|
|
$blood = substr($foot_data, 0, 4);
|
|
$blood1 = hexdec(substr($blood, 0, 2));
|
|
$blood2 = substr($blood, 2, 2);
|
|
$blood2 = CommonService::customHex2dec($blood2);
|
|
|
|
$foot[] = $blood1 + $blood2;
|
|
|
|
// //心跳70
|
|
// $heart = substr($foot_data, 8, 4);
|
|
// $heart = hexdec($heart);
|
|
// Cache::put('heart' . $request_data['node'], $heart);
|
|
// //脉搏70
|
|
// $heart2 = substr($foot_data, 12, 4);
|
|
// $heart2 = hexdec($heart2);
|
|
// Cache::put('heart2' . $request_data['node'], $heart2);
|
|
}
|
|
}
|
|
|
|
|
|
return [
|
|
'pressure' => $chunk3 ?? '',
|
|
'foot' => $foot
|
|
// 'foot' => [36.2, 80, 36.1, 75, 35.9, 79, 36.3, 80]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 存储足底数据
|
|
* @return string
|
|
*/
|
|
public function storePelma()
|
|
{
|
|
$req = request()->all();
|
|
|
|
$time = time();
|
|
// echo Cache::get('pelma');
|
|
Log::info($req);
|
|
|
|
if ($req['type'] == "0001"){
|
|
$pelma_key = "pelma:" . hexdec($req['device']);
|
|
|
|
//按时间添加
|
|
Redis::zadd($pelma_key, $time, $req['send_data']);
|
|
|
|
//删除过期
|
|
Redis::ZREMRANGEBYSCORE($pelma_key, 0, ($time - 120));
|
|
} elseif ($req['type'] == "0002") {
|
|
$pelma_key = "foot:" . hexdec($req['device']);
|
|
|
|
//按时间添加
|
|
Redis::zadd($pelma_key, $time, $req['send_data']);
|
|
|
|
//删除过期
|
|
Redis::ZREMRANGEBYSCORE($pelma_key, 0, ($time - 120));
|
|
}
|
|
|
|
// $data = request('pelma');
|
|
// Cache::put('pelma', $data);
|
|
// Log::info($req);
|
|
return 'ok';
|
|
}
|
|
|
|
|
|
public function lora()
|
|
{
|
|
return view('http.lora');
|
|
}
|
|
|
|
public function lora2()
|
|
{
|
|
Cache::flush();
|
|
|
|
return view('http.lora2');
|
|
}
|
|
|
|
/**
|
|
* 上传血压数据
|
|
* http://127.0.0.1:8001/storeBlood?node=616162626365&data=0090243050005500
|
|
* @return string
|
|
*/
|
|
public function storeBlood()
|
|
{
|
|
// echo Cache::get('blood');
|
|
|
|
//00F10D59006F0061
|
|
|
|
$request_data = request()->all();
|
|
|
|
$lora_mac = config("custom.lora_mac");
|
|
|
|
if (empty($request_data['node']) || empty($request_data['data'])){
|
|
return 'error';
|
|
}
|
|
|
|
if (!in_array($request_data['node'], $lora_mac)){
|
|
return 'error';
|
|
}
|
|
//血氧80.1
|
|
$blood = substr($request_data['data'], 0, 4);
|
|
$blood1 = hexdec(substr($blood, 0, 2));
|
|
$blood2 = substr($blood, 2, 2);
|
|
$blood2 = CommonService::customHex2dec($blood2);
|
|
|
|
Cache::put('blood' . $request_data['node'], ($blood1 + $blood2) * 100);
|
|
|
|
//体温36.1
|
|
$temperature = substr($request_data['data'], 4, 4);
|
|
$temperature = hexdec($temperature) / 100;
|
|
Cache::put('temperature' . $request_data['node'], $temperature);
|
|
//心跳70
|
|
$heart = substr($request_data['data'], 8, 4);
|
|
$heart = hexdec($heart);
|
|
Cache::put('heart' . $request_data['node'], $heart);
|
|
//脉搏70
|
|
$heart2 = substr($request_data['data'], 12, 4);
|
|
$heart2 = hexdec($heart2);
|
|
Cache::put('heart2' . $request_data['node'], $heart2);
|
|
|
|
return 'ok';
|
|
}
|
|
|
|
public function loraData()
|
|
{
|
|
$request_data = request()->all();
|
|
|
|
// if (!empty($request_data['item']) && $request_data['item'] == '温度'){
|
|
// $temperature = rand(359, 366) / 10;
|
|
//
|
|
// $data = [[$temperature, 0, 0, "温度", date('m:s')]];
|
|
//
|
|
// } elseif (!empty($request_data['item']) && $request_data['item'] == '血氧'){
|
|
// $oxygen = rand(70, 100);
|
|
//
|
|
// $data = [[$oxygen, 0, 0, "血氧", date('m:s')]];
|
|
//
|
|
// } else {
|
|
// $temperature = rand(359, 366) / 10;
|
|
// $oxygen = rand(70, 100);
|
|
//
|
|
// $data = [[$temperature, 0, 0, "温度", date('m:s')],
|
|
// [$oxygen, 0, 0, "血氧", date('m:s')]];
|
|
//
|
|
// }
|
|
|
|
$temperature = rand(359, 366) / 10;
|
|
$oxygen = rand(70, 100);
|
|
|
|
$oxygen = 80 + ((time() % 3) + 1) * 5;
|
|
|
|
$data = [[$temperature, 0, 0, "温度", date('m:s')],
|
|
[$oxygen, 0, 0, "血氧", date('m:s')]];
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 设备列表
|
|
* @return void
|
|
*/
|
|
public function loraDeviceList()
|
|
{
|
|
$lora_mac = config("custom.lora_mac");
|
|
|
|
$devices = [];
|
|
foreach ($lora_mac as $key => $mac){
|
|
$devices[] = [
|
|
'name' => '设备' . ($key + 1),
|
|
'mac' => $mac,
|
|
'online' => 0,
|
|
];
|
|
}
|
|
|
|
return $devices;
|
|
}
|
|
|
|
public function loraData2()
|
|
{
|
|
|
|
//00F10D59006F0061
|
|
|
|
$time = (int)(time() . '000');
|
|
|
|
$request_data = request()->all();
|
|
|
|
$node = $request_data['node'] ?? config("custom.lora_mac")[0];
|
|
|
|
$return_data = [];
|
|
$blood_data = Cache::get('blood' . $node, '');
|
|
if ($blood_data){
|
|
$return_data['blood'] = [
|
|
[
|
|
$time,
|
|
$blood_data,
|
|
]
|
|
];
|
|
}
|
|
|
|
$temperature_data = Cache::get('temperature' . $node, '');
|
|
if ($temperature_data){
|
|
$return_data['temperature'] = [
|
|
[
|
|
$time,
|
|
$temperature_data,
|
|
]
|
|
];
|
|
}
|
|
|
|
$heart_data = Cache::get('heart' . $node, '');
|
|
if ($heart_data){
|
|
$return_data['heart'] = [
|
|
[
|
|
$time,
|
|
$heart_data,
|
|
]
|
|
];
|
|
}
|
|
|
|
$heart2_data = Cache::get('heart2' . $node, '');
|
|
if ($heart2_data){
|
|
$return_data['humidity'] = [
|
|
[
|
|
$time,
|
|
$heart2_data,
|
|
]
|
|
];
|
|
}
|
|
|
|
$total = [50, 70, 90, 85, 80, 75, 70, 65, 60, 55];
|
|
|
|
$total_data = [];
|
|
foreach ($total as $key => $item){
|
|
$item_time = $time + 100 * $key;
|
|
$total_data[] = [
|
|
$item_time,
|
|
$item
|
|
];
|
|
}
|
|
|
|
return $return_data;
|
|
}
|
|
|
|
/**
|
|
* 专项对比数据
|
|
* @return void
|
|
*/
|
|
public function getSpecialCompare()
|
|
{
|
|
$request_data = request()->all();
|
|
|
|
$compare_type = $request_data['compare_type'] ?? 1;
|
|
|
|
$time = (int)(time() . '000');
|
|
|
|
$nodes = config("custom.lora_mac");
|
|
|
|
$return_data = [];
|
|
|
|
foreach ($nodes as $key => $node){
|
|
switch ($compare_type) {
|
|
case 1:
|
|
$device_data = Cache::get('blood' . $node, '');
|
|
break;
|
|
case 2:
|
|
$device_data = Cache::get('temperature' . $node, '');
|
|
break;
|
|
case 3:
|
|
$device_data = Cache::get('heart' . $node, '');
|
|
break;
|
|
case 4:
|
|
$device_data = Cache::get('heart2' . $node, '');
|
|
break;
|
|
default:
|
|
$device_data = Cache::get('blood' . $node, '');
|
|
}
|
|
if (empty($device_data)){
|
|
continue;
|
|
}
|
|
|
|
$device_id = $key + 1;
|
|
$device_name = '设备' . $device_id;
|
|
$return_data[$device_name] = [
|
|
[
|
|
$time,
|
|
$device_data
|
|
]
|
|
];
|
|
}
|
|
|
|
return $return_data;
|
|
|
|
|
|
|
|
|
|
// return [
|
|
// '设备1' => [
|
|
// [
|
|
// $time,
|
|
// 70,
|
|
// ]
|
|
// ],
|
|
// '设备2' => [
|
|
// [
|
|
// $time,
|
|
// 80,
|
|
// ]
|
|
// ],
|
|
// '设备3' => [
|
|
// [
|
|
// $time,
|
|
// 90,
|
|
// ]
|
|
// ],
|
|
//
|
|
// ];
|
|
}
|
|
}
|
|
|