source: tools/FAD/simple_daq/cmd_send.cpp@ 254

Last change on this file since 254 was 248, checked in by dneise, 14 years ago
initial check in of FAD tools simple daq - simple command line interface to FAD will produce binary socket_x.dat files ddd_for_fad - simple GUI able to plot FAD raw data.
File size: 6.8 KB
Line 
1#include "simple_daq.h"
2
3// Send commands to socket
4void cmd_send (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", 2) == 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, "dd\n", 2) == 0)
48 {
49 CMD_Buffer[0] = htons (CMD_DDISABLE);
50 printf ("# domino wave disabled ->\n");
51 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
52 }
53
54 else if (strncmp (Buffer, "dr\n", 2) == 0)
55 {
56 CMD_Buffer[0] = htons (CMD_DWRITE_RUN);
57 printf ("# DWRITE HIGH->\n");
58 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
59 }
60
61 else if (strncmp (Buffer, "ds\n", 2) == 0)
62 {
63 CMD_Buffer[0] = htons (CMD_DWRITE_STOP);
64 printf ("# DWRITE LOW ->\n");
65 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
66 }
67
68 else if (strncmp (Buffer, "tc\n", 3) == 0)
69 {
70 CMD_Buffer[0] = htons (CMD_Trigger_C);
71 printf ("# Continuous Trigger ->\n");
72 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
73 }
74
75 else if (strncmp (Buffer, "ts\n", 3) == 0)
76 {
77 CMD_Buffer[0] = htons (CMD_Trigger_S);
78 printf ("# Stop Trigger ->\n");
79 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
80 }
81
82 // Set ROI value
83 else if (strncmp (Buffer, "sr ", 3) == 0)
84 {
85 CMD_Num = 0;
86 if (sscanf (Buffer, "%3s %i %i", CMD_Str, &num, &val) == 3)
87 {
88 if ((num >= 0) & (num <= MAX_ROINUM) & (val >= 0) & (val <= MAX_ROIVAL))
89 {
90 printf ("# Set ROI %d to %d ->\n", num, val);
91 CMD_Buffer[0] = htons (CMD_Write | (BADDR_ROI + num));
92 CMD_Buffer[1] = htons (val);
93 printf ("# 0x%.4X 0x%.4X\n", ntohs (CMD_Buffer[0]), ntohs (CMD_Buffer[1]));
94 CMD_Num = 2;
95 }
96 else
97 {
98 printf ("Out of range\n");
99 printf ("Usage: sr NUM VAL: Set ROI NUM (0-%d) to VAL (0-%d)\n", MAX_ROINUM, MAX_ROIVAL);
100 }
101 }
102 else
103 {
104 printf ("Usage: sr NUM VAL: Set ROI NUM (0-%d) to VAL (0-%d)\n", MAX_ROINUM, MAX_ROIVAL);
105 }
106 }
107
108 // Set all ROIs
109 else if (strncmp (Buffer, "sra ", 4) == 0)
110 {
111 CMD_Num = 0;
112 if (sscanf (Buffer, "%4s %i", CMD_Str, &val) == 2)
113 {
114 if ((val >= 0) & (val <= MAX_ROIVAL))
115 {
116 printf ("# Set all ROIs to %d ->\n", val);
117 for (i = 0; i < (MAX_ROINUM + 1); i++)
118 {
119 CMD_Buffer[i * 2] = htons (CMD_Write | (BADDR_ROI + i));
120 CMD_Buffer[(i * 2) + 1] = htons (val);
121 CMD_Num += 2;
122 }
123 for (i = 0; i < ((MAX_ROINUM + 1) * 2); i += 8)
124 {
125 printf ("# 0x%.4X 0x%.4X 0x%.4X 0x%.4X 0x%.4X 0x%.4X 0x%.4X 0x%.4X\n",
126 ntohs (CMD_Buffer[i]), ntohs (CMD_Buffer[i + 1]),
127 ntohs (CMD_Buffer[i + 2]), ntohs (CMD_Buffer[i + 3]),
128 ntohs (CMD_Buffer[i + 4]), ntohs (CMD_Buffer[i + 5]),
129 ntohs (CMD_Buffer[i + 6]), ntohs (CMD_Buffer[i + 7]));
130 }
131 }
132 else
133 {
134 printf ("Out of range\n");
135 printf ("Usage: sra VAL: Set all ROIs to VAL (0-%d)\n", MAX_ROIVAL);
136 }
137 }
138 else
139 {
140 printf ("Usage: sra VAL: Set all ROIs to VAL (0-%d)\n", MAX_ROIVAL);
141 }
142 }
143
144 // Set DAC value
145 else if (strncmp (Buffer, "sd ", 3) == 0)
146 {
147 CMD_Num = 0;
148 if (sscanf (Buffer, "%3s %i %i", CMD_Str, &num, &val) == 3)
149 {
150 if ((num >= 0) & (num <= MAX_DACNUM) & (val >= 0) & (val <= MAX_DACVAL))
151 {
152 printf ("# Set DAC %d to %d ->\n", num, val);
153 CMD_Buffer[0] = htons (CMD_Write | (BADDR_DAC + num));
154 CMD_Buffer[1] = htons (val);
155 printf ("# 0x%.4X 0x%.4X\n", ntohs (CMD_Buffer[0]), ntohs (CMD_Buffer[1]));
156 CMD_Num = 2;
157 }
158 else
159 {
160 printf ("Out of range\n");
161 printf ("Usage: sd NUM VAL: Set DAC NUM (0-%d) to VAL (0-%d)\n", MAX_DACNUM, MAX_DACVAL);
162 }
163 }
164 else
165 {
166 printf ("Usage: sd NUM VAL: Set DAC NUM (0-%d) to VAL (0-%d)\n", MAX_DACNUM, MAX_DACVAL);
167 }
168 }
169
170 // Set address to value
171 else if (strncmp (Buffer, "sa ", 3) == 0)
172 {
173 CMD_Num = 0;
174 if (sscanf (Buffer, "%4s %i %i", CMD_Str, &num, &val) == 3)
175 {
176 if ((num >= 0) & (num <= MAX_ADDR) & (val >= 0) & (val <= MAX_VAL))
177 {
178 printf ("# Set ADDR %d to %d ->\n", num, val);
179 CMD_Buffer[0] = htons (CMD_Write | num);
180 CMD_Buffer[1] = htons (val);
181 printf ("# 0x%.4X 0x%.4X\n", ntohs (CMD_Buffer[0]), ntohs (CMD_Buffer[1]));
182 CMD_Num = 2;
183 }
184 else
185 {
186 printf ("Out of range\n");
187 printf ("Usage: sa NUM VAL: Set addr NUM (0-%d) to VAL (0-%d)\n", MAX_ADDR, MAX_VAL);
188 }
189 }
190 else
191 {
192 printf ("Usage: raw NUM VAL: Set addr NUM (0-%d) to VAL (0-%d)\n", MAX_ADDR, MAX_VAL);
193 }
194 }
195
196 // Send value
197 else if (strncmp (Buffer, "sv ", 3) == 0)
198 {
199 CMD_Num = 0;
200 if (sscanf (Buffer, "%4s %i", CMD_Str, &val) == 2)
201 {
202 if ((val >= 0) & (val <= MAX_VAL))
203 {
204 printf ("# Send %d ->\n", val);
205 CMD_Buffer[0] = htons (val);
206 printf ("# 0x%.4X\n", ntohs (CMD_Buffer[0]));
207 CMD_Num = 1;
208 }
209 else
210 {
211 printf ("Out of range\n");
212 printf ("Usage: sv VAL: Send VAL (0-%d)\n", MAX_VAL);
213 }
214 }
215 else
216 {
217 printf ("Usage: sv VAL: Send VAL (0-%d)\n", MAX_VAL);
218 }
219 }
220
221 else if (strncmp (Buffer, "q\n", 2) == 0)
222 {
223 // Exit program
224 printf ("# Quit\n");
225 exit_program (EXIT_SUCCESS);
226 }
227
228 // Anything else... , print help
229 else
230 {
231 printf ("Commands:\n");
232 printf (" r: Start Run -- TODO\n");
233 printf (" s: Stop Run -- TODO\n");
234 printf (" t: Single Trigger\n\n");
235 printf (" de: DENABLE HIGH\n");
236 printf (" dd: DENABLE LOW\n");
237 printf (" dr: DWRITE HIGH\n");
238 printf (" ds: DWRITE LOW\n\n");
239 printf (" tc: Continuous Trigger\n");
240 printf (" ts: Stop Trigger\n");
241 printf (" sr NUM VAL: Set ROI NUM (0-35) to VAL (0-1024)\n");
242 printf (" sra VAL: Set all ROIs to VAL (0-1024)\n");
243 printf (" sd NUM VAL: Set DAC NUM (0-7) to VAL (0-65535)\n");
244 printf (" q: Quit\n");
245 printf ("\n");
246 printf (" Only for debugging:\n");
247 printf (" sa NUM VAL: Set addr NUM (0-255) to VAL (0-65535)\n");
248 printf (" sv VAL: Send VAL\n");
249 printf (" sz: Send 0x0000\n");
250 printf ("\n");
251
252 CMD_Num = 0;
253 }
254
255 // Send commands
256 if (CMD_Num > 0)
257 {
258 if (write (Socket, CMD_Buffer, CMD_Num * sizeof (short)) < 1)
259 {
260 printf ("Error: could not write to socket\n");
261 }
262 }
263}
264
Note: See TracBrowser for help on using the repository browser.