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;
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";
378 enabled = (boost::lexical_cast<
int>(vec[1]) == 1);
390 if ( (_parent != NULL) && (_parent->
isConnected()) )
392 std::ostringstream oss;
393 oss <<
"FRQ? " << index <<
"\n";
402 freq = boost::lexical_cast<
int>(vec[1]) * _freqUnits;
413 if ( (_parent != NULL) && (_parent->
isConnected()) )
415 std::ostringstream oss;
416 oss <<
"ATT? " << index <<
"\n";
425 atten = boost::lexical_cast<
double>(vec[1]);
436 if ( (_parent != NULL) && (_parent->
isConnected()) )
438 std::ostringstream oss;
439 oss <<
"FIF? " << index <<
"\n";
448 filter = boost::lexical_cast<
int>(vec[1]);
458 if ( (_parent != NULL) && (_parent->
isConnected()) )
460 std::ostringstream oss;
461 oss <<
"TADJ? " << index <<
"\n";
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)
499 if ( (_parent != NULL) && (_parent->
isConnected()) )
501 std::ostringstream oss;
502 oss <<
"FRQ " << index
503 <<
", " << boost::lexical_cast<
int>(freq / _freqUnits)
508 freq = (int)(freq / _freqUnits) * _freqUnits;
519 if ( (_parent != NULL) && (_parent->
isConnected()) )
521 std::ostringstream oss;
522 oss <<
"ATT " << index
528 atten = (double)((
int)atten);
539 if ( (_parent != NULL) && (_parent->
isConnected()) )
541 std::ostringstream oss;
542 oss <<
"FIF " << index
557 if ( (_parent != NULL) && (_parent->
isConnected()) )
559 std::ostringstream oss;
560 oss <<
"TADJ " << index
virtual bool setTimingAdjustment(int timingAdj)
Sets the timing adjustment setting.
virtual bool executeFreqQuery(int index, double &freq)
Executes the tuner frequency query command.
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual TunerComponent & operator=(const TunerComponent &other)
Assignment operator for TunerComponent objects.
virtual bool executeTimingAdjustmentCommand(int index, int &timingAdj)
Executes the tuner timing adjustment command.
virtual bool executeAttenCommand(int index, double &atten)
Executes the tuner attenuation set command.
virtual double getAttenuationRes() const
Gets the attenuation resolution.
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual double getFrequencyUnit() const
Gets the tuned frequency units.
virtual bool setConfigurationValueToDbl(const std::string &key, const double value)
Sets a named configuration value to a double value.
virtual bool setFrequencyRangeMax(double freq)
Sets the maximum end of the tunable frequency range.
Base hardware component class.
virtual bool executeFilterCommand(int index, int &filter)
Executes the tuner filter set command.
virtual bool hasKey(const std::string &key) const
Determines if the dictionary has the given key.
virtual void queryConfiguration()
Tells the component to query its hardware configuration in order to create its configuration dictiona...
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 bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this component.
BASIC_LIST_CONTAINER< double > BasicDoubleList
Type representing a list of doubles.
virtual int getConfigurationValueAsInt(const std::string &key) const
Gets a named configuration value as an integer value.
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 BasicDoubleList getFrequencyRange() const
Gets the tunable frequency range.
virtual bool setFilter(int filter)
Sets the filter setting.
virtual double getAttenuation() const
Gets the attenuation.
virtual bool isConnected() const
Gets whether or not the handler is connected.
virtual RadioComponent & operator=(const RadioComponent &other)
Assignment operator for RadioComponent objects.
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.
virtual double getFrequency() const
Gets the tuned frequency.
virtual bool enable(bool enabled=true)
Enables this component.
virtual bool setAttenuation(double atten)
Sets the attenuation.
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.
virtual bool enable(bool enabled=true)
Enables this component.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this component.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
Generic radio handler class.
virtual int debug(const char *format,...)
Outputs debug information.
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.
virtual bool executeFilterQuery(int index, int &filter)
Executes the tuner filter query command.
virtual bool isAgcSupported() const
Gets whether or not the tuner supports AGC.
Defines functionality for LibCyberRadio applications.
virtual bool setFrequency(double freq)
Sets the tuned frequency.
A configuration dictionary.
virtual std::string getLastCommandErrorInfo() const
Gets the error message from the last command attempted.
virtual const char * debugBool(bool x)
Gets a debug output string for a Boolean value.
Base tuner component class.
virtual int getTimingAdjustment() const
Gets the timing adjustment setting.
virtual bool executeEnableCommand(int index, bool &enabled)
Executes the tuner enable command.
virtual BasicStringList sendCommand(const std::string &cmdString, double timeout=-1)
Sends a command to the radio.
virtual double getConfigurationValueAsDbl(const std::string &key) const
Gets a named configuration value as a double value.
virtual bool executeAttenQuery(int index, double &atten)
Executes the tuner attenuation query command.
virtual ~TunerComponent()
Destroys a TunerComponent object.
virtual bool executeFreqCommand(int index, double &freq)
Executes the tuner frequency set command.
virtual double getFrequencyRes() const
Gets the tuned frequency resolution.
virtual int getFilter() const
Gets the filter setting.
virtual bool setConfigurationValueToInt(const std::string &key, const int value)
Sets a named configuration value to an integer value.
virtual BasicDoubleList getAttenuationRange() const
Gets the attenuation range.