コード例 #1
0
def init_server_connections(IMGPROC=True):
    camerasock, imgprocsock, plotsock = None, None, None
    RPi_ip = '134.28.136.49'
    pc_ip = '134.28.136.131'
    #    pc_ip = '192.168.7.1'

    # RPi connection
    with timeout.timeout(12):
        try:
            if IMGPROC:
                client.start_img_processing(RPi_ip)
                time.sleep(10)
                imgprocsock = client.IMGProcSocket(RPi_ip)
                rootLogger.info("RPi Server found: Img Processing is running")
            else:
                time.sleep(3)


#                client.start_image_capture_server(RPi_ip)
#                time.sleep(3)
#                camerasock = client.CameraSocket(RPi_ip)
#                rootLogger.info("RPi Server found: Camera is running")
        except exception.TimeoutError:
            rootLogger.info("RPi Server not found")
        except SocketError as err:
            if err.errno == errno.ECONNREFUSED:
                rootLogger.info("RPi Server refused connection")
            elif err.errno == errno.EADDRINUSE:
                rootLogger.info("RPi Server already in Use")
            else:
                raise
    # PC Dell Latitude Connection
    with timeout.timeout(2):
        try:
            plotsock = client.LivePlotterSocket(pc_ip)
            rootLogger.info("Connected to LivePlotter Server")
        except exception.TimeoutError:
            rootLogger.info("LivePlotter Server not found")
        except SocketError as err:
            if err.errno == errno.ECONNREFUSED:
                rootLogger.info("LivePlotter Server refused connection")
            elif err.errno == errno.EADDRINUSE:
                rootLogger.info("LivePlotter Server already in Use")
            else:
                raise

    return camerasock, imgprocsock, plotsock
コード例 #2
0
 def run(self):
     while self.is_running:
         if self.ui_sock.busy:
             time.sleep(.2)
         else:
             with timeout.timeout(1):
                 try:
                     ui_state.set_state(self.ui_sock.get_data())
                 except exception.TimeoutError:
                     print('UI doesnt respond')
コード例 #3
0
def init_BBB_connection(hostname):
    # Create a TCP/IP socket
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    # Connect the socket to the port where the server is listening
    # eth0 IP of BBB in AmP: 134.28.136.51
    hostname = '192.168.7.2'  # static IP of BBB-USB
    server_address = (hostname, 10000)
    print >> sys.stderr, 'connecting to %s port %s' % server_address
    with timeout.timeout():
        sock.connect(server_address)
    return sock
コード例 #4
0
def init_monitor_connection():
    plotsock = None
    pc_ip = '134.28.136.131'  #'192.168.7.1'

    with timeout.timeout(2):
        try:
            plotsock = client.LivePlotterSocket(pc_ip)
            rootLogger.info("Connected to LivePlotter Server")
        except exception.TimeoutError:
            rootLogger.info("LivePlotter Server not found")
        except SocketError as err:
            if err.errno == errno.ECONNREFUSED:
                rootLogger.info("LivePlotter Server refused connection")
            elif err.errno == errno.EADDRINUSE:
                rootLogger.info("LivePlotter Server already in Use")
            else:
                raise

    return plotsock
コード例 #5
0
ファイル: UI_main.py プロジェクト: larslevity/GeckoBot
def main(connection):
    def send_back(data_out):
        data_out_raw = pickler.pickle_data(data_out)
        connection.sendall(data_out_raw)

    exit_flag = False

    while not exit_flag:
        task_raw = connection.recv(4096)
        task = pickler.unpickle_data(task_raw)

        if task[0] == 'get':
            send_back(ui_state.get())
        elif task[0] == 'display':
            msg = task[1]
            lcd.display(msg)
        elif task[0] == 'Exit':
            exit_flag = True
            break
        elif task[0] == 'select from list':
            lis = task[1]
            Q = task[2]
            time_to_answer = task[3]
            with timeout.timeout(time_to_answer):
                try:
                    ans = lcd.select_elem_from_list(lis, Quest=Q)
                except exception.TimeoutError:
                    lcd.display('time out ...')
                    lcd.display('')
                    ans = None
            send_back(ans)

        elif task[0] == 'select from keylist':
            keylist = task[1]
            default = task[2]
            ans = lcd.select_from_keylist(keylist, default)
            send_back(ans)

        time.sleep(.05)
    return 0
