BikeControl.php 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714
  1. <?php
  2. ///**
  3. // * Created by PhpStorm.
  4. // * User: Mead
  5. // * Date: 2019/9/5
  6. // * Time: 9:36 PM
  7. // */
  8. //
  9. //namespace App\Handlers\Weikemu;
  10. //
  11. //
  12. //use GatewayClient\Gateway;
  13. //use Illuminate\Support\Facades\Redis;
  14. //
  15. //class BikeControl
  16. //{
  17. // private static $start = '42 44';
  18. //
  19. // private static $registerAddress = 'node1:2238';
  20. //
  21. // // 还车成功,请规范停车
  22. // const VIDEO_RETURN_BIKE = '01';
  23. //// 开锁成功
  24. // const VIDEO_OPEN_LOCK = '02';
  25. //// 请文明骑行规范停车
  26. // const VIDEO_CIVILIZATION = '03';
  27. //// 车辆已断电请回到服务区
  28. // const VIDEO_POWER_FAILURE = '04';
  29. //// 车辆已下线
  30. // const VIDEO_OFFLINE = '05';
  31. //// 非法移动
  32. // const VIDEO_ILLEGAL_MOVE = '06';
  33. //// 临停成功将持续计费
  34. // const VIDEO_FIND_BIKE = '07';
  35. //// 向着诗和远方我们继续出发吧
  36. // const VIDEO_KEEP_GOING = '08';
  37. //// 小喵在这里
  38. // const VIDEO_BIKE_HERE = '09';
  39. //// 靠近服务区边缘,服务区外将断电 10
  40. // const VIDEO_BATTERY_EDGE = '0A';
  41. //// 换电完成您辛苦了 11
  42. // const VIDEO_POWER_CHANGE = '0B';
  43. //// 您已出服务区请尽快骑回 12
  44. // const VIDEO_GO_BEYOND = '0C';
  45. //// 夜间出行注意安全 13
  46. // const VIDEO_NIGHT_SAFETY = '0D';
  47. //// 当前为禁停区禁止停车 14
  48. // const VIDEO_NO_STOPPING = '0E';
  49. // // 空 15
  50. //
  51. // // 小喵生病了试试别的车吧 16
  52. // const VIDEO_USE_OTHER = '10';
  53. //
  54. // //电量过低 17
  55. // const VIDEO_LOW_POWER = '11';
  56. // // 主人即将回来试试别的车吧 18
  57. // const VIDEO_OCCUPIED = '12';
  58. // //小猫被预约了试试别的车吧 19
  59. // const VIDEO_RESERVED = '13';
  60. // // (带告警音)请停止偷窃行为 20
  61. // const VIDEO_WARNING = '14';
  62. // // 您已进入禁停区 21
  63. // const VIDEO_NO_STOP_ZONE = '15';
  64. // // 车辆已报警请勿移动 22
  65. // const VIDEO_ALARMED = '16';
  66. // //请停止偷窃行为 23
  67. // const VIDEO_NO_STEALING = '17';
  68. // // 设备已绑定 24
  69. // const VIDEO_BOUND = '18';
  70. // // 小喵摔倒了
  71. // const VIDEO_FALL = '19';
  72. //
  73. // /**
  74. // * 播放语音
  75. // * @param $box_no
  76. // * @return bool
  77. // * User: Mead
  78. // */
  79. // public static function playVoice($box_no, $voice_no)
  80. // {
  81. // $cmd = "2A";
  82. //
  83. // $body = [
  84. // self::getMsgId(),
  85. // '01',
  86. // $voice_no,
  87. // 'FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF',
  88. // 'FF FF FF FF',
  89. // 'FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF',
  90. // 'FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF',
  91. // ];
  92. //
  93. // $send_msg = self::makeSendMsg($cmd, $body);
  94. //
  95. // return self::send($box_no, $send_msg);
  96. // }
  97. //
  98. // /**
  99. // * queryCmd 3.2.1 查询指令
  100. // *
  101. // * @param $box_no
  102. // * @return bool
  103. // * @author Fx
  104. // *
  105. // */
  106. // public static function queryCmd($box_no, $str2 = '00111101')
  107. // {
  108. // // echo 'queryCmd' . PHP_EOL;
  109. // $cmd = "2B";
  110. //
  111. //// $str2 = '00111101'; // 3d
  112. // $body = [
  113. // self::getMsgId(),
  114. // str_pad(base_convert($str2, 2, 16), 2, 0, STR_PAD_LEFT)
  115. // ];
  116. //
  117. // $send_msg = self::makeSendMsg($cmd, $body);
  118. //
  119. // // echo $send_msg . PHP_EOL;
  120. // return self::send($box_no, $send_msg);
  121. // }
  122. //
  123. // /**
  124. // * electricSwitchControl 电门控制
  125. // *
  126. // * @param $box_no
  127. // * @param $control 01 电门开启; 00 电门关闭(关闭防盗开关);02 电门关闭(开启防盗开关);
  128. // * @return bool
  129. // * @author Fx
  130. // *
  131. // */
  132. // public static function electricSwitchControl($box_no, $control = "01")
  133. // {
  134. //// echo 'kaiguansuo' . PHP_EOL;
  135. // $cmd = "2D";
  136. //
  137. // $body = [
  138. // self::getMsgId(),
  139. // $control,// 01 电门开启; 00 电门关闭(关闭防盗开关);02 电门关闭(开启防盗开关);
  140. // ];
  141. //
  142. // $send_msg = self::makeSendMsg($cmd, $body);
  143. //
  144. // return self::send($box_no, $send_msg);
  145. // }
  146. //
  147. // /**
  148. // * realLocation 3.2.2 实时位置上报参数设置
  149. // *
  150. // * @param $box_no
  151. // * @param string $control 01:实时追踪开启,00:实时追踪关闭
  152. // * @param int $interval 上报间隔 秒 量化值30
  153. // * @param int $continued 持续时长(1-43200) 分钟
  154. // * @return bool
  155. // * @author Fx
  156. // *
  157. // */
  158. // public static function realLocation($box_no, $control = "01", $interval = 1, $continued = 60)
  159. // {
  160. //// $box_no = '868626040174578';
  161. // $cmd = "23";
  162. //
  163. // $body = [
  164. // self::getMsgId(),
  165. // $control,// 1:实时追踪开启,0:实时追踪关闭
  166. // str_pad(base_convert($interval, 10, 16), 4, 0, STR_PAD_LEFT),//上报间隔
  167. // str_pad(base_convert($continued, 10, 16), 4, 0, STR_PAD_LEFT),//持续时长(1-43200)
  168. // ];
  169. //
  170. // $send_msg = self::makeSendMsg($cmd, $body);
  171. //
  172. //// var_dump($body);
  173. // return self::send($box_no, $send_msg);
  174. // }
  175. //
  176. // /**
  177. // * multipleConfigsSetting 3.2.3 综合配置参数设置
  178. // *
  179. // * @param $box_no
  180. // * @param $arr
  181. // * @return bool
  182. // * @author Fx
  183. // *
  184. // */
  185. // public static function multipleConfigsSetting($box_no, $arr)
  186. // {
  187. //
  188. //
  189. // $cmd = "2C";
  190. //// ['ip' => $ip,'port' => $port,'bluetooth_name' => $bluetooth_name,'bluetooth_token' => $bluetooth_token,
  191. //// 'is_auto_lock' => $is_auto_lock, 'auto_lock_time' => $auto_lock_time,
  192. //// 'is_displacement' => $is_displacement, 'displacement_radius' => $displacement_radius,
  193. //// 'is_shock' => $is_shock,
  194. //// 'is_temperature' => $is_temperature,'temperature' => $temperature,
  195. //// 'is_speeding' => $is_speeding,'speeding'=>$speeding,
  196. //// 'motion_position_sampling_interval'=>$motion_position_sampling_interval,
  197. //// 'motion_position_reporting_interval'=>$motion_position_reporting_interval,
  198. //// 'static_position_reporting_interval'=>$static_position_reporting_interval];
  199. // $ip = $arr['ip'];
  200. // $port = $arr['port'];
  201. // $bluetooth_name = $arr['bluetooth_name']; // 蓝牙名称
  202. // $bluetooth_token = $arr['bluetooth_token']; //蓝牙token
  203. // $is_auto_lock = $arr['is_auto_lock']; // 是否开启自动落锁1:自动落锁开启;0:关闭自动落锁
  204. // $auto_lock_time = str_pad(base_convert($arr['auto_lock_time'], 10, 2), 7, 0, STR_PAD_LEFT); // 自动落锁时长,量化单位1分钟
  205. //
  206. // $is_displacement = $arr['is_displacement']; // 位移告警开启设置1:位移告警开启;0: 位移告警关闭
  207. // $displacement_radius = str_pad(base_convert($arr['displacement_radius'], 10, 2), 7, 0, STR_PAD_LEFT); // 位移告警半径门限,取值范围0~126,量化单位10米
  208. //
  209. // $is_shock = $arr['is_shock'];//震动告警开启设置1:震动告警开启,0:震动告警关闭
  210. //
  211. // $is_temperature = $arr['is_temperature'];//温度告警开启设置。1:温度告警开启;0:温度告警关闭
  212. // $temperature = str_pad(base_convert($arr['temperature'], 10, 2), 7, 0, STR_PAD_LEFT); // 温度告警门限,取值范围0~126,
  213. //
  214. // $is_speeding = $arr['is_speeding']; // 超速告警开启设置。1:超速告警开启;0:超速告警关闭
  215. // $speeding = str_pad(base_convert($arr['speeding'] * 2, 10, 2), 7, 0, STR_PAD_LEFT); // 超速告警门限 量化单位2km/h,范围 0~126
  216. // $motion_position_sampling_interval = $arr['motion_position_sampling_interval']; // 运动状态,位置采样间隔设置(默认1秒)
  217. // $motion_position_reporting_interval = $arr['motion_position_reporting_interval']; // 运动状态,位置上报间隔设置
  218. // $static_position_reporting_interval = $arr['static_position_reporting_interval']; // 静止状态,位置上报间隔设置
  219. //
  220. //
  221. // $body = [
  222. // self::getMsgId(),
  223. // str_pad(base_convert($motion_position_sampling_interval, 10, 16), 2, 0, STR_PAD_LEFT),// 运动状态,位置采样间隔设置(默认1秒)
  224. // str_pad(base_convert($motion_position_reporting_interval, 10, 16), 2, 0, STR_PAD_LEFT),// 运动状态,位置上报间隔设置
  225. // str_pad(base_convert($static_position_reporting_interval, 10, 16), 4, 0, STR_PAD_LEFT),// 静止状态,位置上报间隔设置
  226. // str_pad(base_convert($displacement_radius . $is_displacement, 2, 16), 2, 0, STR_PAD_LEFT),// 位移告警
  227. // str_pad(base_convert('0000000' . $is_shock, 2, 16), 2, 0, STR_PAD_LEFT),// 震动告警
  228. // str_pad(base_convert($temperature . $is_temperature, 2, 16), 2, 0, STR_PAD_LEFT),// 温度告警
  229. // str_pad(base_convert($speeding . $is_speeding, 2, 16), 2, 0, STR_PAD_LEFT),// 超速告警
  230. // str_pad(base_convert($auto_lock_time . $is_auto_lock, 2, 16), 2, 0, STR_PAD_LEFT),// 自动落锁
  231. // str_pad(base_convert($port, 10, 16), 4, 0, STR_PAD_LEFT),// 自动落锁
  232. // str_pad(base_convert($ip, 10, 16), 8, 0, STR_PAD_LEFT),// 自动落锁
  233. // str_pad($bluetooth_name, 10, 0, STR_PAD_LEFT),
  234. // str_pad(base_convert($bluetooth_token, 10, 16), 8, 0, STR_PAD_LEFT),// 自动落锁
  235. // '00 00 00 00 00 00'
  236. // ];
  237. //
  238. // $send_msg = self::makeSendMsg($cmd, $body);
  239. //
  240. // return self::send($box_no, $send_msg);
  241. // }
  242. //
  243. // /**
  244. // * reboot 重启中控
  245. // *
  246. // * @param $box_no
  247. // * @param $reboot string 11:重启升级;01:重启不升级
  248. // * @param $ip string 重启升级地址(域名或IP地址)
  249. // * @param $port int 重启升级端口号
  250. // * @param $path string 重启升级路径
  251. // * @param $upFile string 重启升级文件名称
  252. // * @return bool
  253. // * @author Fx
  254. // *
  255. // */
  256. // public static function reboot($box_no, $reboot = "01", $ip, $port, $path, $upFile)
  257. // {
  258. //// $box_no = '868626040174578';
  259. // $cmd = "25";
  260. //// $reboot = '000000' . $reboot; // 11:重启升级;01:重启不升级
  261. //
  262. //
  263. // $body = [
  264. // self::getMsgId(),
  265. // self::str2Hex($reboot, 2, 8),
  266. // self::char2Hex($ip, 20),
  267. // self::str2Hex($port, 10, 8),
  268. // self::char2Hex($path, 20),
  269. // self::char2Hex($upFile, 20),
  270. // ];
  271. //
  272. // $send_msg = self::makeSendMsg($cmd, $body);
  273. //
  274. // return self::send($box_no, $send_msg);
  275. // }
  276. //
  277. // /**
  278. // * settingVoice 语音设置
  279. // *
  280. // * @param $box_no
  281. // * @param $voice_no
  282. // * @param $ip
  283. // * @param $port
  284. // * @param $path
  285. // * @param $upFile
  286. // * @return bool
  287. // * @author Fx
  288. // *
  289. // */
  290. // public static function settingVoice($box_no, $voice_no, $ip, $port, $path, $upFile)
  291. // {
  292. //
  293. // $cmd = "2A";
  294. //
  295. // $body = [
  296. // self::getMsgId(),
  297. // '00',
  298. // self::str2Hex($voice_no, 10, 2),
  299. // self::char2Hex($ip, 20),
  300. // self::str2Hex($port, 10, 8),
  301. // self::char2Hex($path, 20),
  302. // self::char2Hex($upFile, 20),
  303. // ];
  304. //
  305. // $send_msg = self::makeSendMsg($cmd, $body);
  306. //
  307. // return self::send($box_no, $send_msg);
  308. // }
  309. //
  310. // /**
  311. // * guardSwitch 3.2.7 防盗开关设置
  312. // *
  313. // * @param $box_no
  314. // * @param $control 00:关闭 01:开启
  315. // * @return bool
  316. // * @author Fx
  317. // *
  318. // */
  319. // public static function guardSwitch($box_no, $control)
  320. // {
  321. //// echo 'guard' . PHP_EOL;
  322. //
  323. // $cmd = "2E";
  324. //
  325. // $body = [
  326. // self::getMsgId(),
  327. // $control
  328. // ];
  329. //
  330. // $send_msg = self::makeSendMsg($cmd, $body);
  331. //
  332. // return self::send($box_no, $send_msg);
  333. // }
  334. //
  335. // /**
  336. // * batterySwitch 3.2.8 电池仓开关设置
  337. // *
  338. // * @param $box_no
  339. // * @return bool
  340. // * @author Fx
  341. // *
  342. // */
  343. // public static function batterySwitch($box_no)
  344. // {
  345. //// echo 'batterySwitch' . PHP_EOL;
  346. //
  347. // $cmd = "2F";
  348. //
  349. // $body = [
  350. // self::getMsgId(),
  351. // '01',
  352. // ];
  353. //
  354. // $send_msg = self::makeSendMsg($cmd, $body);
  355. //
  356. // return self::send($box_no, $send_msg);
  357. // }
  358. //
  359. // /**
  360. // * limitSpeed 限速
  361. // *
  362. // * @param $box_no
  363. // * @param $limit int 限速[%]
  364. // * @return bool
  365. // * @author Fx
  366. // *
  367. // */
  368. // public static function limitSpeed($box_no, $limit)
  369. // {
  370. //
  371. // $cmd = "30";
  372. //
  373. // $body = [
  374. // self::getMsgId(),
  375. // self::str2Hex($limit, 10, 2),// 限速[%]
  376. // ];
  377. //
  378. // $send_msg = self::makeSendMsg($cmd, $body);
  379. //
  380. // return self::send($box_no, $send_msg);
  381. // }
  382. //
  383. // /**
  384. // * undervoltageProtection 3.2.10 控制器欠压保护设置
  385. // *
  386. // * @param $box_no
  387. // * @param $limit int 控制器欠压保护值,量单位1mv
  388. // * @return bool
  389. // * @author Fx
  390. // *
  391. // */
  392. // public static function undervoltageProtection($box_no, $limit)
  393. // {
  394. //
  395. // $cmd = "31";
  396. //
  397. // $body = [
  398. // self::getMsgId(),
  399. // self::str2Hex($limit, 10, 4),// 限速[%]
  400. // ];
  401. //
  402. // $send_msg = self::makeSendMsg($cmd, $body);
  403. //
  404. // return self::send($box_no, $send_msg);
  405. // }
  406. //
  407. //
  408. // /**
  409. // * currentLimitingProtection 3.2.11 控制器限流保护设置
  410. // *
  411. // * @param $box_no
  412. // * @param $limit int 控制器限流保护值,量化单位1mA
  413. // * @return bool
  414. // * @author Fx
  415. // *
  416. // */
  417. // public static function currentLimitingProtection($box_no, $limit)
  418. // {
  419. //
  420. // $cmd = "32";
  421. //
  422. // $body = [
  423. // self::getMsgId(),
  424. // self::str2Hex($limit, 10, 4),//
  425. // ];
  426. //
  427. // $send_msg = self::makeSendMsg($cmd, $body);
  428. //
  429. // return self::send($box_no, $send_msg);
  430. // }
  431. //
  432. // /**
  433. // * slowReboot 3.2.12 控制器缓启动设置
  434. // *
  435. // * @param $box_no
  436. // * @param $control string 01,缓启动;00,快启动
  437. // * @return bool
  438. // * @author Fx
  439. // *
  440. // */
  441. // public static function slowReboot($box_no, $control)
  442. // {
  443. //
  444. // $cmd = "33";
  445. //
  446. // $body = [
  447. // self::getMsgId(),
  448. // $control,
  449. // ];
  450. //
  451. // $send_msg = self::makeSendMsg($cmd, $body);
  452. //
  453. // return self::send($box_no, $send_msg);
  454. // }
  455. //
  456. // /**
  457. // * lampSwitch 3.2.13 控制器大灯设置
  458. // *
  459. // * @param $box_no
  460. // * @param $control string 01,大灯开;00,大灯关
  461. // * @return bool
  462. // * @author Fx
  463. // *
  464. // */
  465. // public static function lampSwitch($box_no, $control)
  466. // {
  467. //
  468. // $cmd = "34";
  469. //
  470. // $body = [
  471. // self::getMsgId(),
  472. // $control,
  473. // ];
  474. //
  475. // $send_msg = self::makeSendMsg($cmd, $body);
  476. //
  477. // return self::send($box_no, $send_msg);
  478. // }
  479. //
  480. //
  481. // /**
  482. // * orderStatus
  483. // *
  484. // * @param $box_no
  485. // * @param $control string 01:接单开启;00:接单关闭
  486. // * @return bool
  487. // * @author Fx
  488. // *
  489. // */
  490. // public static function orderStatus($box_no, $control)
  491. // {
  492. // $cmd = "35";
  493. //
  494. // $body = [
  495. // self::getMsgId(),
  496. // $control,
  497. // ];
  498. //
  499. // $send_msg = self::makeSendMsg($cmd, $body);
  500. //
  501. // return self::send($box_no, $send_msg);
  502. // }
  503. //
  504. // /**
  505. // * nowBikeLocation 立即定位
  506. // *
  507. // * @param $box_no
  508. // * @return bool
  509. // * @author Fx
  510. // *
  511. // */
  512. // public static function nowBikeLocation($box_no)
  513. // {
  514. // //删除ridis位置缓存
  515. // self::delRedisCache($box_no, 'update_bike_location');
  516. // return self::queryCmd($box_no, '00000001');
  517. // }
  518. //
  519. //
  520. // /**
  521. // * openLock 开锁
  522. // *
  523. // * @param $box_no
  524. // * @return bool
  525. // * @author Fx
  526. // *
  527. // */
  528. // public static function openLock($box_no)
  529. // {
  530. // self::playVoice($box_no, self::VIDEO_OPEN_LOCK);
  531. // self::orderStatus($box_no, '01');
  532. // return self::electricSwitchControl($box_no, '01');
  533. // }
  534. //
  535. // /**
  536. // * closeLock 关锁 (设防)
  537. // *
  538. // * @param $box_no
  539. // * @return bool
  540. // * @author Fx
  541. // *
  542. // */
  543. // public static function closeLock($box_no)
  544. // {
  545. // self::playVoice($box_no, self::VIDEO_RETURN_BIKE);
  546. // self::orderStatus($box_no, '00');
  547. // return self::electricSwitchControl($box_no, '02');
  548. // }
  549. //
  550. // /**
  551. // * closeLock 临时关锁 (设防)
  552. // *
  553. // * @param $box_no
  554. // * @return bool
  555. // * @author Fx
  556. // *
  557. // */
  558. // public static function temporaryCloseLock($box_no)
  559. // {
  560. // self::playVoice($box_no, self::VIDEO_FIND_BIKE);
  561. // return self::electricSwitchControl($box_no, '02');
  562. // }
  563. //
  564. // /**
  565. // * temporaryOpnLock 临时开锁
  566. // *
  567. // * @param $box_no
  568. // * @return bool
  569. // * @author Fx
  570. // *
  571. // */
  572. // public static function temporaryOpnLock($box_no)
  573. // {
  574. // self::playVoice($box_no, self::VIDEO_KEEP_GOING);
  575. // return self::electricSwitchControl($box_no, '01');
  576. // }
  577. //
  578. // /**
  579. // * closeLockNoGuard 关锁 (不设防) 失能
  580. // *
  581. // * @param $box_no
  582. // * @return bool
  583. // * @author Fx
  584. // *
  585. // */
  586. // public static function outAreaLoseElectric($box_no)
  587. // {
  588. // self::playVoice($box_no, self::VIDEO_GO_BEYOND);
  589. // return self::electricSwitchControl($box_no, '00');
  590. // }
  591. //
  592. // /**
  593. // * outAreaGetElectric 开锁 获能
  594. // *
  595. // * @param $box_no
  596. // * @return bool
  597. // * @author Fx
  598. // *
  599. // */
  600. // public static function outAreaGetElectric($box_no)
  601. // {
  602. // self::playVoice($box_no, self::VIDEO_KEEP_GOING);
  603. // return self::electricSwitchControl($box_no, '01');
  604. // }
  605. //
  606. // public static function bellBike($box_no)
  607. // {
  608. // return self::playVoice($box_no, self::VIDEO_BIKE_HERE);
  609. // }
  610. //
  611. // /**
  612. // * 删除缓存
  613. // * @param $box_no
  614. // * @param $type
  615. // * User: Mead
  616. // */
  617. // public static function delRedisCache($box_no, $types)
  618. // {
  619. // $cacheNames = [];
  620. // if (is_array($types)) {
  621. // foreach ($types as $type) {
  622. // $cacheNames[] = "cache:min:{$type}:{$box_no}";
  623. // }
  624. // } else {
  625. // $cacheNames[] = "cache:min:{$types}:{$box_no}";
  626. // }
  627. // if (!count($cacheNames)) return false;
  628. // Redis::connection()->del($cacheNames);
  629. // }
  630. //
  631. //
  632. // /**
  633. // * 获取序号(msg_id)
  634. // * @return string
  635. // * Author: Mead
  636. // */
  637. // private static function getMsgId()
  638. // {
  639. // $msg_id = str_pad(dechex(rand(0, 65535)), 4, "0", STR_PAD_LEFT);
  640. // return $msg_id;
  641. // }
  642. //
  643. // /**
  644. // * str2Hex 其他进制转16进制
  645. // *
  646. // * @param $str string 需要转的数据
  647. // * @param $frombase int 需要转的进制
  648. // * @param $pad_length int 长度
  649. // * @return string
  650. // * @author Fx
  651. // *
  652. // */
  653. // private static function str2Hex($str, $frombase, $pad_length)
  654. // {
  655. // return str_pad(base_convert($str, $frombase, 16), $pad_length, 0, STR_PAD_LEFT);
  656. // }
  657. //
  658. // /**
  659. // * char2Hex char 转16进制
  660. // *
  661. // * @param $char
  662. // * @param $pad_length
  663. // * @return string
  664. // * @author Fx
  665. // *
  666. // */
  667. // private static function char2Hex($char, $pad_length)
  668. // {
  669. // return str_pad(bin2hex($char), $pad_length, 0, STR_PAD_LEFT);
  670. // }
  671. //
  672. // /**
  673. // * 发送数据
  674. // * @param $box_no
  675. // * @param $msg
  676. // * @return bool
  677. // * User: Mead
  678. // */
  679. // private static function send($box_no, $msg)
  680. // {
  681. // Gateway::$registerAddress = config('bike.bike_control_register_address');
  682. // if (Gateway::isUidOnline($box_no)) {
  683. // Gateway::sendToUid($box_no, '+NNMI,' . hex2bin(str_replace(' ', '', $msg . '0D0A')));
  684. // return true;
  685. // }
  686. // return false;
  687. // }
  688. //
  689. // /**
  690. // * 组装命令
  691. // * @param $cmd
  692. // * @param $msgID
  693. // * @return string
  694. // * User: Mead
  695. // */
  696. // private static function makeSendMsg($cmd, $body, $msg_id = false, $length = false)
  697. // {
  698. // if (is_array($body)) {
  699. // $body = self::arr2arr($body);
  700. // }
  701. // if (is_string($body)) {
  702. // $body = str_split($body, 2);
  703. // }
  704. //
  705. //
  706. // if ($length !== false) {
  707. // $length = str_pad($length, 4, '0', STR_PAD_LEFT);
  708. // } else {
  709. // $length = str_pad(dechex(count($body)), 4, '0', STR_PAD_LEFT);
  710. // }
  711. //
  712. // if ($msg_id === false) {
  713. // $msg_id = self::getMsgId();
  714. // }
  715. // $header = [
  716. // $cmd,
  717. // $msg_id,
  718. // '00',
  719. // $length
  720. // ];
  721. // $response = self::formatArr($header, $body);
  722. // $response[] = self::verification($response);
  723. //
  724. // return self::format(self::$start . implode('', $response));
  725. // }
  726. //
  727. // /**
  728. // * 校检
  729. // * @param $data
  730. // * @param $verification
  731. // * @return bool
  732. // * Author: Mead
  733. // */
  734. // protected static function verification($data)
  735. // {
  736. // $a = $b = 0;
  737. // for ($i = 0; $i < count($data); $i++) {
  738. // $a = $a + hexdec($data[$i]);
  739. // $b = $a + $b;
  740. // }
  741. // return str_pad(substr(dechex($a), -2), 2, 0, STR_PAD_LEFT) . str_pad(substr(dechex($b), -2), 2, 0, STR_PAD_LEFT);
  742. // }
  743. //
  744. // /**
  745. // * 格式数组
  746. // * @param $arr
  747. // * @return array
  748. // * User: Mead
  749. // */
  750. // private static function arr2arr($arr)
  751. // {
  752. // $arr = implode('', $arr);
  753. // return str_split(str_replace(' ', '', $arr), 2);
  754. // }
  755. //
  756. // /**
  757. // * 合并数组
  758. // * @return array
  759. // * User: Mead
  760. // */
  761. // private static function formatArr()
  762. // {
  763. // $args = func_get_args();
  764. // $arr = '';
  765. // foreach ($args as $arg) {
  766. // $arr .= implode('', $arg);
  767. // }
  768. // return str_split($arr, 2);
  769. // }
  770. //
  771. // /**
  772. // * 格式字符
  773. // * @param $str
  774. // * @return string
  775. // * User: Mead
  776. // */
  777. // private static function format($str)
  778. // {
  779. // return strtoupper(implode('', str_split(str_replace(' ', '', $str), 2)));
  780. // }
  781. //}
  782. /**
  783. * Created by PhpStorm.
  784. * User: Mead
  785. * Date: 2019/9/5
  786. * Time: 9:36 PM
  787. */
  788. namespace App\Handlers\Weikemu;
  789. use GatewayClient\Gateway;
  790. use Illuminate\Support\Facades\Log;
  791. use Illuminate\Support\Facades\Redis;
  792. class BikeControl
  793. {
  794. private static $start = '42 44';
  795. private static $registerAddress = 'node1:2238';
  796. // 还车成功,请规范停车
  797. const VIDEO_RETURN_BIKE = '01';
  798. // 开锁成功
  799. const VIDEO_OPEN_LOCK = '02';
  800. // 请文明骑行规范停车
  801. const VIDEO_CIVILIZATION = '03';
  802. // 车辆已断电请回到服务区
  803. const VIDEO_POWER_FAILURE = '04';
  804. // 车辆已下线
  805. const VIDEO_OFFLINE = '05';
  806. // 非法移动
  807. const VIDEO_ILLEGAL_MOVE = '06';
  808. // 临停成功将持续计费
  809. const VIDEO_FIND_BIKE = '07';
  810. // 向着诗和远方我们继续出发吧
  811. const VIDEO_KEEP_GOING = '08';
  812. // 小喵在这里
  813. const VIDEO_BIKE_HERE = '09';
  814. // 靠近服务区边缘,服务区外将断电 10
  815. const VIDEO_BATTERY_EDGE = '0A';
  816. // 换电完成您辛苦了 11
  817. const VIDEO_POWER_CHANGE = '0B';
  818. // 您已出服务区请尽快骑回 12
  819. const VIDEO_GO_BEYOND = '0C';
  820. // 夜间出行注意安全 13
  821. const VIDEO_NIGHT_SAFETY = '0D';
  822. // 当前为禁停区禁止停车 14
  823. const VIDEO_NO_STOPPING = '0E';
  824. // 空 15
  825. // 小喵生病了试试别的车吧 16
  826. const VIDEO_USE_OTHER = '10';
  827. //电量过低 17
  828. const VIDEO_LOW_POWER = '11';
  829. // 主人即将回来试试别的车吧 18
  830. const VIDEO_OCCUPIED = '12';
  831. //小猫被预约了试试别的车吧 19
  832. const VIDEO_RESERVED = '13';
  833. // (带告警音)请停止偷窃行为 20
  834. const VIDEO_WARNING = '14';
  835. // 您已进入禁停区 21
  836. const VIDEO_NO_STOP_ZONE = '15';
  837. // 车辆已报警请勿移动 22
  838. const VIDEO_ALARMED = '16';
  839. //请停止偷窃行为 23
  840. const VIDEO_NO_STEALING = '17';
  841. // 设备已绑定 24
  842. const VIDEO_BOUND = '18';
  843. // 小喵摔倒了
  844. const VIDEO_FALL = '19';
  845. const CACHE_KEY = 'cache:select';
  846. /**
  847. * 播放语音
  848. * @param $box_no
  849. * @return bool
  850. * User: Mead
  851. */
  852. public static function playVoice($box_no, $voice_no, $msg_id = false)
  853. {
  854. $cmd = "2A";
  855. $body = [
  856. self::getMsgId(),
  857. '01',
  858. $voice_no,
  859. 'FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF',
  860. 'FF FF FF FF',
  861. 'FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF',
  862. 'FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF',
  863. ];
  864. $send_msg = self::makeSendMsg($cmd, $body);
  865. return self::send($box_no, $send_msg, false);
  866. }
  867. /**
  868. * queryCmd 3.2.1 查询指令
  869. *
  870. * @param $box_no
  871. * @return bool
  872. * @author Fx
  873. *
  874. */
  875. public static function queryCmd($box_no, $str2 = '00111101')
  876. {
  877. $cmd = "2B";
  878. $body = [
  879. self::getMsgId(),
  880. str_pad(base_convert($str2, 2, 16), 2, 0, STR_PAD_LEFT)
  881. ];
  882. $send_msg = self::makeSendMsg($cmd, $body);
  883. return self::send($box_no, $send_msg, false);
  884. }
  885. /**
  886. * electricSwitchControl 电门控制
  887. *
  888. * @param $box_no
  889. * @param $control 01 电门开启; 00 电门关闭(关闭防盗开关);02 电门关闭(开启防盗开关);
  890. * @return bool
  891. * @author Fx
  892. *
  893. */
  894. public static function electricSwitchControl($box_no, $control = "01")
  895. {
  896. $cmd = "2D";
  897. $msg_id = self::getMsgId();
  898. $body = [
  899. $msg_id,
  900. $control,// 01 电门开启; 00 电门关闭(关闭防盗开关);02 电门关闭(开启防盗开关);
  901. ];
  902. $send_msg = self::makeSendMsg($cmd, $body);
  903. return self::send($box_no, $send_msg, $msg_id);
  904. }
  905. /**
  906. * realLocation 3.2.2 实时位置上报参数设置
  907. *
  908. * @param $box_no
  909. * @param string $control 01:实时追踪开启,00:实时追踪关闭
  910. * @param int $interval 上报间隔 秒 量化值30
  911. * @param int $continued 持续时长(1-43200) 分钟
  912. * @return bool
  913. * @author Fx
  914. *
  915. */
  916. public static function realLocation($box_no, $control = "01", $interval = 1, $continued = 60)
  917. {
  918. $cmd = "23";
  919. $body = [
  920. self::getMsgId(),
  921. $control,// 1:实时追踪开启,0:实时追踪关闭
  922. str_pad(base_convert($interval, 10, 16), 4, 0, STR_PAD_LEFT),//上报间隔
  923. str_pad(base_convert($continued, 10, 16), 4, 0, STR_PAD_LEFT),//持续时长(1-43200)
  924. ];
  925. $send_msg = self::makeSendMsg($cmd, $body);
  926. return self::send($box_no, $send_msg, false);
  927. }
  928. /**
  929. * multipleConfigsSetting 3.2.3 综合配置参数设置
  930. *
  931. * @param $box_no
  932. * @param $arr
  933. * @return bool
  934. * @author Fx
  935. *
  936. */
  937. public static function multipleConfigsSetting($box_no, $arr)
  938. {
  939. $cmd = "2C";
  940. // ['ip' => $ip,'port' => $port,'bluetooth_name' => $bluetooth_name,'bluetooth_token' => $bluetooth_token,
  941. // 'is_auto_lock' => $is_auto_lock, 'auto_lock_time' => $auto_lock_time,
  942. // 'is_displacement' => $is_displacement, 'displacement_radius' => $displacement_radius,
  943. // 'is_shock' => $is_shock,
  944. // 'is_temperature' => $is_temperature,'temperature' => $temperature,
  945. // 'is_speeding' => $is_speeding,'speeding'=>$speeding,
  946. // 'motion_position_sampling_interval'=>$motion_position_sampling_interval,
  947. // 'motion_position_reporting_interval'=>$motion_position_reporting_interval,
  948. // 'static_position_reporting_interval'=>$static_position_reporting_interval];
  949. $ip = $arr['ip'];
  950. $port = $arr['port'];
  951. $bluetooth_name = $arr['bluetooth_name']; // 蓝牙名称
  952. $bluetooth_token = $arr['bluetooth_token']; //蓝牙token
  953. $is_auto_lock = $arr['is_auto_lock']; // 是否开启自动落锁1:自动落锁开启;0:关闭自动落锁
  954. $auto_lock_time = str_pad(base_convert($arr['auto_lock_time'], 10, 2), 7, 0, STR_PAD_LEFT); // 自动落锁时长,量化单位1分钟
  955. $is_displacement = $arr['is_displacement']; // 位移告警开启设置1:位移告警开启;0: 位移告警关闭
  956. $displacement_radius = str_pad(base_convert($arr['displacement_radius'], 10, 2), 7, 0, STR_PAD_LEFT); // 位移告警半径门限,取值范围0~126,量化单位10米
  957. $is_shock = $arr['is_shock'];//震动告警开启设置1:震动告警开启,0:震动告警关闭
  958. $is_temperature = $arr['is_temperature'];//温度告警开启设置。1:温度告警开启;0:温度告警关闭
  959. $temperature = str_pad(base_convert($arr['temperature'], 10, 2), 7, 0, STR_PAD_LEFT); // 温度告警门限,取值范围0~126,
  960. $is_speeding = $arr['is_speeding']; // 超速告警开启设置。1:超速告警开启;0:超速告警关闭
  961. $speeding = str_pad(base_convert($arr['speeding'] * 2, 10, 2), 7, 0, STR_PAD_LEFT); // 超速告警门限 量化单位2km/h,范围 0~126
  962. $motion_position_sampling_interval = $arr['motion_position_sampling_interval']; // 运动状态,位置采样间隔设置(默认1秒)
  963. $motion_position_reporting_interval = $arr['motion_position_reporting_interval']; // 运动状态,位置上报间隔设置
  964. $static_position_reporting_interval = $arr['static_position_reporting_interval']; // 静止状态,位置上报间隔设置
  965. $msg_id = self::getMsgId();
  966. $body = [
  967. $msg_id,
  968. str_pad(base_convert($motion_position_sampling_interval, 10, 16), 2, 0, STR_PAD_LEFT),// 运动状态,位置采样间隔设置(默认1秒)
  969. str_pad(base_convert($motion_position_reporting_interval, 10, 16), 2, 0, STR_PAD_LEFT),// 运动状态,位置上报间隔设置
  970. str_pad(base_convert($static_position_reporting_interval, 10, 16), 4, 0, STR_PAD_LEFT),// 静止状态,位置上报间隔设置
  971. str_pad(base_convert($displacement_radius . $is_displacement, 2, 16), 2, 0, STR_PAD_LEFT),// 位移告警
  972. str_pad(base_convert('0000000' . $is_shock, 2, 16), 2, 0, STR_PAD_LEFT),// 震动告警
  973. str_pad(base_convert($temperature . $is_temperature, 2, 16), 2, 0, STR_PAD_LEFT),// 温度告警
  974. str_pad(base_convert($speeding . $is_speeding, 2, 16), 2, 0, STR_PAD_LEFT),// 超速告警
  975. str_pad(base_convert($auto_lock_time . $is_auto_lock, 2, 16), 2, 0, STR_PAD_LEFT),// 自动落锁
  976. str_pad(base_convert($port, 10, 16), 4, 0, STR_PAD_LEFT),// 自动落锁
  977. str_pad(base_convert($ip, 10, 16), 8, 0, STR_PAD_LEFT),// 自动落锁
  978. str_pad($bluetooth_name, 10, 0, STR_PAD_LEFT),
  979. str_pad(base_convert($bluetooth_token, 10, 16), 8, 0, STR_PAD_LEFT),// 自动落锁
  980. '00 00 00 00 00 00'
  981. ];
  982. $send_msg = self::makeSendMsg($cmd, $body);
  983. return self::send($box_no, $send_msg, $msg_id);
  984. }
  985. public static function setBoxSetting($box_no, $arr)
  986. {
  987. $cmd = "2C";
  988. $auto_lock_time = str_pad(base_convert($arr['auto_lock_time'], 10, 2), 7, 0, STR_PAD_LEFT); // 自动落锁时长,量化单位1分钟
  989. $ipArr = explode('.', $arr['ip']);
  990. $ip =
  991. $msg_id = self::getMsgId();
  992. $body = [
  993. $msg_id,
  994. 'FF',// 运动状态,位置采样间隔设置(默认1秒)
  995. str_pad(base_convert($arr['motion_position_reporting_interval'], 10, 16), 2, 0, STR_PAD_LEFT),// 运动状态,位置上报间隔设置
  996. str_pad(base_convert($arr['static_position_reporting_interval'], 10, 16), 4, 0, STR_PAD_LEFT),// 静止状态,位置上报间隔设置
  997. 'FF',// 位移告警
  998. 'FF',// 震动告警
  999. 'FF',// 温度告警
  1000. 'FF',// 超速告警
  1001. str_pad(base_convert($auto_lock_time . '1', 2, 16), 2, 0, STR_PAD_LEFT),// 自动落锁
  1002. 'FF FF',
  1003. //str_pad(base_convert($arr['port'], 10, 16), 4, 0, STR_PAD_LEFT),// port
  1004. 'FF FF FF FF',
  1005. // str_pad(base_convert($arr['ip'], 10, 16), 8, 0, STR_PAD_LEFT),// ip
  1006. 'FF FF FF FF FF FF FF FF FF FF',// 20位
  1007. 'FF FF FF FF ',//
  1008. 'FF FF FF FF FF FF'
  1009. ];
  1010. $send_msg = self::makeSendMsg($cmd, $body);
  1011. // Log::info($send_msg);
  1012. return self::send($box_no, $send_msg, $msg_id);
  1013. }
  1014. /**
  1015. * reboot 重启中控
  1016. *
  1017. * @param $box_no
  1018. * @param $reboot string 11:重启升级;01:重启不升级
  1019. * @param $ip string 重启升级地址(域名或IP地址)
  1020. * @param $port int 重启升级端口号
  1021. * @param $path string 重启升级路径
  1022. * @param $upFile string 重启升级文件名称
  1023. * @return bool
  1024. * @author Fx
  1025. *
  1026. */
  1027. public static function reboot($box_no, $reboot = "01", $ip, $port, $path, $upFile)
  1028. {
  1029. $cmd = "25";
  1030. $reboot = '000000' . $reboot; // 11:重启升级;01:重启不升级
  1031. $msg_id = self::getMsgId();
  1032. $body = [
  1033. $msg_id,
  1034. self::str2Hex($reboot, 2, 8),
  1035. self::char2Hex($ip, 20),
  1036. self::str2Hex($port, 10, 8),
  1037. self::char2Hex($path, 20),
  1038. self::char2Hex($upFile, 20),
  1039. ];
  1040. $send_msg = self::makeSendMsg($cmd, $body);
  1041. return self::send($box_no, $send_msg, $msg_id);
  1042. }
  1043. /**
  1044. * nowBikeBatteryMSG 从定位包中获取电量
  1045. *
  1046. * @param $box_no
  1047. * @return bool
  1048. * @author Fx
  1049. *
  1050. */
  1051. public static function nowBikeBatteryMSG($box_no)
  1052. {
  1053. return self::nowBikeLocation($box_no);
  1054. }
  1055. public static function rebootBox($box_no)
  1056. {
  1057. $cmd = "25";
  1058. $msg_id = self::getMsgId();
  1059. $body = [
  1060. $msg_id,
  1061. '01',// 0X02:重启升级;0X01:重启不升级
  1062. 'FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF',// ip 20 bytes
  1063. 'FF FF FF FF FF FF FF FF FF FF ', // PORT 10 BYTES
  1064. 'FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF', // 重启升级路径
  1065. 'FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF', // 重启升级文件名称
  1066. ];
  1067. $send_msg = self::makeSendMsg($cmd, $body);
  1068. return self::send($box_no, $send_msg, $msg_id);
  1069. }
  1070. public static function maxecuspeedToMaxspeedpercent($maxecuspeed = 7)
  1071. {
  1072. $MAXSPEEDPERCENT = 100;
  1073. switch ($maxecuspeed) {
  1074. case 1:
  1075. $MAXSPEEDPERCENT = 70;
  1076. break;
  1077. case 2:
  1078. $MAXSPEEDPERCENT = 75;
  1079. break;
  1080. case 3:
  1081. $MAXSPEEDPERCENT = 80;
  1082. break;
  1083. case 4:
  1084. $MAXSPEEDPERCENT = 85;
  1085. break;
  1086. case 5:
  1087. $MAXSPEEDPERCENT = 90;
  1088. break;
  1089. case 6:
  1090. $MAXSPEEDPERCENT = 95;
  1091. break;
  1092. case 7:
  1093. $MAXSPEEDPERCENT = 100;
  1094. break;
  1095. }
  1096. return $MAXSPEEDPERCENT;
  1097. }
  1098. /**
  1099. * settingVoice 语音设置
  1100. *
  1101. * @param $box_no
  1102. * @param $voice_no
  1103. * @param $ip
  1104. * @param $port
  1105. * @param $path
  1106. * @param $upFile
  1107. * @return bool
  1108. * @author Fx
  1109. *
  1110. */
  1111. public static function settingVoice($box_no, $voice_no, $ip, $port, $path, $upFile)
  1112. {
  1113. $cmd = "2A";
  1114. $msg_id = self::getMsgId();
  1115. $body = [
  1116. $msg_id,
  1117. '00',
  1118. self::str2Hex($voice_no, 10, 2),
  1119. self::char2Hex($ip, 20),
  1120. self::str2Hex($port, 10, 8),
  1121. self::char2Hex($path, 20),
  1122. self::char2Hex($upFile, 20),
  1123. ];
  1124. $send_msg = self::makeSendMsg($cmd, $body);
  1125. return self::send($box_no, $send_msg, $msg_id);
  1126. }
  1127. /**
  1128. * guardSwitch 3.2.7 防盗开关设置
  1129. *
  1130. * @param $box_no
  1131. * @param $control 00:关闭 01:开启
  1132. * @return bool
  1133. * @author Fx
  1134. *
  1135. */
  1136. public static function guardSwitch($box_no, $control)
  1137. {
  1138. $cmd = "2E";
  1139. $msg_id = self::getMsgId();
  1140. $body = [
  1141. $msg_id,
  1142. $control
  1143. ];
  1144. $send_msg = self::makeSendMsg($cmd, $body);
  1145. return self::send($box_no, $send_msg, $msg_id);
  1146. }
  1147. /**
  1148. * batterySwitch 3.2.8 电池仓开关设置
  1149. *
  1150. * @param $box_no
  1151. * @return bool
  1152. * @author Fx
  1153. *
  1154. */
  1155. public static function openBatteryLock($box_no)
  1156. {
  1157. $cmd = "2F";
  1158. $msg_id = self::getMsgId();
  1159. $body = [
  1160. $msg_id,
  1161. '01',
  1162. ];
  1163. $send_msg = self::makeSendMsg($cmd, $body);
  1164. return self::send($box_no, $send_msg, $msg_id);
  1165. }
  1166. /**
  1167. * limitSpeed 限速
  1168. *
  1169. * @param $box_no
  1170. * @param $limit int 限速[%]
  1171. * @return bool
  1172. * @author Fx
  1173. *
  1174. */
  1175. public static function limitSpeed($box_no, $limit)
  1176. {
  1177. $cmd = "30";
  1178. $body = [
  1179. self::getMsgId(),
  1180. self::str2Hex($limit, 10, 2),// 限速[%]
  1181. ];
  1182. $send_msg = self::makeSendMsg($cmd, $body);
  1183. return self::send($box_no, $send_msg, false);
  1184. }
  1185. /**
  1186. * undervoltageProtection 3.2.10 控制器欠压保护设置
  1187. *
  1188. * @param $box_no
  1189. * @param $limit int 控制器欠压保护值,量单位1mv
  1190. * @return bool
  1191. * @author Fx
  1192. *
  1193. */
  1194. public static function undervoltageProtection($box_no, $limit)
  1195. {
  1196. $cmd = "31";
  1197. $body = [
  1198. self::getMsgId(),
  1199. self::str2Hex($limit, 10, 4),// 限速[%]
  1200. ];
  1201. $send_msg = self::makeSendMsg($cmd, $body);
  1202. return self::send($box_no, $send_msg, false);
  1203. }
  1204. /**
  1205. * currentLimitingProtection 3.2.11 控制器限流保护设置
  1206. *
  1207. * @param $box_no
  1208. * @param $limit int 控制器限流保护值,量化单位1mA
  1209. * @return bool
  1210. * @author Fx
  1211. *
  1212. */
  1213. public static function currentLimitingProtection($box_no, $limit)
  1214. {
  1215. $cmd = "32";
  1216. $body = [
  1217. self::getMsgId(),
  1218. self::str2Hex($limit, 10, 4),//
  1219. ];
  1220. $send_msg = self::makeSendMsg($cmd, $body);
  1221. return self::send($box_no, $send_msg, false);
  1222. }
  1223. /**
  1224. * slowReboot 3.2.12 控制器缓启动设置
  1225. *
  1226. * @param $box_no
  1227. * @param $control string 01,缓启动;00,快启动
  1228. * @return bool
  1229. * @author Fx
  1230. *
  1231. */
  1232. public static function slowReboot($box_no, $control)
  1233. {
  1234. $cmd = "33";
  1235. $body = [
  1236. self::getMsgId(),
  1237. $control,
  1238. ];
  1239. $send_msg = self::makeSendMsg($cmd, $body);
  1240. return self::send($box_no, $send_msg, false);
  1241. }
  1242. /**
  1243. * lampSwitch 3.2.13 控制器大灯设置
  1244. *
  1245. * @param $box_no
  1246. * @param $control string 01,大灯开;00,大灯关
  1247. * @return bool
  1248. * @author Fx
  1249. *
  1250. */
  1251. public static function lampSwitch($box_no, $control)
  1252. {
  1253. $cmd = "34";
  1254. $body = [
  1255. self::getMsgId(),
  1256. $control,
  1257. ];
  1258. $send_msg = self::makeSendMsg($cmd, $body);
  1259. return self::send($box_no, $send_msg, false);
  1260. }
  1261. /**
  1262. * orderStatus
  1263. *
  1264. * @param $box_no
  1265. * @param $control string 01:接单开启;00:接单关闭
  1266. * @return bool
  1267. * @author Fx
  1268. *
  1269. */
  1270. public static function orderStatus($box_no, $control)
  1271. {
  1272. $cmd = "35";
  1273. $body = [
  1274. self::getMsgId(),
  1275. $control,
  1276. ];
  1277. $send_msg = self::makeSendMsg($cmd, $body);
  1278. return self::send($box_no, $send_msg, false);
  1279. }
  1280. /**
  1281. * nowBikeLocation 立即定位
  1282. *
  1283. * @param $box_no
  1284. * @return bool
  1285. * @author Fx
  1286. *
  1287. */
  1288. public static function nowBikeLocation($box_no)
  1289. {
  1290. return self::queryCmd($box_no, '00000001');
  1291. }
  1292. /**
  1293. * openLock 开锁
  1294. *
  1295. * @param $box_no
  1296. * @return bool
  1297. * @author Fx
  1298. *
  1299. */
  1300. public static function openLock($box_no)
  1301. {
  1302. $re = self::electricSwitchControl($box_no, '01');
  1303. if ($re) {
  1304. self::orderStatus($box_no, '01');
  1305. self::playVoice($box_no, self::VIDEO_OPEN_LOCK);
  1306. return true;
  1307. }
  1308. return false;
  1309. }
  1310. /**
  1311. * closeLock 关锁 (设防)
  1312. *
  1313. * @param $box_no
  1314. * @return bool
  1315. * @author Fx
  1316. *
  1317. */
  1318. public static function closeLock($box_no)
  1319. {
  1320. $re = self::electricSwitchControl($box_no, '02');
  1321. if ($re) {
  1322. self::orderStatus($box_no, '00');
  1323. self::playVoice($box_no, self::VIDEO_RETURN_BIKE);
  1324. return true;
  1325. }
  1326. return false;
  1327. }
  1328. /**
  1329. * closeLock 临时关锁 (设防)
  1330. *
  1331. * @param $box_no
  1332. * @return bool
  1333. * @author Fx
  1334. *
  1335. */
  1336. public static function temporaryCloseLock($box_no)
  1337. {
  1338. self::electricSwitchControl($box_no, '02');
  1339. return self::playVoice($box_no, self::VIDEO_FIND_BIKE);
  1340. }
  1341. /**
  1342. * temporaryOpnLock 临时开锁
  1343. *
  1344. * @param $box_no
  1345. * @return bool
  1346. * @author Fx
  1347. *
  1348. */
  1349. public static function temporaryOpnLock($box_no)
  1350. {
  1351. self::electricSwitchControl($box_no, '01');
  1352. return self::playVoice($box_no, self::VIDEO_KEEP_GOING);
  1353. }
  1354. /**
  1355. * closeLockNoGuard 关锁 (不设防) 失能
  1356. *
  1357. * @param $box_no
  1358. * @return bool
  1359. * @author Fx
  1360. *
  1361. */
  1362. public static function outAreaLoseElectric($box_no)
  1363. {
  1364. self::electricSwitchControl($box_no, '00');
  1365. return self::playVoice($box_no, self::VIDEO_GO_BEYOND);
  1366. }
  1367. /**
  1368. * outAreaGetElectric 开锁 获能
  1369. *
  1370. * @param $box_no
  1371. * @return bool
  1372. * @author Fx
  1373. *
  1374. */
  1375. public static function outAreaGetElectric($box_no)
  1376. {
  1377. self::electricSwitchControl($box_no, '01');
  1378. return self::playVoice($box_no, self::VIDEO_KEEP_GOING);
  1379. }
  1380. /**
  1381. * 寻铃
  1382. * @param $box_no
  1383. * @return bool
  1384. * Author: Mead
  1385. */
  1386. public static function bellBike($box_no)
  1387. {
  1388. return self::playVoice($box_no, self::VIDEO_BIKE_HERE, true);
  1389. }
  1390. public static function queryConfig($box_no, $str2 = '00000100')
  1391. {
  1392. $cmd = "2B";
  1393. $msg_id = self::getMsgId();
  1394. $body = [
  1395. $msg_id,
  1396. str_pad(base_convert($str2, 2, 16), 2, 0, STR_PAD_LEFT)
  1397. ];
  1398. $send_msg = self::makeSendMsg($cmd, $body, $msg_id);
  1399. return self::send($box_no, $send_msg, $msg_id);
  1400. }
  1401. /**
  1402. * 解析车辆返回数据
  1403. * @param $data
  1404. * @return bool|mixed
  1405. */
  1406. public static function decodeData($data, $decode = true)
  1407. {
  1408. $array = explode('||', $data);
  1409. if (count($array) !== 2) return false;
  1410. list($type, $value) = $array;
  1411. if (!$decode) return $value;
  1412. switch ($type) {
  1413. case 'string':
  1414. return $value;
  1415. break;
  1416. case 'bool':
  1417. return (boolean)$data;
  1418. break;
  1419. case 'array':
  1420. return json_decode($value);
  1421. }
  1422. return false;
  1423. }
  1424. /**
  1425. * 获取序号(msg_id)
  1426. * @return string
  1427. * Author: Mead
  1428. */
  1429. private static function getMsgId()
  1430. {
  1431. $msg_id = str_pad(dechex(rand(0, 65535)), 4, "0", STR_PAD_LEFT);
  1432. return $msg_id;
  1433. }
  1434. /**
  1435. * str2Hex 其他进制转16进制
  1436. *
  1437. * @param $str string 需要转的数据
  1438. * @param $frombase int 需要转的进制
  1439. * @param $pad_length int 长度
  1440. * @return string
  1441. * @author Fx
  1442. *
  1443. */
  1444. private static function str2Hex($str, $frombase, $pad_length)
  1445. {
  1446. return str_pad(base_convert($str, $frombase, 16), $pad_length, 0, STR_PAD_LEFT);
  1447. }
  1448. /**
  1449. * char2Hex char 转16进制
  1450. *
  1451. * @param $char
  1452. * @param $pad_length
  1453. * @return string
  1454. * @author Fx
  1455. *
  1456. */
  1457. private static function char2Hex($char, $pad_length)
  1458. {
  1459. return str_pad(bin2hex($char), $pad_length, 0, STR_PAD_LEFT);
  1460. }
  1461. public static function getBikeResponse($box_no, $msg_id, $decode = true)
  1462. {
  1463. $redis = Redis::connection();
  1464. $response = false;
  1465. for ($i = 1; $i <= 30; $i++) {
  1466. usleep(500000);
  1467. $data = $redis->get(self::CACHE_KEY . ':' . $box_no . ':' . $msg_id);
  1468. if ($data) {
  1469. $response = self::decodeData($data, $decode);
  1470. break;
  1471. }
  1472. }
  1473. return $response;
  1474. }
  1475. /**
  1476. * 发送数据
  1477. * @param $box_no
  1478. * @param $msg
  1479. * @return bool
  1480. * User: Mead
  1481. */
  1482. private static function send($box_no, $msg, $msg_id = false, $decode = true)
  1483. {
  1484. Gateway::$registerAddress = config('bike.bike_control_register_address');
  1485. if (Gateway::isUidOnline($box_no)) {
  1486. Gateway::sendToUid($box_no, '+NNMI,' . hex2bin(str_replace(' ', '', $msg . '0D0A')));
  1487. if ($msg_id !== false) {
  1488. $redis = Redis::connection();
  1489. $response = false;
  1490. $msg_id = strtolower(substr($msg, 6, 4));
  1491. for ($i = 1; $i <= 40; $i++) {
  1492. usleep(500000);
  1493. $data = $redis->get(self::CACHE_KEY . ':' . $box_no . ':' . $msg_id);
  1494. if ($data) {
  1495. Log::error('检查key:' . $msg_id);
  1496. Log::error($data);
  1497. $response = self::decodeData($data, $decode);
  1498. break;
  1499. }
  1500. if ($i == 20) {
  1501. //重试一次
  1502. Gateway::sendToUid($box_no, '+NNMI,' . hex2bin(str_replace(' ', '', $msg . '0D0A')));
  1503. }
  1504. }
  1505. return $response;
  1506. }
  1507. return true;
  1508. }
  1509. return false;
  1510. }
  1511. /**
  1512. * 组装命令
  1513. * @param $cmd
  1514. * @param $msgID
  1515. * @return string
  1516. * User: Mead
  1517. */
  1518. private static function makeSendMsg($cmd, $body, $msg_id = false, $length = false)
  1519. {
  1520. if (is_array($body)) {
  1521. $body = self::arr2arr($body);
  1522. }
  1523. if (is_string($body)) {
  1524. $body = str_split($body, 2);
  1525. }
  1526. if ($length !== false) {
  1527. $length = str_pad($length, 4, '0', STR_PAD_LEFT);
  1528. } else {
  1529. $length = str_pad(dechex(count($body)), 4, '0', STR_PAD_LEFT);
  1530. }
  1531. if ($msg_id === false) {
  1532. $msg_id = self::getMsgId();
  1533. }
  1534. $header = [
  1535. $cmd,
  1536. $msg_id,
  1537. '00',
  1538. $length
  1539. ];
  1540. $response = self::formatArr($header, $body);
  1541. $response[] = self::verification($response);
  1542. return self::format(self::$start . implode('', $response));
  1543. }
  1544. /**
  1545. * 校检
  1546. * @param $data
  1547. * @param $verification
  1548. * @return bool
  1549. * Author: Mead
  1550. */
  1551. protected static function verification($data)
  1552. {
  1553. $a = $b = 0;
  1554. for ($i = 0; $i < count($data); $i++) {
  1555. $a = $a + hexdec($data[$i]);
  1556. $b = $a + $b;
  1557. }
  1558. return str_pad(substr(dechex($a), -2), 2, 0, STR_PAD_LEFT) . str_pad(substr(dechex($b), -2), 2, 0, STR_PAD_LEFT);
  1559. }
  1560. /**
  1561. * 格式数组
  1562. * @param $arr
  1563. * @return array
  1564. * User: Mead
  1565. */
  1566. private static function arr2arr($arr)
  1567. {
  1568. $arr = implode('', $arr);
  1569. return str_split(str_replace(' ', '', $arr), 2);
  1570. }
  1571. /**
  1572. * 合并数组
  1573. * @return array
  1574. * User: Mead
  1575. */
  1576. private static function formatArr()
  1577. {
  1578. $args = func_get_args();
  1579. $arr = '';
  1580. foreach ($args as $arg) {
  1581. $arr .= implode('', $arg);
  1582. }
  1583. return str_split($arr, 2);
  1584. }
  1585. /**
  1586. * 格式字符
  1587. * @param $str
  1588. * @return string
  1589. * User: Mead
  1590. */
  1591. private static function format($str)
  1592. {
  1593. return strtoupper(implode('', str_split(str_replace(' ', '', $str), 2)));
  1594. }
  1595. /**
  1596. * 10 进制转 16
  1597. */
  1598. private static function decToHex($hex)
  1599. {
  1600. return str_pad(base_convert($hex, 10, 16), 2, 0, STR_PAD_LEFT);
  1601. }
  1602. }