class ControlSocket(Thread): def __init__(self, cport=DEFAULT_PORT, start=True): Thread.__init__(self) logging.basicConfig(filename="ColorBlast.log", filemode='w', level=logging.INFO) self._log = logging.getLogger('ControlSocket') self._port = cport # self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self._stop = False self._complete = Event() self._colorBlast = ColorBlast(NUM_PORTS, NUM_LIGHTS, logging.getLogger('ColorBlast')) self._kinetSender = KinetSender.KinetSender(SRC_IP, DATA_ENABLER_IP, NUM_PORTS, 3*NUM_LIGHTS, logging.getLogger('KinetSender')) if start: self.start() def killAll(self): self._stop = True if self.isAlive(): self._log.info('killAll(): Waiting for thread to finish') self._complete.wait() self._log.info('killAll(): Thread stopped') KinetSender.finish(self._kinetSender) def _processLight(self, id, r, g, b): (port, ch) = _lightMap(id) if port==0 or ch==0: return 0 self._colorBlast.setRGB(r, g, b, [port-1], [ch-1]) return port def _processCmd(self, cmd): # Command format: # NUM LIGHTS | ID1 | R | G | B | ID2 | R | ... cfields = cmd.strip().split('|') ports_to_update = [] try: num_lights = int(cfields[0]) print("ControlSocket :: processing command...") except Exception, e: self._log.error('_processCmd(): Can not process # of lights - %s:%s', type(e), e) else:
def __init__(self, cport=DEFAULT_PORT, start=True): Thread.__init__(self) logging.basicConfig(filename="ColorBlast.log", filemode='w', level=logging.INFO) self._log = logging.getLogger('ControlSocket') self._port = cport # self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self._stop = False self._complete = Event() self._colorBlast = ColorBlast(NUM_PORTS, NUM_LIGHTS, logging.getLogger('ColorBlast')) self._kinetSender = KinetSender.KinetSender(SRC_IP, DATA_ENABLER_IP, NUM_PORTS, 3*NUM_LIGHTS, logging.getLogger('KinetSender')) if start: self.start()