API
siglentSDG_parsers.hpp
Go to the documentation of this file.
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 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  std::vector<std::string> v;
27 
28  mx::ioutils::parseStringVector(v, strRead, ":, \n");
29 
30  channel = -1;
31  output = -1;
32  if(v.size() < 2) return -1;
33 
34  if(v[1] != "OUTP") return -2;
35 
36  if(v[0][0] != 'C') return -3;
37  if(v[0].size() < 2) return -4;
38  channel = mx::ioutils::convertFromString<int>(v[0].substr(1, v[0].size()-1));
39 
40  if(v.size() < 3) return -5;
41 
42  if(v[2] == "OFF") output = 0;
43  else if(v[2] == "ON") output = 1;
44  else return -6;
45  return 0;
46 }
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 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  channel = 0;
75  freq = 0;
76  peri = 0;
77  amp = 0;
78  ampvrms = 0;
79  ofst = 0;
80  hlev = 0;
81  llev = 0;
82  phse = 0;
83  wdth = 0;
84 
85  std::vector<std::string> v;
86 
87  mx::ioutils::parseStringVector(v, strRead, ":, \n");
88  //std::cout << strRead << "\n";
89 
90  if(v.size() < 4) return -1; //We need to get to at least the WVTP parameter.
91 
92  if(v[1] != "BSWV") return -2;
93 
94  if(v[0][0] != 'C') return -3;
95  if(v[0].size() < 2) return -4;
96  channel = mx::ioutils::convertFromString<int>(v[0].substr(1, v[0].size()-1));
97 
98  if(v[2] != "WVTP") return -5;
99  wvtp = v[3];
100 
101  if(wvtp != "SINE" && wvtp != "PULSE" && wvtp != "DC") return SDG_PARSEERR_WVTP; //We don't actually know how to handle anything else.
102 
103  if(wvtp == "DC")
104  {
105  if(v.size() < 6) return -7;
106 
107  if(v[4] != "OFST") return -8;
108 
109  ofst = mx::ioutils::convertFromString<double>(v[5]);
110 
111  return 0;
112  }
113 
114  if(v.size() < 20) return -9;
115 
116  if(v[4] != "FRQ") return -10;
117  freq = mx::ioutils::convertFromString<double>(v[5]);
118 
119  if(v[6] != "PERI") return -11;
120  peri = mx::ioutils::convertFromString<double>(v[7]);
121 
122  if(v[8] != "AMP") return -12;
123  amp = mx::ioutils::convertFromString<double>(v[9]);
124 
125  if(v[10] != "AMPVRMS") return -13;
126  ampvrms = mx::ioutils::convertFromString<double>(v[11]);
127 
128  if(v[12] != "OFST") return -14;
129  ofst = mx::ioutils::convertFromString<double>(v[13]);
130 
131  if(v[14] != "HLEV") return -15;
132  hlev = mx::ioutils::convertFromString<double>(v[15]);
133 
134  if(v[16] != "LLEV") return -16;
135  llev = mx::ioutils::convertFromString<double>(v[17]);
136 
137  if(wvtp == "SINE")
138  {
139  if(v[18] != "PHSE") return -17;
140  phse = mx::ioutils::convertFromString<double>(v[19]);
141  }
142 
143  if(wvtp == "PULSE")
144  {
145  if(v[20] != "WIDTH") return -18;
146  wdth = mx::ioutils::convertFromString<double>(v[21]);
147  }
148 
149  return 0;
150 }
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 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  channel = 0;
167 
168  std::vector<std::string> v;
169 
170  mx::ioutils::parseStringVector(v, strRead, ":, \n");
171 
172 
173  if(v.size() < 4) return -1;
174 
175  if(v[1] != "MDWV") return -2;
176 
177  if(v[0][0] != 'C') return -3;
178  channel = mx::ioutils::convertFromString<int>(v[0].substr(1, v[0].size()-1));
179 
180  if(v[2] != "STATE") return -4;
181  state = v[3];
182 
183  return 0;
184 }
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 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  channel = 0;
201 
202  std::vector<std::string> v;
203 
204  mx::ioutils::parseStringVector(v, strRead, ":, \n");
205 
206 
207  if(v.size() < 4) return -1;
208 
209  if(v[1] != "SWWV") return -2;
210 
211  if(v[0][0] != 'C') return -3;
212  channel = mx::ioutils::convertFromString<int>(v[0].substr(1, v[0].size()-1));
213 
214  if(v[2] != "STATE") return -4;
215  state = v[3];
216 
217  return 0;
218 }
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 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  channel = 0;
235 
236  std::vector<std::string> v;
237 
238  mx::ioutils::parseStringVector(v, strRead, ":, \n");
239 
240 
241  if(v.size() < 4) return -1;
242 
243  if(v[1] != "BTWV") return -2;
244 
245  if(v[0][0] != 'C') return -3;
246  channel = mx::ioutils::convertFromString<int>(v[0].substr(1, v[0].size()-1));
247 
248  if(v[2] != "STATE") return -4;
249  state = v[3];
250 
251  return 0;
252 }
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 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  channel = 0;
268  index = -1;
269 
270  std::vector<std::string> v;
271 
272  mx::ioutils::parseStringVector(v, strRead, ":, \n");
273 
274 
275  if(v.size() < 4) return -1;
276 
277  if(v[1] != "ARWV") return -2;
278 
279  if(v[0][0] != 'C') return -3;
280  channel = mx::ioutils::convertFromString<int>(v[0].substr(1, v[0].size()-1));
281 
282  if(v[2] != "INDEX") return -4;
283  index = mx::ioutils::convertFromString<int>(v[3]);
284 
285  return 0;
286 }
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 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  channel = 0;
302 
303  sync = false;
304 
305  std::vector<std::string> v;
306 
307  mx::ioutils::parseStringVector(v, strRead, ":, \n");
308 
309 
310  if(v.size() < 3) return -1;
311 
312  if(v[1] != "SYNC") return -2;
313 
314  if(v[0][0] != 'C') return -3;
315  channel = mx::ioutils::convertFromString<int>(v[0].substr(1, v[0].size()-1));
316 
317  if(v[2] == "ON")
318  {
319  sync = true;
320  return 0;
321  }
322  else if(v[2] == "OFF")
323  {
324  sync = false;
325  return 0;
326  }
327  else return -4;
328 
329  return 0;
330 }
331 
332 } //namespace app
333 } //namespace MagAOX
334 
335 #endif //siglentSDG_hpp
int parseOUTP(int &channel, int &output, const std::string &strRead)
Parse the SDG response to the OUTP query.
int parseSWWV(int &channel, std::string &state, const std::string &strRead)
Parse the SDG response to the SWWV query.
int parseMDWV(int &channel, std::string &state, const std::string &strRead)
Parse the SDG response to the MDWV query.
int parseBSWV(int &channel, std::string &wvtp, double &freq, double &peri, double &amp, double &ampvrms, double &ofst, double &hlev, double &llev, double &phse, double &wdth, const std::string &strRead)
Parse the SDG response to the BSWV query.
int parseBTWV(int &channel, std::string &state, const std::string &strRead)
Parse the SDG response to the BTWV query.
int parseARWV(int &channel, int &index, const std::string &strRead)
Parse the SDG response to the ARWV query.
int parseSYNC(int &channel, bool &sync, const std::string &strRead)
Parse the SDG response to the SYNC query.
Definition: dm.hpp:24
#define SDG_PARSEERR_WVTP