LCOV - code coverage report
Current view: top level - apps/ocam2KCtrl - ocamUtils.hpp (source / functions) Coverage Total Hit
Test: MagAOX Lines: 77.8 % 36 28
Test Date: 2026-01-03 21:03:39 Functions: 66.7 % 3 2

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

Generated by: LCOV version 2.0-1