Пример #1
0
TEST(ComediTest,AnalogReadings ) {
    lsampl_t data;
    int ret;
    int subdev = 0;        
    int chan = 0;          
    int range = 0;         
    int aref = AREF_GROUND;
    int num_scans = options.n_scan;
    int num_channels = options.n_chan;
    int readscans;
    std::string prop("/sys/class/comedi/comedi0/read_buffer_pos");

    dev = comedi_open(options.filename);
    ASSERT_TRUE( dev );
    subdev_flags = comedi_get_subdevice_flags(dev, options.subdevice);
    
    RecordProperty("NumScans", num_scans);
    #if 0
    fprintf(stderr, "command before testing:\n");
    dump_cmd(stderr, cmd);
    #endif

    prepare_cmd_lib(dev, options.subdevice, num_scans, num_channels, 1e9 / options.freq, cmd);
    #if 0
    fprintf(stderr, "command before testing:\n");
    dump_cmd(stderr, cmd);
    #endif

    /**
     * Setup the Command structure
     */
    cmd->chanlist_len = 2;
    cmd->stop_arg = num_scans;

    /* verify no problems */
    ret = comedi_command_test(dev, cmd);
    ASSERT_GE( ret, 0 ) << "Comedi Testing of command for device was ok";
    
    /* make sure our scan number hasn't changed */
    ASSERT_EQ( cmd->stop_arg , num_scans );
    ASSERT_EQ( cmd->chanlist_len , 2 );    

    ret = comedi_command(dev, cmd);
    sleep(1);

    ASSERT_GE( ret, 0 ) << "Able to Submit comedi command\n";


    /* Verify that the buffer position has in fact moved
       to say num_scans scans remain in it */
    FILE *fp = fopen(prop.c_str(),"r");
    ASSERT_TRUE( fp ) << "Able to open sysfs property file";
    fscanf(fp,"%d",&readscans );
    
    ASSERT_EQ( readscans, 4*num_scans ) << "Able to read the fifo position 4*" << num_scans << "\n";
    
    fclose(fp);

    comedi_close( dev );
}
Пример #2
0
void do_cmd(comedi_t *dev,comedi_cmd *cmd)
{
	int total=0;
	int ret;
	int go;

	ret=comedi_command_test(dev,cmd);

	printf("test ret=%d\n",ret);
	if(ret<0){
		printf("errno=%d\n",errno);
		comedi_perror("comedi_command_test");
		return;
	}

	dump_cmd(stdout,cmd);

	ret=comedi_command_test(dev,cmd);

	printf("test ret=%d\n",ret);
	if(ret<0){
		printf("errno=%d\n",errno);
		comedi_perror("comedi_command_test");
		return;
	}

	dump_cmd(stdout,cmd);

	ret=comedi_command(dev,cmd);

	printf("ret=%d\n",ret);
	if(ret<0){
		printf("errno=%d\n",errno);
		comedi_perror("comedi_command");
		return;
	}

	go=1;
	while(go){
		ret=read(comedi_fileno(dev),buf,BUFSZ);
		if(ret<0){
			if(errno==EAGAIN){
				printf("EAGAIN\n");
				usleep(10000);
			}else{
				go = 0;
				perror("read");
			}
		}else if(ret==0){
			go = 0;
		}else{
			//int i;

			total+=ret;
			//printf("read %d %d\n",ret,total);
			//printf("count = %d\n",count);
			//print_time();
		}
	}
}
Пример #3
0
void dump_cmd(struct menu_node *node, int lev, unsigned int p) {
    struct menu_node **np;
    int i;

    assert(lev < MAX_DEPTH);
    stack[lev] = node->name;

    if (!lev)
        printf(node->name ? "(%s)#\n" : "#\n", node->name);

    if (node->run) {
        for (i = 1; i <= lev; i++)
            printf("%s ", stack[i]);
        if(p>0)
            printf("[%s]",(char *)guess_ptr((void*)((char*)node->run-p),0));
        printf("\n");
    }

    if (node->subtree == NULL)
        return;

    for (np = node->subtree; *np; np++) {
        if (!strcmp((*np)->name, "|"))
            continue;
        dump_cmd(*np, lev + 1, p);
    }

    if (!lev)
        printf("\n");
}
Пример #4
0
static int process_command(int argc, char **argv)
{
    static struct option long_options[] = {
        { "dump",    no_argument, 0, 'd' },
        { "codegen", no_argument, 0, 'c' },
        { "make",    no_argument, 0, 'm' },
        { 0, 0, 0, 0 }
    };

    opterr = 0;
    optind = 1;

    int index = 0;
    const char *spec = "aer";
    switch (getopt_long(MIN(argc, 2), argv, spec, long_options, &index)) {
    case 'a':
        return analyse(argc, argv);
    case 'e':
        return elaborate(argc, argv);
    case 'r':
        return run(argc, argv);
    case 'd':
        return dump_cmd(argc, argv);
    case 'c':
        return codegen(argc, argv);
    case 'm':
        return make_cmd(argc, argv);
    default:
        fatal("missing command, try %s --help for usage", PACKAGE);
        return EXIT_FAILURE;
    }
}
Пример #5
0
int main(int argc, char **argv) {

    unsigned int offset = 0;
    int opt;
    char anchor[] = "rlshell_main";

    while ((opt = getopt(argc, argv, "s")) != -1) {
        switch (opt) {
        case 's':
            offset = (char*)rlshell_main-(char*)guess_ptr(anchor,1);
            //printf("[%s] -> %x",anchor,offset);
            break;
        }
    }

    dump_cmd(&menu_main, 0, offset);
    dump_cmd(&config_main, 0, offset);
    dump_cmd(&config_if_main, 0, offset);
    dump_cmd(&config_vlan_main, 0, offset);
    dump_cmd(&config_line_main, 0, offset);

    return 0;
}
Пример #6
0
/*
 * Entered into mmc structure during driver init
 *
 * Sends a command out on the bus and deals with the block data.
 * Takes the mmc pointer, a command pointer, and an optional data pointer.
 */
