testing additions

This commit is contained in:
David Schleef 2000-11-30 22:57:04 +00:00
parent 46247c4783
commit 981a9e2c22
10 changed files with 997 additions and 19 deletions

View file

@ -7,7 +7,7 @@ LDFLAGS=-L../lib/ -lcomedi
TARG=comedi_test
OBJS=main.o mode0_read.o insn_read.o info.o cmd_1.o insn_read_time.o \
cmd_2.o mmap.o
cmd_2.o mmap.o select.o cmd_3.o
all: $(TARG)

22
testing/README Normal file
View file

@ -0,0 +1,22 @@
The results directory contains last-known testing results that have
been contributed by users. If your board is listed there,
please compare it the output of comedi_test and if it differs
significantly, send me a copy and/or diff. I'll either update
the file, or it indicates that there is a bug. If your board
is not listed here, send me a copy of the output so it can
be included.
comedi_test tends to create a lot of output. The important
information has lines beginning with either I:, W:, or E:,
indicating information, warning, or error, respectively.
You can grep for this information using the regexp '^.:'.
Errors are usually problems that need to be fixed, but are
not necessarily significant bugs. Warnings need to be
audited by ds to know whether or not they are significant,
since comedi_test isn't very smart about some checks. (That's
why they're warnings and not errors.)

View file

@ -65,7 +65,7 @@ int test_cmd_probe_fast_1chan(void)
return 0;
}
#define BUFSZ 1000
#define BUFSZ 2000
int test_cmd_read_fast_1chan(void)
{
@ -83,7 +83,7 @@ int test_cmd_read_fast_1chan(void)
cmd.chanlist = chanlist;
cmd.scan_end_arg = 1;
cmd.stop_arg = 10000;
cmd.stop_arg = 100000;
cmd.chanlist_len = 1;
chanlist[0] = CR_PACK(0,0,0);
@ -103,7 +103,8 @@ int test_cmd_read_fast_1chan(void)
go = 0;
}else{
total += ret;
printf("read %d %d\n",ret,total);
if(verbose)
printf("read %d %d\n",ret,total);
}
}
@ -200,12 +201,14 @@ int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd)
ret=comedi_command_test(it,cmd);
if(ret==3){
printf("ret==3\n");
/* good */
ret=comedi_command_test(it,cmd);
}
if(ret==4 || ret==0){
return 0;
}
printf("W: comedi_command_test() returned %d\n",ret);
return -1;
}

139
testing/cmd_2.c Normal file
View file

@ -0,0 +1,139 @@
#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 int comedi_get_cmd_src_mask(comedi_t *it,unsigned int s,comedi_cmd *cmd);
static int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd);
static int get_chunks_per_length(int length);
#define BUFSZ 10000
int test_cmd_fifo_depth_check(void)
{
int len;
for(len=64;len<65536;len<<=1){
printf("%d, %d\n",len,get_chunks_per_length(len));
}
return 0;
}
static int get_chunks_per_length(int length)
{
comedi_cmd cmd;
char buf[BUFSZ];
unsigned int chanlist[1];
int go;
int total=0;
int ret;
int chunks=0;
if(comedi_get_cmd_fast_1chan(device,subdevice,&cmd)<0){
printf(" not supported\n");
return 0;
}
cmd.chanlist = chanlist;
cmd.scan_end_arg = 1;
cmd.stop_arg = length;
cmd.chanlist_len = 1;
chanlist[0] = CR_PACK(0,0,0);
comedi_command(device,&cmd);
go=1;
while(go){
ret = read(comedi_fileno(device),buf,BUFSZ);
if(ret<0){
if(errno==EAGAIN){
usleep(10000);
}else{
go = 0;
perror("read");
}
}else if(ret==0){
go = 0;
}else{
total += ret;
chunks++;
}
}
return chunks;
}
static int comedi_get_cmd_src_mask(comedi_t *it,unsigned int s,comedi_cmd *cmd)
{
memset(cmd,0,sizeof(*cmd));
cmd->subdev = s;
cmd->flags = 0;
cmd->start_src = TRIG_ANY;
cmd->scan_begin_src = TRIG_ANY;
cmd->convert_src = TRIG_ANY;
cmd->scan_end_src = TRIG_ANY;
cmd->stop_src = TRIG_ANY;
return comedi_command_test(it,cmd);
}
static int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd)
{
int ret;
ret = comedi_get_cmd_src_mask(it,s,cmd);
if(ret<0)return ret;
cmd->chanlist_len = 1;
cmd->scan_end_src = TRIG_COUNT;
cmd->scan_end_arg = 1;
if(cmd->convert_src&TRIG_TIMER){
if(cmd->scan_begin_src&TRIG_FOLLOW){
cmd->convert_src = TRIG_TIMER;
cmd->scan_begin_src = TRIG_FOLLOW;
}else{
cmd->convert_src = TRIG_TIMER;
cmd->scan_begin_src = TRIG_TIMER;
}
}else{
printf("can't do timed?!?\n");
return -1;
}
if(cmd->stop_src&TRIG_COUNT){
cmd->stop_src=TRIG_COUNT;
cmd->stop_arg=2;
}else if(cmd->stop_src&TRIG_NONE){
cmd->stop_src=TRIG_NONE;
cmd->stop_arg=0;
}else{
printf("can't find a good stop_src\n");
return -1;
}
ret=comedi_command_test(it,cmd);
if(ret==3){
/* good */
ret=comedi_command_test(it,cmd);
}
if(ret==4 || ret==0){
return 0;
}
return -1;
}

