Changeset - 05a5226a8d61
[Not reviewed]
default
0 4 0
drewp@bigasterisk.com - 9 years ago 2016-06-11 04:31:11
drewp@bigasterisk.com
logging and tweaks to collector
Ignore-this: d2083701fb026e834e6bd947d371584f
4 files changed with 11 insertions and 7 deletions:
0 comments (0 inline, 0 general)
bin/collector
Show inline comments
 
@@ -58,14 +58,16 @@ def startZmq(port, collector):
 
            collector.setAttrs()
 
    s.onPull = onPull
 

	
 
def launch(graph):
 

	
 
    # todo: drive outputs with config files
 
    outputs = [EnttecDmx(L9['output/dmx0/'], '/dev/dmx0'),
 
               Udmx(L9['output/udmx/'])]
 
    outputs = [
 
        EnttecDmx(L9['output/dmx0/'], '/dev/dmx0'),
 
        Udmx(L9['output/udmx/']),
 
    ]
 
    c = Collector(graph, outputs)
 

	
 
    server = WebServer(c)
 
    startZmq(networking.collectorZmq.port, c)
 
    
 
    reactor.listenTCP(networking.collector.port,
light9/collector/collector.py
Show inline comments
 
@@ -106,13 +106,15 @@ class Collector(object):
 
        
 
        pendingOut = {} # output : values
 
        for device, attrs in outputAttrs.iteritems():
 
            for outputAttr, value in attrs.iteritems():
 
                self.setAttr(device, outputAttr, value, pendingOut)
 

	
 
        print "%.1fms for client math" % (1000 * (time.time() - now))
 
        self.flush(pendingOut)
 
        print "%.1fms including flush" % (1000 * (time.time() - now))
 

	
 
    def setAttr(self, device, outputAttr, value, pendingOut):
 
        output, index = self.outputMap[(device, outputAttr)]
 
        outList = pendingOut.setdefault(output, [])
 
        setListElem(outList, index, value, combine=max)
 

	
light9/collector/device.py
Show inline comments
 
@@ -6,12 +6,13 @@ from rdflib import Literal
 
from webcolors import hex_to_rgb, rgb_to_hex
 
from colormath.color_objects import sRGBColor, CMYColor
 
import colormath.color_conversions
 

	
 
log = logging.getLogger('device')
 

	
 

	
 
class Device(object):
 
    def setAttrs():
 
        pass
 

	
 

	
 
class ChauvetColorStrip(Device):
light9/collector/output.py
Show inline comments
 
@@ -65,13 +65,13 @@ class EnttecDmx(DmxOutput):
 

	
 
        sys.path.append("dmx_usb_module")
 
        from dmx import Dmx
 
        self.dev = Dmx(devicePath)
 
        self.currentBuffer = ''
 
        self.lastLog = 0
 
        task.LoopingCall(self._loop).start(1 / 50)
 
        task.LoopingCall(self._loop).start(0.050)
 

	
 
    @stats.update.time()
 
    def update(self, values):
 
        now = time.time()
 
        if now > self.lastLog + 1:
 
            log.info('enttec %s', ' '.join(map(str, values)))
 
@@ -102,29 +102,28 @@ class Udmx(DmxOutput):
 
        # Doesn't actually need to get called repeatedly, but we do
 
        # need these two things:
 
        #   1. A throttle so we don't lag behind sending old updates.
 
        #   2. Retries if there are usb errors.
 
        # Copying the LoopingCall logic accomplishes those with a
 
        # little wasted time if there are no updates.
 
        task.LoopingCall(self._loop).start(1 / 50)
 
        task.LoopingCall(self._loop).start(0.050)
 

	
 
    @stats.update.time()
 
    def update(self, values):
 
        now = time.time()
 
        if now > self.lastLog + 1:
 
            log.info('udmx %s', ' '.join(map(str, values)))
 
            self.lastLog = now
 

	
 
        self.currentBuffer = ''.join(map(chr, values))
 
    
 
    def _loop(self):
 
        if self.lastSentBuffer == self.currentBuffer:
 
            return
 
        #if self.lastSentBuffer == self.currentBuffer:
 
        #    return
 
        with Udmx.stats.write.time():
 
            # frequently errors with usb.core.USBError
 
            try:
 
                self.dev.SendDMX(self.currentBuffer)
 
                self.lastSentBuffer = self.currentBuffer
 
                return
 
            except usb.core.USBError:
 
                Udmx.stats.usbErrors += 1
 

	
0 comments (0 inline, 0 general)