Changeset - b75bfbcf5979
[Not reviewed]
default
0 2 0
drewp - 22 years ago 2003-06-13 14:00:36

new modules: dmxclient provides a very convenient way for clients to talk to the
new modules: dmxclient provides a very convenient way for clients to talk to the
dmxserver; updatefreq stores event times and computes a report about how frequently
they occur
2 files changed with 13 insertions and 36 deletions:
0 comments (0 inline, 0 general)
light8/dmxclient.py
Show inline comments
 
@@ -5,12 +5,11 @@ dmxclient.outputlevels(..)
 
client id is formed from sys.argv[0] and the PID.  """
 

	
 
import xmlrpclib,os,sys,socket,time
 
from twisted.web.xmlrpc import Proxy
 
_dmx=None
 

	
 
_id="%s-%s" % (sys.argv[0].replace('.py','').replace('./',''),os.getpid())
 

	
 
def outputlevels(levellist,twisted=0):
 
def outputlevels(levellist):
 
    """present a list of dmx channel levels, each scaled from
 
    0..1. list can be any length- it will apply to the first len() dmx
 
    channels.
 
@@ -21,33 +20,14 @@ def outputlevels(levellist,twisted=0):
 
    global _dmx,_id
 

	
 
    if _dmx is None:
 
        host = os.getenv('DMXHOST', 'localhost')
 
        url = "http://%s:8030" % host
 
        if not twisted:
 
            _dmx=xmlrpclib.Server(url)
 
        else:
 
            _dmx = Proxy(url)
 
        _dmx=xmlrpclib.Server("http://localhost:8030")
 

	
 
    if not twisted:
 
        try:
 
            _dmx.outputlevels(_id,levellist)
 
        except socket.error,e:
 
            print "dmx server error %s, waiting"%e
 
            time.sleep(1)
 
        except xmlrpclib.Fault,e:
 
            print "outputlevels had xml fault: %s" % e
 
            time.sleep(1)
 
    else:
 
        def err(error):
 
            print "dmx server error",error
 
            time.sleep(1)
 
        d = _dmx.callRemote('outputlevels',_id,levellist)
 
        d.addErrback(err)
 

	
 
    try:
 
        _dmx.outputlevels(_id,levellist)
 
    except socket.error,e:
 
        print "dmx server error %r, waiting"%e
 
        time.sleep(1)
 
    except xmlrpclib.Fault,e:
 
        print "outputlevels had xml fault: %s" % e
 
        time.sleep(1)
 
    
 
dummy = os.getenv('DMXDUMMY')
 
if dummy:
 
    print "dmxclient: DMX is in dummy mode."
 
    def bogus(*args):
 
        pass
 
    outputlevels = bogus
light8/updatefreq.py
Show inline comments
 
@@ -9,7 +9,7 @@ class Updatefreq:
 
    the samples param to __init__ specifies how many past updates will
 
    be stored.  """
 
    
 
    def __init__(self,samples=20):
 
    def __init__(self,samples=40):
 
        self.times=[0]
 
        self.samples=samples
 

	
 
@@ -24,10 +24,7 @@ class Updatefreq:
 
        """a cheap algorithm, for now, which looks at the first and
 
        last times only"""
 

	
 
        try:
 
            hz=len(self.times)/(self.times[-1]-self.times[0])
 
        except ZeroDivisionError:
 
            return 0
 
        hz=len(self.times)/(self.times[-1]-self.times[0])
 
        return hz
 
    def __str__(self):
 
        return "%.2fHz"%float(self)
 
        return "%.1fHz"%float(self)
0 comments (0 inline, 0 general)