177
testing/cmd_3.c Normal file
View file

@ -0,0 +1,177 @@
#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 int comedi_get_cmd_src_mask(comedi_t *it,unsigned int s,comedi_cmd *cmd);
static int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd);
static int do_continuous(int multiplier);
#define BUFSZ 10000
int test_cmd_continuous(void)
{
int mult;
/* as if doing _one_ infinite loop wasn't slow enough,
* we loop through with higher and higher multipliers,
* in case the test fails because of latency problems */
for(mult=1;mult<1024;mult*=2){
do_continuous(mult);
}
return 0;
}
static int do_continuous(int multiplier)
{
comedi_cmd cmd;
char buf[BUFSZ];
unsigned int chanlist[1];
int go;
int total=0;
int ret;
int chunks=0;
unsigned long total_secs = 0;
struct timeval tv,start_tv;
if(comedi_get_cmd_fast_1chan(device,subdevice,&cmd)<0){
printf(" not supported\n");
return 0;
}
cmd.chanlist = chanlist;
cmd.scan_end_arg = 1;
cmd.stop_src = TRIG_NONE;
cmd.stop_arg = 0;
cmd.chanlist_len = 1;
chanlist[0] = CR_PACK(0,0,0);
// slow down a bit
cmd.scan_begin_arg *= multiplier;
printf("multiplier=%d, scan_begin_arg=%d\n",
multiplier,
cmd.scan_begin_arg);
ret=comedi_command(device,&cmd);
if(ret<0){
perror("comedi_command");
}else{
printf("ret==%d\n",ret);
}
gettimeofday(&start_tv,NULL);
go=1;
while(go){
ret = read(comedi_fileno(device),buf,BUFSZ);
if(ret<0){
if(errno==EAGAIN){
usleep(10000);
}else{
go = 0;
perror("read");
}
}else if(ret==0){
go = 0;
}else{
total += ret;
chunks++;
gettimeofday(&tv,NULL);
tv.tv_sec-=start_tv.tv_sec;
tv.tv_usec-=start_tv.tv_usec;
if(tv.tv_usec<0){
tv.tv_usec+=1000000;
tv.tv_sec--;
}
if(tv.tv_sec>total_secs){
double t;
t=tv.tv_sec+1e-6*tv.tv_usec;
printf("%0.3f %d (%g) %d (%g)\n",
t,
chunks,chunks/t,
total,total/t);
total_secs++;
}
}
}
return 0;
}
static int comedi_get_cmd_src_mask(comedi_t *it,unsigned int s,comedi_cmd *cmd)
{
memset(cmd,0,sizeof(*cmd));
cmd->subdev = s;
cmd->flags = 0;
cmd->start_src = TRIG_ANY;
cmd->scan_begin_src = TRIG_ANY;
cmd->convert_src = TRIG_ANY;
cmd->scan_end_src = TRIG_ANY;
cmd->stop_src = TRIG_ANY;
return comedi_command_test(it,cmd);
}
static int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd)
{
int ret;
ret = comedi_get_cmd_src_mask(it,s,cmd);
if(ret<0)return ret;
cmd->chanlist_len = 1;
cmd->scan_end_src = TRIG_COUNT;
cmd->scan_end_arg = 1;
if(cmd->convert_src&TRIG_TIMER){
if(cmd->scan_begin_src&TRIG_FOLLOW){
cmd->convert_src = TRIG_TIMER;
cmd->scan_begin_src = TRIG_FOLLOW;
}else{
cmd->convert_src = TRIG_TIMER;
cmd->scan_begin_src = TRIG_TIMER;
}
}else{
printf("can't do timed?!?\n");
return -1;
}
if(cmd->stop_src&TRIG_COUNT){
cmd->stop_src=TRIG_COUNT;
cmd->stop_arg=2;
}else if(cmd->stop_src&TRIG_NONE){
cmd->stop_src=TRIG_NONE;
cmd->stop_arg=0;
}else{
printf("can't find a good stop_src\n");
return -1;
}
ret=comedi_command_test(it,cmd);
if(ret==3){
/* good */
ret=comedi_command_test(it,cmd);
}
if(ret==4 || ret==0){
return 0;
}
return -1;
}

