ShouhuanCommand.php 33 KB

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