コード例 #6
0
ファイル: walk_commander.py プロジェクト: nicolajbky/GeckoBot
 def _wait(self):
     """ waiting until all PThreads have reached the desired reference """
     with timeout.timeout(self.timeout, 'PThreads TimeOut'):
         while 'PROCESS' in self.status:
             time.sleep(self.cargo.sampling_time)
コード例 #7
0
fileName = 'testlog'
logFormatter = logging.Formatter(
    "%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s]  %(message)s")
rootLogger = logging.getLogger()
rootLogger.setLevel(logging.INFO)

fileHandler = logging.FileHandler("{0}/{1}.log".format(logPath, fileName))
fileHandler.setFormatter(logFormatter)
rootLogger.addHandler(fileHandler)
consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(logFormatter)
rootLogger.addHandler(consoleHandler)

# ------------ CAMERA INIT

with timeout.timeout(2):
    try:
        client.start_server('134.28.136.49')
        time.sleep(1)
        camerasock = client.ClientSocket('134.28.136.49')
    except exception.TimeoutError:
        camerasock = None

# ------------ PATTERN INIT

ptrn_v2_2 = HUI.generate_pattern(.80, 0.80, 0.90, 0.99, 0.80, 0.80, 0.0, 0.0)
ptrn_v2_3 = HUI.generate_pattern(.72, 0.74, 0.99, 0.99, 0.69, 0.63, 0.0, 0.0)
ptrn_v2_4 = HUI.generate_pattern(.64, 0.79, 0.99, 0.99, 0.75, 0.78, 0.0, 0.0)
ptrn_v2_5 = HUI.generate_pattern(.92, 0.68, 0.93, 0.92, 0.90, 0.74, 0.0, 0.0)
ptrn_v2_6 = HUI.generate_pattern(.77, 0.99, 0.97, 0.93, 0.70, 0.71, 0.0, 0.0)
コード例 #8
0
def main(wait=30):
    def fill_rnd_values():
        def gen_rnd_val(mul=1.):
            rnd = random.randint(0, 100)
            if rnd in range(30):
                return None
            return rnd / 100. * mul

        pressure = {'p1': gen_rnd_val(), 'p2': gen_rnd_val()}
        rec_u = {'u1': gen_rnd_val(), 'u2': gen_rnd_val()}
        rec_r = {
            'r1': gen_rnd_val(),
            'r2': gen_rnd_val(),
            'x1': gen_rnd_val(300),
            'y1': gen_rnd_val(300),
            'x2': gen_rnd_val(300),
            'y2': gen_rnd_val(300),
            'x3': np.sin(time.time() / 10.),
            'y3': np.cos(time.time() / 10.)
        }
        timestamp = {'time': time.time()}

        gui_rec.append(pressure)
        gui_rec.append(rec_u)
        gui_rec.append(rec_r)
        gui_rec.append(timestamp)

    def bind_to_client():
        server_socket = socket.socket()
        server_socket.bind(('', 12397))
        server_socket.listen(0)

        conn = server_socket.accept()[0]
        connection = conn.makefile('rb')
        return server_socket, conn, connection

    def recv_sample(connection):
        task_raw = connection.recv(4096)
        task = pickler.unpickle_data(task_raw)
        if task[0] == 'sample':
            send_back(connection, 'ACK')
            return task[1]
        else:
            return 0

    def send_back(connection, data_out):
        data_out_raw = pickler.pickle_data(data_out)
        connection.sendall(data_out_raw)

    def get_sample_from_client_and_put_into_gui_rec(connection):
        sample = recv_sample(connection)
        if sample:
            gui_rec.append(sample)

    gui_rec = datamanagement.GUIRecorder()

    print('wait for client .. ')
    is_client = False
    with timeout.timeout(wait):
        try:
            server_socket, conn, connection = bind_to_client()
            get_sample_from_client_and_put_into_gui_rec(conn)
            is_client = True
            print("client DETECTED!")
        except exception.TimeoutError:
            print("There is no client. fill with rnd vals ...")
            fill_rnd_values()

    print('start GUI .. ')
    gui = GuiThread(gui_rec)
    gui.start()
    time.sleep(.5)
    print('GUI started .. ')

    try:
        while gui.is_running():
            if is_client:
                get_sample_from_client_and_put_into_gui_rec(conn)
            else:
                fill_rnd_values()
            if gui_rec.record:
                save.save_last_sample_as_csv(gui_rec.recorded,
                                             gui_rec.record_filename)

            time.sleep(.03)
    except KeyboardInterrupt:
        print('keyboard interrupt')
    finally:
        connection.close()
        server_socket.close()
        gui.kill()

    gui.join()
    print('all is done')