bms_main_ctl.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. from widget.bms_main import Win_Main
  4. from utils.globalvar import SD
  5. from utils.qt import Qt
  6. class BmsMainControll:
  7. def __init__(self):
  8. self._view = Win_Main()
  9. self.i = 0
  10. self.init()
  11. def init(self):
  12. self._view.up_signal.connect(self.sys_up)
  13. self._view.down_signal.connect(self.sys_down)
  14. self._view.controll_signal.connect(self.sys_controller)
  15. self._view.do1_signal.connect(self.do1)
  16. self._view.do2_signal.connect(self.do2)
  17. self._view.do3_signal.connect(self.do3)
  18. self._view.do4_signal.connect(self.do4)
  19. self._view.do5_signal.connect(self.do5)
  20. self._view.do6_signal.connect(self.do6)
  21. self._view.do7_signal.connect(self.do7)
  22. self._view.do8_signal.connect(self.do8)
  23. self._view.fault_release_signal.connect(self.operate1)
  24. self._view.jy_signal.connect(self.operate2)
  25. self._view.jy_one_signal.connect(self.operate3)
  26. self._view.chg_mos_signal.connect(self.operate4)
  27. self._view.dchg_mos_signal.connect(self.operate5)
  28. self._view.pre_mos_signal.connect(self.operate6)
  29. self._view.gjd1_signal.connect(self.operate7)
  30. self._view.gjd2_signal.connect(self.operate8)
  31. self._view.chg_signal.connect(self.operate9)
  32. self._view.sleep_signal.connect(self.operate10)
  33. self._view.reset_signal.connect(self.operate11)
  34. self._view.clear_balance_signal.connect(self.operate12)
  35. self._view.fan_signal.connect(self.operate13)
  36. def sys_up(self):
  37. try:
  38. data = []
  39. if len(data) < 8:
  40. data += (8 - len(data)) * [0]
  41. data[0] = 0xFF
  42. data[1] = 0xFF
  43. data[2] = 0xAA
  44. data[6] = self.i
  45. self.i = self.i + 1
  46. if self.i == 255:
  47. self.i = 0
  48. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  49. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  50. except:
  51. self._view.can_connect_error()
  52. def sys_down(self):
  53. try:
  54. data = []
  55. if len(data) < 8:
  56. data += (8 - len(data)) * [0]
  57. data[0] = 0xFF
  58. data[1] = 0xFF
  59. data[2] = 0xBB
  60. data[6] = self.i
  61. self.i = self.i + 1
  62. if self.i == 255:
  63. self.i = 0
  64. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  65. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  66. except:
  67. self._view.can_connect_error()
  68. def sys_controller(self, check_status):
  69. if check_status:
  70. try:
  71. data = []
  72. if len(data) < 8:
  73. data += (8 - len(data)) * [0]
  74. data[0] = 0xFF
  75. data[1] = 0xFF
  76. data[2] = 0xAA
  77. data[6] = self.i
  78. self.i = self.i + 1
  79. if self.i == 255:
  80. self.i = 0
  81. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  82. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  83. data[0] = 4
  84. data[1] = 0xFF
  85. data[2] = 0
  86. data[6] = self.i
  87. self.i = self.i + 1
  88. if self.i == 255:
  89. self.i = 0
  90. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  91. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  92. except:
  93. # self._view.under_widget.snkz_check_box.setCheckState(Qt.Unchecked)
  94. self._view.can_connect_error()
  95. else:
  96. try:
  97. data = []
  98. if len(data) < 8:
  99. data += (8 - len(data)) * [0]
  100. data[0] = 5
  101. data[1] = 0xFF
  102. data[2] = 0
  103. data[6] = self.i
  104. self.i = self.i + 1
  105. if self.i == 255:
  106. self.i = 0
  107. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  108. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  109. except:
  110. self._view.can_connect_error()
  111. def do1(self, do1_status):
  112. try:
  113. data = []
  114. if len(data) < 8:
  115. data += (8 - len(data)) * [0]
  116. data[0] = 0x01
  117. data[1] = 0xC0
  118. data[2] = (do1_status >> 1) & 0xFF
  119. data[3] = 0
  120. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  121. except:
  122. self._view.can_connect_error()
  123. def do2(self, do2_status):
  124. try:
  125. data = []
  126. if len(data) < 8:
  127. data += (8 - len(data)) * [0]
  128. data[0] = 0x01
  129. data[1] = 0xC0
  130. data[2] = do2_status & 0xFF
  131. data[3] = 0
  132. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  133. except:
  134. self._view.can_connect_error()
  135. def do3(self, do3_status):
  136. try:
  137. data = []
  138. if len(data) < 8:
  139. data += (8 - len(data)) * [0]
  140. data[0] = 0x01
  141. data[1] = 0xC0
  142. data[2] = (do3_status << 1) & 0xFF
  143. data[3] = 0
  144. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  145. except:
  146. self._view.can_connect_error()
  147. def do4(self, do4_status):
  148. try:
  149. data = []
  150. if len(data) < 8:
  151. data += (8 - len(data)) * [0]
  152. data[0] = 0x01
  153. data[1] = 0xC0
  154. data[2] = (do4_status << 2) & 0xFF
  155. data[3] = 0
  156. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  157. except:
  158. self._view.can_connect_error()
  159. def do5(self, do5_status):
  160. try:
  161. data = []
  162. if len(data) < 8:
  163. data += (8 - len(data)) * [0]
  164. data[0] = 0x01
  165. data[1] = 0xC0
  166. data[2] = (do5_status << 3) & 0xFF
  167. data[3] = 0
  168. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  169. except:
  170. self._view.can_connect_error()
  171. def do6(self, do6_status):
  172. try:
  173. data = []
  174. if len(data) < 8:
  175. data += (8 - len(data)) * [0]
  176. data[0] = 0x01
  177. data[1] = 0xC0
  178. data[2] = (do6_status << 4) & 0xFF
  179. data[3] = 0
  180. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  181. except:
  182. self._view.can_connect_error()
  183. def do7(self, do7_status):
  184. try:
  185. data = []
  186. if len(data) < 8:
  187. data += (8 - len(data)) * [0]
  188. data[0] = 0x01
  189. data[1] = 0xC0
  190. data[2] = (do7_status << 1) & 0xFF
  191. data[3] = 0
  192. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  193. except:
  194. self._view.can_connect_error()
  195. def do8(self, do8_status):
  196. try:
  197. data = []
  198. if len(data) < 8:
  199. data += (8 - len(data)) * [0]
  200. data[0] = 0x01
  201. data[1] = 0xC0
  202. data[2] = (do8_status << 1) & 0xFF
  203. data[3] = 0
  204. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  205. except:
  206. self._view.can_connect_error()
  207. def operate1(self, status):
  208. try:
  209. data = []
  210. if len(data) < 8:
  211. data += (8 - len(data)) * [0]
  212. data[0] = 0x00
  213. data[1] = 0xC0
  214. data[2] = (status >> 1) & 0xFF
  215. data[3] = 0
  216. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  217. except:
  218. self._view.can_connect_error()
  219. def operate2(self, status):
  220. try:
  221. data = []
  222. if len(data) < 8:
  223. data += (8 - len(data)) * [0]
  224. data[0] = 0x00
  225. data[1] = 0xC0
  226. data[2] = (status) & 0xFF
  227. data[3] = 0
  228. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  229. except:
  230. self._view.can_connect_error()
  231. def operate3(self, status):
  232. try:
  233. data = []
  234. if len(data) < 8:
  235. data += (8 - len(data)) * [0]
  236. data[0] = 0x00
  237. data[1] = 0xC0
  238. data[2] = (status << 1) & 0xFF
  239. data[3] = 0
  240. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  241. except:
  242. self._view.can_connect_error()
  243. def operate4(self, status):
  244. try:
  245. data = []
  246. if len(data) < 8:
  247. data += (8 - len(data)) * [0]
  248. data[0] = 0x00
  249. data[1] = 0xC0
  250. data[2] = (status << 2) & 0xFF
  251. data[3] = 0
  252. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  253. except:
  254. self._view.can_connect_error()
  255. def operate5(self, status):
  256. try:
  257. data = []
  258. if len(data) < 8:
  259. data += (8 - len(data)) * [0]
  260. data[0] = 0x00
  261. data[1] = 0xC0
  262. data[2] = (status << 3) & 0xFF
  263. data[3] = 0
  264. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  265. except:
  266. self._view.can_connect_error()
  267. def operate6(self, status):
  268. try:
  269. data = []
  270. if len(data) < 8:
  271. data += (8 - len(data)) * [0]
  272. data[0] = 0x00
  273. data[1] = 0xC0
  274. data[2] = (status << 4) & 0xFF
  275. data[3] = 0
  276. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  277. except:
  278. self._view.can_connect_error()
  279. def operate7(self, status):
  280. try:
  281. data = []
  282. if len(data) < 8:
  283. data += (8 - len(data)) * [0]
  284. data[0] = 0x00
  285. data[1] = 0xC0
  286. data[2] = (status << 5) & 0xFF
  287. data[3] = 0
  288. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  289. except:
  290. self._view.can_connect_error()
  291. def operate8(self, status):
  292. try:
  293. data = []
  294. if len(data) < 8:
  295. data += (8 - len(data)) * [0]
  296. data[0] = 0x00
  297. data[1] = 0xC0
  298. data[2] = (status << 6) & 0xFF
  299. data[3] = 0
  300. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  301. except:
  302. self._view.can_connect_error()
  303. def operate9(self, status):
  304. try:
  305. data = []
  306. if len(data) < 8:
  307. data += (8 - len(data)) * [0]
  308. data[0] = 0x00
  309. data[1] = 0xC0
  310. data[2] = 0
  311. data[3] = (status >> 1) & 0xFF
  312. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  313. except:
  314. self._view.can_connect_error()
  315. def operate10(self, status):
  316. try:
  317. data = []
  318. if len(data) < 8:
  319. data += (8 - len(data)) * [0]
  320. data[0] = 0x00
  321. data[1] = 0xC0
  322. data[2] = 0
  323. data[3] = (status) & 0xFF
  324. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  325. except:
  326. self._view.can_connect_error()
  327. def operate11(self, status):
  328. try:
  329. data = []
  330. if len(data) < 8:
  331. data += (8 - len(data)) * [0]
  332. data[0] = 0x00
  333. data[1] = 0xC0
  334. data[2] = 0
  335. data[3] = (status >> 1) & 0xFF
  336. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  337. except:
  338. self._view.can_connect_error()
  339. def operate12(self, status):
  340. try:
  341. data = []
  342. if len(data) < 8:
  343. data += (8 - len(data)) * [0]
  344. data[0] = 0x00
  345. data[1] = 0xC0
  346. data[2] = 0
  347. data[3] = (status >> 2) & 0xFF
  348. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  349. except:
  350. self._view.can_connect_error()
  351. def operate13(self, status):
  352. try:
  353. data = []
  354. if len(data) < 8:
  355. data += (8 - len(data)) * [0]
  356. data[0] = 0x00
  357. data[1] = 0xC0
  358. data[2] = 0
  359. data[3] = (status >> 4) & 0xFF
  360. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  361. except:
  362. self._view.can_connect_error()