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
633eae6d
Commit
633eae6d
authored
Apr 15, 2018
by
joliu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
任务循环处理模块
parent
a5c6b6d1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
96 deletions
+6
-96
hfv/workProcess.py
hfv/workProcess.py
+6
-96
No files found.
hfv/workProcess.py
View file @
633eae6d
'''
****************************************************
* 任务执行模块 *
* 1. 检查任务队列是否存在任务 *
* 2. 从任务队列中取任务并执行 *
* 3. 发送控制命令到指定的智能体 *
* 4. 读取全部任务队列中任务,并依次执行 *
* 5. 未来或许可以根据配置的智能体参数, *
* 动态修改智能体的计算资源等 *
* *
* author: joliu<joliu@s-an.org> *
* date: 2018-3-22 *
****************************************************
'''
from
controllMatrix
import
*
from
resolveMatrix
import
runTask
from
listenSer
import
sendBySocket
from
listenSer
import
sendCommandToDevice
import
sqlite3
import
time
while
True
:
def
findTask
():
try
:
sql
=
"select * from task"
conn
=
sqlite3
.
connect
(
"task.db"
)
cursor
=
conn
.
cursor
()
cursor
.
execute
(
sql
)
data
=
cursor
.
fetchall
()
if
data
is
None
:
(
status
,
output
)
=
(
-
1
,
'database is empty!'
)
else
:
(
status
,
output
)
=
(
1
,
data
)
except
sqlite3
.
Error
as
err_msg
:
(
status
,
output
)
=
(
-
1
,
err_msg
)
except
Exception
as
err_msg
:
(
status
,
output
)
=
(
-
1
,
err_msg
)
finally
:
return
(
status
,
output
)
# 根据任务队列中任务,依次执行
def
doTask
():
(
status
,
outputs
)
=
findTask
()
if
status
!=
1
:
return
(
status
,
outputs
)
for
output
in
outputs
:
(
task
,
taskid
,
ctime
)
=
output
if
len
(
task
.
split
(
';'
))
!=
2
or
len
(
task
.
split
(
':'
))
!=
3
:
print
(
"Error task: %s"
%
task
)
continue
# 初步定义task字符串模式 eg: >30;192.168.1.1:3000:off
(
condition
,
command
)
=
task
.
split
(
';'
)
(
ip
,
port
,
method
)
=
command
.
split
(
':'
)
# 构建控制命令
method
=
'device&'
+
method
# 读取传感器数值
(
status
,
data
)
=
sendCommandToDevice
(
method
)
# 千杀的dht11,需要处理下数据
data
=
data
.
split
(
'&'
)[
0
]
print
(
output
)
if
status
==
-
1
:
print
(
"get device data failed! ip: %s, method: %s"
%
(
ip
,
method
))
return
(
status
,
"get device data failed! ip: %s, method: %s"
%
(
ip
,
method
))
if
compare
(
condition
[
0
],
float
(
data
),
float
(
condition
[
1
:])):
# 当结果为真,向目标传感器发出指令
(
status
,
recvdata
)
=
sendBySocket
(
ip
,
int
(
port
),
method
)
print
(
recvdata
)
time
.
sleep
(
ctime
)
else
:
pass
return
(
1
,
'success'
)
# 根据符号来比较两个数值的大小
def
compare
(
signal
,
value1
,
value2
):
if
signal
==
'>'
:
return
value1
>
value2
elif
signal
==
'<'
:
return
value1
<
value2
elif
signal
==
'='
:
return
value1
==
value2
else
:
return
False
def
mainWhileProcess
(
input_ctime
):
while
True
:
print
(
"cycle time :"
+
str
(
input_ctime
))
time
.
sleep
(
input_ctime
)
(
status
,
output
)
=
doTask
()
print
(
output
)
if
__name__
==
"__main__"
:
mainWhileProcess
(
5
)
ctime
=
getCircleTime
()
print
(
runTask
())
time
.
sleep
(
ctime
)
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