def send(data, seq, flag, send_socket, target): hexseq = hex(seq)[2:] if len(hexseq) == 1: hexseq = '0' + hexseq print("Send Hex", hexseq, "Send FLAG", flag) message = flag + hexseq + data crc = cg.generate(message) if len(crc) < 4: crc = '0' + crc print("Send crc", crc) frame = bg.fill(message + crc) print("Send Frame:", frame) send_socket.sendto(frame.encode(), target)
def sendcheck(seq, receive_socket, target, state=False): print("Feedback Start") hexseq = hex(seq)[2:] if len(hexseq) == 1: hexseq = '0' + hexseq print("Hex:", hexseq) if state is False: hexseq = '00' + hexseq else: hexseq = '01' + hexseq print("State:", hexseq[:2]) crc = cg.generate(hexseq) if len(crc) < 4: crc = '0' + crc print("Receive crc:", crc) frame = bg.fill(hexseq + crc) print("Feedback Frame:", frame) print("Feedback stop:") receive_socket.sendto(frame.encode(), target)
def send(message, seq): # This data should be a Hex String List _FLAG = False hexseq = hex(seq)[2:] if len(hexseq) == 1: hexseq = '0' + hexseq print("Send Hex", hexseq) message = hexseq + message crc = cg.generate(message) if len(crc) < 4: crc = '0' + crc print("Crc", crc) frame = bg.fill(message + crc) print("Send Frame:", frame) send_socket.sendto(frame.encode(), ('127.0.0.2', 8888)) try: _FLAG = wait(hexseq) except Exception as e: print("Send Timeout!", e) _FLAG = False if _FLAG is False: send(message, seq) else: return True
import ByteFill.decode as bd import ByteFill.generate as bg message = '1b7d7d7e7d7d7e23' print("Init Message", message) message = bg.fill(message) print("Encode", message) message = bd.decode(message) print("After Decode", message)