def update(self, observable, frame): if frame[0] == OpCode.MY_ID() and len(frame[1]) == 1: self.id = frame[1][0] self.log = logging.getLogger("EndPoint[{}]".format(self.id)) self.log.setLevel(logging.DEBUG) self.log.debug("Starting...") elif frame[0] == OpCode.LOG() and len(frame[1]) > 0: if self.log != None: self.log.info("".join(map(chr, frame[1]))) elif frame[0] == OpCode.SWITCH_ACTIVE() and len(frame[1]) == 1: self.switchEventQueue.append(("{}-{}".format(self.id, frame[1][0]), 1)) elif frame[0] == OpCode.SWITCH_INACTIVE() and len(frame[1]) == 1: self.switchEventQueue.append(("{}-{}".format(self.id, frame[1][0]), 0))
def setSwitchDebounceThreshold(self, switchId, microseconds, activity): self.outgoingFrameBuffer += [ [OpCode.SWITCH_DEBOUNCE_CONFIG()] + [switchId] + [1 if activity else 0] + [ microseconds & 255, (microseconds >> 8) & 255, (microseconds >> 16) & 255, microseconds >> 24 ] ]
def update(self, observable, frame): if frame[0] == OpCode.SR_CONFIG() and len(frame[1]) == 5: rule = HardwareRule.fromByteArray(frame[1]) existingRule = self.rules[rule.stimulus] if existingRule == rule: if rule.stimulus in self.dirty: self.dirty.remove(rule.stimulus) if self.isDirty(): self.sendRule() else: self.dirty.add(existingRule.stimulus) self.sendRule(existingRule) elif frame[0] == OpCode.MY_ID(): if len(self.rules) > 0: for stimulus in self.rules.keys(): self.dirty.add(stimulus) self.sendRule()
def setSwitchPullup(self, switchId, pullup): self.outgoingFrameBuffer += [[OpCode.SWITCH_PULLUP_CONFIG()] + [switchId] + [1 if pullup else 0]]
def pulseSolenoid(self, activity): self.outgoingFrameBuffer += [[OpCode.PULSE_COIL()] + activity.toByteArray()]
def update(self, observable, frame): if frame[0] == OpCode.PING(): self.outgoingFrameHandler += [[OpCode.PONG(), frame[1][0]]]
def sendRule(self, rule = None): if rule == None: rule = self.rules[list(self.dirty)[0]] self.outgoingFrameHandler += [[OpCode.SR_CONFIG()] + rule.toByteArray()] self.outgoingFrameHandler += [[OpCode.SR_CONFIG()] + rule.stimulus.toByteArray()]