//============================================================================= // TIMIQLib.cpp //============================================================================= // abstraction.......TimIQ Application Programming Interface // class.............TIMIQLib // original author...J. GOUNO - NEXEYA-FRANCE //============================================================================= // ============================================================================ // DEPENDENCIES // ============================================================================ #include <timiq/TIMIQLib.h> #include "TIMIQCurl.h" 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()")); \ } // ============================================================================ // ============================================================================ // TIMIQLib::TIMIQLib // ============================================================================ TIMIQLib::TIMIQLib () { //std::cout << "TIMIQLib constructor" << std::endl; m_timiq_hw = NULL; m_ipAddress = ""; m_numPort = ""; } // ============================================================================ // TIMIQLib::~TIMIQLib() // ============================================================================ TIMIQLib::~TIMIQLib() { //std::cout << "TIMIQLib destructor" << std::endl; if (m_timiq_hw) { delete m_timiq_hw; m_timiq_hw = NULL; } } // ============================================================================ // TIMIQLib::init // ============================================================================ void TIMIQLib::init(const std::string& ip_address, const short& num_port) 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")); //- 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); CHECK_TIMIQ_HW; } // ============================================================================ // TIMIQLib::set_data // ============================================================================ void TIMIQLib::set_data(float data) throw (Exception) { E_timiq_errno_t err; CHECK_TIMIQ_HW; //- write data value on TIMIQ equipment err = m_timiq_hw->write_data(data); if (err != timiq_NO_ERROR) { 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()")); } } // ============================================================================ // TIMIQLib::set_iValue // ============================================================================ void TIMIQLib::set_iValue(float iValue) throw (Exception) { E_timiq_errno_t err; CHECK_TIMIQ_HW; //- write "I" tension value on TIMIQ equipment err = m_timiq_hw->write_iValue(iValue); if (err != timiq_NO_ERROR) { 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()")); } } // ============================================================================ // TIMIQLib::set_qValue // ============================================================================ void TIMIQLib::set_qValue(float qValue) throw (Exception) { E_timiq_errno_t err; CHECK_TIMIQ_HW; //- write "Q" tension value on TIMIQ equipment err = m_timiq_hw->write_qValue(qValue); if (err != timiq_NO_ERROR) { 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()")); } } // ============================================================================ // TIMIQLib::set_boardTemperature // ============================================================================ void TIMIQLib::set_boardTemperature(float boardTemperature) throw (Exception) { E_timiq_errno_t err; CHECK_TIMIQ_HW; //- write board temperature on TIMIQ equipment err = m_timiq_hw->write_boardTemperature(boardTemperature); if (err != timiq_NO_ERROR) { 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()")); } } // ============================================================================ // TIMIQLib::set_command // ============================================================================ void TIMIQLib::set_command(E_timiq_cmd_t& cmd) throw (Exception) { E_timiq_errno_t err; CHECK_TIMIQ_HW; //- write command on TIMIQ equipment 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()")); } } // ============================================================================ // TIMIQLib::get_data // ============================================================================ void TIMIQLib::get_data(float &data) 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()")); } } // ============================================================================ // TIMIQLib::get_iValue // ============================================================================ void TIMIQLib::get_iValue(float& iValue) 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()")); } } // ============================================================================ // TIMIQLib::get_qValue // ============================================================================ void TIMIQLib::get_qValue(float& qValue) 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()")); } } // ============================================================================ // TIMIQLib::get_mixerCosOutput // ============================================================================ void TIMIQLib::get_mixerCosOutput(float& mixerCosOutput) 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()")); } } // ============================================================================ // TIMIQLib::get_mixerSinOutput // ============================================================================ void TIMIQLib::get_mixerSinOutput(float& mixerSinOutput) 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()")); } } // ============================================================================ // TIMIQLib::get_boardTemperature // ============================================================================ void TIMIQLib::get_boardTemperature(float& boardTemperature) 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()")); } } // ============================================================================ // TIMIQLib::get_state // ============================================================================ E_timiq_code_t TIMIQLib::get_state(std::string& status) throw (Exception) { E_timiq_errno_t err; E_timiq_code_t retCode; CHECK_TIMIQ_HW; //- read status of TIMIQ equipment err = m_timiq_hw->read_state_and_status(status, retCode); if (err != timiq_NO_ERROR) { 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 retCode; } } // namespace timiqlib