View file

@ -7,5 +7,7 @@ extern comedi_t *device;
extern int subdevice;
extern int verbose;
#endif

64
testing/insn_read_time.c Normal file
View file

@ -0,0 +1,64 @@
#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_time(void)
{
comedi_insn insn[3];
comedi_insnlist il;
struct timeval t1,t2;
lsampl_t data;
int save_errno;
int ret;
printf("rev 1\n");
memset(&il,0,sizeof(il));
memset(insn,0,sizeof(insn));
il.n_insns = 3;
il.insns = insn;
insn[0].insn = INSN_GTOD;
insn[0].n=2;
insn[0].data = (void *)&t1;
insn[1].subdev = subdevice;
insn[1].insn = INSN_READ;
insn[1].n = 1;
insn[1].chanspec = CR_PACK(0,0,0);
insn[1].data = &data;
insn[2].insn = INSN_GTOD;
insn[2].n=2;
insn[2].data = (void *)&t2;
ret = comedi_do_insnlist(device,&il);
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));
}
if(ret<2){
printf("W: comedi_do_insn: returned %d (expected 3)\n",ret);
}
printf("read time: %ld us\n",
(t2.tv_sec-t1.tv_sec)*1000000+(t2.tv_usec-t1.tv_usec));
return 0;
}

View file

