123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/9/3
- * Time: 8:05 PM
- */
- namespace App\Servers\Weikemu\Transforms;
- use App\Models\BoxSettingTraitModel;
- use App\Models\WarningLogTraitModel;
- use App\Servers\BaseServer;
- use App\Servers\Weikemu\Models\CacheLogTraitModel;
- /**
- * 配置报文
- * Class LoginServer
- * @package App\Servers
- */
- class ConfigTransform extends BaseServer
- {
- use BoxSettingTraitModel, WarningLogTraitModel, CacheLogTraitModel;
- /**
- * 处理设备序列号
- * @param $no
- * @return bool|string
- * User: Mead
- */
- private static function box_no($no)
- {
- return substr($no, 0, 9);
- }
- public function main($body)
- {
- $data = $this->decode($body);
- $this->cacheLog($data['box_no'], $this->msg_id, [
- 'SERVER' => $data['server_ip'] . ':' . $data['server_port'],
- 'FREQ' => $data['motion_position_reporting_interval'],
- 'MAXSPEEDPERCENT' => $data['controller_speed_limit_threshold'],
- 'SOFTVERSION' => $data['function_version'],
- 'PULSE' => $data['static_position_reporting_interval'] * 60,
- 'MAXECUSPEED' => self::speedFormat($data['controller_speed_limit_threshold']),
- 'BLUETOOTH_TOKEN' => $data['bluetooth_token'],
- 'BLUETOOTH_MAC' => $data['bluetooth_MAC'],
- 'imei' => $data['imei'],
- 'AUTO_LOCK_TIME' => $data['configs'][7]['value'] ? $data['automatic_locking_time'] : '关闭'
- ]);
- return $this->response();
- }
- /**
- * 解析装载的状态消息
- * @param $body
- * @return array
- * User: Mead
- */
- private function decode($body)
- {
- $top34Data = $this->decodeWeiKeMuTop34($body);
- $i = 34;
- $configs = self::stitching($body, $i, 2); // i=34
- $i += 2;
- // 实时追踪消息上报时间间隔,量化单位30秒
- $real_time_tracking_interval = self::stitching($body, $i, 2); // i=36
- $i += 2;
- //实时追踪持续时间
- $real_time_tracking_duration = self::stitching($body, $i, 2); // i=38
- $i += 2;
- //运动状态,位置采样间隔设置
- $motion_position_sampling_interval = self::stitching($body, $i, 1); // i=40
- $i += 1;
- // 运动状态,位置上报间隔设置
- $motion_position_reporting_interval = self::stitching($body, $i, 1); // i=41
- $i += 1;
- //静止状态,位置上报间隔设置
- $static_position_reporting_interval = self::stitching($body, $i, 2); // i=42
- $i += 2;
- // 超速门限,取值范围 0~126,量化单位2km/h,
- $overspeed_threshold = self::stitching($body, $i, 1); // i=44
- $i += 1;
- // 温度门限
- $temperature_threshold = self::stitching($body, $i, 1); // i=45
- $i += 1;
- // 位移告警门限
- $displacement_threshold = self::stitching($body, $i, 1); // i=46
- $i += 1;
- //自动落锁时长,量化单位1分钟
- $automatic_locking_time = self::stitching($body, $i, 1); // i=47
- $i += 1;
- //服务器地址端口号
- $server_port = self::stitching($body, $i, 2); // i=48
- $i += 2;
- // ip
- $server_ip = self::stitching($body, $i, 4); // i=50
- // self::log($server_ip,'ip',2);
- $i += 4;
- // 蓝牙名称
- $bluetooth_name = self::stitching($body, $i, 10); // i=54
- // self::dd($bluetooth_name);
- $i += 10;
- // 蓝牙token
- $bluetooth_token = self::stitching($body, $i, 4); // i=64
- $i += 4;
- $i += 6;
- // 控制器限速门限
- $controller_speed_limit_threshold = self::stitching($body, $i, 2); // i=74
- $i += 2;
- $i += 6;
- $i += 8;
- $i += 4;
- // 设备版本号
- $equipment_version = self::stitching($body, $i, 20); // i=94
- $i += 20;
- // 功能版本号
- $function_version = self::stitching($body, $i, 1); // i=114
- $i += 1;
- //蓝牙MAC
- $bluetooth_MAC = substr(self::stitching($body, $i, 8), 0); // i=115
- self::log($automatic_locking_time, 'Setting');
- self::log(hexdec($automatic_locking_time), 'Setting');
- self::log($configs, 'Setting');
- self::log(self::handleConfigs($configs), 'Setting');
- return array_merge($top34Data, [
- 'configs' => self::handleConfigs($configs),
- 'real_time_tracking_interval' => hexdec($real_time_tracking_interval) * 30, //秒
- 'real_time_tracking_duration' => hexdec($real_time_tracking_duration), // 分钟
- 'motion_position_sampling_interval' => hexdec($motion_position_sampling_interval), // 秒
- 'motion_position_reporting_interval' => hexdec($motion_position_reporting_interval), // 秒
- 'static_position_reporting_interval' => hexdec($static_position_reporting_interval), // 分钟
- 'overspeed_threshold' => hexdec($overspeed_threshold) * 2, // km/h
- 'temperature_threshold' => hexdec($temperature_threshold),// 度
- 'displacement_threshold' => hexdec($displacement_threshold),// 米
- 'automatic_locking_time' => hexdec($automatic_locking_time), // 分钟
- 'server_port' => hexdec($server_port),
- 'server_ip' => self::handleIp($server_ip),
- 'bluetooth_name' => hex2bin($bluetooth_name),
- 'bluetooth_token' => $bluetooth_token,
- 'controller_speed_limit_threshold' => hexdec($controller_speed_limit_threshold),
- 'equipment_version' => hex2bin($equipment_version),
- 'function_version' => hexdec($function_version),
- 'bluetooth_MAC' => $bluetooth_MAC
- ]);
- }
- private static function handleConfigs($configs)
- {
- $data = self::handleU2($configs);
- $config = array_slice($data, 0, 8);
- $names = ['震动告警开启设置', '断电告警开启设置', '位移告警开启设置', '实时追踪开启设置', '保留', '超速开启设置', '保留', '自动落锁', '温度告警'];
- $nConfigs = [];
- foreach ($config as $k => $c) {
- $nConfigs[$k] = [
- 'value' => $c,
- 'name' => $names[$k]
- ];
- }
- return $nConfigs;
- }
- private static function handleIp($ip)
- {
- $ipArr = str_split($ip, 2);
- $res = '';
- foreach ($ipArr as $v) {
- $res .= base_convert($v, 16, 10) . '.';
- }
- return rtrim($res, '.');
- }
- private static function speedFormat($speed)
- {
- $MAXSPEEDPERCENT = 7;
- switch ($speed) {
- case 70:
- $MAXSPEEDPERCENT = 1;
- break;
- case 75:
- $MAXSPEEDPERCENT = 2;
- break;
- case 80:
- $MAXSPEEDPERCENT = 3;
- break;
- case 85:
- $MAXSPEEDPERCENT = 4;
- break;
- case 90:
- $MAXSPEEDPERCENT = 5;
- break;
- case 95:
- $MAXSPEEDPERCENT = 6;
- break;
- case 100:
- $MAXSPEEDPERCENT = 7;
- break;
- }
- return $MAXSPEEDPERCENT;
- }
- /**
- * 状态响应
- * @param $login_type
- * @return array
- * User: Mead
- */
- public function response($login_type = '00')
- {
- $body = [
- '5b',
- '0000'
- ];
- return $body;
- }
- }
|