File: cmd_2.c

package info (click to toggle)
comedilib 0.11.0%2B5-1.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,544 kB
  • sloc: xml: 19,779; ansic: 14,719; sh: 5,679; cpp: 2,211; ruby: 1,658; perl: 700; makefile: 596; yacc: 439; lex: 86; python: 17
file content (83 lines) | stat: -rw-r--r-- 1,519 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

#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 get_chunks_per_length(int length);

#define BUFSZ 10000

int test_cmd_fifo_depth_check(void)
{
	int len;
	unsigned int flags = comedi_get_subdevice_flags(device,subdevice);

	/* attempt to make subdevice the current 'read' subdevice */
	if(flags&SDF_CMD_READ) comedi_set_read_subdevice(device,subdevice);
	if(!(flags&SDF_CMD) || (comedi_get_read_subdevice(device)!=subdevice)){
		printf("not applicable\n");
		return 0;
	}

	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_generic_timed(device, subdevice, &cmd, 1, 1)<0){
		printf("  not supported\n");
		return 0;
	}

	if(realtime)cmd.flags |= TRIG_RT;

	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;
}