source: fact/tools/FSC/simple_daq/cmd_send.cpp@ 16334

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