bms_work.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @文件 :ccuWork.py
  5. @时间 :2021/12/09 08:31:48
  6. @作者 :None
  7. @版本 :1.0
  8. @说明 :二级BMS工作线程
  9. '''
  10. from utils.delay import m_delay
  11. from utils.globalvar import SD
  12. from utils.hex_bit import hex_bcd
  13. from utils.log_signal import LogSignal
  14. from utils.qt import QObject, Signal, QDateTime
  15. class BmsSend(QObject):
  16. def __init__(self):
  17. super(BmsSend, self).__init__()
  18. self.page = 1
  19. def send(self):
  20. i = 0
  21. while SD.START_RUN:
  22. if SD.FRAM_READ_START:
  23. if SD.FRAM_SEND_PAGE:
  24. self._fram_read(self.page)
  25. self.page += 1
  26. SD.FRAM_SEND_PAGE = False
  27. else:
  28. if SD.FRAM_DELAY_TIME < 10000:
  29. m_delay(1)
  30. SD.FRAM_DELAY_TIME = SD.FRAM_DELAY_TIME + 1
  31. else:
  32. LogSignal.print_log_signal().log_emit("BCMU 铁电数据接收超时重发!" if SD.SYSTEM_LANGUAGE == 0 else "BCMU Fram Timeout!")
  33. self.page -= 1
  34. SD.FRAM_SEND_PAGE = True
  35. else:
  36. if SD.CCU_CHIP == 0 or SD.CCU_CHIP == 1:
  37. self._run_old()
  38. elif SD.CCU_CHIP == 2:
  39. self._run_new(i)
  40. m_delay(100)
  41. self._run_relay(i)
  42. i = i + 1
  43. if i == 256:
  44. i = 0
  45. if SD.LIFE_CTL == 2:
  46. self._life_date()
  47. m_delay(1000)
  48. def _fram_read(self, page):
  49. data = []
  50. if len(data) < 8:
  51. data += (8 - len(data)) * [0]
  52. data[0] = 0x01
  53. data[1] = page & 0xFF
  54. data[2] = (page & 0xFF00) >> 8
  55. data[3] = 0x01
  56. data[4] = 0xFF
  57. data[5] = 0xFF
  58. data[6] = 0xFF
  59. data[7] = 0xFF
  60. SD.CAN_CONTROL.send(0x1801B1C1, data, extern_flag=True)
  61. def _run_old(self):
  62. if SD.CCU_CHIP == 0:
  63. id = 0x18F403F0
  64. elif SD.CCU_CHIP == 1:
  65. id = 0x18F403F0 | ((SD.BCU_ID & 0xF0) << 8) | (SD.BCU_ID & 0xF)
  66. SD.CAN_CONTROL.send(id, [0x52, 0x55, 0x4E, 0, 0, 0, 0, 0xF5], extern_flag=True)
  67. def _run_new(self, i):
  68. data = []
  69. if len(data) < 8:
  70. data += (8 - len(data)) * [0]
  71. data[0] = 2
  72. data[1] = SD.SINGLE_ACQUISITION_OR_BALANCE
  73. data[6] = i
  74. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  75. SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x0020, data, extern_flag=True)
  76. def _run_relay(self, i):
  77. data = []
  78. if len(data) < 8:
  79. data += (8 - len(data)) * [0]
  80. data[0] = 4
  81. data[6] = i
  82. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  83. SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x0020, data, extern_flag=True)
  84. def _life_date(self):
  85. data = []
  86. if len(data) < 8:
  87. data += (8 - len(data)) * [0x00]
  88. SD.CAN_CONTROL.send(0x18FF0000, data, extern_flag=True)
  89. class BmsReceived(QObject):
  90. to_show_masterid_signal = Signal(int)
  91. to_show_0000_signal = Signal(object, int)
  92. to_show_0001_signal = Signal(object, int)
  93. to_show_0002_signal = Signal(object, int)
  94. to_show_0003_signal = Signal(object, int)
  95. to_show_0004_signal = Signal(object, int)
  96. to_show_0005_signal = Signal(object, int)
  97. to_show_0006_signal = Signal(object, int)
  98. to_show_0007_signal = Signal(object, int)
  99. to_show_0008_signal = Signal(object, int)
  100. to_show_0009_signal = Signal(object, int)
  101. to_show_000A_signal = Signal(object, int)
  102. to_show_000B_signal = Signal(object, int)
  103. to_show_000C_signal = Signal(object, int)
  104. to_show_000D_signal = Signal(object, int)
  105. to_show_000E_signal = Signal(object, int)
  106. to_show_000F_signal = Signal(object, int)
  107. to_show_0010_signal = Signal(object, int)
  108. to_show_0011_signal = Signal(object, int)
  109. to_show_0012_signal = Signal(object, int)
  110. to_show_0013_signal = Signal(object, int)
  111. to_show_0014_signal = Signal(object, int)
  112. to_show_0015_signal = Signal(object, int)
  113. to_show_0016_signal = Signal(object, int)
  114. to_show_0017_signal = Signal(object, int)
  115. to_show_0018_signal = Signal(object, int)
  116. to_show_0019_signal = Signal(object, int)
  117. to_show_001A_signal = Signal(object, int)
  118. to_show_001B_signal = Signal(object, int)
  119. to_show_001C_signal = Signal(object, int)
  120. to_show_001D_signal = Signal(object, int)
  121. to_show_001E_signal = Signal(object, int)
  122. to_show_001F_signal = Signal(object, int)
  123. to_show_0020_signal = Signal(object, int)
  124. to_show_0021_signal = Signal(object, int)
  125. to_show_0022_signal = Signal(object, int)
  126. to_show_0023_signal = Signal(object, int)
  127. def __init__(self):
  128. super(BmsReceived, self).__init__()
  129. self.dantidianya = [0 for i in range(10000)]
  130. self.dantiwendu = [0 for i in range(10000)]
  131. self.masterVersion = ["" for i in range(18)]
  132. self.fram_param = ["" for i in range(24)]
  133. self.single_low_vol_x = ""
  134. self.single_high_temp_x = ""
  135. # 接收数据
  136. def received(self):
  137. while SD.CAN_ON_OFF:
  138. result = SD.CAN_CONTROL.receive()
  139. if (result[1]):
  140. # ID主机号识别
  141. if result[1] & 0xFFFF == 1:
  142. self.to_show_masterid_signal.emit((result[1] >> 16) & 0xFF)
  143. # 0001
  144. if (result[1] ^ 0x18000000) & 0xFFFF == 0:
  145. self.to_show_0000_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  146. # 0001
  147. if (result[1] ^ 0x18000001) & 0xFFFF == 0:
  148. self.to_show_0001_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  149. # 0002
  150. elif (result[1] ^ 0x18000002) & 0xFFFF == 0:
  151. self.to_show_0002_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  152. # 0003
  153. elif (result[1] ^ 0x18000003) & 0xFFFF == 0:
  154. self.to_show_0003_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  155. # 0004
  156. elif (result[1] ^ 0x18000004) & 0xFFFF == 0:
  157. self.to_show_0004_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  158. # 0005
  159. elif (result[1] ^ 0x18000005) & 0xFFFF == 0:
  160. self.to_show_0005_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  161. # 0006
  162. elif (result[1] ^ 0x18000006) & 0xFFFF == 0:
  163. self.to_show_0006_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  164. # 0007
  165. elif (result[1] ^ 0x18000007) & 0xFFFF == 0:
  166. self.to_show_0007_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  167. # 0008
  168. elif (result[1] ^ 0x18000008) & 0xFFFF == 0:
  169. self.to_show_0008_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  170. # 0009
  171. elif (result[1] ^ 0x18000009) & 0xFFFF == 0:
  172. self.to_show_0009_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  173. # 000A
  174. elif (result[1] ^ 0x1800000A) & 0xFFFF == 0:
  175. self.to_show_000A_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  176. # 000B
  177. elif (result[1] ^ 0x1800000B) & 0xFFFF == 0:
  178. self.to_show_000B_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  179. # 000C
  180. elif (result[1] ^ 0x1800000C) & 0xFFFF == 0:
  181. self.to_show_000C_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  182. # 000D
  183. elif (result[1] ^ 0x1800000D) & 0xFFFF == 0:
  184. self.to_show_000D_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  185. # 000E
  186. elif (result[1] ^ 0x1800000E) & 0xFFFF == 0:
  187. self.to_show_000E_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  188. # 000F
  189. elif (result[1] ^ 0x1800000F) & 0xFFFF == 0:
  190. self.to_show_000F_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  191. # 0010
  192. elif (result[1] ^ 0x18000010) & 0xFFFF == 0:
  193. self.to_show_0010_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  194. # 0011
  195. elif (result[1] ^ 0x18000011) & 0xFFFF == 0:
  196. self.to_show_0011_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  197. # 0012
  198. elif (result[1] ^ 0x18000012) & 0xFFFF == 0:
  199. self.to_show_0012_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  200. # 0013
  201. elif (result[1] ^ 0x18000013) & 0xFFFF == 0:
  202. self.to_show_0013_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  203. # 0014
  204. elif (result[1] ^ 0x18000014) & 0xFFFF == 0:
  205. self.to_show_0014_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  206. # 0015
  207. elif (result[1] ^ 0x18000015) & 0xFFFF == 0:
  208. self.to_show_0015_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  209. # 0016
  210. elif (result[1] ^ 0x18000016) & 0xFFFF == 0:
  211. self.to_show_0016_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  212. # 0017
  213. elif (result[1] ^ 0x18000017) & 0xFFFF == 0:
  214. self.to_show_0017_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  215. # 0018
  216. elif (result[1] ^ 0x18000018) & 0xFFFF == 0:
  217. self.to_show_0018_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  218. # 0019
  219. elif (result[1] ^ 0x18000019) & 0xFFFF == 0:
  220. self.to_show_0019_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  221. # 001A
  222. elif (result[1] ^ 0x1800001A) & 0xFFFF == 0:
  223. self.to_show_001A_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  224. # 001B
  225. elif (result[1] ^ 0x1800001B) & 0xFFFF == 0:
  226. self.to_show_001B_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  227. # 001C
  228. elif (result[1] ^ 0x1800001C) & 0xFFFF == 0:
  229. self.to_show_001C_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  230. # 001D
  231. elif (result[1] ^ 0x1800001D) & 0xFFFF == 0:
  232. self.to_show_001D_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  233. # 001E
  234. elif (result[1] ^ 0x1800001E) & 0xFFFF == 0:
  235. self.to_show_001E_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  236. # 001F
  237. elif (result[1] ^ 0x1800001F) & 0xFFFF == 0:
  238. self.to_show_001F_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  239. # 0020
  240. elif (result[1] ^ 0x18000020) & 0xFFFF == 0:
  241. self.to_show_0020_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  242. # 0021
  243. elif (result[1] ^ 0x18000021) & 0xFFFF == 0:
  244. self.to_show_0021_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  245. # 0022
  246. elif (result[1] ^ 0x18000022) & 0xFFFF == 0:
  247. self.to_show_0022_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  248. # 0023
  249. elif (result[1] ^ 0x18000023) & 0xFFFF == 0:
  250. self.to_show_0023_signal.emit(result[2], (result[1] >> 16) & 0xFF)
  251. # # 接收数据
  252. # def received(self):
  253. # while SD.CAN_ON_OFF:
  254. # restNum = SD.CAN_CONTROL.get_undeal_number()
  255. # if restNum <= 0:
  256. # continue
  257. # revRet = SD.CAN_CONTROL.receive()
  258. # for i in revRet:
  259. # print(i)
  260. # if int(i.RemoteFlag) == 0:
  261. # print(i.ID)
  262. # # ID主机号识别
  263. # if i.ID & 0xFFFF == 1:
  264. # self.to_show_masterid_signal.emit((i.ID >> 16) & 0xFF)
  265. # # 0001
  266. # if i.ID == 0x18000001 | (SD.BCU_ID << 16):
  267. # self.to_show_0001_signal.emit(i.Data)
  268. # # 0002
  269. # elif i.ID == 0x18000002 | (SD.BCU_ID << 16):
  270. # self.to_show_0002_signal.emit(i.Data)
  271. # # 0003
  272. # elif i.ID == 0x18000003 | (SD.BCU_ID << 16):
  273. # self.to_show_0003_signal.emit(i.Data)
  274. # # 0004
  275. # elif i.ID == 0x18000004 | (SD.BCU_ID << 16):
  276. # self.to_show_0004_signal.emit(i.Data)
  277. # # 0005
  278. # elif i.ID == 0x18000005 | (SD.BCU_ID << 16):
  279. # self.to_show_0005_signal.emit(i.Data)
  280. # # 0006
  281. # elif i.ID == 0x18000006 | (SD.BCU_ID << 16):
  282. # self.to_show_0006_signal.emit(i.Data)
  283. # # 0007
  284. # elif i.ID == 0x18000007 | (SD.BCU_ID << 16):
  285. # self.to_show_0007_signal.emit(i.Data)
  286. # # 0008
  287. # elif i.ID == 0x18000008 | (SD.BCU_ID << 16):
  288. # self.to_show_0008_signal.emit(i.Data)
  289. # # 0009
  290. # elif i.ID == 0x18000009 | (SD.BCU_ID << 16):
  291. # self.to_show_0009_signal.emit(i.Data)
  292. # # 000A
  293. # elif i.ID == 0x1800000A | (SD.BCU_ID << 16):
  294. # self.to_show_000A_signal.emit(i.Data)
  295. # # 000B
  296. # elif i.ID == 0x1800000B | (SD.BCU_ID << 16):
  297. # self.to_show_000B_signal.emit(i.Data)
  298. # # 000C
  299. # elif i.ID == 0x1800000C | (SD.BCU_ID << 16):
  300. # self.to_show_000C_signal.emit(i.Data)
  301. # # 000D
  302. # elif i.ID == 0x1800000D | (SD.BCU_ID << 16):
  303. # self.to_show_000D_signal.emit(i.Data)
  304. # # 000E
  305. # elif i.ID == 0x1800000E | (SD.BCU_ID << 16):
  306. # self.to_show_000E_signal.emit(i.Data)
  307. # # 000F
  308. # elif i.ID == 0x1800000F | (SD.BCU_ID << 16):
  309. # self.to_show_000F_signal.emit(i.Data)
  310. # # 0010
  311. # elif i.ID == 0x18000010 | (SD.BCU_ID << 16):
  312. # self.to_show_0010_signal.emit(i.Data)
  313. # # 0011
  314. # elif i.ID == 0x18000011 | (SD.BCU_ID << 16):
  315. # self.to_show_0011_signal.emit(i.Data)
  316. # # 0012
  317. # elif i.ID == 0x18000012 | (SD.BCU_ID << 16):
  318. # self.to_show_0012_signal.emit(i.Data)
  319. # # 0013
  320. # elif i.ID == 0x18000013 | (SD.BCU_ID << 16):
  321. # self.to_show_0013_signal.emit(i.Data)
  322. # # 0014
  323. # elif i.ID == 0x18000014 | (SD.BCU_ID << 16):
  324. # self.to_show_0014_signal.emit(i.Data)
  325. # # 0015
  326. # elif i.ID == 0x18000015 | (SD.BCU_ID << 16):
  327. # self.to_show_0015_signal.emit(i.Data)
  328. # # 0016
  329. # elif i.ID == 0x18000016 | (SD.BCU_ID << 16):
  330. # self.to_show_0016_signal.emit(i.Data)
  331. # # 0017
  332. # elif i.ID == 0x18000017 | (SD.BCU_ID << 16):
  333. # self.to_show_0017_signal.emit(i.Data)
  334. # # 0018
  335. # elif i.ID == 0x18000018 | (SD.BCU_ID << 16):
  336. # self.to_show_0018_signal.emit(i.Data)
  337. # # 0019
  338. # elif i.ID == 0x18000019 | (SD.BCU_ID << 16):
  339. # self.to_show_0019_signal.emit(i.Data)
  340. # # 001A
  341. # elif i.ID == 0x1800001A | (SD.BCU_ID << 16):
  342. # self.to_show_001A_signal.emit(i.Data)
  343. # # 001B
  344. # elif i.ID == 0x1800001B | (SD.BCU_ID << 16):
  345. # self.to_show_001B_signal.emit(i.Data)
  346. # # 001C
  347. # elif i.ID == 0x1800001C | (SD.BCU_ID << 16):
  348. # self.to_show_001C_signal.emit(i.Data)
  349. # # 001D
  350. # elif i.ID == 0x1800001D | (SD.BCU_ID << 16):
  351. # self.to_show_001D_signal.emit(i.Data)
  352. # # 001E
  353. # elif i.ID == 0x1800001E | (SD.BCU_ID << 16):
  354. # self.to_show_001E_signal.emit(i.Data)
  355. # # 001F
  356. # elif i.ID == 0x1800001F | (SD.BCU_ID << 16):
  357. # self.to_show_001F_signal.emit(i.Data)
  358. # # 0020
  359. # elif i.ID == 0x18000020 | (SD.BCU_ID << 16):
  360. # self.to_show_0020_signal.emit(i.Data)
  361. # # 0021
  362. # elif i.ID == 0x18000021 | (SD.BCU_ID << 16):
  363. # self.to_show_0021_signal.emit(i.Data)
  364. # # 0022
  365. # elif i.ID == 0x18000022 | (SD.BCU_ID << 16):
  366. # self.to_show_0022_signal.emit(i.Data)
  367. # # 0023
  368. # elif i.ID == 0x18000023 | (SD.BCU_ID << 16):
  369. # self.to_show_0023_signal.emit(i.Data)