Commit 795fdf5e authored by 方开's avatar 方开 🍔
Browse files

并发处理指令

parent f1f69a60
......@@ -253,7 +253,7 @@ def measureit(houseId, measureType="all", timeout=2):
for subId in subIds:
# 如果命令列表数据不为空
addr, cmds, pointNum = gc.getCmdsBySubId(subId)
logging.debug(f"温湿度分机地址为{addr},对应命令为{cmds},点数为{pointNums}")
logging.debug(f"温湿度分机地址为{addr},对应命令为{cmds}")
if cmds:
# 分别存放外温外湿、内温内湿
for cmd in cmds:
......@@ -485,27 +485,34 @@ def recv(tcpSocket):
if not data:
break
logging.info(f"接收到服务器数据: {data}")
if "ff" in data and len(data) < 10:
logging.info("接收心跳响应成功")
if "ff" in data and len(data)<10:
logging.info("接收心跳包成功")
elif "measure" in data or "control" in data:
logging.info("正在处理测试或控制指令")
# 命令处理后发送给服务器
result = handleCommand(data)
if result == None:
logging.info("解析指令和返回数据失败")
else:
sendData = result + "eeffeeff"
logging.info(f"发送给服务器的数据为{sendData}")
tcpSocket.send(sendData.encode())
logging.info("发送给服务器数据完毕")
cmds = data.split("eeffeeff")
for cmd in cmds:
if len(cmd) != 0:
gevent.spawn(multiCmd, cmd, tcpSocket)
else:
logging.info("不明指令,忽略")
logging.info("不明指令")
except Exception as e:
logging.info(f"接收服务器发来的数据异常,详细错误为:{e}")
logging.info(f"接收error:{e}")
returnData = json.dumps({"code": "0"}, ensure_ascii=False) + "eeffeeff"
tcpSocket.send(returnData.encode())
finally:
pass
def multiCmd(cmd, tcpSocket):
result = handleCommand(cmd)
if result == None:
logging.info("解析指令和返回数据失败")
pass
else:
sendData = result + "eeffeeff"
tcpSocket.send(sendData.encode())
logging.info("发送给服务器数据完毕")
# 定时发送心跳信息
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment