Rev 146 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 146 | Rev 173 | ||
---|---|---|---|
Line 5... | Line 5... | ||
5 | #include <sys/mman.h> |
5 | #include <sys/mman.h> |
6 | #include <errno.h> |
6 | #include <errno.h> |
7 | #include <signal.h> |
7 | #include <signal.h> |
8 | #include <ctype.h> |
8 | #include <ctype.h> |
9 | #include <time.h> |
9 | #include <time.h> |
10 |
|
10 | #include "../include/wusbxx_dll.h" /* the header of the shared library */ |
11 | #include "../include/daq.h" |
11 | #include "../include/daq.h" |
12 | 12 | ||
13 | //#define DEBUG /* vkljuci dodatni izpis */ |
13 | //#define DEBUG /* vkljuci dodatni izpis */ |
14 | #ifdef DEBUG |
14 | #ifdef DEBUG |
15 | #define DBG(X) X |
15 | #define DBG(X) X |
Line 24... | Line 24... | ||
24 | //#define NTDCCH 8 |
24 | //#define NTDCCH 8 |
25 | //#define NADC 2 /* ADC */ |
25 | //#define NADC 2 /* ADC */ |
26 | //#define NADCCH 8 |
26 | //#define NADCCH 8 |
27 | int ctrlc=0; |
27 | int ctrlc=0; |
28 | char *ccserial=(char*)"CC0126"; |
28 | char *ccserial=(char*)"CC0126"; |
29 |
|
29 | //int devDetect; // variable to tell if we detect any devices |
30 | 30 | ||
31 | int daq::connect(){ |
31 | int daq::connect(){ |
32 | // odpri daq |
32 | // odpri daq |
33 |
|
33 | xxusb_device_type devices[100]; |
34 | //struct usb_device *dev; |
34 | //struct usb_device *dev; |
35 | devDetect = xxusb_devices_find(devices); |
35 | devDetect = xxusb_devices_find(devices); |
36 | // printf("Detected devices: %d\n", devDetect); |
36 | // printf("Detected devices: %d\n", devDetect); |
37 | //dev = devices[0].usbdev; |
37 | //dev = devices[0].usbdev; |
38 | //udev = xxusb_device_open(dev); |
38 | //udev = xxusb_device_open(dev); |
Line 42... | Line 42... | ||
42 | WUSBXX_load(NULL); |
42 | WUSBXX_load(NULL); |
43 | WUSBXX_open(ccserial); |
43 | WUSBXX_open(ccserial); |
44 | printf("daq::connect()\n"); |
44 | printf("daq::connect()\n"); |
45 | } |
45 | } |
46 | else |
46 | else |
47 |
|
47 | printf("daq::connect() - No devices were detected!\n"); |
48 | return 0; |
48 | return 0; |
49 | } |
49 | } |
50 | 50 | ||
51 | int daq::init(int chan = 0){ |
51 | int daq::init(int chan = 0){ |
52 | 52 | ||
53 |
|
53 | int i; |
54 |
|
54 | long k; |
55 | 55 | ||
56 |
|
56 | DBGFUNI(xxusb_register_write(udev,1,0x0)); // Stop DAQ mode |
57 | while (xxusb_usbfifo_read(udev, (int*) stackdump,BUFF_L,100)>0); |
57 | while (xxusb_usbfifo_read(udev, (int*) stackdump,BUFF_L,100)>0); |
58 | |
58 | |
59 | CCCZ; |
59 | CCCZ; |
60 | CCCC; |
60 | CCCC; |
61 | CREM_I; |
61 | CREM_I; |
Line 113... | Line 113... | ||
113 | // for(i = 0; i < 10; i++) printf("Setting %d? -> return = %d\n",i,ret[i]); |
113 | // for(i = 0; i < 10; i++) printf("Setting %d? -> return = %d\n",i,ret[i]); |
114 | 114 | ||
115 | // ret[0] = CAMAC_register_read(udev,1,&k); |
115 | // ret[0] = CAMAC_register_read(udev,1,&k); |
116 | // printf("k (return %d) -> 0x%08lX\n",ret[0],k); |
116 | // printf("k (return %d) -> 0x%08lX\n",ret[0],k); |
117 | |
117 | |
118 |
|
118 | printf("daq::init()\n"); |
119 | return 0; |
119 | return 0; |
120 | } |
120 | } |
121 | 121 | ||
122 | int daq::start(){ |
122 | int daq::start(){ |
123 |
|
123 | xxusb_register_write(udev,1,0x1); // Start DAQ mode |
124 | printf("daq::start()\n"); |
124 | printf("daq::start()\n"); |
125 | return 0; |
125 | return 0; |
126 | } |
126 | } |
127 | 127 | ||
128 | int daq::stop(){ |
128 | int daq::stop(){ |
129 |
|
129 | xxusb_register_write(udev,1,0x0); // Stop DAQ mode |
130 |
|
130 | while (xxusb_usbfifo_read(udev,(int *)stackdump,BUFF_L,30)>0); |
131 | printf("daq::stop()\n"); |
131 | printf("daq::stop()\n"); |
132 | return 0; |
132 | return 0; |
133 | } |
133 | } |
134 | 134 | ||
135 | int daq::event(unsigned int *data, int maxn){ |
135 | int daq::event(unsigned int *data, int maxn){ |
136 |
|
136 | int ib,count; |
137 | int count; |
- | |
138 |
|
137 | int events,evsize; |
139 | short ret; |
138 | short ret; |
140 | 139 | ||
141 | ib=0; |
140 | ib=0; |
142 | ret=xxusb_usbfifo_read(udev,(int *) stackdata,BUFF_L,500); |
141 | ret=xxusb_usbfifo_read(udev,(int *) stackdata,BUFF_L,500); |
143 | events=stackdata[ib++]; |
142 | events=stackdata[ib++]; |
Line 148... | Line 147... | ||
148 | while (ib<(ret/2-1)){ |
147 | while (ib<(ret/2-1)){ |
149 | evsize = stackdata[ib++]&0xffff; |
148 | evsize = stackdata[ib++]&0xffff; |
150 | DBG(printf("Event:%d EvSize:%d\n", events, evsize);) |
149 | DBG(printf("Event:%d EvSize:%d\n", events, evsize);) |
151 | for (int i=0;i<(NTDCCH+NADCCH);i++,ib++) data[count++] =stackdata[ib++]&0xffff; |
150 | for (int i=0;i<(NTDCCH+NADCCH);i++,ib++) data[count++] =stackdata[ib++]&0xffff; |
152 | if (stackdata[ib++]!=0xfafb){ |
151 | if (stackdata[ib++]!=0xfafb){ |
153 |
|
152 | printf("Error!\n"); |
154 | return 0; |
153 | return 0; |
155 | } |
154 | } |
156 | events--; |
155 | events--; |
157 | if (fStop) return 0; |
156 | if (fStop) return 0; |
158 | } |
157 | } |
159 | if (stackdata[ib++]!=0xffff){ |
158 | if (stackdata[ib++]!=0xffff){ |
160 | printf("Error!\n"); |
159 | printf("Error!\n"); |
161 | return 0; |
160 | return 0; |
162 | } |
161 | } |
163 | */ |
162 | |
164 |
|
163 | // count = 1; |
165 | return count; |
164 | return count; |
166 | } |
165 | } |
167 | 166 | ||
168 | int daq::disconnect(){ |
167 | int daq::disconnect(){ |
169 | // zapri daq |
168 | // zapri daq |
170 |
|
169 | WUSBXX_close(); |
171 | printf("daq::disconnect()\n"); |
170 | printf("daq::disconnect()\n"); |
172 | return 0; |
171 | return 0; |
173 | } |
172 | } |
174 | 173 | ||
175 | daq::daq(){ |
174 | daq::daq(){ |
Line 202... | Line 201... | ||
202 | if (argc>1) neve = atoi(argv[1]); |
201 | if (argc>1) neve = atoi(argv[1]); |
203 | if (argc>2) fname = argv[2]; |
202 | if (argc>2) fname = argv[2]; |
204 | 203 | ||
205 | 204 | ||
206 | // intercept routine |
205 | // intercept routine |
207 | if (signal (SIGINT, CatchSig) == |
206 | if (signal (SIGINT, CatchSig) == SIG_ERR) perror ("sigignore"); |
208 | 207 | ||
209 | #define BSIZE 10000 |
208 | #define BSIZE 10000 |
210 | int i,ieve,nc,nb; |
209 | int i,ieve,nc,nb; |
211 | // int hdr[4]={1,(NTDCCH+4)*sizeof(int)}; // hdr[0]=1, hdr[1]=(NTDCCH+4)*4 |
210 | // int hdr[4]={1,(NTDCCH+4)*sizeof(int)}; // hdr[0]=1, hdr[1]=(NTDCCH+4)*4 |
212 | int hdr[4]={1,(NTDCCH+NADCCH+4)*sizeof(int)}; |
211 | int hdr[4]={1,(NTDCCH+NADCCH+4)*sizeof(int)}; |
213 | unsigned short adc; |
212 | unsigned short adc; |
214 | unsigned int data[BSIZE]; |
213 | unsigned int data[BSIZE]; |
215 | daq *d= new daq(); |
214 | daq *d= new daq(); |
216 | time_t time_check; |
215 | time_t time_check; |
217 | 216 | ||
218 | // odpremo datoteko za pisanje |
217 | // odpremo datoteko za pisanje |
219 | FILE *fp=fopen(fname,"w"); |
218 | FILE *fp=fopen(fname,"w"); |
220 | 219 | ||
221 | d->start(); |
220 | d->start(); |