123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- #!/usr/bin/env python
- # -*- encoding: utf-8 -*-
- from widget.bms_hard import Win_Hard
- from utils.globalvar import SD
- from utils.qt import QDateTime
- import decimal
- class BmsHardControll:
- def __init__(self):
- self._view = Win_Hard()
- self.i = 0
- self.init()
- def init(self):
- self._view.rtc_update_signal.connect(self._rtc_time_update)
- self._view.read_hard_signal.connect(self._read_hard)
- self._view.exit_hard_signal.connect(self._exit_hard)
- self._view.pack_vol_cali_signal.connect(self._vol_cali)
- self._view.cur_cali_signal.connect(self._cur_cali)
- self._view.cell_vol_one_cali_signal.connect(self._cell_one)
- self._view.cell_vol_all_cali_signal.connect(self._cell_all)
- self._view.temp_control_signal.connect(self._temp_ctl)
-
- def _rtc_time_update(self):
- text = QDateTime.currentDateTime().toString("yy MM dd HH mm ss")
- time_str = text.split(" ")
- try:
- data = []
- if len(data) < 8:
- data += (8 - len(data)) * [0]
- data[0] = 0x05
- data[1] = 0xB0
- data[2] = int(time_str[0])
- data[3] = int(time_str[1])
- data[4] = int(time_str[2])
- data[5] = int(time_str[3])
- data[6] = int(time_str[4])
- data[7] = int(time_str[5])
- msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
- except:
- self._view.can_connect_error()
- def _read_hard(self):
- try:
- data = []
- if len(data) < 8:
- data += (8 - len(data)) * [0]
- data[0] = 0xFF
- data[1] = 0xFF
- data[2] = 0xBB
- data[6] = self.i
- self.i = self.i + 1
- if self.i == 255:
- self.i = 0
- data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
- msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
- data[0] = 2
- data[2] = 0
- data[6] = self.i
- self.i = self.i + 1
- if self.i == 255:
- self.i = 0
- data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
- msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
- except:
- self._view.can_connect_error()
- def _exit_hard(self):
- try:
- data = []
- if len(data) < 8:
- data += (8 - len(data)) * [0]
- data[0] = 3
- data[1] = 0xFF
- data[6] = self.i
- self.i = self.i + 1
- if self.i == 255:
- self.i = 0
- data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
- msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
- except:
- self._view.can_connect_error()
- def _vol_cali(self):
- try:
- value = decimal.Decimal(self._view.vol_table.cellWidget(0, 2).text()) * decimal.Decimal(10)
- data = []
- if len(data) < 8:
- data += (8 - len(data)) * [0]
- data[0] = 0xB000 & 0xFF
- data[1] = 0xB000 >> 8
- data[2] = int(value) & 0xFF
- data[3] = int(value) >> 8
- msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
- value = decimal.Decimal(self._view.vol_table.cellWidget(1, 2).text()) * decimal.Decimal(10)
- data = []
- if len(data) < 8:
- data += (8 - len(data)) * [0]
- data[0] = 0xB001 & 0xFF
- data[1] = 0xB001 >> 8
- data[2] = int(value) & 0xFF
- data[3] = int(value) >> 8
- msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
- value = decimal.Decimal(self._view.vol_table.cellWidget(1, 2).text()) * decimal.Decimal(10)
- data = []
- if len(data) < 8:
- data += (8 - len(data)) * [0]
- data[0] = 0xB002 & 0xFF
- data[1] = 0xB002 >> 8
- data[2] = int(value) & 0xFF
- data[3] = int(value) >> 8
- msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
- except:
- self._view.can_connect_error()
- def _cur_cali(self):
- try:
- value = decimal.Decimal(self._view.qline_cali_fbl.text()) * decimal.Decimal(1000)
- data = []
- if len(data) < 8:
- data += (8 - len(data)) * [0]
- data[0] = 0xB003 & 0xFF
- data[1] = 0xB003 >> 8
- data[2] = int(value) & 0xFF
- data[3] = int(value) >> 8
- msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
- value = decimal.Decimal(self._view.qline_cur_offset.text()) * decimal.Decimal(10)
- data = []
- if len(data) < 8:
- data += (8 - len(data)) * [0]
- data[0] = 0xB004 & 0xFF
- data[1] = 0xB004 >> 8
- data[2] = int(value) & 0xFF
- data[3] = int(value) >> 8
- msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
- except:
- self._view.can_connect_error()
- def _cell_one(self):
- current_onclick_index = self._view.hard_table.currentRow()
- if current_onclick_index == -1:
- self._view.data_error()
- return
- if (self._view.hard_table.item(current_onclick_index, 3).text() == '0') | (self._view.hard_table.item(current_onclick_index, 3).text() == ''):
- self._view.data_error()
- return
- try:
- self._view.set_diff(current_onclick_index)
- data = []
- if len(data) < 8:
- data += (8 - len(data)) * [0]
- data[0] = (0xB111 + current_onclick_index) & 0xFF
- data[1] = (0xB111 + current_onclick_index) >> 8
- data[2] = self._view.cb_bmu_index.currentIndex() + 1
- data[3] = int(self._view.hard_table.item(current_onclick_index, 4).text()) & 0xFF
- data[4] = int(self._view.hard_table.item(current_onclick_index, 4).text()) >> 8
- msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
- except:
- self._view.can_connect_error()
- def _cell_all(self):
- try:
- data = []
- if len(data) < 8:
- data += (8 - len(data)) * [0]
- data[0] = 0xB110 & 0xFF
- data[1] = 0xB110 >> 8
- data[2] = self._view.cb_bmu_index.currentIndex() + 1
- data[3] = int(self._view.edt_cell.text()) & 0xFF
- data[4] = int(self._view.edt_cell.text()) >> 8
- msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
- except:
- self._view.can_connect_error()
- def _temp_ctl(self, cmu_id, cell_id, state):
- try:
- data = []
- if len(data) < 8:
- data += (8 - len(data)) * [0]
- data[0] = 0x05 + int(cell_id/8)
- data[1] = 0xC0
- data[2] = cmu_id
- data[3] = ((1 if (state > 0) else 0) << int(cell_id % 8)) & 0xFF
- msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
- except:
- self._view.can_connect_error()
|