Line data Source code
1 :
2 :
3 : #ifndef siglentSDG_parsers_hpp
4 : #define siglentSDG_parsers_hpp
5 :
6 :
7 : #include <mx/ioutils/stringUtils.hpp>
8 :
9 : namespace MagAOX
10 : {
11 : namespace app
12 : {
13 :
14 : /// Parse the SDG response to the OUTP query
15 : /**
16 : * Example: C1:OUTP OFF,LOAD,HZ,PLRT,NOR
17 : *
18 : * \returns 0 on success
19 : * \returns \<0 on error, with value indicating location of error.
20 : */
21 7 : int parseOUTP( int & channel, ///< [out] the channel indicated by this response.
22 : int & output, ///< [out] the output status of the channel, ON or OFF
23 : const std::string & strRead ///< [in] string containing the device response
24 : )
25 : {
26 7 : std::vector<std::string> v;
27 :
28 7 : mx::ioutils::parseStringVector(v, strRead, ":, \n");
29 :
30 7 : channel = -1;
31 7 : output = -1;
32 7 : if(v.size() < 2) return -1;
33 :
34 6 : if(v[1] != "OUTP") return -2;
35 :
36 4 : if(v[0][0] != 'C') return -3;
37 4 : if(v[0].size() < 2) return -4;
38 4 : channel = mx::ioutils::convertFromString<int>(v[0].substr(1, v[0].size()-1));
39 :
40 4 : if(v.size() < 3) return -5;
41 :
42 4 : if(v[2] == "OFF") output = 0;
43 3 : else if(v[2] == "ON") output = 1;
44 1 : else return -6;
45 3 : return 0;
46 7 : }
47 :
48 : #define SDG_PARSEERR_WVTP (-6)
49 :
50 : /// Parse the SDG response to the BSWV query
51 : /**
52 : * Example: C1:BSWV WVTP,SINE,FRQ,10HZ,PERI,0.1S,AMP,2V,AMPVRMS,0.707Vrms,OFST,0V,HLEV,1V,LLEV,-1V,PHSE,0
53 : *
54 : * \todo document tests
55 : * \todo update tests for new wdth parameter in PULSE
56 : *
57 : * \returns 0 on success
58 : * \returns \<0 on error, with value indicating location of error.
59 : */
60 15 : int parseBSWV( int & channel, ///< [out] the channel indicated by this response.
61 : std::string & wvtp,
62 : double & freq,
63 : double & peri,
64 : double & amp,
65 : double & ampvrms,
66 : double & ofst,
67 : double & hlev,
68 : double & llev,
69 : double & phse,
70 : double & wdth,
71 : const std::string & strRead ///< [in] string containing the device response
72 : )
73 : {
74 15 : channel = 0;
75 15 : freq = 0;
76 15 : peri = 0;
77 15 : amp = 0;
78 15 : ampvrms = 0;
79 15 : ofst = 0;
80 15 : hlev = 0;
81 15 : llev = 0;
82 15 : phse = 0;
83 15 : wdth = 0;
84 :
85 15 : std::vector<std::string> v;
86 :
87 15 : mx::ioutils::parseStringVector(v, strRead, ":, \n");
88 : //std::cout << strRead << "\n";
89 :
90 15 : if(v.size() < 4) return -1; //We need to get to at least the WVTP parameter.
91 :
92 14 : if(v[1] != "BSWV") return -2;
93 :
94 13 : if(v[0][0] != 'C') return -3;
95 12 : if(v[0].size() < 2) return -4;
96 11 : channel = mx::ioutils::convertFromString<int>(v[0].substr(1, v[0].size()-1));
97 :
98 11 : if(v[2] != "WVTP") return -5;
99 10 : wvtp = v[3];
100 :
101 10 : if(wvtp != "SINE" && wvtp != "PULSE" && wvtp != "DC") return SDG_PARSEERR_WVTP; //We don't actually know how to handle anything else.
102 :
103 9 : if(wvtp == "DC")
104 : {
105 0 : if(v.size() < 6) return -7;
106 :
107 0 : if(v[4] != "OFST") return -8;
108 :
109 0 : ofst = mx::ioutils::convertFromString<double>(v[5]);
110 :
111 0 : return 0;
112 : }
113 :
114 9 : if(v.size() < 20) return -9;
115 :
116 9 : if(v[4] != "FRQ") return -10;
117 8 : freq = mx::ioutils::convertFromString<double>(v[5]);
118 :
119 8 : if(v[6] != "PERI") return -11;
120 7 : peri = mx::ioutils::convertFromString<double>(v[7]);
121 :
122 7 : if(v[8] != "AMP") return -12;
123 6 : amp = mx::ioutils::convertFromString<double>(v[9]);
124 :
125 6 : if(v[10] != "AMPVRMS") return -13;
126 5 : ampvrms = mx::ioutils::convertFromString<double>(v[11]);
127 :
128 5 : if(v[12] != "OFST") return -14;
129 4 : ofst = mx::ioutils::convertFromString<double>(v[13]);
130 :
131 4 : if(v[14] != "HLEV") return -15;
132 3 : hlev = mx::ioutils::convertFromString<double>(v[15]);
133 :
134 3 : if(v[16] != "LLEV") return -16;
135 2 : llev = mx::ioutils::convertFromString<double>(v[17]);
136 :
137 2 : if(wvtp == "SINE")
138 : {
139 2 : if(v[18] != "PHSE") return -17;
140 1 : phse = mx::ioutils::convertFromString<double>(v[19]);
141 : }
142 :
143 1 : if(wvtp == "PULSE")
144 : {
145 0 : if(v[20] != "WIDTH") return -18;
146 0 : wdth = mx::ioutils::convertFromString<double>(v[21]);
147 : }
148 :
149 1 : return 0;
150 15 : }
151 :
152 : /// Parse the SDG response to the MDWV query
153 : /** Currently we are only looking for STATE,ON or STATE,OFF. If ON,
154 : * we ignore the rest of the values.
155 : *
156 : * Example: C1:MDWV STATE,OFF
157 : *
158 : * \returns 0 on success
159 : * \returns \<0 on error, with value indicating location of error.
160 : */
161 7 : int parseMDWV( int & channel, ///< [out] the channel indicated by this response.
162 : std::string & state, ///< [out] the MDWV state of the channel, ON or OFF
163 : const std::string & strRead ///< [in] string containing the device response
164 : )
165 : {
166 7 : channel = 0;
167 :
168 7 : std::vector<std::string> v;
169 :
170 7 : mx::ioutils::parseStringVector(v, strRead, ":, \n");
171 :
172 :
173 7 : if(v.size() < 4) return -1;
174 :
175 6 : if(v[1] != "MDWV") return -2;
176 :
177 5 : if(v[0][0] != 'C') return -3;
178 4 : channel = mx::ioutils::convertFromString<int>(v[0].substr(1, v[0].size()-1));
179 :
180 4 : if(v[2] != "STATE") return -4;
181 3 : state = v[3];
182 :
183 3 : return 0;
184 7 : }
185 :
186 : /// Parse the SDG response to the SWWV query
187 : /** Currently we are only looking for STATE,ON or STATE,OFF. If ON,
188 : * we ignore the rest of the values.
189 : *
190 : * Example: C1:SWWV STATE,OFF
191 : *
192 : * \returns 0 on success
193 : * \returns \<0 on error, with value indicating location of error.
194 : */
195 7 : int parseSWWV( int & channel, ///< [out] the channel indicated by this response.
196 : std::string & state, ///< [out] the SWWV state of the channel, ON or OFF
197 : const std::string & strRead ///< [in] string containing the device response
198 : )
199 : {
200 7 : channel = 0;
201 :
202 7 : std::vector<std::string> v;
203 :
204 7 : mx::ioutils::parseStringVector(v, strRead, ":, \n");
205 :
206 :
207 7 : if(v.size() < 4) return -1;
208 :
209 6 : if(v[1] != "SWWV") return -2;
210 :
211 5 : if(v[0][0] != 'C') return -3;
212 4 : channel = mx::ioutils::convertFromString<int>(v[0].substr(1, v[0].size()-1));
213 :
214 4 : if(v[2] != "STATE") return -4;
215 3 : state = v[3];
216 :
217 3 : return 0;
218 7 : }
219 :
220 : /// Parse the SDG response to the BTWV query
221 : /** Currently we are only looking for STATE,ON or STATE,OFF. If ON,
222 : * we ignore the rest of the values.
223 : *
224 : * Example: C1:BTWV STATE,OFF
225 : *
226 : * \returns 0 on success
227 : * \returns \<0 on error, with value indicating location of error.
228 : */
229 7 : int parseBTWV( int & channel, ///< [out] the channel indicated by this response.
230 : std::string & state, ///< [out] the BTWV state of the channel, ON or OFF
231 : const std::string & strRead ///< [in] string containing the device response
232 : )
233 : {
234 7 : channel = 0;
235 :
236 7 : std::vector<std::string> v;
237 :
238 7 : mx::ioutils::parseStringVector(v, strRead, ":, \n");
239 :
240 :
241 7 : if(v.size() < 4) return -1;
242 :
243 6 : if(v[1] != "BTWV") return -2;
244 :
245 5 : if(v[0][0] != 'C') return -3;
246 4 : channel = mx::ioutils::convertFromString<int>(v[0].substr(1, v[0].size()-1));
247 :
248 4 : if(v[2] != "STATE") return -4;
249 3 : state = v[3];
250 :
251 3 : return 0;
252 7 : }
253 :
254 : /// Parse the SDG response to the ARWV query
255 : /** Currently we are only looking for INDEX,0
256 : *
257 : * Example: C1:ARWV INDEX,0,NAME,
258 : *
259 : * \returns 0 on success
260 : * \returns \<0 on error, with value indicating location of error.
261 : */
262 7 : int parseARWV( int & channel, ///< [out] the channel indicated by this response.
263 : int & index, ///< [out] the ARWV index of the channel. Should be 0.
264 : const std::string & strRead ///< [in] string containing the device response
265 : )
266 : {
267 7 : channel = 0;
268 7 : index = -1;
269 :
270 7 : std::vector<std::string> v;
271 :
272 7 : mx::ioutils::parseStringVector(v, strRead, ":, \n");
273 :
274 :
275 7 : if(v.size() < 4) return -1;
276 :
277 6 : if(v[1] != "ARWV") return -2;
278 :
279 5 : if(v[0][0] != 'C') return -3;
280 4 : channel = mx::ioutils::convertFromString<int>(v[0].substr(1, v[0].size()-1));
281 :
282 4 : if(v[2] != "INDEX") return -4;
283 3 : index = mx::ioutils::convertFromString<int>(v[3]);
284 :
285 3 : return 0;
286 7 : }
287 :
288 : /// Parse the SDG response to the SYNC query
289 : /**
290 : *
291 : * Example: C1:SYNC ON
292 : *
293 : * \returns 0 on success
294 : * \returns \<0 on error, with value indicating location of error.
295 : */
296 0 : int parseSYNC( int & channel, ///< [out] the channel indicated by this response.
297 : bool & sync, ///< [out] the ARWV index of the channel. Should be 0.
298 : const std::string & strRead ///< [in] string containing the device response
299 : )
300 : {
301 0 : channel = 0;
302 :
303 0 : sync = false;
304 :
305 0 : std::vector<std::string> v;
306 :
307 0 : mx::ioutils::parseStringVector(v, strRead, ":, \n");
308 :
309 :
310 0 : if(v.size() < 3) return -1;
311 :
312 0 : if(v[1] != "SYNC") return -2;
313 :
314 0 : if(v[0][0] != 'C') return -3;
315 0 : channel = mx::ioutils::convertFromString<int>(v[0].substr(1, v[0].size()-1));
316 :
317 0 : if(v[2] == "ON")
318 : {
319 0 : sync = true;
320 0 : return 0;
321 : }
322 0 : else if(v[2] == "OFF")
323 : {
324 0 : sync = false;
325 0 : return 0;
326 : }
327 0 : else return -4;
328 :
329 : return 0;
330 0 : }
331 :
332 : } //namespace app
333 : } //namespace MagAOX
334 :
335 : #endif //siglentSDG_hpp
|