bms_hard_ctl.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. def _rtc_time_update(self):
  21. text = QDateTime.currentDateTime().toString("yy MM dd HH mm ss")
  22. time_str = text.split(" ")
  23. print(time_str)
  24. # time_list = [bcd_hex(data) for data in time_str]
  25. try:
  26. data = []
  27. if len(data) < 8:
  28. data += (8 - len(data)) * [0]
  29. data[0] = 0x05
  30. data[1] = 0xB0
  31. data[2] = int(time_str[0])
  32. data[3] = int(time_str[1])
  33. data[4] = int(time_str[2])
  34. data[5] = int(time_str[3])
  35. data[6] = int(time_str[4])
  36. data[7] = int(time_str[5])
  37. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  38. except:
  39. self._view.can_connect_error()
  40. def _read_hard(self):
  41. try:
  42. data = []
  43. if len(data) < 8:
  44. data += (8 - len(data)) * [0]
  45. data[0] = 0xFF
  46. data[1] = 0xFF
  47. data[2] = 0xBB
  48. data[6] = self.i
  49. self.i = self.i + 1
  50. if self.i == 255:
  51. self.i = 0
  52. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  53. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  54. data[0] = 2
  55. data[2] = 0
  56. data[6] = self.i
  57. self.i = self.i + 1
  58. if self.i == 255:
  59. self.i = 0
  60. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  61. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  62. except:
  63. self._view.can_connect_error()
  64. def _exit_hard(self):
  65. try:
  66. data = []
  67. if len(data) < 8:
  68. data += (8 - len(data)) * [0]
  69. data[0] = 3
  70. data[1] = 0xFF
  71. data[6] = self.i
  72. self.i = self.i + 1
  73. if self.i == 255:
  74. self.i = 0
  75. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  76. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  77. except:
  78. self._view.can_connect_error()
  79. def _vol_cali(self):
  80. try:
  81. value = decimal.Decimal(self._view.vol_table.cellWidget(0, 2).text()) * decimal.Decimal(10)
  82. data = []
  83. if len(data) < 8:
  84. data += (8 - len(data)) * [0]
  85. data[0] = 0xB000 & 0xFF
  86. data[1] = 0xB000 >> 8
  87. data[2] = int(value) & 0xFF
  88. data[3] = int(value) >> 8
  89. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  90. value = decimal.Decimal(self._view.vol_table.cellWidget(1, 2).text()) * decimal.Decimal(10)
  91. data = []
  92. if len(data) < 8:
  93. data += (8 - len(data)) * [0]
  94. data[0] = 0xB001 & 0xFF
  95. data[1] = 0xB001 >> 8
  96. data[2] = int(value) & 0xFF
  97. data[3] = int(value) >> 8
  98. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  99. value = decimal.Decimal(self._view.vol_table.cellWidget(1, 2).text()) * decimal.Decimal(10)
  100. data = []
  101. if len(data) < 8:
  102. data += (8 - len(data)) * [0]
  103. data[0] = 0xB002 & 0xFF
  104. data[1] = 0xB002 >> 8
  105. data[2] = int(value) & 0xFF
  106. data[3] = int(value) >> 8
  107. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  108. except:
  109. self._view.can_connect_error()
  110. def _cur_cali(self):
  111. try:
  112. value = decimal.Decimal(self._view.qline_cali_fbl.text()) * decimal.Decimal(1000)
  113. data = []
  114. if len(data) < 8:
  115. data += (8 - len(data)) * [0]
  116. data[0] = 0xB003 & 0xFF
  117. data[1] = 0xB003 >> 8
  118. data[2] = int(value) & 0xFF
  119. data[3] = int(value) >> 8
  120. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  121. value = decimal.Decimal(self._view.qline_cur_offset.text()) * decimal.Decimal(10)
  122. data = []
  123. if len(data) < 8:
  124. data += (8 - len(data)) * [0]
  125. data[0] = 0xB004 & 0xFF
  126. data[1] = 0xB004 >> 8
  127. data[2] = int(value) & 0xFF
  128. data[3] = int(value) >> 8
  129. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  130. except:
  131. self._view.can_connect_error()
  132. def _cell_one(self):
  133. current_onclick_index = self._view.hard_table.currentRow()
  134. try:
  135. data = []
  136. if len(data) < 8:
  137. data += (8 - len(data)) * [0]
  138. data[0] = (0xB111 + current_onclick_index) & 0xFF
  139. data[1] = (0xB111 + current_onclick_index) >> 8
  140. data[2] = self._view.cb_bmu_index.currentIndex() + 1
  141. data[3] = int(self._view.hard_table.item(current_onclick_index, 4).text()) & 0xFF
  142. data[4] = int(self._view.hard_table.item(current_onclick_index, 4).text()) >> 8
  143. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  144. except:
  145. self._view.can_connect_error()
  146. def _cell_all(self):
  147. try:
  148. # value = float(self._view.edt_cell.text()) * 1000
  149. data = []
  150. if len(data) < 8:
  151. data += (8 - len(data)) * [0]
  152. data[0] = 0xB110 & 0xFF
  153. data[1] = 0xB110 >> 8
  154. data[2] = self._view.cb_bmu_index.currentIndex() + 1
  155. data[3] = int(self._view.edt_cell.text()) & 0xFF
  156. data[4] = int(self._view.edt_cell.text()) >> 8
  157. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1803, data)
  158. except:
  159. self._view.can_connect_error()