11#include "LibCyberRadio/Driver/TunerComponent.h"
12#include "LibCyberRadio/Driver/RadioHandler.h"
13#include "LibCyberRadio/Common/Pythonesque.h"
14#include <boost/lexical_cast.hpp>
25 const std::string& name,
41 _freqRangeMin(freqRangeMin),
42 _freqRangeMax(freqRangeMax),
44 _freqUnits(freqUnits),
45 _attRangeMin(attRangeMin),
46 _attRangeMax(attRangeMax),
49 _frequency(frequency),
50 _attenuation(attenuation),
64 _freqRangeMin(other._freqRangeMin),
65 _freqRangeMax(other._freqRangeMax),
66 _freqRes(other._freqRes),
67 _freqUnits(other._freqUnits),
68 _attRangeMin(other._attRangeMin),
69 _attRangeMax(other._attRangeMax),
70 _attRes(other._attRes),
72 _frequency(other._frequency),
73 _attenuation(other._attenuation),
74 _filter(other._filter),
75 _timingAdj(other._timingAdj)
84 _freqRangeMin = other._freqRangeMin;
85 _freqRangeMax = other._freqRangeMax;
86 _freqRes = other._freqRes;
87 _freqUnits = other._freqUnits;
88 _attRangeMin = other._attRangeMin;
89 _attRangeMax = other._attRangeMax;
90 _attRes = other._attRes;
92 _frequency = other._frequency;
93 _attenuation = other._attenuation;
94 _filter = other._filter;
95 _timingAdj = other._timingAdj;
102 bool adjEnabled = enabled;
104 if ( _config.hasKey(
"enable") )
118 this->
debug(
"[TunerComponent::setConfiguration] Called\n");
124 double adjFrequency = _frequency;
125 double adjAttenuation = _attenuation;
126 int adjFilter = _filter;
127 int adjAdj = _timingAdj;
128 bool freqCmdNeedsExecuting =
false;
129 bool attCmdNeedsExecuting =
false;
130 bool filCmdNeedsExecuting =
false;
131 bool adjCmdNeedsExecuting =
false;
132 if ( cfg.
hasKey(
"frequency") && _config.hasKey(
"frequency") )
135 freqCmdNeedsExecuting =
true;
137 if ( cfg.
hasKey(
"attenuation") && _config.hasKey(
"attenuation") )
140 attCmdNeedsExecuting =
true;
142 if ( cfg.
hasKey(
"filter") && _config.hasKey(
"filter") )
145 filCmdNeedsExecuting =
true;
147 if ( cfg.
hasKey(
"timingAdj") && _config.hasKey(
"timingAdj") )
150 adjCmdNeedsExecuting =
true;
152 if ( freqCmdNeedsExecuting )
156 if ( attCmdNeedsExecuting )
160 if ( filCmdNeedsExecuting )
164 if ( adjCmdNeedsExecuting )
168 this->
debug(
"[TunerComponent::setConfiguration] Returning %s\n",
debugBool(ret));
174 this->
debug(
"[TunerComponent::queryConfiguration] Called\n");
175 if ( _config.hasKey(
"enable") )
179 if ( _config.hasKey(
"frequency") )
183 if ( _config.hasKey(
"attenuation") )
187 if ( _config.hasKey(
"filter") )
191 if ( _config.hasKey(
"timingAdj") )
196 this->
debug(
"[TunerComponent::queryConfiguration] Returning\n");
206 double adjFreq = freq;
208 if ( _config.hasKey(
"frequency") )
213 _frequency = adjFreq;
227 double adjAtten = atten;
229 if ( _config.hasKey(
"attenuation") )
234 _attenuation = adjAtten;
248 int adjFilter = filter;
250 if ( _config.hasKey(
"filter") )
269 int adjAdj = timingAdj;
271 if ( _config.hasKey(
"timingAdj") )
286 ret.push_back(_freqRangeMin);
287 ret.push_back(_freqRangeMax);
304 ret.push_back(_attRangeMin);
305 ret.push_back(_attRangeMax);
321 _freqRangeMax = freq;
329 _config[
"enable"] =
"";
330 _config[
"frequency"] =
"";
331 _config[
"attenuation"] =
"";
332 _config[
"filter"] =
"";
333 _config[
"timingAdj"] =
"";
339 this->
debug(
"[TunerComponent::updateConfigurationDict] Called\n");
342 if ( _config.hasKey(
"frequency") )
346 if ( _config.hasKey(
"attenuation") )
350 if ( _config.hasKey(
"filter") )
354 if ( _config.hasKey(
"timingAdj") )
360 this->
debug(
"[TunerComponent::updateConfigurationDict] Returning\n");
366 if ( (_parent != NULL) && (_parent->isConnected()) )
368 std::ostringstream oss;
369 oss <<
"TPWR? " << index <<
"\n";
371 if ( _parent->getLastCommandErrorInfo() ==
"" )
378 enabled = (boost::lexical_cast<int>(vec[1]) == 1);
390 if ( (_parent != NULL) && (_parent->isConnected()) )
392 std::ostringstream oss;
393 oss <<
"FRQ? " << index <<
"\n";
395 if ( _parent->getLastCommandErrorInfo() ==
"" )
402 freq = boost::lexical_cast<int>(vec[1]) * _freqUnits;
413 if ( (_parent != NULL) && (_parent->isConnected()) )
415 std::ostringstream oss;
416 oss <<
"ATT? " << index <<
"\n";
418 if ( _parent->getLastCommandErrorInfo() ==
"" )
425 atten = boost::lexical_cast<double>(vec[1]);
436 if ( (_parent != NULL) && (_parent->isConnected()) )
438 std::ostringstream oss;
439 oss <<
"FIF? " << index <<
"\n";
441 if ( _parent->getLastCommandErrorInfo() ==
"" )
448 filter = boost::lexical_cast<int>(vec[1]);
458 if ( (_parent != NULL) && (_parent->isConnected()) )
460 std::ostringstream oss;
461 oss <<
"TADJ? " << index <<
"\n";
463 if ( _parent->getLastCommandErrorInfo() ==
"" )
470 timingAdj = boost::lexical_cast<int>(vec[1]);
480 if ( (_parent != NULL) && (_parent->isConnected()) )
482 std::ostringstream oss;
483 oss <<
"TPWR " << index
484 <<
", " << (enabled ? 1 : 0)
487 if ( _parent->getLastCommandErrorInfo() ==
"" )
499 if ( (_parent != NULL) && (_parent->isConnected()) )
501 std::ostringstream oss;
502 oss <<
"FRQ " << index
503 <<
", " << boost::lexical_cast<int>(freq / _freqUnits)
506 if ( _parent->getLastCommandErrorInfo() ==
"" )
508 freq = (int)(freq / _freqUnits) * _freqUnits;
519 if ( (_parent != NULL) && (_parent->isConnected()) )
521 std::ostringstream oss;
522 oss <<
"ATT " << index
526 if ( _parent->getLastCommandErrorInfo() ==
"" )
528 atten = (double)((
int)atten);
539 if ( (_parent != NULL) && (_parent->isConnected()) )
541 std::ostringstream oss;
542 oss <<
"FIF " << index
546 if ( _parent->getLastCommandErrorInfo() ==
"" )
557 if ( (_parent != NULL) && (_parent->isConnected()) )
559 std::ostringstream oss;
560 oss <<
"TADJ " << index
564 if ( _parent->getLastCommandErrorInfo() ==
"" )
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 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.
virtual bool enable(bool enabled=true)
Enables this component.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this component.
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual RadioComponent & operator=(const RadioComponent &other)
Assignment operator for RadioComponent objects.
RadioComponent(const std::string &name="<unknown>", int index=0, RadioHandler *parent=NULL, bool debug=false)
Constructs a RadioComponent object.
Generic radio handler class.
virtual bool enable(bool enabled=true)
Enables this component.
virtual int getTimingAdjustment() const
Gets the timing adjustment setting.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this component.
virtual int getFilter() const
Gets the filter setting.
TunerComponent(const std::string &name="TUNER", int index=1, RadioHandler *parent=NULL, bool debug=false, double freqRangeMin=20e6, double freqRangeMax=6000e6, double freqRes=1e6, double freqUnits=1e6, double attRangeMin=0.0, double attRangeMax=30.0, double attRes=1.0, bool agc=false, double frequency=800e6, double attenuation=0.0, int filter=0)
Constructs a TunerComponent object.
virtual double getAttenuation() const
Gets the attenuation.
virtual bool setAttenuation(double atten)
Sets the attenuation.
virtual bool executeEnableCommand(int index, bool &enabled)
Executes the tuner enable command.
virtual BasicDoubleList getFrequencyRange() const
Gets the tunable frequency range.
virtual bool setFrequency(double freq)
Sets the tuned frequency.
virtual bool executeAttenCommand(int index, double &atten)
Executes the tuner attenuation set command.
virtual bool isAgcSupported() const
Gets whether or not the tuner supports AGC.
virtual double getFrequency() const
Gets the tuned frequency.
virtual bool executeFreqCommand(int index, double &freq)
Executes the tuner frequency set command.
virtual bool executeTimingAdjustmentCommand(int index, int &timingAdj)
Executes the tuner timing adjustment command.
virtual BasicDoubleList getAttenuationRange() const
Gets the attenuation range.
virtual TunerComponent & operator=(const TunerComponent &other)
Assignment operator for TunerComponent objects.
virtual void queryConfiguration()
Tells the component to query its hardware configuration in order to create its configuration dictiona...
virtual bool setTimingAdjustment(int timingAdj)
Sets the timing adjustment setting.
virtual bool executeFreqQuery(int index, double &freq)
Executes the tuner frequency query command.
virtual bool executeFilterQuery(int index, int &filter)
Executes the tuner filter query command.
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual double getAttenuationRes() const
Gets the attenuation resolution.
virtual bool setFrequencyRangeMax(double freq)
Sets the maximum end of the tunable frequency range.
virtual bool setFilter(int filter)
Sets the filter setting.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
virtual bool executeEnableQuery(int index, bool &enabled)
Executes the tuner enabled query command.
virtual bool executeTimingAdjustmentQuery(int index, int &timingAdj)
Executes the tuner timing adjustment query.
virtual double getFrequencyUnit() const
Gets the tuned frequency units.
virtual ~TunerComponent()
Destroys a TunerComponent object.
virtual bool executeFilterCommand(int index, int &filter)
Executes the tuner filter set command.
virtual bool executeAttenQuery(int index, double &atten)
Executes the tuner attenuation query command.
virtual double getFrequencyRes() const
Gets the tuned frequency resolution.
static BasicStringList Split(const std::string &str, const std::string &sep, int maxsplit=INT_MAX)
Splits the given string into a list of string tokens.
static std::string Replace(const std::string &str, const std::string &oldstr, const std::string &newstr, int count=INT_MAX)
Replaces occurrences of one substring with another within the given string.
Provides programming elements for driving CRS NDR-class radios.
Defines functionality for LibCyberRadio applications.
BASIC_LIST_CONTAINER< double > BasicDoubleList
Type representing a list of doubles.
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.