1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/9/3
- * Time: 8:05 PM
- */
- namespace App\Servers;
- class BoxUpgradeServer extends BaseServer
- {
- public function main($body)
- {
- $data = $this->decode($body);
- self::log($data, 'BoxUpgradeServer', self::$LOG_MAJOR);
- return $this->response();
- }
- const RESPONSE_SUCCESS = '01';
- const RESPONSE_FAIL = '00';
- protected function response($response_status = self::RESPONSE_FAIL)
- {
- $body = [
- $response_status
- ];
- $body = str_split(implode('', $body), 2);
- return $body;
- }
- /**
- * 解析装载的数据
- * @param $body
- * @return array
- * User: Mead
- */
- private function decode($body)
- {
- $i = 0;
- $box_no = self::stitching($body, $i, 5);
- $i += 5;
- // 客户代码
- $code = self::stitching($body, $i, 2);
- // 客户型号
- $i += 2;
- // 硬件型号
- $i += 2;
- // 需下载固件版本号
- $i += 3;
- // 固件类型
- $i += 1;
- // 分块机制
- $i += 1;
- // 数据块编号
- $i += 2;
- // 处理值
- $box_no = $this->decodeBoxNo($box_no);
- return [
- 'box_no' => $box_no,
- 'code' => $code
- ];
- }
- }
|