BoxUpgradeServer.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. class BoxUpgradeServer extends BaseServer
  10. {
  11. public function main($body)
  12. {
  13. $data = $this->decode($body);
  14. self::log($data, 'BoxUpgradeServer', self::$LOG_MAJOR);
  15. return $this->response();
  16. }
  17. const RESPONSE_SUCCESS = '01';
  18. const RESPONSE_FAIL = '00';
  19. protected function response($response_status = self::RESPONSE_FAIL)
  20. {
  21. $body = [
  22. $response_status
  23. ];
  24. $body = str_split(implode('', $body), 2);
  25. return $body;
  26. }
  27. /**
  28. * 解析装载的数据
  29. * @param $body
  30. * @return array
  31. * User: Mead
  32. */
  33. private function decode($body)
  34. {
  35. $i = 0;
  36. $box_no = self::stitching($body, $i, 5);
  37. $i += 5;
  38. // 客户代码
  39. $code = self::stitching($body, $i, 2);
  40. // 客户型号
  41. $i += 2;
  42. // 硬件型号
  43. $i += 2;
  44. // 需下载固件版本号
  45. $i += 3;
  46. // 固件类型
  47. $i += 1;
  48. // 分块机制
  49. $i += 1;
  50. // 数据块编号
  51. $i += 2;
  52. // 处理值
  53. $box_no = $this->decodeBoxNo($box_no);
  54. return [
  55. 'box_no' => $box_no,
  56. 'code' => $code
  57. ];
  58. }
  59. }