From: Frank Mori Hess Date: Thu, 25 Jan 2001 00:49:26 +0000 (+0000) Subject: added --read-buffer and --write-buffer options for resizing buffers, X-Git-Tag: r0_7_15~23 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fd7a408853d2308efe6844f9d1e2d0ea83b01253;p=comedilib.git added --read-buffer and --write-buffer options for resizing buffers, incremented CC_VERSION to 0.7.13 --- diff --git a/comedi_config/comedi_config.c b/comedi_config/comedi_config.c index c9cad3f..0117905 100644 --- a/comedi_config/comedi_config.c +++ b/comedi_config/comedi_config.c @@ -21,7 +21,7 @@ */ -#define CC_VERSION "0.7.12" +#define CC_VERSION "0.7.13" #include #include @@ -34,39 +34,66 @@ #include #include #include +#include #include int quiet=0,verbose=0; +int read_buf_flag=0; +int read_buf_size=0; +int write_buf_flag=0; +int write_buf_size=0; + int init_fd; char *init_file; void *init_data; int init_size; -void do_help(int i) -{ - fputs( -"comedi_config version " CC_VERSION "\n" -"usage: comedi_config [-[vVq]] ,,...\n" -"where are integers (or blank) whose interpretation depends on\n" -"the driver. In general, however, option1 refers to the I/O port address\n" -"and option2 refers to IRQ number to be used by the driver\n" - ,stderr); - exit(i); -} - struct option options[] = { { "verbose", 0, 0, 'v' }, { "quiet", 0, 0, 'q' }, { "version", 0, 0, 'V' }, { "init-data", 1, 0, 'i' }, { "remove", 0, 0, 'r' }, + { "read-buffer", 1, &read_buf_flag, 1}, + { "write-buffer", 1, &write_buf_flag, 1}, }; +void do_help(int i) +{ + fputs( + "comedi_config version " CC_VERSION "\n" + "usage: comedi_config [OPTIONS] [ ,,...]\n" + "\n" + "OPTIONS:\n" + "\t-v --verbose\n" + "\t\tverbose output\n" + "\t-q --quiet\n" + "\t\tquiet output\n" + "\t-V --version\n" + "\t\tprint program version\n" + "\t-i --init-data \n" + "\t\tI don't know what this does\n" + "\t--read-buffer \n" + "\t\tset buffer size in kilobytes used for reads from the \n" + "\t--write-buffer \n" + "\t\tset buffer size in kilobytes used for writes to the \n" + "\n" + " are integers whose interpretation depends on\n" + "the driver. In general, however, for non-plug-and-play boards\n" + "opt1 refers to the I/O port address and opt2 refers to IRQ number\n" + "to be used by the driver. For plug-and-play boards, opt1 and opt2\n" + "are optional and allow you to specify the bus and slot of the card\n" + "(in case you have two identical cards).\n" + ,stderr); + exit(i); +} + int main(int argc,char *argv[]) { comedi_devconfig it; + comedi_bufconfig bc; int fd; int c,i,num,k; char *opts; @@ -74,9 +101,10 @@ int main(int argc,char *argv[]) struct stat statbuf; int ret; int remove=0; - + int index; + while(1){ - c=getopt(argc,argv,"rvVqf"); + c=getopt_long(argc, argv, "rvVqi:", options, &index); if(c==-1)break; switch(c){ case 'v': @@ -95,125 +123,159 @@ int main(int argc,char *argv[]) case 'i': init_file=optarg; break; + case 0: + if(read_buf_flag) read_buf_size = strtol(optarg, NULL, 0); + if(write_buf_flag) write_buf_size = strtol(optarg, NULL, 0); + if(read_buf_size < 0 || write_buf_size < 0) + { + fprintf(stderr, "invalid buffer size\n"); + exit(-1); + } + break; default: do_help(1); } } - if((argc-optind)!=2 && (argc-optind)!=3){ + if((argc-optind) < 1 || (argc-optind) > 3 || + ((argc-optind) == 1 && read_buf_flag == 0 && write_buf_flag == 0)){ do_help(1); } - + fn=argv[optind]; - - driver=argv[optind+1]; - strncpy(it.board_name,driver,COMEDI_NAMELEN-1); - - for(i=0;i=COMEDI_NDEVCONFOPTS) - do_help(1); - continue; - } - if(sscanf(opts,"%i%n",&num,&k)>0){ - it.options[i]=num; - opts+=k; - continue; - } - do_help(1); - } - } - - ret=stat(fn,&statbuf); - if(ret<0){ + + fd=open(fn,O_RDWR); + if(fd<0){ perror(fn); exit(1); } -#if 0 - /* this appears to be broken */ - if( !(S_ISCHR(statbuf.st_mode)) || - major(statbuf.st_dev)!=COMEDI_MAJOR){ - if(!quiet) - fprintf(stderr,"warning: %s might not be a comedi device\n",fn); - } -#endif - - if(init_file){ - struct stat buf; - init_fd = open(init_file,O_RDONLY); - if(init_fd<0){ - perror(init_file); - exit(1); - } + // if we are attaching a device and not just changing buffer size + if((argc-optind) > 1) + { + driver=argv[optind+1]; + strncpy(it.board_name,driver,COMEDI_NAMELEN-1); - fstat(init_fd,&buf); - - init_size = buf.st_size; - init_data = malloc(init_size); - if(init_data==NULL){ - perror("allocating initialization data\n"); - exit(1); + for(i=0;i=COMEDI_NDEVCONFOPTS) + do_help(1); + continue; + } + if(sscanf(opts,"%i%n",&num,&k)>0){ + it.options[i]=num; + opts+=k; + continue; + } + do_help(1); + } } - ret = read(init_fd,init_data,init_size); + ret=stat(fn,&statbuf); if(ret<0){ - perror("reading initialization data\n"); + perror(fn); exit(1); } +#if 0 + /* this appears to be broken */ + if( !(S_ISCHR(statbuf.st_mode)) || + major(statbuf.st_dev)!=COMEDI_MAJOR){ + if(!quiet) + fprintf(stderr,"warning: %s might not be a comedi device\n",fn); + } +#endif - it.options[0]=(int)init_data; - it.options[1]=init_size; - } + if(init_file){ + struct stat buf; + + init_fd = open(init_file,O_RDONLY); + if(init_fd<0){ + perror(init_file); + exit(1); + } + + fstat(init_fd,&buf); + + init_size = buf.st_size; + init_data = malloc(init_size); + if(init_data==NULL){ + perror("allocating initialization data\n"); + exit(1); + } + + ret = read(init_fd,init_data,init_size); + if(ret<0){ + perror("reading initialization data\n"); + exit(1); + } + + it.options[0]=(int)init_data; + it.options[1]=init_size; + } - fd=open(fn,O_RDWR); - if(fd<0){ - perror(fn); - exit(1); - } - /* add: sanity check for device */ - - if(verbose){ - printf("configuring driver=%s ",it.board_name); - for(i=0;i