added tests and created main
authorDavid Schleef <ds@schleef.org>
Tue, 10 Oct 2000 00:52:10 +0000 (00:52 +0000)
committerDavid Schleef <ds@schleef.org>
Tue, 10 Oct 2000 00:52:10 +0000 (00:52 +0000)
testing/Makefile
testing/comedi_test.h [new file with mode: 0644]
testing/info.c [new file with mode: 0644]
testing/inpn.c [deleted file]
testing/insn_read.c [new file with mode: 0644]
testing/main.c
testing/mode0_read.c [new file with mode: 0644]
testing/mode1.c [deleted file]
testing/mode2.c [deleted file]

index 2c04b65db7e97b51b911bfccd4e7a63875ed861d..ba2cb110ce58cff845c85ce623f7f21d56750764 100644 (file)
@@ -6,7 +6,7 @@ LDFLAGS=-L../lib/ -lcomedi
 
 
 TARG=comedi_test
-OBJS=main.o mode1.o
+OBJS=main.o mode0_read.o insn_read.o info.o
 
 all: $(TARG)
 
diff --git a/testing/comedi_test.h b/testing/comedi_test.h
new file mode 100644 (file)
index 0000000..2732062
--- /dev/null
@@ -0,0 +1,11 @@
+
+#ifndef _COMEDI_TEST_H_
+#define _COMEDI_TEST_H_
+
+extern char *filename;
+extern comedi_t *device;
+
+extern int subdevice;
+
+#endif
+
diff --git a/testing/info.c b/testing/info.c
new file mode 100644 (file)
index 0000000..d863f5c
--- /dev/null
@@ -0,0 +1,79 @@
+
+#include <stdio.h>
+#include <comedilib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <getopt.h>
+#include <ctype.h>
+#include <math.h>
+#include <sys/time.h>
+#include <string.h>
+#include "comedi_test.h"
+
+
+static char *subdevice_types[]={
+       "unused",
+       "analog input",
+       "analog output",
+       "digital input",
+       "digital output",
+       "digital I/O",
+       "counter",
+       "timer",
+       "memory",
+       "calibration",
+       "processor"
+};
+
+
+int test_info(void)
+{
+       int j;
+       int type;
+       int chan,n_chans;
+       int n_ranges;
+       comedi_range *rng;
+
+       printf("rev 1\n");
+
+       type = comedi_get_subdevice_type(device,subdevice);
+       printf("I: subdevice type: %d (%s)\n",type,subdevice_types[type]);
+       if(type==COMEDI_SUBD_UNUSED)
+               return 0;
+       n_chans=comedi_get_n_channels(device,subdevice);
+       printf("  number of channels: %d\n",n_chans);
+       if(!comedi_maxdata_is_chan_specific(device,subdevice)){
+               printf("  max data value: %d\n",comedi_get_maxdata(device,subdevice,0));
+       }else{
+               printf("  max data value: (channel specific)\n");
+               for(chan=0;chan<n_chans;chan++){
+                       printf("    chan%d: %d\n",chan,
+                               comedi_get_maxdata(device,subdevice,chan));
+               }
+       }
+       printf("  ranges:\n");
+       if(!comedi_range_is_chan_specific(device,subdevice)){
+               n_ranges=comedi_get_n_ranges(device,subdevice,0);
+               printf("    all chans:");
+               for(j=0;j<n_ranges;j++){
+                       rng=comedi_get_range(device,subdevice,0,j);
+                       printf(" [%g,%g]",rng->min,rng->max);
+               }
+               printf("\n");
+       }else{
+               for(chan=0;chan<n_chans;chan++){
+                       n_ranges=comedi_get_n_ranges(device,subdevice,chan);
+                       printf("    chan%d:",chan);
+                       for(j=0;j<n_ranges;j++){
+                               rng=comedi_get_range(device,subdevice,chan,j);
+                               printf(" [%g,%g]",rng->min,rng->max);
+                       }
+                       printf("\n");
+               }
+       }
+
+       return 0;
+}
+
diff --git a/testing/inpn.c b/testing/inpn.c
deleted file mode 100644 (file)
index 4268121..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
-   This demo opens /dev/comedi0 and looks for an analog input
-   subdevice.  If it finds one, it measures one sample on each
-   channel for each input range.  The value NaN indicates that
-   the measurement was out of range.
- */
-
-#include <stdio.h>
-#include <comedilib.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <getopt.h>
-#include <ctype.h>
-
-extern int verbose_flag;
-extern int subdevice;
-extern int range;
-extern int channel;
-extern int aref;
-extern char *filename;
-
-comedi_t *device;
-
-
-int main(int argc, char *argv[])
-{
-       int n_subdevs;
-       int n_chans,chan;
-       int n_ranges;
-       int range;
-       int rangetype;
-       int maxdata;
-       lsampl_t data;
-       double voltage;
-
-       parse_options(argc,argv);
-
-       device=comedi_open(filename);
-       if(!device){
-               comedi_perror(filename);
-               exit(0);
-       }
-
-       subdevice=comedi_find_subdevice_by_type(device,COMEDI_SUBD_AI,0);
-       if(subdevice<0){
-               printf("no analog input subdevice found\n");
-               exit(0);
-       }
-
-       n_chans=comedi_get_n_channels(device,subdevice);
-       for(chan=0;chan<n_chans;chan++){
-               printf("%d: ",chan);
-
-               //n_ranges=comedi_get_n_ranges(device,subdevice,chan);
-               rangetype=comedi_get_rangetype(device,subdevice,chan);
-               n_ranges=RANGE_LENGTH(rangetype);
-
-               maxdata=comedi_get_maxdata(device,subdevice,chan);
-               for(range=0;range<n_ranges;range++){
-                       comedi_data_read(device,subdevice,chan,range,aref,&data);
-                       voltage=comedi_to_phys(data,comedi_get_range(device,subdevice,chan,range),maxdata);
-                       printf("%g ",voltage);
-               }
-               printf("\n");
-       }
-       
-       exit(0);
-}
-
diff --git a/testing/insn_read.c b/testing/insn_read.c
new file mode 100644 (file)
index 0000000..60631ab
--- /dev/null
@@ -0,0 +1,42 @@
+
+#include <stdio.h>
+#include <comedilib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <getopt.h>
+#include <ctype.h>
+#include <math.h>
+#include <sys/time.h>
+#include <string.h>
+#include "comedi_test.h"
+
+
+int test_insn_read(void)
+{
+       comedi_insn it;
+       lsampl_t data;
+       int save_errno;
+       int ret;
+
+       printf("rev 1\n");
+
+       memset(&it,0,sizeof(it));
+       it.subdev = subdevice;
+       it.insn = INSN_READ;
+       it.n = 1;
+       it.chanspec = CR_PACK(0,0,0);
+       it.data = &data;
+
+       ret = comedi_do_insn(device,&it);
+       save_errno = errno;
+
+       printf("comedi_do_insn: %d\n",ret);
+       if(ret<0){
+               printf("W: comedi_do_insn: errno=%d %s\n",save_errno,strerror(save_errno));
+       }
+
+       return 0;
+}
+
index e591eb2edc578f8a59010bfb9250359bbcc7255b..59bf598b2c68fcd55a45efcbc552eaf7c75a37c3 100644 (file)
@@ -11,6 +11,7 @@
 #include <ctype.h>
 #include <malloc.h>
 