static int
mci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
{
	atmel_mci_t *mci = (atmel_mci_t *)mmc->priv;
	u32 cmdr;
	u32 error_flags = 0;
	u32 status;

	if (!initialized) {
		puts ("MCI not initialized!\n");
		return COMM_ERR;
	}

	/* Figure out the transfer arguments */
	cmdr = mci_encode_cmd(cmd, data, &error_flags);

	/* For multi blocks read/write, set the block register */
	if ((cmd->cmdidx == MMC_CMD_READ_MULTIPLE_BLOCK)
			|| (cmd->cmdidx == MMC_CMD_WRITE_MULTIPLE_BLOCK))
		writel(data->blocks | MMCI_BF(BLKLEN, mmc->read_bl_len),
			&mci->blkr);

	/* Send the command */
	writel(cmd->cmdarg, &mci->argr);
	writel(cmdr, &mci->cmdr);

#ifdef DEBUG
	dump_cmd(cmdr, cmd->cmdarg, 0, "DEBUG");
#endif

	/* Wait for the command to complete */
	while (!((status = readl(&mci->sr)) & MMCI_BIT(CMDRDY)));

	if (status & error_flags) {
		dump_cmd(cmdr, cmd->cmdarg, status, "Command Failed");
		return COMM_ERR;
	}

	/* Copy the response to the response buffer */
	if (cmd->resp_type & MMC_RSP_136) {
		cmd->response[0] = readl(&mci->rspr);
		cmd->response[1] = readl(&mci->rspr1);
		cmd->response[2] = readl(&mci->rspr2);
		cmd->response[3] = readl(&mci->rspr3);
	} else
		cmd->response[0] = readl(&mci->rspr);

	/* transfer all of the blocks */
	if (data) {
		u32 word_count, block_count;
		u32* ioptr;
		u32 sys_blocksize, dummy, i;
		u32 (*mci_data_op)
			(atmel_mci_t *mci, u32* data, u32 error_flags);

		if (data->flags & MMC_DATA_READ) {
			mci_data_op = mci_data_read;
			sys_blocksize = mmc->read_bl_len;
			ioptr = (u32*)data->dest;
		} else {
			mci_data_op = mci_data_write;
			sys_blocksize = mmc->write_bl_len;
			ioptr = (u32*)data->src;
		}

		status = 0;
		for (block_count = 0;
				block_count < data->blocks && !status;
				block_count++) {
			word_count = 0;
			do {
				status = mci_data_op(mci, ioptr, error_flags);
				word_count++;
				ioptr++;
			} while (!status && word_count < (data->blocksize/4));
#ifdef DEBUG
			if (data->flags & MMC_DATA_READ)
			{
				printf("Read Data:\n");
				print_buffer(0, data->dest, 1,
					word_count*4, 0);
			}
#endif
#ifdef DEBUG
			if (!status && word_count < (sys_blocksize / 4))
				printf("filling rest of block...\n");
#endif
			/* fill the rest of a full block */
			while (!status && word_count < (sys_blocksize / 4)) {
				status = mci_data_op(mci, &dummy,
					error_flags);
				word_count++;
			}
			if (status) {
				dump_cmd(cmdr, cmd->cmdarg, status,
					"Data Transfer Failed");
				return COMM_ERR;
			}
		}

		/* Wait for Transfer End */
		i = 0;
		do {
			status = readl(&mci->sr);

			if (status & error_flags) {
				dump_cmd(cmdr, cmd->cmdarg, status,
					"DTIP Wait Failed");
				return COMM_ERR;
			}
			i++;
		} while ((status & MMCI_BIT(DTIP)) && i < 10000);
		if (status & MMCI_BIT(DTIP)) {
			dump_cmd(cmdr, cmd->cmdarg, status,
				"XFER DTIP never unset, ignoring");
		}
	}

	return 0;
}
Пример #7
0
int main ( int argc, char * argv [] )
{
	
	cmd_defaults(&cmd,argv[0]);
	
	init_error();
		
	if(!is_path_absolute(argv[0])) {
		wrn_print("Require execution with absolute path(%s)",argv[0]);
		terminate();
	}		
	
	cmd_process(argc,argv,&cmd);	
	
	if(!cmd.no_dump_config)
		dump_cmd(&cmd);
//	if( check_creds(&cmd.creds) == -1 )
//		wrn_print("check_creds failed, program execution compromised");
		
	if( cmd.kill_running || cmd.rexec_running) {
		// dbg_print("Sending %s signal",strsignal(cmd.rexec_running ? SIGHUP : cmd.kill_running ? SIGTERM : 0));
		KILL_FROM_PID_ERRORS(kill_from_pid_file(cmd.pid_file, cmd.rexec_running ? SIGHUP : SIGTERM));
		exit(EXIT_SUCCESS);
	}

	
	if(cmd.logs_enable)
		if(reopen_files() == -1) {
			wrn_print("reopen_files failed");
			terminate();
		}
		
	dbg_print("%s started executinon", argv[0]);
	dbg_print("Running as uid:%ld gid:%ld", (long)getuid(), (long)getgid());
	
	if(cmd.need_daemon) {
		dbg_print("Demonizing..");
		if(become_daemon()) {
			wrn_print("Can't demonize because of error");
			terminate();
		}
	} 
	if(cmd.pid_file) {	
		switch (create_pid_file(cmd.pid_file)) {
	        case -1: 
			wrn_print("creat_pid_file failed");
			terminate();
		case -2:
			wrn_print("An instance of %s is already running",cmd.path);
			exit(EXIT_SUCCESS);		

		}
	}	
	
	if(cmd.exit_after_dump) 
		exit(EXIT_SUCCESS);
		
	block_all_sigs();
	
	main_loop();
	
	wrn_print("suspicious main_loop return...");
	exit(EXIT_FAILURE);
}
Пример #8
0
static PyObject*
comediModule(PyObject* self, PyObject* args)
{
	char *device;
	int subdevice;
	int channel;
	int range;
	int aref;
	int n_chan;
	int n_scan;
	float freq;
    if (!PyArg_ParseTuple(args, "siiiiiif", &device, &subdevice, &channel, &range, &aref, &n_chan, &n_scan, &freq))
        return NULL;
    
	comedi_t *dev;
	comedi_cmd c,*cmd=&c;
	int ret;
	int total=0;
	int i;
	struct timeval start,end;
	int subdev_flags;
	lsampl_t raw;
	struct parsed_options options;

	init_parsed_options(&options);
	options.filename = device;
	options.subdevice = subdevice;
	options.channel = channel;
	options.range = range;
	options.aref = aref;
	options.n_chan = n_chan;
	options.n_scan = n_scan;
	options.freq = freq;

	/* open the device */
	dev = comedi_open(options.filename);
	if(!dev){
		comedi_perror(options.filename);
		exit(1);
	}

	// Print numbers for clipped inputs
	comedi_set_global_oor_behavior(COMEDI_OOR_NUMBER);

	/* Set up channel list */
	for(i = 0; i < options.n_chan; i++){
		chanlist[i] = CR_PACK(options.channel + i, options.range, options.aref);
		range_info[i] = comedi_get_range(dev, options.subdevice, options.channel, options.range);
		maxdata[i] = comedi_get_maxdata(dev, options.subdevice, options.channel);
	}
	prepare_cmd_lib(dev, options.subdevice, options.n_scan, options.n_chan, 1e9 / options.freq, cmd);

	fprintf(stderr, "command before testing:\n");
	dump_cmd(stderr, cmd);

	ret = comedi_command_test(dev, cmd);
	if(ret < 0){
		comedi_perror("comedi_command_test");
		if(errno == EIO){
			fprintf(stderr,"Ummm... this subdevice doesn't support commands\n");
		}
		exit(1);
	}
	fprintf(stderr,"first test returned %d (%s)\n", ret,
			cmdtest_messages[ret]);
	dump_cmd(stderr, cmd);

	ret = comedi_command_test(dev, cmd);
	if(ret < 0){
		comedi_perror("comedi_command_test");
		exit(1);
	}
	fprintf(stderr,"second test returned %d (%s)\n", ret,
			cmdtest_messages[ret]);
	if(ret!=0){
		dump_cmd(stderr, cmd);
		fprintf(stderr, "Error preparing command\n");
		exit(1);
	}

	/* this is only for informational purposes */
	gettimeofday(&start, NULL);
	fprintf(stderr,"start time: %ld.%06ld\n", start.tv_sec, start.tv_usec);

	/* start the command */
	ret = comedi_command(dev, cmd);
	if(ret < 0){
		comedi_perror("comedi_command");
		exit(1);
	}
	subdev_flags = comedi_get_subdevice_flags(dev, options.subdevice);

	const int ndim = 2;
	npy_intp nd[2] = {n_scan, n_chan};
	
	PyObject *myarray;
	double *array_buffer;
	myarray = PyArray_SimpleNew(ndim, nd, NPY_DOUBLE);
	Py_INCREF(myarray);
	array_buffer = (double *)PyArray_DATA(myarray);
	
	while(1){
		ret = read(comedi_fileno(dev),buf,BUFSZ);
		if(ret < 0){
			/* some error occurred */
			perror("read");
			break;
		}else if(ret == 0){
			/* reached stop condition */
			break;
		}else{
			static int col = 0;
			double j = 0.0;
			
			int bytes_per_sample;
			total += ret;
			if(options.verbose)fprintf(stderr, "read %d %d\n", ret, total);
			if(subdev_flags & SDF_LSAMPL)
				bytes_per_sample = sizeof(lsampl_t);
			else
				bytes_per_sample = sizeof(sampl_t);
			for(i = 0; i < ret / bytes_per_sample; i++){
				if(subdev_flags & SDF_LSAMPL) {
					raw = ((lsampl_t *)buf)[i];
				} else {
					raw = ((sampl_t *)buf)[i];
				}
				*array_buffer++ = print_datum(raw, col, 1);
				col++;
				if(col == options.n_chan){
					col=0;
					j++;
					printf("\n");
				}
			}
		}
	}

	/* this is only for informational purposes */
	gettimeofday(&end,NULL);
	fprintf(stderr,"end time: %ld.%06ld\n", end.tv_sec, end.tv_usec);

	end.tv_sec -= start.tv_sec;
	if(end.tv_usec < start.tv_usec){
		end.tv_sec--;
		end.tv_usec += 1000000;
	}
	end.tv_usec -= start.tv_usec;
	fprintf(stderr,"time: %ld.%06ld\n", end.tv_sec, end.tv_usec);
    
	return myarray;
}
Пример #9
0
int main(int argc, char **argv)
{
   term_init();
   set_default_opts();

   if (getenv("NVC_GDB") != NULL)
      register_gdb_signal_handlers();
   else
      register_trace_signal_handlers();

   atexit(fbuf_cleanup);

   static struct option long_options[] = {
      { "help",    no_argument,       0, 'h' },
      { "version", no_argument,       0, 'v' },
      { "work",    required_argument, 0, 'w' },
      { "dump",    no_argument,       0, 'd' },
      { "codegen", no_argument,       0, 'c' },
      { "make",    no_argument,       0, 'm' },
      { "std",     required_argument, 0, 's' },
      { 0, 0, 0, 0 }
   };

   int c, index = 0;
   const char *spec = "aehrvL:";
   while ((c = getopt_long(argc, argv, spec, long_options, &index)) != -1) {
      switch (c) {
      case 0:
         // Set a flag
         break;
      case 'h':
         usage();
         exit(EXIT_SUCCESS);
      case 'v':
         printf("%s\n%s\n", version_string, copy_string);
         exit(EXIT_SUCCESS);
      case 'w':
         opt_set_str("work-name", optarg);
         break;
      case 'L':
         lib_add_search_path(optarg);
         break;
      case 's':
         set_standard(parse_standard(optarg));
         break;
      case 'a':
      case 'e':
      case 'd':
      case 'r':
      case 'c':
      case 'm':
         // Subcommand options are parsed later
         argc -= (optind - 1);
         argv += (optind - 1);
         goto getopt_out;
      case '?':
         // getopt_long already printed an error message
         exit(EXIT_FAILURE);
      default:
         abort();
      }
   }
 getopt_out:

   switch (c) {
   case 'a':
      return analyse(argc, argv);
   case 'e':
      return elaborate(argc, argv);
   case 'r':
      return run(argc, argv);
   case 'd':
      return dump_cmd(argc, argv);
   case 'c':
      return codegen(argc, argv);
   case 'm':
      return make_cmd(argc, argv);
   default:
      fprintf(stderr, "%s: missing command\n", PACKAGE);
      return EXIT_FAILURE;
   }
}
Пример #10
0
int main(int argc, char *argv[])
{
	comedi_t *dev;
	comedi_cmd c,*cmd=&c;
	int ret;
	int total=0;
	int i;
	struct timeval start,end;
	int subdev_flags;
	lsampl_t raw;
	struct parsed_options options;

	init_parsed_options(&options);
	parse_options(&options, argc, argv);

	/* The following variables used in this demo
	 * can be modified by command line
	 * options.  When modifying this demo, you may want to
	 * change them here. */
	options.filename = "/dev/comedi0";
	options.subdevice = 0;
	options.channel = 0;
	options.range = 6;  
	options.aref = AREF_DIFF;
	options.n_chan = 8;
	options.n_scan = 100000;
	options.freq = 1000.0;
	options.physical = 1;

	/* open the device */
	dev = comedi_open(options.filename);
	if(!dev){
		comedi_perror(options.filename);
		exit(1);
	}

	// Print numbers for clipped inputs
	comedi_set_global_oor_behavior(COMEDI_OOR_NUMBER);

	/* Set up channel list */
	//for(i = 0; i < options.n_chan/2; i++){
	for(i = 0; i < options.n_chan; i++){	
		chanlist[i] = CR_PACK(options.channel + i, options.range, options.aref);
		range_info[i] = comedi_get_range(dev, options.subdevice, options.channel, options.range);
		maxdata[i] = comedi_get_maxdata(dev, options.subdevice, options.channel);
	}

/*
    for(i = options.n_chan/2; i < options.n_chan; i++){
        fprintf(stderr,"%d: %d\n", i, options.channel + i + 8);
        chanlist[i] = CR_PACK(options.channel + i + 8, options.range, options.aref);
        range_info[i] = comedi_get_range(dev, options.subdevice, options.channel, options.range);
        maxdata[i] = comedi_get_maxdata(dev, options.subdevice, options.channel);
    }    
*/

	/* prepare_cmd_lib() uses a Comedilib routine to find a
	 * good command for the device.  prepare_cmd() explicitly
	 * creates a command, which may not work for your device. */
	prepare_cmd_lib(dev, options.subdevice, options.n_scan, options.n_chan, 1e9 / options.freq, cmd);
	//prepare_cmd(dev, options.subdevice, options.n_scan, options.n_chan, 1e9 / options.freq, cmd);

	fprintf(stderr, "command:\n");
	dump_cmd(stderr, cmd);

	/* this is only for informational purposes */
	gettimeofday(&start, NULL);
	fprintf(stderr,"start time: %ld.%06ld\n", start.tv_sec, start.tv_usec);

	/* start the command */
	ret = comedi_command(dev, cmd);
	if(ret < 0){
		comedi_perror("comedi_command");
		exit(1);
	}
	subdev_flags = comedi_get_subdevice_flags(dev, options.subdevice);
	while(1){
		ret = read(comedi_fileno(dev),buf,BUFSZ);
		if(ret < 0){
			/* some error occurred */
			perror("read");
			continue;
		}else if(ret == 0){
			/* reached stop condition */
			break;
		}else{
			static int col = 0;
			int bytes_per_sample;
			total += ret;
			if(options.verbose)fprintf(stderr, "read %d %d\n", ret, total);
			if(subdev_flags & SDF_LSAMPL)
				bytes_per_sample = sizeof(lsampl_t);
			else
				bytes_per_sample = sizeof(sampl_t);
			for(i = 0; i < ret / bytes_per_sample; i++){
				if(subdev_flags & SDF_LSAMPL) {
					raw = ((lsampl_t *)buf)[i];
				} else {
					raw = ((sampl_t *)buf)[i];
				}
				print_datum(raw, col, options.physical);
				col++;
				if(col == options.n_chan){
					printf("\n");
					col=0;
				}
			}
		}
	}

	/* this is only for informational purposes */
	gettimeofday(&end,NULL);
	fprintf(stderr,"end time: %ld.%06ld\n", end.tv_sec, end.tv_usec);

	end.tv_sec -= start.tv_sec;
	if(end.tv_usec < start.tv_usec){
		end.tv_sec--;
		end.tv_usec += 1000000;
	}
	end.tv_usec -= start.tv_usec;
	fprintf(stderr,"time: %ld.%06ld\n", end.tv_sec, end.tv_usec);

	return 0;
}
Пример #11
0
void do_cmd(comedi_t *dev,comedi_cmd *cmd)
{
	int total=0;
	int ret;
	int go;
	fd_set rdset;
	struct timeval timeout;

	ret=comedi_command_test(dev,cmd);

	printf("test ret=%d\n",ret);
	if(ret<0){
		printf("errno=%d\n",errno);
		comedi_perror("comedi_command_test");
		return;
	}

	dump_cmd(stdout,cmd);

	ret=comedi_command_test(dev,cmd);

	printf("test ret=%d\n",ret);
	if(ret<0){
		printf("errno=%d\n",errno);
		comedi_perror("comedi_command_test");
		return;
	}

	dump_cmd(stdout,cmd);

	ret=comedi_command(dev,cmd);

	printf("ret=%d\n",ret);
	if(ret<0){
		printf("errno=%d\n",errno);
		comedi_perror("comedi_command");
		return;
	}

	go=1;
	while(go){
		FD_ZERO(&rdset);
		FD_SET(comedi_fileno(dev),&rdset);
		timeout.tv_sec = 0;
		timeout.tv_usec = 50000;
		ret = select(comedi_fileno(dev)+1,&rdset,NULL,NULL,&timeout);
		if(ret<0){
			perror("select");
		}else if(ret==0){
			/* timeout */
		}else if(FD_ISSET(comedi_fileno(dev),&rdset)){
			ret=read(comedi_fileno(dev),buf,BUFSZ);
			if(ret<0){
				if(errno==EAGAIN){
					go = 0;
					perror("read");
				}
			}else if(ret==0){
				go = 0;
			}else{
				//int i;

				total+=ret;
				//printf("read %d %d\n",ret,total);
				//printf("count = %d\n",count);
				do_toggle();
#if 0
				for(i=0;i<ret;i+=sizeof(sampl_t)){
					do_toggle();
				}
#endif
			}
		}
	}
}
Пример #12
0
int _papi_hwd_merge(EventSetInfo_t *ESI, EventSetInfo_t *zero)
{ 
  int i, retval;
  hwd_control_state_t *this_state = &ESI->machdep;
  hwd_control_state_t *current_state = &zero->machdep;
  
  /* If we ARE NOT nested, 
     just copy the global counter structure to the current eventset */

  if (current_state->allocated_registers.selector == 0x0)
    {
      current_state->allocated_registers.selector = this_state->allocated_registers.selector;
      memcpy(&current_state->counter_cmd,&this_state->counter_cmd,sizeof(struct pmc_control));

      /* Stop the current context 

      retval = perf(PERF_RESET_COUNTERS, 0, 0);
      if (retval) 
	return(PAPI_ESYS);  */
      
      /* (Re)start the counters */
      
#ifdef DEBUG
      dump_cmd(&current_state->counter_cmd);
#endif

      if (pmc_control(current_state->self, &current_state->counter_cmd) < 0)
		return(PAPI_ESYS);
      
      return(PAPI_OK);
    }

  /* If we ARE nested, 
     carefully merge the global counter structure with the current eventset */
  else
    {
      int tmp, hwcntrs_in_both, hwcntrs_in_all, hwcntr;

      /* Stop the current context 

      retval = perf(PERF_STOP, 0, 0);
      if (retval) 
	return(PAPI_ESYS); */
  
      /* Update the global values */

      retval = update_global_hwcounters(zero);
      if (retval)
	return(retval);

      /* Delete the current context */

      hwcntrs_in_both = this_state->allocated_registers.selector & current_state->allocated_registers.selector;
      hwcntrs_in_all  = this_state->allocated_registers.selector | current_state->allocated_registers.selector;

      /* Check for events that are shared between eventsets and 
	 therefore require no modification to the control state. */

      /* First time through, error check */

      tmp = hwcntrs_in_all;
      while ((i = ffs(tmp)))
	{
	  hwcntr = 1 << (i-1);
	  tmp = tmp ^ hwcntr;
	  if (hwcntr & hwcntrs_in_both)
	    {
	      if (!(counter_event_shared(&this_state->counter_cmd, &current_state->counter_cmd, i-1)))
		return(PAPI_ECNFLCT);
	    }
	  else if (!(counter_event_compat(&this_state->counter_cmd, &current_state->counter_cmd, i-1)))
	    return(PAPI_ECNFLCT);
	}

      /* Now everything is good, so actually do the merge */

      tmp = hwcntrs_in_all;
      while ((i = ffs(tmp)))
	{
	  hwcntr = 1 << (i-1);
	  tmp = tmp ^ hwcntr;
	  if (hwcntr & hwcntrs_in_both)
	    {
	      ESI->hw_start[i-1] = zero->hw_start[i-1];
	      zero->multistart.SharedDepth[i-1]++; 
	    }
	  else if (hwcntr & this_state->allocated_registers.selector)
	    {
	      current_state->allocated_registers.selector |= hwcntr;
	      counter_event_copy(&this_state->counter_cmd, &current_state->counter_cmd, i-1);
	      ESI->hw_start[i-1] = 0;
	      zero->hw_start[i-1] = 0;
	    }
	}
    }

  /* Set up the new merged control structure */
  
#ifdef DEBUG
  dump_cmd(&current_state->counter_cmd);
#endif
      
  /* Stop the current context 

  retval = perf(PERF_RESET_COUNTERS, 0, 0);
  if (retval) 
    return(PAPI_ESYS); */

  /* (Re)start the counters */
  
  if (pmc_control(current_state->self, &current_state->counter_cmd) < 0)
    return(PAPI_ESYS);

  return(PAPI_OK);
} 
Пример #13
0
int main(int argc, char *argv[])
{
	comedi_cmd c,*cmd=&c;
	struct header_info header;
	long int t_samples, t_bytes, t_sleep;
	long int ret;
	int dt_usec, usec_elapsed;
//	struct timeval start,end;
	struct parsed_options options;
	unsigned short *samples; //, *junk;
	struct timeval now,then;
	long long unsigned int exec = 0;
	time_t t;

	umask(000);

	signal(SIGINT,do_depart);

	if (geteuid() != 0) {
		fprintf(stderr,"Must be setuid root to renice self.\n");
		exit(0);
	}

	cmd_init_parsed_options(&options);
	cmd_parse_options(&options, argc, argv);

	t_samples = options.n_chan * options.samples;
	t_bytes = t_samples * 2;
	t_sleep = (long int) DMA_OVERSCAN_MULT*(1e6/options.freq)*options.samples;
	printf("freq = %f, tsamp = %li, tby = %li, tsleep = %li.\n",options.freq,t_samples,t_bytes,t_sleep);


	/* Test for failful options */
	if (options.freq <= 1/(options.cadence + 0.00005)) {
		fprintf(stderr,"Acquisition frequency is faster than sampling frequency!  FAIL!\n");
		exit(ACQERR_BADINPUT);
	}

	if (options.samples > 16777216) {
		fprintf(stderr,"acq_d can't take more than 2^24 samples per set!  Try acq_c.\n");
		exit(ACQERR_BADINPUT);
	}

	ret = nice(-20);
	fprintf(stderr,"I've been niced to %li.\n",ret);
	if (ret != -20) printf("  WARNING!! Data collection could not set nice=-20. Data loss is probable at high speed.");

	dt_usec = options.cadence * 1e6;
	gettimeofday(&then, NULL);

	/* open the device */
	dev = comedi_open(options.devfile);
	if (!dev) {
		comedi_perror(options.devfile);
		exit(ACQERR_BADDEV);
	}

//	printf("%li samples in %i-byte buffer.\n\n",t_samples,comedi_get_buffer_size(dev,options.subdevice));

	prepare_cmd_lib(dev,options,cmd);

	printf("Testing command...");
	ret = comedi_command_test(dev, cmd);
	if (ret < 0) {
		comedi_perror("comedi_command_test");
		if(errno == EIO){
			fprintf(stderr,"Ummm... this subdevice doesn't support commands\n");
		}
		exit(ACQERR_BADCMD);
	}
	printf("%s...",cmdtest_messages[ret]);
	ret = comedi_command_test(dev, cmd);
	printf("%s...",cmdtest_messages[ret]);
	ret = comedi_command_test(dev, cmd);
	printf("%s...\n",cmdtest_messages[ret]);
	if (ret < 0) {
		fprintf(stderr,"Bad command, and unable to fix.\n");
		dump_cmd(stderr, cmd);
		exit(ACQERR_BADCMD);
	}
	dump_cmd(stdout,cmd);
	comedi_close(dev);

	//fprintf(stderr,"%i scan -- %i chan -- %li samples -- %li bytes\n",options.samples,options.n_chan,t_samples,t_bytes);

	/* Print data file header */
//	sprintf(dataheader,	"[system]\n"
//				"whoami = \"%s\"")

	samples = (unsigned short*) malloc(t_bytes);
//	junk = (unsigned short*) malloc(t_bytes);
	if ((samples == NULL)) { // | (junk == NULL)) {
		fprintf(stderr,"Error allocating sample memory!\n");
		exit(ACQERR_BADMEM);
	}

	printf("Starting acquisition...\n");
	/*Open the serial port*/
	/*serial = (FILE*)fopen("/dev/ttyS0","w");*/
	

	/* Do what we're here to do */
	while (running) {
		if (exec == options.sets) {
			break;
		}
		exec++;

       serial_toggle();

		/* open the device */
		dev = comedi_open(options.devfile);
		if (!dev) {
			comedi_perror(options.devfile);
			exit(ACQERR_BADDEV);
		}

		gettimeofday(&now, NULL);
		usec_elapsed = (now.tv_sec - then.tv_sec) * 1e6 + (now.tv_usec - then.tv_usec);
		while (usec_elapsed < dt_usec) {
			usleep(USLEEP_GRAN);
			gettimeofday(&now, NULL);
			usec_elapsed = (now.tv_sec - then.tv_sec) * 1e6 + (now.tv_usec - then.tv_usec);
		}
		/* start the command */
		ret = comedi_command(dev, cmd);
		if (ret < 0) {
			comedi_perror("comedi_command");
			exit(ACQERR_BADCMD);
		}

		then = now;

		/*
		 * Insert enough waiting to get through most of the sampling
		 */
		/*serial_toggle();*/
		usleep(t_sleep);

		/*
		 * Wait until the buffer has our data.
		 */

		int exsleeps = 0;
		do {
			usleep(USLEEP_GRAN);
			comedi_poll(dev,options.subdevice);
			ret = comedi_get_buffer_contents(dev,options.subdevice);
			exsleeps++;
		} while(ret < t_bytes);

//		printf("Waited %ius for additional data.\n",exsleeps);

		/*
		 * Get teh dataz.
		 */
		ret = read(comedi_fileno(dev), samples, t_bytes);
		if (ret < t_bytes) {
			fprintf(stderr,"Read mismatch!  Got %li of %li bytes (%li/%li samples).\n",ret,t_bytes,ret/2,t_samples);
		}
		header.num_read = ret/2;

		// collect & discard overscan
/*		ret = comedi_get_buffer_contents(dev,options.subdevice);
		if (realloc(junk,ret) == NULL) {
			fprintf(stderr,"Error in oversample realloc?\n");
			exit(ACQERR_BADMEM);
		}
		if (ret > 0) {
			ret = read(comedi_fileno(dev),junk,ret);
		}*/

		comedi_close(dev);

		// Prepare header
		t = time(NULL);
		sprintf(header.site_id,"%s",site_str);
		header.start_time = t;
		header.start_timeval = now;
		header.num_channels=options.n_chan;
		header.channel_flags=0x0F;
		header.num_samples=options.samples;
		header.sample_frequency=options.freq;
		header.time_between_acquisitions=options.cadence;
		header.byte_packing=0;
		header.code_version=current_code_version;

		// Save latest to monitor file
		if (strcmp(options.monfile,"") != 0) {
			out = open(options.monfile,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
			ret = errno;
			if (out > 0) {
				ret = write(out,&header,sizeof(header));
				ret = write(out,samples,2*header.num_read);
				close(out);
			}
			else {
				fprintf(stderr,"Unable to open monitor file %s: %s.\n",options.monfile,strerror(ret));
				exit(ACQERR_BADOUT);
			}
		}

		if (options.cadence >= 1.0 && options.verbose) printf("\tSaved latest to: %s\n",options.monfile);

		// Append to output file
		if (strcmp(options.outfile,"") != 0) {
			out = open(options.outfile,O_WRONLY|O_APPEND|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
			ret = errno;
			if (out > 0) {
				ret = write(out,samples,2*header.num_read);
				close(out);
				if (options.cadence >= 1.0 && options.verbose) printf("\tAppended to: %s\n",options.outfile);
			}
			else {
				fprintf(stderr,"Unable to open output file %s: %s.\n",options.outfile,strerror(ret));
				exit(ACQERR_BADOUT);
			}
		}
	}

	if (dev != NULL)
		comedi_close(dev);
	if (out != 0)
		close(out);

	printf("\nEnd.\n");

	exit(0);
}
Пример #14
0
int
_ultra_hwd_update_control_state( hwd_control_state_t * this_state,
								NativeInfo_t * native, int count,
								hwd_context_t * zero )
{
	int nidx1, nidx2, hwcntr;
	uint64_t tmp = 0;
	uint64_t pcr;
	int64_t cmd0, cmd1;

/* save the last three bits */
	pcr = this_state->counter_cmd.cmd.ce_pcr & 0x7;

/* clear the control register */
	this_state->counter_cmd.cmd.ce_pcr = pcr;

/* no native events left */
	if ( count == 0 )
		return ( PAPI_OK );

	cmd0 = -1;
	cmd1 = -1;
/* one native event */
	if ( count == 1 ) {
		nidx1 = native[0].ni_event & PAPI_NATIVE_AND_MASK;
		hwcntr = 0;
		cmd0 = native_table[nidx1].encoding[0];
		native[0].ni_position = 0;
		if ( cmd0 == -1 ) {
			cmd1 = native_table[nidx1].encoding[1];
			native[0].ni_position = 1;
		}
	}

/* two native events */
	if ( count == 2 ) {
		int avail1, avail2;

		avail1 = 0;
		avail2 = 0;
		nidx1 = native[0].ni_event & PAPI_NATIVE_AND_MASK;
		nidx2 = native[1].ni_event & PAPI_NATIVE_AND_MASK;
		if ( native_table[nidx1].encoding[0] != -1 )
			avail1 = 0x1;
		if ( native_table[nidx1].encoding[1] != -1 )
			avail1 += 0x2;
		if ( native_table[nidx2].encoding[0] != -1 )
			avail2 = 0x1;
		if ( native_table[nidx2].encoding[1] != -1 )
			avail2 += 0x2;
		if ( ( avail1 | avail2 ) != 0x3 )
			return ( PAPI_ECNFLCT );
		if ( avail1 == 0x3 ) {
			if ( avail2 == 0x1 ) {
				cmd0 = native_table[nidx2].encoding[0];
				cmd1 = native_table[nidx1].encoding[1];
				native[0].ni_position = 1;
				native[1].ni_position = 0;
			} else {
				cmd1 = native_table[nidx2].encoding[1];
				cmd0 = native_table[nidx1].encoding[0];
				native[0].ni_position = 0;
				native[1].ni_position = 1;
			}
		} else {
			if ( avail1 == 0x1 ) {
				cmd0 = native_table[nidx1].encoding[0];
				cmd1 = native_table[nidx2].encoding[1];
				native[0].ni_position = 0;
				native[1].ni_position = 1;
			} else {
				cmd0 = native_table[nidx2].encoding[0];
				cmd1 = native_table[nidx1].encoding[1];
				native[0].ni_position = 1;
				native[1].ni_position = 0;
			}
		}
	}

/* set the control register */
	if ( cmd0 != -1 ) {
		tmp = ( ( uint64_t ) cmd0 << pcr_shift[0] );
	}
	if ( cmd1 != -1 ) {
		tmp = tmp | ( ( uint64_t ) cmd1 << pcr_shift[1] );
	}
	this_state->counter_cmd.cmd.ce_pcr = tmp | pcr;
#if DEBUG
	dump_cmd( &this_state->counter_cmd );
#endif

	return ( PAPI_OK );
}
Пример #15
0
int main(int argc, char *argv[])
{
  comedi_cmd cmd;
  int err;
  int n, m, k;
  comedi_t *dev;
  unsigned int chanlist[100];
  unsigned int maxdata;
  comedi_range *rng;
  int ret;
  struct parsed_options options;
  int fn = 256*256;
  sampl_t *data, *dp;
  float v;

  init_parsed_options(&options);
  options.subdevice = -1;
  options.n_chan = 100000;/* default number of samples */
  parse_options(&options, argc, argv);

  dev = comedi_open( options.filename );
  if(dev == NULL){
    fprintf(stderr, "error opening %s\n", options.filename);
    return -1;
  }
  if(options.subdevice < 0)
    options.subdevice = comedi_find_subdevice_by_type(dev, COMEDI_SUBD_AI, 0);

  maxdata = comedi_get_maxdata(dev, options.subdevice, options.channel);
  rng = comedi_get_range(dev, options.subdevice, options.channel, options.range);

  memset(&cmd,0,sizeof(cmd));
  /*
  cmd.subdev = options.subdevice;
  cmd.flags = 0;
  cmd.start_src = TRIG_INT;
  cmd.start_arg = 0;
  cmd.scan_begin_src = TRIG_TIMER;
  cmd.scan_begin_arg = 1e9 / options.freq;
  cmd.convert_src = TRIG_TIMER;
  cmd.convert_arg = 1e9 / options.freq / 50;
  cmd.scan_end_src = TRIG_COUNT;
  cmd.scan_end_arg = options.n_chan;
  cmd.stop_src = TRIG_COUNT;
  cmd.stop_arg = fn;
  cmd.stop_src = TRIG_NONE;
  cmd.stop_arg = 0;
  */

  cmd.scan_begin_src = TRIG_TIMER;
  cmd.flags = TRIG_ROUND_NEAREST;
  err = comedi_get_cmd_generic_timed( dev, options.subdevice,
				      &cmd, options.n_chan,
				      1e9 / options.freq );
  cmd.start_src = TRIG_INT;
  cmd.start_arg = 0;
  cmd.scan_end_arg = options.n_chan;
  cmd.stop_src = TRIG_NONE;
  cmd.stop_arg = 0;
  
  cmd.chanlist = chanlist;
  cmd.chanlist_len = options.n_chan;

  for ( k=0; k<options.n_chan; k++ )
    chanlist[k] = CR_PACK(k, options.range, options.aref);

  dump_cmd(stderr,&cmd);

  if ( cmd.scan_begin_arg > 1e9 / options.freq ) {
    fprintf( stderr, "frequency too high! Maximum possible is %g Hz\n", 1.0e9/cmd.scan_begin_arg );
    comedi_close( dev );
    return 1;
  }

  err = comedi_command_test(dev, &cmd);
  if (err > 0 && err != 4 ) {
    fprintf( stderr, "comedi_command_test returned %d\n", err );
    dump_cmd(stdout,&cmd);
    exit(1);
  }
  
  err = comedi_command_test(dev, &cmd);
  if (err > 0 && err != 4 ) {
    fprintf( stderr, "comedi_command_test returned %d\n", err );
    dump_cmd(stdout,&cmd);
    exit(1);
  }

  dump_cmd(stderr,&cmd);

  /* init data buffer: */
  data = (sampl_t *)malloc( fn*sizeof( sampl_t ) );
  if(data == NULL ){
    perror("malloc\n");
    exit(1);
  }
  
  fprintf( stderr, "execute command ...\n" );
  if ((err = comedi_command(dev, &cmd)) < 0) {
    comedi_perror("comedi_command");
    exit(1);
  }
  
  fprintf( stderr, "start analog input ...\n" );
  ret = comedi_internal_trigger(dev, options.subdevice, 0);
  if(ret < 0){
    perror("comedi_internal_trigger\n");
    exit(1);
  }
  
  n = 0;
  while( 1 ) {
    m = read(comedi_fileno(dev),(void *)data,fn*sizeof( sampl_t));
    if(m<0){
      if ( errno != EAGAIN ) {
	perror("read");
	exit(0);
      }
      else {
	fprintf( stderr, "... no more data can be read! Try later.\n" );
	usleep( 100000 );
      }
    }
    else {
      m /= sizeof( sampl_t);
      fprintf( stderr, "read %d samples\n",m);
      n+=m;
    }
  }
  comedi_cancel( dev, cmd.subdev );

  fprintf( stderr, "finished\n" );

  /* save data: */

  dp = data;  
  for ( k=0; k<n; k++ ) {
    v = comedi_to_phys(*dp, rng, maxdata);
    printf( "%g\n", v );
    /*    printf( "%d\n", *dp );*/
    ++dp;
  }

  free( data );

  comedi_close( dev );
  
  return 0;
}
Пример #16
0
static void
dispatch_emt( int signal, siginfo_t * sip, void *arg )
{
	int event_counter;
	_papi_hwi_context_t ctx;
	caddr_t address;
	ctx.si = sip;
	ctx.ucontext = arg;
	SUBDBG( "%d, %p, %p\n", signal, sip, arg );

	if ( sip->si_code == EMT_CPCOVF ) {
		papi_cpc_event_t *sample;
		EventSetInfo_t *ESI;
		ThreadInfo_t *thread = NULL;
		int t, overflow_vector, readvalue;

		thread = _papi_hwi_lookup_thread( 0 );
		ESI = ( EventSetInfo_t * ) thread->running_eventset;
		int cidx = ESI->CmpIdx;

		if ( ( ESI == NULL ) || ( ( ESI->state & PAPI_OVERFLOWING ) == 0 ) ) {
			OVFDBG( "Either no eventset or eventset not set to overflow.\n" );
			return;
		}

		if ( ESI->master != thread ) {
			PAPIERROR
				( "eventset->thread 0x%lx vs. current thread 0x%lx mismatch",
				  ESI->master, thread );
			return;
		}

		event_counter = ESI->overflow.event_counter;
		sample = &( ESI->ctl_state->counter_cmd );

		/* GROSS! This is a hack to 'push' the correct values 
		   back into the hardware, such that when PAPI handles
		   the overflow and reads the values, it gets the correct ones.
		 */

		/* Find which HW counter overflowed */

		if ( ESI->EventInfoArray[ESI->overflow.EventIndex[0]].pos[0] == 0 )
			t = 0;
		else
			t = 1;

		if ( cpc_take_sample( &sample->cmd ) == -1 )
			return;
		if ( event_counter == 1 ) {
			/* only one event is set to be the overflow monitor */

			/* generate the overflow vector */
			overflow_vector = 1 << t;
			/* reset the threshold */
			sample->cmd.ce_pic[t] = UINT64_MAX - ESI->overflow.threshold[0];
		} else {
			/* two events are set to be the overflow monitors */
			overflow_vector = 0;
			readvalue = sample->cmd.ce_pic[0];
			if ( readvalue >= 0 ) {
				/* the first counter overflowed */

				/* generate the overflow vector */
				overflow_vector = 1;
				/* reset the threshold */
				if ( t == 0 )
					sample->cmd.ce_pic[0] =
						UINT64_MAX - ESI->overflow.threshold[0];
				else
					sample->cmd.ce_pic[0] =
						UINT64_MAX - ESI->overflow.threshold[1];
			}
			readvalue = sample->cmd.ce_pic[1];
			if ( readvalue >= 0 ) {
				/* the second counter overflowed */

				/* generate the overflow vector */
				overflow_vector ^= 1 << 1;
				/* reset the threshold */
				if ( t == 0 )
					sample->cmd.ce_pic[1] =
						UINT64_MAX - ESI->overflow.threshold[1];
				else
					sample->cmd.ce_pic[1] =
						UINT64_MAX - ESI->overflow.threshold[0];
			}
			SUBDBG( "overflow_vector, = %d\n", overflow_vector );
			/* something is wrong here */
			if ( overflow_vector == 0 ) {
				PAPIERROR( "BUG! overflow_vector is 0, dropping interrupt" );
				return;
			}
		}

		/* Call the regular overflow function in extras.c */
		if ( thread->running_eventset[cidx]->overflow.
			 flags & PAPI_OVERFLOW_FORCE_SW ) {
			address = GET_OVERFLOW_ADDRESS(ctx);
			_papi_hwi_dispatch_overflow_signal( ( void * ) &ctx, address, NULL,
												overflow_vector, 0, &thread,
												cidx );
		} else {
			PAPIERROR( "Additional implementation needed in dispatch_emt!" );
		}

#if DEBUG
		dump_cmd( sample );
#endif
		/* push back the correct values and start counting again */
		if ( cpc_bind_event( &sample->cmd, sample->flags ) == -1 )
			return;
	} else {
		SUBDBG( "dispatch_emt() dropped, si_code = %d\n", sip->si_code );
		return;
	}
}
Пример #17
0
void do_cmd(comedi_t *dev,comedi_cmd *cmd)
{
	int total=0;
	int ret;
	int go;
	fd_set rdset;
	struct timeval timeout;

	ret=comedi_command_test(dev,cmd);

	printf("test ret=%d\n",ret);
	if(ret<0){
		printf("errno=%d\n",errno);
		comedi_perror("comedi_command_test");
		return;
	}

	dump_cmd(stdout,cmd);

	ret=comedi_command_test(dev,cmd);

	printf("test ret=%d\n",ret);
	if(ret<0){
		printf("errno=%d\n",errno);
		comedi_perror("comedi_command_test");
		return;
	}

	dump_cmd(stdout,cmd);

	comedi_set_read_subdevice(dev, cmd->subdev);
	ret = comedi_get_read_subdevice(dev);
	if (ret < 0 || ret != cmd->subdev) {
		fprintf(stderr,
			"failed to change 'read' subdevice from %d to %d\n",
			ret, cmd->subdev);
		return;
	}

	ret=comedi_command(dev,cmd);

	printf("ret=%d\n",ret);
	if(ret<0){
		printf("errno=%d\n",errno);
		comedi_perror("comedi_command");
		return;
	}

	go=1;
	while(go){
		FD_ZERO(&rdset);
		FD_SET(comedi_fileno(device),&rdset);
		timeout.tv_sec = 0;
		timeout.tv_usec = 50000;
		ret = select(comedi_fileno(dev)+1,&rdset,NULL,NULL,&timeout);
		//printf("select returned %d\n",ret);
		if(ret<0){
			perror("select");
		}else if(ret==0){
			/* hit timeout */
			printf("timeout, polling...\n");
			ret = comedi_poll(device,cmd->subdev);
			printf("poll returned %d\n",ret);
		}else if(FD_ISSET(comedi_fileno(device),&rdset)){
			/* comedi file descriptor became ready */
			//printf("comedi file descriptor ready\n");
			ret=read(comedi_fileno(dev),buf,sizeof(buf));
			printf("read returned %d\n",ret);
			if(ret<0){
				if(errno==EAGAIN){
					go = 0;
					perror("read");
				}
			}else if(ret==0){
				go = 0;
			}else{
				int i;
				total+=ret;
				//printf("read %d %d\n",ret,total);
				for(i=0;i<ret/sizeof(sampl_t);i++){
					printf("%d\n",buf[i]);
				}
			}
		}else{
			/* unknown file descriptor became ready */
			printf("unknown file descriptor ready\n");
		}
	}
}