예제 #1
0
파일: tui.c 프로젝트: amigrave/PUAE
static void CPUOptions (void)
{
    char *tmp;
    int c = 0;
    for (;;) {
	tui_selwin(0);
	print_configuration ();

	c = tui_menubrowse (cpumenu, MENU_COL_OFFSET, 5, c, MAX_MENU_HEIGHT);
	if (c == -1)
	    break;
	else switch (c) {
	 case 0:
	    currprefs.cpu_level++;
	    if (currprefs.cpu_level > 3)
		currprefs.cpu_level = 0;
	    /* Default to 32 bit addressing when switching from a 68000/68010 to a 32 bit CPU */
	    if (currprefs.cpu_level == 2)
		currprefs.address_space_24 = 0;
	    if (currprefs.cpu_level != 0)
		currprefs.cpu_compatible = 0;
	    break;
	}
    }
}
예제 #2
0
파일: tui.c 프로젝트: amigrave/PUAE
static void DiskOptions (void)
{
    char tmp[256];
    int c = 0;

    for (;;) {
	char *sel;

	tui_selwin(0);
	print_configuration();

	c = tui_menubrowse (diskmenu, MENU_COL_OFFSET, 5, c, MAX_MENU_HEIGHT);
	if (c == -1)
	    break;
	else switch (c) {
	 case 0:
	 case 1:
	 case 2:
	 case 3:
	    sprintf (tmp, "Select a diskfile for DF%d:", c);
	    sel = tui_filereq("*.adf", currprefs.df[c], tmp);
	    if (sel == NULL)
		break;
	    strcpy (currprefs.df[c], sel);
	    break;
	}
    }
}
예제 #3
0
파일: tui.c 프로젝트: amigrave/PUAE
static void OtherOptions (void)
{
    char tmp[256];
    int c = 0;

    for (;;) {
	tui_selwin (0);
	print_configuration ();
	c = tui_menubrowse (miscmenu, MENU_COL_OFFSET, 5, c, MAX_MENU_HEIGHT);
	if (c == -1) {
	    break;
	} else switch (c) {
	 case 0:
	    currprefs.jport0 = (currprefs.jport0 + 1) % 6;
	    if (currprefs.jport0 == currprefs.jport1)
	      currprefs.jport1 = (currprefs.jport1 + 5) % 6;
	    break;
	 case 1:
	    currprefs.jport1 = (currprefs.jport1 + 1) % 6;
	    if (currprefs.jport0 == currprefs.jport1)
	      currprefs.jport0 = (currprefs.jport0 + 5) % 6;
	    break;
	 case 2:
	    tui_wgets (tmp, "Enter new CPU emulation speed", 6);
	    if (atoi (tmp) < 1 || atoi (tmp) > 20)
		tui_errorbox ("Unsupported CPU emulation speed");
	    else
		currprefs.m68k_speed = atoi (tmp);
	    break;
	}
    }
}
예제 #4
0
파일: main.c 프로젝트: top4e/tmdbclt
static void configuration(tmdb_options_t *opts)
{
	tmdb_configuration_t	*cfg;

	cfg = tmdb_configuration();
	print_configuration(cfg);
	tmdb_clean_configuration(cfg);
}
예제 #5
0
파일: tui.c 프로젝트: ApolloniaUK/PUAE
static void HDOptions (void)
{
    char *buff;
    char tmp[256];
    char mountvol[256];
    char mountdir[256];
    int c = 0;

    for (;;){

	tui_selwin(0);
	print_configuration();

	c = tui_menubrowse (hdmenu, MENU_COL_OFFSET, 5, c, MAX_MENU_HEIGHT);
	if (c == -1)
	    break;
	else switch (c) {
	 case 0:
	    tui_wgets (mountvol, "Enter mounted volume name", 10);
	    if (strlen (mountvol) == 0)
		break;
	    if (mountvol[strlen(mountvol)-1]==':')
		mountvol[strlen(mountvol)-1] = 0;
	    tui_wgets (mountdir, "Enter mounted volume path", 78);
	    add_filesys_unit (currprefs.mountinfo, "", mountvol, mountdir, 0, 0, 0, 0, 0, 0, 0);
	    break;
	 case 1:
	    tui_wgets (mountvol, "Enter mounted volume name", 10);
	    if (strlen (mountvol) == 0)
		break;
	    if (mountvol[strlen (mountvol)-1]==':')
		mountvol[strlen (mountvol)-1] = 0;
	    tui_wgets (mountdir, "Enter mounted volume path", 78);
	    add_filesys_unit (currprefs.mountinfo, "", mountvol, mountdir, 1, 0, 0, 0, 0, 0, 0);
	    break;
	 case 2:
	    buff = tui_filereq("*", "", "Select the hardfile to be mounted");
	    if (buff == NULL)
		break;
	    strcpy (mountvol, buff);
	    tui_wgets (mountdir, "Enter number of sectors per track", 4);
	    tui_wgets (mountdir + 10, "Enter number of heads", 4);
	    tui_wgets (mountdir + 20, "Enter number of reserved blocks", 3);
	    tui_wgets (mountdir + 30, "Enter block size", 4);
	    buff = add_filesys_unit (currprefs.mountinfo, "", 0, mountvol, 1,
				     atoi (mountdir), atoi (mountdir + 10),
				     atoi (mountdir + 20), atoi (mountdir + 30), 0, 0);
	    if (buff)
		tui_errorbox (buff);
	    break;
	 case 3:
	    tui_wgets (mountvol, "Enter number of volume to be removed (0 for UAE0:, etc.)", 2);
	    if (kill_filesys_unit (currprefs.mountinfo, atoi (mountvol)) == -1)
		tui_errorbox ("Volume does not exist");
	    break;
	}
    }
}
예제 #6
0
파일: tui.c 프로젝트: ApolloniaUK/PUAE
static int do_gui (int mode)
{
    char cwd[1024];

    if (getcwd (cwd, 1024) == NULL)
	return 0;

    tui_setup ();

    for (;;) {
	int c;

	tui_selwin (0);
	print_configuration ();
	c = tui_menubrowse (mode == 0 ? mainmenu2 : mainmenu, MENU_COL_OFFSET, 4, 0, MAX_MENU_HEIGHT);
	if (c == -1) {
	    tui_shutdown ();
	    return -2;
	}
	if (mode == 1) {
	    if (c == 8)
		break;
	    switch (c) {
	     case 0: DiskOptions (); break;
	     case 1: VideoOptions (); break;
	     case 2: MemoryOptions (); break;
	     case 3: CPUOptions (); break;
	     case 4: HDOptions (); break;
	     case 5: SoundOptions (); break;
	     case 6: OtherOptions (); break;
	     case 7: save_settings (); break;
	    }
	} else {
	    if (c == 5)
		break;
	    switch (c) {
	     case 0: DiskOptions (); break;
	     case 1: OtherOptions (); break;
	     case 2: save_settings (); break;
	     case 3: uae_reset (0); break;
	     case 4: uae_quit (); break;
	    }
	}
    }
    tui_shutdown ();

    chdir (cwd);
    return 0;
}
예제 #7
0
int main(int argc, char *argv[])
{
	
	if (create_initial_conditions() == -1)
	{
		printf("\nCOULD NOT ALLOCATE MEMORY. EXITING NOW!\n");
		exit(-1);
	}
	create_initial_configuration();
	printf("\n******* CURRENT CONFIGURATION *******\n");
	print_configuration(current_board_config->matrix);
	num_step = 0;
	printf("\n******* GOING TO EXIT *******\n");
	go_to_exit(&current_board_config);
	return 0;
}
예제 #8
0
파일: main.c 프로젝트: rtubio/linklayertool
/* main */
int main(int argc, char **argv)
{

	configuration_t *cfg = NULL;
	ll_socket_t *ll_socket = NULL;
	
	/* 1) Runtime configuration is read from the CLI (POSIX.2). */
	cfg = create_configuration(argc, argv);
	print_configuration(cfg);

	/* 2) Link layer socket is open. */
	if ( ( ll_socket = open_ll_socket
						(	cfg->is_transmitter,
							cfg->tx_delay,
							cfg->if_name,
							cfg->lsap,
							cfg->frame_type	)
						) == NULL )
		{ handle_app_error("Could not open ll_socket.\n"); }
	
	#ifdef KERNEL_RING
		log_app_msg("TX socket open with fd = %d\n", ll_socket->tx_socket_fd);
		log_app_msg("RX socket open with fd = %d\n", ll_socket->rx_socket_fd);
	#else
		log_app_msg("Socket open with fd = %d\n", ll_socket->socket_fd);
	#endif

	/* 3) Set-up this programe either as a transmitter or a receiver. */
	if ( cfg->is_transmitter == true )
	{
		log_app_msg("Setting up transmitter mode...\n");
	}
	else
	{
		log_app_msg("Setting up receiver mode...\n");
	}

	//exit(EXIT_SUCCESS);
	start_ll_socket(ll_socket);

	// 4) sockets are closed before exiting application
	close_ll_socket(ll_socket);
	log_app_msg("Socket is closed.\n");

	exit(EXIT_SUCCESS);

}
예제 #9
0
int main(void)
{
        char       query_string[256];
        int        i;
        PGconn     *conn;
        PGresult   *res;
        rate_limit_configuration_t config;

        conn = PQconnectdb("dbname=rate_limiter");

        if (PQstatus(conn) == CONNECTION_BAD) {
                fprintf(stderr, "Connection to database failed.\n");
                fprintf(stderr, "%s", PQerrorMessage(conn));
                exit(1);
        }

        sprintf(query_string, "SELECT * FROM configuration");

        res = PQexec(conn, query_string);

        if (PQresultStatus(res) != PGRES_TUPLES_OK) {
                fprintf(stderr, "SELECT query failed.\n");
                PQclear(res);
                PQfinish(conn);
                exit(1);
        }

	rate_limit_configuration_t clients[PQntuples(res)];

	for (i = 0; i < PQntuples(res); i++) {
                config.service_name = PQgetvalue(res, i, 1);
                config.client_id = PQgetvalue(res, i, 2);
                config.rate_limit = strtol(PQgetvalue(res, i, 3), 0, 10);
                config.window_size = strtol(PQgetvalue(res, i, 4), 0, 10);
		clients[i] = config;
        }

	for (i = 0; i < PQntuples(res); i++) {
		print_configuration(clients[i]);
	}

        PQclear(res);
        PQfinish(conn);

        return 0;
}
예제 #10
0
파일: tui.c 프로젝트: ApolloniaUK/PUAE
static void SoundOptions (void)
{
    char tmp[256];
    int c = 0;
    for (;;) {
	tui_selwin(0);
	print_configuration ();
	c = tui_menubrowse (soundmenu, MENU_COL_OFFSET, 5, c, MAX_MENU_HEIGHT);
	if (c == -1)
	    break;
	else switch (c) {
	 case 0:
	    currprefs.produce_sound++;
	    if (currprefs.produce_sound > 3)
		currprefs.produce_sound = 0;
	    break;

	 case 1:
	    tui_wgets (tmp, "Enter new maximum sound buffer size in bytes", 6);
	    if (atoi (tmp) < 128 || atoi (tmp) > 65536)
		tui_errorbox ("Insane value for maximum sound buffer size");
	    else
		currprefs.sound_maxbsiz = atoi (tmp);
	    break;

	 case 2:
	    tui_wgets (tmp, "Enter new number of bits", 3);
	    if (atoi (tmp)!= 8 && atoi (tmp) != 16)
		tui_errorbox ("Unsupported number of bits");
	    else
		currprefs.sound_bits = atoi (tmp);
	    break;

	 case 3:
	    tui_wgets (tmp, "Enter new sound output frequency", 6);
	    if (atoi (tmp) < 11025 || atoi (tmp) > 44100)
		tui_errorbox ("Unsupported frequency");
	    else
		currprefs.sound_freq = atoi (tmp);
	    break;
	 case 4:
	    currprefs.stereo = (currprefs.stereo + 1) % 3;
	    break;
	}
    }
}
예제 #11
0
/* print device descriptors */
static void print_device(openusb_devid_t devid, int indent)
{
	struct usb_device_desc dev;
	unsigned char *buf=NULL;
	uint16_t buflen = 0;
	int i, ret;

	printf("\n%.*s+ device #%d\n", indent * 2, "                ",
			(int)devid);

	ret = openusb_parse_device_desc(libhandle,devid, NULL, 0,&dev);
	if(ret != 0) {
		return;
	}

	printf("bcdUSB:                 %04xh\n", dev.bcdUSB);
	printf("bDeviceClass:           %02x\n", dev.bDeviceClass);
	printf("bDeviceSubClass:        %02x\n", dev.bDeviceSubClass);
	printf("bDeviceProtocol:        %02x\n", dev.bDeviceProtocol);
	printf("bMaxPacketSize0:        %02x\n", dev.bMaxPacketSize0);
	printf("idVendor:               %04xh\n", dev.idVendor);
	printf("idProduct:              %04xh\n", dev.idProduct);
	printf("bcdDevice:              %04xh\n", dev.bcdDevice);
	printf("iManufacturer:          %d\n", dev.iManufacturer);
	printf("iProduct:               %d\n", dev.iProduct);
	printf("iSerialNumber:          %d\n", dev.iSerialNumber);
	printf("bNumConfigurations:     %d\n", dev.bNumConfigurations);
	printf("\n");
	
	for (i = 0; i < dev.bNumConfigurations; i++) {
		struct usb_config_desc cfg;

		ret = openusb_parse_config_desc(libhandle, devid, buf,
				buflen, i, &cfg);
		if(ret != 0) {
			printf("parse config desc fail: %s\n",
				openusb_strerror(ret));
			return;
		}

		print_configuration(devid, i, &cfg);
	}

	printf("\n");
}
예제 #12
0
파일: tui.c 프로젝트: ApolloniaUK/PUAE
static void MemoryOptions (void)
{
    char *tmp;
    int c = 0;
    for (;;) {

	tui_selwin(0);
	print_configuration ();

	c = tui_menubrowse (memorymenu, MENU_COL_OFFSET, 5, c, MAX_MENU_HEIGHT);
	if (c == -1)
	    break;
	else switch (c) {
	 case 0:
	    if (currprefs.fastmem_size == 0)
		currprefs.fastmem_size = 0x200000;
	    else if (currprefs.fastmem_size == 0x800000)
		currprefs.fastmem_size = 0;
	    else
		currprefs.fastmem_size <<= 1;
	    break;
	 case 1:
	    if (currprefs.chipmem_size == 0x800000)
		currprefs.chipmem_size = 0x80000;
	    else
		currprefs.chipmem_size <<= 1;
	    if (currprefs.chipmem_size > 0x200000)
		currprefs.fastmem_size = 0;
	    break;
	 case 2:
	    if (currprefs.bogomem_size == 0)
		currprefs.bogomem_size = 0x40000;
	    else if (currprefs.bogomem_size == 0x100000)
		currprefs.bogomem_size = 0;
	    else
		currprefs.bogomem_size <<= 1;
	    break;
	 case 3:
	    tmp = tui_filereq ("*.rom", currprefs.romfile, "Select a ROM image");
	    if (tmp != NULL)
		strcpy (currprefs.romfile, tmp);
	    break;
	}
    }
}
예제 #13
0
/* Set up an IPC pipe server that hands out listen sockets to the worker
 * threads. It's kind of cumbersome for such a simple operation, maybe we
 * should revive uv_import() and uv_export().
 */
