Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-WIC-Opencpc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenXG
OpenXG-WIC-Opencpc
Commits
d187bcec
Commit
d187bcec
authored
Apr 15, 2018
by
joliu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加延时器的功能验证
parent
633eae6d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
18 deletions
+22
-18
hfv/resolveMatrix.py
hfv/resolveMatrix.py
+22
-18
No files found.
hfv/resolveMatrix.py
View file @
d187bcec
...
...
@@ -16,41 +16,45 @@ from controllMatrix import *
inputDeviceData
=
np
.
array
([])
def
resolveMatrix
(
inputTask
,
inputTypeList
,
outputNode
,
input
):
def
resolveMatrix
(
inputTask
,
inputTypeList
,
outputNode
):
'''
根据矩阵构建输入输出关系
inputTask: 输入矩阵;inputTypeList: 节点类型列表,指明各个节点的具体功能;outputNode: 输出节点;
inputDeviceData: 输入设备节点状态值
更改获取实时的传感器数据
'''
nodeType
=
inputTypeList
[
outputNode
]
lastNode
=
np
.
where
((
inputTask
.
T
[
outputNode
]
==
1
))[
0
]
if
nodeType
==
0
:
output
=
resolveMatrix
(
inputTask
,
inputTypeList
,
lastNode
[
0
]
,
input
)
output
=
resolveMatrix
(
inputTask
,
inputTypeList
,
lastNode
[
0
])
elif
nodeType
==
1
:
a
=
resolveMatrix
(
inputTask
,
inputTypeList
,
lastNode
[
0
]
,
input
)
b
=
resolveMatrix
(
inputTask
,
inputTypeList
,
lastNode
[
1
]
,
input
)
a
=
resolveMatrix
(
inputTask
,
inputTypeList
,
lastNode
[
0
])
b
=
resolveMatrix
(
inputTask
,
inputTypeList
,
lastNode
[
1
])
output
=
a
&
b
elif
nodeType
==
2
:
a
=
resolveMatrix
(
inputTask
,
inputTypeList
,
lastNode
[
0
]
,
input
)
b
=
resolveMatrix
(
inputTask
,
inputTypeList
,
lastNode
[
1
]
,
input
)
a
=
resolveMatrix
(
inputTask
,
inputTypeList
,
lastNode
[
0
])
b
=
resolveMatrix
(
inputTask
,
inputTypeList
,
lastNode
[
1
])
output
=
a
|
b
elif
nodeType
==
3
:
a
=
resolveMatrix
(
inputTask
,
inputTypeList
,
lastNode
[
0
]
,
input
)
a
=
resolveMatrix
(
inputTask
,
inputTypeList
,
lastNode
[
0
])
output
=
not
a
elif
nodeType
==
5
:
# 延时器
sleepTime
=
getValueByNodeID
(
outputNode
)[
1
]
output
=
resolveMatrix
(
inputTask
,
inputTypeList
,
lastNode
[
0
])
time
.
sleep
(
sleepTime
)
elif
nodeType
==
4
:
output
=
input
[
outputNode
]
print
(
outputNode
)
output
=
getValueByNodeID
(
outputNode
)[
1
]
print
(
output
)
return
output
def
checkMatrix
(
inputTask
,
inputTypeList
,
input
):
def
checkMatrix
(
inputTask
,
inputTypeList
):
# 测试矩阵是否符合要求
input
=
np
.
array
(
input
)
length
=
inputTask
.
shape
[
0
]
zeroList
=
np
.
zeros
(
length
)
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
:
print
(
"输出节点不符合单输出要求"
)
return
False
...
...
@@ -78,15 +82,15 @@ def checkMatrix(inputTask, inputTypeList, input):
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
))
inputTypeList
=
np
.
array
(
json
.
loads
(
inputTypeList
))
if
not
checkMatrix
(
inputTask
,
inputTypeList
,
inputData
):
if
not
checkMatrix
(
inputTask
,
inputTypeList
):
return
(
-
1
,
'矩阵检查不通过'
)
# 获取矩阵宽度
...
...
@@ -99,10 +103,10 @@ def runTask(inputData):
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__"
:
inputData
=
[
0
,
0
,
0
,
0
,
0
,
1
,
0
,
1
]
print
(
runTask
(
inputData
))
print
(
runTask
())
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment