123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/9/3
- * Time: 8:05 PM
- */
- namespace App\Servers;
- use App\Models\BatteryTraitModel;
- class BatteryServer extends BaseServer
- {
- use BatteryTraitModel;
- /**
- *
- * @param $body
- * @return array
- * User: Mead
- */
- public function main($body)
- {
- $data = $this->decode($body);
- self::log($data, 'BatteryServer', self::$LOG_MAJOR);
- if ($this->is_ep_min($data['box_no'], 'update_battery_box_no', 3)) {
- // 更新电车的电量
- $cols['battery_power'] = $this->byVoltageGetElectric($data['battery_voltage']);
- $cols['is_low_battery_power'] = 1;
- if ($cols['battery_power'] <= self::$max_ride_v) {
- $cols['is_low_battery_power'] = 0;
- }
- $this->db->update('bikes')->where('box_no = ' . $data['box_no'])->cols($cols)->query();
- }
- return $this->response();
- }
- /**
- * 解析装载的数据
- * @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);
- $i += 4;
- // 相对soc
- $battery_xd_soc = self::stitching($body, $i, 1);
- $i += 1;
- // 可用剩余容量
- $battery_mb_free = self::stitching($body, $i, 2);
- $i += 2;
- // 绝对soc
- $battery_jd_soc = self::stitching($body, $i, 1);
- $i += 1;
- // 绝对满电容量
- $i += 2;
- // SOH
- // $battery_soh = self::stitching($body, $i, 1);
- $i += 1;
- // 内部温度
- $i += 2;
- // 实时电流
- $i += 2;
- // 电压
- $battery_voltage = self::stitching($body, $i, 2);
- $i += 2;
- // 循环次数
- $i += 2;
- // 1~7节电池电压
- $i += 14;
- // 8~14节电池电压
- $i += 14;
- // 当前充电间隔时间
- $i += 2;
- // 最大充电间隔时间
- $i += 2;
- // 读写成本条形码
- $i += 16;
- //读版本号
- $i += 2;
- //电池组制造厂名称
- $battery_name = self::stitching($body, $i, 16);
- $i += 16;
- // 处理值
- $box_no = $this->decodeBoxNo($box_no);
- $time = $this->decodeTime($time);
- $battery_voltage = $this->decodeBatteryVoltage($battery_voltage);
- return [
- 'box_no' => $box_no,
- 'time' => $time,
- 'battery_voltage' => $battery_voltage,
- 'battery_name' => $battery_name,
- 'battery_xd_soc' => $battery_xd_soc,
- 'battery_mb_free' => $battery_mb_free,
- 'battery_jd_soc' => $battery_jd_soc,
- ];
- }
- }
|