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

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