BoxSelectCmdServer.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Mead
  5. * Date: 2019/9/3
  6. * Time: 8:05 PM
  7. */
  8. namespace App\Servers;
  9. use App\Maps\SettingCmdMap;
  10. use App\Models\BatteryTraitModel;
  11. use App\Models\CacheLogTraitModel;
  12. class BoxSelectCmdServer extends BaseServer
  13. {
  14. use CacheLogTraitModel, BatteryTraitModel;
  15. public function main($body)
  16. {
  17. $data = $this->decode($body);
  18. $this->cacheLog($data['msg_id'], $data['setting']);
  19. self::log($data, 'BoxSelectCmdServer', self::$LOG_MAJOR);
  20. return false;
  21. }
  22. /**
  23. * 解析装载的数据
  24. * @param $body
  25. * @return array
  26. * User: Mead
  27. */
  28. private function decode($body)
  29. {
  30. $arr = explode(BikeControl::SPLIT_TAG, implode('', $body));
  31. $setting = $_msg = $msg = '';
  32. if (count($arr) === 2) {
  33. list($setting, $_msg) = explode(BikeControl::SPLIT_TAG, implode('', $body));
  34. } else {
  35. $setting = $arr[0];
  36. }
  37. // $msg = $this->decodeMsgId($_msg);
  38. $setting = $this->decodeSetting($setting);
  39. foreach ($setting as $key => $item) {
  40. switch ($key) {
  41. case SettingCmdMap::SETTING_VIN:
  42. $setting[$key] = $this->byVoltageGetElectric($item / 1000);
  43. break;
  44. case SettingCmdMap::SETTING_ACCFILT:
  45. case SettingCmdMap::SETTING_FDZT:
  46. case SettingCmdMap::SETTING_OILSTATE:
  47. if ($item === 'FAIL') {
  48. $setting[$key] = "获取失败";
  49. } else {
  50. $setting[$key] = $item ? "打开" : "关闭";
  51. }
  52. break;
  53. }
  54. }
  55. return [
  56. 'setting' => $setting,
  57. 'msg_id' => $_msg,
  58. ];
  59. }
  60. }