Added realtime command line option. Fixed tests to use realtime
[comedilib.git] / testing / cmd_2.c
1
2 #include <stdio.h>
3 #include <comedilib.h>
4 #include <fcntl.h>
5 #include <unistd.h>
6 #include <sys/ioctl.h>
7 #include <errno.h>
8 #include <getopt.h>
9 #include <ctype.h>
10 #include <math.h>
11 #include <sys/time.h>
12 #include <string.h>
13 #include "comedi_test.h"
14
15 static int get_chunks_per_length(int length);
16
17 #define BUFSZ 10000
18
19 int test_cmd_fifo_depth_check(void)
20 {
21         int len;
22
23         if(!(comedi_get_subdevice_flags(device,subdevice)&SDF_CMD)){
24                 printf("not applicable\n");
25                 return 0;
26         }
27
28         for(len=64;len<65536;len<<=1){
29                 printf("%d, %d\n",len,get_chunks_per_length(len));
30         }
31
32         return 0;
33 }
34
35 static int get_chunks_per_length(int length)
36 {
37         comedi_cmd cmd;
38         char buf[BUFSZ];
39         unsigned int chanlist[1];
40         int go;
41         int total=0;
42         int ret;
43         int chunks=0;
44
45         if(comedi_get_cmd_generic_timed(device,subdevice,&cmd)<0){
46                 printf("  not supported\n");
47                 return 0;
48         }
49
50         if(realtime)cmd.flags |= TRIG_RT;
51
52         cmd.chanlist = chanlist;
53         cmd.scan_end_arg = 1;
54         cmd.stop_arg = length;
55         cmd.chanlist_len = 1;
56         chanlist[0] = CR_PACK(0,0,0);
57
58         comedi_command(device,&cmd);
59
60         go=1;
61         while(go){
62                 ret = read(comedi_fileno(device),buf,BUFSZ);
63                 if(ret<0){
64                         if(errno==EAGAIN){
65                                 usleep(10000);
66                         }else{
67                                 go = 0;
68                                 perror("read");
69                         }
70                 }else if(ret==0){
71                         go = 0;
72                 }else{
73                         total += ret;
74                         chunks++;
75                 }
76         }
77
78         return chunks;
79 }
80