diff options
author | Matthias P. Braendli (think) <matthias@mpb.li> | 2012-08-16 18:05:40 +0200 |
---|---|---|
committer | Matthias P. Braendli (think) <matthias@mpb.li> | 2012-08-16 18:05:40 +0200 |
commit | b946ff6bceef6150f19da0a86950ed9ebbf0c2cb (patch) | |
tree | 6987a458cdb324a0155f7f8d36fc1ecc0d336bb3 | |
parent | 521ee81560be5d065bd090002a2c6b92a322a034 (diff) | |
download | dabmod-b946ff6bceef6150f19da0a86950ed9ebbf0c2cb.tar.gz dabmod-b946ff6bceef6150f19da0a86950ed9ebbf0c2cb.tar.bz2 dabmod-b946ff6bceef6150f19da0a86950ed9ebbf0c2cb.zip |
crc-dabmod: removed useless set_parameters from remote_control
-rw-r--r-- | src/OutputUHD.cpp | 38 | ||||
-rw-r--r-- | src/OutputUHD.h | 21 | ||||
-rw-r--r-- | src/RemoteControl.cpp | 3 | ||||
-rw-r--r-- | src/RemoteControl.h | 12 | ||||
-rw-r--r-- | src/testremotecontrol/test.cpp | 41 |
5 files changed, 54 insertions, 61 deletions
diff --git a/src/OutputUHD.cpp b/src/OutputUHD.cpp index 971f33b..0195841 100644 --- a/src/OutputUHD.cpp +++ b/src/OutputUHD.cpp @@ -27,6 +27,7 @@ #include "OutputUHD.h" #include "PcDebug.h" #include "Log.h" +#include "RemoteControl.h" #include <iostream> #include <assert.h> @@ -42,6 +43,7 @@ OutputUHD::OutputUHD(const char* device, unsigned sampleRate, double frequency, int txgain, bool enableSync, bool muteNoTimestamps, Logger& logger) : ModOutput(ModFormat(1), ModFormat(0)), + RemoteControl("uhd"), myLogger(logger), mySampleRate(sampleRate), myTxGain(txgain), @@ -52,6 +54,9 @@ OutputUHD::OutputUHD(const char* device, unsigned sampleRate, MDEBUG("OutputUHD::OutputUHD(device: %s) @ %p\n", device, this); + /* register the parameters that can be remote controlled */ + RC_ADD_PARAMETER("txgain", "UHD analog daughterboard TX gain") + myDevice = device; #if ENABLE_UHD @@ -499,3 +504,36 @@ loopend: workerbuffer = (workerbuffer + 1) % 2; } } + + +virtual void OutputUHD::set_parameter(string parameter, string value) +{ + stringstream ss(value); + ss.exceptions ( stringstream::failbit | stringstream::badbit ); + + if (parameter == "txgain") { + ss >> myTxStream; +#if ENABLE_UHD + myUsrp->set_tx_gain(myTxGain); +#endif + } + else { + stringstream ss; + ss << "Parameter '" << parameter << "' is not exported by controllable " << get_rc_name(); + throw ParameterError(ss.str()); + } +} + +virtual string OutputUHD::get_parameter(string parameter) +{ + stringstream ss; + if (parameter == "txgain") { + ss << myTxGain; + } + else { + ss << "Parameter '" << parameter << "' is not exported by controllable " << get_rc_name(); + throw ParameterError(ss.str()); + } + return ss.str(); +} + diff --git a/src/OutputUHD.h b/src/OutputUHD.h index 6d2df55..1a53804 100644 --- a/src/OutputUHD.h +++ b/src/OutputUHD.h @@ -159,32 +159,14 @@ class OutputUHD: public ModOutput, public RemoteControl { } /*********** REMOTE CONTROL ***************/ - virtual std::string get_rc_name() { return "uhd"; } - /* Tell the controllable to enrol at the given controller / virtual void enrol_at(BaseRemoteController& controller) { controller.enrol(this); } // */ - /* Return a list of possible parameters that can be set */ - list<string> get_supported_parameters() { - list<string> parameterlist; - for (list< vector<string> >::iterator it = parameters_.begin(); it != parameters_.end(); it++) { - parameterlist.push_back((*it)[0]); - } - return parameterlist; - } - - /* Return a mapping of the descriptions of all parameters */ - virtual std::list< std::vector<std::string> > get_parameter_descriptions() = 0; - /* Base function to set parameters. */ virtual void set_parameter(string parameter, string value) = 0; - /* Convenience functions for other common types */ - virtual void set_parameter(string parameter, double value) = 0; - virtual void set_parameter(string parameter, long value) = 0; - /* Getting a parameter always returns a string. */ virtual string get_parameter(string parameter) = 0; @@ -206,9 +188,6 @@ class OutputUHD: public ModOutput, public RemoteControl { bool enable_sync; size_t lastLen; - - - /*********** REMOTE CONTROL ***************/ }; diff --git a/src/RemoteControl.cpp b/src/RemoteControl.cpp index 53b7204..ad745db 100644 --- a/src/RemoteControl.cpp +++ b/src/RemoteControl.cpp @@ -191,6 +191,9 @@ RemoteControllerTelnet::dispatch_command(tcp::socket& socket, string command) catch (ParameterError &e) { reply(socket, e.what()); } + catch (exception &e) { + reply(socket, "Error: Invalid parameter value. "); + } } else { diff --git a/src/RemoteControl.h b/src/RemoteControl.h index 2830210..53fc912 100644 --- a/src/RemoteControl.h +++ b/src/RemoteControl.h @@ -40,7 +40,7 @@ #include <stdexcept> -#define ADD_PARAMETER(p, desc) { \ +#define RC_ADD_PARAMETER(p, desc) { \ vector<string> p; \ p.push_back(#p); \ p.push_back(desc); \ @@ -81,7 +81,7 @@ class RemoteControllable { * It might be used in the commands the user has to type, so keep * it short */ - virtual std::string get_rc_name() = 0; + virtual std::string get_rc_name() { return name_; } /* Tell the controllable to enrol at the given controller */ virtual void enrol_at(BaseRemoteController& controller) { @@ -99,15 +99,13 @@ class RemoteControllable { } /* Return a mapping of the descriptions of all parameters */ - virtual std::list< std::vector<std::string> > get_parameter_descriptions() = 0; + virtual std::list< std::vector<std::string> > get_parameter_descriptions() { + return parameters_; + } /* Base function to set parameters. */ virtual void set_parameter(string parameter, string value) = 0; - /* Convenience functions for other common types */ - virtual void set_parameter(string parameter, double value) = 0; - virtual void set_parameter(string parameter, long value) = 0; - /* Getting a parameter always returns a string. */ virtual string get_parameter(string parameter) = 0; diff --git a/src/testremotecontrol/test.cpp b/src/testremotecontrol/test.cpp index 07b761f..40f0e25 100644 --- a/src/testremotecontrol/test.cpp +++ b/src/testremotecontrol/test.cpp @@ -1,6 +1,7 @@ #include <string> #include <map> #include <unistd.h> + #include "RemoteControl.h" using namespace std; @@ -10,23 +11,22 @@ class TestControllable : public RemoteControllable public: TestControllable(string name) : RemoteControllable(name) { - ADD_PARAMETER(foo, "That's the foo"); - ADD_PARAMETER(bar, "That's the bar"); - ADD_PARAMETER(baz, "That's the baz"); + RC_ADD_PARAMETER(foo, "That's the foo"); + RC_ADD_PARAMETER(bar, "That's the bar"); + RC_ADD_PARAMETER(baz, "That's the baz"); } - string get_rc_name() { return name_; }; - void set_parameter(string parameter, string value) { + stringstream ss(value); + ss.exceptions ( stringstream::failbit | stringstream::badbit ); + if (parameter == "foo") { - stringstream ss(value); ss >> foo_; } else if (parameter == "bar") { bar_ = value; } else if (parameter == "baz") { - stringstream ss(value); ss >> baz_; } else { @@ -36,30 +36,9 @@ class TestControllable : public RemoteControllable } } - void set_parameter(string parameter, double value) { - if (parameter == "baz") { - baz_ = value; - } - else { - stringstream ss; - ss << "Parameter '" << parameter << "' is not a double in controllable " << get_rc_name(); - throw ParameterError(ss.str()); - } - } - - void set_parameter(string parameter, long value) { - if (parameter == "foo") { - foo_ = value; - } - else { - stringstream ss; - ss << "Parameter '" << parameter << "' is not a long in controllable " << get_rc_name(); - throw ParameterError(ss.str()); - } - } - string get_parameter(string parameter) { stringstream ss; + if (parameter == "foo") { ss << foo_; } @@ -77,10 +56,6 @@ class TestControllable : public RemoteControllable return ss.str(); } - std::list< std::vector<std::string> > get_parameter_descriptions() { - return parameters_; - } - private: long foo_; std::string bar_; |