+#include "comedi_test.h"
 
 char *filename="/dev/comedi0";
 int verbose_flag;
@@ -21,54 +22,52 @@ int channel;
 int aref;
 int range;
 
+int test_info(void);
+int test_mode0_read(void);
+int test_insn_read(void);
 
-int parse_options(int argc, char *argv[])
+struct test_struct{
+       char *name;
+       int (*do_test)(void);
+};
+struct test_struct tests[]={
+       { "info", test_info },
+       { "mode0_read", test_mode0_read },
+       { "insn_read", test_insn_read },
+};
+static int n_tests = sizeof(tests)/sizeof(tests[0]);
+
+int main(int argc, char *argv[])
 {
        int c;
-
+       int i;
 
        while (1) {
-               c = getopt(argc, argv, "acsrfvdgom");
+               c = getopt(argc, argv, "f");
                if (c == -1)
                        break;
                switch (c) {
                case 'f':
                        filename = argv[optind];
                        break;
-               case 's':
-                       sscanf(argv[optind],"%d",&subdevice);
-                       break;
-               case 'c':
-                       sscanf(argv[optind],"%d",&channel);
-                       break;
-               case 'a':
-                       sscanf(argv[optind],"%d",&aref);
-                       break;
-               case 'r':
-                       sscanf(argv[optind],"%d",&range);
-                       break;
-               case 'v':
-                       verbose_flag = 1;
-                       break;
-               case 'd':
-                       aref=AREF_DIFF;
-                       break;
-               case 'g':
-                       aref=AREF_GROUND;
-                       break;
-               case 'o':
-                       aref=AREF_OTHER;
-                       break;
-               case 'm':
-                       aref=AREF_COMMON;
-                       break;
                default:
                        printf("bad option\n");
                        exit(1);
                }
        }
 
-       return argc;
+       device = comedi_open(filename);
+
+       for(subdevice=0;subdevice<comedi_get_n_subdevices(device);subdevice++){
+               printf("I:\n");
+               printf("I: subdevice %d\n",subdevice);
+               for(i=0;i<n_tests;i++){
+                       printf("I: testing %s...\n",tests[i].name);
+                       tests[i].do_test();
+               }
+       }
+
+       return 0;
 }
 
 
