bms_main_ctl.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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.dchg_mos_signal.connect(self.operate4)
  27. self._view.chg_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.can_connect_error()
  94. else:
  95. try:
  96. data = []
  97. if len(data) < 8:
  98. data += (8 - len(data)) * [0]
  99. data[0] = 5
  100. data[1] = 0xFF
  101. data[2] = 0
  102. data[6] = self.i
  103. self.i = self.i + 1
  104. if self.i == 255:
  105. self.i = 0
  106. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  107. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  108. except:
  109. self._view.can_connect_error()
  110. def do1(self, do1_status):
  111. try:
  112. data = []
  113. if len(data) < 8:
  114. data += (8 - len(data)) * [0]
  115. data[0] = 0x01
  116. data[1] = 0xC0
  117. data[2] = (do1_status >> 1) & 0xFF
  118. data[3] = 0
  119. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  120. except:
  121. self._view.can_connect_error()
  122. def do2(self, do2_status):
  123. try:
  124. data = []
  125. if len(data) < 8:
  126. data += (8 - len(data)) * [0]
  127. data[0] = 0x01
  128. data[1] = 0xC0
  129. data[2] = do2_status & 0xFF
  130. data[3] = 0
  131. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  132. except:
  133. self._view.can_connect_error()
  134. def do3(self, do3_status):
  135. try:
  136. data = []
  137. if len(data) < 8:
  138. data += (8 - len(data)) * [0]
  139. data[0] = 0x01
  140. data[1] = 0xC0
  141. data[2] = (do3_status << 1) & 0xFF
  142. data[3] = 0
  143. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  144. except:
  145. self._view.can_connect_error()
  146. def do4(self, do4_status):
  147. try:
  148. data = []
  149. if len(data) < 8:
  150. data += (8 - len(data)) * [0]
  151. data[0] = 0x01
  152. data[1] = 0xC0
  153. data[2] = (do4_status << 2) & 0xFF
  154. data[3] = 0
  155. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  156. except:
  157. self._view.can_connect_error()
  158. def do5(self, do5_status):
  159. try:
  160. data = []
  161. if len(data) < 8:
  162. data += (8 - len(data)) * [0]
  163. data[0] = 0x01
  164. data[1] = 0xC0
  165. data[2] = (do5_status << 3) & 0xFF
  166. data[3] = 0
  167. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  168. except:
  169. self._view.can_connect_error()
  170. def do6(self, do6_status):
  171. try:
  172. data = []
  173. if len(data) < 8:
  174. data += (8 - len(data)) * [0]
  175. data[0] = 0x01
  176. data[1] = 0xC0
  177. data[2] = (do6_status << 4) & 0xFF
  178. data[3] = 0
  179. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  180. except:
  181. self._view.can_connect_error()
  182. def do7(self, do7_status):
  183. try:
  184. data = []
  185. if len(data) < 8:
  186. data += (8 - len(data)) * [0]
  187. data[0] = 0x01
  188. data[1] = 0xC0
  189. data[2] = (do7_status << 5) & 0xFF
  190. data[3] = 0
  191. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  192. except:
  193. self._view.can_connect_error()
  194. def do8(self, do8_status):
  195. try:
  196. data = []
  197. if len(data) < 8:
  198. data += (8 - len(data)) * [0]
  199. data[0] = 0x01
  200. data[1] = 0xC0
  201. data[2] = (do8_status << 6) & 0xFF
  202. data[3] = 0
  203. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  204. except:
  205. self._view.can_connect_error()
  206. def operate1(self, status):
  207. try:
  208. data = []
  209. if len(data) < 8:
  210. data += (8 - len(data)) * [0]
  211. data[0] = 0x00
  212. data[1] = 0xC0
  213. data[2] = (status >> 1) & 0xFF
  214. data[3] = 0
  215. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  216. except:
  217. self._view.can_connect_error()
  218. def operate2(self, status):
  219. try:
  220. data = []
  221. if len(data) < 8:
  222. data += (8 - len(data)) * [0]
  223. data[0] = 0x00
  224. data[1] = 0xC0
  225. data[2] = (status) & 0xFF
  226. data[3] = 0
  227. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  228. except:
  229. self._view.can_connect_error()
  230. def operate3(self, status):
  231. try:
  232. data = []
  233. if len(data) < 8:
  234. data += (8 - len(data)) * [0]
  235. data[0] = 0x00
  236. data[1] = 0xC0
  237. data[2] = (status << 1) & 0xFF
  238. data[3] = 0
  239. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  240. except:
  241. self._view.can_connect_error()
  242. def operate4(self, status):
  243. try:
  244. data = []
  245. if len(data) < 8:
  246. data += (8 - len(data)) * [0]
  247. data[0] = 0x00
  248. data[1] = 0xC0
  249. data[2] = (status << 2) & 0xFF
  250. data[3] = 0
  251. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  252. except:
  253. self._view.can_connect_error()
  254. def operate5(self, status):
  255. try:
  256. data = []
  257. if len(data) < 8:
  258. data += (8 - len(data)) * [0]
  259. data[0] = 0x00
  260. data[1] = 0xC0
  261. data[2] = (status << 3) & 0xFF
  262. data[3] = 0
  263. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  264. except:
  265. self._view.can_connect_error()
  266. def operate6(self, status):
  267. try:
  268. data = []
  269. if len(data) < 8:
  270. data += (8 - len(data)) * [0]
  271. data[0] = 0x00
  272. data[1] = 0xC0
  273. data[2] = (status << 4) & 0xFF
  274. data[3] = 0
  275. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  276. except:
  277. self._view.can_connect_error()
  278. def operate7(self, status):
  279. try:
  280. data = []
  281. if len(data) < 8:
  282. data += (8 - len(data)) * [0]
  283. data[0] = 0x00
  284. data[1] = 0xC0
  285. data[2] = (status << 5) & 0xFF
  286. data[3] = 0
  287. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  288. except:
  289. self._view.can_connect_error()
  290. def operate8(self, status):
  291. try:
  292. data = []
  293. if len(data) < 8:
  294. data += (8 - len(data)) * [0]
  295. data[0] = 0x00
  296. data[1] = 0xC0
  297. data[2] = (status << 6) & 0xFF
  298. data[3] = 0
  299. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  300. except:
  301. self._view.can_connect_error()
  302. def operate9(self, status):
  303. try:
  304. data = []
  305. if len(data) < 8:
  306. data += (8 - len(data)) * [0]
  307. data[0] = 0x00
  308. data[1] = 0xC0
  309. data[2] = 0
  310. data[3] = (status >> 1) & 0xFF
  311. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  312. except:
  313. self._view.can_connect_error()
  314. def operate10(self, status):
  315. try:
  316. data = []
  317. if len(data) < 8:
  318. data += (8 - len(data)) * [0]
  319. data[0] = 0x00
  320. data[1] = 0xC0
  321. data[2] = 0
  322. data[3] = (status) & 0xFF
  323. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  324. except:
  325. self._view.can_connect_error()
  326. def operate11(self, status):
  327. try:
  328. data = []
  329. if len(data) < 8:
  330. data += (8 - len(data)) * [0]
  331. data[0] = 0x00
  332. data[1] = 0xC0
  333. data[2] = 0
  334. data[3] = (status << 1) & 0xFF
  335. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  336. except:
  337. self._view.can_connect_error()
  338. def operate12(self, status):
  339. try:
  340. data = []
  341. if len(data) < 8:
  342. data += (8 - len(data)) * [0]
  343. data[0] = 0x00
  344. data[1] = 0xC0
  345. data[2] = 0
  346. data[3] = (status << 2) & 0xFF
  347. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  348. except:
  349. self._view.can_connect_error()
  350. def operate13(self, status):
  351. try:
  352. data = []
  353. if len(data) < 8:
  354. data += (8 - len(data)) * [0]
  355. data[0] = 0x00
  356. data[1] = 0xC0
  357. data[2] = 0
  358. data[3] = (status << 4) & 0xFF
  359. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1804, data)
  360. except:
  361. self._view.can_connect_error()