コード例 #1
0
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
コード例 #2
0
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)
コード例 #3
0
ファイル: main.py プロジェクト: hkust-smartcar/Creative18
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 = []
コード例 #4
0
ファイル: xipmsg.py プロジェクト: nranjan54/xipmsg
#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
コード例 #5
0
ファイル: xipmsg.py プロジェクト: ZhuZhengyi/xipmsg
#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