diff --git a/include/timiq/TIMIQLib.h b/include/timiq/TIMIQLib.h index 4e099e32ef55ca5a4f577929afcf77969e937065..23bd1a5d587e59aa4dafc998e13cf04aee9b9f29 100644 --- a/include/timiq/TIMIQLib.h +++ b/include/timiq/TIMIQLib.h @@ -26,165 +26,185 @@ // via a http web protocol. // =========================================================================== -namespace TIMIQLib_ns { - //------------------------------------------------------------------------ - // Class Description: - // Thread to write the values and commands on the TimIQ equipment - //------------------------------------------------------------------------ - class ThreadedAction : public yat::Thread - { - friend class TIMIQLib; +namespace TIMIQLib_ns { + +//------------------------------------------------------------------------ +// Class Description: +// Thread to write the values and commands on the TimIQ equipment +//------------------------------------------------------------------------ +class ThreadedAction : public yat::Thread +{ + friend class TIMIQLib; - protected: - //- ctor --------------------------------- - ThreadedAction ( yat::Thread::IOArg ioa, timIQConfig& cfg); + protected: + + //- ctor --------------------------------- + ThreadedAction(yat::Thread::IOArg ioa, timIQConfig& cfg); - //- dtor --------------------------------- - virtual ~ThreadedAction (void); + //- dtor --------------------------------- + virtual ~ThreadedAction(); - //- thread's entry point - virtual yat::Thread::IOArg run_undetached (yat::Thread::IOArg ioa); + //- thread's entry point + virtual yat::Thread::IOArg run_undetached (yat::Thread::IOArg ioa); - //- asks this ThreadedAction to quit - virtual void exit (void); + //- asks this ThreadedAction to quit + virtual void exit(); - //- Thread state - bool isThreadAlive() - { - return m_goOn; - } + //- Thread state + bool isThreadAlive() + { + return m_goOn; + } - bool isWriteDone() - { - return m_isActionDone; - } + bool isWriteDone() + { + return m_isActionDone; + } - private: + private: - //- thread's ctrl flag - bool m_goOn; + //- thread's ctrl flag + bool m_goOn; - //- indicates if the threaded action is done - bool m_isActionDone; + //- indicates if the threaded action is done + bool m_isActionDone; - //- indicates if the threaded action has generated an error - bool m_isActionInError; + //- indicates if the threaded action has generated an error + bool m_isActionInError; - //- Thread action configuration member - timIQConfig m_ti_cfg; - }; + //- Thread action configuration member + timIQConfig m_ti_cfg; +}; - //- low layer TimIQ curl class - //----------------------------- - class TIMIQCurl; +//- low layer TimIQ curl class +//----------------------------- +class TIMIQCurl; - //------------------------------------------------------------------------ - //- TIMIQProxy Class - //- Ensures the interface of the timIQ equipment with - //- a tango software control system - //------------------------------------------------------------------------ - class TIMIQLib - { - friend class ThreadedAction; +//------------------------------------------------------------------------ +//- TIMIQProxy Class +//- Ensures the interface of the timIQ equipment with +//- a tango software control system +//------------------------------------------------------------------------ +class TIMIQLib +{ + friend class ThreadedAction; - public: - // Contructor - TIMIQLib (); + public: + + // Contructor + TIMIQLib(); - // Destructor - ~TIMIQLib(); - - //- Write functions - //--------------------------------------------------------------------------- - // Sets data to TimIQ equipment - // @param data float value. - void set_data(float data) throw (Exception); - - // Regulates "I" tension to TimIQ equipment - // @param iValue float value. - void set_iValue(float iValue)throw (Exception); - - // Regulates "Q" tension to TimIQ equipment - // @param qValue float value. - void set_qValue(float qValue)throw (Exception); - - // Sets board temperature to TimIQ equipment - // @param boardTemperature float value. - void set_boardTemperature(float boardTemperature) throw (Exception); - - // Sets command to TimIQ equipment - // @param cmd TimIQCmd_t value. - void set_command(E_timiq_cmd_t& cmd) throw (Exception); + // Destructor + ~TIMIQLib(); + + //- Write functions + //--------------------------------------------------------------------------- + // Sets data to TimIQ equipment + // @param data float value. + void set_data(float data) + throw (Exception); + + // Regulates "I" tension to TimIQ equipment + // @param iValue float value. + void set_iValue(float iValue) + throw (Exception); + + // Regulates "Q" tension to TimIQ equipment + // @param qValue float value. + void set_qValue(float qValue) + throw (Exception); + + // Sets board temperature to TimIQ equipment + // @param boardTemperature float value. + void set_boardTemperature(float boardTemperature) + throw (Exception); + + // Sets command to TimIQ equipment + // @param cmd TimIQCmd_t value. + void set_command(E_timiq_cmd_t& cmd) + throw (Exception); - //- Read functions - //--------------------------------------------------------------------------- - // Gets data from TimIQ equipment - // @param [out] data float pointer. - void get_data(float &data)throw (Exception); - - // Gets "I" value from TimIQ equipment - // @param [out] iValue float pointer. - void get_iValue(float& iValue)throw (Exception); - - // Gets "Q" value from TimIQ equipment - // @param [out] qValue float pointer. - void get_qValue(float& qValue)throw (Exception); - - // Gets the mixer cosinus output from TimIQ equipment - // @param [out] mixerCosOutput float pointer. - void get_mixerCosOutput(float& mixerCosOutput)throw (Exception); - - // Gets the mixer sinus output from TimIQ equipment - // @param [out] mixerSinOutput float pointer. - void get_mixerSinOutput(float& mixerSinOutput)throw (Exception); - - // Gets the board temperature from TimIQ equipment - // @param [out] boardTemperature float pointer. - void get_boardTemperature(float& boardTemperature)throw (Exception); + //- Read functions + //--------------------------------------------------------------------------- + // Gets data from TimIQ equipment + // @param [out] data float pointer. + void get_data(float &data) + throw (Exception); + + // Gets "I" value from TimIQ equipment + // @param [out] iValue float pointer. + void get_iValue(float& iValue) + throw (Exception); + + // Gets "Q" value from TimIQ equipment + // @param [out] qValue float pointer. + void get_qValue(float& qValue) + throw (Exception); + + // Gets the mixer cosinus output from TimIQ equipment + // @param [out] mixerCosOutput float pointer. + void get_mixerCosOutput(float& mixerCosOutput) + throw (Exception); + + // Gets the mixer sinus output from TimIQ equipment + // @param [out] mixerSinOutput float pointer. + void get_mixerSinOutput(float& mixerSinOutput) + throw (Exception); + + // Gets the board temperature from TimIQ equipment + // @param [out] boardTemperature float pointer. + void get_boardTemperature(float& boardTemperature) + throw (Exception); - // Gets state of TimIQ equipment - // @param [out] status string - E_timiq_code_t get_state(std::string& status) throw (Exception); - - // Initialize TimIQCurl library - // @param ip_address string, port_number string - void init (const std::string& ip_address, const short& port_number) throw (Exception); - - private: - //- internal members - //-------------------------- - TIMIQCurl * m_timiq_hw; - - //- ip address number - std::string m_ipAddress; - - //- port number - std::string m_numPort; - - //- internal timiq state - E_timiq_code_t m_internal_timiq_state; + // Gets state of TimIQ equipment + // @param [out] status string + E_timiq_code_t get_state(std::string& status) + throw (Exception); + + // Initialize TimIQCurl library + // @param ip_address string, port_number string + void init (const std::string& ip_address, const short& port_number) + throw (Exception); + + private: + + //- internal members + //-------------------------- + TIMIQCurl * m_timiq_hw; + + //- ip address number + std::string m_ipAddress; + + //- port number + std::string m_numPort; + //- internal timiq state + E_timiq_code_t m_internal_timiq_state; - protected: - //- internal function - //------------------------- - // ... - //- manage command by using task - ThreadedAction * m_timiq_task; + protected: + + //- internal functions + //------------------------- + + //- manage command by using task + ThreadedAction * m_timiq_task; - void ExecuteAction(timIQConfig & cfg); - void end_task() throw (Exception); + // execute action specified in argument + 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/src/TIMIQCurl.cpp b/src/TIMIQCurl.cpp index 1ef6a729c186db1396c24231bbc5b518e66d9057..1d26d25a01112a6b2f0aee8ba7c7441dab722f16 100644 --- a/src/TIMIQCurl.cpp +++ b/src/TIMIQCurl.cpp @@ -30,10 +30,11 @@ static std::string m_timiq_internal_buff; // ---------------------------------------------------------------------------- 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; + // 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; } // ============================================================================ @@ -41,12 +42,15 @@ static size_t write_callback( char *buffer, size_t size, size_t nmemb, void* ) // ============================================================================ TIMIQCurl::TIMIQCurl(const std::string& ip_address, const std::string& num_port) { - //std::cout << "TIMIQCurl constructor" << std::endl; - m_base_addr = kHTTP_WEB_PROTOCOL + ip_address + ":"+ num_port; + //std::cout << "TIMIQCurl constructor" << std::endl; + m_base_addr = kHTTP_WEB_PROTOCOL + ip_address + ":"+ num_port; - m_error_string = ""; + m_error_string = ""; - m_hw_curl = NULL; + m_hw_curl = NULL; + m_thr_hw_curl = NULL; + + curl_global_init(CURL_GLOBAL_ALL); } // ============================================================================ @@ -54,548 +58,638 @@ TIMIQCurl::TIMIQCurl(const std::string& ip_address, const std::string& num_port) // ============================================================================ TIMIQCurl::~TIMIQCurl () { - m_hw_curl = NULL; + if (m_hw_curl) + { + //- clean up + curl_easy_cleanup(m_hw_curl); + m_hw_curl = NULL; + } + + if (m_thr_hw_curl) + { + //- clean up + curl_easy_cleanup(m_thr_hw_curl); + m_thr_hw_curl = NULL; + } + + curl_global_cleanup(); } // ============================================================================ // TIMIQCurl::write_data // ============================================================================ -E_timiq_errno_t TIMIQCurl::write_data(float& data) +E_timiq_errno_t TIMIQCurl::write_data(float& data) { - E_timiq_errno_t err_num = timiq_internal_ERROR; + E_timiq_errno_t err_num = timiq_internal_ERROR; - char buff[kMAX_DATA_SIZE]; - memset(buff, 0, sizeof(buff)); - sprintf(buff, "%s=%2.3f", (char*)kTIMIQ_DATA_KEY.c_str(), data); - std::string strbuff(buff); + char buff[kMAX_DATA_SIZE]; + memset(buff, 0, sizeof(buff)); + sprintf(buff, "%s=%2.3f", (char*)kTIMIQ_DATA_KEY.c_str(), data); + std::string strbuff(buff); - //- request to the web page - // http://address/set_data - std::string str_url = m_base_addr + kTIMIQ_DATA_PAGE+ "?" + strbuff; + //- request to the web page + // http://address/set_data + std::string str_url = m_base_addr + kTIMIQ_DATA_PAGE+ "?" + strbuff; - if (this->write_i(str_url, strbuff)) - err_num = timiq_NO_ERROR; + if (this->write_i(str_url, strbuff)) + err_num = timiq_NO_ERROR; - return err_num; + return err_num; } // ============================================================================ // TIMIQCurl::write_iValue // ============================================================================ -E_timiq_errno_t TIMIQCurl::write_iValue(float& iValue) +E_timiq_errno_t TIMIQCurl::write_iValue(float& iValue) { - E_timiq_errno_t err_num = timiq_internal_ERROR; + std::cout << "TIMIQCurl::write_iValue() write iValue = " << iValue << std::endl; // soso traces + E_timiq_errno_t err_num = timiq_internal_ERROR; - char buff[kMAX_DATA_SIZE]; - memset(buff, 0, sizeof(buff)); - sprintf(buff, "%s=%1.6f", kTIMIQ_IVALUE_KEY.c_str() , iValue); - std::string strbuff(buff); + char buff[kMAX_DATA_SIZE]; + memset(buff, 0, sizeof(buff)); + sprintf(buff, "%s=%1.6f", kTIMIQ_IVALUE_KEY.c_str() , iValue); + std::string strbuff(buff); - //- request to the web page - // http://address/set_iValue - std::string str_url = m_base_addr + kTIMIQ_IVALUE_PAGE + "?" + strbuff; + //- request to the web page + // http://address/set_iValue + std::string str_url = m_base_addr + kTIMIQ_IVALUE_PAGE + "?" + strbuff; - if (this->write_i(str_url, strbuff)) - err_num = timiq_NO_ERROR; + if (this->write_i(str_url, strbuff)) + err_num = timiq_NO_ERROR; - return err_num; + return err_num; } // ============================================================================ // TIMIQCurl::write_qValue // ============================================================================ -E_timiq_errno_t TIMIQCurl::write_qValue(float& qValue) -{ - E_timiq_errno_t err_num = timiq_internal_ERROR; +E_timiq_errno_t TIMIQCurl::write_qValue(float& qValue) +{ +std::cout << "TIMIQCurl::write_qValue() write qValue = " << qValue << std::endl; // soso traces + E_timiq_errno_t err_num = timiq_internal_ERROR; - char buff[kMAX_DATA_SIZE]; - memset(buff, 0, sizeof (buff)); - sprintf(buff, "%s=%1.6f", kTIMIQ_QVALUE_KEY.c_str(), qValue); - std::string strbuff(buff); + char buff[kMAX_DATA_SIZE]; + memset(buff, 0, sizeof (buff)); + sprintf(buff, "%s=%1.6f", kTIMIQ_QVALUE_KEY.c_str(), qValue); + std::string strbuff(buff); - //- request to the web page - // http://address/set_qValue - std::string str_url = m_base_addr + kTIMIQ_QVALUE_PAGE + "?" + strbuff; + //- request to the web page + // http://address/set_qValue + std::string str_url = m_base_addr + kTIMIQ_QVALUE_PAGE + "?" + strbuff; - if (this->write_i(str_url, strbuff)) - err_num = timiq_NO_ERROR; + if (this->write_i(str_url, strbuff)) + err_num = timiq_NO_ERROR; - return err_num; + return err_num; } - + // ============================================================================ // TIMIQCurl::write_boardTemperature // ============================================================================ -E_timiq_errno_t TIMIQCurl::write_boardTemperature(float& boardTemperature) +E_timiq_errno_t TIMIQCurl::write_boardTemperature(float& boardTemperature) { - E_timiq_errno_t err_num = timiq_internal_ERROR; + E_timiq_errno_t err_num = timiq_internal_ERROR; - char buff[kMAX_DATA_SIZE]; - memset(buff, 0, sizeof (buff)); - sprintf(buff, "%s=%2.3f", kTIMIQ_BOARD_TEMPERATURE_KEY.c_str(), boardTemperature); - std::string strbuff(buff); + char buff[kMAX_DATA_SIZE]; + memset(buff, 0, sizeof (buff)); + sprintf(buff, "%s=%2.3f", kTIMIQ_BOARD_TEMPERATURE_KEY.c_str(), boardTemperature); + std::string strbuff(buff); - //- request to the web page - // http://address/set_boardTemperature.wsgi - std::string str_url = m_base_addr + kTIMIQ_BOARD_TEMPERATURE_PAGE + "?" + strbuff; + //- request to the web page + // http://address/set_boardTemperature.wsgi + std::string str_url = m_base_addr + kTIMIQ_BOARD_TEMPERATURE_PAGE + "?" + strbuff; - if (this->write_i(str_url, strbuff)) - err_num = timiq_NO_ERROR; + if (this->write_i(str_url, strbuff)) + err_num = timiq_NO_ERROR; - return err_num; + return err_num; } // ============================================================================ // TIMIQCurl::write_command // ============================================================================ -E_timiq_errno_t TIMIQCurl::write_command(E_timiq_cmd_t& cmd) +E_timiq_errno_t TIMIQCurl::write_command(E_timiq_cmd_t& cmd, bool thr) { - E_timiq_errno_t err_num = timiq_internal_ERROR; + E_timiq_errno_t err_num = timiq_internal_ERROR; - char buff[kMAX_DATA_SIZE]; - memset(buff, 0, sizeof(buff)); - sprintf(buff, "%s=%d", kTIMIQ_COMMAND_KEY.c_str(), (unsigned short)cmd); - std::string strbuff(buff); + char buff[kMAX_DATA_SIZE]; + memset(buff, 0, sizeof(buff)); + sprintf(buff, "%s=%d", kTIMIQ_COMMAND_KEY.c_str(), (unsigned short)cmd); + std::string strbuff(buff); - //- request to the web page - // http://address/set_command - std::string str_url = m_base_addr + kTIMIQ_COMMAND_PAGE + "?" + strbuff; + //- request to the web page + // http://address/set_command + std::string str_url = m_base_addr + kTIMIQ_COMMAND_PAGE + "?" + strbuff; - if (this->write_i(str_url, strbuff)) - err_num = timiq_NO_ERROR; + if (this->write_i(str_url, strbuff, thr)) + err_num = timiq_NO_ERROR; - return err_num; + return err_num; } // ============================================================================ // TIMIQCurl::read_data // ============================================================================ -E_timiq_errno_t TIMIQCurl::read_data(float& data) +E_timiq_errno_t TIMIQCurl::read_data(float& data) { - E_timiq_errno_t err_num = timiq_internal_ERROR; + E_timiq_errno_t err_num = timiq_internal_ERROR; - //- request to the web page - // http://address/get_data.wsgi - std::string str_url = m_base_addr + kTIMIQ_DATA_PAGE; + //- request to the web page + // http://address/get_data.wsgi + std::string str_url = m_base_addr + kTIMIQ_DATA_PAGE; - if (this->read_float_i(str_url, kTIMIQ_DATA_KEY, data)) - err_num = timiq_NO_ERROR; + if (this->read_float_i(str_url, kTIMIQ_DATA_KEY, data)) + err_num = timiq_NO_ERROR; - return err_num; + return err_num; } // ============================================================================ // TIMIQCurl::read_iValue // ============================================================================ -E_timiq_errno_t TIMIQCurl::read_iValue(float& iValue) +E_timiq_errno_t TIMIQCurl::read_iValue(float& iValue) { - E_timiq_errno_t err_num = timiq_internal_ERROR; + 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; + //- request to the web page + // http://address/get_feedback.wsgi + std::string str_url = m_base_addr + kTIMIQ_FEEDBACK_PAGE; - if (this->read_float_i(str_url, kTIMIQ_IVALUE_KEY, iValue)) - err_num = timiq_NO_ERROR; + if (this->read_float_i(str_url, kTIMIQ_IVALUE_KEY, iValue)) + err_num = timiq_NO_ERROR; - return err_num; + return err_num; } // ============================================================================ // TIMIQCurl::read_qValue // ============================================================================ -E_timiq_errno_t TIMIQCurl::read_qValue(float& qValue) +E_timiq_errno_t TIMIQCurl::read_qValue(float& qValue) { - E_timiq_errno_t err_num = timiq_internal_ERROR; + 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; + //- request to the web page + // http://address/get_feedback.wsgi + std::string str_url = m_base_addr + kTIMIQ_FEEDBACK_PAGE; - if (this->read_float_i(str_url, kTIMIQ_QVALUE_KEY, qValue)) - err_num = timiq_NO_ERROR; + if (this->read_float_i(str_url, kTIMIQ_QVALUE_KEY, qValue)) + err_num = timiq_NO_ERROR; - return err_num; + return err_num; } // ============================================================================ // TIMIQCurl::read_mixerCosOutput // ============================================================================ -E_timiq_errno_t TIMIQCurl::read_mixerCosOutput(float& mixerCosOutput) +E_timiq_errno_t TIMIQCurl::read_mixerCosOutput(float& mixerCosOutput) { - E_timiq_errno_t err_num = timiq_internal_ERROR; + 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; + //- request to the web page + //- http://address/get_feedback.wsgi + std::string str_url = m_base_addr + kTIMIQ_FEEDBACK_PAGE; - if (this->read_float_i(str_url, kTIMIQ_MIXER_COS_OUTPUT_KEY, mixerCosOutput)) - err_num = timiq_NO_ERROR; + if (this->read_float_i(str_url, kTIMIQ_MIXER_COS_OUTPUT_KEY, mixerCosOutput)) + err_num = timiq_NO_ERROR; - return err_num; + return err_num; } // ============================================================================ // TIMIQCurl::read_mixerSinOutput // ============================================================================ -E_timiq_errno_t TIMIQCurl::read_mixerSinOutput(float& mixerSinOutput) +E_timiq_errno_t TIMIQCurl::read_mixerSinOutput(float& mixerSinOutput) { - E_timiq_errno_t err_num = timiq_internal_ERROR; + 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; + //- request to the web page + //- http://address/get_feedback.wsgi + std::string str_url = m_base_addr + kTIMIQ_FEEDBACK_PAGE; - if (this->read_float_i(str_url, kTIMIQ_MIXER_SIN_OUTPUT_KEY, mixerSinOutput)) - err_num = timiq_NO_ERROR; + if (this->read_float_i(str_url, kTIMIQ_MIXER_SIN_OUTPUT_KEY, mixerSinOutput)) + err_num = timiq_NO_ERROR; - return err_num; + return err_num; } // ============================================================================ // TIMIQCurl::read_boardTemperature // ============================================================================ -E_timiq_errno_t TIMIQCurl::read_boardTemperature(float& boardTemperature) +E_timiq_errno_t TIMIQCurl::read_boardTemperature(float& boardTemperature) { - E_timiq_errno_t err_num = timiq_internal_ERROR; + 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; + //- request to the web page + //- http://address/get_feedback.wsgi + std::string str_url = m_base_addr + kTIMIQ_FEEDBACK_PAGE; - if (this->read_float_i(str_url, kTIMIQ_BOARD_TEMPERATURE_KEY, boardTemperature)) - err_num = timiq_NO_ERROR; + if (this->read_float_i(str_url, kTIMIQ_BOARD_TEMPERATURE_KEY, boardTemperature)) + err_num = timiq_NO_ERROR; - return err_num; + return err_num; } // ============================================================================ // TIMIQCurl::read_state_and_status // ============================================================================ -E_timiq_errno_t TIMIQCurl::read_state_and_status(std::string& status, E_timiq_code_t& codeRet) +E_timiq_errno_t TIMIQCurl::read_state_and_status(std::string& status, E_timiq_code_t& codeRet) { - E_timiq_errno_t err_num = timiq_internal_ERROR; + E_timiq_errno_t err_num = timiq_internal_ERROR; - //- request to the web page - //- http://address/get_state.wsgi - std::string str_url = m_base_addr + kTIMIQ_STATE_PAGE; + //- request to the web page + //- http://address/get_state.wsgi + std::string str_url = m_base_addr + kTIMIQ_STATE_PAGE; - if (this->read_state_and_status_i(str_url, status, codeRet)) - err_num = timiq_NO_ERROR; + if (this->read_state_and_status_i(str_url, status, codeRet)) + err_num = timiq_NO_ERROR; - return err_num; + return err_num; } // ============================================================================ // TIMIQCurl::connect_i // ============================================================================ -E_timiq_errno_t TIMIQCurl::connect_i() +E_timiq_errno_t TIMIQCurl::connect_i(bool thr) { - E_timiq_errno_t err_num = timiq_internal_ERROR; - m_error_string = ""; - - try - { - if (!m_hw_curl) - { - m_hw_curl = curl_easy_init(); + E_timiq_errno_t err_num = timiq_internal_ERROR; + m_error_string = ""; + + // according to flag, initialize "standard" or "threaded" curl reference + if (thr) + { + // use threaded reference + try + { + if (!m_thr_hw_curl) + { + m_thr_hw_curl = curl_easy_init(); - if (m_hw_curl) - { - err_num = timiq_NO_ERROR; - } - else - { - m_error_string = "INTERNAL_ERROR\n"; - m_error_string += "TIMIQ WebServer access is not available, null pointer detected!\n"; - m_error_string += "TIMIQCurl::connect()"; - } - } - else - { - m_error_string = "TIMIQ WebServer access allows only single session!\n"; - m_error_string += "TIMIQCurl::connect()"; - } - } - catch (...) - { - m_error_string = "TIMIQCurl::connect: exception while initialize Webserver..."; - m_hw_curl = NULL; - } - return err_num; + if (m_thr_hw_curl) + { + err_num = timiq_NO_ERROR; + } + else + { + m_error_string = "INTERNAL_ERROR\n"; + m_error_string += "TIMIQ WebServer access is not available, null pointer detected for threaded ref!\n"; + m_error_string += "TIMIQCurl::connect()"; + } + } + else + { + m_error_string = "TIMIQ WebServer access allows only single session for threaded ref!\n"; + m_error_string += "TIMIQCurl::connect()"; + } + } + catch (...) + { + m_error_string = "TIMIQCurl::connect: exception while initializing Webserver for threaded ref..."; + m_thr_hw_curl = NULL; + } + } + else + { + // use non threaded reference + try + { + if (!m_hw_curl) + { + m_hw_curl = curl_easy_init(); + + if (m_hw_curl) + { + err_num = timiq_NO_ERROR; + } + else + { + m_error_string = "INTERNAL_ERROR\n"; + m_error_string += "TIMIQ WebServer access is not available, null pointer detected for standard ref!\n"; + m_error_string += "TIMIQCurl::connect()"; + } + } + else + { + m_error_string = "TIMIQ WebServer access allows only single session for standard ref!\n"; + m_error_string += "TIMIQCurl::connect()"; + } + } + catch (...) + { + m_error_string = "TIMIQCurl::connect: exception while initializing Webserver for standard ref..."; + m_hw_curl = NULL; + } + } + + return err_num; } // ============================================================================ // TIMIQCurl::write_i // ============================================================================ -bool TIMIQCurl::write_i(std::string& url, std::string& strData) +bool TIMIQCurl::write_i(std::string& url, std::string& strData, bool thr) { - //- CURL easy return code - CURLcode result; + //- CURL easy return code + CURLcode result; - m_error_string = ""; + m_error_string = ""; #if !defined (_SIMULATION_) - //- no connection is possible - if (this->connect_i() != timiq_NO_ERROR) - return false; - - try - { - result = send_to_webserver_i(url); - } - catch (...) - { - m_error_string = "TIMIQCurl::write_i: exception while writing data on" + url; - return false; - } - - //- check the result - //---------------------------- - if (result != CURLE_OK) - { - //- HTTP error - m_error_string = m_timiq_internal_buff; - return false; - } - else - //- check the data returned - { + //- no connection is possible + if (this->connect_i(thr) != timiq_NO_ERROR) + return false; + + try + { + result = send_to_webserver_i(url, thr); + } + catch (...) + { + m_error_string = "TIMIQCurl::write_i: exception while writing data on" + url; + return false; + } + + //- check the result + //---------------------------- + if (result != CURLE_OK) + { + //- HTTP error + m_error_string = m_timiq_internal_buff; + return false; + } + 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"; - + 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) - { - m_error_string = "OK"; - return true; - } - else - { - //- otherwise error - m_error_string = m_timiq_internal_buff; - } + + std::size_t found = m_timiq_internal_buff.find(strData); + if (found != std::string::npos) + { + m_error_string = "OK"; + return true; + } + else + { + //- otherwise error + m_error_string = m_timiq_internal_buff; + } #if !defined (_SIMULATION_) - } -#endif - return false; + } +#endif + + return false; } // ============================================================================ // TIMIQCurl::read_float_i // ============================================================================ -bool TIMIQCurl::read_float_i(const std::string& url, const std::string& strData, float& value ) +bool TIMIQCurl::read_float_i(const std::string& url, const std::string& strData, float& value) { - // std::cout <<"TIMIQCurl::read_float_i"<<std::endl; - //- CURL easy return code - CURLcode result; + // std::cout <<"TIMIQCurl::read_float_i"<<std::endl; + //- CURL easy return code + CURLcode result; - m_error_string = ""; + m_error_string = ""; #if !defined (_SIMULATION_) - //- no connection is possible - if (this->connect_i() != timiq_NO_ERROR) - return false; - - try - { - result = send_to_webserver_i(url); - } - catch (...) - { - m_error_string = "TIMIQCurl::read_float_i: exception while reading data on " + url; - return false; - } - - //- check the result - //---------------------------- - if (result != CURLE_OK) - { - //- HTTP error - char buff[kMAX_DATA_SIZE]; - memset(buff, 0, sizeof(buff)); - sprintf (buff, "TIMIQCurl::read_float_i - CURL code error <%d>",result); - m_error_string = buff; - return false; - } - else - //- check the data returned - { + //- no connection is possible + if (this->connect_i() != timiq_NO_ERROR) + return false; + + try + { + result = send_to_webserver_i(url); + } + catch (...) + { + m_error_string = "TIMIQCurl::read_float_i: exception while reading data on " + url; + return false; + } + + //- check the result + //---------------------------- + if (result != CURLE_OK) + { + //- HTTP error + char buff[kMAX_DATA_SIZE]; + memset(buff, 0, sizeof(buff)); + sprintf (buff, "TIMIQCurl::read_float_i - CURL code error <%d>",result); + m_error_string = buff; + return false; + } + else + //- check the data returned + { #else - m_timiq_internal_buff = "\niValue=-0.000001\n"; - m_timiq_internal_buff += "qValue=0.000002\n"; - m_timiq_internal_buff += "mixerSinOutput=3.100000\n"; - m_timiq_internal_buff += "mixerCosOutput=0.154600\n"; - m_timiq_internal_buff += "boardTemperature=20.154"; + m_timiq_internal_buff = "\niValue=-0.000001\n"; + m_timiq_internal_buff += "qValue=0.000002\n"; + m_timiq_internal_buff += "mixerSinOutput=3.100000\n"; + m_timiq_internal_buff += "mixerCosOutput=0.154600\n"; + m_timiq_internal_buff += "boardTemperature=20.154"; #endif - std::size_t 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); + std::size_t 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(); + //- 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 - value = (float)yat::XString<float>::to_num(floatStr); - } - catch(...) - { - m_error_string = "TIMIQCurl::read_float_i: exception while converting data from " + url; - m_error_string += m_timiq_internal_buff; - return false; - } + //- convert data to float + value = (float)yat::XString<float>::to_num(floatStr); + } + catch(...) + { + m_error_string = "TIMIQCurl::read_float_i: exception while converting data from " + url; + m_error_string += m_timiq_internal_buff; + return false; + } - //- success - m_error_string = "OK"; - return true; - } + //- success + m_error_string = "OK"; + return true; + } - //- otherwise error - m_error_string = m_timiq_internal_buff; + //- otherwise error + m_error_string = m_timiq_internal_buff; #if !defined (_SIMULATION_) - } -#endif - return false; + } +#endif + + return false; } // ============================================================================ // TIMIQCurl::read_state_and_status_i // ============================================================================ -bool TIMIQCurl::read_state_and_status_i(const std::string& url, std::string& status, E_timiq_code_t& codeRet ) +bool TIMIQCurl::read_state_and_status_i(const std::string& url, std::string& status, E_timiq_code_t& codeRet) { - //- CURL easy return code - CURLcode result; + //- CURL easy return code + CURLcode result; - m_error_string = ""; + m_error_string = ""; #if !defined (_SIMULATION_) - //- no connection is possible - if (this->connect_i() != timiq_NO_ERROR) - return false; - - try - { - result = send_to_webserver_i(url); - } - catch (...) - { - m_error_string = "TIMIQCurl::read_status_i: exception while reading TimIQ status on " + url; - return false; - } - - //- check the result - //---------------------------- - if (result != CURLE_OK) - { - //- HTTP error - char buff[kMAX_DATA_SIZE]; - memset(buff, 0, sizeof(buff)); - sprintf (buff, "TIMIQCurl::read_state_and_status_i - CURL code error <%d>",result); - m_error_string = buff; - return false; - } - else - //- check the data returned - { + //- no connection is possible + if (this->connect_i() != timiq_NO_ERROR) + return false; + + try + { + result = send_to_webserver_i(url); + } + catch (...) + { + m_error_string = "TIMIQCurl::read_status_i: exception while reading TimIQ status on " + url; + return false; + } + + //- check the result + //---------------------------- + if (result != CURLE_OK) + { + //- HTTP error + char buff[kMAX_DATA_SIZE]; + memset(buff, 0, sizeof(buff)); + sprintf (buff, "TIMIQCurl::read_state_and_status_i - CURL code error <%d>",result); + m_error_string = buff; + return false; + } + else + //- check the data returned + { #else - m_timiq_internal_buff="message=System up and running\n"; - m_timiq_internal_buff+="state=OK\n"; - m_timiq_internal_buff+="code=1\n"; + m_timiq_internal_buff="message=System up and running\n"; + m_timiq_internal_buff+="state=OK\n"; + m_timiq_internal_buff+="code=1\n"; #endif - bool b_found = true; + bool b_found = true; - //- key word: message - std::size_t found = m_timiq_internal_buff.find(kTIMIQ_MESSAGE_KEY); - b_found = (found != std::string::npos); + //- key word: message + std::size_t found = m_timiq_internal_buff.find(kTIMIQ_MESSAGE_KEY); + b_found = (found != std::string::npos); - //- key word: state - found = m_timiq_internal_buff.find(kTIMIQ_STATE_KEY); - b_found &=(found != std::string::npos); + //- key word: state + found = m_timiq_internal_buff.find(kTIMIQ_STATE_KEY); + b_found &=(found != std::string::npos); - //- key word: code - found = m_timiq_internal_buff.find(kTIMIQ_CODE_KEY); - b_found &=(found != std::string::npos); + //- key word: code + found = m_timiq_internal_buff.find(kTIMIQ_CODE_KEY); + b_found &=(found != std::string::npos); - if (b_found) - { - //- extract the code value - std::string strCode = m_timiq_internal_buff.substr(found); + if (b_found) + { + //- extract the code value + std::string strCode = m_timiq_internal_buff.substr(found); - //- parse "=" - yat::StringTokenizer tokKeyword (strCode, "="); - try - { - //- field - std::string fieldStr = tokKeyword.next_token(); - - //- value - codeRet = (E_timiq_code_t) tokKeyword.next_int_token(); - } - catch(...) - { - m_error_string = "TIMIQCurl::read_state_and_status_i: exception while converting code from " + url; - m_error_string += m_timiq_internal_buff; - return false; - } + //- parse "=" + yat::StringTokenizer tokKeyword (strCode, "="); + try + { + //- field + std::string fieldStr = tokKeyword.next_token(); - status = m_timiq_internal_buff; - m_error_string = "OK"; - return true; - } + //- value + codeRet = (E_timiq_code_t) tokKeyword.next_int_token(); + } + catch(...) + { + m_error_string = "TIMIQCurl::read_state_and_status_i: exception while converting code from " + url; + m_error_string += m_timiq_internal_buff; + return false; + } + + status = m_timiq_internal_buff; + m_error_string = "OK"; + + return true; + } - //- otherwise error - m_error_string = m_timiq_internal_buff; + //- otherwise error + m_error_string = m_timiq_internal_buff; #if !defined (_SIMULATION_) - } -#endif - return false; + } +#endif + + return false; } // ============================================================================ // TIMIQCurl::send_to_webserver_i // ============================================================================ -CURLcode TIMIQCurl:: send_to_webserver_i(const std::string& url) +CURLcode TIMIQCurl::send_to_webserver_i(const std::string& url, bool thr) { - - CURLcode result; - - //- clean the timiq buffer data before perform - m_timiq_internal_buff.clear(); - - /* ask libcurl to set options */ - curl_easy_setopt(m_hw_curl, CURLOPT_URL, url.c_str()); - curl_easy_setopt(m_hw_curl, CURLOPT_PROXY, ""); - curl_easy_setopt(m_hw_curl, CURLOPT_WRITEFUNCTION, &write_callback); - - /* complete within 1500 ms */ - curl_easy_setopt(m_hw_curl, CURLOPT_TIMEOUT_MS, 1500L); - - /* ask libcurl to show us the verbose output */ - // curl_easy_setopt(m_hw_curl, CURLOPT_VERBOSE, 1L); - - //- perform the query - result = curl_easy_perform(m_hw_curl); - - //- clean up - curl_easy_cleanup(m_hw_curl); - m_hw_curl = NULL; - return result; + std::cout << "TIMIQCurl::send_to_webserver_i() entering... thr? " << thr << " - url = " << url << std::endl; // soso traces + + CURLcode result; + + //- clean the timiq buffer data before perform + m_timiq_internal_buff.clear(); + + // according to flag, use "standard" or "threaded" curl reference + 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, ""); + curl_easy_setopt(m_thr_hw_curl, CURLOPT_WRITEFUNCTION, &write_callback); + + /* complete within 1500 ms */ + curl_easy_setopt(m_thr_hw_curl, CURLOPT_TIMEOUT_MS, 30000L); // High timeout for threaded actions + + /* ask libcurl to show us the verbose output */ + // curl_easy_setopt(hm_thr_hw_curl, CURLOPT_VERBOSE, 1L); + + //- 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 + + //- clean up + curl_easy_cleanup(m_thr_hw_curl); + m_thr_hw_curl = NULL; + } + 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, ""); + curl_easy_setopt(m_hw_curl, CURLOPT_WRITEFUNCTION, &write_callback); + + /* complete within 1500 ms */ + curl_easy_setopt(m_hw_curl, CURLOPT_TIMEOUT_MS, 1500L); + + /* ask libcurl to show us the verbose output */ + // curl_easy_setopt(m_hw_curl, CURLOPT_VERBOSE, 1L); + + //- perform the query + result = curl_easy_perform(m_hw_curl); + + //- clean up + curl_easy_cleanup(m_hw_curl); + m_hw_curl = NULL; + } + + return result; } -} \ No newline at end of file +} diff --git a/src/TIMIQCurl.h b/src/TIMIQCurl.h index 4afeb56aabcee716fbcacfd9535effa80718c444..211ce248d84fa2fee075893c1ce427be6e98f542 100644 --- a/src/TIMIQCurl.h +++ b/src/TIMIQCurl.h @@ -35,47 +35,49 @@ namespace TIMIQLib_ns // Writes "I" tension on TimIQ equipment // @param iValue float value. - E_timiq_errno_t write_iValue(float& iValue); + E_timiq_errno_t write_iValue(float& iValue); // Writes "Q" tension to TimIQ equipment // @param qValue float value. - E_timiq_errno_t write_qValue(float& qValue); + E_timiq_errno_t write_qValue(float& qValue); // Writes board temperature to TimIQ equipment // @param boardTemperature float value. - E_timiq_errno_t write_boardTemperature(float& boardTemperature); + E_timiq_errno_t write_boardTemperature(float& boardTemperature); // Writes command on TimIQ equipment // @param cmd TimIQCmd_t value. - E_timiq_errno_t write_command(E_timiq_cmd_t& cmd); + // @param thr thr = true: use threaded curl reference, otherwise, + // use standard curl reference + E_timiq_errno_t write_command(E_timiq_cmd_t& cmd, bool thr = true); // Reads data from TimIQ equipment // @param [out] data float pointer. - E_timiq_errno_t read_data(float& data); + E_timiq_errno_t read_data(float& data); // Reads "I" value from TimIQ equipment // @param [out] iValue float pointer. - E_timiq_errno_t read_iValue(float& iValue); + E_timiq_errno_t read_iValue(float& iValue); // Reads "Q" value from TimIQ equipment // @param [out] qValue float pointer. - E_timiq_errno_t read_qValue(float& qValue); + E_timiq_errno_t read_qValue(float& qValue); // Reads the mixer cosinus output from TimIQ equipment // @param [out] mixerCosOutput float pointer. - E_timiq_errno_t read_mixerCosOutput(float& mixerCosOutput); + E_timiq_errno_t read_mixerCosOutput(float& mixerCosOutput); // Reads the mixer sinus output from TimIQ equipment // @param [out] mixerSinOutput float pointer. - E_timiq_errno_t read_mixerSinOutput(float& mixerSinOutput); + E_timiq_errno_t read_mixerSinOutput(float& mixerSinOutput); // Reads the board temperature from TimIQ equipment // @param [out] boardTemperature float pointer. - E_timiq_errno_t read_boardTemperature(float& boardTemperature); + E_timiq_errno_t read_boardTemperature(float& boardTemperature); // Reads TimIQ state of TimIQ equipment // @param [out] state vector of string - E_timiq_errno_t read_state_and_status(std::string& status, E_timiq_code_t& codeRet); + E_timiq_errno_t read_state_and_status(std::string& status, E_timiq_code_t& codeRet); // Gets error messages // @return string variable @@ -92,7 +94,10 @@ namespace TIMIQLib_ns //- CURL easy handle CURL * m_hw_curl; - + + //- CURL easy handle for threaded write actions // soso added + CURL * m_thr_hw_curl; + // message error std::string m_error_string; @@ -108,14 +113,19 @@ namespace TIMIQLib_ns //-------------------- // connects to api // connects to an easy handle using curl - // @return 0: no error, others: an internal error occurred - E_timiq_errno_t connect_i(); + // @param thr thr = true: use threaded curl reference, otherwise, + // use standard curl reference + // @return 0: no error, others: an internal error occurred + E_timiq_errno_t connect_i(bool thr = false); // writes on timiq WebServer - // @param url of the page, strData data to send + // @param url Url of the page + // @param strData Data to send + // @param thr thr = true: use threaded curl reference, otherwise, + // use standard curl reference // @return true if success, false otherwise - bool write_i(std::string& url, std::string& strData); + 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 @@ -128,9 +138,11 @@ namespace TIMIQLib_ns bool read_state_and_status_i(const std::string& url, std::string& state, E_timiq_code_t& codeRet ); // send data to webserver - // @param string + // @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); + CURLcode send_to_webserver_i(const std::string& url, bool thr = false); }; } diff --git a/src/TIMIQLib.cpp b/src/TIMIQLib.cpp index d44551702a809fbfe03d00b7118d4c107c368949..f372752f1ca7b8a049af0509e44d6dc4fb8bfdf5 100644 --- a/src/TIMIQLib.cpp +++ b/src/TIMIQLib.cpp @@ -14,15 +14,16 @@ #include "TIMIQCurl.h" -namespace TIMIQLib_ns { +namespace TIMIQLib_ns { + // ============================================================================ //- Check low level access to TIMIQ hardware pointer: #define CHECK_TIMIQ_HW \ if (!m_timiq_hw) \ { \ throw Exception(static_cast<const char*>("INTERNAL_ERROR"), \ - static_cast<const char*>("Low level access to TIMIQ hardware pointer is null!"), \ - static_cast<const char*>("CHECK_TIMIQ_HW()")); \ + static_cast<const char*>("Low level access to TIMIQ hardware pointer is null!"), \ + static_cast<const char*>("CHECK_TIMIQ_HW()")); \ } // ============================================================================ @@ -31,11 +32,11 @@ if (!m_timiq_hw) \ // ============================================================================ TIMIQLib::TIMIQLib () { - m_timiq_hw = NULL; - m_ipAddress = ""; - m_numPort = ""; - m_internal_timiq_state = Undefined; - m_timiq_task = NULL; + m_timiq_hw = NULL; + m_ipAddress = ""; + m_numPort = ""; + m_internal_timiq_state = Undefined; + m_timiq_task = NULL; } // ============================================================================ @@ -43,142 +44,148 @@ TIMIQLib::TIMIQLib () // ============================================================================ TIMIQLib::~TIMIQLib() { - if (m_timiq_hw) - { - delete m_timiq_hw; - m_timiq_hw = NULL; - } + if (m_timiq_hw) + { + delete m_timiq_hw; + m_timiq_hw = NULL; + } - //- - if (m_timiq_task) - { - m_timiq_task->exit(); - //delete m_timiq_task; // soso debug - sure needs delete ? - m_timiq_task = NULL; - } + //- + if (m_timiq_task) + { + m_timiq_task->exit(); + m_timiq_task = NULL; + } } // ============================================================================ // TIMIQLib::init // ============================================================================ void TIMIQLib::init(const std::string& ip_address, const short& num_port) - throw (Exception) + throw (Exception) { - //- chek Ip Address/ num port - if (ip_address.empty() || num_port == 0) - throw Exception(static_cast<const char*>("INTERNAL_ERROR"), - static_cast<const char*>("Ip address or port number not properly defined!"), - static_cast<const char*>("TIMIQLib::init")); + //- chek Ip Address/ num port + if (ip_address.empty() || num_port == 0) + throw Exception(static_cast<const char*>("INTERNAL_ERROR"), + static_cast<const char*>("Ip address or port number not properly defined!"), + static_cast<const char*>("TIMIQLib::init")); - //- - m_ipAddress = ip_address; - char buffer[20]; - sprintf(buffer, "%d", num_port); - m_numPort = buffer; + //- + m_ipAddress = ip_address; + char buffer[20]; + sprintf(buffer, "%d", num_port); + m_numPort = buffer; - // instantiate TIMIQCurl pointer - m_timiq_hw = new TIMIQCurl(m_ipAddress, m_numPort); + // instantiate TIMIQCurl pointer + m_timiq_hw = new TIMIQCurl(m_ipAddress, m_numPort); - CHECK_TIMIQ_HW; + CHECK_TIMIQ_HW; } // ============================================================================ // TIMIQLib::set_data // ============================================================================ void TIMIQLib::set_data(float data) - throw (Exception) + throw (Exception) { - //- Threading configuration - timIQConfig l_ti_cfg; + //- Threading configuration + timIQConfig l_ti_cfg; - //- set I value config - l_ti_cfg.id = TI_DATA; - l_ti_cfg.value = data; + //- set I value config + l_ti_cfg.id = TI_DATA; + l_ti_cfg.value = data; - if ( m_internal_timiq_state != Busy ) - { - //- force timiq state = Busy - m_internal_timiq_state = Busy; + if (m_internal_timiq_state != Busy) + { + //- force timiq state = Busy + m_internal_timiq_state = Busy; - m_timiq_task = new ThreadedAction(static_cast<yat::Thread::IOArg>(this), l_ti_cfg); - if (m_timiq_task == NULL) - { - 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::set_data")); - } - - //- start the task to write data on TIMIQ equipment - m_timiq_task->start_undetached(); - } + m_timiq_task = new ThreadedAction(static_cast<yat::Thread::IOArg>(this), l_ti_cfg); + if (m_timiq_task == NULL) + { + 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::set_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) + 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; +// 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; + 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")); - } + 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; + //- destroy otherwise + m_timiq_task->exit(); + delete m_timiq_task; + m_timiq_task = NULL; + } + + //- update state of TIMIQ equipment + m_internal_timiq_state = OK; } // ============================================================================ // TIMIQLib::set_iValue // ============================================================================ void TIMIQLib::set_iValue(float iValue) - throw (Exception) + throw (Exception) { - //- Threading configuration - timIQConfig l_ti_cfg; - - //- set I value config - l_ti_cfg.id = TI_IVAL; - l_ti_cfg.value = iValue; - - if ( m_internal_timiq_state != Busy ) - { - //- force timiq state = Busy - m_internal_timiq_state = Busy; - - m_timiq_task = new ThreadedAction(static_cast<yat::Thread::IOArg>(this), l_ti_cfg); - if (m_timiq_task == NULL) - { - std::string msg_err = " Can't instanciate set I value task"; - throw Exception(static_cast<const char*>("SOFTWARE_FAILURE"), - static_cast<const char*>(msg_err.c_str()), - static_cast<const char*>("TIMIQLib::set_iValue")); - } - - //- start the task - m_timiq_task->start_undetached(); - } + std::cout << "TIMIQLib::set_iValue() entering... - iValue to set = " << iValue << std::endl; // soso traces + + //- Threading configuration + timIQConfig l_ti_cfg; + + //- set I value config + l_ti_cfg.id = TI_IVAL; + l_ti_cfg.value = iValue; + + if (m_internal_timiq_state != Busy) + { + //- force timiq state = Busy + m_internal_timiq_state = Busy; + + m_timiq_task = new ThreadedAction(static_cast<yat::Thread::IOArg>(this), l_ti_cfg); + if (m_timiq_task == NULL) + { + std::string msg_err = " Can't instanciate set I value task"; + throw Exception(static_cast<const char*>("SOFTWARE_FAILURE"), + static_cast<const char*>(msg_err.c_str()), + static_cast<const char*>("TIMIQLib::set_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 + } } // ============================================================================ @@ -213,65 +220,68 @@ void TIMIQLib::iVal_end_task() m_internal_timiq_state = OK; } -// soso add // ============================================================================ // TIMIQLib::end_task // ============================================================================ void TIMIQLib::end_task() - throw (Exception) -{ - //- 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; + throw (Exception) +{ +std::cout << "soso - 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; - std::string msg_err = "Threaded task 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::end_task")); - } - //- destroy otherwise - m_timiq_task->exit(); - m_timiq_task = NULL; - } - - //- update state of TIMIQ equipment - //m_internal_timiq_state = OK; -- est mis à jour par get state + std::string msg_err = "Threaded task 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::end_task")); + } + + //- destroy otherwise + yat::Thread::IOArg ioa; + m_timiq_task->exit(); + m_timiq_task->join(&ioa); // soso plus + m_timiq_task = NULL; + } } // ============================================================================ // TIMIQLib::set_qValue // ============================================================================ void TIMIQLib::set_qValue(float qValue) - throw (Exception) -{ - //- Threading configuration - timIQConfig l_ti_cfg; + throw (Exception) +{ + std::cout << "TIMIQLib::set_qValue() entering... - qValue to set = " << qValue << std::endl; // soso traces + + //- Threading configuration + timIQConfig l_ti_cfg; - //- set Q value config - l_ti_cfg.id = TI_QVAL; - l_ti_cfg.value = qValue; + //- set Q value config + l_ti_cfg.id = TI_QVAL; + l_ti_cfg.value = qValue; - if ( m_internal_timiq_state != Busy ) - { - //- force timiq state = Busy - m_internal_timiq_state = Busy; + if (m_internal_timiq_state != Busy) + { + //- force timiq state = Busy + m_internal_timiq_state = Busy; - m_timiq_task = new ThreadedAction(static_cast<yat::Thread::IOArg>(this), l_ti_cfg); - if (m_timiq_task == NULL) - { - 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::set_qValue")); - } - - //- start the task to write "Q" tension value on TIMIQ equipment - m_timiq_task->start_undetached(); - } + m_timiq_task = new ThreadedAction(static_cast<yat::Thread::IOArg>(this), l_ti_cfg); + if (m_timiq_task == NULL) + { + 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::set_qValue")); + } + + //- start the task to write "Q" tension value on TIMIQ equipment + m_timiq_task->start_undetached(); + } } // ============================================================================ @@ -312,30 +322,30 @@ void TIMIQLib::qVal_end_task() void TIMIQLib::set_boardTemperature(float boardTemperature) throw (Exception) { - //- Threading configuration - timIQConfig l_ti_cfg; + //- Threading configuration + timIQConfig l_ti_cfg; - //- set board temperature value config - l_ti_cfg.id = TI_BTEMP; - l_ti_cfg.value = boardTemperature; + //- set board temperature value config + l_ti_cfg.id = TI_BTEMP; + l_ti_cfg.value = boardTemperature; - if ( m_internal_timiq_state != Busy ) - { - //- force timiq state = Busy - m_internal_timiq_state = Busy; + if (m_internal_timiq_state != Busy) + { + //- force timiq state = Busy + m_internal_timiq_state = Busy; - m_timiq_task = new ThreadedAction(static_cast<yat::Thread::IOArg>(this), l_ti_cfg); - if (m_timiq_task == NULL) - { - 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::set_boardTemperature")); - } - - //- start the task to set board temperature on TIMIQ equipment - m_timiq_task->start_undetached(); - } + m_timiq_task = new ThreadedAction(static_cast<yat::Thread::IOArg>(this), l_ti_cfg); + if (m_timiq_task == NULL) + { + 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::set_boardTemperature")); + } + + //- start the task to set board temperature on TIMIQ equipment + m_timiq_task->start_undetached(); + } } // ============================================================================ @@ -375,208 +385,258 @@ void TIMIQLib::boardT_end_task() // TIMIQLib::set_command // ============================================================================ void TIMIQLib::set_command(E_timiq_cmd_t& cmd) - throw (Exception) + throw (Exception) { - E_timiq_errno_t err; - - CHECK_TIMIQ_HW; - - //- write command on TIMIQ equipment - // soso add - // thread PLL calibration command: - if (cmd == RECALIBRATE_PLL) - { - if ( m_internal_timiq_state != Busy ) - { - timIQConfig l_ti_cfg; - l_ti_cfg.id = TI_CALIB; + E_timiq_errno_t err; + + CHECK_TIMIQ_HW; + + //- write command on TIMIQ equipment + // thread PLL calibration command: + if (cmd == RECALIBRATE_PLL) + { + if (m_internal_timiq_state != Busy) + { + timIQConfig l_ti_cfg; + l_ti_cfg.id = TI_CALIB; - //- force timiq state = Busy - m_internal_timiq_state = Busy; + //- force timiq state = Busy + m_internal_timiq_state = Busy; - m_timiq_task = new ThreadedAction(static_cast<yat::Thread::IOArg>(this), l_ti_cfg); - if (m_timiq_task == NULL) - { - 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::set_command")); - } - - //- start the task to do the pll calibration - m_timiq_task->start_undetached(); - } - } - else - { - err = m_timiq_hw->write_command(cmd); - if (err != timiq_NO_ERROR) - { - std::string msg_err = "Set command 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_command()")); - } - - //- update state of TIMIQ equipment - m_internal_timiq_state = OK; - } + m_timiq_task = new ThreadedAction(static_cast<yat::Thread::IOArg>(this), l_ti_cfg); + if (m_timiq_task == NULL) + { + 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::set_command")); + } + + //- start the task to do the pll calibration + m_timiq_task->start_undetached(); + } + } + else + { + err = m_timiq_hw->write_command(cmd, false); // use standard curl reference + if (err != timiq_NO_ERROR) + { + std::string msg_err = "Set command 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_command()")); + } + + //- update state of TIMIQ equipment + m_internal_timiq_state = OK; + } } // ============================================================================ // TIMIQLib::get_data // ============================================================================ void TIMIQLib::get_data(float &data) - throw (Exception) + throw (Exception) { - E_timiq_errno_t err; - - CHECK_TIMIQ_HW; - - //- read data from TIMIQ equipment - err = m_timiq_hw->read_data(data); - if (err != timiq_NO_ERROR) - { - std::string msg_err = "Get 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_data()")); - } + E_timiq_errno_t err; + + CHECK_TIMIQ_HW; + + //- read data from TIMIQ equipment + err = m_timiq_hw->read_data(data); + if (err != timiq_NO_ERROR) + { + std::string msg_err = "Get 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_data()")); + } } // ============================================================================ // TIMIQLib::get_iValue // ============================================================================ void TIMIQLib::get_iValue(float& iValue) - throw (Exception) + throw (Exception) { - E_timiq_errno_t err; - - CHECK_TIMIQ_HW; - - //- read "I" tension value from TIMIQ equipment - err = m_timiq_hw->read_iValue(iValue); - if (err != timiq_NO_ERROR) - { - std::string msg_err = "Get 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::get_iValue()")); - } + E_timiq_errno_t err; + + CHECK_TIMIQ_HW; + + //- read "I" tension value from TIMIQ equipment + err = m_timiq_hw->read_iValue(iValue); + if (err != timiq_NO_ERROR) + { + std::string msg_err = "Get 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::get_iValue()")); + } } - + // ============================================================================ // TIMIQLib::get_qValue // ============================================================================ void TIMIQLib::get_qValue(float& qValue) - throw (Exception) + throw (Exception) { - E_timiq_errno_t err; - - CHECK_TIMIQ_HW; - - //- read "Q" tension value from TIMIQ equipment - err = m_timiq_hw->read_qValue(qValue); - if (err != timiq_NO_ERROR) - { - std::string msg_err = "Get 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::get_qValue()")); - } + E_timiq_errno_t err; + + CHECK_TIMIQ_HW; + + //- read "Q" tension value from TIMIQ equipment + err = m_timiq_hw->read_qValue(qValue); + if (err != timiq_NO_ERROR) + { + std::string msg_err = "Get 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::get_qValue()")); + } } // ============================================================================ // TIMIQLib::get_mixerCosOutput // ============================================================================ void TIMIQLib::get_mixerCosOutput(float& mixerCosOutput) - throw (Exception) + throw (Exception) { - E_timiq_errno_t err; - - CHECK_TIMIQ_HW; - - //- read mixer cos output value from TIMIQ equipment - err = m_timiq_hw->read_mixerCosOutput(mixerCosOutput); - if (err != timiq_NO_ERROR) - { - std::string msg_err = "Get mixer cosinus output 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::get_mixerCosOutput()")); - } + E_timiq_errno_t err; + + CHECK_TIMIQ_HW; + + //- read mixer cos output value from TIMIQ equipment + err = m_timiq_hw->read_mixerCosOutput(mixerCosOutput); + if (err != timiq_NO_ERROR) + { + std::string msg_err = "Get mixer cosinus output 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::get_mixerCosOutput()")); + } } // ============================================================================ // TIMIQLib::get_mixerSinOutput // ============================================================================ void TIMIQLib::get_mixerSinOutput(float& mixerSinOutput) - throw (Exception) + throw (Exception) { - E_timiq_errno_t err; - - CHECK_TIMIQ_HW; - - //- read mixer sin output value from TIMIQ equipment - err = m_timiq_hw->read_mixerSinOutput(mixerSinOutput); - if (err != timiq_NO_ERROR) - { - std::string msg_err = "Get mixer sinus output 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::get_mixerSinOutput()")); - } + E_timiq_errno_t err; + + CHECK_TIMIQ_HW; + + //- read mixer sin output value from TIMIQ equipment + err = m_timiq_hw->read_mixerSinOutput(mixerSinOutput); + if (err != timiq_NO_ERROR) + { + std::string msg_err = "Get mixer sinus output 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::get_mixerSinOutput()")); + } } // ============================================================================ // TIMIQLib::get_boardTemperature // ============================================================================ void TIMIQLib::get_boardTemperature(float& boardTemperature) - throw (Exception) + throw (Exception) { - E_timiq_errno_t err; - - CHECK_TIMIQ_HW; - - //- read board temperature value from TIMIQ equipment - err = m_timiq_hw->read_boardTemperature(boardTemperature); - if (err != timiq_NO_ERROR) - { - std::string msg_err = "Get board temperature 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::get_boardTemperature()")); - } + E_timiq_errno_t err; + + CHECK_TIMIQ_HW; + + //- read board temperature value from TIMIQ equipment + err = m_timiq_hw->read_boardTemperature(boardTemperature); + if (err != timiq_NO_ERROR) + { + std::string msg_err = "Get board temperature 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::get_boardTemperature()")); + } } // ============================================================================ // TIMIQLib::get_state // ============================================================================ E_timiq_code_t TIMIQLib::get_state(std::string& status) - throw (Exception) + throw (Exception) { - E_timiq_errno_t err; - E_timiq_code_t retCode; - - CHECK_TIMIQ_HW; - - //- get internal timiq state - //if (m_internal_timiq_state != Busy) -- soso debug : update qqsoit l'état - { - //- read status of TIMIQ equipment - err = m_timiq_hw->read_state_and_status(status, m_internal_timiq_state); - - if (err != timiq_NO_ERROR) - { - m_internal_timiq_state = Undefined; - std::string msg_err = "Get status 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_status()")); - } - } - - return m_internal_timiq_state; + E_timiq_errno_t err; + E_timiq_code_t retCode; + + CHECK_TIMIQ_HW; + + //- 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; + + if (err != timiq_NO_ERROR) + { + m_internal_timiq_state = Undefined; + std::string msg_err = "Get status 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_status()")); + } + return m_internal_timiq_state; +} + +// ============================================================================ +// TIMIQLib::ExecuteAction +// ============================================================================ +void TIMIQLib::ExecuteAction(timIQConfig & cfg) + throw (Exception) +{ + E_timiq_errno_t err; + E_timiq_cmd_t cmd; + + CHECK_TIMIQ_HW; + + // Actions to be threaded + 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; + this->end_task(); + break; + + //- write "Q" value + case TI_QVAL: + cfg.ti_err = m_timiq_hw->write_qValue(cfg.value); + this->end_task(); + break; + + //- write "DATA" value + case TI_DATA: + cfg.ti_err = m_timiq_hw->write_data(cfg.value); + this->end_task(); + break; + + //- write "BOARD Temperature" value + case TI_BTEMP: + cfg.ti_err = m_timiq_hw->write_data(cfg.value); + this->end_task(); + break; + + //- PLL calibration + case TI_CALIB: +std::cout << "soso - Execute action write calibrate" << std::endl; + cmd = RECALIBRATE_PLL; + cfg.ti_err = m_timiq_hw->write_command(cmd); + this->end_task(); + break; + + default: + break; + } } //***************************************************************************** @@ -589,11 +649,11 @@ E_timiq_code_t TIMIQLib::get_state(std::string& status) // ============================================================================ // ThreadedAction::ThreadedAction // ============================================================================ -ThreadedAction::ThreadedAction ( yat::Thread::IOArg ioa, timIQConfig& cfg) - : yat::Thread(ioa), - m_goOn(true), - m_isActionDone(false), - m_ti_cfg(cfg) +ThreadedAction::ThreadedAction(yat::Thread::IOArg ioa, timIQConfig& cfg) +:yat::Thread(ioa), + m_goOn(true), + m_isActionDone(false), + m_ti_cfg(cfg) { //- noop ctor } @@ -601,7 +661,7 @@ ThreadedAction::ThreadedAction ( yat::Thread::IOArg ioa, timIQConfig& cfg) // ============================================================================ // ThreadedAction::~ThreadedAction // ============================================================================ -ThreadedAction::~ThreadedAction (void) +ThreadedAction::~ThreadedAction() { //- noop dtor } @@ -611,74 +671,26 @@ ThreadedAction::~ThreadedAction (void) // ============================================================================ yat::Thread::IOArg ThreadedAction::run_undetached (yat::Thread::IOArg ioa) { - //DEBUG_STREAM << "ThreadedAction::run_undetached() entering... " << std::endl; - m_isActionDone = false; + //DEBUG_STREAM << "ThreadedAction::run_undetached() entering... " << std::endl; + std::cout << "soso -- ThreadedAction::run_undetached() entering... " << std::endl; + m_isActionDone = false; - //- get the reference to parent task - TIMIQLib * l_task = reinterpret_cast<TIMIQLib *>(ioa); - l_task->ExecuteAction(m_ti_cfg); + //- get the reference to parent task + TIMIQLib * l_task = reinterpret_cast<TIMIQLib *>(ioa); + l_task->ExecuteAction(m_ti_cfg); - //- Action is done - m_isActionDone = true; + //- Action is done + m_isActionDone = true; - return 0; + return 0; } // ============================================================================ // ThreadedAction::exit // ============================================================================ -void ThreadedAction::exit (void) +void ThreadedAction::exit() { - this->m_goOn = false; -} - -// ============================================================================ -// TIMIQLib::ExecuteAction -// ============================================================================ -void TIMIQLib::ExecuteAction(timIQConfig & cfg) -{ - E_timiq_errno_t err; - E_timiq_cmd_t cmd; - - CHECK_TIMIQ_HW; - - // Actions to be threaded - switch(cfg.id) - { - //- write "I" value - case TI_IVAL: - cfg.ti_err = m_timiq_hw->write_iValue(cfg.value); - this->end_task(); // soso meme fonction end, non ? - break; - - //- write "Q" value - case TI_QVAL: - cfg.ti_err = m_timiq_hw->write_qValue(cfg.value); - this->end_task(); // soso meme fonction end, non ? - break; - - //- write "DATA" value - case TI_DATA: - cfg.ti_err = m_timiq_hw->write_data(cfg.value); - this->end_task(); // soso meme fonction end, non ? - break; - - //- write "BOARD Temperature" value - case TI_BTEMP: - cfg.ti_err = m_timiq_hw->write_data(cfg.value); - this->end_task(); // soso meme fonction end, non ? - break; - - //- PLL calibration -- soso add - case TI_CALIB: - cmd = RECALIBRATE_PLL; - cfg.ti_err = m_timiq_hw->write_command(cmd); - this->end_task(); - break; - - default: - break; - } + this->m_goOn = false; } } // namespace timiqlib