11#include "LibCyberRadio/Driver/NDR551/TunerComponent.h"
12#include "LibCyberRadio/Driver/RadioHandler.h"
13#include <boost/format.hpp>
14#include <boost/lexical_cast.hpp>
32 (boost::format(
"NDR551-TUNER%02d") % \
49 this->
debug(
"[NDR551::TunerComponent] index - %d\n", index);
55 this->
debug(
"[TunerComponent::updateConfigurationDict] Called\n");
58 if ( _config.hasKey(
"frequency") )
62 if ( _config.hasKey(
"attenuation") )
66 if ( _config.hasKey(
"filter") )
70 if ( _config.hasKey(
"timingAdj") )
74 if ( _config.hasKey(
"if") )
78 if ( _config.hasKey(
"mode") )
82 this->
debug(
"[TunerComponent::updateConfigurationDict] Current configuration\n");
84 this->
debug(
"[TunerComponent::updateConfigurationDict] Returning\n");
89 this->
debug(
"[TunerComponent::setConfiguration] Called\n");
95 double adjFrequency = _frequency;
96 double adjAttenuation = _attenuation;
97 int adjFilter = _filter;
98 int adjAdj = _timingAdj;
99 unsigned int adjIf = _if;
100 bool freqCmdNeedsExecuting =
false;
101 bool attCmdNeedsExecuting =
false;
102 bool filCmdNeedsExecuting =
false;
103 bool adjCmdNeedsExecuting =
false;
104 bool ifCmdNeedsExecuting =
false;
105 if ( cfg.
hasKey(
"frequency") && _config.hasKey(
"frequency") )
108 freqCmdNeedsExecuting =
true;
110 if ( cfg.
hasKey(
"attenuation") && _config.hasKey(
"attenuation") )
113 attCmdNeedsExecuting =
true;
115 if ( cfg.
hasKey(
"filter") && _config.hasKey(
"filter") )
118 filCmdNeedsExecuting =
true;
120 if ( cfg.
hasKey(
"timingAdj") && _config.hasKey(
"timingAdj") )
123 adjCmdNeedsExecuting =
true;
125 if ( cfg.
hasKey(
"if") && _config.hasKey(
"if") )
128 ifCmdNeedsExecuting =
true;
130 if ( freqCmdNeedsExecuting )
134 if ( attCmdNeedsExecuting )
138 if ( filCmdNeedsExecuting )
142 if ( adjCmdNeedsExecuting )
146 if ( ifCmdNeedsExecuting )
148 ret &= executeCommand();
150 this->
debug(
"[TunerComponent::setConfiguration] Returning %s\n",
debugBool(ret));
157 _config[
"enable"] =
"";
158 _config[
"frequency"] =
"";
159 _config[
"attenuation"] =
"";
160 _config[
"mode"] =
"auto";
161 _config[
"if"] =
"80";
176 ::LibCyberRadio::Driver::TunerComponent::operator=(other);
177 if (
this != &other )
186 if ( (_parent != NULL) && (_parent->isConnected()) )
190 command[
"cmd"] =
"tuner";
191 command[
"msg"] = _parent->getMessageId();
192 command[
"params"] = Json::objectValue;
193 command[
"params"][
"id"] = index;
194 command[
"params"][
"freq"] = freq;
195 Json::FastWriter fastWriter;
196 std::string output = fastWriter.write(command);
199 Json::Value returnVal;
200 std::string t = rsp.at(0);
201 bool parsingSuccessful = reader.parse( t.c_str(), returnVal );
211 this->
debug(
"[TunerComponent::queryConfiguration] Called\n");
214 command[
"cmd"] =
"qtuner";
215 command[
"msg"] = _parent->getMessageId();
216 command[
"params"] = Json::objectValue;
217 command[
"params"][
"id"] = _index;
218 Json::FastWriter fastWriter;
219 std::string output = fastWriter.write(command);
222 Json::Value returnVal;
223 std::string t = rsp.at(0);
224 bool parsingSuccessful = reader.parse( t.c_str(), returnVal );
225 _enabled = boost::lexical_cast<bool>(returnVal[
"result"][
"enable"].asBool());
226 _frequency = boost::lexical_cast<double>(returnVal[
"result"][
"freq"].asDouble());
227 _attenuation = boost::lexical_cast<double>(returnVal[
"result"][
"atten"].asDouble());
228 _mode = boost::lexical_cast<std::string>(returnVal[
"result"][
"mode"].asString());
229 _if = boost::lexical_cast<unsigned int>(returnVal[
"result"][
"if"].asUInt());
231 this->
debug(
"[NDR551] [TunerComponent::queryConfiguration] Returning\n");
237 if ( (_parent != NULL) && (_parent->isConnected()) )
241 command[
"cmd"] =
"tuner";
242 command[
"msg"] = _parent->getMessageId();
243 command[
"params"] = Json::objectValue;
244 command[
"params"][
"id"] = index;
245 command[
"params"][
"enable"] = enabled;
246 Json::FastWriter fastWriter;
247 std::string output = fastWriter.write(command);
250 Json::Value returnVal;
251 std::string t = rsp.at(0);
252 bool parsingSuccessful = reader.parse( t.c_str(), returnVal );
253 ret = returnVal[
"success"].asBool();
261 if ( (_parent != NULL) && (_parent->isConnected()) )
265 command[
"cmd"] =
"tuner";
266 command[
"msg"] = _parent->getMessageId();
267 command[
"params"] = Json::objectValue;
268 command[
"params"][
"id"] = index;
269 command[
"params"][
"atten"] = atten;
270 Json::FastWriter fastWriter;
271 std::string output = fastWriter.write(command);
274 Json::Value returnVal;
275 std::string t = rsp.at(0);
276 bool parsingSuccessful = reader.parse( t.c_str(), returnVal );
277 ret = returnVal[
"success"].asBool();
282 bool TunerComponent::executeCommand(
void )
285 if ( (_parent != NULL) && (_parent->
isConnected()) )
289 command[
"cmd"] =
"tuner";
291 command[
"params"] = Json::objectValue;
292 command[
"params"][
"id"] = _index;
293 command[
"params"][
"atten"] = _attenuation;
294 command[
"params"][
"freq"] = _frequency;
296 command[
"mode"] = _mode;
297 Json::FastWriter fastWriter;
298 std::string output = fastWriter.write(command);
301 Json::Value returnVal;
302 std::string t = rsp.at(0);
303 bool parsingSuccessful = reader.parse( t.c_str(), returnVal );
304 ret = returnVal[
"success"].asBool();
virtual const char * debugBool(bool x)
Gets a debug output string for a Boolean value.
virtual int debug(const char *format,...)
Outputs debug information.
virtual int getConfigurationValueAsInt(const std::string &key) const
Gets a named configuration value as an integer value.
virtual double getConfigurationValueAsDbl(const std::string &key) const
Gets a named configuration value as a double value.
virtual bool setConfigurationValue(const std::string &key, const std::string &value)
Sets a named configuration value to a string.
virtual bool setConfigurationValueToUInt(const std::string &key, const unsigned int value)
Sets a named configuration value to an unsigned integer value.
virtual void dumpConfiguration()
Dumps this object's configuration dictionary to debug output.
virtual bool setConfigurationValueToInt(const std::string &key, const int value)
Sets a named configuration value to an integer value.
virtual bool setConfigurationValueToDbl(const std::string &key, const double value)
Sets a named configuration value to a double value.
A configuration dictionary.
virtual bool hasKey(const std::string &key) const
Determines if the dictionary has the given key.
bool executeFreqCommand(int index, double &freq) override
Executes the tuner frequency set command.
bool executeAttenCommand(int index, double &atten) override
Executes the tuner attenuation set command.
bool setConfiguration(ConfigurationDict &cfg) override
Sets the configuration dictionary for this component.
virtual TunerComponent & operator=(const TunerComponent &other)
Assignment operator for TunerComponent objects.
void queryConfiguration()
Tells the component to query its hardware configuration in order to create its configuration dictiona...
void initConfigurationDict() override
Initializes the configuration dictionary, defining the allowed keys.
TunerComponent(int index=1, ::LibCyberRadio::Driver::RadioHandler *parent=NULL, bool debug=false, double frequency=800e6, double attenuation=0.0, int filter=0)
Constructs a TunerComponent object.
virtual ~TunerComponent()
Destroys a TunerComponent object.
bool executeEnableCommand(int index, bool &enabled) override
Executes the tuner enable command.
void updateConfigurationDict() override
Updates the configuration dictionary from component settings.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this component.
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
Generic radio handler class.
virtual uint32_t getMessageId(void)
Get a json Message ID.
virtual bool isConnected() const
Gets whether or not the handler is connected.
virtual BasicStringList sendCommand(const std::string &cmdString, double timeout=-1)
Sends a command to the radio.
virtual bool executeTimingAdjustmentCommand(int index, int &timingAdj)
Executes the tuner timing adjustment command.
virtual bool executeFilterCommand(int index, int &filter)
Executes the tuner filter set command.
Provides programming elements for driving NDR551 radios.
Provides programming elements for driving CRS NDR-class radios.
Defines functionality for LibCyberRadio applications.
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.