ShouhuanCommand.php 30 KB

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