def recv(self): try: data, server_addr = RDLaser.getClient().recvfrom(RDLaser.BUF_SIZE) except socket.timeout: if self.debug: print u"\x1B[30;48;5;1m TIMEOUT REACHED \x1B[0m" return (None, None) if self.debug: print u"\x1B[44m< " + server_addr[0] + ": " + data.encode( "HEX") + u"\x1B[0m - " + RDLaser.descramblestr(data).encode( "HEX") return (data, server_addr)
def request(self, data): if not self.send(data): return None resp, server_addr = self.recv() if resp == None: return None resp = RDLaser.descramblestr(resp) if resp[2:4] == data[2:4]: return resp[4:] else: if self.debug: print u"\x1B[30;48;5;1m MESSAGE CODE MISMATCH %s / %s \x1B[0m" % ( resp[2:4].encode("HEX"), data[2:4].encode("HEX")) return None
def recv(self): data, addr = RDLaser.getServer().recvfrom(RDLaser.BUF_SIZE) if data[:2] != RDLaser.checksum(data[2:])[:2]: print data[0:2].encode("HEX") if self.debug: print(u"\x1B[31mCHECKSUM MISMATCH\x1B[0m") return ("", addr) data = RDLaser.descramblestr(data[2:]) if self.debug: print(u"\x1B[34m< " + addr[0] + ": " + RDLaser.scramblestr(data).encode("HEX") + u"\x1B[0m - " + data.encode("HEX")) self.send(addr[0], '\xcc') #send ACK return (data, addr)