@ -32,36 +32,58 @@ int test_cmd_probe_fast_1chan(void);
int test_cmd_read_fast_1chan(void);
int test_cmd_fifo_depth_check(void);
int test_mmap(void);
int test_read_select(void);
int test_cmd_continuous(void);
#define TEST_NEVER 0
#define TEST_STD 1
struct test_struct{
char *name;
int (*do_test)(void);
int flags;
};
struct test_struct tests[]={
{ "info", test_info },
{ "mode0_read", test_mode0_read },
{ "insn_read", test_insn_read },
{ "insn_read_time", test_insn_read_time },
{ "cmd_probe_src_mask", test_cmd_probe_src_mask },
{ "cmd_probe_fast_1chan", test_cmd_probe_fast_1chan },
{ "cmd_read_fast_1chan", test_cmd_read_fast_1chan },
{ "cmd_fifo_depth_check", test_cmd_fifo_depth_check },
{ "mmap", test_mmap },
{ "info", test_info, TEST_STD },
{ "mode0_read", test_mode0_read, TEST_STD },
{ "insn_read", test_insn_read, TEST_STD },
{ "insn_read_time", test_insn_read_time, TEST_STD },
{ "cmd_probe_src_mask", test_cmd_probe_src_mask, TEST_STD },
{ "cmd_probe_fast_1chan", test_cmd_probe_fast_1chan, TEST_STD },
{ "cmd_read_fast_1chan", test_cmd_read_fast_1chan, TEST_STD },
{ "cmd_fifo_depth_check", test_cmd_fifo_depth_check, TEST_STD },
{ "mmap", test_mmap, TEST_STD },
{ "read_select", test_read_select, TEST_STD },
{ "cmd_continuous", test_cmd_continuous, TEST_NEVER },
};
static int n_tests = sizeof(tests)/sizeof(tests[0]);
int only_subdevice;
int verbose;
char *only_test;
int main(int argc, char *argv[])
{
int c;
int i;
while (1) {
c = getopt(argc, argv, "f");
c = getopt(argc, argv, "f:s:t:v");
if (c == -1)
break;
switch (c) {
case 'f':
filename = argv[optind];
filename = optarg;
break;
case 's':
only_subdevice = 1;
sscanf(optarg,"%d",&subdevice);
break;
case 't':
only_test = optarg;
break;
case 'v':
verbose = 1;
break;
default:
printf("bad option\n");
@ -74,13 +96,25 @@ int main(int argc, char *argv[])
printf("E: comedi_open(\"%s\"): %s\n",filename,strerror(errno));
}
for(subdevice=0;subdevice<comedi_get_n_subdevices(device);subdevice++){
for(;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();
if(only_test){
for(i=0;i<n_tests;i++){
if(!strcmp(tests[i].name,only_test)){
printf("I: testing %s...\n",tests[i].name);
tests[i].do_test();
}
}
}else{
for(i=0;i<n_tests;i++){
if(tests[i].flags&TEST_STD){
printf("I: testing %s...\n",tests[i].name);
tests[i].do_test();
}
}
}
if(only_subdevice)break;
}
return 0;

View file

@ -0,0 +1,393 @@
I:
I: subdevice 0
I: testing info...
rev 1
I: subdevice type: 1 (analog input)
number of channels: 16
max data value: 65535
ranges:
all chans: [-10,10] [-5,5] [-2.5,2.5] [-1,1] [-0.5,0.5] [-0.25,0.25] [-0.1,0.1] [-0.05,0.05] [0,20] [0,10] [0,5] [0,2] [0,1] [0,0.5] [0,0.2] [0,0.1]
I: testing mode0_read...
rev 1
comedi_trig_ioctl: 1
I: testing insn_read...
rev 1
comedi_do_insn: 1
I: testing insn_read_time...
rev 1
comedi_do_insn: 3
read time: 22 us
I: testing cmd_probe_src_mask...
rev 1
command source mask:
start: now
scan_begin: timer|ext
convert: timer|ext
scan_end: count
stop: none|count
I: testing cmd_probe_fast_1chan...
command fast 1chan:
ret==3
start: now 0
scan_begin: timer 50000
convert: timer 50000
scan_end: count 1
stop: count 2
I: testing cmd_read_fast_1chan...
ret==3
I: testing cmd_fifo_depth_check...
64, 1
128, 1
256, 1
512, 1
1024, 2
2048, 4
4096, 8
8192, 16
16384, 32
32768, 64
I: testing mmap...
read 1024 1024
read 1024 2048
read 1024 3072
read 1024 4096
read 1024 5120
read 1024 6144
read 1024 7168
read 1024 8192
read 1024 9216
read 1024 10240
read 1024 11264
read 1024 12288
read 1024 13312
read 1024 14336
read 1024 15360
read 1024 16384
read 1024 17408
read 1024 18432
read 1024 19456
read 544 20000
compare ok
I: testing read_select...
I:
I: subdevice 1
I: testing info...
rev 1
I: subdevice type: 0 (unused)
I: testing mode0_read...
rev 1
comedi_trig_ioctl: -1
W: comedi_trig_ioctl: errno=5 Eingabe-/Ausgabefehler
I: testing insn_read...
rev 1
comedi_do_insn: -1
W: comedi_do_insn: errno=5 Eingabe-/Ausgabefehler
I: testing insn_read_time...
rev 1
comedi_do_insn: 1
W: comedi_do_insn: returned 1 (expected 3)
read time: 1855746208 us
I: testing cmd_probe_src_mask...
rev 1
not supported
I: testing cmd_probe_fast_1chan...
command fast 1chan:
not supported
I: testing cmd_read_fast_1chan...
not supported
I: testing cmd_fifo_depth_check...
not supported
64, 0
not supported
128, 0
not supported
256, 0
not supported
512, 0
not supported
1024, 0
not supported
2048, 0
not supported
4096, 0
not supported
8192, 0
not supported
16384, 0
not supported
32768, 0
I: testing mmap...
not supported
I: testing read_select...
not supported
I:
I: subdevice 2
I: testing info...
rev 1
I: subdevice type: 5 (digital I/O)
number of channels: 8
max data value: 1
ranges:
all chans: [0,5]
I: testing mode0_read...
rev 1
comedi_trig_ioctl: 1
I: testing insn_read...
rev 1
comedi_do_insn: 1
I: testing insn_read_time...
rev 1
comedi_do_insn: 3
read time: 8 us
I: testing cmd_probe_src_mask...
rev 1
not supported
I: testing cmd_probe_fast_1chan...
command fast 1chan:
not supported
I: testing cmd_read_fast_1chan...
not supported
I: testing cmd_fifo_depth_check...
not supported
64, 0
not supported
128, 0
not supported
256, 0
not supported
512, 0
not supported
1024, 0
not supported
2048, 0
not supported
4096, 0
not supported
8192, 0
not supported
16384, 0
not supported
32768, 0
I: testing mmap...
not supported
I: testing read_select...
not supported
I:
I: subdevice 3
I: testing info...
rev 1
I: subdevice type: 0 (unused)
I: testing mode0_read...
rev 1
comedi_trig_ioctl: -1
W: comedi_trig_ioctl: errno=5 Eingabe-/Ausgabefehler
I: testing insn_read...
rev 1
comedi_do_insn: -1
W: comedi_do_insn: errno=5 Eingabe-/Ausgabefehler
I: testing insn_read_time...
rev 1
comedi_do_insn: 1
W: comedi_do_insn: returned 1 (expected 3)
read time: 1855745636 us
I: testing cmd_probe_src_mask...
rev 1
not supported
I: testing cmd_probe_fast_1chan...
command fast 1chan:
not supported
I: testing cmd_read_fast_1chan...
not supported
I: testing cmd_fifo_depth_check...
not supported
64, 0
not supported
128, 0
not supported
256, 0
not supported
512, 0
not supported
1024, 0
not supported
2048, 0
not supported
4096, 0
not supported
8192, 0
not supported
16384, 0
not supported
32768, 0
I: testing mmap...
not supported
I: testing read_select...
not supported
I:
I: subdevice 4
I: testing info...
rev 1
I: subdevice type: 6 (counter)
number of channels: 1
max data value: 1
ranges:
all chans: [0,1]
I: testing mode0_read...
rev 1
comedi_trig_ioctl: -1
W: comedi_trig_ioctl: errno=5 Eingabe-/Ausgabefehler
I: testing insn_read...
rev 1
comedi_do_insn: -1
W: comedi_do_insn: errno=5 Eingabe-/Ausgabefehler
I: testing insn_read_time...
rev 1
comedi_do_insn: 1
W: comedi_do_insn: returned 1 (expected 3)
read time: 1855745145 us
I: testing cmd_probe_src_mask...
rev 1
not supported
I: testing cmd_probe_fast_1chan...
command fast 1chan:
not supported
I: testing cmd_read_fast_1chan...
not supported
I: testing cmd_fifo_depth_check...
not supported
64, 0
not supported
128, 0
not supported
256, 0
not supported
512, 0
not supported
1024, 0
not supported
2048, 0
not supported
4096, 0
not supported
8192, 0
not supported
16384, 0
not supported
32768, 0
I: testing mmap...
not supported
I: testing read_select...
not supported
I:
I: subdevice 5
I: testing info...
rev 1
I: subdevice type: 9 (calibration)
number of channels: 9
max data value: (channel specific)
chan0: 255
chan1: 255
chan2: 255
chan3: 255
chan4: 255
chan5: 255
chan6: 255
chan7: 255
chan8: 4095
ranges:
all chans: [0,1]
I: testing mode0_read...
rev 1
comedi_trig_ioctl: 1
I: testing insn_read...
rev 1
comedi_do_insn: 1
I: testing insn_read_time...
rev 1
comedi_do_insn: 3
read time: 1 us
I: testing cmd_probe_src_mask...
rev 1
not supported
I: testing cmd_probe_fast_1chan...
command fast 1chan:
not supported
I: testing cmd_read_fast_1chan...
not supported
I: testing cmd_fifo_depth_check...
not supported
64, 0
not supported
128, 0
not supported
256, 0
not supported
512, 0
not supported
1024, 0
not supported
2048, 0
not supported
4096, 0
not supported
8192, 0
not supported
16384, 0
not supported
32768, 0
I: testing mmap...
not supported
I: testing read_select...
not supported
I:
I: subdevice 6
I: testing info...
rev 1
I: subdevice type: 8 (memory)
number of channels: 512
max data value: 255
ranges:
all chans: [0,1]
I: testing mode0_read...
rev 1
comedi_trig_ioctl: 1
I: testing insn_read...
rev 1
comedi_do_insn: 1
I: testing insn_read_time...
rev 1
comedi_do_insn: 3
read time: 272 us
I: testing cmd_probe_src_mask...
rev 1
not supported
I: testing cmd_probe_fast_1chan...
command fast 1chan:
not supported
I: testing cmd_read_fast_1chan...
not supported
I: testing cmd_fifo_depth_check...
not supported
64, 0
not supported
128, 0
not supported
256, 0
not supported
512, 0
not supported
1024, 0
not supported
2048, 0
not supported
4096, 0
not supported
8192, 0
not supported
16384, 0
not supported
32768, 0
I: testing mmap...
not supported
I: testing read_select...
not supported

144
testing/select.c Normal file
View file

@ -0,0 +1,144 @@
#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 int comedi_get_cmd_src_mask(comedi_t *it,unsigned int s,comedi_cmd *cmd);
static int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd);
#define BUFSZ 10000
int test_read_select(void)
{
comedi_cmd cmd;
char buf[BUFSZ];
unsigned int chanlist[1];
int go;
int total=0;
int ret;
int chunks=0;
int length=100000;
fd_set rdset;
struct timeval timeout;
if(comedi_get_cmd_fast_1chan(device,subdevice,&cmd)<0){
printf(" not supported\n");
return 0;
}
cmd.chanlist = chanlist;
cmd.scan_end_arg = 1;
cmd.stop_arg = length;
cmd.chanlist_len = 1;
chanlist[0] = CR_PACK(0,0,0);
//fcntl(comedi_fileno(device),F_SETFL,O_NONBLOCK);
comedi_command(device,&cmd);
go=1;
while(go){
FD_ZERO(&rdset);
FD_SET(comedi_fileno(device),&rdset);
timeout.tv_sec = 0;
timeout.tv_usec = 10000;
ret = select(comedi_fileno(device)+1,&rdset,NULL,NULL,&timeout);
if(ret<0){
perror("select");
}else if(ret==0){
if(verbose)printf("timeout\n");
}else{
ret = read(comedi_fileno(device),buf,BUFSZ);
if(verbose)printf("read==%d\n",ret);
if(ret<0){
if(errno==EAGAIN){
printf("E: got EAGAIN!\n");
}else{
go = 0;
perror("read");
}
}else if(ret==0){
go = 0;
}else{
total += ret;
chunks++;
}
}
}
return 0;
}
static int comedi_get_cmd_src_mask(comedi_t *it,unsigned int s,comedi_cmd *cmd)
{
memset(cmd,0,sizeof(*cmd));
cmd->subdev = s;
cmd->flags = 0;
cmd->start_src = TRIG_ANY;
cmd->scan_begin_src = TRIG_ANY;
cmd->convert_src = TRIG_ANY;
cmd->scan_end_src = TRIG_ANY;
cmd->stop_src = TRIG_ANY;
return comedi_command_test(it,cmd);
}
static int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd)
{
int ret;
ret = comedi_get_cmd_src_mask(it,s,cmd);
if(ret<0)return ret;
cmd->chanlist_len = 1;
cmd->scan_end_src = TRIG_COUNT;
cmd->scan_end_arg = 1;
if(cmd->convert_src&TRIG_TIMER){
if(cmd->scan_begin_src&TRIG_FOLLOW){
cmd->convert_src = TRIG_TIMER;
cmd->scan_begin_src = TRIG_FOLLOW;
}else{
cmd->convert_src = TRIG_TIMER;
cmd->scan_begin_src = TRIG_TIMER;
}
}else{
printf("can't do timed?!?\n");
return -1;
}
if(cmd->stop_src&TRIG_COUNT){
cmd->stop_src=TRIG_COUNT;
cmd->stop_arg=2;
}else if(cmd->stop_src&TRIG_NONE){
cmd->stop_src=TRIG_NONE;
cmd->stop_arg=0;
}else{
printf("can't find a good stop_src\n");
return -1;
}
ret=comedi_command_test(it,cmd);
if(ret==3){
/* good */
ret=comedi_command_test(it,cmd);
}
if(ret==4 || ret==0){
return 0;
}
return -1;
}