Debian Codegraph @

demo/sigio.c

raw symbols SCIP
1 /*
2 * SIGIO example
3 * Part of Comedilib
4 *
5 * Copyright (c) 1999,2000 David A. Schleef <[email protected]>
6 *
7 * This file may be freely modified, distributed, and combined with
8 * other software, as long as proper attribution is given in the
9 * source code.
10 */
11
12 #define _GNU_SOURCEcxx . . $ `demo/sigio.c:12:9`!
13
14 #include <stdio.h>
15 #include <comedilib.h>cxx . . $ `<file>/include/comedilib.h`/
16 #include <fcntl.h>
17 #include <unistd.h>
18 #include <stdlib.h>
19 #include <errno.h>
20 #include <getopt.h>
21 #include <ctype.h>
22 #include <signal.h>
23 #include <string.h>
24 #include <sys/time.h>
25 #include "examples.h"cxx . . $ `<file>/demo/examples.h`/
26
27 comedi_tcxx . . $ comedi_t# *devicecxx . . $ device.;
28
29
30 void print_timecxx . . $ print_time(49f6e7a06ebc5aa8).(void);
31
32 void sigio_handlercxx . . $ sigio_handler(d4f767463ce0a6b3).(int sig)
33 {
34 print_timecxx . . $ print_time(49f6e7a06ebc5aa8).();
35 }
36
37 void print_timecxx . . $ print_time(49f6e7a06ebc5aa8).(void)
38 {
39 struct timevalcxx . . $ timeval# tv;
40 static struct timevalcxx . . $ timeval# oldtime={0};
41 int dsec,dusec;
42
43 gettimeofdaycxx . . $ gettimeofday(ee8865a94200b3d6).(&tv,NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
44
45 dsec=tv.tv_seccxx . . $ timeval#tv_sec.-oldtime.tv_seccxx . . $ timeval#tv_sec.;
46 dusec=tv.tv_useccxx . . $ timeval#tv_usec.-oldtime.tv_useccxx . . $ timeval#tv_usec.;
47 if(dusec<0){
48 dsec--;
49 dusec+=1000000;
50 }
51 printfcxx . . $ printf(581fddd72a8db8fc).("%d.%06d +%d.%06d\n",(int)tv.tv_seccxx . . $ timeval#tv_sec.,(int)tv.tv_useccxx . . $ timeval#tv_usec.,dsec,dusec);
52
53 oldtime=tv;
54 }
55
56 int out_subdcxx . . $ out_subd.;
57
58 void config_outputcxx . . $ config_output(49f6e7a06ebc5aa8).(void)
59 {
60 int i;
61
62 for(i=0;i<8;i++){
63 comedi_dio_configcxx . . $ comedi_dio_config(e80ed4ed1c56b623).(devicecxx . . $ device.,out_subdcxx . . $ out_subd.,i,COMEDI_OUTPUTcxx . . $ COMEDI_OUTPUT.);
64 }
65 }
66
67 int countcxx . . $ count.;
68
69 #define BUFSZcxx . . $ `demo/sigio.c:69:9`! 1024
70 sampl_tcxx . . $ sampl_t# bufcxx . . $ buf.[BUFSZcxx . . $ `demo/sigio.c:69:9`!];
71
72 void do_cmd_1cxx . . $ do_cmd_1(b01aa1ceea8394f).(comedi_tcxx . . $ comedi_t# *dev, int subdevice);
73 void do_cmd_2cxx . . $ do_cmd_2(641f548fdbb29019).(comedi_tcxx . . $ comedi_t# *dev);
74 void do_cmdcxx . . $ do_cmd(9c43a04e3b550225).(comedi_tcxx . . $ comedi_t# *dev,comedi_cmdcxx . . $ comedi_cmd# *cmd);
75
76 int maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[])
77 {
78 struct sigactioncxx . . $ sigaction# sa;
79 int ret;
80 sigset_tcxx . . $ sigset_t# sigset;
81 int flags;
82 struct parsed_optionscxx . . $ parsed_options# options;
83
84 init_parsed_optionscxx . . $ init_parsed_options(8caace97c9c42d8f).(&options);
85 parse_optionscxx . . $ parse_options(b6aabb1543a6f628).(&options, argc, argv);
86
87 devicecxx . . $ device. = comedi_opencxx . . $ comedi_open(d67864c6c007fe39).(options.filenamecxx . . $ parsed_options#filename.);
88 if(!devicecxx . . $ device.){
89 perrorcxx . . $ perror(85c52e162fed56f9).(options.filenamecxx . . $ parsed_options#filename.);
90 exitcxx . . $ exit(3ca292c338df9bb3).(1);
91 }
92
93 out_subdcxx . . $ out_subd. = 2;
94
95 config_outputcxx . . $ config_output(49f6e7a06ebc5aa8).();
96
97 fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(comedi_filenocxx . . $ comedi_fileno(33bb234f098f8f92).(devicecxx . . $ device.), F_SETOWNcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:177:10`!, getpidcxx . . $ getpid(b126dc7c1de90089).());
98 flags = fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(comedi_filenocxx . . $ comedi_fileno(33bb234f098f8f92).(devicecxx . . $ device.),F_GETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:168:9`!);
99 ret = fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(comedi_filenocxx . . $ comedi_fileno(33bb234f098f8f92).(devicecxx . . $ device.),F_SETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:169:9`!,flags|O_ASYNCcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:72:10`!);
100 //ret = fcntl(comedi_fileno(device),F_SETFL,O_NONBLOCK|O_ASYNC);
101 if(ret<0)perrorcxx . . $ perror(85c52e162fed56f9).("fcntl");
102
103 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&sa,0,sizeof(sa));
104 sa.sa_handlercxx . . $ `<external>/16635209305659446502/sigaction.h:39:10`! = &sigio_handlercxx . . $ sigio_handler(d4f767463ce0a6b3).;
105 ret = sigactioncxx . . $ sigaction(53aba09fe16b06c7).(SIGIOcxx . . $ `<external>/1457673850468744829/signum-arch.h:57:9`!,&sa,NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
106 if(ret<0)perrorcxx . . $ perror(85c52e162fed56f9).("sigaction");
107
108 sigemptysetcxx . . $ sigemptyset(f9c066a8ff75ee9d).(&sigset);
109 sigaddsetcxx . . $ sigaddset(4917c6e3ecb7dbd5).(&sigset,SIGIOcxx . . $ `<external>/1457673850468744829/signum-arch.h:57:9`!);
110 ret = sigprocmaskcxx . . $ sigprocmask(7504382baa173b1).(SIG_UNBLOCKcxx . . $ `<external>/16635209305659446502/sigaction.h:80:9`!,&sigset,NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
111 if(ret<0)perrorcxx . . $ perror(85c52e162fed56f9).("sigprocmask");
112
113 #if 0
114 {
115 struct sched_param p;
116 memset(&p,0,sizeof(p));
117 p.sched_priority = 1;
118 ret = sched_setscheduler(0,SCHED_FIFO,&p);
119 if(ret<0)perror("sched_setscheduler");
120 }
121 #endif
122
123 do_cmd_1cxx . . $ do_cmd_1(b01aa1ceea8394f).(devicecxx . . $ device., options.subdevicecxx . . $ parsed_options#subdevice.);
124
125 return 0;
126 }
127
128 void do_cmdcxx . . $ do_cmd(9c43a04e3b550225).(comedi_tcxx . . $ comedi_t# *dev,comedi_cmdcxx . . $ comedi_cmd# *cmd)
129 {
130 int total=0;
131 int ret;
132 int go;
133
134 ret=comedi_command_testcxx . . $ comedi_command_test(43d1de8b01a26507).(dev,cmd);
135
136 printfcxx . . $ printf(581fddd72a8db8fc).("test ret=%d\n",ret);
137 if(ret<0){
138 printfcxx . . $ printf(581fddd72a8db8fc).("errno=%d\n",errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
139 comedi_perrorcxx . . $ comedi_perror(85c52e162fed56f9).("comedi_command_test");
140 return;
141 }
142
143 dump_cmdcxx . . $ dump_cmd(2d5db0a34d5045d1).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!,cmd);
144
145 ret=comedi_command_testcxx . . $ comedi_command_test(43d1de8b01a26507).(dev,cmd);
146
147 printfcxx . . $ printf(581fddd72a8db8fc).("test ret=%d\n",ret);
148 if(ret<0){
149 printfcxx . . $ printf(581fddd72a8db8fc).("errno=%d\n",errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
150 comedi_perrorcxx . . $ comedi_perror(85c52e162fed56f9).("comedi_command_test");
151 return;
152 }
153
154 dump_cmdcxx . . $ dump_cmd(2d5db0a34d5045d1).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!,cmd);
155
156 comedi_set_read_subdevicecxx . . $ comedi_set_read_subdevice(7ee088ff0d1b2810).(dev, cmd->subdevcxx . . $ comedi_cmd_struct#subdev.);
157 ret = comedi_get_read_subdevicecxx . . $ comedi_get_read_subdevice(33bb234f098f8f92).(dev);
158 if (ret < 0 || ret != cmd->subdevcxx . . $ comedi_cmd_struct#subdev.) {
159 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,
160 "failed to change 'read' subdevice from %d to %d\n",
161 ret, cmd->subdevcxx . . $ comedi_cmd_struct#subdev.);
162 return;
163 }
164
165 ret=comedi_commandcxx . . $ comedi_command(43d1de8b01a26507).(dev,cmd);
166
167 printfcxx . . $ printf(581fddd72a8db8fc).("ret=%d\n",ret);
168 if(ret<0){
169 printfcxx . . $ printf(581fddd72a8db8fc).("errno=%d\n",errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
170 comedi_perrorcxx . . $ comedi_perror(85c52e162fed56f9).("comedi_command");
171 return;
172 }
173
174 go=1;
175 while(go){
176 ret=readcxx . . $ read(7e34d0a36f355389).(comedi_filenocxx . . $ comedi_fileno(33bb234f098f8f92).(dev),bufcxx . . $ buf.,BUFSZcxx . . $ `demo/sigio.c:69:9`!);
177 if(ret<0){
178 if(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!==EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`!){
179 printfcxx . . $ printf(581fddd72a8db8fc).("EAGAIN\n");
180 usleepcxx . . $ usleep(4c679297bf94b9eb).(10000);
181 }else{
182 go = 0;
183 perrorcxx . . $ perror(85c52e162fed56f9).("read");
184 }
185 }else if(ret==0){
186 go = 0;
187 }else{
188 //int i;
189
190 total+=ret;
191 //printf("read %d %d\n",ret,total);
192 //printf("count = %d\n",count);
193 //print_time();
194 }
195 }
196 }
197
198 unsigned int chanlistcxx . . $ chanlist.[0];
199 /*
200 * This part of the demo measures channels 1, 2, 3, 4 at a rate of
201 * 10 khz, with the inter-sample time at 10 us (100 khz). The number
202 * of scans measured is 10. This is analogous to the old mode2
203 * acquisition.
204 */
205 void do_cmd_1cxx . . $ do_cmd_1(b01aa1ceea8394f).(comedi_tcxx . . $ comedi_t# *dev, int subdevice)
206 {
207 comedi_cmdcxx . . $ comedi_cmd# cmd;
208
209 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&cmd,0,sizeof(cmd));
210
211 /* the subdevice that the command is sent to */
212 cmd.subdevcxx . . $ comedi_cmd_struct#subdev. = subdevice;
213
214 /* flags */
215 cmd.flagscxx . . $ comedi_cmd_struct#flags. = TRIG_WAKE_EOScxx . . $ `include/comedi.h:168:9`!;
216
217 cmd.start_srccxx . . $ comedi_cmd_struct#start_src. = TRIG_NOWcxx . . $ `include/comedi.h:182:9`!;
218 cmd.start_argcxx . . $ comedi_cmd_struct#start_arg. = 0;
219
220 cmd.scan_begin_srccxx . . $ comedi_cmd_struct#scan_begin_src. = TRIG_TIMERcxx . . $ `include/comedi.h:185:9`!;
221 cmd.scan_begin_argcxx . . $ comedi_cmd_struct#scan_begin_arg. = msec_to_nseccxx . . $ `demo/examples.h:36:9`!(100);
222
223 #if 1
224 cmd.convert_srccxx . . $ comedi_cmd_struct#convert_src. = TRIG_TIMERcxx . . $ `include/comedi.h:185:9`!;
225 cmd.convert_argcxx . . $ comedi_cmd_struct#convert_arg. = 1;
226 #else
227 cmd.convert_src = TRIG_ANY;
228 cmd.convert_arg = 0;
229 #endif
230
231 cmd.scan_end_srccxx . . $ comedi_cmd_struct#scan_end_src. = TRIG_COUNTcxx . . $ `include/comedi.h:186:9`!;
232 cmd.scan_end_argcxx . . $ comedi_cmd_struct#scan_end_arg. = 1;
233
234 cmd.stop_srccxx . . $ comedi_cmd_struct#stop_src. = TRIG_NONEcxx . . $ `include/comedi.h:181:9`!;
235 cmd.stop_argcxx . . $ comedi_cmd_struct#stop_arg. = 0;
236
237 cmd.chanlistcxx . . $ comedi_cmd_struct#chanlist. = chanlistcxx . . $ chanlist.;
238 cmd.chanlist_lencxx . . $ comedi_cmd_struct#chanlist_len. = 1;
239
240 chanlistcxx . . $ chanlist.[0]=CR_PACKcxx . . $ `include/comedi.h:79:9`!(0,0,0);
241
242 do_cmdcxx . . $ do_cmd(9c43a04e3b550225).(dev,&cmd);
243 }
244