Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenCPS
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
Operations
Operations
Metrics
Environments
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
joliu
OpenCPS
Commits
e8395c0a
Commit
e8395c0a
authored
Mar 25, 2018
by
joliu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改最新通过的测试代码
parent
21b45a50
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
12 deletions
+61
-12
tests/hfv1/1.log
tests/hfv1/1.log
+9
-0
tests/hfv1/listenSer.py
tests/hfv1/listenSer.py
+0
-6
tests/hfv1/task.db
tests/hfv1/task.db
+0
-0
tests/hfv2/task.db
tests/hfv2/task.db
+0
-0
tests/hfv2/workProcess.py
tests/hfv2/workProcess.py
+52
-6
No files found.
tests/hfv1/1.log
View file @
e8395c0a
...
...
@@ -129,3 +129,12 @@ Server loop running in thread:Thread-1
Program started
Server loop running in thread:Thread-1
....waiting for connection
Program started
Server loop running in thread:Thread-1
....waiting for connection
Program started
Server loop running in thread:Thread-1
....waiting for connection
Program started
Server loop running in thread:Thread-1
....waiting for connection
tests/hfv1/listenSer.py
View file @
e8395c0a
...
...
@@ -128,12 +128,6 @@ def sendBySocket(ip, port, cmd):
print
(
"Error receiving data: %s"
%
err_msg
)
s
.
close
()
return
(
-
1
,
err_msg
)
try
:
response
=
s
.
recv
(
1024
).
decode
()
except
socket
.
error
as
err_msg
:
print
(
"Error receiving data: %s"
%
err_msg
)
s
.
close
()
return
(
-
1
,
err_msg
)
print
(
str
(
response
))
s
.
close
()
...
...
tests/hfv1/task.db
View file @
e8395c0a
No preview for this file type
tests/hfv2/task.db
View file @
e8395c0a
No preview for this file type
tests/hfv2/workProcess.py
View file @
e8395c0a
...
...
@@ -11,12 +11,18 @@
* date: 2018-3-22 *
****************************************************
'''
from
listenSer
import
sendBySocket
from
listenSer
import
sendCommandToDevice
import
sqlite3
import
time
import
socket
# 发送控制指令到Device
def
sendCommandToDevice
(
cmd
):
# 通过容器的环境变量HOST获取绑定传感器的IP地址
ip
,
port
=
"192.168.12.75"
,
8085
return
sendBySocket
(
ip
,
port
,
cmd
)
def
findTask
():
try
:
...
...
@@ -37,6 +43,42 @@ def findTask():
return
(
status
,
output
)
# 通过socket发送信息
def
sendBySocket
(
ip
,
port
,
cmd
):
try
:
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
except
socket
.
error
as
err_msg
:
print
(
"Error creating socket:%s"
%
err_msg
)
s
.
close
()
return
(
-
1
,
err_msg
)
try
:
s
.
connect
((
ip
,
port
))
except
socket
.
error
as
err_msg
:
print
(
"Address-related error connecting to server: %s"
%
err_msg
)
s
.
close
()
return
(
-
1
,
err_msg
)
print
(
"****************send:"
+
cmd
)
try
:
s
.
sendall
(
cmd
.
encode
())
except
socket
.
error
as
err_msg
:
print
(
"Error sending data: %s"
%
err_msg
)
s
.
close
()
return
(
-
1
,
err_msg
)
try
:
response
=
s
.
recv
(
1024
).
decode
()
print
(
response
)
except
socket
.
error
as
err_msg
:
print
(
"Error receiving data: %s"
%
err_msg
)
s
.
close
()
return
(
-
1
,
err_msg
)
#print(str(response))
s
.
close
()
# 程序运行正常返回目标传感器返回的数据
return
(
1
,
str
(
response
))
# 根据符号来比较两个数值的大小
def
compare
(
signal
,
value1
,
value2
):
if
signal
==
'>'
:
...
...
@@ -70,6 +112,8 @@ def mainWhileProcess(input_ctime):
(
condition
,
command
)
=
task
.
split
(
';'
)
(
ip
,
port
,
method
)
=
command
.
split
(
':'
)
# 构建控制命令
method
=
'device&'
+
method
# 读取传感器数值
(
status
,
output
)
=
sendCommandToDevice
(
method
)
# 千杀的dht11,需要处理下数据
...
...
@@ -81,11 +125,13 @@ def mainWhileProcess(input_ctime):
if
compare
(
condition
[
0
],
float
(
output
),
float
(
condition
[
1
:])):
# 当结果为真,向目标传感器发出指令
(
status
,
output
)
=
sendBySocket
(
ip
,
port
,
method
)
print
(
output
)
(
status
,
output
)
=
sendBySocket
(
ip
,
int
(
port
)
,
method
)
#
print(output)
else
:
pass
print
(
1212
)
if
__name__
==
"__main__"
:
mainWhileProcess
(
5
)
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