ShouhuanCommand.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. <?php
  2. namespace app\common\server;
  3. use app\common\model\FacilityModel;
  4. use app\common\model\ShsendlistModel;
  5. use app\common\model\ShsendqueueModel;
  6. //use app\common\server\SouhuanAnalysis;
  7. use think\facade\Log;
  8. /**
  9. * 手环命令创建
  10. *
  11. * @author wj
  12. * @date 2023-09-01
  13. */
  14. class ShouhuanCommand
  15. {
  16. /**
  17. * 获取设备信息
  18. *
  19. * @param [type] $facility_id
  20. * @param [type] $device_id_code
  21. * @return void
  22. * @author wj
  23. * @date 2023-09-01
  24. */
  25. private function getfacilityinfo($facility_id, $device_id_code)
  26. {
  27. $m_f = new FacilityModel();
  28. $fwhere = [
  29. 'id' => $facility_id,
  30. 'code' => $device_id_code,
  31. 'kind' => 1,
  32. 'status' => 1,
  33. ];
  34. $finfo = $m_f->getInfo($fwhere);
  35. if (!$finfo) {
  36. throw new \Exception("无对应信息:" . $facility_id . "-" . $device_id_code);
  37. }
  38. return $finfo;
  39. }
  40. /**
  41. * 创建发送信息
  42. *
  43. * @param [type] $data
  44. * @param [type] $command
  45. * @return void
  46. * @author wj
  47. * @date 2023-08-14
  48. * $data =['command'=>'','content_arr'=>[],]
  49. */
  50. public function createsendmsg($facility_id, $device_id_code, $data, $param = [], $sys_user_id = 0)
  51. {
  52. $command = $data['command'];
  53. $infoarr = $this->getsendcommandinfo($command);
  54. if (!$infoarr) {
  55. // Log::write("无对应命令数据1:" . $command, 'shouhuan');
  56. // Log::write($data, 'shouhuan');
  57. return false;
  58. }
  59. $content_arr = $data['content_arr'];
  60. $config = $infoarr;
  61. $m_ssl = new ShsendlistModel();
  62. $commandxy = "3G";
  63. //仅创建
  64. if ($command == 'AL') {
  65. $msg_type = 1;
  66. } else {
  67. $msg_type = 0;
  68. }
  69. // if ('back' == $config['kind']) {
  70. // $content = $config['content'];
  71. // $content = implode(',', $content);
  72. // $send_type = 0;
  73. // $is_success = 1;
  74. // }
  75. if ('send' == $config['kind']) {
  76. $content = $config['content'];
  77. $useconmmand = $content['command'];
  78. $content_custom = isset($config['content_custom']) ? $config['content_custom'] : false;
  79. $need_back = $config['need_back'];
  80. if ($content_custom) {
  81. $functionname = 'get' . $command . "Commandinfo";
  82. if (method_exists($this, $functionname)) {
  83. $content = $useconmmand . "," . $this->$functionname($param);
  84. } else {
  85. throw new \Exception($command . "自定义方法不存在");
  86. }
  87. } else {
  88. $content = implode(',', $content_arr);
  89. }
  90. $send_type = 1;
  91. if ($need_back) {
  92. $is_success = 0;
  93. } else {
  94. $is_success = 1;
  95. }
  96. $weight = $this->getsendweight($command);
  97. $msgdata = [
  98. 0 => $commandxy,
  99. 'device_id_code' => $device_id_code,
  100. 'len' => str_pad(strtoupper(dechex(mb_strlen($content))), 4, "0", STR_PAD_LEFT),
  101. 'content' => $content,
  102. ];
  103. $msg = '[' . implode('*', $msgdata) . ']';
  104. $sslInsertData = [
  105. 'facility_id' => $facility_id,
  106. 'device_id_code' => $device_id_code,
  107. 'command' => $command,
  108. 'send_msg' => $msg,
  109. 'send_weight' => $weight,
  110. 'send_time' => date('Y-m-d H:i:s'),
  111. 'is_success' => $is_success,
  112. 'send_type' => $send_type,
  113. 'sys_user_id' => $sys_user_id,
  114. ];
  115. $sslid = $m_ssl->insertData($sslInsertData);
  116. if (empty($sslid)) {
  117. throw new \Exception("发送数据添加失败");
  118. }
  119. $data = [
  120. 'msg' => $msg,
  121. 'weight' => $weight,
  122. 'createtime' => date('Y-m-d H:i:s'),
  123. 'facility_id' => $facility_id,
  124. 'device_id_code' => $device_id_code,
  125. 'send_list_id' => $sslid,
  126. 'msg_type' => $msg_type,
  127. ];
  128. $m_ssq = new ShsendqueueModel();
  129. $id = $m_ssq->insertData($data);
  130. if (empty($id)) {
  131. throw new \Exception("发送队列数据添加失败");
  132. }
  133. return true;
  134. }
  135. return false;
  136. }
  137. public function createsendmsg2($facility_id, $device_id_code, $data)
  138. {
  139. $command = $data['command'];
  140. $infoarr = $this->getsendcommandinfo($command);
  141. if (!$infoarr) {
  142. // Log::write("无对应命令数据1:" . $command, 'shouhuan');
  143. // Log::write($data, 'shouhuan');
  144. return false;
  145. }
  146. $content_arr = $data['content_arr'];
  147. $config = $infoarr;
  148. $m_ssl = new ShsendlistModel();
  149. $commandxy = "3G";
  150. if ('back' == $config['kind']) {
  151. $content = $infoarr['command'];
  152. $weight = $this->getsendweight($command);
  153. $msgdata = [
  154. 0 => $commandxy,
  155. 'device_id_code' => $device_id_code,
  156. 'len' => str_pad(strtoupper(dechex(mb_strlen($content))), 4, "0", STR_PAD_LEFT),
  157. 'content' => $content,
  158. ];
  159. $msg = '[' . implode('*', $msgdata) . ']';
  160. $sslInsertData = [
  161. 'facility_id' => $facility_id,
  162. 'device_id_code' => $device_id_code,
  163. 'command' => $command,
  164. 'send_msg' => $msg,
  165. 'send_weight' => $weight,
  166. 'send_time' => date('Y-m-d H:i:s'),
  167. 'is_success' => 1,
  168. 'send_type' => 0,
  169. 'sys_user_id' => 0,
  170. ];
  171. $sslid = $m_ssl->insertData($sslInsertData);
  172. if (empty($sslid)) {
  173. throw new \Exception("发送数据添加失败");
  174. }
  175. return $msg;
  176. }
  177. return false;
  178. }
  179. /**
  180. * 获取回复权重
  181. *
  182. * @param [type] $command
  183. * @return void
  184. * @author wj
  185. * @date 2023-08-11
  186. */
  187. public function getsendweight($command)
  188. {
  189. $weight = -1;
  190. switch ($command) {
  191. case 'POWEROFF':
  192. //关机
  193. $weight = 99;
  194. break;
  195. case 'RESET':
  196. //重启
  197. $weight = 98; //硬件未测试
  198. break;
  199. //平台回复命令
  200. case 'AL':
  201. case 'KA':
  202. case 'LK':
  203. case 'PING':
  204. case 'BPHRT':
  205. case 'TEMP':
  206. case 'HEART':
  207. case 'BLOOD':
  208. case 'OXYGEN':
  209. $weight = 1;
  210. break;
  211. //平台发送命令
  212. case 'ZONE':
  213. case 'UPLOAD':
  214. case 'CR':
  215. case 'SLEEPTIME':
  216. case 'FALLDOWN':
  217. case 'FACTORY':
  218. case 'SOS':
  219. case 'VERNO':
  220. case 'LOWBAT':
  221. case 'POWEROFF':
  222. case 'LSSET':
  223. case 'PEDO':
  224. case 'PHL':
  225. case 'REMIND':
  226. case 'SILENCETIME2':
  227. case 'BOOTOFF':
  228. case 'REMOVE':
  229. case 'CALL':
  230. case 'KEYBRD':
  231. $weight = 0;
  232. break;
  233. default:
  234. $weight = -1;
  235. break;
  236. }
  237. if ($weight < 0) {
  238. //不需设置 发送信息
  239. return false;
  240. }
  241. return $weight;
  242. }
  243. /**
  244. * 获取平台发送命令信息
  245. *
  246. * @param [type] $command
  247. * @return void
  248. * @author wj
  249. * @date 2023-08-11
  250. */
  251. public function getsendcommandinfo($command)
  252. {
  253. $command = strtoupper($command);
  254. $data = [
  255. //平台发送
  256. //时区
  257. 'ZONE' => [
  258. 'content' => [
  259. 'command' => 'ZONE',
  260. 'zone' => '',
  261. ],
  262. 'kind' => 'send',
  263. 'need_back' => 1,
  264. ],
  265. //位置发送间隔
  266. 'UPLOAD' => [
  267. 'content' => [
  268. 'command' => 'UPLOAD',
  269. 'interval' => '',
  270. ],
  271. 'kind' => 'send',
  272. 'need_back' => 1,
  273. ],
  274. //心率上传间隔
  275. 'HRTSTART' => [
  276. 'content' => [
  277. 'command' => 'hrtstart',
  278. 'interval' => '',
  279. ],
  280. 'kind' => 'send',
  281. 'need_back' => 1,
  282. ],
  283. //体温上传间隔
  284. 'WDSTART' => [
  285. 'content' => [
  286. 'command' => 'wdstart',
  287. 'interval' => '',
  288. ],
  289. 'kind' => 'send',
  290. 'need_back' => 1,
  291. ],
  292. //血压上传频率
  293. 'BLDSTART' => [
  294. 'content' => [
  295. 'command' => 'bldstart',
  296. 'interval' => '',
  297. ],
  298. 'kind' => 'send',
  299. 'need_back' => 1,
  300. ],
  301. //血氧上传频率
  302. 'OXSTART' => [
  303. 'content' => [
  304. 'command' => 'oxstart',
  305. 'interval' => '',
  306. ],
  307. 'kind' => 'send',
  308. 'need_back' => 1,
  309. ],
  310. //立即定位
  311. 'CR' => [
  312. 'content' => [
  313. 'command' => 'CR',
  314. ],
  315. 'kind' => 'send',
  316. 'need_back' => 1,
  317. ],
  318. 'SLEEPTIME' => [
  319. 'content' => [
  320. 'command' => 'CR',
  321. ],
  322. 'kind' => 'send',
  323. 'content_custom' => true,
  324. 'need_back' => 1,
  325. ],
  326. 'FALLDOWN' => [
  327. 'content' => [
  328. 'command' => 'FALLDOWN',
  329. 'is_open' => '',
  330. ],
  331. 'kind' => 'send',
  332. 'need_back' => 1,
  333. ],
  334. 'FACTORY' => [
  335. 'content' => [
  336. 'command' => 'FACTORY',
  337. ],
  338. 'kind' => 'send',
  339. 'need_back' => 1,
  340. ],
  341. 'SOS' => [
  342. 'content' => [
  343. 'command' => 'SOS',
  344. ],
  345. 'kind' => 'send',
  346. 'content_custom' => true,
  347. 'need_back' => 1,
  348. ],
  349. 'VERNO' => [
  350. 'content' => [
  351. 'command' => 'VERNO',
  352. ],
  353. 'kind' => 'send',
  354. 'need_back' => 1,
  355. ],
  356. 'LOWBAT' => [
  357. 'content' => [
  358. 'command' => 'LOWBAT',
  359. 'is_open' => '',
  360. ],
  361. 'kind' => 'send',
  362. 'need_back' => 1,
  363. ],
  364. 'POWEROFF' => [
  365. 'content' => [
  366. 'command' => 'POWEROFF',
  367. ],
  368. 'kind' => 'send',
  369. 'need_back' => 1,
  370. ],
  371. 'LSSET' => [
  372. 'content' => [
  373. 'command' => 'LSSET',
  374. ],
  375. 'content_custom' => true,
  376. 'kind' => 'send',
  377. 'need_back' => 1,
  378. ],
  379. 'PEDO' => [
  380. 'content' => [
  381. 'command' => 'PEDO',
  382. 'is_open' => '',
  383. ],
  384. 'kind' => 'send',
  385. 'need_back' => 1,
  386. ],
  387. 'PHL' => [
  388. 'content' => [
  389. 'command' => 'PHL',
  390. ],
  391. 'kind' => 'send',
  392. 'content_custom' => true,
  393. 'need_back' => 1,
  394. ],
  395. 'REMIND' => [
  396. 'content' => [
  397. 'command' => 'REMIND',
  398. ],
  399. 'kind' => 'send',
  400. 'content_custom' => true,
  401. 'need_back' => 1,
  402. ],
  403. 'SILENCETIME2' => [
  404. 'content' => [
  405. 'command' => 'SILENCETIME2',
  406. ],
  407. 'kind' => 'send',
  408. 'content_custom' => true,
  409. 'need_back' => 1,
  410. ],
  411. 'BOOTOFF' => [
  412. 'content' => [
  413. 'command' => 'BOOTOFF',
  414. 'is_open' => '',
  415. 'bootup_time' => '',
  416. 'shutdown_time' => '',
  417. ],
  418. 'kind' => 'send',
  419. 'need_back' => 1,
  420. ],
  421. 'REMOVE' => [
  422. 'content' => [
  423. 'command' => 'REMOVE',
  424. 'is_open' => '',
  425. ],
  426. 'kind' => 'send',
  427. 'need_back' => 1,
  428. ],
  429. //拨打电话
  430. 'CALL' => [
  431. 'content' => [
  432. 'command' => 'CALL',
  433. 'telno' => '',
  434. ],
  435. 'kind' => 'send',
  436. 'need_back' => 1,
  437. ],
  438. 'KEYBRD' => [
  439. 'content' => [
  440. 'command' => 'KEYBRD',
  441. 'is_open' => '',
  442. ],
  443. 'kind' => 'send',
  444. 'need_back' => 1,
  445. ],
  446. //平台回复
  447. 'LK' => [
  448. 'content' => [
  449. 'command' => 'LK',
  450. ],
  451. 'kind' => 'back',
  452. ],
  453. 'PING' => [
  454. 'content' => [
  455. 'command' => 'PING',
  456. 'isbind' => 1,
  457. ],
  458. 'kind' => 'back',
  459. ],
  460. 'KA' => [
  461. 'content' => [
  462. 'command' => 'KA',
  463. ],
  464. 'kind' => 'back',
  465. ],
  466. 'TEMP' => [
  467. 'content' => [
  468. 'command' => 'temp',
  469. ],
  470. 'kind' => 'back',
  471. ],
  472. 'BPHRT' => [
  473. 'content' => [
  474. 'command' => 'bphrt',
  475. ],
  476. 'kind' => 'back',
  477. ],
  478. 'HEART' => [
  479. 'content' => [
  480. 'command' => 'heart',
  481. ],
  482. 'kind' => 'back',
  483. ],
  484. 'BLOOD' => [
  485. 'content' => [
  486. 'command' => 'blood',
  487. ],
  488. 'kind' => 'back',
  489. ],
  490. 'OXYGEN' => [
  491. 'content' => [
  492. 'command' => 'oxygen',
  493. ],
  494. 'kind' => 'back',
  495. ],
  496. 'AL' => [
  497. 'content' => [
  498. 'command' => 'AL',
  499. ],
  500. 'kind' => 'back',
  501. ],
  502. 'TKQ' => [
  503. 'content' => [
  504. 'command' => 'TKQ',
  505. ],
  506. 'kind' => 'back',
  507. ],
  508. 'WG' => [
  509. 'content' => [
  510. 'command' => 'WG',
  511. ],
  512. 'kind' => 'back',
  513. ],
  514. ];
  515. if (!isset($data[$command])) {
  516. return false;
  517. }
  518. return $data[$command];
  519. }
  520. /**
  521. * 创建sos电话设置命令
  522. * 最多三个电话
  523. *
  524. * @return void
  525. * @author wj
  526. * @date 2023-08-21
  527. */
  528. public function getSOSCommandinfo($param)
  529. {
  530. if (count($param) <= 0) {
  531. throw new \Exception("SOS未设置电话");
  532. }
  533. if (count($param) > 3) {
  534. throw new \Exception("SOS设置电话数量过多");
  535. }
  536. foreach ($param as $key => $value) {
  537. //判断是否为手机号
  538. //暂不处理
  539. }
  540. $info = implode(",", $param);
  541. return $info;
  542. }
  543. /**
  544. * 设置跌倒灵敏度命令
  545. * [3G*358800006072996*0009*LSSET,3+6]
  546. *
  547. * @return void
  548. * @author wj
  549. * @date 2023-08-21
  550. */
  551. public function getLSSETCommandinfo($param)
  552. {
  553. if (2 != count($param)) {
  554. throw new \Exception("LSSET参数错误");
  555. }
  556. foreach ($param as $key => $value) {
  557. if (!is_numeric($value)) {
  558. throw new \Exception("LSSET参数错误:" . $value);
  559. }
  560. }
  561. $info = $param[0] . "+" . $param[1];
  562. return $info;
  563. }
  564. /**
  565. * 设置电话本
  566. * 最多10条
  567. *[{telno=>'',name=>''}]
  568. * @param [type] $param
  569. * @return void
  570. * @author wj
  571. * @date 2023-08-21
  572. */
  573. public function getPHLCommandinfo($param)
  574. {
  575. if (empty($param)) {
  576. throw new \Exception("PHL无设置参数");
  577. }
  578. if (count($param) > 50) {
  579. throw new \Exception("PHL参数错误");
  580. }
  581. $usedata = [];
  582. foreach ($param as $key => $value) {
  583. $telno = $value['telno'];
  584. $name = $value['name'];
  585. //电话号码
  586. if (20 < mb_strlen($telno)) {
  587. throw new \Exception("PHL电话号码错误:" . $telno);
  588. }
  589. $name = $this->srtingToUnicode($name);
  590. $usedata[] = $telno;
  591. $usedata[] = $name;
  592. }
  593. $info = implode(",", $usedata);
  594. return $info;
  595. }
  596. /**
  597. * 设置电话本
  598. * 最多10条
  599. *{[time=>'',isopen=>'','type'=>'','weeks'=>[]]}
  600. * weeks 数组 每个1到7 周日到周六
  601. * 最多设置三个
  602. * @param [type] $param
  603. * @return void
  604. * @author wj
  605. * @date 2023-08-21
  606. */
  607. /*
  608. 08:10-1-1:闹钟时间 8:10,打开,响铃一次
  609. 08:10-1-2:闹钟时间 8:10,打开,每天响铃
  610. 08:10-1-3-0111110:闹钟时间 8:10,打开,自定义周一至周五打开
  611. 最左边是周日,最右边是周六,即 0111110 的顺序是:周日,周一,周二,周三,周四,周五,周
  612. 六(1 为打开,0 为关闭),其中周一至周五打开闹钟
  613. */
  614. public function getREMINDCommandinfo($param)
  615. {
  616. if (empty($param)) {
  617. throw new \Exception("REMIND参数错误");
  618. }
  619. $usedata = [];
  620. foreach ($param as $key => $value) {
  621. if (3 > count($value)) {
  622. throw new \Exception("REMINDC参数错误");
  623. }
  624. $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
  625. $time = $this->formattime($value['time'], 'H:i');
  626. $isopen = $value['isopen'];
  627. $type = $value['type'];
  628. $weeks = $value['weeks'];
  629. if (3 == $type) {
  630. foreach ($weeks as $wkey => $wvalue) {
  631. if ($wvalue >= 1 && $wvalue <= 7) {
  632. $useweeks[$wvalue - 1] = '1';
  633. }
  634. }
  635. $useweeks = implode("", $useweeks);
  636. $type = '3-' . $useweeks;
  637. }
  638. $usedata[] = $time . "-" . $isopen . "-" . $type;
  639. }
  640. $usedata = implode(",", $usedata);
  641. return $usedata;
  642. }
  643. /**
  644. * 静默时间段测试
  645. *{[starttime=>'',endtime=>'',isopen=>'',weeks=>[]]}
  646. * weeks 数组 每个1到7 周日到周六
  647. * 最多设置三个
  648. *
  649. * @return void
  650. * @author wj
  651. * @date 2023-08-21
  652. */
  653. /*
  654. [DW*334588000000156*0038*SILENCETIME2,7:30-21:10-1-0111110,7:30-21:10-1-0111110,7:
  655. 30-21:10-0-0111110]
  656. 设置上课禁用时间段范围,拦截终端的任何来电。格式为“起始时间-结束时间-自定义星期几”, 比
  657. 如上面的 7:30-21:00-0111110,则表示周一到周五 7:30 到 21:00 之间上课禁用生效,起始时间
  658. 默认大于结束时间。
  659. 总开关:0 为关,1 为开
  660. 关于自定义星期几的规则:最左边是周日,最右边是周六,即 0111110 的顺序是:周日,周一,周
  661. 二,周三,周四,周五,周六(1 为打开,0 为关闭),所以上面的意思是周一至周五打开上课禁
  662. 用。
  663. */
  664. public function getSILENCETIME2Commandinfo($param)
  665. {
  666. if (empty($param)) {
  667. throw new \Exception("SILENCETIME2参数错误");
  668. }
  669. $usedata = [];
  670. foreach ($param as $key => $value) {
  671. if (4 > count($value)) {
  672. throw new \Exception("SILENCETIME2参数错误");
  673. }
  674. $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
  675. //未比较时间大小
  676. $starttime = $this->formattime($value['starttime'], 'H:i');
  677. $endtime = $this->formattime($value['endtime'], 'H:i');
  678. $isopen = $value['isopen'];
  679. $weeks = $value['weeks'];
  680. foreach ($weeks as $wkey => $wvalue) {
  681. if ($wvalue >= 1 && $wvalue <= 7) {
  682. $useweeks[$wvalue - 1] = '1';
  683. }
  684. }
  685. $useweeks = implode("", $useweeks);
  686. $usedata[] = $starttime . "-" . $endtime . "-" . $isopen . "-" . $useweeks;
  687. }
  688. $usedata = implode(",", $usedata);
  689. return $usedata;
  690. }
  691. /**
  692. * 睡眠时间段设置
  693. *{starttime=>'',endtime=>''}
  694. *
  695. * @return void
  696. * @author wj
  697. * @date 2023-08-21
  698. */
  699. public function getSLEEPTIMECommandinfo($param)
  700. {
  701. if (2 > count($param)) {
  702. throw new \Exception("SLEEPTIME参数错误");
  703. }
  704. $starttime = $this->formattime($param['starttime'], 'H:i');
  705. $endtime = $this->formattime($param['endtime'], 'H:i');
  706. $usedata = $starttime . "-" . $endtime;
  707. return $usedata;
  708. }
  709. public function formattime($time, $format)
  710. {
  711. $time = strtotime($time);
  712. $time = date($format, $time);
  713. return $time;
  714. }
  715. /**
  716. * unicode 编码
  717. *
  718. * @param [type] $str
  719. * @return void
  720. * @author wj
  721. * @date 2023-08-21
  722. */
  723. public function srtingToUnicode($str)
  724. {
  725. $unicode = '';
  726. $arr = mb_str_split($str); //适配中文
  727. foreach ($arr as $key => $value) {
  728. $char = bin2hex(iconv('UTF-8', 'UCS-2BE', $value));
  729. $char = str_pad($char, 4, '0', STR_PAD_LEFT);
  730. $arr[$key] = $char;
  731. }
  732. $unicode = implode("", $arr);
  733. return $unicode;
  734. }
  735. //设置 低电报警开关
  736. public function createlowbatcommand($facility_id, $device_id_code, $is_open, $sys_user_id)
  737. {
  738. $command = ['command' => 'LOWBAT', 'content_arr' => ['command' => 'LOWBAT', 'is_open' => $is_open]];
  739. $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
  740. }
  741. //设置 跌倒报警开关
  742. public function createfalldowncommand($facility_id, $device_id_code, $param, $sys_user_id)
  743. {
  744. $command = ['command' => 'FALLDOWN', 'content_arr' => ['command' => 'FALLDOWN', 'is_open' => $param['is_open']]];
  745. $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
  746. $lssetparam = [];
  747. switch ($param['lsset_type']) {
  748. case '1':
  749. $lssetparam = [3, 6];
  750. break;
  751. case '2':
  752. $lssetparam = [6, 9];
  753. break;
  754. case '3':
  755. $lssetparam = [9, 12];
  756. break;
  757. }
  758. $command = ['command' => 'LSSET', 'content_arr' => ['command' => 'LSSET']];
  759. $this->createsendmsg($facility_id, $device_id_code, $command, $lssetparam, $sys_user_id);
  760. }
  761. /**
  762. * 睡眠时间段设置
  763. *
  764. * @return void
  765. * @author wj
  766. * @date 2023-08-29
  767. */
  768. public function createsleeptimecommand($facility_id, $device_id_code, $param, $sys_user_id)
  769. {
  770. $command = ['command' => 'SLEEPTIME', 'content_arr' => ['command' => 'SLEEPTIME']];
  771. $this->createsendmsg($facility_id, $device_id_code, $command, $param, $sys_user_id);
  772. }
  773. /**
  774. * 立即定位
  775. *
  776. * @return void
  777. * @author wj
  778. * @date 2023-08-29
  779. */
  780. public function createcrcommand($facility_id, $device_id_code, $sys_user_id)
  781. {
  782. $command = ['command' => 'CR', 'content_arr' => ['command' => 'CR']];
  783. $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
  784. }
  785. /**
  786. * 设置警报电话
  787. *
  788. * @param [type] $facility_id
  789. * @param [type] $device_id_code
  790. * @param [type] $param
  791. * @return void
  792. * @author wj
  793. * @date 2023-08-29
  794. */
  795. public function createsoscommand($facility_id, $device_id_code, $param, $sys_user_id)
  796. {
  797. $param = array_filter($param);
  798. $command = ['command' => 'SOS', 'content_arr' => ['command' => 'SOS']];
  799. $this->createsendmsg($facility_id, $device_id_code, $command, $param, $sys_user_id);
  800. }
  801. /**
  802. * 设置电话本
  803. *
  804. * @param [type] $arr
  805. * @return void
  806. * @author wj
  807. * @date 2023-08-29
  808. */
  809. public function createphlcommand($facility_id, $device_id_code, $param, $sys_user_id)
  810. {
  811. $param = array_filter($param);
  812. $command = ['command' => 'PHL', 'content_arr' => ['command' => 'PHL']];
  813. $this->createsendmsg($facility_id, $device_id_code, $command, $param, $sys_user_id);
  814. }
  815. //设备初始化
  816. public function facilityinit($facility_id, $device_id_code, $param, $sys_user_id)
  817. {
  818. Log::write($param, 'shouhuan');
  819. $zone = $param['zone'];
  820. $upload_interval = $param['upload_interval'];
  821. $fd_is_open = $param['fd_is_open'];
  822. $lowbat_is_open = $param['lowbat_is_open'];
  823. $pedo_is_open = $param['pedo_is_open'];
  824. $remove_is_open = $param['remove_is_open'];
  825. $commandlist = [
  826. ['command' => 'ZONE', 'content_arr' => ['command' => 'ZONE', 'zone' => $zone]],
  827. ['command' => 'UPLOAD', 'content_arr' => ['command' => 'UPLOAD', 'interval' => $upload_interval]],
  828. ['command' => 'CR', 'content_arr' => ['command' => 'CR']],
  829. ['command' => 'FALLDOWN', 'content_arr' => ['command' => 'FALLDOWN', 'is_open' => $fd_is_open]],
  830. ['command' => 'VERNO', 'content_arr' => ['command' => 'VERNO']],
  831. ['command' => 'LOWBAT', 'content_arr' => ['command' => 'LOWBAT', 'is_open' => $lowbat_is_open]],
  832. ['command' => 'PEDO', 'content_arr' => ['command' => 'PEDO', 'is_open' => $pedo_is_open]],
  833. ['command' => 'REMOVE', 'content_arr' => ['command' => 'REMOVE', 'is_open' => $remove_is_open]],
  834. ];
  835. foreach ($commandlist as $key => $value) {
  836. $this->createsendmsg($facility_id, $device_id_code, $value, [], $sys_user_id);
  837. }
  838. }
  839. /**
  840. * 数据间隔设置
  841. * 位置 心率 体温 血压 血氧
  842. *
  843. * @return void
  844. * @author wj
  845. * @date 2023-09-01
  846. */
  847. public function setdatainterval($facility_id, $device_id_code, $param = [], $sys_user_id)
  848. {
  849. Log::write($param, 'shouhuan');
  850. $cr_interval = $param['cr_interval'];
  851. $hrt_interval = $param['hrt_interval'];
  852. $wd_interval = $param['wd_interval'];
  853. $bld_interval = $param['bld_interval'];
  854. $ox_interval = $param['ox_interval'];
  855. $commandlist = [
  856. ['command' => 'UPLOAD', 'content_arr' => ['command' => 'UPLOAD', 'interval' => $cr_interval]],
  857. ['command' => 'HRTSTART', 'content_arr' => ['command' => 'HRTSTART', 'interval' => $hrt_interval]],
  858. ['command' => 'WDSTART', 'content_arr' => ['command' => 'WDSTART', 'interval' => $wd_interval]],
  859. ['command' => 'BLDSTART', 'content_arr' => ['command' => 'BLDSTART', 'interval' => $bld_interval]],
  860. ['command' => 'OXSTART', 'content_arr' => ['command' => 'OXSTART', 'interval' => $ox_interval]],
  861. ];
  862. foreach ($commandlist as $key => $value) {
  863. $this->createsendmsg($facility_id, $device_id_code, $value, $sys_user_id);
  864. }
  865. }
  866. /**
  867. * 关机
  868. *
  869. * @param [type] $facility_id
  870. * @param [type] $device_id_code
  871. * @param [type] $sys_user_id
  872. * @return void
  873. * @author wj
  874. * @date 2023-09-05
  875. */
  876. public function createpoweroffcommand($facility_id, $device_id_code, $sys_user_id)
  877. {
  878. $command = ['command' => 'POWEROFF', 'content_arr' => ['command' => 'POWEROFF']];
  879. $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
  880. }
  881. /**
  882. * 计步开关
  883. *
  884. * @param [type] $facility_id
  885. * @param [type] $device_id_code
  886. * @param [type] $sys_user_id
  887. * @return void
  888. * @author wj
  889. * @date 2023-09-05
  890. */
  891. public function createpedocommand($facility_id, $device_id_code, $is_open, $sys_user_id)
  892. {
  893. $command = ['command' => 'PEDO', 'content_arr' => ['command' => 'PEDO', 'is_open' => $is_open]];
  894. $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
  895. }
  896. /**
  897. * 闹钟
  898. *
  899. * @param [type] $facility_id
  900. * @param [type] $device_id_code
  901. * @param [type] $param
  902. * @param [type] $sys_user_id
  903. * @return void
  904. * @author wj
  905. * @date 2023-09-05
  906. */
  907. public function createremindcommand($facility_id, $device_id_code, $param, $sys_user_id)
  908. {
  909. Log::write($param, 'shouhuan');
  910. $command = ['command' => 'REMIND', 'content_arr' => ['command' => 'REMIND']];
  911. $this->createsendmsg($facility_id, $device_id_code, $command, $param, $sys_user_id);
  912. }
  913. /**
  914. * 静默时间
  915. *
  916. * @param [type] $facility_id
  917. * @param [type] $device_id_code
  918. * @param [type] $param
  919. * @param [type] $sys_user_id
  920. * @return void
  921. * @author wj
  922. * @date 2023-09-05
  923. */
  924. public function createsilencetime2command($facility_id, $device_id_code, $param, $sys_user_id)
  925. {
  926. Log::write($param, 'shouhuan');
  927. $command = ['command' => 'SILENCETIME2', 'content_arr' => ['command' => 'SILENCETIME2']];
  928. $this->createsendmsg($facility_id, $device_id_code, $command, $param, $sys_user_id);
  929. }
  930. /**
  931. * 开机关机时间
  932. *
  933. * @param [type] $facility_id
  934. * @param [type] $device_id_code
  935. * @param [type] $param
  936. * @param [type] $sys_user_id
  937. * @return void
  938. * @author wj
  939. * @date 2023-09-05
  940. */
  941. public function createbootoffcommand($facility_id, $device_id_code, $param, $sys_user_id)
  942. {
  943. $is_open = empty($param['is_open']) ? 0 : 1;
  944. $fillfields = ['bootup_time', 'shutdown_time'];
  945. foreach ($fillfields as $key => $value) {
  946. if (!isset($param[$value]) || empty($param[$value])) {
  947. throw new \Exception("BOOTOFF参数错误");
  948. }
  949. }
  950. $bootup_time = $param['bootup_time'];
  951. $shutdown_time = $param['shutdown_time'];
  952. $command = [
  953. 'command' => 'BOOTOFF',
  954. 'content_arr' => ['command' => 'BOOTOFF', 'is_open' => $is_open, 'bootup_time' => $bootup_time, 'shutdown_time' => $shutdown_time],
  955. ];
  956. $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
  957. }
  958. /**
  959. * 佩戴提醒
  960. *
  961. * @param [type] $facility_id
  962. * @param [type] $device_id_code
  963. * @param [type] $param
  964. * @param [type] $sys_user_id
  965. * @return void
  966. * @author wj
  967. * @date 2023-09-05
  968. */
  969. public function createremovecommand($facility_id, $device_id_code, $is_open, $sys_user_id)
  970. {
  971. $command = ['command' => 'REMOVE', 'content_arr' => ['command' => 'REMOVE', 'is_open' => $is_open]];
  972. $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
  973. }
  974. /**
  975. * 拨打电话
  976. *
  977. * @param [type] $facility_id
  978. * @param [type] $device_id_code
  979. * @param [type] $telno
  980. * @param [type] $sys_user_id
  981. * @return void
  982. * @author wj
  983. * @date 2023-09-15
  984. */
  985. public function createcallcommand($facility_id, $device_id_code, $telno, $sys_user_id)
  986. {
  987. $command = ['command' => 'CALL', 'content_arr' => ['command' => 'CALL', 'telno' => $telno]];
  988. $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
  989. }
  990. /**
  991. * 拨号盘开关
  992. *
  993. * @param [type] $facility_id
  994. * @param [type] $device_id_code
  995. * @param [type] $telno
  996. * @param [type] $sys_user_id
  997. * @return void
  998. * @author wj
  999. * @date 2023-09-18
  1000. */
  1001. public function createkeybrdcommand($facility_id, $device_id_code, $is_open, $sys_user_id)
  1002. {
  1003. $command = ['command' => 'KEYBRD', 'content_arr' => ['command' => 'KEYBRD', 'is_open' => $is_open]];
  1004. $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
  1005. }
  1006. }