mirror of
https://github.com/OSURoboticsClub/Rover_2017_2018.git
synced 2025-11-08 10:11:14 +00:00
Equipment servicing now working and integrated. Will have to have the ip changed after we know what it is.
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
from PyQt5 import QtCore, QtWidgets, QtGui
|
from PyQt5 import QtCore, QtWidgets, QtGui
|
||||||
import logging
|
import logging
|
||||||
from time import time
|
from time import time
|
||||||
|
import paramiko
|
||||||
|
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
@@ -13,11 +14,18 @@ from time import time
|
|||||||
#####################################
|
#####################################
|
||||||
THREAD_HERTZ = 5
|
THREAD_HERTZ = 5
|
||||||
|
|
||||||
|
IP = "192.168.1.10"
|
||||||
|
USER = "nvidia"
|
||||||
|
PASS = "nvidia"
|
||||||
|
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
# UbiquitiRadioSettings Class Definition
|
# BashConsole Class Definition
|
||||||
#####################################
|
#####################################
|
||||||
class BashConsole(QtCore.QThread):
|
class BashConsole(QtCore.QThread):
|
||||||
|
|
||||||
|
text_update_ready__signal = QtCore.pyqtSignal(str)
|
||||||
|
|
||||||
def __init__(self, shared_objects):
|
def __init__(self, shared_objects):
|
||||||
super(BashConsole, self).__init__()
|
super(BashConsole, self).__init__()
|
||||||
|
|
||||||
@@ -25,7 +33,19 @@ class BashConsole(QtCore.QThread):
|
|||||||
self.shared_objects = shared_objects
|
self.shared_objects = shared_objects
|
||||||
self.left_screen = self.shared_objects["screens"]["left_screen"]
|
self.left_screen = self.shared_objects["screens"]["left_screen"]
|
||||||
|
|
||||||
self.ssh_widget = self.left_screen.ssh_console_widget # type: QtWidgets.QSpinBox
|
self.console_text_edit = self.left_screen.console_line_edit # type: QtWidgets.QTextEdit
|
||||||
|
self.ssh_console_command_line_edit = self.left_screen.ssh_console_command_line_edit # type:QtWidgets.QLineEdit
|
||||||
|
|
||||||
|
self.ssh_list_wifi_button = self.left_screen.ssh_list_wifi_button # type: QtWidgets.QPushButton
|
||||||
|
self.ssh_equipment_login_button = self.left_screen.ssh_equipment_login_button # type: QtWidgets.QPushButton
|
||||||
|
self.ssh_equipment_logout_button = self.left_screen.ssh_equipment_logout_button # type: QtWidgets.QPushButton
|
||||||
|
self.ssh_equipment_status_button = self.left_screen.ssh_equipment_status_button # type: QtWidgets.QPushButton
|
||||||
|
self.ssh_equipment_start_button = self.left_screen.ssh_equipment_start_button # type: QtWidgets.QPushButton
|
||||||
|
self.ssh_equipment_stop_button = self.left_screen.ssh_equipment_stop_button # type: QtWidgets.QPushButton
|
||||||
|
|
||||||
|
self.ssh_ssid_line_edit = self.left_screen.ssh_ssid_line_edit # type:QtWidgets.QLineEdit
|
||||||
|
self.ssh_connect_ssid_push_button = self.left_screen.ssh_ssid_push_button # type: QtWidgets.QPushButton
|
||||||
|
self.ssh_disconnect_wifi_button = self.left_screen.ssh_disconnect_wifi_button # type: QtWidgets.QPushButton
|
||||||
|
|
||||||
# ########## Get the settings instance ##########
|
# ########## Get the settings instance ##########
|
||||||
self.settings = QtCore.QSettings()
|
self.settings = QtCore.QSettings()
|
||||||
@@ -37,18 +57,114 @@ class BashConsole(QtCore.QThread):
|
|||||||
self.run_thread_flag = True
|
self.run_thread_flag = True
|
||||||
|
|
||||||
# ########## Class Variables ##########
|
# ########## Class Variables ##########
|
||||||
|
self.bash_process = None
|
||||||
|
self.new_widget = None
|
||||||
|
self.window = None
|
||||||
|
|
||||||
self.wait_time = 1.0 / THREAD_HERTZ
|
self.wait_time = 1.0 / THREAD_HERTZ
|
||||||
|
|
||||||
|
self.ssh_client = None
|
||||||
|
|
||||||
|
self.set_text_contents = ""
|
||||||
|
|
||||||
|
self.new_command_text = ""
|
||||||
|
self.new_command = False
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
while not self.ssh_client:
|
||||||
|
try:
|
||||||
|
self.ssh_client = paramiko.SSHClient()
|
||||||
|
self.ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
|
self.ssh_client.connect(IP, username=USER, password=PASS, compress=True)
|
||||||
|
except:
|
||||||
|
print "No connection"
|
||||||
|
self.ssh_client = None
|
||||||
|
self.msleep(1000)
|
||||||
|
|
||||||
while self.run_thread_flag:
|
while self.run_thread_flag:
|
||||||
start_time = time()
|
start_time = time()
|
||||||
|
|
||||||
|
if self.new_command:
|
||||||
|
_, ssh_stdout, ssh_stderr = self.ssh_client.exec_command(self.new_command_text)
|
||||||
|
|
||||||
|
stdout_read = ssh_stdout.read()
|
||||||
|
stderr_read = ssh_stderr.read()
|
||||||
|
|
||||||
|
output = ""
|
||||||
|
output += "\n%s@%s:$" % (USER, IP)
|
||||||
|
output += self.new_command_text + "\n"
|
||||||
|
output += stdout_read.decode("utf-8") if stdout_read else ""
|
||||||
|
output += stderr_read.decode("utf-8") if stderr_read else ""
|
||||||
|
|
||||||
|
self.set_text_contents += output
|
||||||
|
self.text_update_ready__signal.emit(self.set_text_contents)
|
||||||
|
self.new_command = False
|
||||||
|
|
||||||
time_diff = time() - start_time
|
time_diff = time() - start_time
|
||||||
|
|
||||||
self.msleep(max(int(self.wait_time - time_diff), 0))
|
self.msleep(max(int(self.wait_time - time_diff), 0))
|
||||||
|
|
||||||
|
del self.bash_process
|
||||||
|
|
||||||
|
def on_text_readout_updated__slot(self):
|
||||||
|
self.console_text_edit.moveCursor(QtGui.QTextCursor.End)
|
||||||
|
|
||||||
|
def on_text_editing_finished__slot(self):
|
||||||
|
self.new_command_text = self.ssh_console_command_line_edit.text()
|
||||||
|
self.new_command = True
|
||||||
|
|
||||||
|
def on_list_wifi_button_pressed__slot(self):
|
||||||
|
self.new_command_text = "nmcli dev wifi list"
|
||||||
|
self.new_command = True
|
||||||
|
|
||||||
|
def on_login_button_pressed__slot(self):
|
||||||
|
self.new_command_text = "python equipment_servicing_interface.py 'task.cstag.ca' 'LOGIN MTECH GITRDONE' HELP"
|
||||||
|
self.new_command = True
|
||||||
|
|
||||||
|
def on_logout_button_pressed__slot(self):
|
||||||
|
self.new_command_text = "python equipment_servicing_interface.py 'task.cstag.ca' LOGOUT"
|
||||||
|
self.new_command = True
|
||||||
|
|
||||||
|
def on_status_button_pressed__slot(self):
|
||||||
|
self.new_command_text = "python equipment_servicing_interface.py 'task.cstag.ca' STATUS"
|
||||||
|
self.new_command = True
|
||||||
|
|
||||||
|
def on_start_button_pressed__slot(self):
|
||||||
|
self.new_command_text = "python equipment_servicing_interface.py 'task.cstag.ca' START"
|
||||||
|
self.new_command = True
|
||||||
|
|
||||||
|
def on_stop_button_pressed__slot(self):
|
||||||
|
self.new_command_text = "python equipment_servicing_interface.py 'task.cstag.ca' STOP"
|
||||||
|
self.new_command = True
|
||||||
|
|
||||||
|
def on_connect_ssid_button_pressed__slot(self):
|
||||||
|
ssid_text = self.ssh_ssid_line_edit.text()
|
||||||
|
|
||||||
|
self.new_command_text = "sudo nmcli dev wifi connect %s" % ssid_text
|
||||||
|
|
||||||
|
self.new_command = True
|
||||||
|
|
||||||
|
def on_disconnect_ssid_button_pressed__slot(self):
|
||||||
|
ssid_text = self.ssh_ssid_line_edit.text()
|
||||||
|
|
||||||
|
self.new_command_text = "sudo nmcli con down id %s ; sudo nmcli connection delete %s" % (ssid_text, ssid_text)
|
||||||
|
|
||||||
|
self.new_command = True
|
||||||
|
|
||||||
def connect_signals_and_slots(self):
|
def connect_signals_and_slots(self):
|
||||||
pass
|
self.text_update_ready__signal.connect(self.console_text_edit.setText)
|
||||||
|
self.ssh_console_command_line_edit.editingFinished.connect(self.on_text_editing_finished__slot)
|
||||||
|
self.console_text_edit.textChanged.connect(self.on_text_readout_updated__slot)
|
||||||
|
|
||||||
|
self.ssh_equipment_login_button.clicked.connect(self.on_login_button_pressed__slot)
|
||||||
|
self.ssh_equipment_logout_button.clicked.connect(self.on_logout_button_pressed__slot)
|
||||||
|
self.ssh_equipment_status_button.clicked.connect(self.on_status_button_pressed__slot)
|
||||||
|
self.ssh_equipment_start_button.clicked.connect(self.on_start_button_pressed__slot)
|
||||||
|
self.ssh_equipment_stop_button.clicked.connect(self.on_stop_button_pressed__slot)
|
||||||
|
|
||||||
|
self.ssh_list_wifi_button.clicked.connect(self.on_list_wifi_button_pressed__slot)
|
||||||
|
self.ssh_connect_ssid_push_button.clicked.connect(self.on_connect_ssid_button_pressed__slot)
|
||||||
|
self.ssh_disconnect_wifi_button.clicked.connect(self.on_disconnect_ssid_button_pressed__slot)
|
||||||
|
|
||||||
def setup_signals(self, start_signal, signals_and_slots_signal, kill_signal):
|
def setup_signals(self, start_signal, signals_and_slots_signal, kill_signal):
|
||||||
start_signal.connect(self.start)
|
start_signal.connect(self.start)
|
||||||
|
|||||||
@@ -1390,7 +1390,7 @@ N/A</string>
|
|||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>2</number>
|
<number>3</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="tab_5">
|
<widget class="QWidget" name="tab_5">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
@@ -2194,7 +2194,118 @@ Permittivity</string>
|
|||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QGridLayout" name="gridLayout_4">
|
<layout class="QGridLayout" name="gridLayout_4">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QWidget" name="ssh_console_widget" native="true"/>
|
<widget class="QTextEdit" name="console_line_edit"/>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_19">
|
||||||
|
<item>
|
||||||
|
<widget class="Line" name="line_10">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_23">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Preset Commands</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_18">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QPushButton" name="ssh_list_wifi_button">
|
||||||
|
<property name="text">
|
||||||
|
<string>List Wifi</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="2">
|
||||||
|
<widget class="QPushButton" name="ssh_equipment_logout_button">
|
||||||
|
<property name="text">
|
||||||
|
<string>Equipment Logout</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QPushButton" name="ssh_equipment_login_button">
|
||||||
|
<property name="text">
|
||||||
|
<string>Equipment Login and Help</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QPushButton" name="ssh_equipment_status_button">
|
||||||
|
<property name="text">
|
||||||
|
<string>Equipment Status</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QPushButton" name="ssh_equipment_start_button">
|
||||||
|
<property name="text">
|
||||||
|
<string>Equipment Start</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="2">
|
||||||
|
<widget class="QPushButton" name="ssh_equipment_stop_button">
|
||||||
|
<property name="text">
|
||||||
|
<string>Equipment Stop</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_17">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_22">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Command</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="ssh_console_command_line_edit"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_18">
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="ssh_ssid_line_edit"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="ssh_ssid_push_button">
|
||||||
|
<property name="text">
|
||||||
|
<string>Connect SSID</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="ssh_disconnect_wifi_button">
|
||||||
|
<property name="text">
|
||||||
|
<string>Disconnect SSID</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
40
software/scripts/equipment_servicing_interface.py
Normal file
40
software/scripts/equipment_servicing_interface.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import socket
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# Create a UDP socket
|
||||||
|
messages = ["HELP", "LOGIN MTECH GITRDONE", "STATUS", "START", "STOP", "LOGOUT"]
|
||||||
|
|
||||||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
|
||||||
|
server_address = (sys.argv[1], 4547)
|
||||||
|
|
||||||
|
commands = []
|
||||||
|
commands.append(sys.argv[2])
|
||||||
|
|
||||||
|
if len(sys.argv) > 3:
|
||||||
|
commands.append(sys.argv[3])
|
||||||
|
|
||||||
|
for command in commands:
|
||||||
|
if command in messages:
|
||||||
|
sent = sock.sendto(command, server_address)
|
||||||
|
|
||||||
|
data, server = sock.recvfrom(4096)
|
||||||
|
print data
|
||||||
|
|
||||||
|
# while True:
|
||||||
|
# try:
|
||||||
|
# # Send data
|
||||||
|
# message = raw_input()
|
||||||
|
# # print type(message)
|
||||||
|
# if message not in messages:
|
||||||
|
# print "Invalid command. Please try again."
|
||||||
|
# continue
|
||||||
|
#
|
||||||
|
# sent = sock.sendto(message, server_address)
|
||||||
|
#
|
||||||
|
# # Receive response
|
||||||
|
# # print 'waiting to receive'
|
||||||
|
# data, server = sock.recvfrom(4096)
|
||||||
|
# print data
|
||||||
|
# except:
|
||||||
|
# pass
|
||||||
Reference in New Issue
Block a user