示例#1
0
def main(conf=None):
    """
    Main function

    Args:
        conf (dict, optional): Configuration dictionary. If left to default
        command line arguments will be parsed. Defaults to None.
    """
    if conf is None:
        conf = vars(parse_args())

    home_dir = os.path.expanduser('~')
    home_conf_path = os.path.join(home_dir, '.conf')
    pysync_path = os.path.join(home_conf_path, 'pysync')
    confs_path = os.path.join(pysync_path, 'configs')
    os.makedirs(confs_path, exist_ok=True)

    if conf.get('config', None) is None:
        print_intro()
        conf = check_for_config(conf, confs_path)
        print()
    else:
        if not os.path.exists(conf['config']):
            test_path = os.path.join(confs_path, conf['config'])
            if not os.path.exists(test_path):
                test_path += '.json'
                if not os.path.exists(test_path):
                    print('The configuration file specified does not exist!')
                    return
            conf['config'] = test_path
        conf = get_config_file(conf)
    while True:
        _conf = configure(conf.copy())
        if _conf != conf:
            conf, done = confirm_conf(_conf)
            if done:
                save_config(conf, confs_path)
                break
        else:
            conf = _conf
            break
    if os.name == 'nt':
        os.system('cls')
    else:
        os.system('clear')
    if conf['host'] == 'Server':
        server_start(conf)
    else:
        client_start(conf)
示例#2
0
    retmsg = xdrive_pb2.XMsg()
    rs = retmsg.rowset
    # return 4 columns, (filename, ordinal, score, class)
    col1 = rs.columns.add()
    col2 = rs.columns.add()
    col3 = rs.columns.add()
    col4 = rs.columns.add()
    col1.nrow = len(ret)
    col2.nrow = len(ret)
    col3.nrow = len(ret)
    col4.nrow = len(ret)

    for i in range(len(ret)):
        (a, b, c, d) = ret[i]
        # print("Return {0}, {1}, {2}, {3}.\n".format(a, b, c, d))
        col1.nullmap.append(False)
        col1.sdata.append(a)
        col2.nullmap.append(False)
        col2.i32data.append(b)
        col3.nullmap.append(False)
        col3.f64data.append(c)
        col4.nullmap.append(False)
        col4.sdata.append(d)

    return retmsg


if __name__ == '__main__':
    init_fpga()
    server.server_start("/tmp/ml.sock", img_classify)
示例#3
0
def settings(program_type=None, port=None, ip=None):
    """
    Get the parameters for how to run the program
    :param program_type: Server = 1, Client = 2
    :param port: Port to communicate on
    :param ip: IP of the server to connect to
    """

    try:
        # Detect if command line arguments were used
        if program_type is not None and port is not None:

            # Create new settings and overwrite old settings file if it exists
            raise FileNotFoundError

        # Try to load config file
        with open('settings.txt', 'r') as options:

            # Detect basic settings
            server_or_client = check_program_type(options.readline().strip())
            port = check_port(options.readline().strip())

            # Start as server on specified port
            if server_or_client == 'server':
                server.server_start(port=int(port))

            # Start as client with specified port and IP
            elif server_or_client == 'client':
                ip = check_server_ip(options.readline().strip())
                client.client_start(port=int(port), ip=ip)

    # If no config file exists, run first time setup
    except FileNotFoundError:

        if program_type is None:
            # Welcome message on first time setup
            print('Welcome to Secure Storage!')
            print(
                'It seems this is the first time you are running this program, let\'s set a few things up.\n'
            )

        # Get the program type
        program_type = check_program_type(program_type)

        # Get the port number
        port = check_port(port)

        # Ask for the server IP if the program will run as a client
        if program_type == 'client':

            # Get the server IP
            ip = check_server_ip(ip)

        # Write the options to a file
        save_settings(program_type=program_type, port=port, ip=ip)

        # Spawn Server or Client
        if program_type == 'server':
            server.server_start(port=int(port))
        elif program_type == 'client':
            client.client_start(port=int(port), ip=ip)
示例#4
0
    
if __name__=='__main__':
    global g_qIn, g_qOut

    # Test: an echo server.
    if len(sys.argv) != 3:
        raise SystemExit("Usage: yolov2.py [server|client] addr")

    if sys.argv[1] == "server":
        qIn = multiprocessing.Queue(1)
        qOut = multiprocessing.Queue(1)
        fpgaProc = multiprocessing.Process(target=fpga_process, args=(qIn, qOut))
        fpgaProc.start()
        g_qIn = qIn
        g_qOut = qOut
        server.server_start(sys.argv[2], obj_detect) 
    elif sys.argv[1] == "client":
        sock = server.cli_connect(sys.argv[2])
        xmsg = xdrive_pb2.XMsg()
        col1 = xmsg.rowset.columns.add()
        col1.nrow = 1
        col1.nullmap.append(False)
        col1.sdata.append("/home/ftian/BJVideo/24-converted.mp4") 
        col2 = xmsg.rowset.columns.add()
        col2.nrow = 1
        col2.nullmap.append(False)
        col2.f32data.append(0.0) 
        col3 = xmsg.rowset.columns.add()
        col3.nrow = 1
        col3.nullmap.append(False)
        col3.f32data.append(10.0) 
示例#5
0
        col3.nullmap.append(False)
        col3.f64data.append(c)
        col4.nullmap.append(False)
        col4.sdata.append(d)

    return retmsg


if __name__ == '__main__':
    # Test: an echo server.
    if len(sys.argv) != 3:
        raise SystemExit("Usage: googlenet.py [server|client] addr")

    if sys.argv[1] == "server":
        init_fpga()
        server.server_start(sys.argv[2], img_classify)
    elif sys.argv[1] == "client":
        imgs = [
            "apple.jpeg", "banana.jpeg", "beer.jpeg", "coffee.jpeg",
            "egg.jpeg", "salad.jpeg"
        ]
        sock = server.cli_connect(sys.argv[2])
        for ii in range(6):
            xmsg = xdrive_pb2.XMsg()
            col = xmsg.rowset.columns.add()
            col.nrow = 1
            col.nullmap.append(False)
            col.sdata.append("./xdrive/images/food/" + imgs[ii])

            server.writeXMsg(sock, xmsg)
            ret = server.readXMsg(sock)