This commit is contained in:
gac-S_Changer
2018-06-07 16:31:33 +02:00
parent 4af6939fb4
commit 640fc477fe
7 changed files with 254 additions and 15 deletions

View File

@@ -53,6 +53,15 @@ def system_check(robot_move=True):
raise Exception("Guiding tool not parked")
def start_puck_detection():
run("tools/RestartPuckDetection")
def check_puck_detection():
return run("tools/CheckPuckDetection")
def stop_puck_detection():
run("tools/StopPuckDetection")
###################################################################################################
# Device initialization
###################################################################################################

View File

@@ -0,0 +1,6 @@
USR,PWD = "pi", "raspberry"
HOST,PORT = "tell-raspberrypi", 22
CMD= "sudo systemctl status puck_detection.service"
ret = run("tools/SshExec")
set_return(ret)

View File

@@ -0,0 +1,6 @@
USR,PWD = "pi", "raspberry"
HOST,PORT = "tell-raspberrypi", 22
CMD= "sudo systemctl stop puck_detection.service;sudo systemctl start puck_detection.service"
ret = run("tools/SshExec")
set_return(ret)

61
script/tools/SshExec.py Normal file
View File

@@ -0,0 +1,61 @@
import com.jcraft.jsch.Channel as Channel
import com.jcraft.jsch.ChannelShell as ChannelShell
import com.jcraft.jsch.JSch as JSch
import com.jcraft.jsch.JSchException as JSchException
import com.jcraft.jsch.Session as Session
import java.lang.System as System
import java.io.PrintStream as PrintStream
#Parameters:
#CMD
#USR
#PWD
#HOST
#PORT
jsch= JSch()
session=jsch.getSession(USR, HOST, PORT)
session.setPassword(PWD)
session.setConfig("StrictHostKeyChecking", "no")
session.connect()
#channel=session.openChannel("shell")
#input_stream=channel.getInputStream()
#output_stream = channel.getOutputStream()
#print_stream = PrintStream(output_stream, True)
#print_stream.println("ls")
channel=session.openChannel("exec")
channel.setCommand(CMD)
channel.setInputStream(None)
channel.setOutputStream(System.out)
channel.setErrStream(System.err)
input_stream=channel.getInputStream()
def wait_ret():
global input_stream
rx = ""
while True:
while (input_stream.available() > 0):
i = input_stream.read()
if i < 0:
break
rx=rx+chr(i)
if channel.closed:
break
time.sleep(0.1)
return rx
channel.connect()
try:
ret = wait_ret()
except:
channel.disconnect()
session.disconnect()
raise
set_return(ret)

View File

@@ -0,0 +1,8 @@
USR,PWD = "pi", "raspberry"
HOST,PORT = "tell-raspberrypi", 22
CMD= "sudo systemctl stop puck_detection.service"
ret = run("tools/SshExec")
set_return(ret)