diff --git a/testing/mode0_read.c b/testing/mode0_read.c
new file mode 100644 (file)
index 0000000..ce43d80
--- /dev/null
@@ -0,0 +1,48 @@
+
+#include <stdio.h>
+#include <comedilib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <getopt.h>
+#include <ctype.h>
+#include <math.h>
+#include <sys/time.h>
+#include <string.h>
+
+#include "comedi_test.h"
+
+
+int test_mode0_read(void)
+{
+       comedi_trig it;
+       lsampl_t data;
+       unsigned int chanspec;
+       int save_errno;
+       int ret;
+
+       printf("rev 1\n");
+
+       memset(&it,0,sizeof(it));
+       it.subdev = subdevice;
+       it.mode = 0;
+       it.n_chan = 1;
+       it.chanlist = &chanspec;
+       it.data = (sampl_t *)&data;
+       it.n = 1;
+
+       chanspec = CR_PACK(0,0,0);
+
+       ret = comedi_trigger(device,&it);
+       save_errno = errno;
+
+       printf("comedi_trig_ioctl: %d\n",ret);
+       if(ret<0){
+               printf("W: comedi_trig_ioctl: errno=%d %s\n",save_errno,
+                       strerror(save_errno));
+       }
+
+       return 0;
+}
+
diff --git a/testing/mode1.c b/testing/mode1.c
deleted file mode 100644 (file)
index 6c7752c..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
-       A little input demo for mode 1
-
-       Mode 1 uses a timer to acquire samples at regular intervals.
-       It scans through the channel list, and then repeats.
- */
-
-#include <stdio.h>
-#include <comedilib.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <getopt.h>
-#include <ctype.h>
-#include <math.h>
-#include <sys/time.h>
-#include <string.h>
-
-#define BUFSZ          1000
-#define N_CHANS                1000
-
-extern int verbose_flag;
-extern int subdevice;
-extern int range;
-extern int channel;
-extern int aref;
-extern char *filename;
-
-comedi_t *device;
-
-void parse_options(int argc,char *argv[]);
-
-sampl_t data[BUFSZ];
-
-unsigned int chanlist[N_CHANS];
-
-int ai_mode1_test(double freq,int n_chans,int n_scans);
-
-int main(int argc, char *argv[])
-{
-       parse_options(argc,argv);
-
-       device=comedi_open(filename);
-       if(!device){
-               comedi_perror(filename);
-               exit(0);
-       }
-
-       subdevice=comedi_find_subdevice_by_type(device,COMEDI_SUBD_AI,0);
-       if(subdevice<0){
-               printf("no analog input subdevice found\n");
-               exit(0);
-       }
-
-while(1){
-       printf("Testing mode 1:\n");
-
-       printf("10 hz, 1 chan\n");
-       ai_mode1_test(10.0,1,10);
-
-       printf("100 hz, 1 chan\n");
-       ai_mode1_test(100.0,1,100);
-
-       printf("1000 hz, 1 chan\n");
-       ai_mode1_test(1000.0,1,1000);
-
-       printf("10000 hz, 1 chan\n");
-       ai_mode1_test(10000.0,1,10000);
-
-       printf("100000 hz, 1 chan\n");
-       ai_mode1_test(100000.0,1,100000);
-
-       printf("100000 hz, 2 chan\n");
-       ai_mode1_test(100000.0,2,50000);
-
-       printf("100000 hz, 16 chans\n");
-       ai_mode1_test(100000.0,16,100000/16);
-}
-
-
-       return 0;
-}
-
-int ai_mode1_test(double freq,int n_chans,int n_scans)
-{
-       comedi_trig it;
-       int err;
-       int n,i;
-       double actual_freq;
-       void *data_ptr;
-       int n_left;
-       int maxchan;
-       struct timeval start,stop;
-       int m;
-
-       memset(&it,0,sizeof(it));
-       it.subdev = subdevice;
-       it.mode = 1;
-       it.n_chan = n_chans;
-       it.chanlist = chanlist;
-       it.data = data;
-       it.n = n_scans;
-
-       maxchan = comedi_get_n_channels(device,subdevice);
-
-       /* pack the channel list */
-       for(i=0;i<n_chans;i++){
-               chanlist[i] = CR_PACK(i%maxchan, range, aref);
-       }
-
-       comedi_get_timer(device,subdevice,freq,&it.trigvar,&actual_freq);
-       printf("primary actual frequency=%g timer value=%d\n",actual_freq,it.trigvar);
-
-       gettimeofday(&start,NULL);
-
-       if ((err = comedi_trigger(device, &it)) < 0) {
-               perror("ioctl");
-       }
-
-       data_ptr=data;
-       n_left=n_scans*n_chans*sizeof(sampl_t);
-       while(n_left>0){
-               m=n_left;
-               if(m>=BUFSZ)m=BUFSZ;
-               if((n=read(comedi_fileno(device),data_ptr,m))<0){
-                       perror("read");
-                       exit(1);
-               }
-               //printf("read %d\n",n);
-               n_left-=n;
-               //data_ptr+=n;
-       }
-
-       gettimeofday(&stop,NULL);
-
-       if(stop.tv_usec<=start.tv_usec){
-               stop.tv_usec+=1000000;
-               stop.tv_sec--;
-       }
-       stop.tv_sec-=start.tv_sec;
-       stop.tv_usec-=start.tv_usec;
-
-       printf("actual time elapsed: %d.%06d s.\n",(int)stop.tv_sec,(int)stop.tv_usec);
-       printf("expected time: %g\n",n_scans*n_chans/actual_freq);
-
-       return 0;
-}
-
diff --git a/testing/mode2.c b/testing/mode2.c
deleted file mode 100644 (file)
index 45013e3..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
-   A little input demo for mode 2
-
-   Mode 2 uses two different timers to convert samples.
-   The primary timer determines the time between scans,
-   and the secondary timer determines the time between
-   samples in a scan.
-
-   The time between scans is in trigval; the time
-   between samples is selected by trigval1.  Conversion
-   from seconds or Hz is done using the standard timer
-   routines.
-
- */
-
-#include <stdio.h>
-#include <comedilib.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <getopt.h>
-#include <ctype.h>
-
-#define N_SCANS                10
-#define N_CHANS                16
-
-int subdevice = 0;
-int chan=0;
-int range = 0;
-int aref = AREF_GROUND;
-double freq = 1000;
-
-#define N_SAMPLES      1000
-
-double data[N_SAMPLES];
-
-
-int main(int argc, char *argv[])
-{
-       char *fn = NULL;
-       int i;
-       comedi_t *dev;
-
-       fn = "/dev/comedi0";
-
-       dev = comedi_open(fn);
-
-#if 0
-       for(i=0;i<10;i++){
-               range=comedi_find_range(dev,subdevice,chan,0,-i,i);
-               printf("%d\n",range);
-       }
-#endif
-       comedi_timed_1chan(dev,subdevice,chan,range,aref,freq,N_SAMPLES,data);
-
-       for(i=0;i<N_SAMPLES;i++){
-               printf("%g\n",data[i]);
-       }
-
-       return 0;
-}
-