bms_protect_ctl.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. from utils.globalvar import SD
  4. from widget.bms_protect import Win_Protect
  5. import decimal
  6. class BmsProtectControll:
  7. def __init__(self):
  8. self._view = Win_Protect()
  9. self.i = 0
  10. self.init()
  11. def init(self):
  12. self._view.read_param_signal.connect(self._read_param)
  13. self._view.write_param_signal.connect(self._write_param)
  14. self._view.exit_param_signal.connect(self._exit_param)
  15. self._view.reset_param_signal.connect(self._reset_param)
  16. def _read_param(self):
  17. try:
  18. data = []
  19. if len(data) < 8:
  20. data += (8 - len(data)) * [0]
  21. data[0] = 0xFF
  22. data[1] = 0xFF
  23. data[2] = 0xBB
  24. data[6] = self.i
  25. self.i = self.i + 1
  26. if self.i == 255:
  27. self.i = 0
  28. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  29. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  30. data[0] = 1
  31. data[2] = 0
  32. data[6] = self.i
  33. self.i = self.i + 1
  34. if self.i == 255:
  35. self.i = 0
  36. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  37. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  38. except:
  39. self._view.can_connect_error()
  40. def _write_param(self):
  41. try:
  42. value = (decimal.Decimal(self._view.qline_data_set.text()) - decimal.Decimal(self._view.qline_offset.text()))/decimal.Decimal(self._view.qline_fbl.text())
  43. self._view.qline_data.setText(str(int(value) & 0xFFFF))
  44. data = []
  45. if len(data) < 8:
  46. data += (8 - len(data)) * [0]
  47. data[0] = int(self._view.qline_addr.text(), 16) & 0xFF
  48. data[1] = int(self._view.qline_addr.text(), 16) >> 8
  49. data[2] = int(value) & 0xFF
  50. data[3] = int(value) >> 8
  51. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1802, data)
  52. self._view.start_timer()
  53. except ValueError:
  54. self._view.set_error()
  55. except:
  56. self._view.can_connect_error()
  57. def _exit_param(self):
  58. try:
  59. data = []
  60. if len(data) < 8:
  61. data += (8 - len(data)) * [0]
  62. data[0] = 3
  63. data[1] = 0xFF
  64. data[6] = self.i
  65. self.i = self.i + 1
  66. if self.i == 255:
  67. self.i = 0
  68. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  69. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  70. except:
  71. self._view.can_connect_error()
  72. def _reset_param(self):
  73. try:
  74. data = []
  75. if len(data) < 8:
  76. data += (8 - len(data)) * [0]
  77. data[0] = 0xEE
  78. data[1] = 0xFF
  79. data[6] = self.i
  80. self.i = self.i + 1
  81. if self.i == 255:
  82. self.i = 0
  83. data[7] = data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6]
  84. msg = SD.CAN_CONTROL.send((0x18 << 24) | (SD.BCU_ID << 16) | 0x1801, data)
  85. except:
  86. self._view.can_connect_error()