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, ]; } }