Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
Add flag to disable server


Update readme


Add config option passing to drc_sim_c
  • Loading branch information
rolandoislas committed Jun 1, 2017
1 parent fc09c01 commit 6ec4eae
Show file tree
Hide file tree
Showing 10 changed files with 452 additions and 42 deletions.
6 changes: 3 additions & 3 deletions drc-sim-backend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from src.server.data import constants
from src.server.data.args import Args
from src.server.data.config_server import ConfigServer
from src.server.data.config_general import ConfigGeneral
from src.server.ui.cli.cli_main import CliMain
from src.server.util.logging.logger import Logger
from src.server.util.logging.logger_backend import LoggerBackend
Expand Down Expand Up @@ -74,8 +74,8 @@ def main():
:return: None
"""
Args.parse_args()
ConfigServer.load()
ConfigServer.save()
ConfigGeneral.load()
ConfigGeneral.save()
init_loggers()
Logger.info("Initializing drc-sim-backend version %s", constants.VERSION)
Logger.info("Using \"%s\" as home folder.", constants.PATH_ROOT)
Expand Down
358 changes: 358 additions & 0 deletions license.txt

Large diffs are not rendered by default.

25 changes: 23 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DRC Sim Server
Stable: [![Build Status](https://travis-ci.org/rolandoislas/drc-sim.svg?branch=master)](https://travis-ci.org/rolandoislas/drc-sim)
Dev: [![Build Status](https://travis-ci.org/rolandoislas/drc-sim.svg?branch=develop)](https://travis-ci.org/rolandoislas/drc-sim)

Fork of drc-sim with a server/client implementation. This allows for a broader range of clients.
DRC Sim Server is a utility for pairing a computer to a Wii U to emulate a gamepad.

It needs a [client] for full functionality.

Expand All @@ -16,9 +16,24 @@ See the [wiki] for more info.

# Credits

[drc-sim] \(original\) by memahaxx
[drc-sim] \(original\) by [memahaxx]
- The original Python codebase

[libdrc documentation] by memahaxx
- Gamepad and Wii U software and hardware details

[drc-sim-keyboard] by justjake
- The readme that got me set up initially

# Additional Software

[wpa_supplicant] modified by memahaxx

[drc_sim_c] drc-sim rewritten in C++

[netifaces] Python network interfaces library

[pexpect] Python process interaction library



Expand All @@ -27,3 +42,9 @@ See the [wiki] for more info.
[Installation instructions]: https://github.com/rolandoislas/drc-sim/wiki/Install
[client]: https://github.com/rolandoislas/drc-sim-client/wiki/Home
[wiki]: https://github.com/rolandoislas/drc-sim/wiki/Home
[wpa_supplicant]: https://github.com/rolandoislas/drc-hostap
[drc_sim_c]: https://github.com/rolandoislas/drc-sim-c
[memahaxx]: https://bitbucket.org/memahaxx/
[libdrc documentation]: http://libdrc.org/docs/index.html
[netifaces]: https://pypi.python.org/pypi/netifaces
[pexpect]: https://pypi.python.org/pypi/pexpect
4 changes: 4 additions & 0 deletions src/server/data/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def parse_args():
help="verbose debug output")
arg_parser.add_argument("-c", "--cli", action="store_const", const=True, default=False,
help="disable gui")
# Disable server
arg_parser.add_argument("--disable-server", "--disable_server", action="store_const", const=True, default=False,
help="dev: disable packet handling and serving")
# CLI
args = ["-c", "--cli", "-h", "--help"]
found = False
Expand All @@ -38,6 +41,7 @@ def parse_args():
run_server = subparsers.add_parser("run_server")
run_server.add_argument("wii_u_interface", type=str)
run_server.add_argument("normal_interface", type=str)
run_server.add_argument("-region", type=str, default="none")
# Get Key
get_key = subparsers.add_parser("get_key")
get_key.add_argument("wii_u_interface", type=str)
Expand Down
35 changes: 35 additions & 0 deletions src/server/data/config_general.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from src.server.data.config import Config


class ConfigGeneral:
scan_timeout = None
config = Config()
stream_audio = None
input_delay = None
video_quality = None
stream_video = None

def __init__(self):
pass

@classmethod
def load(cls):
cls.config.load("~/.drc-sim/server.conf")
# Audio
cls.stream_audio = cls.config.get_boolean("AUDIO", "stream", True, "Stream audio to clients")
# Input
cls.input_delay = cls.config.get_int("INPUT", "delay", 0, 1000, 100, "Amount of time in milliseconds to send "
"input to the Wii U")
# Video
cls.video_quality = cls.config.get_int("VIDEO", "quality", 0, 100, 75, "Quality of video stream.\n"
"5/10/15 low - 75 lan - 100 loopback\n"
"There is latency at 100.")
cls.stream_video = cls.config.get_boolean("VIDEO", "stream", True, "Stream video to clients")
# General
cls.scan_timeout = cls.config.get_int("GENERAL", "scan_timeout", 0, 60 * 5, 60 * 2, "Sets the time "
"allowed to scan for the "
"Wii U")

@classmethod
def save(cls):
cls.config.save()
21 changes: 0 additions & 21 deletions src/server/data/config_server.py

This file was deleted.

4 changes: 1 addition & 3 deletions src/server/ui/cli/cli_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def __init__(self):
self.wpa_supplicant = None

def start(self):
LoggerCli.warn("The CLI not user friendly. It is here to provide a way to automate"
" the server via a shell. The GUI is a better alternative for normal use.")
if Args.args.run_server:
self.run_server()
elif Args.args.get_key:
Expand Down Expand Up @@ -49,7 +47,7 @@ def run_server(self):
InterfaceUtil.set_metric(normal_interface, 0)
InterfaceUtil.set_metric(wii_u_interface, 1)
self.drc_sim_c = DrcSimC()
self.drc_sim_c.set_region("none") # TODO get add region to args
self.drc_sim_c.set_region(Args.args.region)
self.drc_sim_c.add_status_change_listener(self.drc_sim_c_status_changed)
self.drc_sim_c.start()
while self.drc_sim_c.running:
Expand Down
3 changes: 1 addition & 2 deletions src/server/ui/gui/frame/frame_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def activate(self):
pass

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

def kill_other_tabs(self):
return False
19 changes: 18 additions & 1 deletion src/server/util/drc_sim_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import time

from src.server.data import constants
from src.server.data.args import Args
from src.server.data.config_general import ConfigGeneral
from src.server.util.logging.logger_backend import LoggerBackend
from src.server.util.process_util import ProcessUtil
from src.server.util.status_sending_thread import StatusSendingThread
Expand All @@ -29,10 +31,25 @@ def set_region(self, region):
self.region = region

def start(self):
if Args.args.disable_server:
return
self.running = True
self.kill_drc_sim_c()
LoggerBackend.debug("Starting drc_sim_c")
command = ["drc_sim_c", "-region", self.region]
command = ["drc_sim_c", "-region", self.region, "-video-quality", str(ConfigGeneral.video_quality),
"-input-delay", str(ConfigGeneral.input_delay)]
if not ConfigGeneral.stream_video:
command.append("--no-video")
if not ConfigGeneral.stream_audio:
command.append("--no-audio")
if Args.args.debug:
command.append("-d")
if Args.args.extra:
command.append("-e")
if Args.args.finer:
command.append("-f")
if Args.args.verbose:
command.append("-v")
self.drc_sim_c_process = subprocess.Popen(command, stdout=open(constants.PATH_LOG_DRC_SIM_C, "w"),
stderr=subprocess.STDOUT)
LoggerBackend.debug("Starting status check thread")
Expand Down
19 changes: 9 additions & 10 deletions src/server/util/wpa_supplicant.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pexpect

from src.server.data import constants
from src.server.data.config_server import ConfigServer
from src.server.data.config_general import ConfigGeneral
from src.server.util.logging.logger_wpa import LoggerWpa
from src.server.util.process_util import ProcessUtil
from src.server.util.status_sending_thread import StatusSendingThread
Expand Down Expand Up @@ -94,20 +94,25 @@ def check_status(self):
self.time_start += 1
# scanning
elif not self.scan_contains_wii_u(scan_results) or "wpa_state=SCANNING" in wpa_status:
LoggerWpa.finer("%d seconds until scan timeout", ConfigServer.scan_timeout - self.time_scan)
LoggerWpa.finer("%d seconds until scan timeout", ConfigGeneral.scan_timeout - self.time_scan)
# disconnect
if self.time_scan == -1:
status = self.DISCONNECTED
# timeout scan
if self.time_scan >= ConfigServer.scan_timeout:
elif self.time_scan >= ConfigGeneral.scan_timeout:
status = self.NOT_FOUND
else:
status = self.SCANNING
self.time_scan += 1
elif "wpa_state=COMPLETED" in wpa_status:
status = self.CONNECTED
self.time_scan = 0 # forces a disconnect - might need to be handled better
self.time_scan = -1 # forces a disconnect - might need to be handled better
elif "wpa_state=AUTHENTICATING" in wpa_status or "wpa_state=ASSOCIATING" in wpa_status:
status = self.CONNECTING
elif "wpa_state=DISCONNECTED" in wpa_status:
status = self.DISCONNECTED
if self.time_scan != -1:
status = self.FAILED_START
else:
LoggerWpa.extra("WPA status: %s", wpa_status)
status = self.UNKNOWN
Expand Down Expand Up @@ -150,12 +155,6 @@ def stop(self):
LoggerWpa.debug("Ignored stop request: already stopped")
return
self.running = False
if self.status_check_thread:
LoggerWpa.debug("Stopping wpa status check")
try:
self.status_check_thread.join()
except RuntimeError as e:
LoggerWpa.exception(e)
if self.psk_thread_cli and self.psk_thread_cli.isalive():
LoggerWpa.debug("Stopping psk pexpect spawn")
self.psk_thread_cli.sendline("quit")
Expand Down

0 comments on commit 6ec4eae

Please sign in to comment.