def writeToSlave(identifier, value): slaveID = (identifier & 0b11000000) >> 6 v = int(value) try: bus.write_byte_data(address[slaveID], identifier, v) except OSError: CL.log(CL.ERROR, "During sending Data " + str(identifier) + ", " + str(value)) return
def sendData(packetID, data): CL.log(CL.SERVERMSG, "Sending: %s; %s" % (packetID, data)) msg = packetID + data for conn in conns: try: conn.send(msg) except: CL.log(CL.ERROR, "Send failed")
def executeRoutine(routine, routineName, cbFunctions): CL.log(CL.ROUTINE, "Starting routine \"%s\"" % routineName) startTime = time.time() for i in range(len(routine)): if i > 0: curR = routine[i - 1][1] else: curR = cbFunctions[2]() timeOfAction = routine[i][0] + startTime timeForAction = timeOfAction - time.time() nxtR = routine[i][1] while time.time() < timeOfAction: p = 1 - ((timeOfAction - time.time()) / timeForAction) cbFunctions[0](LERPr(curR, nxtR, p), -4)
def setProperty(property, value): if property == b'L': CL.log(CL.INFO, "Light set to %s" % value) elif property == b'B': CL.log(CL.INFO, "Buzzer set to %s" % value) else: CL.log(CL.ERROR, "Property name not found: %s" % property)
def run(self): while 1: try: msg = self.conn.recv(1024) if len(msg) > 0: #CL.log(CL.SERVERMSG, "(%s) Reveived %s" % (self.addr[0], r.decode())) CL.log(CL.SERVERMSG, "Received: %s" % (msg)) packetParser.parse(msg) except ConnectionResetError: CL.log(CL.ERROR, "Connection Reset") break except ConnectionAbortedError: CL.log(CL.ERROR, "Connection Aborted") break self.conn.close() CL.log(CL.SERVER, "(%s) Client disconnected" % self.addr[0]) global conns conns.remove(self.conn)
def run(self): self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) try: self.s.bind((HOSTNAME, PORT)) CL.log(CL.SERVER, "Bind was succesful") except socket.error as msg: CL.log(CL.ERROR, "Bind failed; " + str(msg)) return self.s.listen() while 1: (conn, addr) = self.s.accept() global conns conns.append(conn) connHandler = ConnHandler(conn, addr) connHandler.setDaemon(True) connHandler.start() CL.log( CL.SERVER, "(%s) Client connected; Total number of connections is %s" % (addr[0], len(conns)))
def setMode(m): CL.log(CL.VGC, "Mode set to %s" % m) mode = m