source: fact/tools/FAD/simple_daq/cmd_send.cpp@ 10107

Last change on this file since 10107 was 9926, checked in by ogrimm, 14 years ago
now checks revision and just prints it. init_fad() now sets DACs. minor changes..
File size: 8.8 KB
Line 
1#include "simple_daq.h"
2
3// Send commands to socket
4void cmd_send (const char* Buffer, int Socket)
5{
6 int i;
7 unsigned short CMD_Buffer[512];
8 unsigned char CMD_Str[16];
9 unsigned short CMD_Num = 1;
10 unsigned int val, num;
11
12 if (strncmp (Buffer, "r\n", 2) == 0)
13 {
14 CMD_Buffer[0] = htons (CMD_Start);
15 printf ("# Start Run ->\n");
16 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
17 }
18
19 else if (strncmp (Buffer, "s\n", 2) == 0)
20 {
21 CMD_Buffer[0] = htons (CMD_Stop);
22 printf ("# Stop Run ->\n");
23 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
24 }
25
26 else if (strncmp (Buffer, "sz\n", 3) == 0)
27 {
28 CMD_Buffer[0] = 0x0000;
29 printf ("# Send 0x0000 ->\n");
30 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
31 }
32
33 else if (strncmp (Buffer, "t\n", 2) == 0)
34 {
35 CMD_Buffer[0] = htons (CMD_Trigger);
36 printf ("# Trigger ->\n");
37 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
38 }
39
40 else if (strncmp (Buffer, "de\n", 3) == 0)
41 {
42 CMD_Buffer[0] = htons (CMD_DENABLE);
43 printf ("# domino wave enabled ->\n");
44 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
45 }
46
47 else if (strncmp (Buffer, "psup\n", 5) == 0)
48 {
49 CMD_Buffer[0] = htons (CMD_PS_DIRINC);
50 printf ("# increasing phase shift ->\n");
51 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
52 }
53
54 else if (strncmp (Buffer, "psdn\n", 5) == 0)
55 {
56 CMD_Buffer[0] = htons (CMD_PS_DIRDEC);
57 printf ("# decreasing phase shift ->\n");
58 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
59 }
60
61 else if (strncmp (Buffer, "psreset\n", 8) == 0)
62 {
63 CMD_Buffer[0] = htons (CMD_PS_RESET);
64 printf ("# resetting phase shift ->\n");
65 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
66 }
67
68 else if (strncmp (Buffer, "ps\n", 3) == 0)
69 {
70 CMD_Buffer[0] = htons (CMD_PS_DO);
71 printf ("# phase shifting once! ->\n");
72 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
73 }
74
75
76
77 else if (strncmp (Buffer, "dd\n", 3) == 0)
78 {
79 CMD_Buffer[0] = htons (CMD_DDISABLE);
80 printf ("# domino wave disabled ->\n");
81 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
82 }
83
84 else if (strncmp (Buffer, "dr\n", 3) == 0)
85 {
86 CMD_Buffer[0] = htons (CMD_DWRITE_RUN);
87 printf ("# DWRITE HIGH->\n");
88 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
89 }
90
91 else if (strncmp (Buffer, "ds\n", 3) == 0)
92 {
93 CMD_Buffer[0] = htons (CMD_DWRITE_STOP);
94 printf ("# DWRITE LOW ->\n");
95 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
96 }
97
98 else if (strncmp (Buffer, "srclkon\n", 8) == 0)
99 {
100 CMD_Buffer[0] = htons (CMD_SRCLK_ON);
101 printf ("# DRS readoutclock SRCLK ENABLED ->\n");
102 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
103 }
104 else if (strncmp (Buffer, "srclkoff\n", 9) == 0)
105 {
106 CMD_Buffer[0] = htons (CMD_SRCLK_OFF);
107 printf ("# DRS readoutclock SRCLK DISABLED ->\n");
108 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
109 }
110 else if (strncmp (Buffer, "sclkon\n", 7) == 0)
111 {
112 CMD_Buffer[0] = htons (CMD_SCLK_ON);
113 printf ("# SCLK ENABLED ->\n");
114 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
115 }
116 else if (strncmp (Buffer, "sclkoff\n", 8) == 0)
117 {
118 CMD_Buffer[0] = htons (CMD_SCLK_OFF);
119 printf ("# SCLK DISABLED ->\n");
120 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
121 }
122
123 else if (strncmp (Buffer, "tc\n", 3) == 0)
124 {
125 CMD_Buffer[0] = htons (CMD_Trigger_C);
126 printf ("# Continuous Trigger ->\n");
127 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
128 }
129
130 else if (strncmp (Buffer, "ts\n", 3) == 0)
131 {
132 CMD_Buffer[0] = htons (CMD_Trigger_S);
133 printf ("# Stop Trigger ->\n");
134 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
135 }
136
137 // Set ROI value
138 else if (strncmp (Buffer, "sr ", 3) == 0)
139 {
140 CMD_Num = 0;
141 if (sscanf (Buffer, "%3s %i %i", CMD_Str, &num, &val) == 3)
142 {
143 if ((num >= 0) & (num <= MAX_ROINUM) & (val >= 0) & (val <= MAX_ROIVAL))
144 {
145 printf ("# Set ROI %d to %d ->\n", num, val);
146 CMD_Buffer[0] = htons (CMD_Write | (BADDR_ROI + num));
147 CMD_Buffer[1] = htons (val);
148 printf ("# 0x%.4X 0x%.4X\n", ntohs (CMD_Buffer[0]), ntohs (CMD_Buffer[1]));
149 CMD_Num = 2;
150 }
151 else
152 {
153 printf ("Out of range\n");
154 printf ("Usage: sr NUM VAL: Set ROI NUM (0-%d) to VAL (0-%d)\n", MAX_ROINUM, MAX_ROIVAL);
155 }
156 }
157 else
158 {
159 printf ("Usage: sr NUM VAL: Set ROI NUM (0-%d) to VAL (0-%d)\n", MAX_ROINUM, MAX_ROIVAL);
160 }
161 }
162
163 // Set all ROIs
164 else if (strncmp (Buffer, "sra ", 4) == 0)
165 {
166 CMD_Num = 0;
167 if (sscanf (Buffer, "%4s %i", CMD_Str, &val) == 2)
168 {
169 if ((val >= 0) & (val <= MAX_ROIVAL))
170 {
171 printf ("# Set all ROIs to %d ->\n", val);
172 for (i = 0; i < (MAX_ROINUM + 1); i++)
173 {
174 CMD_Buffer[i * 2] = htons (CMD_Write | (BADDR_ROI + i));
175 CMD_Buffer[(i * 2) + 1] = htons (val);
176 CMD_Num += 2;
177 }
178 for (i = 0; i < ((MAX_ROINUM + 1) * 2); i += 8)
179 {
180 printf ("# 0x%.4X 0x%.4X 0x%.4X 0x%.4X 0x%.4X 0x%.4X 0x%.4X 0x%.4X\n",
181 ntohs (CMD_Buffer[i]), ntohs (CMD_Buffer[i + 1]),
182 ntohs (CMD_Buffer[i + 2]), ntohs (CMD_Buffer[i + 3]),
183 ntohs (CMD_Buffer[i + 4]), ntohs (CMD_Buffer[i + 5]),
184 ntohs (CMD_Buffer[i + 6]), ntohs (CMD_Buffer[i + 7]));
185 }
186 }
187 else
188 {
189 printf ("Out of range\n");
190 printf ("Usage: sra VAL: Set all ROIs to VAL (0-%d)\n", MAX_ROIVAL);
191 }
192 }
193 else
194 {
195 printf ("Usage: sra VAL: Set all ROIs to VAL (0-%d)\n", MAX_ROIVAL);
196 }
197 }
198
199 // Set DAC value
200 else if (strncmp (Buffer, "sd ", 3) == 0)
201 {
202 CMD_Num = 0;
203 if (sscanf (Buffer, "%3s %i %i", CMD_Str, &num, &val) == 3)
204 {
205 if ((num >= 0) & (num <= MAX_DACNUM) & (val >= 0) & (val <= MAX_DACVAL))
206 {
207 printf ("# Set DAC %d to %d ->\n", num, val);
208 CMD_Buffer[0] = htons (CMD_Write | (BADDR_DAC + num));
209 CMD_Buffer[1] = htons (val);
210 printf ("# 0x%.4X 0x%.4X\n", ntohs (CMD_Buffer[0]), ntohs (CMD_Buffer[1]));
211 CMD_Num = 2;
212 }
213 else
214 {
215 printf ("Out of range\n");
216 printf ("Usage: sd NUM VAL: Set DAC NUM (0-%d) to VAL (0-%d)\n", MAX_DACNUM, MAX_DACVAL);
217 }
218 }
219 else
220 {
221 printf ("Usage: sd NUM VAL: Set DAC NUM (0-%d) to VAL (0-%d)\n", MAX_DACNUM, MAX_DACVAL);
222 }
223 }
224
225 // Set address to value
226 else if (strncmp (Buffer, "sa ", 3) == 0)
227 {
228 CMD_Num = 0;
229 if (sscanf (Buffer, "%4s %i %i", CMD_Str, &num, &val) == 3)
230 {
231 if ((num >= 0) & (num <= MAX_ADDR) & (val >= 0) & (val <= MAX_VAL))
232 {
233 printf ("# Set ADDR %d to %d ->\n", num, val);
234 CMD_Buffer[0] = htons (CMD_Write | num);
235 CMD_Buffer[1] = htons (val);
236 printf ("# 0x%.4X 0x%.4X\n", ntohs (CMD_Buffer[0]), ntohs (CMD_Buffer[1]));
237 CMD_Num = 2;
238 }
239 else
240 {
241 printf ("Out of range\n");
242 printf ("Usage: sa NUM VAL: Set addr NUM (0-%d) to VAL (0-%d)\n", MAX_ADDR, MAX_VAL);
243 }
244 }
245 else
246 {
247 printf ("Usage: raw NUM VAL: Set addr NUM (0-%d) to VAL (0-%d)\n", MAX_ADDR, MAX_VAL);
248 }
249 }
250
251 // Send value
252 else if (strncmp (Buffer, "sv ", 3) == 0)
253 {
254 CMD_Num = 0;
255 if (sscanf (Buffer, "%4s %i", CMD_Str, &val) == 2)
256 {
257 if ((val >= 0) & (val <= MAX_VAL))
258 {
259 printf ("# Send %d ->\n", val);
260 CMD_Buffer[0] = htons (val);
261 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
262 CMD_Num = 1;
263 }
264 else
265 {
266 printf ("Out of range\n");
267 printf ("Usage: sv VAL: Send VAL (0-%d)\n", MAX_VAL);
268 }
269 }
270 else
271 {
272 printf ("Usage: sv VAL: Send VAL (0-%d)\n", MAX_VAL);
273 }
274 }
275
276 else if (strncmp (Buffer, "q\n", 2) == 0)
277 {
278 // Exit program
279 printf ("# Quit\n");
280 exit_program (EXIT_SUCCESS);
281 }
282
283 // Anything else... , print help
284 else
285 {
286 printf ("Commands:\n");
287 printf (" t: Single Trigger\n\n");
288 printf (" tc: Continuous Trigger\n");
289 printf (" ts: Stop Trigger\n");
290
291 printf ("\n");
292 printf (" sclkon: Switch SPI SLCK on\n");
293 printf (" sclkoff: Switch SPI SLCK off\n");
294
295 printf ("\n");
296 printf (" srclkon: Switch DRS SRLCK on\n");
297 printf (" srclkoff: Switch DRS SRLCK off\n");
298
299 printf ("\n");
300 printf (" ps: Phase shift ADCCLK against SRCLK - one step\n");
301 printf (" psup: 'increse' phase shift - default\n");
302 printf (" psdn: 'decrease' phase shift\n");
303 printf (" psreset: reset phase shift\n");
304
305
306 printf ("\n");
307 printf (" de: DENABLE HIGH\n");
308 printf (" dd: DENABLE LOW\n");
309 printf (" dr: DWRITE HIGH\n");
310 printf (" ds: DWRITE LOW\n");
311
312 printf ("\n");
313 printf (" sr NUM VAL: Set ROI NUM (0-35) to VAL (0-1024)\n");
314 printf (" sra VAL: Set all ROIs to VAL (0-1024)\n");
315 printf (" sd NUM VAL: Set DAC NUM (0-7) to VAL (0-65535)\n");
316 printf (" q: Quit\n");
317 printf ("\n");
318 printf (" Only for debugging:\n");
319 printf (" sa NUM VAL: Set addr NUM (0-255) to VAL (0-65535)\n");
320 printf (" sv VAL: Send VAL\n");
321 printf (" sz: Send 0x0000\n");
322 printf ("\n");
323 printf (" r: Start Run -- TODO\n");
324 printf (" s: Stop Run -- TODO\n");
325
326 CMD_Num = 0;
327 }
328
329 // Send commands
330 if (CMD_Num > 0)
331 {
332 if (write (Socket, CMD_Buffer, CMD_Num * sizeof (short)) < 1)
333 {
334 printf ("Error: could not write to socket\n");
335 }
336 }
337}
338
Note: See TracBrowser for help on using the repository browser.