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'], ]); return $this->response(); } /** * 状态响应 * @param $login_type * @return array * User: Mead */ public function response($login_type = '00') { $body = [ '5b', '0000' ]; return $body; } /** * 解析装载的状态消息 * @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 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 ]); } /** * 处理设备序列号 * @param $no * @return bool|string * User: Mead */ private static function box_no($no) { return substr($no, 0, 9); } private static function handleConfigs($configs) { $data = self::handleU2($configs); return array_slice($data, 0, 8); } 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; } }