1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- """
- @Date :2021/7/7/10:25
- @Author:zz
- @Desc :自动启动发动机充电
- """
- import time
- import json
- import threading
- from event_storage import EventStorage
- from utility import Utility
- from log import OutPutLog
- class AutoCharge:
- def __init__(self):
- self._storage = EventStorage()
- self._log = OutPutLog()
- self._error = 0
- # 历史存储主函数
- def run(self):
- self._log.info('[AutoCharge] - AutoFeeding module is running!')
- # c601 蓄电池电压
- # c476 主发运行 c472 主发自动 c482 主发备车
- # c576 应急发运行 c572 应发自动 c582 应发备车
- list = ["c601","c476","c472","c482","c576","c572","c582"]
- # 获取配置信息
- while 1:
- time.sleep(10)
- real_data_dict = self._storage.get_real_data(list)
- self._error = 0
- for key in real_data_dict:
- if real_data_dict[key] == None:
- self._error = 1
- sql_wind_light_configuration = "SELECT * FROM wind_light_configuration;"
- wind_light_configuration = self._storage.execute_sql(sql_wind_light_configuration)
- if wind_light_configuration != None:
- if len(wind_light_configuration) > 0:
- self._error = 0
- charge_device = int(wind_light_configuration[0]['recharge_device_set'])
- charge_voltage = int(wind_light_configuration[0]['recharge_device_start_voltage'])
- else:
- self._error = 1
- else:
- self._error = 1
- if self._error==0:
- #print("zz")
- #print(charge_voltage)
- charge_connectors = Utility.available_connectors["sct003"]
- battery_voltage = int(real_data_dict['c601'])
- fdj_run = int(real_data_dict['c476']) + int(real_data_dict['c576'])
- zfdj_aotu = int(real_data_dict['c472'])
- zfdj_ready = int(real_data_dict['c482'])
- yjfdj_aotu = int(real_data_dict['c572'])
- yjfdj_ready = int(real_data_dict['c582'])
- if battery_voltage <= charge_voltage:
- if charge_device == 1 and fdj_run == 0 and zfdj_aotu == 1 and zfdj_ready == 1:
- charge_connectors.send_command([{"length": 0, "start_addr": 20483, "output_value": 65280, "function_code": 5}]) #启动主发电机
- elif charge_device == 2 and fdj_run == 0 and yjfdj_aotu == 1 and yjfdj_ready == 1:
- charge_connectors.send_command([{"length": 0, "start_addr": 20485, "output_value": 65280, "function_code": 5}]) #启动应急发电机
- else:
- self._log.info('[AutoCharge]—参数获取失败')
|