From 640f5deb979ef48a44ffc03851381995c5dfb807 Mon Sep 17 00:00:00 2001 From: Eero af Heurlin Date: Wed, 23 May 2012 17:40:48 +0300 Subject: [PATCH 01/10] linked to article with photos from Pixelache --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index ff95e91..7d3f874 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,10 @@ We didn't quite finish everything in time but still got very nice feedback, phot The game was playable and we made a lot of alarm noises, the dials indicating control rod positions were missing though (we didn't have enough time to re-do them as most of the servos used at ALT party were dead). +Some photos from the event and late nights preceding it can be seen in this [article][1] (text in Finnish) + +[1]: http://www.mbnet.fi/artikkeli/blogit/mblabra/hacklabin_reaktoripeli_kotitekoinen_t_ernobyl + ## ??? Where to next ? We'll continue by finishing the dials and tuning the gameplay. From f82a1fef37b101a709397968cfdd9ddb4fdda925 Mon Sep 17 00:00:00 2001 From: Eero af Heurlin Date: Wed, 23 May 2012 17:42:14 +0300 Subject: [PATCH 02/10] this file relates to the virtual hardware --- software/{launch_stack.sh => launch_virtual_stack.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename software/{launch_stack.sh => launch_virtual_stack.sh} (100%) diff --git a/software/launch_stack.sh b/software/launch_virtual_stack.sh similarity index 100% rename from software/launch_stack.sh rename to software/launch_virtual_stack.sh From a755e6422f76d8c6885bc1106fff6439a4917c25 Mon Sep 17 00:00:00 2001 From: Eero af Heurlin Date: Wed, 23 May 2012 17:47:43 +0300 Subject: [PATCH 03/10] untested code to launch the stack with physical consoles --- software/launch_physical_stack.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 software/launch_physical_stack.sh diff --git a/software/launch_physical_stack.sh b/software/launch_physical_stack.sh new file mode 100755 index 0000000..2666e72 --- /dev/null +++ b/software/launch_physical_stack.sh @@ -0,0 +1,10 @@ +#!/bin/bash -ex +TPROG="gnome-terminal -e " +# The visualizer does not have any use for a terminal +python simulationengine/visualizer_launcher.py & +# For others it's usefull for debugging +$TPROG "python simulationengine/simulation_launcher.py" & +$TPROG "python noisemaker/noisemaker_launcher.py" & +$TPROG "python arDuBUS/ardubus_launcher.py" & +sleep 2 # Give the others time to actually register on the bus before firing up the middleware that will throw a hissy fit if it doesn't seem them +$TPROG "python middleware/middleware_launcher.py" & From 20816dc7a67ed0e586330833e1e7bbc155c03c2e Mon Sep 17 00:00:00 2001 From: Eero af Heurlin Date: Wed, 23 May 2012 17:53:46 +0300 Subject: [PATCH 04/10] seems a bit longer pause is a good idea here, also reorganized slow starting dependencies to be started first --- software/launch_physical_stack.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/software/launch_physical_stack.sh b/software/launch_physical_stack.sh index 2666e72..cbb33ab 100755 --- a/software/launch_physical_stack.sh +++ b/software/launch_physical_stack.sh @@ -3,8 +3,8 @@ TPROG="gnome-terminal -e " # The visualizer does not have any use for a terminal python simulationengine/visualizer_launcher.py & # For others it's usefull for debugging -$TPROG "python simulationengine/simulation_launcher.py" & -$TPROG "python noisemaker/noisemaker_launcher.py" & $TPROG "python arDuBUS/ardubus_launcher.py" & -sleep 2 # Give the others time to actually register on the bus before firing up the middleware that will throw a hissy fit if it doesn't seem them +$TPROG "python noisemaker/noisemaker_launcher.py" & +$TPROG "python simulationengine/simulation_launcher.py" & +sleep 5 # Give the others time to actually register on the bus before firing up the middleware that will throw a hissy fit if it doesn't seem them $TPROG "python middleware/middleware_launcher.py" & From f6fe654dfae40d43ee1407c5cb00088da258d063 Mon Sep 17 00:00:00 2001 From: Eero af Heurlin Date: Wed, 23 May 2012 17:56:46 +0300 Subject: [PATCH 05/10] window titles and since we depend already on gnome-termninal specific feature do not bother configureing the terminal prog --- software/launch_physical_stack.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/software/launch_physical_stack.sh b/software/launch_physical_stack.sh index cbb33ab..58ff317 100755 --- a/software/launch_physical_stack.sh +++ b/software/launch_physical_stack.sh @@ -1,10 +1,9 @@ #!/bin/bash -ex -TPROG="gnome-terminal -e " # The visualizer does not have any use for a terminal python simulationengine/visualizer_launcher.py & # For others it's usefull for debugging -$TPROG "python arDuBUS/ardubus_launcher.py" & -$TPROG "python noisemaker/noisemaker_launcher.py" & -$TPROG "python simulationengine/simulation_launcher.py" & +gnome-terminal --title="arDuBUS" -e "python arDuBUS/ardubus_launcher.py" & +gnome-terminal --title="Noisemaker" -e "python noisemaker/noisemaker_launcher.py" & +gnome-terminal --title="Simulationengine" -e "python simulationengine/simulation_launcher.py" & sleep 5 # Give the others time to actually register on the bus before firing up the middleware that will throw a hissy fit if it doesn't seem them -$TPROG "python middleware/middleware_launcher.py" & +gnome-terminal --title="Middleware" -e "python middleware/middleware_launcher.py" & From 57976d4d20e2d7c32757fac704547c592c679a86 Mon Sep 17 00:00:00 2001 From: Eero af Heurlin Date: Wed, 23 May 2012 18:04:37 +0300 Subject: [PATCH 06/10] change to correct dir --- software/launch_physical_stack.sh | 2 ++ software/launch_virtual_stack.sh | 2 ++ 2 files changed, 4 insertions(+) diff --git a/software/launch_physical_stack.sh b/software/launch_physical_stack.sh index 58ff317..a24031d 100755 --- a/software/launch_physical_stack.sh +++ b/software/launch_physical_stack.sh @@ -1,4 +1,6 @@ #!/bin/bash -ex +# Change the working dir to the directory of this file +cd `dirname $0` # The visualizer does not have any use for a terminal python simulationengine/visualizer_launcher.py & # For others it's usefull for debugging diff --git a/software/launch_virtual_stack.sh b/software/launch_virtual_stack.sh index a81f5f5..bed7d79 100755 --- a/software/launch_virtual_stack.sh +++ b/software/launch_virtual_stack.sh @@ -1,4 +1,6 @@ #!/bin/bash -ex +# Change the working dir to the directory of this file +cd `dirname $0` for vh in $( find virtual_hardware/ -name '*.py' | grep -v '\._' ) do python $vh & From 195a85cc8d0fe7c477705a8be98c6d6d3987f2ee Mon Sep 17 00:00:00 2001 From: Eero af Heurlin Date: Wed, 23 May 2012 18:13:45 +0300 Subject: [PATCH 07/10] make the launcher runnable via desktop links --- software/install_dependencies.sh | 5 ++++- software/launch_physical_stack.sh | 4 +++- software/launch_virtual_stack.sh | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/software/install_dependencies.sh b/software/install_dependencies.sh index 370a69c..6db0b44 100755 --- a/software/install_dependencies.sh +++ b/software/install_dependencies.sh @@ -1,5 +1,8 @@ -#! /bin/bash +#!/bin/bash -x # Python and python libs sudo apt-get install python python-pygame python-yaml python-dbus python-gobject python-pyside python-gst0.10 +# Realpath required for calling the launchers via desktop links +sudo apt-get install realpath + diff --git a/software/launch_physical_stack.sh b/software/launch_physical_stack.sh index a24031d..e6d5207 100755 --- a/software/launch_physical_stack.sh +++ b/software/launch_physical_stack.sh @@ -1,6 +1,7 @@ #!/bin/bash -ex # Change the working dir to the directory of this file -cd `dirname $0` +filep=`realpath "$0"` +cd `dirname "$filep"` # The visualizer does not have any use for a terminal python simulationengine/visualizer_launcher.py & # For others it's usefull for debugging @@ -9,3 +10,4 @@ gnome-terminal --title="Noisemaker" -e "python noisemaker/noisemaker_launcher.py gnome-terminal --title="Simulationengine" -e "python simulationengine/simulation_launcher.py" & sleep 5 # Give the others time to actually register on the bus before firing up the middleware that will throw a hissy fit if it doesn't seem them gnome-terminal --title="Middleware" -e "python middleware/middleware_launcher.py" & + diff --git a/software/launch_virtual_stack.sh b/software/launch_virtual_stack.sh index bed7d79..b985350 100755 --- a/software/launch_virtual_stack.sh +++ b/software/launch_virtual_stack.sh @@ -1,6 +1,7 @@ #!/bin/bash -ex # Change the working dir to the directory of this file -cd `dirname $0` +filep=`realpath "$0"` +cd `dirname "$filep"` for vh in $( find virtual_hardware/ -name '*.py' | grep -v '\._' ) do python $vh & From 80cdd69e3a0b9106bf43400e0377fe6c80ee1674 Mon Sep 17 00:00:00 2001 From: Eero af Heurlin Date: Sat, 26 May 2012 15:00:06 +0300 Subject: [PATCH 08/10] this method is universally usefull so make it part of the libs --- software/middleware/middleware.py | 26 ++------------------ software/pythonlibs/dbus_utilities.py | 35 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 software/pythonlibs/dbus_utilities.py diff --git a/software/middleware/middleware.py b/software/middleware/middleware.py index 5262b79..b67cb76 100644 --- a/software/middleware/middleware.py +++ b/software/middleware/middleware.py @@ -6,7 +6,7 @@ sys.path.append(libs_dir) # Import our DBUS service module -import service,dbus,gobject +import service,dbus,gobject,dbus_utilities import dbus,time import numpy as np @@ -210,29 +210,7 @@ def aliased_signal_received(self, alias, state, sender): def call_cached(self, busname, buspath, method, *args): """Maintains a cache of DBUS proxy objects and calls the given objects method. If the proxy object is stale tries to refresh""" - obj_cache_key = "%s@%s" % (busname, buspath) - method_cache_key = "%s::%s" % (obj_cache_key, method) - if not self.dbus_cache.has_key(obj_cache_key): - self.dbus_cache[obj_cache_key] = self.bus.get_object(busname, buspath) - if not self.dbus_cache.has_key(method_cache_key): - self.dbus_cache[method_cache_key] = getattr(self.dbus_cache[obj_cache_key], method) - - try: - ret = self.dbus_cache[method_cache_key](*args) - if self.dbus_cache_error_count.has_key(method_cache_key): # Zero the error count - self.dbus_cache_error_count[method_cache_key] = 0 - return ret - except dbus.exceptions.DBusException: - if not self.dbus_cache_error_count.has_key(method_cache_key): - self.dbus_cache_error_count[method_cache_key] = 0 - self.dbus_cache_error_count[method_cache_key] += 1 - # TODO Check that it's a method os object name exception first - # Remove stale keys - print "Removing stale keys for %s" % method_cache_key - del(self.dbus_cache[obj_cache_key]) - del(self.dbus_cache[method_cache_key]) - if self.dbus_cache_error_count[method_cache_key] < 4: - return self.call_cached(busname, buspath, method, *args) + return dbus_utilities.call_cached(buspath, method, *args, busname=busname) def depth_report(self, x, y, depth, *args): diff --git a/software/pythonlibs/dbus_utilities.py b/software/pythonlibs/dbus_utilities.py new file mode 100644 index 0000000..28b3e28 --- /dev/null +++ b/software/pythonlibs/dbus_utilities.py @@ -0,0 +1,35 @@ +"""Some utility functions to hve more grafull handling of DBUS exceptions we might get when dependent services get restarted""" +import dbus + +dbus_cache = {} +dbus_cache_error_count = {} +bus = dbus.SessionBus() + +def call_cached(buspath, method, *args, **kwargs): + """Maintains a cache of DBUS proxy objects and calls the given objects method. If the proxy object is stale tries to refresh""" + if not kwargs.has_key('busname'): + kwargs['busname'] = buspath.replace('/', '.')[1:] + busname = kwargs['busname'] + obj_cache_key = "%s@%s" % (busname, buspath) + method_cache_key = "%s::%s" % (obj_cache_key, method) + if not dbus_cache.has_key(obj_cache_key): + dbus_cache[obj_cache_key] = bus.get_object(busname, buspath) + if not dbus_cache.has_key(method_cache_key): + dbus_cache[method_cache_key] = getattr(dbus_cache[obj_cache_key], method) + + try: + ret = dbus_cache[method_cache_key](*args) + if dbus_cache_error_count.has_key(method_cache_key): # Zero the error count + dbus_cache_error_count[method_cache_key] = 0 + return ret + except dbus.exceptions.DBusException: + if not dbus_cache_error_count.has_key(method_cache_key): + dbus_cache_error_count[method_cache_key] = 0 + dbus_cache_error_count[method_cache_key] += 1 + # TODO Check that it's a method os object name exception first + # Remove stale keys + print "dbus_utilities.call_cached: Removing stale keys for %s" % method_cache_key + del(dbus_cache[obj_cache_key]) + del(dbus_cache[method_cache_key]) + if dbus_cache_error_count[method_cache_key] < 4: + return call_cached(busname, buspath, method, *args) From ad12c62bc808248a94a9352ed3e03aa93a0c6d24 Mon Sep 17 00:00:00 2001 From: Eero af Heurlin Date: Sat, 26 May 2012 15:07:45 +0300 Subject: [PATCH 09/10] stubs for the simulation control panel where we can reload service configs and gracefully shutdown all services via GUI --- software/simcontrol/simcontrol.py | 18 +++++++++++ software/simcontrol/simcontrol.yml | 0 software/simcontrol/simcontrol_launcher.py | 36 ++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 software/simcontrol/simcontrol.py create mode 100644 software/simcontrol/simcontrol.yml create mode 100644 software/simcontrol/simcontrol_launcher.py diff --git a/software/simcontrol/simcontrol.py b/software/simcontrol/simcontrol.py new file mode 100644 index 0000000..94f2986 --- /dev/null +++ b/software/simcontrol/simcontrol.py @@ -0,0 +1,18 @@ +from __future__ import with_statement +# Boilerplate to add ../pythonlibs (via full path resolution) to import paths +import os,sys +libs_dir = os.path.join(os.path.dirname( os.path.realpath( __file__ ) ), '..', 'pythonlibs') +if os.path.isdir(libs_dir): + sys.path.append(libs_dir) + +# Import our DBUS service module +import service,dbus,gobject,dbus_utilities +import dbus,time + +class simcontrol(service.baseclass): + def __init__(self, config, launcher_instance, **kwargs): + super(simcontrol, self).__init__(config, launcher_instance, **kwargs) + + @dbus.service.method('fi.hacklab.reactorsimulator.simcontrol') + def quit(self): + return self.launcher_instance.quit() diff --git a/software/simcontrol/simcontrol.yml b/software/simcontrol/simcontrol.yml new file mode 100644 index 0000000..e69de29 diff --git a/software/simcontrol/simcontrol_launcher.py b/software/simcontrol/simcontrol_launcher.py new file mode 100644 index 0000000..9bacef2 --- /dev/null +++ b/software/simcontrol/simcontrol_launcher.py @@ -0,0 +1,36 @@ +# Boilerplate to add ../pythonlibs (via full path resolution) to import paths +import os,sys +libs_dir = os.path.join(os.path.dirname( os.path.realpath( __file__ ) ), '..', 'pythonlibs') +if os.path.isdir(libs_dir): + sys.path.append(libs_dir) +# Import the launcher and dbus modules +import launcher,dbus + + +# Define some values that will be used +my_signature = 'fi.hacklab.reactorsimulator.simcontrol' +launcher_config = { + 'dbus_default_interface_name': my_signature, + 'dbus_object_path': '/fi/hacklab/reactorsimulator/simcontrol', + 'main_class_name': os.path.basename(__file__).replace('_launcher.py', ''), + 'config_file_path': os.path.realpath(__file__).replace('_launcher.py', '.yml'), +} + +# Basic pass-through implementation +class my_launcher(launcher.baseclass): + def __init__(self, mainloop, bus, **kwargs): + super(my_launcher, self).__init__(mainloop, bus, **kwargs) + print "launcher initialized as %s:%s with config %s" % (self.dbus_interface_name, self.dbus_object_path, repr(self.config)) + + @dbus.service.method(my_signature + '.launcher') + def quit(self): + launcher.baseclass.quit(self) + + @dbus.service.method(my_signature + '.launcher') + def reload(self): + launcher.baseclass.reload(self) + self.main_instance.config_reloaded() + +# Another small bit of boilerplate +if __name__ == '__main__': + launcher.main(my_launcher, **launcher_config) From 74caa1ae0910a0f5c7f764235a1ce0e9c7fd0b8e Mon Sep 17 00:00:00 2001 From: Eero af Heurlin Date: Sat, 26 May 2012 15:53:03 +0300 Subject: [PATCH 10/10] QT stub imports --- software/simcontrol/simcontrol.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/software/simcontrol/simcontrol.py b/software/simcontrol/simcontrol.py index 94f2986..a926062 100644 --- a/software/simcontrol/simcontrol.py +++ b/software/simcontrol/simcontrol.py @@ -9,6 +9,11 @@ import service,dbus,gobject,dbus_utilities import dbus,time +from PySide import QtCore +from PySide import QtGui +from PySide import QtDeclarative + + class simcontrol(service.baseclass): def __init__(self, config, launcher_instance, **kwargs): super(simcontrol, self).__init__(config, launcher_instance, **kwargs)