Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandoislas committed May 11, 2017
2 parents 1b08652 + ba4fe93 commit b7ab1ee
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/server/control/util/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Controller:
hid_seq_id = 0
hid_update_timestamp = 0
HID_UPDATE_INTERVAL = int((1. / 180.) * 1000.) # 5 - leaving it since it may make sense later
HID_UPDATE_INTERVAL = int((1 / 10) * 1000) # should be 180 per second FIXME python 3 sockets are slow
# Button buffers
button_buffer = (0, 0)
extra_button_buffer = (0, 0)
Expand Down
5 changes: 3 additions & 2 deletions src/server/data/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os

# Info
VERSION = "1.5"
VERSION = "1.6"
NAME = "DRC SIM Server"

# Port
PORT_WII_MSG = 50010
Expand All @@ -14,7 +15,7 @@
PORT_SERVER_CMD = 50002

# Video
WII_VIDEO_WIDTH = 854
WII_VIDEO_WIDTH = 848
WII_VIDEO_HEIGHT = 480
WII_CAMERA_WIDTH = 640
WII_CAMERA_HEIGHT = 480
Expand Down
17 changes: 8 additions & 9 deletions src/server/net/wii/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,16 @@ def update(self, packet, test=False):
# Get image
nals = self.h264_nal_encapsulate(is_idr, self.frame)
image_buffer = self.decoder.get_image_buffer(nals.tostring())
if not image_buffer:
return
# Check fps limit
if ConfigServer.fps < 60 and time.time() - self.last_sent_time < 1. / ConfigServer.fps:
if time.time() - self.last_sent_time < 1. / ConfigServer.fps:
return
# Reduce quality at the expense of CPU
if ConfigServer.quality < 100:
image = Image.frombuffer("RGB", (constants.WII_VIDEO_WIDTH, constants.WII_CAMERA_HEIGHT),
image_buffer, "raw", "RGB", 0, 1)
ib = BytesIO()
image.save(ib, "JPEG", quality=ConfigServer.quality)
ServiceVID.broadcast(ib.getvalue())
else:
ServiceVID.broadcast(image_buffer)
image = Image.frombuffer("RGB", (constants.WII_VIDEO_WIDTH, constants.WII_CAMERA_HEIGHT),
bytes(image_buffer), "raw", "RGB", 0, 1)
ib = BytesIO()
image.save(ib, "JPEG", quality=ConfigServer.quality)
ServiceVID.broadcast(ib.getvalue())
# Update time
self.last_sent_time = time.time()
24 changes: 24 additions & 0 deletions src/server/ui/gui/frame/frame_about.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from tkinter import Label

from src.server.data import constants
from src.server.ui.gui.frame.frame_tab import FrameTab


class FrameAbout(FrameTab):
def __init__(self, master=None, **kw):
super().__init__(master, **kw)
self.text_name = Label(self, text=constants.NAME)
self.text_version = Label(self, text="v" + constants.VERSION)

self.text_name.grid(row=0, column=0)
self.text_version.grid(row=1, column=0)
self.grid_columnconfigure(0, weight=1)

def activate(self):
pass

def deactivate(self):
pass

def kill_other_tabs(self):
return False
7 changes: 6 additions & 1 deletion src/server/ui/gui/frame/frame_get_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ def activate(self):
self.getting_psk = False
self.set_code_text("")
self.progress_bar.start()
self.progress_bar.grid_remove()
if not self.wpa_supplicant or not self.wpa_supplicant.get_status():
self.progress_bar.grid_remove()
self.dropdown_wii_u["values"] = InterfaceUtil.get_wiiu_compatible_interfaces()

def deactivate(self):
Expand All @@ -142,6 +143,7 @@ def deactivate(self):
self.getting_psk = False
if self.wpa_supplicant:
self.wpa_supplicant.stop()
self.wpa_supplicant = None

@staticmethod
def get_image(location, width, height):
Expand All @@ -157,3 +159,6 @@ def set_code_text(self, text):
self.entry_pair_code.delete(0, END)
self.entry_pair_code.insert(0, text)
self.entry_pair_code.config(state="readonly")

def kill_other_tabs(self):
return True
36 changes: 36 additions & 0 deletions src/server/ui/gui/frame/frame_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import subprocess
from tkinter import Button, CENTER, messagebox

from src.server.data import constants
from src.server.ui.gui.frame.frame_tab import FrameTab


class FrameLog(FrameTab):
def __init__(self, master=None, **kw):
super().__init__(master, **kw)
self.button_log = Button(self, text="Open Log in Console")
self.button_log.bind("<Button-1>", self.button_clicked)
self.button_log.place(relx=0.5, rely=0.5, anchor=CENTER)
self.log = None

# noinspection PyUnusedLocal
def button_clicked(self, event):
tail = ["x-terminal-emulator", "-e", "tail", "-f"]
for file in ("drcsim", "cli", "gui", "wpa", "backend"):
tail.append(os.path.join(constants.PATH_LOG_DIR, file + ".log"))
self.deactivate()
try:
self.log = subprocess.Popen(tail, stdout=open(os.devnull, "w"), stderr=subprocess.PIPE)
except FileNotFoundError:
messagebox.showerror("Log Error", "Could not open log window.")

def activate(self):
pass

def deactivate(self):
if self.log and self.log.poll() is None:
self.log.kill()

def kill_other_tabs(self):
return False
11 changes: 9 additions & 2 deletions src/server/ui/gui/frame/frame_run_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ def stop_server(self, event=None):
return
if self.gamepad:
self.gamepad.close()
self.gamepad = None
if self.wpa_supplicant:
self.wpa_supplicant.stop()
self.wpa_supplicant = None
self.activate()

