def main(args): config = setup(args.config, args.params) logger.info(config) logger.info("Watching serial %s", args.dev) with Serial(args.dev, config.baud_rate, timeout=config.timeout) as dev: while True: hello_message = protocol.init(dev) logger.info("Received hello: %s", hello_message) try: while True: magic, payload = protocol.readline(dev) if magic == b"M": logger.info("Recv message %s", payload) elif magic == b"C": cmd = int(payload.decode().strip()) logger.info("Recv command %s", cmd) config.commands[cmd].run(log=True) else: raise ValueError( f"main: unexpected magic {magic}, mesg {payload}") except KeyboardInterrupt: break except Exception as e: logger.warning(f"Unhandled exception: {e}. Restarting.") continue
def _connect(uri, password): global conn conn = yield from websockets.connect(uri) yield from conn.send(w.init(password)) yield from conn.send( '(list_buffers) hdata buffer:gui_buffers(*) full_name,short_name,title,nicklist,type,local_variables,completion\n' ) yield from conn.send( '(hotlist) hdata hotlist:gui_hotlist(*) count,buffer\n') yield from conn.send('sync *\n') yield from conn.send('ping connected\n') while True: data = yield from conn.recv() if not data: pyotherside.emit('disconnected') return id, msg = w.parse_message(data) print(id) pyotherside.send(id, msg)
rotateLocalTranslation,\ getGlobalTranslation,\ sortRects,\ getLocalRotateType from util import mapToWorld, mapToImage, deg from math import sin, cos import preprocess import comm import protocol draw = True mycomm = comm.Comm(print) protocol.init(mycomm) sensor.reset() # grayscale is faster (160x120 max on OpenMV-M7) # sensor.set_pixformat(sensor.RGB565) sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(time=2000) clock = time.clock() size = [160, 120] Size = [280, 240] equations = [] corners = []
#init env sys.setcheckinterval(1) PORT = protocol.PORT address = ('', PORT) server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #server_socket.settimeout(1) server_socket.setblocking(1) server_socket.bind(address) client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) client_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) client_socket.settimeout(1) #print '#init finished' protocol.init(client_socket) #print '#protocol init finished' print ">" class clientthread(threading.Thread): def __init__(self, client_socket, server_socket): threading.Thread.__init__(self) self.client_socket = client_socket self.server_socket = server_socket def run(self): while True: try: msg = raw_input() #get user input
#init env sys.setcheckinterval(1) PORT = protocol.PORT address = ('', PORT) server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #server_socket.settimeout(1) server_socket.setblocking(1) server_socket.bind(address) client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) client_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) client_socket.settimeout(1) #print '#init finished' protocol.init(client_socket) #print '#protocol init finished' print ">" class clientthread(threading.Thread): def __init__(self, client_socket, server_socket): threading.Thread.__init__(self) self.client_socket = client_socket self.server_socket = server_socket def run(self): while True: try: msg = raw_input() #get user input msgsquence = msg.strip().split(':') #strip the input and explode the string by ":" #print msgsquence