Skip to content

Commit

Permalink
Merge branch 'master' of github.com:HelsinkiHacklab/reactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rambo committed Jun 6, 2012
2 parents 5ba1bf2 + 74caa1a commit 5952c2f
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 24 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -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.
13 changes: 13 additions & 0 deletions software/launch_physical_stack.sh
@@ -0,0 +1,13 @@
#!/bin/bash -ex
# Change the working dir to the directory of this file
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
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
gnome-terminal --title="Middleware" -e "python middleware/middleware_launcher.py" &

3 changes: 3 additions & 0 deletions software/launch_stack.sh → software/launch_virtual_stack.sh
@@ -1,4 +1,7 @@
#!/bin/bash -ex
# Change the working dir to the directory of this file
filep=`realpath "$0"`
cd `dirname "$filep"`
for vh in $( find virtual_hardware/ -name '*.py' | grep -v '\._' )
do
python $vh &
Expand Down
26 changes: 2 additions & 24 deletions software/middleware/middleware.py
Expand Up @@ -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
Expand Down Expand Up @@ -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):

Expand Down
35 changes: 35 additions & 0 deletions 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)
23 changes: 23 additions & 0 deletions software/simcontrol/simcontrol.py
@@ -0,0 +1,23 @@
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

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)

@dbus.service.method('fi.hacklab.reactorsimulator.simcontrol')
def quit(self):
return self.launcher_instance.quit()
Empty file.
36 changes: 36 additions & 0 deletions 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)

0 comments on commit 5952c2f

Please sign in to comment.