def activate(self):
Expand All @@ -181,8 +183,10 @@ def activate(self):
self.dropdown_wiiu_interface["values"] = InterfaceUtil.get_wiiu_compatible_interfaces()
self.dropdown_normal_interface["values"] = InterfaceUtil.get_all_interfaces()
self.dropdown_region["values"] = ["NONE", "NA"]
self.label_wpa_status["text"] = WpaSupplicant.DISCONNECTED
self.label_backend_status["text"] = Gamepad.STOPPED
self.label_wpa_status["text"] = self.wpa_supplicant.get_status() \
if self.wpa_supplicant and self.wpa_supplicant.get_status() else WpaSupplicant.DISCONNECTED
self.label_backend_status["text"] = self.gamepad.get_status() \
if self.gamepad and self.gamepad.get_status() else Gamepad.STOPPED
self.button_start.config(state="normal")
self.button_stop.config(state="normal")
self.label_interface_info.config(text="")
Expand All @@ -194,3 +198,6 @@ def deactivate(self):
"""
LoggerGui.debug("FrameRunServer deactivated")
self.stop_server()

def kill_other_tabs(self):
return True
3 changes: 3 additions & 0 deletions src/server/ui/gui/frame/frame_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ def activate(self):

def deactivate(self):
raise NotImplementedError()

def kill_other_tabs(self):
raise NotImplementedError()
16 changes: 13 additions & 3 deletions src/server/ui/gui/gui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from tkinter.ttk import Notebook

from src.server.data.resource import Resource
from src.server.ui.gui.frame.frame_about import FrameAbout
from src.server.ui.gui.frame.frame_get_key import FrameGetKey
from src.server.ui.gui.frame.frame_log import FrameLog
from src.server.ui.gui.frame.frame_run_server import FrameRunServer
from src.server.util.logging.logger_gui import LoggerGui

Expand Down Expand Up @@ -33,6 +35,12 @@ def __init__(self):
# Get Key Frame
self.frame_get_key = FrameGetKey(self.notebook)
self.notebook.add(self.frame_get_key, text="Get Key")
# Log Frame
self.frame_log = FrameLog(self.notebook)
self.notebook.add(self.frame_log, text="Log")
# About Frame
self.frame_about = FrameAbout(self.notebook)
self.notebook.add(self.frame_about, text="About")

@staticmethod
def throw(*args):
Expand Down Expand Up @@ -96,7 +104,9 @@ def on_tab_changed(self, event):
tab_index = self.notebook.index(tab_id)
tab_name = self.notebook.tab(tab_index, "text")
LoggerGui.debug("Notebook tab changed to \"%s\" with id %d", tab_name, tab_index)
if self.tab_id:
self.notebook.children[self.tab_id].deactivate()
self.tab_id = tab_id.split(".")[len(tab_id.split(".")) - 1]
self.tab_id = tab_id.split(".")[len(tab_id.split(".")) - 1] # Parse notebook/tab id to only tab id
if self.notebook.children[self.tab_id].kill_other_tabs():
for tab in self.notebook.children:
if tab != self.tab_id:
self.notebook.children[tab].deactivate()
self.notebook.children[self.tab_id].activate()
34 changes: 27 additions & 7 deletions src/server/util/interface_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,38 @@ def is_managed_by_network_manager(cls, interface):
conf = open(constants.PATH_CONF_NETWORK_MANAGER)
conf_data = conf.readlines()
conf.close()
managed = False
for line in conf_data:
if line.startswith("unmanaged") and "mac:" + cls.get_mac(interface) in line:
Logger.debug("Interface \"%s\" is unmanaged by network manager.", interface)
return False
return True
if line.startswith("unmanaged-devices=") and "mac:" + cls.get_mac(interface) not in line:
managed = True # Ensure configs with duplicates raise an unmanaged prompt
Logger.debug("Interface \"%s\" managed by network manager: %s", interface, managed)
return managed

@classmethod
def set_unmanaged_by_network_manager(cls, interface):
Logger.debug("Adding interface \"%s-%s\" as an unmanaged interface to network manager", interface,
cls.get_mac(interface))
conf = open(constants.PATH_CONF_NETWORK_MANAGER, "a")
conf.writelines(["[keyfile]\n", "unmanaged-devices=mac:" + cls.get_mac(interface) + "\n"])
conf.close()
with open(constants.PATH_CONF_NETWORK_MANAGER, "r") as conf_read:
conf = conf_read.read().splitlines()
added = False
entry = "mac:" + cls.get_mac(interface)
# Add Entry
for line in range(0, len(conf)):
# Add keyfile plugin if it's not enabled
if conf[line].startswith("plugins=") and "keyfile" not in conf[line]:
conf[line] += ",keyfile"
# Add unmanaged device
if conf[line].startswith("unmanaged-devices=") and entry not in conf[line]:
conf[line] += ";" + entry
added = True
# Add the initial unmanaged entry if it was not present
if not added:
conf.append("[keyfile]")
conf.append("unmanaged-devices=" + entry)
# Write
with open(constants.PATH_CONF_NETWORK_MANAGER, "w") as conf_write:
for line in conf:
conf_write.write(line + "\n")
# Restart the service
ProcessUtil.call(["service", "network-manager", "restart"])
ProcessUtil.call(["service", "networking", "restart"])
7 changes: 7 additions & 0 deletions src/server/util/status_sending_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def set_status(self, status):
for listener in self.status_change_listeners:
listener(status)

def get_status(self):
"""
Status getter
:return: status string
"""
return self.status

def add_status_change_listener(self, callback):
"""
Add a callback that will be called on status change.
Expand Down

0 comments on commit b7ab1ee

Please sign in to comment.