123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace App\Servers;
- use App\Models\BatteryTraitModel;
- class BatteryServer extends BaseServer
- {
- use BatteryTraitModel;
-
- 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();
- }
-
- private function decode($body)
- {
- $i = 0;
- $box_no = self::stitching($body, $i, 5);
- $i += 5;
-
- $time = self::stitching($body, $i, 4);
- $i += 4;
-
- $battery_xd_soc = self::stitching($body, $i, 1);
- $i += 1;
-
- $battery_mb_free = self::stitching($body, $i, 2);
- $i += 2;
-
- $battery_jd_soc = self::stitching($body, $i, 1);
- $i += 1;
-
- $i += 2;
-
- $i += 1;
-
- $i += 2;
-
- $i += 2;
-
- $battery_voltage = self::stitching($body, $i, 2);
- $i += 2;
-
- $i += 2;
-
- $i += 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,
- ];
- }
- }
|