diff options
author | Jörgen Scott <jorgen.scott@gmail.com> | 2015-02-09 13:36:22 +0100 |
---|---|---|
committer | Jörgen Scott <jorgen.scott@gmail.com> | 2015-02-09 13:36:22 +0100 |
commit | b31494c688ad93f2c09688a9061c7d392c6844a7 (patch) | |
tree | 095f37e97cdb26daf4cec87e71f2abde4565be7d | |
parent | ebdd156e45a520c67201c0382b1971e39bb25b72 (diff) | |
download | dabmod-b31494c688ad93f2c09688a9061c7d392c6844a7.tar.gz dabmod-b31494c688ad93f2c09688a9061c7d392c6844a7.tar.bz2 dabmod-b31494c688ad93f2c09688a9061c7d392c6844a7.zip |
added ping method + some cleaning
-rw-r--r-- | doc/zmq-ctrl/cpp/OdrModCtrl.cpp | 60 | ||||
-rw-r--r-- | doc/zmq-ctrl/cpp/OdrModCtrl.hpp | 1 | ||||
-rw-r--r-- | doc/zmq-ctrl/cpp/test/ctrl_test.cpp | 7 |
3 files changed, 57 insertions, 11 deletions
diff --git a/doc/zmq-ctrl/cpp/OdrModCtrl.cpp b/doc/zmq-ctrl/cpp/OdrModCtrl.cpp index 9b3f8dd..cd48fd1 100644 --- a/doc/zmq-ctrl/cpp/OdrModCtrl.cpp +++ b/doc/zmq-ctrl/cpp/OdrModCtrl.cpp @@ -36,6 +36,15 @@ #include "OdrModCtrl.hpp" #include <sstream> +#define MOD_GAIN "gain" +#define MOD_UHD "uhd" + +#define PARAM_DIG_GAIN "digital" +#define PARAM_TX_GAIN "txgain" +#define PARAM_FREQ "freq" +#define PARAM_MUTE "muting" +#define PARAM_STAT_DELAY "staticdelay" + COdrModCtrl::COdrModCtrl(zmq::context_t *pContext, std::string odrEndpoint, unsigned int timeoutMs) { @@ -56,55 +65,86 @@ COdrModCtrl::~COdrModCtrl() //// public get methods ///////////////////////////////////////////////////////// bool COdrModCtrl::GetDigitalGain(double &gain, std::string &error) { - return DoGet("gain", "digital", gain, error); + return DoGet(MOD_GAIN, PARAM_DIG_GAIN, gain, error); } bool COdrModCtrl::GetTxGain(double &gain, std::string &error) { - return DoGet("uhd", "txgain", gain, error); + return DoGet(MOD_UHD, PARAM_TX_GAIN, gain, error); } bool COdrModCtrl::GetTxFrequency(double &freqHz, std::string &error) { - return DoGet("uhd", "freq", freqHz, error); + return DoGet(MOD_UHD, PARAM_FREQ, freqHz, error); } bool COdrModCtrl::GetMuting(bool &mute, std::string &error) { - return DoGet("uhd", "muting", (uint32_t&) mute, error); + return DoGet(MOD_UHD, PARAM_MUTE, (uint32_t&) mute, error); } bool COdrModCtrl::GetStaticDelay(uint32_t &delayUs, std::string &error) { - return DoGet("uhd", "staticdelay", delayUs, error); + return DoGet(MOD_UHD, PARAM_STAT_DELAY, delayUs, error); } //// public set methods ///////////////////////////////////////////////////////// +bool COdrModCtrl::Ping() +{ + std::string error; + if (m_pReqSocket == NULL) + { + m_pReqSocket = new zmq::socket_t(*m_pContext, ZMQ_REQ); + if (!ConnectSocket(m_pReqSocket, m_odrEndpoint, error)) + return false; + } + + std::vector<std::string> msg; + msg.push_back("ping"); + + // send the message + if (!SendMessage(m_pReqSocket, msg, error)) + { + // destroy the socket according to the "Lazy Pirate Pattern" in + // the zmq guide + m_pReqSocket->close(); + delete m_pReqSocket; + m_pReqSocket = NULL; + return false; + } + + // wait for reply + if (!RecvAll(m_pReqSocket, msg, m_timeoutMs, error)) + return false; + + return true; +} + bool COdrModCtrl::SetDigitalGain(const double gain, std::string &error) { - return DoSet("gain", "digital", gain, error); + return DoSet(MOD_GAIN, PARAM_DIG_GAIN, gain, error); } bool COdrModCtrl::SetTxGain(const double gain, std::string &error) { - return DoSet("uhd", "txgain", gain, error); + return DoSet(MOD_UHD, PARAM_TX_GAIN, gain, error); } bool COdrModCtrl::SetTxFrequency(const double freqHz, std::string &error) { - return DoSet("uhd", "freq", freqHz, error); + return DoSet(MOD_UHD, PARAM_FREQ, freqHz, error); } bool COdrModCtrl::SetMuting(const bool mute, std::string &error) { - return DoSet("uhd", "muting", mute, error); + return DoSet(MOD_UHD, PARAM_MUTE, mute, error); } bool COdrModCtrl::SetStaticDelay(const uint32_t delayUs, std::string &error) { - return DoSet("uhd", "staticdelay", delayUs, error); + return DoSet(MOD_UHD, PARAM_STAT_DELAY, delayUs, error); } diff --git a/doc/zmq-ctrl/cpp/OdrModCtrl.hpp b/doc/zmq-ctrl/cpp/OdrModCtrl.hpp index 0651311..8b40666 100644 --- a/doc/zmq-ctrl/cpp/OdrModCtrl.hpp +++ b/doc/zmq-ctrl/cpp/OdrModCtrl.hpp @@ -39,6 +39,7 @@ class COdrModCtrl // // For a detailed description of the various parameters, see // example.ini. + virtual bool Ping(void); virtual bool GetDigitalGain(double &gain, std::string &error); virtual bool GetTxGain(double &gain, std::string &error); virtual bool GetTxFrequency(double &freqHz, std::string &error); diff --git a/doc/zmq-ctrl/cpp/test/ctrl_test.cpp b/doc/zmq-ctrl/cpp/test/ctrl_test.cpp index 3c38c89..21811d6 100644 --- a/doc/zmq-ctrl/cpp/test/ctrl_test.cpp +++ b/doc/zmq-ctrl/cpp/test/ctrl_test.cpp @@ -40,6 +40,11 @@ struct TemplateVars // made for setting invalid parameters. BOOST_FIXTURE_TEST_SUITE(test_template1, TemplateVars) +BOOST_AUTO_TEST_CASE (Ping) +{ + BOOST_CHECK(modCtrl.Ping() == true); +} + BOOST_AUTO_TEST_CASE (DigitalGain) { BOOST_CHECK(modCtrl.SetDigitalGain(0.5, error) == true); @@ -75,7 +80,7 @@ BOOST_AUTO_TEST_CASE (Muting) BOOST_AUTO_TEST_CASE (StaticDelay) { - // reset first or else test will fail on successive calls + // reset first or else test will fail on successive runs BOOST_CHECK(modCtrl.SetStaticDelay(-1, error) == true); BOOST_CHECK(modCtrl.SetStaticDelay(45000, error) == true); uint32_t value; |