ConfigTransform.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Mead
  5. * Date: 2019/9/3
  6. * Time: 8:05 PM
  7. */
  8. namespace App\Servers\Weikemu\Transforms;
  9. use App\Models\BoxSettingTraitModel;
  10. use App\Models\WarningLogTraitModel;
  11. use App\Servers\BaseServer;
  12. use App\Servers\Weikemu\Models\CacheLogTraitModel;
  13. /**
  14. * 配置报文
  15. * Class LoginServer
  16. * @package App\Servers
  17. */
  18. class ConfigTransform extends BaseServer
  19. {
  20. use BoxSettingTraitModel, WarningLogTraitModel, CacheLogTraitModel;
  21. public function main($body)
  22. {
  23. $data = $this->decode($body);
  24. $this->cacheLog($data['box_no'], $this->msg_id, [
  25. 'SERVER' => $data['server_ip'] . ':' . $data['server_port'],
  26. 'FREQ' => $data['motion_position_reporting_interval'],
  27. 'MAXSPEEDPERCENT' => $data['controller_speed_limit_threshold'],
  28. 'SOFTVERSION' => $data['function_version'],
  29. 'PULSE' => $data['static_position_reporting_interval'] * 60,
  30. 'MAXECUSPEED' => self::speedFormat($data['controller_speed_limit_threshold']),
  31. 'BLUETOOTH_TOKEN' => $data['bluetooth_token'],
  32. 'BLUETOOTH_MAC' => $data['bluetooth_MAC'],
  33. 'imei' => $data['imei'],
  34. ]);
  35. return $this->response();
  36. }
  37. /**
  38. * 状态响应
  39. * @param $login_type
  40. * @return array
  41. * User: Mead
  42. */
  43. public function response($login_type = '00')
  44. {
  45. $body = [
  46. '5b',
  47. '0000'
  48. ];
  49. return $body;
  50. }
  51. /**
  52. * 解析装载的状态消息
  53. * @param $body
  54. * @return array
  55. * User: Mead
  56. */
  57. private function decode($body)
  58. {
  59. $top34Data = $this->decodeWeiKeMuTop34($body);
  60. $i = 34;
  61. $configs = self::stitching($body, $i, 2); // i=34
  62. $i += 2;
  63. // 实时追踪消息上报时间间隔,量化单位30秒
  64. $real_time_tracking_interval = self::stitching($body, $i, 2); // i=36
  65. $i += 2;
  66. //实时追踪持续时间
  67. $real_time_tracking_duration = self::stitching($body, $i, 2); // i=38
  68. $i += 2;
  69. //运动状态,位置采样间隔设置
  70. $motion_position_sampling_interval = self::stitching($body, $i, 1); // i=40
  71. $i += 1;
  72. // 运动状态,位置上报间隔设置
  73. $motion_position_reporting_interval = self::stitching($body, $i, 1); // i=41
  74. $i += 1;
  75. //静止状态,位置上报间隔设置
  76. $static_position_reporting_interval = self::stitching($body, $i, 2); // i=42
  77. $i += 2;
  78. // 超速门限,取值范围 0~126,量化单位2km/h,
  79. $overspeed_threshold = self::stitching($body, $i, 1); // i=44
  80. $i += 1;
  81. // 温度门限
  82. $temperature_threshold = self::stitching($body, $i, 1); // i=45
  83. $i += 1;
  84. // 位移告警门限
  85. $displacement_threshold = self::stitching($body, $i, 1); // i=46
  86. $i += 1;
  87. //自动落锁时长,量化单位1分钟
  88. $automatic_locking_time = self::stitching($body, $i, 1); // i=47
  89. $i += 1;
  90. //服务器地址端口号
  91. $server_port = self::stitching($body, $i, 2); // i=48
  92. $i += 2;
  93. // ip
  94. $server_ip = self::stitching($body, $i, 4); // i=50
  95. // self::log($server_ip,'ip',2);
  96. $i += 4;
  97. // 蓝牙名称
  98. $bluetooth_name = self::stitching($body, $i, 10); // i=54
  99. // self::dd($bluetooth_name);
  100. $i += 10;
  101. // 蓝牙token
  102. $bluetooth_token = self::stitching($body, $i, 4); // i=64
  103. $i += 4;
  104. $i += 6;
  105. // 控制器限速门限
  106. $controller_speed_limit_threshold = self::stitching($body, $i, 2); // i=74
  107. $i += 2;
  108. $i += 6;
  109. $i += 8;
  110. $i += 4;
  111. // 设备版本号
  112. $equipment_version = self::stitching($body, $i, 20); // i=94
  113. $i += 20;
  114. // 功能版本号
  115. $function_version = self::stitching($body, $i, 1); // i=114
  116. $i += 1;
  117. //蓝牙MAC
  118. $bluetooth_MAC = substr(self::stitching($body, $i, 8), 0); // i=115
  119. return array_merge($top34Data, [
  120. 'configs' => self::handleConfigs($configs),
  121. 'real_time_tracking_interval' => hexdec($real_time_tracking_interval) * 30, //秒
  122. 'real_time_tracking_duration' => hexdec($real_time_tracking_duration), // 分钟
  123. 'motion_position_sampling_interval' => hexdec($motion_position_sampling_interval), // 秒
  124. 'motion_position_reporting_interval' => hexdec($motion_position_reporting_interval), // 秒
  125. 'static_position_reporting_interval' => hexdec($static_position_reporting_interval), // 分钟
  126. 'overspeed_threshold' => hexdec($overspeed_threshold) * 2, // km/h
  127. 'temperature_threshold' => hexdec($temperature_threshold),// 度
  128. 'displacement_threshold' => hexdec($displacement_threshold),// 米
  129. 'automatic_locking_time' => hexdec($automatic_locking_time), // 分钟
  130. 'server_port' => hexdec($server_port),
  131. 'server_ip' => self::handleIp($server_ip),
  132. 'bluetooth_name' => hex2bin($bluetooth_name),
  133. 'bluetooth_token' => $bluetooth_token,
  134. 'controller_speed_limit_threshold' => hexdec($controller_speed_limit_threshold),
  135. 'equipment_version' => hex2bin($equipment_version),
  136. 'function_version' => hexdec($function_version),
  137. 'bluetooth_MAC' => $bluetooth_MAC
  138. ]);
  139. }
  140. /**
  141. * 处理设备序列号
  142. * @param $no
  143. * @return bool|string
  144. * User: Mead
  145. */
  146. private
  147. static function box_no($no)
  148. {
  149. return substr($no, 0, 9);
  150. }
  151. private static function handleConfigs($configs)
  152. {
  153. $data = self::handleU2($configs);
  154. return array_slice($data, 0, 8);
  155. }
  156. private static function handleIp($ip)
  157. {
  158. $ipArr = str_split($ip, 2);
  159. $res = '';
  160. foreach ($ipArr as $v) {
  161. $res .= base_convert($v, 16, 10) . '.';
  162. }
  163. return rtrim($res, '.');
  164. }
  165. private static function speedFormat($speed)
  166. {
  167. $MAXSPEEDPERCENT = 7;
  168. switch ($speed) {
  169. case 70:
  170. $MAXSPEEDPERCENT = 1;
  171. break;
  172. case 75:
  173. $MAXSPEEDPERCENT = 2;
  174. break;
  175. case 80:
  176. $MAXSPEEDPERCENT = 3;
  177. break;
  178. case 85:
  179. $MAXSPEEDPERCENT = 4;
  180. break;
  181. case 90:
  182. $MAXSPEEDPERCENT = 5;
  183. break;
  184. case 95:
  185. $MAXSPEEDPERCENT = 6;
  186. break;
  187. case 100:
  188. $MAXSPEEDPERCENT = 7;
  189. break;
  190. }
  191. return $MAXSPEEDPERCENT;
  192. }
  193. }