basically done again
This commit is contained in:
@ -81,23 +81,18 @@ def handle_exception(func):
|
||||
return wrapper
|
||||
|
||||
|
||||
log_path = f"assets/logs"
|
||||
PREFIX = "resources/assets" # for pyinstaller
|
||||
# PREFIX = "assets" # for local testing
|
||||
log_path = f"{PREFIX}/logs"
|
||||
lock = threading.Lock()
|
||||
running = [0, 0, 0, 0, 0, 0, 0] # 制动数据/转矩数据/激光数据/精度数据/制动自动化/转矩自动化/耐久数据采集
|
||||
functions = ["制动数据处理", "转矩数据处理", "激光数据处理", "精度数据处理", "制动自动化测试", "转矩自动化测试", "耐久数据采集"]
|
||||
levels = ["DEBUG", "INFO", "WARNING", "ERROR"]
|
||||
ip_addr, ssh_port, socket_port, xService_port, external_port, modbus_port, upgrade_port = "", 22, 5050, 6666, 8080, 502, 4567
|
||||
username, password = "luoshi", "luoshi2019"
|
||||
INTERVAL, RADIAN, MAX_FRAME_SIZE, MAX_LOG_NUMBER = 1, 57.3, 1024, 10
|
||||
INTERVAL, RADIAN, MAX_FRAME_SIZE, MAX_LOG_NUMBER, CYCLE = 1, 57.3, 1024, 10, 300
|
||||
c_md, c_hr, c_ec, c_pd, conn, cursor, search_records = None, None, None, None, None, None, None
|
||||
status = {"mysql": 0, "hmi": 0, "md": 0, "ec": 0}
|
||||
c_joint_vel, c_servo_trq, c_sensor_trq, c_estimate_trans_trq, c_safety_estop = 1, 2, 3, 4, 3 # 各个指标所在列
|
||||
|
||||
init_logdb()
|
||||
|
||||
# ============== ↓↓↓DEBUG CODE↓↓↓ ==============
|
||||
for i in range(100):
|
||||
logger("DEBUG", "clibs", 'running123', flag="cursor")
|
||||
logger("INFO", "aio", 'running234', flag="cursor")
|
||||
logger("WARNING", "openapi", 'running345', flag="cursor")
|
||||
logger("ERROR", "brake", 'running456', flag="cursor")
|
||||
|
@ -745,7 +745,7 @@ class HmiRequest(QThread):
|
||||
def execution(self, command, **kwargs):
|
||||
req = None
|
||||
try:
|
||||
with open(f"assets/files/protocols/hmi/{command}.json", encoding="utf-8", mode="r") as f_json:
|
||||
with open(f"{clibs.PREFIX}/files/protocols/hmi/{command}.json", encoding="utf-8", mode="r") as f_json:
|
||||
req = json.load(f_json)
|
||||
t = datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")
|
||||
req["id"] = f"{command}@{t}"
|
||||
@ -768,12 +768,14 @@ class HmiRequest(QThread):
|
||||
cmd = json.dumps(req, separators=(",", ":"))
|
||||
try:
|
||||
self.c.send(self.package(cmd))
|
||||
time.sleep(clibs.INTERVAL/4)
|
||||
self.logger("DEBUG", "openapi", f"hmi: 老协议请求发送成功 {cmd}")
|
||||
except Exception as err:
|
||||
self.logger("ERROR", "openapi", f"hmi: 老协议请求发送失败 {cmd},报错信息 {err}", "red", "CommandSendFailed")
|
||||
elif flag == 1:
|
||||
try:
|
||||
self.c_xs.send(self.package_xs(req))
|
||||
time.sleep(clibs.INTERVAL/4)
|
||||
self.logger("DEBUG", "openapi", f"hmi: xService请求发送成功 {req}")
|
||||
except Exception as Err:
|
||||
self.logger("ERROR", "openapi", f"hr: xService请求发送失败 {req} 报错信息 {Err}", "red", "CommandSendFailed")
|
||||
@ -1804,9 +1806,9 @@ class ExternalCommunication(QThread):
|
||||
if clibs.status["ec"]:
|
||||
try:
|
||||
self.c.close()
|
||||
self.logger("INFO", "openapi", f"ec: 关闭 EC 连接成功", "green")
|
||||
self.logger("INFO", "openapi", f"ec: 关闭外部通信连接成功", "green")
|
||||
except Exception as err:
|
||||
self.logger("ERROR", "openapi", f"ec: 关闭 EC 连接失败:{err}", "red", "EcCloseFailed")
|
||||
self.logger("ERROR", "openapi", f"ec: 关闭外部通信连接失败:{err}", "red", "EcCloseFailed")
|
||||
|
||||
def s_string(self, directive):
|
||||
order = "".join([directive, self.suffix])
|
||||
@ -2057,7 +2059,7 @@ class ExternalCommunication(QThread):
|
||||
self.s_string(directive)
|
||||
time.sleep(clibs.INTERVAL)
|
||||
result = self.r_string(directive).strip()
|
||||
self.logger("INFO", "openapi", f"ec: 执行{description}指令是 {directive},返回值为 {result}{more_desc}")
|
||||
self.logger("DEBUG", "openapi", f"ec: 执行{description}指令是 {directive},返回值为 {result}{more_desc}")
|
||||
return result
|
||||
|
||||
|
||||
@ -2167,9 +2169,9 @@ class RobotInit(object):
|
||||
interactive_data = f"/home/luoshi/bin/controller/interactive_data/{robot_type}"
|
||||
|
||||
config_files = [
|
||||
f"assets/files/projects/fieldbus_device.json",
|
||||
f"assets/files/projects/registers.json",
|
||||
f"assets/files/projects/registers.xml"
|
||||
f"{clibs.PREFIX}/files/projects/fieldbus_device.json",
|
||||
f"{clibs.PREFIX}/files/projects/registers.json",
|
||||
f"{clibs.PREFIX}/files/projects/registers.xml"
|
||||
]
|
||||
for config_file in config_files:
|
||||
filename = config_file.split("/")[-1]
|
||||
@ -2197,10 +2199,10 @@ class RobotInit(object):
|
||||
os.remove(io_device_file_local_tmp)
|
||||
except:
|
||||
...
|
||||
clibs.c_hr.execution("io_device.load_cfg")
|
||||
clibs.c_hr.execution("modbus.load_cfg")
|
||||
clibs.c_hr.execution("fieldbus_device.load_cfg")
|
||||
clibs.c_hr.execution("fieldbus_device.set_params", device_name="autotest", enable=True)
|
||||
clibs.c_hr.execution("io_device.load_cfg")
|
||||
clibs.c_hr.execution("modbus.load_cfg")
|
||||
|
||||
def robot_init(self):
|
||||
pd = PreDos(clibs.ip_addr, clibs.ssh_port, clibs.username, clibs.password)
|
||||
|
Reference in New Issue
Block a user