bms_protect_ctl.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. self._view.reset_param_signal.connect(self._reset_param)
  15. def _read_param(self):
  16. try:
  17. data = []
  18. if len(data) < 8:
  19. data += (8 - len(data)) * [0]
  20. data[0] = 0xFF
  21. data[1] = 0xFF
  22. data[2] = 0xBB
  23. data[6] = self.i
  24. self.i = self.i + 1
  25. if self.i == 255:
  26. self.i = 0
  27. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  28. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  29. data[0] = 1
  30. data[2] = 0
  31. data[6] = self.i
  32. self.i = self.i + 1
  33. if self.i == 255:
  34. self.i = 0
  35. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  36. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  37. except:
  38. self._view.can_connect_error()
  39. def _write_param(self):
  40. try:
  41. data = []
  42. if len(data) < 8:
  43. data += (8 - len(data)) * [0]
  44. data[0] = int(self._view.qline_addr.text(), 16) & 0xFF
  45. data[1] = int(self._view.qline_addr.text(), 16) >> 8
  46. data[2] = int(float(self._view.qline_data.text())) & 0xFF
  47. data[3] = int(float(self._view.qline_data.text())) >> 8
  48. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1802, data)
  49. except ValueError:
  50. self._view.set_error()
  51. except:
  52. self._view.can_connect_error()
  53. def _exit_param(self):
  54. try:
  55. data = []
  56. if len(data) < 8:
  57. data += (8 - len(data)) * [0]
  58. data[0] = 0xEE
  59. data[1] = 0xFF
  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 _reset_param(self):
  69. try:
  70. data = []
  71. if len(data) < 8:
  72. data += (8 - len(data)) * [0]
  73. data[0] = 3
  74. data[1] = 0xFF
  75. data[6] = self.i
  76. self.i = self.i + 1
  77. if self.i == 255:
  78. self.i = 0
  79. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  80. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  81. except:
  82. self._view.can_connect_error()