ShouhuanCommand.php 30 KB

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