SouhuanAnalysis.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464
  1. <?php
  2. namespace app\common\server;
  3. use app\common\model\FacilityModel;
  4. use app\common\model\ShalarmlistModel;
  5. use app\common\model\ShinfoModel;
  6. use app\common\model\ShreceivequeueModel;
  7. use app\common\model\ShreceiveredocdeModel;
  8. use app\common\model\ShsendlistModel;
  9. use app\common\model\ShsendqueueModel;
  10. use think\facade\Log;
  11. /**
  12. * 手环字符串解析
  13. *
  14. * @author wj
  15. * @date 2023-08-11
  16. */
  17. class SouhuanAnalysis
  18. {
  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. Log::write("长度校验失败: len:" . $len . " str:" . $str, 'shouhuan');
  31. return false;
  32. }
  33. return true;
  34. }
  35. /**
  36. * 获取信息 整个信息解析
  37. * 并验证是否可解析 无解析命令配置 不报错
  38. *
  39. * @return void
  40. * @author wj
  41. * @date 2023-08-11
  42. */
  43. public function getline($str, $field = null)
  44. {
  45. //[厂商*设备 ID*内容长度*内容]
  46. $preg = "/^\[(.*)\*(.*)\*(.*)\*(.*)\]$/";
  47. preg_match($preg, $str, $match);
  48. if (empty($match)) {
  49. Log::write("解析失败:" . $str, 'shouhuan');
  50. throw new \Exception('解析失败:' . $str);
  51. }
  52. unset($match[0]);
  53. $data = array_values($match);
  54. $sandom_string = $data[0]; //厂商 随机字符串
  55. $device_id_code = $data[1]; //设置id编码
  56. $content_len = $data[2]; //内容长度
  57. $content_str = $data[3]; //内容字符串
  58. $content_len = $this->analysislen($content_len);
  59. $result = $this->checklen($content_len, $content_str);
  60. if (empty($result)) {
  61. $errmsg = '内容位数错误';
  62. Log::write($errmsg . ":" . $str, 'shouhuan');
  63. throw new \Exception($errmsg);
  64. }
  65. $data = [
  66. 'device_id_code' => $device_id_code,
  67. 'content_len' => $content_len,
  68. 'content_str' => $content_str,
  69. ];
  70. $contentarr = $this->getcommandcontent($content_str);
  71. $command = $contentarr['command'];
  72. $data['command'] = $command;
  73. $data['content_arr'] = $contentarr['content'];
  74. $config = $this->getreceivecommandinfo($command);
  75. $data['config'] = $config;
  76. if (!$config) {
  77. $errmsg = '命令无解析配置 command:' . $command;
  78. Log::write($errmsg, 'shouhuan');
  79. return false;
  80. }
  81. if (isset($field)) {
  82. return $data[$field];
  83. }
  84. return $data;
  85. }
  86. /**
  87. * 内容解析
  88. *
  89. * @param [type] $content_str
  90. * @return void
  91. * @author wj
  92. * @date 2023-08-19
  93. */
  94. public function getcommandcontent($content_str)
  95. {
  96. $content = explode(',', $content_str);
  97. $command = $content[0];
  98. unset($content[0]);
  99. $data = [
  100. 'command' => $command,
  101. 'content' => $content,
  102. ];
  103. return $data;
  104. }
  105. /**
  106. * 解析终端发送命令长度
  107. *
  108. * @param [type] $len
  109. * @return void
  110. * @author wj
  111. * @date 2023-08-18
  112. */
  113. public function analysislen($len)
  114. {
  115. $len = base_convert($len, 16, 10);
  116. return $len;
  117. }
  118. /**
  119. * 获取平台发送命令信息
  120. *
  121. * @param [type] $command
  122. * @return void
  123. * @author wj
  124. * @date 2023-08-11
  125. */
  126. public function getsendcommandinfo($command)
  127. {
  128. $command = strtoupper($command);
  129. $data = [
  130. //平台发送
  131. 'ZONE' => [
  132. 'content' => [
  133. 'command' => 'ZONE',
  134. 'zone' => '',
  135. ],
  136. 'kind' => 'send',
  137. 'need_back' => 1,
  138. ],
  139. 'UPLOAD' => [
  140. 'content' => [
  141. 'command' => 'UPLOAD',
  142. ],
  143. 'kind' => 'send',
  144. 'need_back' => 1,
  145. ],
  146. 'CR' => [
  147. 'content' => [
  148. 'command' => 'CR',
  149. ],
  150. 'kind' => 'send',
  151. 'need_back' => 1,
  152. ],
  153. 'SLEEPTIME' => [
  154. 'content' => [
  155. 'command' => 'CR',
  156. ],
  157. 'kind' => 'send',
  158. 'content_custom' => true,
  159. 'need_back' => 1,
  160. ],
  161. 'FALLDOWN' => [
  162. 'content' => [
  163. 'command' => 'FALLDOWN',
  164. 'is_open' => '',
  165. ],
  166. 'kind' => 'send',
  167. 'need_back' => 1,
  168. ],
  169. 'FACTORY' => [
  170. 'content' => [
  171. 'command' => 'FACTORY',
  172. ],
  173. 'kind' => 'send',
  174. 'need_back' => 1,
  175. ],
  176. 'SOS' => [
  177. 'content' => [
  178. 'command' => 'SOS',
  179. ],
  180. 'kind' => 'send',
  181. 'content_custom' => true,
  182. 'need_back' => 1,
  183. ],
  184. 'VERNO' => [
  185. 'content' => [
  186. 'command' => 'VERNO',
  187. ],
  188. 'kind' => 'send',
  189. 'need_back' => 1,
  190. ],
  191. 'LOWBAT' => [
  192. 'content' => [
  193. 'command' => 'LOWBAT',
  194. 'is_open' => '',
  195. ],
  196. 'kind' => 'send',
  197. 'need_back' => 1,
  198. ],
  199. 'POWEROFF' => [
  200. 'content' => [
  201. 'command' => 'POWEROFF',
  202. ],
  203. 'kind' => 'send',
  204. 'need_back' => 1,
  205. ],
  206. 'LSSET' => [
  207. 'content' => [
  208. 'command' => 'LSSET',
  209. 'content_custom' => true,
  210. ],
  211. 'kind' => 'send',
  212. 'need_back' => 1,
  213. ],
  214. 'PEDO' => [
  215. 'content' => [
  216. 'command' => 'PEDO',
  217. 'is_open' => '',
  218. ],
  219. 'kind' => 'send',
  220. 'need_back' => 1,
  221. ],
  222. 'PHL' => [
  223. 'content' => [
  224. 'command' => 'PEDO',
  225. ],
  226. 'kind' => 'send',
  227. 'content_custom' => true,
  228. 'need_back' => 1,
  229. ],
  230. 'REMIND' => [
  231. 'content' => [
  232. 'command' => 'REMIND',
  233. ],
  234. 'kind' => 'send',
  235. 'content_custom' => true,
  236. 'need_back' => 1,
  237. ],
  238. 'SILENCETIME2' => [
  239. 'content' => [
  240. 'command' => 'SILENCETIME2',
  241. ],
  242. 'kind' => 'send',
  243. 'content_custom' => true,
  244. 'need_back' => 1,
  245. ],
  246. 'BOOTOFF' => [
  247. 'content' => [
  248. 'command' => 'BOOTOFF',
  249. 'is_open' => '',
  250. 'bootup_time' => '',
  251. 'shutdown_time' => '',
  252. ],
  253. 'kind' => 'send',
  254. 'need_back' => 1,
  255. ],
  256. 'REMOVE' => [
  257. 'content' => [
  258. 'command' => 'REMOVE',
  259. 'is_open' => '',
  260. ],
  261. 'kind' => 'send',
  262. 'need_back' => 1,
  263. ],
  264. //平台回复
  265. 'LK' => [
  266. 'content' => [
  267. 'command' => 'LK',
  268. ],
  269. 'kind' => 'back',
  270. ],
  271. 'PING' => [
  272. 'content' => [
  273. 'command' => 'PING',
  274. 'isbind' => 1,
  275. ],
  276. 'kind' => 'back',
  277. ],
  278. 'KA' => [
  279. 'content' => [
  280. 'command' => 'KA',
  281. ],
  282. 'kind' => 'back',
  283. ],
  284. 'TEMP' => [
  285. 'content' => [
  286. 'command' => 'temp',
  287. ],
  288. 'kind' => 'back',
  289. ],
  290. 'BPHRT' => [
  291. 'content' => [
  292. 'command' => 'bphrt',
  293. ],
  294. 'kind' => 'back',
  295. ],
  296. 'HEART' => [
  297. 'content' => [
  298. 'command' => 'heart',
  299. ],
  300. 'kind' => 'back',
  301. ],
  302. 'BLOOD' => [
  303. 'content' => [
  304. 'command' => 'blood',
  305. ],
  306. 'kind' => 'back',
  307. ],
  308. 'OXYGEN' => [
  309. 'content' => [
  310. 'command' => 'oxygen',
  311. ],
  312. 'kind' => 'back',
  313. ],
  314. 'AL' => [
  315. 'content' => [
  316. 'command' => 'AL',
  317. ],
  318. 'kind' => 'back',
  319. ],
  320. ];
  321. if (!isset($data[$command])) {
  322. return false;
  323. }
  324. return $data[$command];
  325. }
  326. /**
  327. * 设置可解析数据 终端发送信息解析
  328. *
  329. * @param [type] $command
  330. * @return void
  331. * @author wj
  332. * @date 2023-08-18
  333. * analysis_digit 解析位数
  334. * content 解析对应字段
  335. * kind 类型 tsend 平台发送 tback平台回复
  336. * need_back 是否需回复 1是 0否 没设置为0
  337. * command 未设置则和键值相同
  338. */
  339. public function getreceivecommandinfo($command)
  340. {
  341. $command = strtoupper($command);
  342. $data = [
  343. 'UD' => [
  344. 'analysis_digit' => [1, 2, 4, 6, 8, 9, 10, 13, 14, 15, 16],
  345. 'content' => [
  346. 'date',
  347. 'time',
  348. 'gps_long',
  349. 'gps_lat',
  350. 'speed',
  351. 'direction',
  352. 'poster',
  353. 'electric_quantity',
  354. 'step_number',
  355. 'roll_number',
  356. 'terminal_status',
  357. ],
  358. 'kind' => 'tsend',
  359. 'need_back' => 0,
  360. ],
  361. 'AL' => [
  362. 'analysis_digit' => [1, 2, 4, 6, 8, 9, 10, 13, 14, 15, 16],
  363. 'content' => [
  364. 'date',
  365. 'time',
  366. 'gps_long',
  367. 'gps_lat',
  368. 'speed',
  369. 'direction',
  370. 'poster',
  371. 'electric_quantity',
  372. 'step_number',
  373. 'roll_number',
  374. 'terminal_status',
  375. ],
  376. 'kind' => 'tsend',
  377. 'need_back' => 0,
  378. ],
  379. 'KA' => [
  380. 'analysis_digit' => [1, 2, 3, 4],
  381. 'content' => [
  382. 'date',
  383. 'step_number',
  384. 'roll_number',
  385. 'electric_quantity',
  386. ],
  387. 'kind' => 'tsend',
  388. 'need_back' => 1,
  389. ],
  390. 'LK' => [
  391. 'analysis_digit' => null,
  392. 'content' => null,
  393. 'kind' => 'tsend',
  394. 'need_back' => 1,
  395. ],
  396. 'BPHRT' => [
  397. 'analysis_digit' => [1, 2, 3],
  398. 'content' => [
  399. 'blood_height_pressure',
  400. 'blood_low_pressure',
  401. 'heart_rate',
  402. ],
  403. 'kind' => 'tsend',
  404. 'need_back' => 1,
  405. 'command' => 'bphrt',
  406. ],
  407. 'TEMP' => [
  408. 'analysis_digit' => [1],
  409. 'content' => [
  410. 'temp',
  411. ],
  412. 'kind' => 'tsend',
  413. 'need_back' => 1,
  414. 'command' => 'temp',
  415. ],
  416. 'HEART' => [
  417. 'analysis_digit' => [1],
  418. 'content' => [
  419. 'heart_rate',
  420. ],
  421. 'kind' => 'tsend',
  422. 'need_back' => 1,
  423. 'command' => 'heart',
  424. ],
  425. 'BLOOD' => [
  426. 'analysis_digit' => [1, 2],
  427. 'content' => [
  428. 'blood_height_pressure',
  429. 'blood_low_pressure',
  430. ],
  431. 'kind' => 'tsend',
  432. 'need_back' => 1,
  433. 'command' => 'blood',
  434. ],
  435. 'OXYGEN' => [
  436. 'analysis_digit' => [1],
  437. 'content' => [
  438. 'oxygen',
  439. ],
  440. 'kind' => 'tsend',
  441. 'need_back' => 1,
  442. 'command' => 'oxygen',
  443. ],
  444. //终端回复
  445. //ZONE UPLOAD CR SLEEPTIME FALLDOWN FACTORY SOS VERNO LOWBAT
  446. //POWEROFF LSSET PEDO PHL REMIND SILENCETIME2 BOOTOFF REMOVE
  447. 'ZONE' => [
  448. 'analysis_digit' => null,
  449. 'content' => null,
  450. 'kind' => 'tback',
  451. ],
  452. 'UPLOAD' => [
  453. 'analysis_digit' => null,
  454. 'content' => null,
  455. 'kind' => 'tback',
  456. ],
  457. 'CR' => [
  458. 'analysis_digit' => null,
  459. 'content' => null,
  460. 'kind' => 'tback',
  461. ],
  462. 'SLEEPTIME' => [
  463. 'analysis_digit' => null,
  464. 'content' => null,
  465. 'kind' => 'tback',
  466. ],
  467. 'FALLDOWN' => [
  468. 'analysis_digit' => null,
  469. 'content' => null,
  470. 'kind' => 'tback',
  471. ],
  472. 'SOS' => [
  473. 'analysis_digit' => null,
  474. 'content' => null,
  475. 'kind' => 'tback',
  476. ],
  477. 'VERNO' => [
  478. 'analysis_digit' => [1],
  479. 'content' => ['version'],
  480. 'kind' => 'tback',
  481. ],
  482. 'LOWBAT' => [
  483. 'analysis_digit' => null,
  484. 'content' => null,
  485. 'kind' => 'tback',
  486. ],
  487. 'POWEROFF' => [
  488. 'analysis_digit' => null,
  489. 'content' => null,
  490. 'kind' => 'tback',
  491. ],
  492. 'LSSET' => [
  493. 'analysis_digit' => null,
  494. 'content' => null,
  495. 'kind' => 'tback',
  496. ],
  497. 'PEDO' => [
  498. 'analysis_digit' => null,
  499. 'content' => null,
  500. 'kind' => 'tback',
  501. ],
  502. 'PHL' => [
  503. 'analysis_digit' => null,
  504. 'content' => null,
  505. 'kind' => 'tback',
  506. ],
  507. 'REMIND' => [
  508. 'analysis_digit' => null,
  509. 'content' => null,
  510. 'kind' => 'tback',
  511. ],
  512. 'SILENCETIME2' => [
  513. 'analysis_digit' => null,
  514. 'content' => null,
  515. 'kind' => 'tback',
  516. ],
  517. 'BOOTOFF' => [
  518. 'analysis_digit' => null,
  519. 'content' => null,
  520. 'kind' => 'tback',
  521. ],
  522. 'REMOVE' => [
  523. 'analysis_digit' => null,
  524. 'content' => null,
  525. 'kind' => 'tback',
  526. ],
  527. ];
  528. if (!isset($data[$command])) {
  529. return false;
  530. }
  531. return $data[$command];
  532. }
  533. /**
  534. * 获取回复权重
  535. *
  536. * @param [type] $command
  537. * @return void
  538. * @author wj
  539. * @date 2023-08-11
  540. */
  541. public function getsendweight($command)
  542. {
  543. $weight = -1;
  544. switch ($command) {
  545. case 'POWEROFF':
  546. //关机
  547. $weight = 99;
  548. break;
  549. case 'RESET':
  550. //重启
  551. $weight = 98; //硬件未测试
  552. break;
  553. //平台回复命令
  554. case 'AL':
  555. case 'KA':
  556. case 'LK':
  557. case 'PING':
  558. case 'BPHRT':
  559. case 'TEMP':
  560. case 'HEART':
  561. case 'BLOOD':
  562. case 'OXYGEN':
  563. $weight = 1;
  564. break;
  565. //平台发送命令
  566. case 'ZONE':
  567. case 'UPLOAD':
  568. case 'CR':
  569. case 'SLEEPTIME':
  570. case 'FALLDOWN':
  571. case 'FACTORY':
  572. case 'SOS':
  573. case 'VERNO':
  574. case 'LOWBAT':
  575. case 'POWEROFF':
  576. case 'LSSET':
  577. case 'PEDO':
  578. case 'PHL':
  579. case 'REMIND':
  580. case 'SILENCETIME2':
  581. case 'BOOTOFF':
  582. case 'REMOVE':
  583. $weight = 0;
  584. break;
  585. default:
  586. $weight = -1;
  587. break;
  588. }
  589. if ($weight < 0) {
  590. //不需设置 发送信息
  591. return false;
  592. }
  593. return $weight;
  594. }
  595. /**
  596. * 获取数据值
  597. *
  598. * @param [type] $data
  599. * @param [type] $command
  600. * @return void
  601. * @author wj
  602. * @date 2023-08-14
  603. */
  604. public function getdata($config, $content_arr)
  605. {
  606. $analysis_digit = $config['analysis_digit'];
  607. $config_content = $config['content'];
  608. $data = [];
  609. if (is_array($analysis_digit)) {
  610. foreach ($analysis_digit as $key => $value) {
  611. if (isset($content_arr[$value])) {
  612. if (isset($config_content[$key])) {
  613. $item_key = $config_content[$key];
  614. $item_value = $content_arr[$value];
  615. $data[$item_key] = $item_value;
  616. }
  617. }
  618. }
  619. }
  620. if (isset($data['time'])) {
  621. $time = $data['time'];
  622. $data['time'] = $this->gettime($time);
  623. }
  624. if (isset($data['date'])) {
  625. $date = $data['date'];
  626. $data['date'] = $this->getdate($date);
  627. }
  628. if (isset($data['terminal_status'])) {
  629. $terminalstatus = $data['terminal_status'];
  630. $terminal_status_arr = $this->getterminalstatus($terminalstatus);
  631. unset($data['terminal_status']);
  632. $data['status_type'] = $terminal_status_arr['status_type'];
  633. $data['alarm_type'] = $terminal_status_arr['alarm_type'];
  634. }
  635. return $data;
  636. }
  637. /**
  638. * 时间解析
  639. *
  640. * @param [type] $time
  641. * @return void
  642. * @author wj
  643. * @date 2023-08-19
  644. */
  645. public function gettime($time)
  646. {
  647. $hour = substr($time, 0, 2);
  648. $minute = substr($time, 2, 2);
  649. $second = substr($time, 4, 2);
  650. $time = $hour . ':' . $minute . ':' . $second;
  651. return $time;
  652. }
  653. /**
  654. * 日期解析
  655. *
  656. * @return void
  657. * @author wj
  658. * @date 2023-08-15
  659. */
  660. public function getdate($date)
  661. {
  662. $day = substr($date, 0, 2);
  663. $month = substr($date, 2, 2);
  664. $year = substr($date, 4, 2);
  665. $year1 = date('Y');
  666. $year2 = substr($year1, 0, 2);
  667. $year = $year2 . $year;
  668. if ($year != $year1) {
  669. $day = date('Y-m-d');
  670. } else {
  671. $day = $year . '-' . $month . '-' . $day;
  672. }
  673. return $day;
  674. }
  675. /**
  676. * 解析终端状态
  677. *
  678. * @param [type] $terminal_status
  679. * @return void
  680. * @author wj
  681. * @date 2023-08-19
  682. */
  683. public function getterminalstatus($terminal_status)
  684. {
  685. $terminal_status = str_split($terminal_status);
  686. foreach ($terminal_status as $key => $value) {
  687. $value = base_convert($value, 16, 2);
  688. $value = str_pad($value, 4, "0", STR_PAD_LEFT);
  689. $terminal_status[$key] = $value;
  690. }
  691. $terminal_status_str = implode("", $terminal_status);
  692. $mid = mb_strlen($terminal_status_str) / 2;
  693. $alarm = substr($terminal_status_str, 0, $mid);
  694. $first_num = strpos($alarm, '1');
  695. $end_num = strrpos($alarm, '1');
  696. if ($first_num != $end_num) {
  697. Log::write("状态解析错误:报警:" . $terminal_status . " " . $terminal_status_str, 'shouhuan');
  698. }
  699. //16:SOS报警;17:低电报警;20:手环拆除报警;21:跌倒报警;22:心率异常报警
  700. $first_num = $mid - $first_num + ($mid - 1);
  701. $alarm_type = $first_num;
  702. $status = substr($terminal_status_str, $mid);
  703. $first_num = strpos($status, '1');
  704. $end_num = strrpos($status, '1');
  705. if ($first_num != $end_num) {
  706. Log::write("状态解析错误:状态:" . $terminal_status . " " . $terminal_status_str, 'shouhuan');
  707. }
  708. $first_num = $mid - 1 - $first_num;
  709. //1:低电状态;2:出围栏状态;3:进围栏状态;4:手环戴上取下状态;5:手表运行静止状态
  710. $status_type = $first_num + 1;
  711. $data = [
  712. 'alarm_type' => $alarm_type,
  713. 'status_type' => $status_type,
  714. ];
  715. return $data;
  716. }
  717. // /**
  718. // * 解析报警
  719. // *
  720. // * @param [type] $first_num
  721. // * @return void
  722. // * @author wj
  723. // * @date 2023-08-19
  724. // */
  725. // public function getalarm($first_num)
  726. // {
  727. // $data = [
  728. // 16 => 'SOS报警',
  729. // 17 => '低电报警',
  730. // 18 => '出围栏报警',
  731. // 19 => '进围栏报警',
  732. // 20 => '手环拆除报警',
  733. // 21 => '跌倒报警',
  734. // 22 => '心率异常报警',
  735. // ];
  736. // if (isset($data[$first_num])) {
  737. // return $data[$first_num];
  738. // }
  739. // return false;
  740. // }
  741. // /**
  742. // * 解析状态
  743. // *
  744. // * @param [type] $first_num
  745. // * @return void
  746. // * @author wj
  747. // * @date 2023-08-19
  748. // */
  749. // public function getstatus($first_num)
  750. // {
  751. // $data = [
  752. // 0 => '低电状态',
  753. // 1 => '出围栏状态',
  754. // 2 => '进围栏状态',
  755. // 3 => '手环戴上取下状态',
  756. // 4 => '手表运行静止状态',
  757. // ];
  758. // if (isset($data[$first_num])) {
  759. // return $data[$first_num];
  760. // }
  761. // return false;
  762. // }
  763. // ̄へ ̄-----------内容解析结束---------------- ̄へ ̄
  764. // ̄へ ̄-----------业务处理开始---------------- ̄へ ̄
  765. /**
  766. * 获取设别表id
  767. *
  768. * @return void
  769. * @author wj
  770. * @date 2023-08-11
  771. */
  772. public function getfacilityid($device_id_code)
  773. {
  774. $m_f = new FacilityModel();
  775. $where = ['code' => $device_id_code, 'status' => 1];
  776. $finfo = $m_f->getInfo($where, ['id']);
  777. if (empty($finfo)) {
  778. throw new \Exception("设备信息错误:" . $device_id_code);
  779. return false;
  780. }
  781. $id = $finfo['id'];
  782. return $id;
  783. }
  784. /**
  785. * 保存接收信息队列
  786. *
  787. * @param [type] $data
  788. * @return void
  789. * @author wj
  790. * @date 2023-08-14
  791. */
  792. public function savereceivequeue($data)
  793. {
  794. $m_srq = new ShreceivequeueModel();
  795. $data = [
  796. 'msg' => $data,
  797. 'createtime' => date('Y-m-d H:i:s'),
  798. ];
  799. $id = $m_srq->insertData($data);
  800. if (empty($id)) {
  801. return false;
  802. }
  803. return true;
  804. }
  805. /**
  806. * 获取接收信息队列列表
  807. *
  808. * @param [type] $page
  809. * @param [type] $size
  810. * @return void
  811. * @author wj
  812. * @date 2023-08-14
  813. */
  814. public function getreceivequeuelist($page = null, $size = null)
  815. {
  816. $m_srq = new ShreceivequeueModel();
  817. $where = ['status' => 0];
  818. $size = empty($size) ? 20 : $size;
  819. if (empty($page)) {
  820. $count = $m_srq->getList($where, 'count');
  821. $totalpage = ceil($count / $size);
  822. $data = ['totalpage' => $totalpage, 'size' => $size];
  823. return $data;
  824. } else {
  825. $list = $m_srq->getList($where, '*', $page, $size, 'id asc');
  826. if (empty($list)) {
  827. //Log::write("手环接收信息队列-无数据", 'shouhuan');
  828. return false;
  829. }
  830. $list = $list->toArray();
  831. foreach ($list as $key => $value) {
  832. $id = $value['id'];
  833. if (1 != $value['status']) {
  834. $row = $m_srq->updateinfo(['id' => $id], ['status' => 1]);
  835. if (1 != $row) {
  836. $msg = "Shreceivequeue id:" . $id . " 修改失败";
  837. Log::write($msg, 'shouhuan');
  838. unset($list[$key]);
  839. }
  840. }
  841. }
  842. return $list;
  843. }
  844. }
  845. /**
  846. * 获取发送信息队列列表
  847. *
  848. * @param [type] $page
  849. * @param [type] $size
  850. * @return void
  851. * @author wj
  852. * @date 2023-08-14
  853. */
  854. public function getsendqueuelist($device_id_code, $page = null, $size = null)
  855. {
  856. $m_ssq = new ShsendqueueModel();
  857. $where = ['status' => 0, 'device_id_code' => $device_id_code];
  858. $size = empty($size) ? 20 : $size;
  859. if (empty($page)) {
  860. $count = $m_ssq->getList($where, 'count');
  861. $totalpage = ceil($count / $size);
  862. $data = ['totalpage' => $totalpage, 'size' => $size];
  863. return $data;
  864. } else {
  865. $list = $m_ssq->getList($where, '*', $page, $size, 'id asc,weight desc');
  866. if (empty($list)) {
  867. Log::write("手环发送信息队列-无数据", 'shouhuan');
  868. return false;
  869. }
  870. $list = $list->toArray();
  871. foreach ($list as $key => $value) {
  872. $id = $value['id'];
  873. if (1 != $value['status']) {
  874. $row = $m_ssq->updateinfo(['id' => $id], ['status' => 1]);
  875. if (1 != $row) {
  876. $msg = "Shsendqueue id:" . $id . " 修改失败";
  877. Log::write($msg, 'shouhuan');
  878. unset($list[$key]);
  879. }
  880. }
  881. }
  882. return $list;
  883. }
  884. }
  885. /**
  886. * 保存手环信息
  887. *
  888. * @return void
  889. * @author wj
  890. * @date 2023-08-14
  891. */
  892. public function saveshinfo($facility_id, $device_id_code, $data, $original_str)
  893. {
  894. $command = $data['command'];
  895. $content_arr = $data['content_arr'];
  896. $config = $data['config'];
  897. $data = $this->getdata($config, $content_arr);
  898. $m_sri = new ShinfoModel();
  899. $m_srir = new ShreceiveredocdeModel();
  900. $m_sa = new ShalarmlistModel();
  901. if ('AL' == $command) {
  902. //手环警报信息
  903. $data['alarm_from_type'] = 1;
  904. $said = $m_sa->insertData($data);
  905. if (empty($said)) {
  906. $msg = "报警信息添加失败:" . $original_str;
  907. Log::write($msg, 'shouhuan');
  908. throw new \Exception($msg);
  909. }
  910. } else {
  911. //手环基础信息修改
  912. $sriData = $data;
  913. $sriwhere = [
  914. 'facility_id' => $facility_id,
  915. 'device_id_code' => $device_id_code,
  916. ];
  917. $sriinfo = $m_sri->getInfo($sriwhere);
  918. if (empty($sriinfo)) {
  919. $sriData = [
  920. 'device_id_code' => $device_id_code,
  921. 'facility_id' => $facility_id,
  922. ];
  923. $sriinsertData = $sriData;
  924. $sriinsertData['createtime'] = date('Y-m-d H:i:s');
  925. $sriinsertData['updatetime'] = date('Y-m-d H:i:s');
  926. $sriinsertData = $m_sri->formatinfo($sriinsertData);
  927. $sriid = $m_sri->insertData($sriinsertData);
  928. if (empty($sriid)) {
  929. throw new \Exception("设备信息添加失败:" . $device_id_code);
  930. }
  931. } else {
  932. $sriid = $sriinfo['id'];
  933. $sriupdateData = $sriData;
  934. $sriupdateData['updatetime'] = date('Y-m-d H:i:s');
  935. $sriupdateData = $m_sri->formatinfo($sriupdateData);
  936. $row = $m_sri->updateinfo(['id' => $sriid], $sriupdateData);
  937. if (empty($row)) {
  938. throw new \Exception("设备信息修改失败:" . $device_id_code);
  939. }
  940. }
  941. //接收信息历史添加
  942. $sririnsertData['facility_id'] = $facility_id;
  943. $sririnsertData['device_id_code'] = $device_id_code;
  944. $sririnsertData['original_str'] = $original_str;
  945. $sririnsertData['content'] = json_encode($sriData);
  946. if (isset($sriData['date'])) {
  947. $sririnsertData['date'] = $sriData['date'];
  948. }
  949. if (isset($sriData['time'])) {
  950. $sririnsertData['time'] = $sriData['time'];
  951. }
  952. $sririnsertData['command'] = $command;
  953. $sririnsertData['createtime'] = date('Y-m-d H:i:s');
  954. if ('tback' == $config['kind']) {
  955. $is_back_msg = true;
  956. $sririnsertData['is_back_msg'] = 0;
  957. } else {
  958. $is_back_msg = false;
  959. $sririnsertData['is_back_msg'] = 1;
  960. }
  961. $sririd = $m_srir->insertData($sririnsertData);
  962. if (empty($sririd)) {
  963. throw new \Exception("设备历史信息添加失败:" . $device_id_code);
  964. }
  965. if ($is_back_msg) {
  966. //处理回复信息
  967. $m_ssl = new ShsendlistModel();
  968. $where = [
  969. 'is_success' => 0,
  970. 'is_send' => 1,
  971. 'command' => $command,
  972. ];
  973. $sslinfo = $m_ssl->getInfo($where);
  974. if ($sslinfo) {
  975. //发送成功状态回写
  976. $sslid = $sslinfo['id'];
  977. $sslupdateData = ['is_success' => 1];
  978. $m_ssl->updateinfo(['id' => $sslid], $sslupdateData);
  979. $srirupdateData = ['send_list_id' => $sslid];
  980. $m_srir->updateinfo(['id' => $sririd], $srirupdateData);
  981. }
  982. }
  983. }
  984. }
  985. /**
  986. * 创建发送信息
  987. *
  988. * @param [type] $data
  989. * @param [type] $command
  990. * @return void
  991. * @author wj
  992. * @date 2023-08-14
  993. */
  994. public function createsendmsg($facility_id, $device_id_code, $data, $command, $param = [])
  995. {
  996. $infoarr = $this->getsendcommandinfo($command);
  997. if (!$infoarr) {
  998. // Log::write("无对应命令数据1:" . $command, 'shouhuan');
  999. // Log::write($data, 'shouhuan');
  1000. return false;
  1001. }
  1002. $command = $data['command'];
  1003. $content_arr = $data['content_arr'];
  1004. $config = $data['config'];
  1005. $m_ssl = new ShsendlistModel();
  1006. $commandxy = "3G";
  1007. //仅创建
  1008. if ('back' == $config['kind']) {
  1009. $content = $config['content'];
  1010. $content = implode(',', $content);
  1011. $send_type = 0;
  1012. $is_success = 1;
  1013. }
  1014. if ('send' == $config['kind']) {
  1015. $content = $config['content'];
  1016. $useconmmand = $content['command'];
  1017. $content_custom = $config['content_custom'];
  1018. $need_back = $config['need_back'];
  1019. if ($content_custom) {
  1020. $functionname = 'get' . $command . "Commandinfo";
  1021. if (method_exists($this, $functionname)) {
  1022. $content = $useconmmand . "," . $this->$functionname($param);
  1023. } else {
  1024. throw new \Exception($command . "自定义方法不存在");
  1025. }
  1026. } else {
  1027. $content = implode(',', $content_arr);
  1028. }
  1029. $send_type = 1;
  1030. if ($need_back) {
  1031. $is_success = 0;
  1032. } else {
  1033. $is_success = 1;
  1034. }
  1035. }
  1036. $weight = $this->getsendweight($command);
  1037. $msgdata = [
  1038. 0 => $commandxy,
  1039. 'device_id_code' => $device_id_code,
  1040. 'len' => str_pad(dechex(mb_strlen($content)), 4, "0", STR_PAD_LEFT),
  1041. 'content' => $content,
  1042. ];
  1043. $msg = '[' . implode('*', $msgdata) . ']';
  1044. $sslInsertData = [
  1045. 'facility_id' => $facility_id,
  1046. 'device_id_code' => $device_id_code,
  1047. 'command' => $command,
  1048. 'send_msg' => $msg,
  1049. 'send_weight' => $weight,
  1050. 'send_time' => date('Y-m-d H:i:s'),
  1051. 'is_success' => $is_success,
  1052. 'send_type' => $send_type,
  1053. ];
  1054. $sslid = $m_ssl->insertData($sslInsertData);
  1055. if (empty($sslid)) {
  1056. throw new \Exception("发送数据添加失败");
  1057. }
  1058. $data = [
  1059. 'msg' => $msg,
  1060. 'weight' => $weight,
  1061. 'createtime' => date('Y-m-d H:i:s'),
  1062. 'facility_id' => $facility_id,
  1063. 'device_id_code' => $device_id_code,
  1064. 'send_list_id' => $sslid,
  1065. ];
  1066. $m_ssq = new ShsendqueueModel();
  1067. $id = $m_ssq->insertData($data);
  1068. if (empty($id)) {
  1069. throw new \Exception("发送队列数据添加失败");
  1070. }
  1071. return true;
  1072. }
  1073. /**
  1074. * 创建sos电话设置命令
  1075. * 最多三个电话
  1076. *
  1077. * @return void
  1078. * @author wj
  1079. * @date 2023-08-21
  1080. */
  1081. public function getSOSCommandinfo($param)
  1082. {
  1083. if (count($param) <= 0) {
  1084. throw new \Exception("未设置电话");
  1085. }
  1086. if (count($param) > 3) {
  1087. throw new \Exception("设置电话数量过多");
  1088. }
  1089. foreach ($param as $key => $value) {
  1090. //判断是否为手机号
  1091. //暂不处理
  1092. }
  1093. $info = implode(",", $param);
  1094. return $info;
  1095. }
  1096. /**
  1097. * 设置跌倒灵敏度命令
  1098. * [3G*358800006072996*0009*LSSET,3+6]
  1099. *
  1100. * @return void
  1101. * @author wj
  1102. * @date 2023-08-21
  1103. */
  1104. public function getLSSETCommandinfo($param)
  1105. {
  1106. if (2 != count($param)) {
  1107. throw new \Exception("LSSET参数错误");
  1108. }
  1109. foreach ($param as $key => $value) {
  1110. if (!is_numeric($value)) {
  1111. throw new \Exception("LSSET参数错误:" . $value);
  1112. }
  1113. }
  1114. $info = $param[0] . "+" . $param[1];
  1115. return $info;
  1116. }
  1117. /**
  1118. * 设置电话本
  1119. * 最多10条
  1120. *[{telno=>'',name=>''}]
  1121. * @param [type] $param
  1122. * @return void
  1123. * @author wj
  1124. * @date 2023-08-21
  1125. */
  1126. public function getPHLCommaninfo($param)
  1127. {
  1128. if (50 < count($param)) {
  1129. throw new \Exception("PHL参数错误");
  1130. }
  1131. if (0 != count($param) % 2) {
  1132. throw new \Exception("PHL参数长度错误");
  1133. }
  1134. $usedata = [];
  1135. foreach ($param as $key => $value) {
  1136. $telno = $value['telno'];
  1137. $name = $value['name'];
  1138. //电话号码
  1139. if (20 < mb_strlen($telno)) {
  1140. throw new \Exception("PHL电话号码错误:" . $telno);
  1141. }
  1142. $name = $this->srtingToUnicode($name);
  1143. $usedata[] = $telno;
  1144. $usedata[] = $name;
  1145. }
  1146. $info = implode(",", $usedata);
  1147. return $info;
  1148. }
  1149. /**
  1150. * 设置电话本
  1151. * 最多10条
  1152. *{[time=>'',isopen=>'','type'=>'','weeks'=>[]]}
  1153. * weeks 数组 每个1到7 周日到周六
  1154. * 最多设置三个
  1155. * @param [type] $param
  1156. * @return void
  1157. * @author wj
  1158. * @date 2023-08-21
  1159. */
  1160. /*
  1161. 08:10-1-1:闹钟时间 8:10,打开,响铃一次
  1162. 08:10-1-2:闹钟时间 8:10,打开,每天响铃
  1163. 08:10-1-3-0111110:闹钟时间 8:10,打开,自定义周一至周五打开
  1164. 最左边是周日,最右边是周六,即 0111110 的顺序是:周日,周一,周二,周三,周四,周五,周
  1165. 六(1 为打开,0 为关闭),其中周一至周五打开闹钟
  1166. */
  1167. public function getREMINDCommandinfo($param)
  1168. {
  1169. if (3 > count($param)) {
  1170. throw new \Exception("PHL参数错误");
  1171. }
  1172. $usedata = [];
  1173. foreach ($param as $key => $value) {
  1174. $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
  1175. $time = $this->formattime($value['time'], 'H:i');
  1176. $isopen = $value['isopen'];
  1177. $type = $value['type'];
  1178. $weeks = $value['weeks'];
  1179. if (3 == $type) {
  1180. foreach ($weeks as $wkey => $wvalue) {
  1181. if ($wvalue >= 1 && $wvalue <= 7) {
  1182. $useweeks[$wvalue - 1] = '1';
  1183. }
  1184. }
  1185. $useweeks = implode("", $useweeks);
  1186. $type = $useweeks;
  1187. }
  1188. $usedata[] = $time . "-" . $isopen . "-" . $type;
  1189. }
  1190. $usedata = implode(",", $usedata);
  1191. return $usedata;
  1192. }
  1193. /**
  1194. * 静默时间段测试
  1195. *{[starttime=>'',endtime=>'',isopen=>'',weeks=>[]]}
  1196. * weeks 数组 每个1到7 周日到周六
  1197. * 最多设置三个
  1198. *
  1199. * @return void
  1200. * @author wj
  1201. * @date 2023-08-21
  1202. */
  1203. /*
  1204. [DW*334588000000156*0038*SILENCETIME2,7:30-21:10-1-0111110,7:30-21:10-1-0111110,7:
  1205. 30-21:10-0-0111110]
  1206. 设置上课禁用时间段范围,拦截终端的任何来电。格式为“起始时间-结束时间-自定义星期几”, 比
  1207. 如上面的 7:30-21:00-0111110,则表示周一到周五 7:30 到 21:00 之间上课禁用生效,起始时间
  1208. 默认大于结束时间。
  1209. 总开关:0 为关,1 为开
  1210. 关于自定义星期几的规则:最左边是周日,最右边是周六,即 0111110 的顺序是:周日,周一,周
  1211. 二,周三,周四,周五,周六(1 为打开,0 为关闭),所以上面的意思是周一至周五打开上课禁
  1212. 用。
  1213. */
  1214. public function getSILENCETIME2Commandinfo($param)
  1215. {
  1216. if (3 <= count($param)) {
  1217. throw new \Exception("SILENCETIME2参数错误");
  1218. }
  1219. $usedata = [];
  1220. foreach ($param as $key => $value) {
  1221. $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
  1222. //未比较时间大小
  1223. $starttime = $this->formattime($value['starttime'], 'H:i');
  1224. $endtime = $this->formattime($value['endtime'], 'H:i');
  1225. $isopen = $value['isopen'];
  1226. $weeks = $value['weeks'];
  1227. foreach ($weeks as $wkey => $wvalue) {
  1228. if ($wvalue >= 1 && $wvalue <= 7) {
  1229. $useweeks[$wvalue - 1] = '1';
  1230. }
  1231. }
  1232. $useweeks = implode("", $useweeks);
  1233. $usedata[] = $starttime . "-" . $endtime . "-" . $isopen . "-" . $useweeks;
  1234. }
  1235. $usedata = implode(",", $usedata);
  1236. return $usedata;
  1237. }
  1238. /**
  1239. * 睡眠时间段设置
  1240. *{starttime=>'',endtime=>''}
  1241. *
  1242. * @return void
  1243. * @author wj
  1244. * @date 2023-08-21
  1245. */
  1246. public function getSLEEPTIMECommandinfo($param)
  1247. {
  1248. if (2 > count($param)) {
  1249. throw new \Exception("SLEEPTIME参数错误");
  1250. }
  1251. $starttime = $this->formattime($param['starttime'], 'H:i');
  1252. $endtime = $this->formattime($param['endtime'], 'H:i');
  1253. $usedata = $starttime . "-" . $endtime;
  1254. return $usedata;
  1255. }
  1256. //发送完处理
  1257. /**
  1258. * 发送成功 删除发送数据
  1259. *
  1260. * @param [type] $item
  1261. * @return void
  1262. * @author wj
  1263. * @date 2023-08-21
  1264. */
  1265. public function sendmsgsuccess($item)
  1266. {
  1267. $m_ssq = new ShsendqueueModel();
  1268. $m_ssl = new ShsendlistModel();
  1269. $ssqid = $item['id'];
  1270. if ($item['list_id']) {
  1271. $list_id = $item['list_id'];
  1272. $sslwhere = ['id' => $list_id, 'is_send' => 0];
  1273. $sslinfo = $m_ssl->getInfo($sslwhere);
  1274. if ($sslinfo) {
  1275. $row = $m_ssl->updateinfo(['id' => $sslinfo['id']], ['is_send' => 1, 'send_time' => date('Y-m-d H:i:s')]);
  1276. }
  1277. }
  1278. $ssqwhere = ['id' => $ssqid];
  1279. $ssqinfo = $m_ssq->getInfo($ssqwhere);
  1280. if ($ssqinfo) {
  1281. $m_ssq->deleteinfobyid($ssqid);
  1282. }
  1283. }
  1284. /**
  1285. * 解析成功 删除接收数据
  1286. *
  1287. * @param [type] $item
  1288. * @return void
  1289. * @author wj
  1290. * @date 2023-08-21
  1291. */
  1292. public function receivemsgsuccess($item)
  1293. {
  1294. $m_srq = new ShreceivequeueModel();
  1295. $srqid = $item['id'];
  1296. $srqwhere = ['id' => $srqid, 'status' => 1];
  1297. $srqinfo = $m_srq->getInfo($srqwhere);
  1298. if ($srqinfo) {
  1299. $m_srq->deleteinfobyid($srqid);
  1300. }
  1301. }
  1302. /**
  1303. * 初始化手环接收信息解析
  1304. *
  1305. * @return void
  1306. * @author wj
  1307. * @date 2023-08-15
  1308. */
  1309. public function initanalysisShoneReceiveMsg()
  1310. {
  1311. $m_srq = new ShreceivequeueModel();
  1312. $where = ['status' => 1];
  1313. $m_srq->updateinfo($where, ['status' => 0]);
  1314. }
  1315. /**
  1316. * 测试使用
  1317. *
  1318. * @param [type] $data
  1319. * @return void
  1320. * @author wj
  1321. * @date 2023-08-21
  1322. */
  1323. public function showfortest($data)
  1324. {
  1325. $strdata = $this->getline($data);
  1326. if (!is_array($strdata)) {
  1327. Log::write($data, 'shouhuan');
  1328. return false;
  1329. }
  1330. $command = strtoupper($strdata['command']);
  1331. $showcommands = [
  1332. 'SOS', 'CR', 'UPLOAD', 'SLEEPTIME', 'ZONE', 'FALLDOWN',
  1333. 'APPLOCK', 'FACTORY', 'VERNO', 'LOWBAT', 'UD', 'POWEROFF', 'MESSAGE',
  1334. 'WALKTIME', 'PEDO', 'PHB', 'PHL', 'REMIND', 'SILENCETIME2', 'BOOTOFF',
  1335. 'REMOVE', 'INFO', 'AL', 'LSSET',
  1336. ];
  1337. if (in_array($command, $showcommands)) {
  1338. var_dump(date('Y-m-d H:i:s'));
  1339. var_dump($data);
  1340. }
  1341. }
  1342. /**
  1343. * 设置设备上线
  1344. *
  1345. * @return void
  1346. * @author wj
  1347. * @date 2023-08-21
  1348. */
  1349. public function setonlineinfo($device_id_code)
  1350. {
  1351. $m_si = new ShinfoModel();
  1352. $where = ['device_id_code' => $device_id_code, 'online_statis' => 0];
  1353. $finfo = $m_si->getInfo($where, ['id', 'online_statis']);
  1354. if ($finfo) {
  1355. $facility_id = $finfo['id'];
  1356. $m_si->setonlineinfobyid($facility_id);
  1357. }
  1358. }
  1359. /**
  1360. * 设置设备下线
  1361. *
  1362. * @return void
  1363. * @author wj
  1364. * @date 2023-08-21
  1365. */
  1366. public function setofflineinfo()
  1367. {
  1368. $m_si = new ShinfoModel();
  1369. $list = $m_si->getcheckupdatetimelist();
  1370. $list = (array) $list;
  1371. if (!empty($list)) {
  1372. $facility_ids = array_column($list, 'id');
  1373. $m_si->setofflineinfobyids($facility_ids);
  1374. }
  1375. }
  1376. //工具方法
  1377. /**
  1378. * unicode 编码
  1379. *
  1380. * @param [type] $str
  1381. * @return void
  1382. * @author wj
  1383. * @date 2023-08-21
  1384. */
  1385. public function srtingToUnicode($str)
  1386. {
  1387. $unicode = '';
  1388. $arr = mb_str_split($str); //适配中文
  1389. foreach ($arr as $key => $value) {
  1390. var_dump($value);
  1391. $char = bin2hex(iconv('UTF-8', 'UCS-2BE', $value));
  1392. $char = str_pad($char, 4, '0', STR_PAD_LEFT);
  1393. $arr[$key] = $char;
  1394. }
  1395. $unicode = implode("", $arr);
  1396. return $unicode;
  1397. }
  1398. /**
  1399. * unicode 解码
  1400. *
  1401. * @param [type] $str
  1402. * @return void
  1403. * @author wj
  1404. * @date 2023-08-21
  1405. */
  1406. public function unicodeToChn($str)
  1407. {
  1408. $arr = str_split($str);
  1409. $items = [];
  1410. $item = "";
  1411. foreach ($arr as $key => $value) {
  1412. $index = $key + 1;
  1413. if (0 != $index % 4) {
  1414. $item .= $value;
  1415. } else {
  1416. $item = "";
  1417. $items[] = $item;
  1418. }
  1419. }
  1420. foreach ($items as $key => $value) {
  1421. $char = hex2bin($value);
  1422. $char = iconv('UCS-2BE', 'UTF-8', $char);
  1423. $items[$key] = $char;
  1424. }
  1425. $info = implode("", $items);
  1426. return $info;
  1427. }
  1428. /**
  1429. * 拆包
  1430. *
  1431. * @return void
  1432. * @author wj
  1433. * @date 2023-08-15
  1434. */
  1435. public function unpack($data)
  1436. {
  1437. $arr = explode("][", $data);
  1438. foreach ($arr as $key => $value) {
  1439. if ($value[0] !== "[") {
  1440. $arr[$key] = '[' . $value;
  1441. }
  1442. if ($value[mb_strlen($value) - 1] !== "]") {
  1443. $arr[$key] .= "]";
  1444. }
  1445. }
  1446. return $arr;
  1447. }
  1448. public function formattime($time, $format)
  1449. {
  1450. $time = strtotime($time);
  1451. $time = date($format, $time);
  1452. return $time;
  1453. }
  1454. }