ShOneanalysis.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. <?php
  2. namespace app\common\server;
  3. use app\common\model\FacilityModel;
  4. use app\common\model\ShoneReceiveInfoModel;
  5. use app\common\model\ShoneReceiveInfoRecode;
  6. use app\common\model\ShoneReceiveQueueModel;
  7. use app\common\model\ShoneSendListModel;
  8. use app\common\model\ShoneSendQueueModel;
  9. use think\facade\Log;
  10. /**
  11. * 手环字符串解析
  12. *
  13. * @author wj
  14. * @date 2023-08-11
  15. */
  16. class ShOneanalysis
  17. {
  18. private $num_scale = 16; //16进制
  19. /**
  20. * 校验长度
  21. *
  22. * @return void
  23. * @author wj
  24. * @date 2023-08-11
  25. */
  26. public function checklen($len, $str)
  27. {
  28. $strlen = mb_strlen($str);
  29. if ($len != $strlen) {
  30. return false;
  31. }
  32. return true;
  33. }
  34. /**
  35. * 获取信息
  36. *
  37. * @return void
  38. * @author wj
  39. * @date 2023-08-11
  40. */
  41. public function getline($str)
  42. {
  43. //[厂商*设备 ID*内容长度*内容]
  44. $preg = "/^\[(.*)\*(.*)\*(.*)\*(.*)\]$/";
  45. preg_match($preg, $str, $match);
  46. if (empty($match)) {
  47. throw new \Exception('解析失败:' . $str);
  48. }
  49. unset($match[0]);
  50. $data = array_values($match);
  51. $sandom_string = $data[0]; //厂商 随机字符串
  52. $device_id_code = $data[1]; //设置id编码
  53. $content_len = $data[2]; //内容长度
  54. $content_str = $data[3]; //内容字符串
  55. $content_len = $this->analysislen($content_len);
  56. $result = $this->checklen($content_len, $content_str);
  57. if (empty($result)) {
  58. throw new \Exception('内容位数错误');
  59. }
  60. $data = [
  61. 'device_id_code' => $device_id_code,
  62. 'content_len' => $content_len,
  63. 'content_str' => $content_str,
  64. ];
  65. return $data;
  66. }
  67. //KA,230814,0,0,96
  68. //WT,130823,160054,V,22.601242,N,113.8302765,E,0.00,0.0,29.2,0,70,96,0,0,00000000,1,1,460,0,8593,265807240,136,0,9999.0
  69. //ICCID,02203002080045057806
  70. public function getcommandcontent($content_str)
  71. {
  72. $content = explode(',', $content_str);
  73. return $content;
  74. }
  75. /**
  76. * 保存手环设备one信息
  77. *
  78. * @return void
  79. * @author wj
  80. * @date 2023-08-11
  81. */
  82. public function saveshouhuanoneinfo()
  83. {
  84. //保存时时
  85. //保存历史
  86. }
  87. //内容解析
  88. //解析长度
  89. public function analysislen($len)
  90. {
  91. //低位数在前
  92. $len = base_convert($len, 16, 10);
  93. return $len;
  94. }
  95. /**
  96. * 获取命令信息
  97. *
  98. * @param [type] $command
  99. * @return void
  100. * @author wj
  101. * @date 2023-08-11
  102. */
  103. public function getcommandinfo($command)
  104. {
  105. $command = strtoupper($command);
  106. $data = [
  107. 'LK' => [
  108. 'content' => [
  109. 'command' => 'LK',
  110. ],
  111. 'kind' => 'back',
  112. ],
  113. 'PING' => [
  114. 'content' => [
  115. 'command' => 'PING',
  116. 'isbind' => 1,
  117. ],
  118. 'kind' => 'back',
  119. ],
  120. 'KA' => [
  121. 'content' => [
  122. 'command' => 'KA',
  123. ],
  124. 'kind' => 'back',
  125. ],
  126. 'MONITOR' => [
  127. 'content' => [
  128. 'command' => 'MONITOR',
  129. 'telno' => '',
  130. ],
  131. 'kind' => 'send',
  132. ],
  133. 'SOS' => [
  134. 'content' => [
  135. 'command' => 'SOS',
  136. 'telno1' => '',
  137. 'telno2' => '',
  138. 'telno3' => '',
  139. ],
  140. 'kind' => 'send',
  141. ],
  142. 'VERNO' => [
  143. 'content' => [
  144. 'command' => 'VERNO',
  145. ],
  146. 'kind' => 'send',
  147. ],
  148. 'ZONE' => [
  149. 'content' => [
  150. 'command' => 'ZONE',
  151. 'zone' => '',
  152. ],
  153. 'kind' => 'send',
  154. ],
  155. 'POWEROFF' => [
  156. 'content' => [
  157. 'command' => 'POWEROFF',
  158. ],
  159. 'kind' => 'send',
  160. ],
  161. 'TEMP' => [
  162. 'content' => [
  163. 'command' => 'temp',
  164. ],
  165. 'kind' => 'back',
  166. ],
  167. 'BPHRT' => [
  168. 'content' => [
  169. 'command' => 'bphrt',
  170. ],
  171. 'kind' => 'back',
  172. ],
  173. 'HEART' => [
  174. 'content' => [
  175. 'command' => 'heart',
  176. ],
  177. 'kind' => 'back',
  178. ],
  179. 'BLOOD' => [
  180. 'content' => [
  181. 'command' => 'blood',
  182. ],
  183. 'kind' => 'back',
  184. ],
  185. 'OXYGEN' => [
  186. 'content' => [
  187. 'command' => 'oxygen',
  188. ],
  189. 'kind' => 'back',
  190. ],
  191. ];
  192. if (!isset($data[$command])) {
  193. return false;
  194. }
  195. return $data[$command];
  196. }
  197. public function gettsendcommandinfo($command)
  198. {
  199. $command = strtoupper($command);
  200. $data = [
  201. 'WT' => [
  202. 'content' => [
  203. 'command' => 'WT',
  204. 'date' => '',
  205. 'time' => '',
  206. 'is_location' => '',
  207. 'gps_long' => '',
  208. 'gps_long_tag' => '',
  209. 'gps_lat' => '',
  210. 'gps_lat_tag' => '',
  211. 'speed' => '',
  212. 'direction' => '',
  213. 'poster' => '',
  214. 'direction' => '',
  215. 'gps_satellite_num' => '',
  216. 'gsm_signal_strength' => '',
  217. 'electric_quantity' => '',
  218. 'step_number' => '',
  219. 'roll_number' => '',
  220. 'terminal_status' => '',
  221. ],
  222. 'kind' => 'tsend',
  223. 'need_bacl' => 0,
  224. ],
  225. 'WG' => [
  226. 'content' => [
  227. 'command' => 'WT',
  228. 'date' => '',
  229. 'time' => '',
  230. 'is_location' => '',
  231. 'gps_long' => '',
  232. 'gps_long_tag' => '',
  233. 'gps_lat' => '',
  234. 'gps_lat_tag' => '',
  235. 'speed' => '',
  236. 'direction' => '',
  237. 'poster' => '',
  238. 'direction' => '',
  239. 'gps_satellite_num' => '',
  240. 'gsm_signal_strength' => '',
  241. 'electric_quantity' => '',
  242. 'step_number' => '',
  243. 'roll_number' => '',
  244. 'terminal_status' => '',
  245. ],
  246. 'kind' => 'tsend',
  247. 'need_bacl' => 0,
  248. ],
  249. 'KA' => [
  250. 'content' => [
  251. 'command' => 'KA',
  252. 'date' => '',
  253. 'step_number' => '',
  254. 'roll_number' => '',
  255. 'electric_quantity' => '',
  256. ],
  257. 'kind' => 'tsend',
  258. 'need_back' => 1,
  259. ],
  260. 'LK' => [
  261. 'content' => [
  262. 'command' => 'LK',
  263. ],
  264. 'kind' => 'tsend',
  265. 'need_back' => 1,
  266. ],
  267. 'MONITOR' => [
  268. 'content' => [
  269. 'command' => 'MONITOR',
  270. ],
  271. 'kind' => 'tback',
  272. ],
  273. 'SOS3' => [
  274. 'content' => [
  275. 'command' => 'SOS',
  276. ],
  277. 'kind' => 'tback',
  278. ],
  279. 'VERNO' => [
  280. 'content' => [
  281. 'command' => 'VERNO',
  282. 'version' => '',
  283. ],
  284. 'kind' => 'tback',
  285. ],
  286. 'TEMP' => [
  287. 'content' => [
  288. 'command' => 'temp',
  289. 'temp' => '',
  290. ],
  291. 'kind' => 'tsend',
  292. 'need_back' => 1,
  293. ],
  294. 'BPHRT' => [
  295. 'content' => [
  296. 'command' => 'bphrt',
  297. 'blood_height_pressure' => '',
  298. 'blood_low_pressure' => '',
  299. 'heart_rate' => '',
  300. 'height' => '',
  301. 'gender' => '',
  302. 'age' => '',
  303. 'weight' => '',
  304. ],
  305. 'kind' => 'tsend',
  306. 'need_back' => 1,
  307. ],
  308. 'HEART' => [
  309. 'content' => [
  310. 'command' => 'heart',
  311. 'heart_rate' => '',
  312. ],
  313. 'kind' => 'tsend',
  314. 'need_back' => 1,
  315. ],
  316. 'BLOOD' => [
  317. 'content' => [
  318. 'command' => 'blood',
  319. 'blood_height_pressure' => '',
  320. 'blood_low_pressure' => '',
  321. ],
  322. 'kind' => 'tsend',
  323. 'need_back' => 1,
  324. ],
  325. 'OXYGEN' => [
  326. 'content' => [
  327. 'command' => 'oxygen',
  328. 'oxygen' => '',
  329. ],
  330. 'kind' => 'tsend',
  331. 'need_back' => 1,
  332. ],
  333. ];
  334. if (!isset($data[$command])) {
  335. return false;
  336. }
  337. return $data[$command];
  338. }
  339. /**
  340. * 获取回复权重
  341. *
  342. * @param [type] $command
  343. * @return void
  344. * @author wj
  345. * @date 2023-08-11
  346. */
  347. public function getsendweight($command)
  348. {
  349. $weight = -1;
  350. switch ($command) {
  351. case 'POWEROFF':
  352. //关机
  353. $weight = 99;
  354. break;
  355. case 'RESET':
  356. //重启
  357. $weight = 98;
  358. break;
  359. case 'LK':
  360. case 'PING':
  361. case 'KA':
  362. case 'AL':
  363. case 'UD2';
  364. $weight = 1;
  365. break;
  366. case 'UPLOAD':
  367. case 'MONITOR':
  368. case 'SOS':
  369. case 'LANG':
  370. case 'ZONE':
  371. case 'CENTER':
  372. case 'SOSSMS':
  373. case 'REMOVE':
  374. case 'REMOVESMS':
  375. case 'VERNO':
  376. case 'CR':
  377. case 'SILENCETIME2':
  378. case 'WALKTIME':
  379. case 'SLEEPTIME':
  380. case 'FIND':
  381. case 'REMIND':
  382. case 'SCHEDULE':
  383. case 'PHB':
  384. case 'PHBX':
  385. case 'DPHBX':
  386. case 'MESSAGE':
  387. case 'FACTORY':
  388. case 'PROFILE':
  389. case 'BTEMP2':
  390. case 'BODYTEMP':
  391. case 'BTWARNSET':
  392. case 'APPLOCK':
  393. case 'HRTSTART':
  394. case 'BPHRT':
  395. case 'LSSET':
  396. $weight = 0;
  397. break;
  398. default:
  399. $weight = -1;
  400. break;
  401. }
  402. if ($weight < 0) {
  403. //不需设置 发送信息
  404. return false;
  405. }
  406. return $weight;
  407. }
  408. /**
  409. * 获取设别表id
  410. *
  411. * @return void
  412. * @author wj
  413. * @date 2023-08-11
  414. */
  415. public function getfacilityid($device_id_code)
  416. {
  417. $m_f = new FacilityModel();
  418. $where = ['code' => $device_id_code, 'status' => 1];
  419. $finfo = $m_f->getInfo($where, ['id']);
  420. if (empty($finfo)) {
  421. throw new \Exception("设备信息错误:" . $device_id_code);
  422. return false;
  423. }
  424. $id = $finfo['id'];
  425. return $id;
  426. }
  427. /**
  428. * 创建发送信息
  429. *
  430. * @param [type] $data
  431. * @param [type] $command
  432. * @return void
  433. * @author wj
  434. * @date 2023-08-14
  435. */
  436. public function createbacksendmsg($facility_id, $device_id_code, $data, $command)
  437. {
  438. $infoarr = $this->gettsendcommandinfo($command);
  439. if (!$infoarr) {
  440. Log::write("无对应命令数据1:" . $command, 'shouhuan');
  441. Log::write($data, 'shouhuan');
  442. return false;
  443. }
  444. $data = $this->getdata($data, $command, $infoarr);
  445. $info_content = $data['info_content'];
  446. $need_back = isset($data['need_back']) && $data['need_back'] ? true : false;
  447. if ($need_back) {
  448. $infoarr = $this->getcommandinfo($command);
  449. $data = $this->getdata($data, $command, $infoarr);
  450. $info_content = $data['info_content'];
  451. $weight = $this->getsendweight($command);
  452. $content = implode(',', $info_content);
  453. $msgdata = [
  454. 0 => '3G',
  455. 'device_id_code' => $device_id_code,
  456. 'len' => str_pad(dechex(mb_strlen($content)), 4, "0", STR_PAD_LEFT),
  457. 'content' => $content,
  458. ];
  459. $msg = '[' . implode('*', $msgdata) . ']';
  460. $sslInsertData = [
  461. 'facility_id' => $facility_id,
  462. 'device_id_code' => $device_id_code,
  463. 'send_msg' => $msg,
  464. 'send_time' => date('Y-m-d H:i:s'),
  465. 'send_weight' => $weight,
  466. ];
  467. $m_ssl = new ShoneSendListModel();
  468. $sslid = $m_ssl->insertData($sslInsertData);
  469. if (empty($sslid)) {
  470. throw new \Exception("发送数据添加失败");
  471. }
  472. $data = [
  473. 'msg' => $msg,
  474. 'weight' => $weight,
  475. 'createtime' => date('Y-m-d H:i:s'),
  476. 'device_id_code' => $device_id_code,
  477. 'list_id' => $sslid,
  478. ];
  479. $m_ssq = new ShoneSendQueueModel();
  480. $id = $m_ssq->insertData($data);
  481. if (empty($id)) {
  482. throw new \Exception("发送队列数据添加失败");
  483. }
  484. return $data;
  485. }
  486. return false;
  487. }
  488. /**
  489. * 获取数据值
  490. *
  491. * @param [type] $data
  492. * @param [type] $command
  493. * @return void
  494. * @author wj
  495. * @date 2023-08-14
  496. */
  497. public function getdata($data, $command, $infoarr)
  498. {
  499. $info_content = $infoarr['content'];
  500. foreach (array_keys($info_content) as $key => $value) {
  501. if (empty($info_content[$value])) {
  502. if (isset($data[$key])) {
  503. $info_content[$value] = $data[$key];
  504. }
  505. }
  506. }
  507. if (isset($info_content['time'])) {
  508. $time = $info_content['time'];
  509. $info_content['time'] = $this->gettime($time);
  510. }
  511. if (isset($info_content['date'])) {
  512. $date = $info_content['date'];
  513. $info_content['date'] = $this->getdate($date);
  514. }
  515. $infoarr['info_content'] = $info_content;
  516. return $infoarr;
  517. }
  518. /**
  519. * 保存接收信息队列
  520. *
  521. * @param [type] $data
  522. * @return void
  523. * @author wj
  524. * @date 2023-08-14
  525. */
  526. public function savereceivequeue($data)
  527. {
  528. $m_srq = new ShoneReceiveQueueModel();
  529. $data = [
  530. 'msg' => $data,
  531. 'createtime' => date('Y-m-d H:i:s'),
  532. ];
  533. $id = $m_srq->insertData($data);
  534. //Log::write('id:' . $id, 'shouhuan');
  535. if (empty($id)) {
  536. return false;
  537. }
  538. return true;
  539. }
  540. /**
  541. * 保存手环信息
  542. *
  543. * @return void
  544. * @author wj
  545. * @date 2023-08-14
  546. */
  547. public function saveshinfo($facility_id, $device_id_code, $data, $original_str)
  548. {
  549. $command = $data[0];
  550. $infoarr = $this->gettsendcommandinfo($command);
  551. if (!$infoarr) {
  552. Log::write("无对应命令数据2:" . $command, 'shouhuan');
  553. Log::write($original_str, 'shouhuan');
  554. return false;
  555. }
  556. $data = $this->getdata($data, $data[0], $infoarr);
  557. $m_sri = new ShoneReceiveInfoModel();
  558. $m_srir = new ShoneReceiveInfoRecode();
  559. $data = $data['info_content'];
  560. $data['facility_id'] = $facility_id;
  561. $data['device_id_code'] = $device_id_code;
  562. //$m_sri处理
  563. $sriwhere = [
  564. 'facility_id' => $facility_id,
  565. 'device_id_code' => $device_id_code,
  566. ];
  567. $sriinfo = $m_sri->getInfo($sriwhere);
  568. unset($data['command']);
  569. if (empty($sriinfo)) {
  570. $sriinsertData = $data;
  571. $sriinsertData['createtime'] = date('Y-m-d H:i:s');
  572. $sriinsertData = $m_sri->formatinfo($sriinsertData);
  573. $sriid = $m_sri->insertData($sriinsertData);
  574. if (empty($sriid)) {
  575. throw new \Exception("设备信息添加失败:" . $device_id_code);
  576. }
  577. } else {
  578. unset($data['device_id_code']);
  579. unset($data['facility_id']);
  580. $sriid = $sriinfo['id'];
  581. $sriupdateData = $data;
  582. $sriupdateData['updatetime'] = date('Y-m-d H:i:s');
  583. $sriupdateData = $m_sri->formatinfo($sriupdateData);
  584. $row = $m_sri->updateinfo(['id' => $sriid], $sriupdateData);
  585. if (empty($row)) {
  586. throw new \Exception("设备信息修改失败:" . $device_id_code);
  587. }
  588. }
  589. //m_srir处理
  590. $data['original_str'] = $original_str;
  591. $sririnsertData = $data;
  592. $sririnsertData['facility_id'] = $facility_id;
  593. $sririnsertData['device_id_code'] = $device_id_code;
  594. $sririnsertData['createtime'] = date('Y-m-d H:i:s');
  595. $sririnsertData['command'] = $command;
  596. $sririd = $m_srir->insertData($sririnsertData);
  597. if (empty($sririd)) {
  598. throw new \Exception("设备历史信息添加失败:" . $device_id_code);
  599. }
  600. }
  601. /**
  602. * 获取接收信息队列列表
  603. *
  604. * @param [type] $page
  605. * @param [type] $size
  606. * @return void
  607. * @author wj
  608. * @date 2023-08-14
  609. */
  610. public function getreceivequeuelist($page = null, $size = null)
  611. {
  612. $m_srq = new ShoneReceiveQueueModel();
  613. $where = ['status' => 0];
  614. $size = empty($size) ? 20 : $size;
  615. if (empty($page)) {
  616. $count = $m_srq->getList($where, 'count');
  617. $totalpage = ceil($count / $size);
  618. $data = ['totalpage' => $totalpage, 'size' => $size];
  619. return $data;
  620. } else {
  621. $list = $m_srq->getList($where, '*', $page, $size, 'id asc');
  622. if (empty($list)) {
  623. //Log::write("手环接收信息队列-无数据", 'shouhuan');
  624. return false;
  625. }
  626. $list = $list->toArray();
  627. $ids = array_column($list, 'id');
  628. $updatecount = $m_srq->updateinfo(['id' => ['in', $ids], 'status' => 0], ['status' => 1]);
  629. if ($updatecount != count($ids)) {
  630. //Log::write("手环接收信息队列-部分未修改", 'shouhuan');
  631. $updatecount = empty($updatecount) ? 0 : (int) $updatecount;
  632. Log::write("count:" . count($ids) . " update count:" . $updatecount, 'shouhuan');
  633. }
  634. if (empty($updatecount)) {
  635. //Log::write("手环接收信息队列-无修改数据", 'shouhuan');
  636. return false;
  637. }
  638. return $list;
  639. }
  640. }
  641. /**
  642. * 获取发送信息队列列表
  643. *
  644. * @param [type] $page
  645. * @param [type] $size
  646. * @return void
  647. * @author wj
  648. * @date 2023-08-14
  649. */
  650. public function getsendqueuelist($device_id_code, $page = null, $size = null)
  651. {
  652. $m_ssq = new ShoneSendQueueModel();
  653. $where = ['status' => 0, 'device_id_code' => $device_id_code];
  654. $size = empty($size) ? 20 : $size;
  655. if (empty($page)) {
  656. $count = $m_ssq->getList($where, 'count');
  657. $totalpage = ceil($count / $size);
  658. $data = ['totalpage' => $totalpage, 'size' => $size];
  659. return $data;
  660. } else {
  661. $list = $m_ssq->getList($where, '*', $page, $size, 'id asc,weight desc');
  662. if (empty($list)) {
  663. Log::write("手环发送信息队列-无数据", 'shouhuan');
  664. return false;
  665. }
  666. $list = $list->toArray();
  667. $ids = array_column($list, 'id');
  668. $updatecount = $m_ssq->updateinfo(['id' => ['in', $ids], 'status' => 0], ['status' => 1]);
  669. if ($updatecount != count($ids)) {
  670. Log::write("手环发送信息队列-部分未修改", 'shouhuan');
  671. Log::write("count:" . count($ids) . " update count:" . $updatecount, 'shouhuan');
  672. }
  673. if (empty($updatecount)) {
  674. Log::write("手环发送信息队列-无修改数据", 'shouhuan');
  675. return false;
  676. }
  677. return $list;
  678. }
  679. }
  680. public function sendmsgsuccess($item)
  681. {
  682. $m_ssq = new ShoneSendQueueModel();
  683. $m_ssl = new ShoneSendListModel();
  684. $ssqid = $item['id'];
  685. if ($item['list_id']) {
  686. $list_id = $item['list_id'];
  687. $sslwhere = ['id' => $list_id, 'is_send' => 0];
  688. $sslinfo = $m_ssl->getInfo($sslwhere);
  689. if ($sslinfo) {
  690. $row = $m_ssl->updateinfo(['id' => $sslinfo['id']], ['is_send' => 1, 'send_time' => date('Y-m-d H:i:s')]);
  691. }
  692. }
  693. $ssqwhere = ['id' => $ssqid];
  694. $ssqinfo = $m_ssq->getInfo($ssqwhere);
  695. if ($ssqinfo) {
  696. $m_ssq->deleteinfobyid($ssqid);
  697. }
  698. }
  699. public function receivemsgsuccess($item)
  700. {
  701. $m_srq = new ShoneReceiveQueueModel();
  702. $srqid = $item['id'];
  703. $srqwhere = ['id' => $srqid, 'status' => 1];
  704. $srqinfo = $m_srq->getInfo($srqwhere);
  705. if ($srqinfo) {
  706. $m_srq->deleteinfobyid($srqid);
  707. }
  708. }
  709. /**
  710. * 日期解析
  711. *
  712. * @return void
  713. * @author wj
  714. * @date 2023-08-15
  715. */
  716. public function getdate($date)
  717. {
  718. $day = substr($date, 0, 2);
  719. $month = substr($date, 2, 2);
  720. $year = substr($date, 4, 2);
  721. $year1 = date('Y');
  722. $year2 = substr($year1, 0, 2);
  723. $year = $year2 . $year;
  724. if ($year != $year1) {
  725. $day = date('Y-m-d');
  726. } else {
  727. $day = $year . '-' . $month . '-' . $day;
  728. }
  729. return $day;
  730. }
  731. public function gettime($time)
  732. {
  733. $hour = substr($time, 0, 2);
  734. $minute = substr($time, 2, 2);
  735. $second = substr($time, 4, 2);
  736. $time = $hour . ':' . $minute . ':' . $second;
  737. return $time;
  738. }
  739. /**
  740. * 初始化手环接收信息解析
  741. *
  742. * @return void
  743. * @author wj
  744. * @date 2023-08-15
  745. */
  746. public function initanalysisShoneReceiveMsg()
  747. {
  748. $m_srq = new ShoneReceiveQueueModel();
  749. $where = ['status' => 1];
  750. $m_srq->updateinfo($where, ['status' => 0]);
  751. }
  752. /**
  753. * 拆包
  754. *
  755. * @return void
  756. * @author wj
  757. * @date 2023-08-15
  758. */
  759. public function unpack($data)
  760. {
  761. $arr = explode("][", $data);
  762. foreach ($arr as $key => $value) {
  763. if ($value[0] !== "[") {
  764. $arr[$key] = '[' . $value;
  765. }
  766. if ($value[mb_strlen($value) - 1] !== "]") {
  767. $arr[$key] .= "]";
  768. }
  769. }
  770. return $arr;
  771. }
  772. public function showfortest($data)
  773. {
  774. $strdata = $this->getline($data);
  775. $content = $strdata['content_str'];
  776. $content = $this->getcommandcontent($content);
  777. $command = $content[0];
  778. $showcommands = ['SOS', 'CR', 'UPLOAD', 'SLEEPTIME'];
  779. if (in_array($command, $showcommands)) {
  780. var_dump($data);
  781. }
  782. }
  783. }