auto_charge.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. """
  2. @Date :2021/7/7/10:25
  3. @Author:zz
  4. @Desc :自动启动发动机充电
  5. """
  6. import time
  7. import json
  8. import threading
  9. from event_storage import EventStorage
  10. from utility import Utility
  11. from log import OutPutLog
  12. class AutoCharge:
  13. def __init__(self):
  14. self._storage = EventStorage()
  15. self._log = OutPutLog()
  16. self._error = 0
  17. # 历史存储主函数
  18. def run(self):
  19. self._log.info('[AutoCharge] - AutoFeeding module is running!')
  20. # c601 蓄电池电压
  21. # c476 主发运行 c472 主发自动 c482 主发备车
  22. # c576 应急发运行 c572 应发自动 c582 应发备车
  23. list = ["c601","c476","c472","c482","c576","c572","c582"]
  24. # 获取配置信息
  25. while 1:
  26. time.sleep(10)
  27. real_data_dict = self._storage.get_real_data(list)
  28. self._error = 0
  29. for key in real_data_dict:
  30. if real_data_dict[key] == None:
  31. self._error = 1
  32. sql_wind_light_configuration = "SELECT * FROM wind_light_configuration;"
  33. wind_light_configuration = self._storage.execute_sql(sql_wind_light_configuration)
  34. if wind_light_configuration != None:
  35. if len(wind_light_configuration) > 0:
  36. self._error = 0
  37. charge_device = int(wind_light_configuration[0]['recharge_device_set'])
  38. charge_voltage = int(wind_light_configuration[0]['recharge_device_start_voltage'])
  39. else:
  40. self._error = 1
  41. else:
  42. self._error = 1
  43. if self._error==0:
  44. print("zz")
  45. print(charge_voltage)
  46. charge_connectors = Utility.available_connectors["sct003"]
  47. battery_voltage = int(real_data_dict['c601'])
  48. fdj_run = int(real_data_dict['c476']) + int(real_data_dict['c576'])
  49. zfdj_aotu = int(real_data_dict['c472'])
  50. zfdj_ready = int(real_data_dict['c482'])
  51. yjfdj_aotu = int(real_data_dict['c572'])
  52. yjfdj_ready = int(real_data_dict['c582'])
  53. if battery_voltage <= charge_voltage:
  54. if charge_device == 1 and fdj_run == 0 and zfdj_aotu == 1 and zfdj_ready == 1:
  55. charge_connectors.send_command([{"length": 0, "start_addr": 20483, "output_value": 65280, "function_code": 5}]) #启动主发电机
  56. elif charge_device == 2 and fdj_run == 0 and yjfdj_aotu == 1 and yjfdj_ready == 1:
  57. charge_connectors.send_command([{"length": 0, "start_addr": 20485, "output_value": 65280, "function_code": 5}]) #启动应急发电机
  58. else:
  59. self._log.info('[AutoCharge]—参数获取失败')