bms_hard_ctl.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. from widget.bms_hard import Win_Hard
  4. from utils.globalvar import SD
  5. from utils.qt import QDateTime
  6. import decimal
  7. class BmsHardControll:
  8. def __init__(self):
  9. self._view = Win_Hard()
  10. self.i = 0
  11. self.init()
  12. def init(self):
  13. self._view.rtc_update_signal.connect(self._rtc_time_update)
  14. self._view.read_hard_signal.connect(self._read_hard)
  15. self._view.exit_hard_signal.connect(self._exit_hard)
  16. self._view.pack_vol_cali_signal.connect(self._vol_cali)
  17. self._view.cur_cali_signal.connect(self._cur_cali)
  18. self._view.cell_vol_one_cali_signal.connect(self._cell_one)
  19. self._view.cell_vol_all_cali_signal.connect(self._cell_all)
  20. self._view.temp_control_signal.connect(self._temp_ctl)
  21. def _rtc_time_update(self):
  22. text = QDateTime.currentDateTime().toString("yy MM dd HH mm ss")
  23. time_str = text.split(" ")
  24. try:
  25. data = []
  26. if len(data) < 8:
  27. data += (8 - len(data)) * [0]
  28. data[0] = 0x05
  29. data[1] = 0xB0
  30. data[2] = int(time_str[0])
  31. data[3] = int(time_str[1])
  32. data[4] = int(time_str[2])
  33. data[5] = int(time_str[3])
  34. data[6] = int(time_str[4])
  35. data[7] = int(time_str[5])
  36. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  37. except:
  38. self._view.can_connect_error()
  39. def _read_hard(self):
  40. try:
  41. data = []
  42. if len(data) < 8:
  43. data += (8 - len(data)) * [0]
  44. data[0] = 0xFF
  45. data[1] = 0xFF
  46. data[2] = 0xBB
  47. data[6] = self.i
  48. self.i = self.i + 1
  49. if self.i == 255:
  50. self.i = 0
  51. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  52. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  53. data[0] = 2
  54. data[2] = 0
  55. data[6] = self.i
  56. self.i = self.i + 1
  57. if self.i == 255:
  58. self.i = 0
  59. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  60. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  61. except:
  62. self._view.can_connect_error()
  63. def _exit_hard(self):
  64. try:
  65. data = []
  66. if len(data) < 8:
  67. data += (8 - len(data)) * [0]
  68. data[0] = 3
  69. data[1] = 0xFF
  70. data[6] = self.i
  71. self.i = self.i + 1
  72. if self.i == 255:
  73. self.i = 0
  74. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  75. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  76. except:
  77. self._view.can_connect_error()
  78. def _vol_cali(self):
  79. try:
  80. value = decimal.Decimal(self._view.vol_table.cellWidget(0, 2).text()) * decimal.Decimal(10)
  81. data = []
  82. if len(data) < 8:
  83. data += (8 - len(data)) * [0]
  84. data[0] = 0xB000 & 0xFF
  85. data[1] = 0xB000 >> 8
  86. data[2] = int(value) & 0xFF
  87. data[3] = int(value) >> 8
  88. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  89. value = decimal.Decimal(self._view.vol_table.cellWidget(1, 2).text()) * decimal.Decimal(10)
  90. data = []
  91. if len(data) < 8:
  92. data += (8 - len(data)) * [0]
  93. data[0] = 0xB001 & 0xFF
  94. data[1] = 0xB001 >> 8
  95. data[2] = int(value) & 0xFF
  96. data[3] = int(value) >> 8
  97. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  98. value = decimal.Decimal(self._view.vol_table.cellWidget(1, 2).text()) * decimal.Decimal(10)
  99. data = []
  100. if len(data) < 8:
  101. data += (8 - len(data)) * [0]
  102. data[0] = 0xB002 & 0xFF
  103. data[1] = 0xB002 >> 8
  104. data[2] = int(value) & 0xFF
  105. data[3] = int(value) >> 8
  106. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  107. except:
  108. self._view.can_connect_error()
  109. def _cur_cali(self):
  110. try:
  111. value = decimal.Decimal(self._view.qline_cali_fbl.text()) * decimal.Decimal(1000)
  112. data = []
  113. if len(data) < 8:
  114. data += (8 - len(data)) * [0]
  115. data[0] = 0xB003 & 0xFF
  116. data[1] = 0xB003 >> 8
  117. data[2] = int(value) & 0xFF
  118. data[3] = int(value) >> 8
  119. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  120. value = decimal.Decimal(self._view.qline_cur_offset.text()) * decimal.Decimal(10)
  121. data = []
  122. if len(data) < 8:
  123. data += (8 - len(data)) * [0]
  124. data[0] = 0xB004 & 0xFF
  125. data[1] = 0xB004 >> 8
  126. data[2] = int(value) & 0xFF
  127. data[3] = int(value) >> 8
  128. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  129. except:
  130. self._view.can_connect_error()
  131. def _cell_one(self):
  132. current_onclick_index = self._view.hard_table.currentRow()
  133. if current_onclick_index == -1:
  134. self._view.data_error()
  135. return
  136. if (self._view.hard_table.item(current_onclick_index, 3).text() == '0') | (self._view.hard_table.item(current_onclick_index, 3).text() == ''):
  137. self._view.data_error()
  138. return
  139. try:
  140. self._view.set_diff(current_onclick_index)
  141. data = []
  142. if len(data) < 8:
  143. data += (8 - len(data)) * [0]
  144. data[0] = (0xB111 + current_onclick_index) & 0xFF
  145. data[1] = (0xB111 + current_onclick_index) >> 8
  146. data[2] = self._view.cb_bmu_index.currentIndex() + 1
  147. data[3] = int(self._view.hard_table.item(current_onclick_index, 4).text()) & 0xFF
  148. data[4] = int(self._view.hard_table.item(current_onclick_index, 4).text()) >> 8
  149. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  150. except:
  151. self._view.can_connect_error()
  152. def _cell_all(self):
  153. try:
  154. data = []
  155. if len(data) < 8:
  156. data += (8 - len(data)) * [0]
  157. data[0] = 0xB110 & 0xFF
  158. data[1] = 0xB110 >> 8
  159. data[2] = self._view.cb_bmu_index.currentIndex() + 1
  160. data[3] = int(self._view.edt_cell.text()) & 0xFF
  161. data[4] = int(self._view.edt_cell.text()) >> 8
  162. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  163. except:
  164. self._view.can_connect_error()
  165. def _temp_ctl(self, cmu_id, cell_id, state):
  166. try:
  167. data = []
  168. if len(data) < 8:
  169. data += (8 - len(data)) * [0]
  170. data[0] = 0x05 + int(cell_id/8)
  171. data[1] = 0xC0
  172. data[2] = cmu_id
  173. data[3] = ((1 if (state > 0) else 0) << int(cell_id % 8)) & 0xFF
  174. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  175. except:
  176. self._view.can_connect_error()