void start_connection_dispatching(uv_handle_type type, unsigned int num_servers, struct server_ctx* servers, char* listen_address, int listen_port, bool tcp_nodelay)
{
    int rc;
    struct ipc_server_ctx ctx;
    uv_loop_t* loop;
    unsigned int i;
    
    loop = uv_default_loop();
    ctx.num_connects = num_servers;
    ctx.tcp_nodelay = tcp_nodelay;
    
    if (type == UV_TCP)
    {
        uv_ip4_addr(listen_address, listen_port, &listen_addr);
        
        rc = uv_tcp_init(loop, (uv_tcp_t*) &ctx.server_handle);
        
        if (ctx.tcp_nodelay) {
            rc = uv_tcp_nodelay((uv_tcp_t*) &ctx.server_handle, 1);
        }

        rc = uv_tcp_bind((uv_tcp_t*) &ctx.server_handle, (const struct sockaddr*)&listen_addr, 0);
        print_configuration();
        printf("Listening...\n");
    }
    
    rc = uv_pipe_init(loop, &ctx.ipc_pipe, 1);
    rc = uv_pipe_bind(&ctx.ipc_pipe, "HAYWIRE_CONNECTION_DISPATCH_PIPE_NAME");
    rc = uv_listen((uv_stream_t*) &ctx.ipc_pipe, 128, ipc_connection_cb);
    
    for (i = 0; i < num_servers; i++)
        uv_sem_post(&servers[i].semaphore);
    
    rc = uv_run(loop, UV_RUN_DEFAULT);
    uv_close((uv_handle_t*) &ctx.server_handle, NULL);
    rc = uv_run(loop, UV_RUN_DEFAULT);
    
    for (i = 0; i < num_servers; i++)
        uv_sem_wait(&servers[i].semaphore);
}
예제 #14
0
파일: ga.cpp 프로젝트: franaln/evolve
GA::GA(TString configfile)
{
  read_configuration(configfile);
  print_configuration();

  init_random();

  // output file
  output.open(m_name+".log");

  // chains
  m_signal_chain = new TChain(m_signal_treename);
  for (auto signal_file : m_signal_files)
    m_signal_chain->Add(signal_file);

  m_background_chain = new TChain(m_background_treename);
  for (auto bkg_file : m_background_files)
    m_background_chain->Add(bkg_file);

  // init some variables
  m_stall_generation = 0;

  // histograms
  Int_t bins[m_nvars];
  Double_t xmin[m_nvars];
  Double_t xmax[m_nvars];

  for (unsigned int i=0; i<m_nvars; i++) {
    bins[i] = (m_variables[i].max - m_variables[i].min)/m_variables[i].step;
    xmin[i] = m_variables[i].min;
    xmax[i] = m_variables[i].max;
  }

  hist_s = new THnSparseD("hist_s", "Signal", m_nvars, bins, xmin, xmax);
  hist_b = new THnSparseD("hist_b", "Background", m_nvars, bins, xmin, xmax);
  hist_z = new THnSparseD("hist_z", "Significance", m_nvars, bins, xmin, xmax);

}
예제 #15
0
static void on_refresh(void)
{
  struct usb_bus *bus;
  struct usb_device *dev;
  const struct usb_version *version;

  edit_printf_init();

  usb_find_devices();

  version = usb_get_version();

  if(version)
    {
      edit_printf("DLL version:\t%d.%d.%d.%d\r\n",
                  version->dll.major, version->dll.minor, 
                  version->dll.micro, version->dll.nano);

      edit_printf("Driver version:\t%d.%d.%d.%d\r\n\r\n",
                  version->driver.major, version->driver.minor, 
                  version->driver.micro, version->driver.nano);
    }

  edit_printf("bus/device  idVendor/idProduct\r\n");

  for (bus = usb_get_busses(); bus; bus = bus->next) {
    for (dev = bus->devices; dev; dev = dev->next) {
      int ret, i;
      char string[256];
      usb_dev_handle *udev;

      edit_printf("%s/%s     %04X/%04X\r\n", bus->dirname, dev->filename,
                  dev->descriptor.idVendor, dev->descriptor.idProduct);
      udev = usb_open(dev);
      
      if (udev) {
        if (dev->descriptor.iManufacturer) {
          ret = usb_get_string_simple(udev, dev->descriptor.iManufacturer,
                                      string, sizeof(string));
          if (ret > 0)
            edit_printf("- Manufacturer : %s\r\n", string);
          else
            edit_printf("- Unable to fetch manufacturer string\r\n");
        }

        if (dev->descriptor.iProduct) {
          ret = usb_get_string_simple(udev, dev->descriptor.iProduct, string,
                                      sizeof(string));
          if (ret > 0)
            edit_printf("- Product      : %s\r\n", string);
          else
            edit_printf("- Unable to fetch product string\r\n");
        }

        if (dev->descriptor.iSerialNumber) {
          ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber, 
                                      string, sizeof(string));
          if (ret > 0)
            edit_printf("- Serial Number: %s\r\n", string);
          else
            edit_printf("- Unable to fetch serial number string\r\n");
        }

        usb_close (udev);
      }

      if (!dev->config) {
        edit_printf("  Couldn't retrieve descriptors\r\n");
        continue;
      }

      for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
        print_configuration(&dev->config[i]);
    }
  }

  SendMessage(edit_box, WM_SETTEXT, 0, (LPARAM) edit_buffer); 
  edit_printf_free();
}
예제 #16
0
파일: tui.c 프로젝트: ApolloniaUK/PUAE
static void VideoOptions (void)
{
    char tmp[256];
    int c = 0;

    for (c = 0; c < 10; c++)
	if (videomenu[c].val == 'M') {
	    if (video_mode_menu == NULL)
		videomenu[c].val = -4;
	    break;
	}

    c = 0;
    for (;;) {

	tui_selwin(0);
	print_configuration();

	c = tui_menubrowse (videomenu, MENU_COL_OFFSET, 5, c, MAX_MENU_HEIGHT);
	if (c == -1)
	    break;
	else switch (c) {
	 case 0:
	    tui_wgets (tmp, "Enter new video mode width", 4);
	    if (atoi (tmp) < 320 || atoi (tmp) > 1600 /* maybe we'll implement SHires */)
		tui_errorbox ("Insane value for video mode width");
	    else
		currprefs.gfx_width = atoi (tmp);
	    break;
	 case 1:
	    tui_wgets (tmp, "Enter new video mode height", 4);
	    if (atoi (tmp) < 200 || atoi (tmp) > 800 /* whatever */)
		tui_errorbox ("Insane value for video mode height");
	    else
		currprefs.gfx_height = atoi (tmp);
	    break;
	 case 2:
	    currprefs.color_mode++;
	    if (currprefs.color_mode > MAX_COLOR_MODES)
		currprefs.color_mode=0;
	    break;
	 case 3:
	    c = tui_menubrowse (video_mode_menu, 4, 6, 0, 15);
	    if (c != -1)
		vidmode_menu_selected(c);
	    c = 3;
	    break;
	 case 4:
	    currprefs.gfx_lores_mode = !currprefs.gfx_lores_mode;
	    break;
	 case 5:
	    currprefs.gfx_xcenter = (currprefs.gfx_xcenter + 1) % 3;
	    break;
	 case 6:
	    currprefs.gfx_ycenter = (currprefs.gfx_ycenter + 1) % 3;
	    break;
	 case 7:
	    currprefs.gfx_vresolution = !currprefs.gfx_vresolution;
	    break;
	 case 8:
//	    currprefs.gfx_correct_aspect = !currprefs.gfx_correct_aspect;
	    break;
	 case 9:
	    currprefs.gfx_framerate++;
	    if (currprefs.gfx_framerate > 9)
		currprefs.gfx_framerate=1;
	    break;
	 case 10:
	    currprefs.gfxmem_size += 0x100000;
	    if (currprefs.gfxmem_size > 0x800000)
		currprefs.gfxmem_size = 0;
	    break;
	}
    }
}
예제 #17
0
파일: imsd.c 프로젝트: bedis/imsd
int 
main( int argc, char *argv[] ) {
	CONFIGURATION conf;
	int shm_fd;
	RINGBUFFER rb;
	char *logs;

	/* NETWORK Socket */
	int sockfd;
	ssize_t n;
	socklen_t len;
	struct sockaddr_in cliaddr;
	char msg[NET_BUF_SIZE];
	char clientip[IP_STRLEN];

	/* Other variables */
	int c;

	erase_conf_struct( &conf );

	 /* Analyze command line arguments */
	opterr = 0;
	while ((c = getopt (argc, argv, AVAILABLE_ARGUMENTS)) != -1)
		switch(c) {
			case 'd':
				conf.debug = YES;
				break;
			case 'f':
				break;
			case 'n':
				conf.nb_bytes = atoll(optarg);
				break;
			case 'h':
				help(0);
				break;
			case '?':
				if ( (optopt == 'f') || (optopt == 'n') )
					fprintf(stderr, 
						"-%c: missing arguments\n",
						optopt);
				else if (isprint(optopt))
					fprintf (stderr, 
						"Unknown option `-%c'.\n",
						optopt);
				else
					fprintf (stderr,
						"Unknown option character `\\x%x'.\n", 
						optopt);
				help(1);
				break;
			default:
				help(1);
		}

	/* 
	 * Init phase
	 */
	/* Configuration initialisation */
	init_configuration( &conf );
	if (conf.debug == YES)
		print_configuration( &conf );

	/* SHM setup */
	if ((shm_fd = create_shm(SHM_PATH, conf.nb_bytes)) < 0)
		MANAGE_ERROR("can't create shm", TRUE, EXIT_FAILURE);

	if ((logs = mmap(NULL, conf.nb_bytes, (PROT_READ | PROT_WRITE), 
					MAP_SHARED, shm_fd, 0)) == MAP_FAILED)
		MANAGE_ERROR("mmap", TRUE, EXIT_FAILURE);

	/* ring buffer */
	rb_init(&rb, logs, conf.nb_bytes);
	//rb_info(&rb);

	/* main listening daemon */
	udp_daemon_setup(&sockfd, 1514);

	/* Signals management */
	(void) signal(SIGINT, leave);

	len = sizeof(cliaddr);

	/* 
	 * Main Loop
	 */
	while ((n = recvfrom(sockfd, msg, NET_BUF_SIZE, 0, 
				(struct sockaddr *)&cliaddr, &len)) > 0) {
		/*if (memcmp(msg, "dump logs", 9) == 0) {
			printf("DUMP:\n");
			rb_dump(&rb);
			continue;
		}
		if (memcmp(msg, "print logs", 10) == 0) {
			printf("PRINT:\n");
			rb_print(&rb);
			continue;
		}
		*/
		// n - 1 to remove the remaining \n
		memcpy(clientip, inet_ntoa(cliaddr.sin_addr), IP_STRLEN);
		//rb_add_row(&rb, msg, n);
		rb_add_row(&rb, msg, n, clientip);
		memset(msg, '\0', NET_BUF_SIZE);
	}
	printf("\n");
	unlink_shm(SHM_PATH);

	return EXIT_SUCCESS;
}
예제 #18
0
int main(void)
{
  struct usb_bus *bus;
  struct usb_device *dev;

  usb_init();

  usb_find_busses();
  usb_find_devices();

  printf("bus/device  idVendor/idProduct\n");
  for (bus = usb_busses; bus; bus = bus->next) {
    for (dev = bus->devices; dev; dev = dev->next) {
      int ret, i, i_stripe;
      char string[256];
      usb_dev_handle *udev;
      
      printf("%s/%s     %04X/%04X\n", bus->dirname, dev->filename,
	     dev->descriptor.idVendor, dev->descriptor.idProduct);
      
      if ((dev->descriptor.idVendor == 0x04B8) 
	  && (dev->descriptor.idProduct == 0x0001)) {
	udev = usb_open(dev);
	if (udev) {
	  int in_ep;
	  int out_ep;
	  char bytes[4096];

	  usb_set_debug(10);

	  if (dev->descriptor.iManufacturer) {
	    ret = usb_get_string_simple(udev, dev->descriptor.iManufacturer, string, sizeof(string));
	    if (ret > 0)
	      printf("- Manufacturer : %s\n", string);
	    else
	      printf("- Unable to fetch manufacturer string\n");
	  }
	  
	  if (dev->descriptor.iProduct) {
	    ret = usb_get_string_simple(udev, dev->descriptor.iProduct, string, sizeof(string));
	    if (ret > 0)
	      printf("- Product      : %s\n", string);
	    else
	      printf("- Unable to fetch product string\n");
	  }
	  
	  if (dev->descriptor.iSerialNumber) {
	    ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber, string, sizeof(string));
	    if (ret > 0)
	      printf("- Serial Number: %s\n", string);
	    else
	      printf("- Unable to fetch serial number string\n");
	  }


	    
	  ret = usb_claim_interface (udev, 0);

	  printf ("claim %d\n", ret);
	  
	  out_ep = 0x01;
	  in_ep = 0x82;

	  bytes[1] = 0x00;

	  bytes[0] = 0x06;
	  ret = usb_bulk_write (udev, out_ep,bytes, 2, 100);
	  printf ("first write %d\n", ret);
	  ret = usb_bulk_read (udev, in_ep,bytes, 19, 100);
	  printf ("first read %d\n", ret);

	  bytes[0] = 0x07;
	  ret = usb_bulk_write (udev, out_ep,bytes, 2, 100);
	  printf ("2nd write %d\n", ret);
	  ret = usb_bulk_read (udev, in_ep,bytes, 28, 100);
  	  printf ("2nd read %d\n", ret);

	  bytes[0] = 0x06;
	  ret = usb_bulk_write (udev, out_ep,bytes, 2, 100);
	  printf ("3 write %d\n", ret);
	  ret = usb_bulk_read (udev, in_ep,bytes, 19, 100);
	  printf ("3 read %d\n", ret);

	  bytes[0] = 0x05;
	  ret = usb_bulk_write (udev, out_ep,bytes, 2, 100);
	  printf ("4 write %d\n", ret);
	  ret = usb_bulk_read (udev, in_ep, bytes, 21, 100);
	  printf ("4 read %d\n", ret);

	  sprintf(bytes, "%c%c%c%c%c%c%c%c",
		  0x00, 0x00,0x00,0x00, 0x01,0x01, 0x00,0x03) ;
	  ret = usb_bulk_write (udev, out_ep,bytes, 8, 100);
	  printf ("5 write %d\n", ret);
	  ret = usb_bulk_read (udev, in_ep, bytes, 15, 100);
	  printf ("5 read %d\n", ret);

	  bytes[0] = 0x07;
	  ret = usb_bulk_write (udev, out_ep, bytes, 2, 100);
	  printf ("2nd write %d\n", ret);
	  ret = usb_bulk_read (udev, in_ep, bytes, 28, 100);
  	  printf ("2nd read %d\n", ret);

	  sprintf(bytes, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
		  0x02,0x00,0xff,0x40,0x01,0x2c,0x00,0x00,
		  0x00,0x00,0x0d,0x50,0x09,0x4b,0x00,0x36,
		  0xff,0x00,0x01,0xff,0xfe,0x00,0xd2,0x01,
		  0x29);
	  ret = usb_bulk_write (udev, out_ep,bytes, 25, 100);
	  printf ("5 write %d\n", ret);
	  ret = usb_bulk_read (udev, in_ep, bytes, 30, 100);
	  printf ("5 read %d\n", ret);

	  for(i_stripe = 0 ; i_stripe < 54 ; i_stripe++) {
	    int j;
	    sprintf(bytes, "%c%c%c%c%c%c%c",
		    0x04,  0x00, 0x01, 0x00, 0x00, 0x00, 0x68);
	    ret = usb_bulk_write (udev, out_ep,bytes, 7, 100);
	    printf ("5 write %d\n", ret);

	    for (j = 0 ; j < 4; j++) {
	      sprintf(bytes, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
		      0xa0,0x1d,
		      0x74,0x03,0x0e,0x80,0x01,0xd0,0x40,0x3a,
		      0xe8,0x07,0x1d,0x00,0x03,0xa0,0x80,0x74,
		      0xd0,0x0e,0x3a,0x01,0x07,0x40,0x00,0xe8);
	      ret = usb_bulk_write (udev, out_ep,bytes, 26, 100);
	      printf ("5 write %d\n", ret);
	    }
	  }
	  bytes[1] = 0x00;

	  bytes[0] = 0x03;
	  ret = usb_bulk_write (udev, out_ep,bytes, 2, 100);
	  printf ("3 write %d\n", ret);
	  ret = usb_bulk_read (udev, in_ep,bytes, 15, 100);
	  printf ("3 read %d\n", ret);

	  bytes[0] = 0x01;
	  ret = usb_bulk_write (udev, out_ep,bytes, 2, 100);
	  printf ("4 write %d\n", ret);
	  ret = usb_bulk_read (udev, in_ep, bytes, 15, 100);
	  printf ("4 read %d\n", ret);

  	  if (usb_release_interface (udev,0) < 0) {
	    printf ("Could not release interface %d\n", 0);
	  } else {
	    printf ("Released interface %d.\n", 0);	    
	  }  

	  usb_close (udev);
	}

	if (!dev->config) {
	  printf("  Couldn't retrieve descriptors\n");
	  continue;
	}
	
	for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
	  print_configuration(&dev->config[i]);

	

      }
    }
  }
  return 0;
}
예제 #19
0
파일: usb.c 프로젝트: JokeLook/dbstar
static int print_device(struct usb_device *dev, int level)
{
  usb_dev_handle *udev;
  char description[256];
  char string[256];
  int ret, i;
//	indent_usb_table = 0;
  udev = usb_open(dev);
  if (udev) {
    if (dev->descriptor.iManufacturer) {
      ret = usb_get_string_simple(udev, dev->descriptor.iManufacturer, string, sizeof(string));
      if (ret > 0)
        snprintf(description, sizeof(description), "%s - ", string);
      else
        snprintf(description, sizeof(description), "%04X - ",
                 dev->descriptor.idVendor);
    } else
      snprintf(description, sizeof(description), "%04X - ",
               dev->descriptor.idVendor);
	LOGE("The VID is %04X \n",dev->descriptor.idVendor);
	LOGE("indent_usb_table is %d\n",indent_usb_table);
	usb_table[indent_usb_table].vid = dev->descriptor.idVendor;
    
    if (dev->descriptor.iProduct) {
      ret = usb_get_string_simple(udev, dev->descriptor.iProduct, string, sizeof(string));
      if (ret > 0)
        snprintf(description + strlen(description), sizeof(description) -
                 strlen(description), "%s", string);
      else
        snprintf(description + strlen(description), sizeof(description) -
                 strlen(description), "%04X", dev->descriptor.idProduct);
    } else
      snprintf(description + strlen(description), sizeof(description) -
               strlen(description), "%04X", dev->descriptor.idProduct);
    LOGE("The PID is %04X\n",dev->descriptor.idProduct);
	usb_table[indent_usb_table].pid = dev->descriptor.idProduct;
    indent_usb_table ++;
  } else{
  	LOGE("Open failed! \n");
  	snprintf(description, sizeof(description), "%04X - %04X",
             dev->descriptor.idVendor, dev->descriptor.idProduct);
    LOGE("The VID:PID is 0x%04X : 0x%04X\n",dev->descriptor.idVendor,dev->descriptor.idProduct);
}


  printf("%.*sDev #%d: %s\n", level * 2, "                    ", dev->devnum,
         description);

  if (udev && verbose1) {
    if (dev->descriptor.iSerialNumber) {
      ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber, string, sizeof(string));
      if (ret > 0)
        printf("%.*s  - Serial Number: %s\n", level * 2,
               "                    ", string);
    }
  }

  if (udev)
    usb_close(udev);

  if (verbose1) {
    if (!dev->config) {
      printf("  Couldn't retrieve descriptors\n");
      return 0;
    }

    for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
      print_configuration(&dev->config[i]);
  } else {
    for (i = 0; i < dev->num_children; i++)
      print_device(dev->children[i], level + 1);
  }
  
  return 0;
}
예제 #20
0
static int print_device(libusb_device *dev, int level)
{
	struct libusb_device_descriptor desc;
	libusb_device_handle *handle = NULL;
	char description[256];
	char string[256];
	int ret, i;

	ret = libusb_get_device_descriptor(dev, &desc);
	if (ret < 0) {
		fprintf(stderr, "failed to get device descriptor");
		return -1;
	}

	ret = libusb_open(dev, &handle);
	if (LIBUSB_SUCCESS == ret) {
		if (desc.iManufacturer) {
			ret = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, string, sizeof(string));
			if (ret > 0)
				snprintf(description, sizeof(description), "%s - ", string);
			else
				snprintf(description, sizeof(description), "%04X - ",
				desc.idVendor);
		}
		else
			snprintf(description, sizeof(description), "%04X - ",
			desc.idVendor);

		if (desc.iProduct) {
			ret = libusb_get_string_descriptor_ascii(handle, desc.iProduct, string, sizeof(string));
			if (ret > 0)
				snprintf(description + strlen(description), sizeof(description) -
				strlen(description), "%s", string);
			else
				snprintf(description + strlen(description), sizeof(description) -
				strlen(description), "%04X", desc.idProduct);
		}
		else
			snprintf(description + strlen(description), sizeof(description) -
			strlen(description), "%04X", desc.idProduct);
	}
	else {
		snprintf(description, sizeof(description), "%04X - %04X",
			desc.idVendor, desc.idProduct);
	}

	printf("%.*sDev (bus %d, device %d): %s\n", level * 2, "                    ",
		libusb_get_bus_number(dev), libusb_get_device_address(dev), description);

	if (handle && verbose) {
		if (desc.iSerialNumber) {
			ret = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, string, sizeof(string));
			if (ret > 0)
				printf("%.*s  - Serial Number: %s\n", level * 2,
				"                    ", string);
		}
	}

	if (verbose) {
		for (i = 0; i < desc.bNumConfigurations; i++) {
			struct libusb_config_descriptor *config;
			ret = libusb_get_config_descriptor(dev, i, &config);
			if (LIBUSB_SUCCESS != ret) {
				printf("  Couldn't retrieve descriptors\n");
				continue;
			}

			print_configuration(config);

			libusb_free_config_descriptor(config);
		}

                
		if (handle && desc.bcdUSB >= 0x0201) {
			print_bos(handle);
		}
	}

	if (handle)
		libusb_close(handle);

	return 0;
}
예제 #21
0
int print_device(struct usb_device *dev, int level)
{
  usb_dev_handle *udev;
  char description[256];
  char string[256];
  int ret, i;

  udev = usb_open(dev);
  if (udev) {
    if (dev->descriptor.iManufacturer) {
      ret = usb_get_string_simple(udev, dev->descriptor.iManufacturer, string, sizeof(string));
      if (ret > 0)
        snprintf(description, sizeof(description), "%s - ", string);
      else
        snprintf(description, sizeof(description), "%04X - ",
                 dev->descriptor.idVendor);
    } else
      snprintf(description, sizeof(description), "%04X - ",
               dev->descriptor.idVendor);

    if (dev->descriptor.iProduct) {
      ret = usb_get_string_simple(udev, dev->descriptor.iProduct, string, sizeof(string));
      if (ret > 0)
        snprintf(description + strlen(description), sizeof(description) -
                 strlen(description), "%s", string);
      else
        snprintf(description + strlen(description), sizeof(description) -
                 strlen(description), "%04X", dev->descriptor.idProduct);
    } else
      snprintf(description + strlen(description), sizeof(description) -
               strlen(description), "%04X", dev->descriptor.idProduct);

  } else
    snprintf(description, sizeof(description), "%04X - %04X",
             dev->descriptor.idVendor, dev->descriptor.idProduct);

  printf("%.*sDev #%d: %s\n", level * 2, "                    ", dev->devnum,
         description);

  if (udev && verbose) {
    if (dev->descriptor.iSerialNumber) {
      ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber, string, sizeof(string));
      if (ret > 0)
        printf("%.*s  - Serial Number: %s\n", level * 2,
               "                    ", string);
    }
  }

  if (udev)
    usb_close(udev);

  if (verbose) {
    if (!dev->config) {
      printf("  Couldn't retrieve descriptors\n");
      return 0;
    }

    for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
      print_configuration(&dev->config[i]);
  } else {
    for (i = 0; i < dev->num_children; i++)
      print_device(dev->children[i], level + 1);
  }

  return 0;
}
예제 #22
0
int main(int argc, char **argv)
{

    ros::init(argc, argv, "reset");
    ros::NodeHandle nh("~");

    // parameters
    int node_id;
    std::string dev_path;

    nh.param("node_id", node_id, 100);
    nh.param("dev_path", dev_path, std::string("/dev/ttyACM0"));

    int r;

    // initialize interface
    r = rcmIfInit(rcmIfUsb, (char*) dev_path.c_str());
    error_check(r, "Initialization Failed");
    
    // put in idle mode during configuration
    r = rcmSleepModeSet(RCM_SLEEP_MODE_IDLE);
    error_check(r, "Time out waiting for sleep mode set");

    // make sure correct internal opmode is set
    r = rcmOpModeSet(RCM_OPMODE_RCM);
    error_check(r, "Timeout waiting for opmode set");

    // execute Built-In Test
    int status;
    r = rcmBit(&status);
    error_check(r, "Timeout waiting for test");
    error_check(status, "Built-In Test Failed");

    // get status information
    rcmMsg_GetStatusInfoConfirm statusInfo;
    r = rcmStatusInfoGet(&statusInfo);
    error_check(r, "Timeout waiting for status information");
    print_status(&statusInfo);

    // get configuration from RCM
    rcmConfiguration config;
    r = rcmConfigGet(&config);
    error_check(r, "Timeout waiting for configuration");
    print_configuration(&config);

    // default configuration
    config.nodeId = node_id;
    config.integrationIndex = 7;
    config.codeChannel = 0;
    config.electricalDelayPsA = 0;
    config.electricalDelayPsB = 0;
    config.flags = 0;
    config.txGain = RCM_TXGAIN_MAX;
    config.persistFlag = RCM_PERSIST_ALL;

    r = rcmConfigSet(&config);
    error_check(r, "Time out waiting for rcmConfig confirm");
    print_configuration(&config);

    // cleanup
    rcmIfFlush();
    rcmIfClose();
    
}