API
ocamUtils.hpp
Go to the documentation of this file.
1 /** \file ocamUtils.hpp
2  * \brief Utilities for the OCAM camera
3  *
4  * \ingroup ocam2kCtrl_files
5  */
6 
7 #ifndef ocamUtils_hpp
8 #define ocamUtils_hpp
9 
10 
11 #include <mx/ioutils/stringUtils.hpp>
12 
13 namespace MagAOX
14 {
15 namespace app
16 {
17 
18 /// Structure to hold the OCAM camera temperature readings returned by the device.
19 struct ocamTemps
20 {
21  float CCD {0}; ///< The detector temperature.
22  float CPU {0}; ///< The CPU temperature
23  float POWER {0}; ///< Power supply temperature
24  float BIAS {0}; ///< Bias temperature
25  float WATER {0}; ///< Cooling water temperature
26  float LEFT {0}; ///< The left amplifier temperature
27  float RIGHT {0}; ///< The right amplifier temperature
28  float SET {0}; ///< The CCD set temeperature
29  float COOLING_POWER {0}; ///< the cooling power in 100 mw.
30 
31  ///Test for equality between two ocamTemps structures
32  /**
33  * \returns true if all members are equal
34  * \returns false otherwise
35  */
36  bool operator==(const ocamTemps & t /**< [in] the struct to compare to*/)
37  {
38  return (CCD == t.CCD && POWER == t.POWER && BIAS == t.BIAS && WATER == t.WATER && LEFT == t.LEFT && RIGHT == t.RIGHT && SET == t.SET &&
40  }
41 
42  ///Set all values to the invalid value, -999.
43  int setInvalid()
44  {
45  CCD = -999;
46  CPU = -999;
47  POWER = -999;
48  BIAS = -999;
49  WATER = -999;
50  LEFT = -999;
51  RIGHT = -999;
52  SET = -999;
53  COOLING_POWER = -999;
54 
55  return 0;
56  }
57 };
58 
59 ///Parse the OCAM temp query and fill the ocamTemps structure.
60 /**
61  * \returns 0 on success
62  * \returns -1 on error
63  */
64 int parseTemps( ocamTemps & temps, ///< [out] the struture of temperature readings
65  const std::string & tstr ///< [in] the device response to parse.
66  )
67 {
68  std::vector<std::string> v;
69  mx::ioutils::parseStringVector(v, tstr, "[]");
70 
71  if( v.size() < 18) return -1;
72 
73  temps.CCD = mx::ioutils::convertFromString<float>( v[1] );
74  temps.CPU = mx::ioutils::convertFromString<float>( v[3] );
75  temps.POWER = mx::ioutils::convertFromString<float>( v[5] );
76  temps.BIAS = mx::ioutils::convertFromString<float>( v[7] );
77  temps.WATER = mx::ioutils::convertFromString<float>( v[9] );
78  temps.LEFT = mx::ioutils::convertFromString<float>( v[11] );
79  temps.RIGHT = mx::ioutils::convertFromString<float>( v[13] );
80  temps.SET = mx::ioutils::convertFromString<float>( v[15] )/10.0;
81  temps.COOLING_POWER = mx::ioutils::convertFromString<float>( v[17] );
82 
83  return 0;
84 }
85 
86 /// Parse the FPS response
87 /** Parses the OCAM 2K response to the "fps" query.
88  *
89  * \returns 0 on success
90  * \returns -1 on error
91  *
92  * \todo add test for FPS
93  */
94 int parseFPS( float & fps, ///< [out] the fps returned by the camera
95  const std::string & fstr ///< [in] the response to parse
96  )
97 {
98  std::vector<std::string> v;
99  mx::ioutils::parseStringVector(v, fstr, "[]");
100 
101  if( v.size() < 3) return -1;
102 
103  fps = mx::ioutils::convertFromString<float>( v[1] );
104 
105  return 0;
106 }
107 
108 /// Parse the EM gain response
109 /** Example response: "Gain set to 2 \n\n", with the trailing space.
110  * Expects gain >=1 and <= 600, otherwise returns an error.
111  *
112  * \returns 0 on success, and emGain set to a value >= 1
113  * \returns -1 on error, and emGain will be set to 0.
114  */
115 int parseEMGain( unsigned & emGain, ///< [out] the value of gain returned by the camera
116  const std::string & fstr ///< [in] the query response from the camera.
117  )
118 {
119  std::vector<std::string> v;
120  mx::ioutils::parseStringVector(v, fstr, " ");
121 
122  if( v.size() != 5)
123  {
124  emGain = 0;
125  return -1;
126  }
127 
128  emGain = mx::ioutils::convertFromString<unsigned>( v[3] );
129 
130  if(emGain < 1 || emGain > 600)
131  {
132  emGain = 0;
133  return -1;
134  }
135 
136  return 0;
137 }
138 
139 } //namespace app
140 } //namespace MagAOX
141 
142 #endif //ocamUtils_hpp
int parseFPS(float &fps, const std::string &fstr)
Parse the FPS response.
Definition: ocamUtils.hpp:94
int parseTemps(ocamTemps &temps, const std::string &tstr)
Parse the OCAM temp query and fill the ocamTemps structure.
Definition: ocamUtils.hpp:64
int parseEMGain(unsigned &emGain, const std::string &fstr)
Parse the EM gain response.
Definition: ocamUtils.hpp:115
Definition: dm.hpp:24
Structure to hold the OCAM camera temperature readings returned by the device.
Definition: ocamUtils.hpp:20
float WATER
Cooling water temperature.
Definition: ocamUtils.hpp:25
int setInvalid()
Set all values to the invalid value, -999.
Definition: ocamUtils.hpp:43
float COOLING_POWER
the cooling power in 100 mw.
Definition: ocamUtils.hpp:29
float BIAS
Bias temperature.
Definition: ocamUtils.hpp:24
bool operator==(const ocamTemps &t)
Test for equality between two ocamTemps structures.
Definition: ocamUtils.hpp:36
float SET
The CCD set temeperature.
Definition: ocamUtils.hpp:28
float CCD
The detector temperature.
Definition: ocamUtils.hpp:21
float POWER
Power supply temperature.
Definition: ocamUtils.hpp:23
float CPU
The CPU temperature.
Definition: ocamUtils.hpp:22
float LEFT
The left amplifier temperature.
Definition: ocamUtils.hpp:26
float RIGHT
The right amplifier temperature.
Definition: ocamUtils.hpp:27