From 31b3e7ed7fc2b63a99537a85dfac3444eaf2fa03 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Sat, 14 Jul 2001 00:50:52 +0000 Subject: [PATCH] Changed the name of verbose_flag; Added a few more flags in main.c --- demo/Makefile | 2 +- demo/README | 23 ++++++++++++--------- demo/antialias.c | 2 +- demo/examples.h | 8 ++++++- demo/inp.c | 2 +- demo/insn.c | 2 +- demo/ledclock.c | 4 ++-- demo/main.c | 54 +++++++++++++++++++++++++++++++----------------- demo/mmap.c | 6 ++---- demo/outp.c | 2 +- demo/poll.c | 6 ++---- demo/receiver.c | 4 ++-- demo/select.c | 6 ++---- demo/sigio.c | 4 ++-- demo/sv.c | 2 +- 15 files changed, 73 insertions(+), 54 deletions(-) diff --git a/demo/Makefile b/demo/Makefile index e51ba5b..0c5f209 100644 --- a/demo/Makefile +++ b/demo/Makefile @@ -1,7 +1,7 @@ -CFLAGS += -I ../include -I . -O2 -Wall -Wstrict-prototypes +CFLAGS += -I ../include -I . -O2 -Wall -Wstrict-prototypes -g #CFLAGS += -I ../include -I . -Wall -Wstrict-prototypes -g LDFLAGS = -L../lib/ -lcomedi -lm diff --git a/demo/README b/demo/README index 37109f6..f32bbf1 100644 --- a/demo/README +++ b/demo/README @@ -110,14 +110,17 @@ Many of these demos are linked with the file main.c, which parses command line options. Some options don't make sense with all programs. The options are: --a use analog reference (default: 0 == ground) --c use channel (default: 0) --s use subdevice (default: 0) --r use voltage range (default: 0) --f use device file (default: /dev/comedi0) --v verbose --d set analog reference to differential --g set analog reference to ground --o set analog reference to other --m set analog reference to common + -a use analog reference (default: 0 == ground) + -c use channel (default: 0) + -s use subdevice (default: 0) + -r use voltage range (default: 0) + -f use device file (default: /dev/comedi0) + -n use for the number of channels in a scan + -N use for the number of scans + -F use as the scan frequency + -v verbose + -d set analog reference to differential + -g set analog reference to ground + -o set analog reference to other + -m set analog reference to common diff --git a/demo/antialias.c b/demo/antialias.c index b3881fd..2e1e957 100644 --- a/demo/antialias.c +++ b/demo/antialias.c @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) } data = value; - if(verbose_flag){ + if(verbose){ printf("writing %d to device=%s subdevice=%d channel=%d range=%d analog reference=%d\n", data,filename,subdevice,channel,range,aref); } diff --git a/demo/examples.h b/demo/examples.h index 41cc3bc..65dcb59 100644 --- a/demo/examples.h +++ b/demo/examples.h @@ -2,6 +2,8 @@ #ifndef _EXAMPLES_H #define _EXAMPLES_H +#include + /* * Definitions of some of the common code. */ @@ -15,10 +17,14 @@ extern int subdevice; extern int channel; extern int aref; extern int range; +extern int verbose; +extern int n_chan; +extern int n_scan; +extern double freq; int parse_options(int argc, char *argv[]); char *cmd_src(int src,char *buf); -void dump_cmd(comedi_cmd *cmd); +void dump_cmd(FILE *file,comedi_cmd *cmd); #define sec_to_nsec(x) ((x)*1000000000) diff --git a/demo/inp.c b/demo/inp.c index 02425a6..d09b165 100644 --- a/demo/inp.c +++ b/demo/inp.c @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) exit(0); } - if(verbose_flag){ + if(verbose){ printf("measuring device=%s subdevice=%d channel=%d range=%d analog reference=%d\n", filename,subdevice,channel,range,aref); } diff --git a/demo/insn.c b/demo/insn.c index 96a1c10..59fbbb9 100644 --- a/demo/insn.c +++ b/demo/insn.c @@ -55,7 +55,7 @@ int main(int argc, char *argv[]) exit(0); } - if(verbose_flag){ + if(verbose){ printf("measuring device=%s subdevice=%d channel=%d range=%d analog reference=%d\n", filename,subdevice,channel,range,aref); } diff --git a/demo/ledclock.c b/demo/ledclock.c index 7a6f96d..695583f 100644 --- a/demo/ledclock.c +++ b/demo/ledclock.c @@ -179,7 +179,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd) return; } - dump_cmd(cmd); + dump_cmd(stdout,cmd); ret=comedi_command_test(dev,cmd); @@ -190,7 +190,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd) return; } - dump_cmd(cmd); + dump_cmd(stdout,cmd); ret=comedi_command(dev,cmd); diff --git a/demo/main.c b/demo/main.c index e11a5ff..a2e73d8 100644 --- a/demo/main.c +++ b/demo/main.c @@ -12,17 +12,21 @@ #include #include #include +#include #include "examples.h" char *filename="/dev/comedi0"; -int verbose_flag; +int verbose; int value=0; int subdevice=0; int channel=0; -int aref=0; +int aref=AREF_GROUND; int range=0; +int n_chan=4; +int n_scan=1000; +double freq=1000.0; int parse_options(int argc, char *argv[]) @@ -30,37 +34,46 @@ int parse_options(int argc, char *argv[]) int c; - while (-1 != (c = getopt(argc, argv, "a:c:s:r:f:vdgom"))) { + while (-1 != (c = getopt(argc, argv, "a:c:s:r:f:n:N:F:vdgom"))) { switch (c) { case 'f': filename = optarg; break; case 's': - sscanf(optarg,"%d",&subdevice); + subdevice = strtoul(optarg,NULL,0); break; case 'c': - sscanf(optarg,"%d",&channel); + channel = strtoul(optarg,NULL,0); break; case 'a': - sscanf(optarg,"%d",&aref); + aref = strtoul(optarg,NULL,0); break; case 'r': - sscanf(optarg,"%d",&range); + range = strtoul(optarg,NULL,0); + break; + case 'n': + n_chan = strtoul(optarg,NULL,0); + break; + case 'N': + n_scan = strtoul(optarg,NULL,0); + break; + case 'F': + freq = strtoul(optarg,NULL,0); break; case 'v': - verbose_flag = 1; + verbose = 1; break; case 'd': - aref=AREF_DIFF; + aref = AREF_DIFF; break; case 'g': - aref=AREF_GROUND; + aref = AREF_GROUND; break; case 'o': - aref=AREF_OTHER; + aref = AREF_OTHER; break; case 'm': - aref=AREF_COMMON; + aref = AREF_COMMON; break; default: printf("bad option\n"); @@ -87,9 +100,12 @@ char *cmd_src(int src,char *buf) if(src&TRIG_COUNT)strcat(buf, "count|"); if(src&TRIG_EXT)strcat(buf, "ext|"); if(src&TRIG_INT)strcat(buf, "int|"); +#ifdef TRIG_OTHER + if(src&TRIG_OTHER)strcat(buf, "other|"); +#endif if(strlen(buf)==0){ - sprintf(buf,"unknown(0x%02x)",src); + sprintf(buf,"unknown(0x%08x)",src); }else{ buf[strlen(buf)-1]=0; } @@ -97,27 +113,27 @@ char *cmd_src(int src,char *buf) return buf; } -void dump_cmd(comedi_cmd *cmd) +void dump_cmd(FILE *out,comedi_cmd *cmd) { char buf[100]; - printf("start: %s %d\n", + fprintf(out,"start: %-8s %d\n", cmd_src(cmd->start_src,buf), cmd->start_arg); - printf("scan_begin: %s %d\n", + fprintf(out,"scan_begin: %-8s %d\n", cmd_src(cmd->scan_begin_src,buf), cmd->scan_begin_arg); - printf("convert: %s %d\n", + fprintf(out,"convert: %-8s %d\n", cmd_src(cmd->convert_src,buf), cmd->convert_arg); - printf("scan_end: %s %d\n", + fprintf(out,"scan_end: %-8s %d\n", cmd_src(cmd->scan_end_src,buf), cmd->scan_end_arg); - printf("stop: %s %d\n", + fprintf(out,"stop: %-8s %d\n", cmd_src(cmd->stop_src,buf), cmd->stop_arg); } diff --git a/demo/mmap.c b/demo/mmap.c index f2aef3b..301e19e 100644 --- a/demo/mmap.c +++ b/demo/mmap.c @@ -30,8 +30,6 @@ #define N_SCANS 10 #define N_CHANS 16 -double freq = 1000; - #define BUFSZ 1000 char buf[BUFSZ]; @@ -80,7 +78,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd) return; } - dump_cmd(cmd); + dump_cmd(stdout,cmd); ret = comedi_command_test(dev,cmd); @@ -91,7 +89,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd) return; } - dump_cmd(cmd); + dump_cmd(stdout,cmd); ret = comedi_command(dev,cmd); diff --git a/demo/outp.c b/demo/outp.c index 6fafef7..9a54b85 100644 --- a/demo/outp.c +++ b/demo/outp.c @@ -38,7 +38,7 @@ int main(int argc, char *argv[]) } data = value; - if(verbose_flag){ + if(verbose){ printf("writing %d to device=%s subdevice=%d channel=%d range=%d analog reference=%d\n", data,filename,subdevice,channel,range,aref); } diff --git a/demo/poll.c b/demo/poll.c index 3ee5a0b..3acb864 100644 --- a/demo/poll.c +++ b/demo/poll.c @@ -29,8 +29,6 @@ #define N_SCANS 10 #define N_CHANS 16 -double freq = 1000; - #define BUFSZ 1000 sampl_t buf[BUFSZ]; @@ -99,7 +97,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd) return; } - dump_cmd(cmd); + dump_cmd(stdout,cmd); ret=comedi_command_test(dev,cmd); @@ -110,7 +108,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd) return; } - dump_cmd(cmd); + dump_cmd(stdout,cmd); ret=comedi_command(dev,cmd); diff --git a/demo/receiver.c b/demo/receiver.c index 4bddf51..c0e687e 100644 --- a/demo/receiver.c +++ b/demo/receiver.c @@ -97,7 +97,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd) return; } - dump_cmd(cmd); + dump_cmd(stdout,cmd); cmd->chanlist = chanlist; cmd->chanlist_len = n_chans; @@ -111,7 +111,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd) return; } - dump_cmd(cmd); + dump_cmd(stdout,cmd); cmd->chanlist = chanlist; cmd->chanlist_len = n_chans; diff --git a/demo/select.c b/demo/select.c index 5e59c98..aeba724 100644 --- a/demo/select.c +++ b/demo/select.c @@ -29,8 +29,6 @@ #define N_SCANS 10 #define N_CHANS 16 -double freq = 1000; - #define BUFSZ 1000 sampl_t buf[BUFSZ]; @@ -94,7 +92,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd) return; } - dump_cmd(cmd); + dump_cmd(stdout,cmd); ret=comedi_command_test(dev,cmd); @@ -105,7 +103,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd) return; } - dump_cmd(cmd); + dump_cmd(stdout,cmd); ret=comedi_command(dev,cmd); diff --git a/demo/sigio.c b/demo/sigio.c index 15bd4df..e096030 100644 --- a/demo/sigio.c +++ b/demo/sigio.c @@ -142,7 +142,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd) return; } - dump_cmd(cmd); + dump_cmd(stdout,cmd); ret=comedi_command_test(dev,cmd); @@ -153,7 +153,7 @@ void do_cmd(comedi_t *dev,comedi_cmd *cmd) return; } - dump_cmd(cmd); + dump_cmd(stdout,cmd); ret=comedi_command(dev,cmd); diff --git a/demo/sv.c b/demo/sv.c index 14c7c43..ae51115 100644 --- a/demo/sv.c +++ b/demo/sv.c @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) exit(0); } - if(verbose_flag){ + if(verbose){ printf("measuring device=%s subdevice=%d channel=%d range=%d analog reference=%d\n", filename,subdevice,channel,range,aref); } -- 2.26.2