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
alex037yang
openXG-WIC-Opencpc
Commits
b5602872
Commit
b5602872
authored
May 10, 2018
by
joliu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分布式物联网控制器终端
parent
d3d66520
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
105 additions
and
18 deletions
+105
-18
controller/bin/__pycache__/controler.cpython-34.pyc
controller/bin/__pycache__/controler.cpython-34.pyc
+0
-0
controller/bin/controler.pyc
controller/bin/controler.pyc
+0
-0
controller/bin/show.py
controller/bin/show.py
+0
-12
controller/console.py
controller/console.py
+11
-5
controller/opencps/controler.py
controller/opencps/controler.py
+9
-1
controller/opencps/node.py
controller/opencps/node.py
+29
-0
controller/opencps/show.py
controller/opencps/show.py
+56
-0
No files found.
controller/bin/__pycache__/controler.cpython-34.pyc
deleted
100644 → 0
View file @
d3d66520
File deleted
controller/bin/controler.pyc
deleted
100644 → 0
View file @
d3d66520
File deleted
controller/bin/show.py
deleted
100644 → 0
View file @
d3d66520
from
controler
import
execute
import
sys
if
len
(
sys
.
argv
)
!=
3
:
print
(
"Usage: port database_name"
)
exit
(
0
)
cmd
=
"controller&show&%s"
%
sys
.
argv
[
2
]
execute
(
int
(
sys
.
argv
[
1
]),
cmd
)
controller/console.py
View file @
b5602872
import
subprocess
import
subprocess
import
pymysql
def
Print
(
msg
):
def
Print
(
msg
):
print
(
msg
)
print
(
msg
)
def
Input
():
def
Input
():
print
(
"
\033
[1;35mopencps $
\033
[0m"
,
end
=
''
)
print
(
"
\033
[1;35mopencps $
\033
[0m"
,
end
=
''
)
return
input
()
return
input
()
command_list
=
subprocess
.
getoutput
(
'cd
bin
&& ls *.py'
).
split
(
'
\n
'
)
command_list
=
subprocess
.
getoutput
(
'cd
opencps
&& ls *.py'
).
split
(
'
\n
'
)
commands
=
[
x
.
split
(
'.'
)[
0
]
for
x
in
command_list
if
x
!=
'controler.py'
]
commands
=
[
x
.
split
(
'.'
)[
0
]
for
x
in
command_list
if
x
!=
'controler.py'
]
while
True
:
while
True
:
...
@@ -24,11 +25,16 @@ while True:
...
@@ -24,11 +25,16 @@ while True:
Print
(
'Illegal Command!'
)
Print
(
'Illegal Command!'
)
continue
continue
else
:
else
:
'''
c_list = cmd.split(' ')
c_list = cmd.split(' ')
run_commands = "python3 "
run_commands = "python3 "
c_list
[
0
]
=
'
bin
/'
+
c_list
[
0
]
+
'.py'
c_list[0] = '
opencps
/' + c_list[0] + '.py'
c_list = ['python'] + c_list
c_list = ['python'] + c_list
subprocess.call((c_list))
subprocess.call((c_list))
'''
c_list
=
cmd
.
split
(
' '
)
run_commands
=
"cd opencps&&python3 "
+
c_list
[
0
]
+
'.py '
for
i
in
range
(
1
,
len
(
c_list
)):
run_commands
=
run_commands
+
c_list
[
i
]
+
' '
print
(
subprocess
.
getoutput
(
run_commands
))
controller/
bin
/controler.py
→
controller/
opencps
/controler.py
View file @
b5602872
...
@@ -8,7 +8,15 @@ def execute(port, message):
...
@@ -8,7 +8,15 @@ def execute(port, message):
s
.
connect
((
"192.168.12.19"
,
port
))
s
.
connect
((
"192.168.12.19"
,
port
))
s
.
sendall
(
message
.
encode
())
s
.
sendall
(
message
.
encode
())
response
=
s
.
recv
(
1024
).
decode
()
response
=
s
.
recv
(
1024
).
decode
()
print
(
response
)
return
json
.
loads
(
response
)
def
Print
(
data
):
print
(
format
(
data
,
"<20"
),
end
=
''
)
def
PrintTitle
(
title
):
for
t
in
title
:
Print
(
t
)
print
(
''
)
controller/opencps/node.py
0 → 100644
View file @
b5602872
import
pymysql
def
showDevice
():
output
=
''
try
:
sql
=
'select * from deviceinfo'
conn
=
pymysql
.
connect
(
host
=
'127.0.0.1'
,
port
=
12306
,
user
=
'root'
,
passwd
=
'Vudo3423'
,
db
=
'HiDockerwifi'
,
charset
=
'utf8'
)
cur
=
conn
.
cursor
()
cur
.
execute
(
sql
)
output
=
cur
.
fetchall
()
#print(output)
except
pymysql
.
Error
as
err_msg
:
print
(
err_msg
)
except
Exception
as
err_msg
:
print
(
err_msg
)
finally
:
cur
.
close
()
conn
.
close
()
return
output
if
__name__
==
"__main__"
:
device_data
=
showDevice
()
print
(
format
(
"deviceID"
,
"<20"
),
format
(
"IP"
,
"<20"
),
format
(
"status"
,
"<20"
),
format
(
"network status"
))
for
device
in
device_data
:
if
device
[
3
]
==
1
:
status
=
'on-line'
else
:
status
=
'off-line'
#print("%s\t\t%s\t%s\t%s" % (device[1], device[2], status, device[4]))
print
(
format
(
device
[
1
],
"<20"
),
format
(
device
[
2
],
"<20"
),
format
(
status
,
"<20"
),
format
(
device
[
4
]))
controller/opencps/show.py
0 → 100644
View file @
b5602872
from
controler
import
execute
import
sys
import
pymysql
import
json
def
findDevicePort
(
deviceID
):
output
=
''
try
:
sql
=
'select port from portdb where equip="%s"'
%
deviceID
conn
=
pymysql
.
connect
(
host
=
'127.0.0.1'
,
port
=
12306
,
user
=
'root'
,
passwd
=
'Vudo3423'
,
db
=
'HiDockerwifi'
,
charset
=
'utf8'
)
cur
=
conn
.
cursor
()
cur
.
execute
(
sql
)
output
=
cur
.
fetchone
()
#print(output)
except
pymysql
.
Error
as
err_msg
:
print
(
err_msg
)
except
Exception
as
err_msg
:
print
(
err_msg
)
finally
:
cur
.
close
()
conn
.
close
()
return
output
def
Print
(
data
):
print
(
format
(
data
,
"<20"
),
end
=
''
)
def
PrintTitle
(
title
):
for
t
in
title
:
Print
(
t
)
print
(
''
)
if
__name__
==
"__main__"
:
if
len
(
sys
.
argv
)
!=
3
:
print
(
"Usage: nodeID database_name"
)
exit
(
0
)
port
=
findDevicePort
(
sys
.
argv
[
1
])[
0
]
cmd
=
"controller&show&%s"
%
sys
.
argv
[
2
]
(
status
,
output
)
=
execute
(
port
,
cmd
)
if
status
==
0
:
print
(
"can't find this database, please check your input"
)
if
sys
.
argv
[
2
]
==
'datacach'
:
output
=
json
.
loads
(
output
)
title_list
=
[
'DeviceID'
,
'Data'
,
'Updata Time'
,
'Status'
]
PrintTitle
(
title_list
)
if
output
==
[]:
output
=
None
else
:
for
items
in
output
:
items
.
remove
(
items
[
0
])
for
item
in
items
:
Print
(
item
)
print
(
''
)
elif
sys
.
argv
[
2
]
==
'decide'
:
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