doc: add missing -lm option to command line for compiling tut1
[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         unsigned int flags = comedi_get_subdevice_flags(device,subdevice);
23
24         if(!(flags&SDF_CMD) || (comedi_get_read_subdevice(device)!=subdevice)){
25                 printf("not applicable\n");
26                 return 0;
27         }
28
29         for(len=64;len<65536;len<<=1){
30                 printf("%d, %d\n",len,get_chunks_per_length(len));
31         }
32
33         return 0;
34 }
35
36 static int get_chunks_per_length(int length)
37 {
38         comedi_cmd cmd;
39         char buf[BUFSZ];
40         unsigned int chanlist[1];
41         int go;
42         int total=0;
43         int ret;
44         int chunks=0;
45
46         if(comedi_get_cmd_generic_timed(device, subdevice, &cmd, 1, 1)<0){
47                 printf("  not supported\n");
48                 return 0;
49         }
50
51         if(realtime)cmd.flags |= TRIG_RT;
52
53         cmd.chanlist = chanlist;
54         cmd.scan_end_arg = 1;
55         cmd.stop_arg = length;
56         cmd.chanlist_len = 1;
57         chanlist[0] = CR_PACK(0,0,0);
58
59         comedi_command(device,&cmd);
60
61         go=1;
62         while(go){
63                 ret = read(comedi_fileno(device),buf,BUFSZ);
64                 if(ret<0){
65                         if(errno==EAGAIN){
66                                 usleep(10000);
67                         }else{
68                                 go = 0;
69                                 perror("read");
70                         }
71                 }else if(ret==0){
72                         go = 0;
73                 }else{
74                         total += ret;
75                         chunks++;
76                 }
77         }
78
79         return chunks;
80 }
81