bms_protect_ctl.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. from utils.globalvar import SD
  4. from widget.bms_protect import Win_Protect
  5. class BmsProtectControll:
  6. def __init__(self):
  7. self._view = Win_Protect()
  8. self.i = 0
  9. self.init()
  10. def init(self):
  11. self._view.read_param_signal.connect(self._read_param)
  12. self._view.write_param_signal.connect(self._write_param)
  13. self._view.exit_param_signal.connect(self._exit_param)
  14. def _read_param(self):
  15. try:
  16. data = []
  17. if len(data) < 8:
  18. data += (8 - len(data)) * [0]
  19. data[0] = 0xFF
  20. data[1] = 0xFF
  21. data[2] = 0xBB
  22. data[6] = self.i
  23. self.i = self.i + 1
  24. if self.i == 255:
  25. self.i = 0
  26. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  27. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  28. data[0] = 1
  29. data[2] = 0
  30. data[6] = self.i
  31. self.i = self.i + 1
  32. if self.i == 255:
  33. self.i = 0
  34. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  35. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  36. except:
  37. self._view.can_connect_error()
  38. def _write_param(self):
  39. try:
  40. data = []
  41. if len(data) < 8:
  42. data += (8 - len(data)) * [0]
  43. data[0] = int(self._view.qline_addr.text(), 16) & 0xFF
  44. data[1] = int(self._view.qline_addr.text(), 16) >> 8
  45. data[2] = int(float(self._view.qline_data.text())) & 0xFF
  46. data[3] = int(float(self._view.qline_data.text())) >> 8
  47. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1802, data)
  48. except ValueError:
  49. self._view.set_error()
  50. except:
  51. self._view.can_connect_error()
  52. def _exit_param(self):
  53. try:
  54. data = []
  55. if len(data) < 8:
  56. data += (8 - len(data)) * [0]
  57. data[0] = 3
  58. data[1] = 0xFF
  59. data[6] = self.i
  60. self.i = self.i + 1
  61. if self.i == 255:
  62. self.i = 0
  63. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  64. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  65. except:
  66. self._view.can_connect_error()