diff --git a/include/timiq/TIMIQLib.h b/include/timiq/TIMIQLib.h index 23bd1a5d587e59aa4dafc998e13cf04aee9b9f29..695526f539e25af3349d7e7959f74e6b781bf287 100644 --- a/include/timiq/TIMIQLib.h +++ b/include/timiq/TIMIQLib.h @@ -26,7 +26,7 @@ // via a http web protocol. // =========================================================================== -namespace TIMIQLib_ns { +namespace TIMIQLib_ns { //------------------------------------------------------------------------ // Class Description: @@ -36,7 +36,7 @@ class ThreadedAction : public yat::Thread { friend class TIMIQLib; - protected: + protected: //- ctor --------------------------------- ThreadedAction(yat::Thread::IOArg ioa, timIQConfig& cfg); @@ -81,6 +81,7 @@ class ThreadedAction : public yat::Thread //----------------------------- class TIMIQCurl; + //------------------------------------------------------------------------ //- TIMIQProxy Class //- Ensures the interface of the timIQ equipment with @@ -91,7 +92,7 @@ class TIMIQLib friend class ThreadedAction; public: - + // Contructor TIMIQLib(); @@ -157,6 +158,12 @@ class TIMIQLib void get_boardTemperature(float& boardTemperature) throw (Exception); + // Gets the whole data from TimIQ equipment + // i.e. temperature, i & q values, mixer values + // @param [out] val Read values. + void get_boardData(timIQval_t& val) + throw (Exception); + // Gets state of TimIQ equipment // @param [out] status string E_timiq_code_t get_state(std::string& status) @@ -168,7 +175,7 @@ class TIMIQLib throw (Exception); private: - + //- internal members //-------------------------- TIMIQCurl * m_timiq_hw; @@ -184,7 +191,7 @@ class TIMIQLib protected: - + //- internal functions //------------------------- @@ -192,18 +199,13 @@ class TIMIQLib ThreadedAction * m_timiq_task; // execute action specified in argument - void ExecuteAction(timIQConfig & cfg) + void ExecuteAction(timIQConfig & cfg) throw (Exception); // end of task notification void end_task() throw (Exception); - // soso à supprimer: - void iVal_end_task() throw (Exception); - void qVal_end_task() throw (Exception); - void data_end_task() throw (Exception); - void boardT_end_task() throw (Exception); }; } // namespace TIMIQLib_ns diff --git a/pom.xml b/pom.xml index 287929cea5e9b091380a552912df07b58f1f6287..6b2a06e0290067d7b3755da8de689e0417027177 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ </parent> <groupId>fr.soleil.lib</groupId> <artifactId>TimIQLib-${aol}-${library}-${mode}</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.0.0</version> <packaging>nar</packaging> <name>TimIQ</name> <description>TimIQ library</description> @@ -52,7 +52,6 @@ <dependency> <groupId>se.haxx.lib</groupId> <artifactId>curl-i386-Linux-gcc-static-release</artifactId> - <!--<version>7.37.0</version> Already official release version--> </dependency> </dependencies> <developers> diff --git a/src/TIMIQCurl.cpp b/src/TIMIQCurl.cpp index 1d26d25a01112a6b2f0aee8ba7c7441dab722f16..6dc25403306c75bc0821bd5fc6e6abfdd0bf765a 100644 --- a/src/TIMIQCurl.cpp +++ b/src/TIMIQCurl.cpp @@ -33,7 +33,7 @@ static size_t write_callback( char *buffer, size_t size, size_t nmemb, void* ) // std::cout<<"static size_t write_callback <"<<size<<"> nmemb<"<<nmemb<<">"<<std::endl; for (size_t idx = 0; idx < size*nmemb; idx++ ) m_timiq_internal_buff.push_back(buffer[idx]); - + return size*nmemb; } @@ -46,11 +46,18 @@ TIMIQCurl::TIMIQCurl(const std::string& ip_address, const std::string& num_port) m_base_addr = kHTTP_WEB_PROTOCOL + ip_address + ":"+ num_port; m_error_string = ""; - + +#if !defined (_SIMULATION_) m_hw_curl = NULL; m_thr_hw_curl = NULL; curl_global_init(CURL_GLOBAL_ALL); +#endif + +#if defined (_SIMULATION_) + m_sim_ival = 0.0; + m_sim_qval = 0.0; +#endif } // ============================================================================ @@ -58,6 +65,7 @@ TIMIQCurl::TIMIQCurl(const std::string& ip_address, const std::string& num_port) // ============================================================================ TIMIQCurl::~TIMIQCurl () { +#if !defined (_SIMULATION_) if (m_hw_curl) { //- clean up @@ -71,8 +79,9 @@ TIMIQCurl::~TIMIQCurl () curl_easy_cleanup(m_thr_hw_curl); m_thr_hw_curl = NULL; } - + curl_global_cleanup(); +#endif } // ============================================================================ @@ -102,7 +111,7 @@ E_timiq_errno_t TIMIQCurl::write_data(float& data) // ============================================================================ E_timiq_errno_t TIMIQCurl::write_iValue(float& iValue) { - std::cout << "TIMIQCurl::write_iValue() write iValue = " << iValue << std::endl; // soso traces + // std::cout << "TIMIQCurl::write_iValue() write iValue = " << iValue << std::endl; E_timiq_errno_t err_num = timiq_internal_ERROR; char buff[kMAX_DATA_SIZE]; @@ -117,6 +126,9 @@ E_timiq_errno_t TIMIQCurl::write_iValue(float& iValue) if (this->write_i(str_url, strbuff)) err_num = timiq_NO_ERROR; +#if defined (_SIMULATION_) + m_sim_ival = iValue; +#endif return err_num; } @@ -124,8 +136,8 @@ E_timiq_errno_t TIMIQCurl::write_iValue(float& iValue) // TIMIQCurl::write_qValue // ============================================================================ E_timiq_errno_t TIMIQCurl::write_qValue(float& qValue) -{ -std::cout << "TIMIQCurl::write_qValue() write qValue = " << qValue << std::endl; // soso traces +{ + //std::cout << "TIMIQCurl::write_qValue() write qValue = " << qValue << std::endl; E_timiq_errno_t err_num = timiq_internal_ERROR; char buff[kMAX_DATA_SIZE]; @@ -140,6 +152,9 @@ std::cout << "TIMIQCurl::write_qValue() write qValue = " << qValue << std::endl; if (this->write_i(str_url, strbuff)) err_num = timiq_NO_ERROR; +#if defined (_SIMULATION_) + m_sim_qval = qValue; +#endif return err_num; } @@ -184,6 +199,10 @@ E_timiq_errno_t TIMIQCurl::write_command(E_timiq_cmd_t& cmd, bool thr) if (this->write_i(str_url, strbuff, thr)) err_num = timiq_NO_ERROR; +#if defined (_SIMULATION_) + m_sim_ival = 0.0; + m_sim_qval = 0.0; +#endif return err_num; } @@ -289,6 +308,23 @@ E_timiq_errno_t TIMIQCurl::read_boardTemperature(float& boardTemperature) return err_num; } +// ============================================================================ +// TIMIQCurl::read_all +// ============================================================================ +E_timiq_errno_t TIMIQCurl::read_all(timIQval_t& val) +{ + E_timiq_errno_t err_num = timiq_internal_ERROR; + + //- request to the web page + //- http://address/get_feedback.wsgi + std::string str_url = m_base_addr + kTIMIQ_FEEDBACK_PAGE; + + if (this->read_all_i(str_url, val)) + err_num = timiq_NO_ERROR; + + return err_num; +} + // ============================================================================ // TIMIQCurl::read_state_and_status // ============================================================================ @@ -313,11 +349,12 @@ E_timiq_errno_t TIMIQCurl::connect_i(bool thr) { E_timiq_errno_t err_num = timiq_internal_ERROR; m_error_string = ""; - + +#if !defined (_SIMULATION_) // according to flag, initialize "standard" or "threaded" curl reference - if (thr) - { - // use threaded reference + if (thr) + { + // use threaded reference try { if (!m_thr_hw_curl) @@ -345,11 +382,11 @@ E_timiq_errno_t TIMIQCurl::connect_i(bool thr) { m_error_string = "TIMIQCurl::connect: exception while initializing Webserver for threaded ref..."; m_thr_hw_curl = NULL; - } + } } - else - { - // use non threaded reference + else + { + // use non threaded reference try { if (!m_hw_curl) @@ -377,10 +414,13 @@ E_timiq_errno_t TIMIQCurl::connect_i(bool thr) { m_error_string = "TIMIQCurl::connect: exception while initializing Webserver for standard ref..."; m_hw_curl = NULL; - } + } } - + return err_num; +#else + return timiq_NO_ERROR; +#endif } // ============================================================================ @@ -388,12 +428,12 @@ E_timiq_errno_t TIMIQCurl::connect_i(bool thr) // ============================================================================ bool TIMIQCurl::write_i(std::string& url, std::string& strData, bool thr) { +#if !defined (_SIMULATION_) //- CURL easy return code CURLcode result; m_error_string = ""; -#if !defined (_SIMULATION_) //- no connection is possible if (this->connect_i(thr) != timiq_NO_ERROR) return false; @@ -419,14 +459,6 @@ bool TIMIQCurl::write_i(std::string& url, std::string& strData, bool thr) else //- check the data returned { -#else - m_timiq_internal_buff = "\ncommand=1\n"; - m_timiq_internal_buff += "command=2\n"; - m_timiq_internal_buff += "command=3\n"; - m_timiq_internal_buff += "iValue=-0.000001\n"; - m_timiq_internal_buff += "qValue=-0.000002"; -#endif - std::size_t found = m_timiq_internal_buff.find(strData); if (found != std::string::npos) { @@ -438,11 +470,18 @@ bool TIMIQCurl::write_i(std::string& url, std::string& strData, bool thr) //- otherwise error m_error_string = m_timiq_internal_buff; } -#if !defined (_SIMULATION_) } -#endif - return false; + +#else + m_error_string = "OK"; + m_timiq_internal_buff = "\ncommand=1\n"; + m_timiq_internal_buff += "command=2\n"; + m_timiq_internal_buff += "command=3\n"; + m_timiq_internal_buff += "iValue=-0.000001\n"; + m_timiq_internal_buff += "qValue=-0.000002"; + return true; +#endif } // ============================================================================ @@ -451,12 +490,12 @@ bool TIMIQCurl::write_i(std::string& url, std::string& strData, bool thr) bool TIMIQCurl::read_float_i(const std::string& url, const std::string& strData, float& value) { // std::cout <<"TIMIQCurl::read_float_i"<<std::endl; +#if !defined (_SIMULATION_) //- CURL easy return code CURLcode result; m_error_string = ""; -#if !defined (_SIMULATION_) //- no connection is possible if (this->connect_i() != timiq_NO_ERROR) return false; @@ -528,7 +567,7 @@ bool TIMIQCurl::read_float_i(const std::string& url, const std::string& strData, m_error_string = m_timiq_internal_buff; #if !defined (_SIMULATION_) } -#endif +#endif return false; } @@ -538,12 +577,12 @@ bool TIMIQCurl::read_float_i(const std::string& url, const std::string& strData, // ============================================================================ bool TIMIQCurl::read_state_and_status_i(const std::string& url, std::string& status, E_timiq_code_t& codeRet) { +#if !defined (_SIMULATION_) //- CURL easy return code CURLcode result; m_error_string = ""; -#if !defined (_SIMULATION_) //- no connection is possible if (this->connect_i() != timiq_NO_ERROR) return false; @@ -614,7 +653,7 @@ bool TIMIQCurl::read_state_and_status_i(const std::string& url, std::string& sta } status = m_timiq_internal_buff; - m_error_string = "OK"; + m_error_string = "OK"; return true; } @@ -624,17 +663,282 @@ bool TIMIQCurl::read_state_and_status_i(const std::string& url, std::string& sta #if !defined (_SIMULATION_) } -#endif +#endif return false; } +// ============================================================================ +// TIMIQCurl::read_all_i +// ============================================================================ +bool TIMIQCurl::read_all_i(const std::string& url, timIQval_t& values) +{ +#if !defined (_SIMULATION_) + //- CURL easy return code + CURLcode result; + + m_error_string = ""; + + // time logs + //struct timeval begin, inter, depouil, end; + //gettimeofday(&begin, NULL); + + //- no connection is possible + if (this->connect_i() != timiq_NO_ERROR) + return false; + + // time logs + //gettimeofday(&inter, NULL); + + try + { + result = send_to_webserver_i(url); + } + catch (...) + { + m_error_string = "TIMIQCurl::read_all_i: exception while reading data on " + url; + return false; + } + + // time logs + //gettimeofday(&depouil, NULL); + + //- check the result + //---------------------------- + if (result != CURLE_OK) + { + //- HTTP error + char buff[kMAX_DATA_SIZE]; + memset(buff, 0, sizeof(buff)); + sprintf (buff, "TIMIQCurl::read_all_i - CURL code error <%d>",result); + m_error_string = buff; + return false; + } + + //- check the returned data + std::string strData = ""; + std::size_t index = 0; + + + // extract i value + //***************** + strData = kTIMIQ_IVALUE_KEY; + index = m_timiq_internal_buff.find(strData); + + if (index != std::string::npos) + { + //- extract substring from index + std::string l_subStr = m_timiq_internal_buff.substr(index); + + //- parse "=" + yat::StringTokenizer tokfloatStr (l_subStr, "="); + try + { + //- field + std::string fieldStr = tokfloatStr.next_token(); + + //- value + std::string floatStr = tokfloatStr.next_token(); + + //- convert data to float + values.iVal = (float)yat::XString<float>::to_num(floatStr); + } + catch(...) + { + m_error_string = "TIMIQCurl::read_all_i: exception while converting data for i value from " + url; + m_error_string += m_timiq_internal_buff; + return false; + } + } + else + { + //- otherwise error + m_error_string = m_timiq_internal_buff; + return false; + } + + + // extract q value + //***************** + strData = kTIMIQ_QVALUE_KEY; + index = m_timiq_internal_buff.find(strData); + + if (index != std::string::npos) + { + //- extract substring from index + std::string l_subStr = m_timiq_internal_buff.substr(index); + + //- parse "=" + yat::StringTokenizer tokfloatStr (l_subStr, "="); + try + { + //- field + std::string fieldStr = tokfloatStr.next_token(); + + //- value + std::string floatStr = tokfloatStr.next_token(); + + //- convert data to float + values.qVal = (float)yat::XString<float>::to_num(floatStr); + } + catch(...) + { + m_error_string = "TIMIQCurl::read_all_i: exception while converting data for q value from " + url; + m_error_string += m_timiq_internal_buff; + return false; + } + } + else + { + //- otherwise error + m_error_string = m_timiq_internal_buff; + return false; + } + + + // extract mixer cos value + //************************* + strData = kTIMIQ_MIXER_COS_OUTPUT_KEY; + index = m_timiq_internal_buff.find(strData); + + if (index != std::string::npos) + { + //- extract substring from index + std::string l_subStr = m_timiq_internal_buff.substr(index); + + //- parse "=" + yat::StringTokenizer tokfloatStr (l_subStr, "="); + try + { + //- field + std::string fieldStr = tokfloatStr.next_token(); + + //- value + std::string floatStr = tokfloatStr.next_token(); + + //- convert data to float + values.mixerCos = (float)yat::XString<float>::to_num(floatStr); + } + catch(...) + { + m_error_string = "TIMIQCurl::read_all_i: exception while converting data for mixer cos value from " + url; + m_error_string += m_timiq_internal_buff; + return false; + } + } + else + { + //- otherwise error + m_error_string = m_timiq_internal_buff; + return false; + } + + + // extract mixer sin value + //************************* + strData = kTIMIQ_MIXER_SIN_OUTPUT_KEY; + index = m_timiq_internal_buff.find(strData); + + if (index != std::string::npos) + { + //- extract substring from index + std::string l_subStr = m_timiq_internal_buff.substr(index); + + //- parse "=" + yat::StringTokenizer tokfloatStr (l_subStr, "="); + try + { + //- field + std::string fieldStr = tokfloatStr.next_token(); + + //- value + std::string floatStr = tokfloatStr.next_token(); + + //- convert data to float + values.mixerSin = (float)yat::XString<float>::to_num(floatStr); + } + catch(...) + { + m_error_string = "TIMIQCurl::read_all_i: exception while converting data for mixer sin value from " + url; + m_error_string += m_timiq_internal_buff; + return false; + } + } + else + { + //- otherwise error + m_error_string = m_timiq_internal_buff; + return false; + } + + + // extract temperature value + //**************************** + strData = kTIMIQ_BOARD_TEMPERATURE_KEY; + index = m_timiq_internal_buff.find(strData); + + if (index != std::string::npos) + { + //- extract substring from index + std::string l_subStr = m_timiq_internal_buff.substr(index); + + //- parse "=" + yat::StringTokenizer tokfloatStr (l_subStr, "="); + try + { + //- field + std::string fieldStr = tokfloatStr.next_token(); + + //- value + std::string floatStr = tokfloatStr.next_token(); + + //- convert data to float + values.temperature = (float)yat::XString<float>::to_num(floatStr); + } + catch(...) + { + m_error_string = "TIMIQCurl::read_all_i: exception while converting data for temperature from " + url; + m_error_string += m_timiq_internal_buff; + return false; + } + } + else + { + //- otherwise error + m_error_string = m_timiq_internal_buff; + return false; + } + +#else + values.iVal = m_sim_ival; + values.qVal = m_sim_qval; + values.temperature = 37.2 + values.iVal + values.qVal; + values.mixerSin = values.iVal + values.qVal; + values.mixerCos = values.iVal - values.qVal; +#endif + + // time logs + /*gettimeofday(&end, NULL); + std::cout << "INSTRU - TIMIQCurl::read_all_i function took " + << (end.tv_sec * 1000.0 + end.tv_usec / 1000.0) - (begin.tv_sec * 1000.0 + begin.tv_usec / 1000.0) + << " ms - connect took: " + << (inter.tv_sec * 1000.0 + inter.tv_usec / 1000.0) - (begin.tv_sec * 1000.0 + begin.tv_usec / 1000.0) + << " ms - get took: " + << (depouil.tv_sec * 1000.0 + depouil.tv_usec / 1000.0) - (inter.tv_sec * 1000.0 + inter.tv_usec / 1000.0) << std::endl; + */ + + //- success + m_error_string = "OK"; + return true; +} + +#if !defined (_SIMULATION_) // ============================================================================ // TIMIQCurl::send_to_webserver_i // ============================================================================ CURLcode TIMIQCurl::send_to_webserver_i(const std::string& url, bool thr) { - std::cout << "TIMIQCurl::send_to_webserver_i() entering... thr? " << thr << " - url = " << url << std::endl; // soso traces + //std::cout << "TIMIQCurl::send_to_webserver_i() entering... thr? " << thr << " - url = " << url << std::endl; CURLcode result; @@ -642,10 +946,10 @@ CURLcode TIMIQCurl::send_to_webserver_i(const std::string& url, bool thr) m_timiq_internal_buff.clear(); // according to flag, use "standard" or "threaded" curl reference - if (thr) - { + if (thr) + { // use threaded reference - + /* ask libcurl to set options */ curl_easy_setopt(m_thr_hw_curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(m_thr_hw_curl, CURLOPT_PROXY, ""); @@ -659,17 +963,17 @@ CURLcode TIMIQCurl::send_to_webserver_i(const std::string& url, bool thr) //- perform the query result = curl_easy_perform(m_thr_hw_curl); - -std::cout << "TIMIQCurl::send_to_webserver_i() curl_easy_perform rend la main pour url = " << url << std::endl; // soso traces + + // std::cout << "TIMIQCurl::send_to_webserver_i() curl_easy_perform terminates for url = " << url << std::endl; //- clean up curl_easy_cleanup(m_thr_hw_curl); - m_thr_hw_curl = NULL; + m_thr_hw_curl = NULL; } - else - { + else + { // use non threaded reference - + /* ask libcurl to set options */ curl_easy_setopt(m_hw_curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(m_hw_curl, CURLOPT_PROXY, ""); @@ -686,10 +990,11 @@ std::cout << "TIMIQCurl::send_to_webserver_i() curl_easy_perform rend la main po //- clean up curl_easy_cleanup(m_hw_curl); - m_hw_curl = NULL; + m_hw_curl = NULL; } return result; } +#endif -} +} diff --git a/src/TIMIQCurl.h b/src/TIMIQCurl.h index 211ce248d84fa2fee075893c1ce427be6e98f542..7a37bbac7e0dc7927238778aec129e397ccc7bf7 100644 --- a/src/TIMIQCurl.h +++ b/src/TIMIQCurl.h @@ -13,12 +13,29 @@ // DEPENDENCIES // ============================================================================ #include <iostream> + +#if !defined (_SIMULATION_) #include <curl/curl.h> +#endif + #include <TIMIQTypesAndConsts.h> namespace TIMIQLib_ns { + +//- TimIQ values structure +typedef struct timIQval +{ + // Tim IQ board values + float temperature; + float iVal; + float qVal; + float mixerSin; + float mixerCos; +} timIQval_t; + + class TIMIQCurl { public: @@ -79,6 +96,11 @@ namespace TIMIQLib_ns // @param [out] state vector of string E_timiq_errno_t read_state_and_status(std::string& status, E_timiq_code_t& codeRet); + // Reads all values (I, Q, mixer, temperature) from TimIQ equipment + // in a single command + // @param [out] val TimIQ values structure. + E_timiq_errno_t read_all(timIQval_t& values); + // Gets error messages // @return string variable std::string get_err_msg(void) @@ -92,12 +114,18 @@ namespace TIMIQLib_ns //- IP address std::string m_base_addr; +#if !defined (_SIMULATION_) //- CURL easy handle CURL * m_hw_curl; - //- CURL easy handle for threaded write actions // soso added + //- CURL easy handle for threaded write actions CURL * m_thr_hw_curl; +#endif +#if defined (_SIMULATION_) + double m_sim_ival; + double m_sim_qval; +#endif // message error std::string m_error_string; @@ -128,7 +156,7 @@ namespace TIMIQLib_ns bool write_i(std::string& url, std::string& strData, bool thr = true); // reads float data from timiq WebServer - // @param url of the page, strData data value to find, [out]flaot value to extracted + // @param url of the page, strData data value to find, [out] float value to extract // @return true if success, false otherwise bool read_float_i(const std::string& url, const std::string& strData, float& value ); @@ -136,13 +164,20 @@ namespace TIMIQLib_ns // @param url of the page, string state // @return true if success, false otherwise bool read_state_and_status_i(const std::string& url, std::string& state, E_timiq_code_t& codeRet ); + + // reads all values from timiq WebServer + // @param url of the page, [out] extracted values + // @return true if success, false otherwise + bool read_all_i(const std::string& url, timIQval_t& value ); +#if !defined (_SIMULATION_) // send data to webserver // @param url Url to use // @param thr thr = true: use threaded curl reference, otherwise, // use standard curl reference // @return CURLcode CURLcode send_to_webserver_i(const std::string& url, bool thr = false); +#endif }; } diff --git a/src/TIMIQLib.cpp b/src/TIMIQLib.cpp index f372752f1ca7b8a049af0509e44d6dc4fb8bfdf5..67b27ab3b39bf2c22678419fc633eedb9643247c 100644 --- a/src/TIMIQLib.cpp +++ b/src/TIMIQLib.cpp @@ -14,7 +14,7 @@ #include "TIMIQCurl.h" -namespace TIMIQLib_ns { +namespace TIMIQLib_ns { // ============================================================================ //- Check low level access to TIMIQ hardware pointer: @@ -95,6 +95,9 @@ void TIMIQLib::set_data(float data) l_ti_cfg.id = TI_DATA; l_ti_cfg.value = data; + this->ExecuteAction(l_ti_cfg); + +/* Use direct call instead of thread (board cycle is about 30ms) if (m_internal_timiq_state != Busy) { //- force timiq state = Busy @@ -112,42 +115,7 @@ void TIMIQLib::set_data(float data) //- start the task to write data on TIMIQ equipment m_timiq_task->start_undetached(); } -} - -// ============================================================================ -// TIMIQLib::data_end_task -// ============================================================================ -void TIMIQLib::data_end_task() - throw (Exception) -{ -// std::cout <<"data_end_task ..." <<std::endl; - - //- Delete task - if (this->m_timiq_task) - { - if (m_timiq_task->m_ti_cfg.ti_err != timiq_NO_ERROR) - { - // std::cout <<"exit task done ..." <<std::endl; - m_timiq_task->exit(); - delete m_timiq_task; - m_timiq_task = NULL; - - CHECK_TIMIQ_HW; - - std::string msg_err = "Set data error -msg: " + m_timiq_hw->get_err_msg(); - throw Exception(static_cast<const char*>("SOFTWARE_FAILURE"), - static_cast<const char*>(msg_err.c_str()), - static_cast<const char*>("TIMIQLib::data_end_task")); - } - - //- destroy otherwise - m_timiq_task->exit(); - delete m_timiq_task; - m_timiq_task = NULL; - } - - //- update state of TIMIQ equipment - m_internal_timiq_state = OK; +*/ } // ============================================================================ @@ -156,7 +124,7 @@ void TIMIQLib::data_end_task() void TIMIQLib::set_iValue(float iValue) throw (Exception) { - std::cout << "TIMIQLib::set_iValue() entering... - iValue to set = " << iValue << std::endl; // soso traces + //std::cout << "TIMIQLib::set_iValue() entering... - iValue to set = " << iValue << std::endl; //- Threading configuration timIQConfig l_ti_cfg; @@ -165,6 +133,9 @@ void TIMIQLib::set_iValue(float iValue) l_ti_cfg.id = TI_IVAL; l_ti_cfg.value = iValue; + this->ExecuteAction(l_ti_cfg); + +/* Use direct call instead of thread (board cycle is about 30ms) if (m_internal_timiq_state != Busy) { //- force timiq state = Busy @@ -182,42 +153,8 @@ void TIMIQLib::set_iValue(float iValue) //- start the task m_timiq_task->start_undetached(); } - else // soso test à supprimer - { - std::cout << "TIMIQLib::set_iValue() board already busy, do nothing..." << std::endl; // soso traces - } -} +*/ -// ============================================================================ -// TIMIQLib::iVal_end_task -// ============================================================================ -void TIMIQLib::iVal_end_task() - throw (Exception) -{ -// std::cout <<"iVal_end_task ..." <<std::endl; - //- Delete task - if (this->m_timiq_task) - { - if (m_timiq_task->m_ti_cfg.ti_err != timiq_NO_ERROR) - { - m_timiq_task->exit(); - m_timiq_task = NULL; - - CHECK_TIMIQ_HW; - - std::string msg_err = "Set I value error -msg: " + m_timiq_hw->get_err_msg(); - throw Exception(static_cast<const char*>("SOFTWARE_FAILURE"), - static_cast<const char*>(msg_err.c_str()), - static_cast<const char*>("TIMIQLib::set_iValue")); - } - //- destroy otherwise - m_timiq_task->exit(); - m_timiq_task = NULL; - - } - - //- update state of TIMIQ equipment - m_internal_timiq_state = OK; } // ============================================================================ @@ -225,9 +162,7 @@ void TIMIQLib::iVal_end_task() // ============================================================================ void TIMIQLib::end_task() throw (Exception) -{ -std::cout << "soso - end_task ..." <<std::endl; - +{ //- Delete task if (this->m_timiq_task) { @@ -240,13 +175,13 @@ std::cout << "soso - end_task ..." <<std::endl; throw Exception(static_cast<const char*>("SOFTWARE_FAILURE"), static_cast<const char*>(msg_err.c_str()), static_cast<const char*>("TIMIQLib::end_task")); - } + } - //- destroy otherwise + //- destroy otherwise yat::Thread::IOArg ioa; - m_timiq_task->exit(); - m_timiq_task->join(&ioa); // soso plus - m_timiq_task = NULL; + m_timiq_task->exit(); + m_timiq_task->join(&ioa); + m_timiq_task = NULL; } } @@ -255,8 +190,8 @@ std::cout << "soso - end_task ..." <<std::endl; // ============================================================================ void TIMIQLib::set_qValue(float qValue) throw (Exception) -{ - std::cout << "TIMIQLib::set_qValue() entering... - qValue to set = " << qValue << std::endl; // soso traces +{ + //std::cout << "TIMIQLib::set_qValue() entering... - qValue to set = " << qValue << std::endl; //- Threading configuration timIQConfig l_ti_cfg; @@ -265,6 +200,9 @@ void TIMIQLib::set_qValue(float qValue) l_ti_cfg.id = TI_QVAL; l_ti_cfg.value = qValue; + this->ExecuteAction(l_ti_cfg); + +/* Use direct call instead of thread (board cycle is about 30ms) if (m_internal_timiq_state != Busy) { //- force timiq state = Busy @@ -282,40 +220,9 @@ void TIMIQLib::set_qValue(float qValue) //- start the task to write "Q" tension value on TIMIQ equipment m_timiq_task->start_undetached(); } +*/ } -// ============================================================================ -// TIMIQLib::qVal_end_task -// ============================================================================ -void TIMIQLib::qVal_end_task() - throw (Exception) -{ -// std::cout <<"qVal_end_task ..." <<std::endl; - //- Delete task - if (this->m_timiq_task) - { - if (m_timiq_task->m_ti_cfg.ti_err != timiq_NO_ERROR) - { - m_timiq_task->exit(); - m_timiq_task = NULL; - - CHECK_TIMIQ_HW; - - std::string msg_err = "Set Q value error -msg: " + m_timiq_hw->get_err_msg(); - throw Exception(static_cast<const char*>("SOFTWARE_FAILURE"), - static_cast<const char*>(msg_err.c_str()), - static_cast<const char*>("TIMIQLib::qVal_end_task")); - } - - //- destroy otherwise - m_timiq_task->exit(); - m_timiq_task = NULL; - } - - //- update state of TIMIQ equipment - m_internal_timiq_state = OK; -} - // ============================================================================ // TIMIQLib::set_boardTemperature // ============================================================================ @@ -329,6 +236,9 @@ void TIMIQLib::set_boardTemperature(float boardTemperature) l_ti_cfg.id = TI_BTEMP; l_ti_cfg.value = boardTemperature; + this->ExecuteAction(l_ti_cfg); + +/* Use direct call instead of thread (board cycle is about 30ms) if (m_internal_timiq_state != Busy) { //- force timiq state = Busy @@ -345,40 +255,8 @@ void TIMIQLib::set_boardTemperature(float boardTemperature) //- start the task to set board temperature on TIMIQ equipment m_timiq_task->start_undetached(); - } -} - -// ============================================================================ -// TIMIQLib::boardT_end_task -// ============================================================================ -void TIMIQLib::boardT_end_task() - throw (Exception) -{ -// std::cout <<"boardT_end_task ..." <<std::endl; - //- Delete task - if (this->m_timiq_task) - { - if (m_timiq_task->m_ti_cfg.ti_err != timiq_NO_ERROR) - { - //std::cout <<"exit task done ..." <<std::endl; - m_timiq_task->exit(); - m_timiq_task = NULL; - - CHECK_TIMIQ_HW; - - std::string msg_err = "Set board Temperature error -msg: " + m_timiq_hw->get_err_msg(); - throw Exception(static_cast<const char*>("SOFTWARE_FAILURE"), - static_cast<const char*>(msg_err.c_str()), - static_cast<const char*>("TIMIQLib::boardT_end_task")); - } - - //- destroy otherwise - m_timiq_task->exit(); - m_timiq_task = NULL; - } - - //- update state of TIMIQ equipment - m_internal_timiq_state = OK; + } +*/ } // ============================================================================ @@ -392,6 +270,8 @@ void TIMIQLib::set_command(E_timiq_cmd_t& cmd) CHECK_TIMIQ_HW; //- write command on TIMIQ equipment + +/* Use direct call instead of thread (board cycle is about 30ms) // thread PLL calibration command: if (cmd == RECALIBRATE_PLL) { @@ -417,6 +297,7 @@ void TIMIQLib::set_command(E_timiq_cmd_t& cmd) } } else +*/ { err = m_timiq_hw->write_command(cmd, false); // use standard curl reference if (err != timiq_NO_ERROR) @@ -572,8 +453,8 @@ E_timiq_code_t TIMIQLib::get_state(std::string& status) //- get internal timiq state //- read status of TIMIQ equipment err = m_timiq_hw->read_state_and_status(status, m_internal_timiq_state); - -std::cout << "soso m_internal_timiq_state in read state and status = " << m_internal_timiq_state << std::endl; + +//std::cout << "m_internal_timiq_state in read state and status = " << m_internal_timiq_state << std::endl; if (err != timiq_NO_ERROR) { @@ -582,14 +463,15 @@ std::cout << "soso m_internal_timiq_state in read state and status = " << m_inte throw Exception(static_cast<const char*>("SOFTWARE_FAILURE"), static_cast<const char*>(msg_err.c_str()), static_cast<const char*>("TIMIQLib::get_status()")); - } + } + return m_internal_timiq_state; } - + // ============================================================================ // TIMIQLib::ExecuteAction // ============================================================================ -void TIMIQLib::ExecuteAction(timIQConfig & cfg) +void TIMIQLib::ExecuteAction(timIQConfig & cfg) throw (Exception) { E_timiq_errno_t err; @@ -601,10 +483,8 @@ void TIMIQLib::ExecuteAction(timIQConfig & cfg) switch(cfg.id) { //- write "I" value - case TI_IVAL: -std::cout << "soso - Execute action write iValue" << std::endl; - cfg.ti_err = m_timiq_hw->write_iValue(cfg.value); -std::cout << "soso - In Execute action - write_iValue rend la main -> end" << std::endl; + case TI_IVAL: + cfg.ti_err = m_timiq_hw->write_iValue(cfg.value); this->end_task(); break; @@ -627,8 +507,7 @@ std::cout << "soso - In Execute action - write_iValue rend la main -> end" << s break; //- PLL calibration - case TI_CALIB: -std::cout << "soso - Execute action write calibrate" << std::endl; + case TI_CALIB: cmd = RECALIBRATE_PLL; cfg.ti_err = m_timiq_hw->write_command(cmd); this->end_task(); @@ -639,6 +518,33 @@ std::cout << "soso - Execute action write calibrate" << std::endl; } } +// ============================================================================ +// TIMIQLib::get_boardData +// ============================================================================ +void TIMIQLib::get_boardData(timIQval_t& val) + throw (Exception) +{ + val.temperature = yat::IEEE_NAN; + val.iVal = yat::IEEE_NAN; + val.qVal = yat::IEEE_NAN; + val.mixerSin = yat::IEEE_NAN; + val.mixerCos = yat::IEEE_NAN; + + E_timiq_errno_t err; + + CHECK_TIMIQ_HW; + + //- read all values from TIMIQ equipment + err = m_timiq_hw->read_all(val); + if (err != timiq_NO_ERROR) + { + std::string msg_err = "Get all data error -msg: " + m_timiq_hw->get_err_msg(); + throw Exception(static_cast<const char*>("SOFTWARE_FAILURE"), + static_cast<const char*>(msg_err.c_str()), + static_cast<const char*>("TIMIQLib::get_boardData()")); + } +} + //***************************************************************************** //***************************************************************************** //***************************************************************************** @@ -671,8 +577,7 @@ ThreadedAction::~ThreadedAction() // ============================================================================ yat::Thread::IOArg ThreadedAction::run_undetached (yat::Thread::IOArg ioa) { - //DEBUG_STREAM << "ThreadedAction::run_undetached() entering... " << std::endl; - std::cout << "soso -- ThreadedAction::run_undetached() entering... " << std::endl; + //DEBUG_STREAM << "ThreadedAction::run_undetached() entering... " << std::endl; m_isActionDone = false; //- get the reference to parent task diff --git a/src/TIMIQTypesAndConsts.h b/src/TIMIQTypesAndConsts.h index 7d1e9254ab41c2d16af2702aaa7b09edc1c2c7aa..dbe2a15b95ea6057a55ccdb8f18a5bb11edd8c7a 100644 --- a/src/TIMIQTypesAndConsts.h +++ b/src/TIMIQTypesAndConsts.h @@ -113,7 +113,7 @@ typedef enum TI_QVAL, TI_BTEMP, TI_DATA, - TI_CALIB // soso add + TI_CALIB } E_ti_t; typedef struct timIQConfig