123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/9/3
- * Time: 8:05 PM
- */
- namespace App\Servers;
- use App\Models\BatteryTraitModel;
- class BoxSyncServer extends BaseServer
- {
- use BatteryTraitModel;
- public function main($body)
- {
- $data = $this->decode($body);
- self::log($data, 'BoxSyncServer', self::$LOG_MAJOR);
- return $this->response();
- }
- protected function response()
- {
- $time = time();
- $hex_time = dechex($time);
- $body = [
- $hex_time
- ];
- $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;
- // 设备时间
- $time = self::stitching($body, $i, 4);
- // 处理值
- $box_no = $this->decodeBoxNo($box_no);
- $time = $this->decodeTime($time);
- return [
- 'box_no' => $box_no,
- 'time' => $time,
- ];
- }
- }
|