Commit cd859853 authored by 方开's avatar 方开 🍔
Browse files

修复虫害和气体重置问题

parent 07699eec
......@@ -103,7 +103,8 @@ def getConfig(configData: dict):
elif subType == "bug":
cmds = [
"0301" + subAddr + "0000000101f0" +
subMachineData.get("channelId")
subMachineData.get("channelId"),
"0301" + subAddr + "0000000101ff" + "02"
]
bugList.append(subId)
allList.append(subId)
......@@ -113,7 +114,7 @@ def getConfig(configData: dict):
cmds = [
"0301" + subAddr + "0000000101" +
subMachineData.get("channelId"),
"0301" + subAddr + "0000000101ff" + "02"
"0301" + subAddr + "0000000101ff" + "03"
]
airList.append(subId)
allList.append(subId)
......
......@@ -33,11 +33,11 @@ class GetCmds(object):
return self.houseData[types]
# 通过子模块编号来获取子模块的所有命令
def getCmdsBySubId(self, subId):
def getCmdsBySubId(self, subId, types=None):
# 对于通风状态区别开来
cmds = self.houseData["cmds"]
windData = self.houseData["wind"]
if len(windData) != 0:
windData = self.houseData["wind"]
if types == "wind" and len(windData) != 0:
for subData in cmds:
if subId in subData:
windStatusCmd = subData[subId][0].get("status")
......
......@@ -98,7 +98,7 @@ def checkData(data: bytes, houseType: str, measureType: str, pointnum):
# 返回数据的最后两个字节代表1-16路的开关状态
elif flag == "a3" and measureType == "wind":
windData = (bin(int(data[-4:], 16))[2:]).zfill(16)
windData = windData[6:12]
windData = windData[6:16]
logging.info(f"通风状态数据为{windData}")
return [windData]
# 气象站
......@@ -277,7 +277,7 @@ def measureit(houseId, measureType="all", timeout=2):
socket.AF_INET, socket.SOCK_STREAM)
logging.info(f"正在向虫害分机发送复位指令{resetCmd}")
tcpSocket.connect(addr)
tcpSocket.send(cmd)
tcpSocket.send(resetCmd.encode())
except Exception as e:
logging.info(f"发送复位指令异常:{e}")
......@@ -320,7 +320,7 @@ def measureit(houseId, measureType="all", timeout=2):
windList = []
for subId in subIds:
# 如果命令列表数据不为空
addr, cmds, pointNum = gc.getCmdsBySubId(subId)
addr, cmds, pointNum = gc.getCmdsBySubId(subId, types="wind")
if cmds:
cmd = cmds[0]
data = measureClient(addr, a2b_hex(
......@@ -344,20 +344,22 @@ def controlit(houseId, measureType="wind", flag="on", timeout=3):
gc = GetCmds(houseId)
houseType = gc.houseType
SubId = gc.getSubIdByType(measureType)
SubId = "".join(SubId)
addr, cmds = gc.getCmdsByFlag(SubId, flag)
# 如果获取到指定的命令
if cmds:
result = []
for cmd in cmds:
data = measureClient(addr, a2b_hex(
cmd), measureType, houseType, None, timeout)
result.extend(data)
time.sleep(2)
return data
else:
logging.warning(f"无通风命令,请检查通风设置参数是否正确")
return []
result = []
for subid in SubId:
addr, cmds = gc.getCmdsByFlag(subid, flag)
# 如果获取到指定的命令
if cmds:
for cmd in cmds:
# 取最后一次结果
data = measureClient(addr, a2b_hex(
cmd), measureType, houseType, None, timeout)
time.sleep(2)
result.append(data)
else:
logging.warning(f"无通风命令,请检查通风设置参数是否正确")
result.append(None)
return result
except Exception as e:
logging.info(f"控制通风错误:{e}")
return []
......@@ -400,9 +402,9 @@ def handleCommand(command: str):
alldict["water"] = [
{"species": cerealsSpecies, "data": data}]
elif tp in ["temp", "temphumi", "bug", "air", "weather","wind"]:
elif tp in ["temp", "temphumi", "bug", "air", "weather", "wind"]:
alldict[tp] = [{"species": tp, "data": data}]
else:
pass
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