足底健康分析服务端
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.
 
 
 
 

409 lines
13 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
{
public function index()
{
return view('http.index');
}
public function tabularData()
{
$request_data = request()->all();
$vague = 2;
$datas = [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 2, 2, 4, 4, 4, 4, 4, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 6, 6, 8, 4, 2, 1, 1, 1, 1, 1,
1, 1, 1, 1, 2, 4, 8, 9, 8, 6, 6, 4, 2, 1, 1, 1, 1, 1, 1, 1, 2, 6, 8, 8, 8, 4, 2, 2, 1, 1, 1, 1,
1, 1, 1, 2, 4, 6, 8, 9, 8, 6, 6, 4, 2, 2, 1, 1, 1, 1, 1, 1, 2, 6, 8, 8, 8, 8, 4, 2, 1, 1, 1, 1,
1, 1, 1, 2, 4, 6, 8, 9, 8, 6, 6, 4, 2, 1, 1, 1, 1, 1, 1, 1, 2, 6, 8, 8, 8, 8, 6, 2, 1, 1, 1, 1,
1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
];
for ($i = 0; $i < 1024; $i++){
$datas2[intval($i / 32)][$i % 32] = $datas[$i];
}
foreach ($datas2 as $key1 => $data){
foreach ($data as $key2 => $datum){
if (!empty($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 (!empty($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);
}
$chunk3 = [];
foreach ($chunk2 as $key1 => $value) {
foreach ($value as $key2 => $value2) {
$chunk3[] = [
$key2,
$key1,
$value2 / 10,
];
}
}
return [
'pressure' => $chunk3,
'foot' => [36.2, 80, 36.1, 75, 35.9, 79, 36.3, 80]
];
}
public function lora()
{
return view('http.lora');
}
public function lora2()
{
Cache::flush();
return view('http.lora2');
}
public function getPelmaStore()
{
echo Cache::get('pelma');
return;
}
public function store()
{
$time = time();
// echo Cache::get('pelma');
$pelma_key = "pelma:1";
//按时间添加
// Redis::zadd($pelma_key, $time, 'a' . $time);
// Redis::zadd($pelma_key, 1, 'a' . $time);
//删除过期
// Redis::ZREMRANGEBYSCORE($pelma_key, 0, ($time - 60));
//获取最大时间
// $data = Redis::ZREVRANGE($pelma_key, 0, 0);
//获得指定时间
// $data = Redis::ZRANGEBYSCORE($pelma_key, 19, 29);
// var_dump($data);
$data = request('pelma');
Cache::put('pelma', $data);
Log::info($data);
return 'ok';
}
public function getBlood()
{
$blood = Cache::get('blood');
return $blood;
}
/**
* 上传血压数据
* 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,
// ]
// ],
//
// ];
}
}