Commit d187bcec authored by joliu's avatar joliu

添加延时器的功能验证

parent 633eae6d
...@@ -16,41 +16,45 @@ from controllMatrix import * ...@@ -16,41 +16,45 @@ from controllMatrix import *
inputDeviceData = np.array([]) inputDeviceData = np.array([])
def resolveMatrix(inputTask, inputTypeList, outputNode, input): def resolveMatrix(inputTask, inputTypeList, outputNode):
''' '''
根据矩阵构建输入输出关系 根据矩阵构建输入输出关系
inputTask: 输入矩阵;inputTypeList: 节点类型列表,指明各个节点的具体功能;outputNode: 输出节点; inputTask: 输入矩阵;inputTypeList: 节点类型列表,指明各个节点的具体功能;outputNode: 输出节点;
inputDeviceData: 输入设备节点状态值 inputDeviceData: 输入设备节点状态值
更改获取实时的传感器数据
''' '''
nodeType = inputTypeList[outputNode] nodeType = inputTypeList[outputNode]
lastNode = np.where((inputTask.T[outputNode] == 1))[0] lastNode = np.where((inputTask.T[outputNode] == 1))[0]
if nodeType == 0: if nodeType == 0:
output = resolveMatrix(inputTask, inputTypeList, lastNode[0], input) output = resolveMatrix(inputTask, inputTypeList, lastNode[0])
elif nodeType == 1: elif nodeType == 1:
a = resolveMatrix(inputTask, inputTypeList, lastNode[0], input) a = resolveMatrix(inputTask, inputTypeList, lastNode[0])
b = resolveMatrix(inputTask, inputTypeList, lastNode[1], input) b = resolveMatrix(inputTask, inputTypeList, lastNode[1])
output = a & b output = a & b
elif nodeType == 2: elif nodeType == 2:
a = resolveMatrix(inputTask, inputTypeList, lastNode[0], input) a = resolveMatrix(inputTask, inputTypeList, lastNode[0])
b = resolveMatrix(inputTask, inputTypeList, lastNode[1], input) b = resolveMatrix(inputTask, inputTypeList, lastNode[1])
output = a | b output = a | b
elif nodeType == 3: elif nodeType == 3:
a = resolveMatrix(inputTask, inputTypeList, lastNode[0], input) a = resolveMatrix(inputTask, inputTypeList, lastNode[0])
output = not a output = not a
elif nodeType == 5:
# 延时器
sleepTime = getValueByNodeID(outputNode)[1]
output = resolveMatrix(inputTask, inputTypeList, lastNode[0])
time.sleep(sleepTime)
elif nodeType == 4: elif nodeType == 4:
output = input[outputNode] print(outputNode)
output = getValueByNodeID(outputNode)[1]
print(output)
return output return output
def checkMatrix(inputTask, inputTypeList, input): def checkMatrix(inputTask, inputTypeList):
# 测试矩阵是否符合要求 # 测试矩阵是否符合要求
input = np.array(input)
length = inputTask.shape[0] length = inputTask.shape[0]
zeroList = np.zeros(length) zeroList = np.zeros(length)
outputNode = np.where((inputTask == zeroList).all(1))[0] outputNode = np.where((inputTask == zeroList).all(1))[0]
if input.shape[0] != length:
print("输入节点数据异常 %d: %d" % (length, inputDeviceData.shape[0]), input)
return False
if outputNode.shape[0] != 1: if outputNode.shape[0] != 1:
print("输出节点不符合单输出要求") print("输出节点不符合单输出要求")
return False return False
...@@ -78,15 +82,15 @@ def checkMatrix(inputTask, inputTypeList, input): ...@@ -78,15 +82,15 @@ def checkMatrix(inputTask, inputTypeList, input):
return True return True
def runTask(inputData): def runTask():
# 输入各个节点的状态信息 # 输入各个节点的状态信息
(id, inputTask, inputTypeList, status, deviceList) = getTaskFromDB() (id, inputTask, inputTypeList, status, deviceList, ctime) = getTaskFromDB()
inputTask = np.array(json.loads(inputTask)) inputTask = np.array(json.loads(inputTask))
inputTypeList = np.array(json.loads(inputTypeList)) inputTypeList = np.array(json.loads(inputTypeList))
if not checkMatrix(inputTask, inputTypeList, inputData): if not checkMatrix(inputTask, inputTypeList):
return (-1, '矩阵检查不通过') return (-1, '矩阵检查不通过')
# 获取矩阵宽度 # 获取矩阵宽度
...@@ -99,10 +103,10 @@ def runTask(inputData): ...@@ -99,10 +103,10 @@ def runTask(inputData):
inputNodes = np.where((inputTask.T == zeroList).all(1))[0] inputNodes = np.where((inputTask.T == zeroList).all(1))[0]
return (1, resolveMatrix(inputTask, inputTypeList, outputNode[0], inputData)) return (1, resolveMatrix(inputTask, inputTypeList, outputNode[0]))
if __name__ == "__main__": if __name__ == "__main__":
inputData = [0,0,0,0,0,1,0,1] inputData = [0,0,0,0,0,1,0,1]
print(runTask(inputData)) print(runTask())
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