ShouhuanCommand.php 33 KB

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