Changeset - ba47676dde49
[Not reviewed]
default
0 4 0
drewp@bigasterisk.com - 11 years ago 2013-09-08 05:09:53
drewp@bigasterisk.com
dmxserver can receive OSC requests too
Ignore-this: cafc864acd008d8bf7af75b4200fb188
4 files changed with 37 insertions and 2 deletions:
0 comments (0 inline, 0 general)
bin/dmxserver
Show inline comments
 
@@ -19,29 +19,56 @@ server is port 8030; xmlrpc method is ca
 

	
 
todo:
 
  save dmx on quit and restore on restart
 
  if parport fails, run in dummy mode (and make an option for that too)
 
"""
 

	
 
from __future__ import division
 
from twisted.internet import reactor
 
from twisted.web import xmlrpc, server
 
import sys,time,os
 
from optparse import OptionParser
 
import run_local
 
import txosc.dispatch, txosc.async
 
from light9.io import ParportDMX, UsbDMX
 

	
 
from light9.updatefreq import Updatefreq
 
from light9 import networking
 

	
 

	
 
class ReceiverApplication(object):
 
    """
 
    receive UDP OSC messages. address is /dmx/1 for dmx channel 1,
 
    arguments are 0-1 floats for that channel and any number of
 
    following channels.
 
    """
 
    def __init__(self, port, lightServer):
 
        self.port = port
 
        self.lightServer = lightServer
 
        self.receiver = txosc.dispatch.Receiver()
 
        self.receiver.addCallback("/dmx/*", self.pixel_handler)
 
        self._server_port = reactor.listenUDP(
 
            self.port,
 
            txosc.async.DatagramServerProtocol(self.receiver),
 
            interface='0.0.0.0')
 
        print "Listening OSC on udp port %s" % (self.port)
 

	
 
    def pixel_handler(self, message, address):
 
        # this is already 1-based though I don't know why
 
        startChannel = int(message.address.split('/')[2])
 
        levels = [a.value for a in message.arguments]
 
        allLevels = [0] * (startChannel - 1) + levels
 
        self.lightServer.xmlrpc_outputlevels("osc@%s" % startChannel,
 
                                             allLevels)
 

	
 
class XMLRPCServe(xmlrpc.XMLRPC):
 
    def __init__(self,options):
 

	
 
        xmlrpc.XMLRPC.__init__(self)
 
        
 
        self.clientlevels={} # clientID : list of levels
 
        self.lastseen={} # clientID : time last seen
 
        self.clientfreq={} # clientID : updatefreq
 
        
 
        self.combinedlevels=[] # list of levels, after max'ing the clients
 
        self.clientschanged=1 # have clients sent anything since the last send?
 
        self.options=options
 
@@ -206,17 +233,22 @@ parser.add_option("-r","--updates-per-se
 
                  help=('dmx output frequency'))
 
parser.add_option("-d","--dmx-device", default='/dev/dmx0',
 
                  help='dmx device name')
 
parser.add_option("-n", "--dummy", action="store_true",
 
                  help="dummy mode, same as DMXDUMMY=1 env variable")
 
(options,songfiles)=parser.parse_args()
 

	
 
print options
 

	
 
if options.dummy:
 
    os.environ['DMXDUMMY'] = "1"
 

	
 

	
 
port = networking.dmxServer.port
 
print "starting xmlrpc server on port %s" % port
 
reactor.listenTCP(port,server.Site(XMLRPCServe(options)))
 
xmlrpcServe = XMLRPCServe(options)
 
reactor.listenTCP(port,server.Site(xmlrpcServe))
 

	
 
oscApp = ReceiverApplication(9051, xmlrpcServe)
 

	
 
reactor.run()
 

	
light9/networking.py
Show inline comments
 
@@ -26,16 +26,17 @@ class ServiceAddress(object):
 
        _, netloc, _, _, _, _ = urlparse(self._url())
 
        host, port = splitport(netloc)
 
        return host
 

	
 
    @property
 
    def url(self):
 
        return self._url()
 

	
 
    def path(self, more):
 
        return self.url + str(more)
 

	
 
dmxServer = ServiceAddress(L9['dmxServer'])
 
oscDmxServer = ServiceAddress(L9['oscDmxServer'])
 
musicPlayer = ServiceAddress(L9['musicPlayer'])
 
keyboardComposer = ServiceAddress(L9['keyboardComposer'])
 
curveCalc = ServiceAddress(L9['curveCalc'])
 
vidref = ServiceAddress(L9['vidref'])
pydeps
Show inline comments
 
@@ -5,13 +5,14 @@ Louie==1.1
 
cyclone==1.1
 

	
 
web.py==0.37
 
restkit==4.2.1
 
ipython==0.13.2
 
nose==1.3.0
 
nose-alert==0.9.0
 
ipdb==0.7
 
# waiting for https://github.com/xolox/python-coloredlogs/pull/1
 
git+git://github.com/drewp/python-coloredlogs@9803112ddf7d4cd7dd001912ad1aa482fb8383f6
 
genshi==0.7
 
pyjade==2.0.2
 
python-dateutil==2.1
 
\ No newline at end of file
 
python-dateutil==2.1
 
txosc==0.2.0
 
\ No newline at end of file
show/dance2013/networking.n3
Show inline comments
 
@prefix : <http://light9.bigasterisk.com/> .
 
@prefix show: <http://light9.bigasterisk.com/show/> .
 
@prefix sh: <http://light9.bigasterisk.com/show/dance2013/> .
 

	
 
show:dance2013 :networking sh:netHome .
 
sh:netHome  
 
  :musicPlayer <http://plus:8040/>;
 
  :dmxServer <http://plus:8030/>;
 
  :oscDmxServer <udp://plus:9050/>;
 
  :curveCalc <http://plus:8060/>;
 
  :keyboardComposer <http://plus:8050/>;
 
  :vidref <http://amp:8053/> .
 
\ No newline at end of file
0 comments (0 inline, 0 general)