123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/9/5
- * Time: 9:36 PM
- */
- namespace App\Handlers;
- use GatewayClient\Gateway;
- use Illuminate\Support\Facades\Redis;
- class BikeControl
- {
- private static $start = 'AA AA';
- //分割符
- const SPLIT_TAG = 'bbbb';
- // 控制指令
- const CMD_REMOTE_CONTROL = '06';
- // 远程查询
- const CMD_REMOTE_SELECT = '07';
- // 播放语言指令
- const CMD_REMOTE_VOICE = '0C';
- //远程设置参数
- const CMD_REMOTE_CONFIG = '08';
- /**
- * 控制指令(服务器下发)
- */
- //保留
- // const CONTROL_DEFAULT = '00';
- //远程设防(业务关锁)
- const CONTROL_REMOTE_CLOSE_LOCK = '01';
- // 远程撤防
- const CONTROL_REMOTE_CHE_FANG = '02';
- // 远程重启
- const CONTROL_REMOTE_CHONG_QI = '03';
- // 远程关机
- const CONTROL_REMOTE_GUAN_JI = '04';
- // 恢复出差设置
- const CONTROL_HUI_FU_CHU_CHANG = '05';
- // 保留
- // const CONTROL_REMOTE_NO = '06';
- // 保留
- // const CONTROL_REMOTE_NO = '07';
- // 立即定位
- const CONTROL_REMOTE_LOCATION = '08';
- //远程寻车(带寻车提示音)
- const CONTROL_REMOTE_FIND_BIKE = '09';
- // 远程重启蓝牙模块
- const CONTROL_REMOTE_REBOOT_LAN_YA = '0A';
- //远程开锁(业务开锁)
- const CONTROL_REMOTE_UNLOCK = '0B';
- //远程加锁
- const CONTROL_REMOTE_SHUT_UNLOCK = '0C';
- // 主动查询终端电池信息
- const CONTROL_GET_BATTERY_INFO = '0D';
- //主动查询控制器信息
- const CONTROL_GET_BOX_INFO = '0E';
- //远程打开电池锁
- const CONTROL_REMOTE_OPEN_BATTERY_LOCK = '0F';
- //远程关闭电池锁
- const CONTROL_REMOTE_CLOSE_BATTERY_LOCK = '10';
- //关闭远程寻车(待寻车提示音)
- const CONTROL_REMOTE_CLOSE_BELL = '11';
- //远程重启整个系统
- const CONTROL_REMOTE_REBOOT_SYSTEM = '12';
- //远程格式化主控制器
- const CONTROL_REMOTE_FORMAT_BOX = '13';
- //外部USB供电使能
- const CONTROL_REMOTE_USB_OK = '14';
- //外部USB供电失能
- const CONTROL_REMOTE_USB_NO = '15';
- //远程打开轮毂锁
- const CONTROL_REMOTE_OPEN_HUB_LOCK = '16';
- //远程关闭轮毂锁
- const CONTROL_REMOTE_CLOSE_HUB_LOCK = '17';
- // const CONTROL_REMOTE_CLOSE_LOCK = '18';
- //提示终端超出运营区域进行语音播报
- const CONTROL_OUT_AREA_PLAY_VOICE = '19';
- //提示终端进入运营区域关闭语音播放
- const CONTROL_OUT_AREA_CLOSE_VOICE = '1A';
- //出电子围栏直接失能ACC(仅限制在借车状态使用)
- const CONTROL_OUT_AREA_LOST_ELECTRIC = '1B';
- //入电子围栏直接使能ACC(仅限制在借车状态使用)
- const CONTROL_OUT_AREA_OPEN_ELECTRIC = '1C';
- // 打开后座
- const CONTROL_REMOTE_OPEN_BACKSEAT = '20';
- //关闭后座锁
- const CONTROL_REMOTE_CLOSE_BACKSEAT = '21';
- //远程临时关锁
- const CONTROL_REMOTE_TEMPORARY_CLOSE_LOCK = '30';
- //远程临时开锁
- const CONTROL_REMOTE_TEMPORARY_UNLOCK = '31';
- //进入运输模式
- const CONTROL_TRANSPORTATION_MODE = '32';
- //立即上传融合定位包
- const CONTROL_NOW_UP_LOCATION = '33';
- /**
- * 语言指令(警告指令)
- */
- // 警告命令
- const WARNING_SPARE_BATTERY_LOW = '00';
- const WARNING_SHOCK = '01';
- const WARNING_FORCE_OPEN_ELECTRIC = '02';
- const WARNING_OUT_AREA_PLAY_VIDEO = '03';
- const WARNING_BMS = '04';
- const WARNING_STOP_ELECTRIC = '05';
- const WARNING_OVER_SPEED = '06';
- const WARNING_WHEEL_MOVEMENT = '07';
- const WARNING_BIKE_TROUBLE = '08';
- /**
- * 语音指令
- * @var string
- */
- // 欢迎使用共享电单车
- const VIDEO_WELCOME = '01';
- // 没电了,请换一辆车
- const VIDEO_NO_ELECTRIC = '02';
- // 骑出运营区,请尽快返回
- const VIDEO_OUT_AREA = '03';
- // 报警音,车辆未解锁,请扫描骑行
- const VIDEO_WARNING = '04';
- // HI,主人,我在这辆车。
- const VIDEO_BIKE_HERE = '05';
- // 还车成功,欢迎再次使用共享电单车
- const VIDEO_CLOSE_BIKE = '06';
- // 寻车提示音
- const VIDEO_FIND_BIKE = '07';
- // 临时锁车
- const VIDEO_T_CLOSE_BIKE = '08';
- // 当前不在停车点,请在手机查看停车点
- const VIDEO_NO_STOP_SITE = '09';
- // 电池锁已打开
- const VIDEO_BATTERY_OPEN = '0A';
- // 电池锁已关闭
- const VIDEO_BATTERY_CLOSE = '0B';
- // 距离服务区过远,车辆即将断电。
- const VIDEO_OUT_AREA_CLOSE_ELECTRIC = '0C';
- // 已超速,请注意减速慢行
- const VIDEO_OUT_SPEED = '0D';
- // 车铃音
- const VIDEO_BIKE_DELL = '0E';
- const CACHE_KEY = 'cache:select:';
- //查询参数
- const SETTING_VIN = "VIN";
- const SETTING_ACCFILT = "ACCFILT";
- const SETTING_FDZT = "FDZT";
- const SETTING_OILSTATE = "OILSTATE";
- const SETTING_PHASESTATUS = "PHASESTATUS";
- public static $registerAddress = 'node1:1238';
- /**
- * 开车
- * @param $box_no
- * @return bool
- * User: Mead
- */
- public static function openLock($box_no)
- {
- $msg_id = self::makeMsgId($box_no, 'A', self::CONTROL_REMOTE_UNLOCK);
- $str = self::makeSendMsg(self::CONTROL_REMOTE_UNLOCK, $msg_id);
- return self::send($box_no, $str);
- }
- /**
- * 关锁
- * @param $box_no
- * @return bool
- * User: Mead
- */
- public static function closeLock($box_no)
- {
- $msg_id = self::makeMsgId($box_no, 'A', self::CONTROL_REMOTE_CLOSE_LOCK);
- $str = self::makeSendMsg(self::CONTROL_REMOTE_CLOSE_LOCK, $msg_id);
- return self::send($box_no, $str);
- }
- /**
- * 临时关锁
- * @param $box_no
- * @return bool
- * User: Mead
- */
- public static function temporaryCloseLock($box_no)
- {
- $msg_id = self::makeMsgId($box_no, 'A', self::CONTROL_REMOTE_CLOSE_LOCK);
- $str = self::makeSendMsg(self::CONTROL_REMOTE_CLOSE_LOCK, $msg_id);
- return self::send($box_no, $str);
- }
- /**
- * 临时开锁
- * @param $box_no
- * @return bool
- * User: Mead
- */
- public static function temporaryOpnLock($box_no)
- {
- $msg_id = self::makeMsgId($box_no, 'A', self::CONTROL_REMOTE_UNLOCK);
- $str = self::makeSendMsg(self::CONTROL_REMOTE_UNLOCK, $msg_id);
- return self::send($box_no, $str);
- }
- /**
- * 寻车响铃
- * @param $box_no
- * @return bool
- * User: Mead
- */
- public static function bellBike($box_no)
- {
- $msg_id = self::makeMsgId($box_no, 'A', self::CONTROL_REMOTE_FIND_BIKE);
- $str = self::makeSendMsg(self::CONTROL_REMOTE_FIND_BIKE, $msg_id);
- return self::send($box_no, $str);
- }
- /**
- * 打开电池锁
- * @param $box_no
- * @return bool
- * User: Mead
- */
- public static function openBatteryLock($box_no)
- {
- $msg_id = self::makeMsgId($box_no, 'A', self::CONTROL_REMOTE_OPEN_BATTERY_LOCK);
- Redis::connection()->setex("cache:open_battery:{$box_no}", 300, 1);
- $str = self::makeSendMsg(self::CONTROL_REMOTE_OPEN_BATTERY_LOCK, $msg_id);
- return self::send($box_no, $str);
- }
- /**
- * 关闭电池锁
- * @param $box_no
- * @return bool
- * User: Mead
- */
- public static function closeBatteryLock($box_no)
- {
- $msg_id = self::makeMsgId($box_no, 'A', self::CONTROL_REMOTE_CLOSE_BATTERY_LOCK);
- $str = self::makeSendMsg(self::CONTROL_REMOTE_CLOSE_BATTERY_LOCK, $msg_id);
- return self::send($box_no, $str);
- }
- /**
- * 远程重启中控
- * @param $box_no
- * @return bool
- * User: Mead
- */
- public static function rebootBox($box_no)
- {
- $msg_id = self::makeMsgId($box_no, 'A', self::CONTROL_REMOTE_REBOOT_SYSTEM);
- $str = self::makeSendMsg(self::CONTROL_REMOTE_REBOOT_SYSTEM, $msg_id);
- return self::send($box_no, $str);
- }
- /**
- * 立即定位
- * @param $box_no
- * @return bool
- * User: Mead
- */
- public static function nowBikeLocation($box_no)
- {
- $msg_id = self::makeMsgId($box_no, 'A', self::CONTROL_REMOTE_LOCATION);
- //删除ridis位置缓存
- self::delRedisCache($box_no, 'update_bike_location');
- $str = self::makeSendMsg(self::CONTROL_REMOTE_LOCATION, $msg_id);
- return self::send($box_no, $str);
- }
- /**
- * 立即上传电池信息
- * @param $box_no
- * @return bool
- * User: Mead
- */
- public static function nowBikeBatteryMSG($box_no)
- {
- $msg_id = self::makeMsgId($box_no, 'A', self::CONTROL_GET_BATTERY_INFO);
- //删除ridis位置缓存
- self::delRedisCache($box_no, ['heart', 'update_bike_location', 'update_battery_box_no']);
- $str = self::makeSendMsg(self::CONTROL_GET_BATTERY_INFO, $msg_id);
- return self::send($box_no, $str);
- }
- /**
- * 超出骑行区域播放音乐
- * @param $box_no
- * @return bool
- * User: Mead
- */
- public static function outAreaPlayVideo($box_no)
- {
- return self::playVideo($box_no, self::VIDEO_OUT_AREA);
- }
- /**
- * 播放语音
- * @param $box_no
- * @param $video_cmd
- * @return bool
- * User: Mead
- */
- public static function playVideo($box_no, $video_cmd)
- {
- $msg_id = self::makeMsgId($box_no, 'A', $video_cmd);
- $str = self::makeSendMsg($video_cmd, $msg_id, self::CMD_REMOTE_VOICE);
- return self::send($box_no, $str);
- }
- /**
- * 超出骑行区域失能
- * @param $box_no
- * @return bool
- * User: Mead
- */
- public static function outAreaLoseElectric($box_no)
- {
- $msg_id = self::makeMsgId($box_no, 'A', self::CONTROL_OUT_AREA_LOST_ELECTRIC);
- $str = self::makeSendMsg(self::CONTROL_OUT_AREA_LOST_ELECTRIC, $msg_id, self::CMD_REMOTE_CONTROL);
- return self::send($box_no, $str);
- }
- /**
- * 超出区域后返回骑行区域加电
- * @param $box_no
- * @return bool
- * User: Mead
- */
- public static function outAreaGetElectric($box_no)
- {
- $msg_id = self::makeMsgId($box_no, 'A', self::CONTROL_OUT_AREA_OPEN_ELECTRIC);
- $str = self::makeSendMsg(self::CONTROL_OUT_AREA_OPEN_ELECTRIC, $msg_id, self::CMD_REMOTE_CONTROL);
- return self::send($box_no, $str);
- }
- /**
- * 查询车的配置
- * @param $box_no
- * @return bool
- * User: Mead
- */
- public static function downBoxSetting($box_no)
- {
- $msg_id = self::makeMsgId($box_no, 'A', self::CMD_REMOTE_SELECT);
- $setting = ['PULSE', 'SERVER', 'MAXECUSPEED', 'FREQ', 'SOFTVERSION', 'MAXSPEEDPERCENT'];
- $str = self::makeSendMsg($setting, $msg_id, self::CMD_REMOTE_SELECT, false);
- self::send($box_no, $str);
- return self::getBikeResponse($msg_id);
- }
- /**
- * 参数配置
- * @param $box_no
- * @return bool
- * User: Mead
- */
- public static function setBoxSetting($box_no, $setting = [], $is_result = false)
- {
- $msg_id = self::makeMsgId($box_no, 'A', self::CMD_REMOTE_CONFIG);
- $str = self::makeSendMsg($setting, $msg_id, self::CMD_REMOTE_CONFIG, false);
- Gateway::$registerAddress = self::$registerAddress;
- if (!Gateway::isUidOnline($box_no)) return false;
- if (!$is_result) {
- return self::send($box_no, $str);
- }
- self::send($box_no, $str);
- return self::getBikeResponse($msg_id, false);
- }
- /**
- * 查询车的状态
- * @param $box_no
- * @return bool
- * User: Mead
- */
- public static function getBoxStatus($box_no, $setting = [])
- {
- $msg_id = self::makeMsgId($box_no, 'A', self::CMD_REMOTE_SELECT);
- if (count($setting) === 0) return false;
- $str = self::makeSendMsg($setting, $msg_id, self::CMD_REMOTE_SELECT, false);
- self::send($box_no, $str);
- return self::getBikeResponse($msg_id);
- }
- /**
- * 发送数据
- * @param $box_no
- * @param $msg
- * @return bool
- * User: Mead
- */
- private static function send($box_no, $msg)
- {
- Gateway::$registerAddress = self::$registerAddress;
- Gateway::sendToUid($box_no, hex2bin($msg));
- return true;
- }
- /**
- * 生成 msg_id
- * @param $box_no
- * @param $type
- * @param $cmd
- * @return string
- * User: Mead
- */
- private static function makeMsgId($box_no, $type, $cmd)
- {
- $msg = [
- 'no' => $box_no,
- 'time' => time(),
- 'type' => $type,
- 'cmd' => $cmd,
- ];
- $msg_id = bin2hex(implode(',', $msg));
- return $msg_id;
- }
- /**
- * 组装命令
- * @param $cmd
- * @param $msgID
- * @return string
- * User: Mead
- */
- private static function makeSendMsg($controller_cmd, $msgID, $cmd = self::CMD_REMOTE_CONTROL, $is_hex = true)
- {
- if (!$is_hex) {
- $controller_cmd = bin2hex((implode(';', $controller_cmd) . ';FUJIA'));
- }
- $body = [
- "{$controller_cmd}",
- self::SPLIT_TAG . "{$msgID}"
- ];
- $body = self::arr2arr($body);
- return self::encode($body, $cmd);
- }
- /**
- * 效验编码
- * @param $data
- * @return string
- * User: Mead
- */
- private static function encode($data, $cmd)
- {
- $num = 12;
- $num += count($data);
- $data_length = self::byNumGetDataLength($num);
- $header = [
- $data_length,
- self::getSoftwareVersion(),
- $cmd,
- self::getPipelineNumber(),
- '00',
- '00',
- '00'
- ];
- $response = self::arr2str($header, $data);
- $response .= self::crc16(explode(' ', $response));
- return self::format(self::$start . $response);
- }
- /**
- * 获取数据包的长度
- * @param $num
- * @return array
- * User: Mead
- */
- private static function byNumGetDataLength($num)
- {
- $length = dechex($num);
- return str_pad($length, 4, '0', STR_PAD_LEFT);
- }
- /**
- * 删除缓存
- * @param $box_no
- * @param $type
- * User: Mead
- */
- public static function delRedisCache($box_no, $types)
- {
- $cacheNames = [];
- if (is_array($types)) {
- foreach ($types as $type) {
- $cacheNames[] = "cache:min:{$type}:{$box_no}";
- }
- } else {
- $cacheNames[] = "cache:min:{$types}:{$box_no}";
- }
- if (!count($cacheNames)) return false;
- Redis::connection()->del($cacheNames);
- }
- /**
- * 软件版本号
- * @return string
- * User: Mead
- */
- private static function getSoftwareVersion()
- {
- return '04';
- }
- /**
- * 获取流水号
- * @return int
- * User: Mead
- */
- private static function getPipelineNumber()
- {
- return '01';
- }
- /**
- * 格式数组
- * @param $arr
- * @return array
- * User: Mead
- */
- private static function arr2arr($arr)
- {
- $arr = implode('', $arr);
- return str_split(str_replace(' ', '', $arr), 2);
- }
- /**
- * 数组转字符
- * @return string
- * User: Mead
- */
- private static function arr2str()
- {
- $args = func_get_args();
- $arr = '';
- foreach ($args as $arg) {
- $arr .= implode('', $arg);
- }
- return implode(' ', str_split($arr, 2));
- }
- /**
- * 格式字符
- * @param $str
- * @return string
- * User: Mead
- */
- private static function format($str)
- {
- return strtoupper(implode('', str_split(str_replace(' ', '', $str), 2)));
- }
- private static $crc_table = [
- 0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD,
- 0x6536, 0x74BF, 0x8C48, 0x9DC1, 0xAF5A, 0xBED3,
- 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7, 0x1081, 0x0108,
- 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E,
- 0x9CC9, 0x8D40, 0xBFDB, 0xAE52, 0xDAED, 0xCB64,
- 0xF9FF, 0xE876, 0x2102, 0x308B, 0x0210, 0x1399,
- 0x6726, 0x76AF, 0x4434, 0x55BD, 0xAD4A, 0xBCC3,
- 0x8E58, 0x9FD1, 0xEB6E, 0xFAE7, 0xC87C, 0xD9F5,
- 0x3183, 0x200A, 0x1291, 0x0318, 0x77A7, 0x662E,
- 0x54B5, 0x453C, 0xBDCB, 0xAC42, 0x9ED9, 0x8F50,
- 0xFBEF, 0xEA66, 0xD8FD, 0xC974, 0x4204, 0x538D,
- 0x6116, 0x709F, 0x0420, 0x15A9, 0x2732, 0x36BB,
- 0xCE4C, 0xDFC5, 0xED5E, 0xFCD7, 0x8868, 0x99E1,
- 0xAB7A, 0xBAF3, 0x5285, 0x430C, 0x7197, 0x601E,
- 0x14A1, 0x0528, 0x37B3, 0x263A, 0xDECD, 0xCF44,
- 0xFDDF, 0xEC56, 0x98E9, 0x8960, 0xBBFB, 0xAA72,
- 0x6306, 0x728F, 0x4014, 0x519D, 0x2522, 0x34AB,
- 0x0630, 0x17B9, 0xEF4E, 0xFEC7, 0xCC5C, 0xDDD5,
- 0xA96A, 0xB8E3, 0x8A78, 0x9BF1, 0x7387, 0x620E,
- 0x5095, 0x411C, 0x35A3, 0x242A, 0x16B1, 0x0738,
- 0xFFCF, 0xEE46, 0xDCDD, 0xCD54, 0xB9EB, 0xA862,
- 0x9AF9, 0x8B70, 0x8408, 0x9581, 0xA71A, 0xB693,
- 0xC22C, 0xD3A5, 0xE13E, 0xF0B7, 0x0840, 0x19C9,
- 0x2B52, 0x3ADB, 0x4E64, 0x5FED, 0x6D76, 0x7CFF,
- 0x9489, 0x8500, 0xB79B, 0xA612, 0xD2AD, 0xC324,
- 0xF1BF, 0xE036, 0x18C1, 0x0948, 0x3BD3, 0x2A5A,
- 0x5EE5, 0x4F6C, 0x7DF7, 0x6C7E, 0xA50A, 0xB483,
- 0x8618, 0x9791, 0xE32E, 0xF2A7, 0xC03C, 0xD1B5,
- 0x2942, 0x38CB, 0x0A50, 0x1BD9, 0x6F66, 0x7EEF,
- 0x4C74, 0x5DFD, 0xB58B, 0xA402, 0x9699, 0x8710,
- 0xF3AF, 0xE226, 0xD0BD, 0xC134, 0x39C3, 0x284A,
- 0x1AD1, 0x0B58, 0x7FE7, 0x6E6E, 0x5CF5, 0x4D7C,
- 0xC60C, 0xD785, 0xE51E, 0xF497, 0x8028, 0x91A1,
- 0xA33A, 0xB2B3, 0x4A44, 0x5BCD, 0x6956, 0x78DF,
- 0x0C60, 0x1DE9, 0x2F72, 0x3EFB, 0xD68D, 0xC704,
- 0xF59F, 0xE416, 0x90A9, 0x8120, 0xB3BB, 0xA232,
- 0x5AC5, 0x4B4C, 0x79D7, 0x685E, 0x1CE1, 0x0D68,
- 0x3FF3, 0x2E7A, 0xE70E, 0xF687, 0xC41C, 0xD595,
- 0xA12A, 0xB0A3, 0x8238, 0x93B1, 0x6B46, 0x7ACF,
- 0x4854, 0x59DD, 0x2D62, 0x3CEB, 0x0E70, 0x1FF9,
- 0xF78F, 0xE606, 0xD49D, 0xC514, 0xB1AB, 0xA022,
- 0x92B9, 0x8330, 0x7BC7, 0x6A4E, 0x58D5, 0x495C,
- 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78,
- ];
- /**
- * 生成校检码
- * @param $data
- * @return string
- * User: Mead
- */
- private static function crc16($data)
- {
- $crc = 0xFFFF;
- foreach ($data as $d) {
- $d = hexdec($d);
- $crc = self::$crc_table[($d ^ $crc) & 0xFF] ^ ($crc >> 8 & 0xFF);
- }
- $crc = $crc ^ 0xFFFF;
- $crc = $crc & 0xFFFF;
- return str_pad(dechex($crc), 4, '0', STR_PAD_LEFT);
- }
- /**
- * 获取下发命令的返回结果
- * @param $msg_id
- * @param bool $decode
- * @return bool|mixed|string
- */
- public static function getBikeResponse($msg_id, $decode = true)
- {
- $redis = Redis::connection();
- $response = false;
- for ($i = 1; $i <= 30; $i++) {
- sleep(1);
- $data = $redis->get(self::CACHE_KEY . $msg_id);
- if ($data) {
- $response = self::decodeData($data, $decode);
- break;
- }
- }
- return $response;
- }
- /**
- * 解析车辆返回数据
- * @param $data
- * @return bool|mixed
- */
- public static function decodeData($data, $decode = true)
- {
- $array = explode('||', $data);
- if (count($array) !== 2) return false;
- list($type, $value) = $array;
- if (!$decode) return $value;
- switch ($type) {
- case 'string':
- return $value;
- break;
- case 'array':
- return json_decode($value);
- }
- return false;
- }
- /**
- * 速度转速度百分比
- * @param $maxecuspeed
- * @return int
- * Author: Mead
- */
- public static function maxecuspeedToMaxspeedpercent($maxecuspeed = 7)
- {
- $MAXSPEEDPERCENT = 100;
- switch ($maxecuspeed) {
- case 1:
- $MAXSPEEDPERCENT = 70;
- break;
- case 2:
- $MAXSPEEDPERCENT = 75;
- break;
- case 3:
- $MAXSPEEDPERCENT = 80;
- break;
- case 4:
- $MAXSPEEDPERCENT = 85;
- break;
- case 5:
- $MAXSPEEDPERCENT = 90;
- break;
- case 6:
- $MAXSPEEDPERCENT = 95;
- break;
- case 7:
- $MAXSPEEDPERCENT = 100;
- break;
- }
- return $MAXSPEEDPERCENT;
- }
- }
|