11 #include "LibCyberRadio/Driver/TransmitterComponent.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),
48 _numToneGen(numToneGen),
49 _toneGenIndexBase(toneGenIndexBase),
50 _frequency(frequency),
51 _attenuation(attenuation)
59 for ( CWToneGenComponentDict::iterator it = _cwToneGens.begin();
60 it != _cwToneGens.end(); it++)
68 _freqRangeMin(other._freqRangeMin),
69 _freqRangeMax(other._freqRangeMax),
70 _freqRes(other._freqRes),
71 _freqUnits(other._freqUnits),
72 _attRangeMin(other._attRangeMin),
73 _attRangeMax(other._attRangeMax),
74 _attRes(other._attRes),
75 _numToneGen(other._numToneGen),
76 _toneGenIndexBase(other._toneGenIndexBase),
77 _frequency(other._frequency),
78 _attenuation(other._attenuation)
87 _freqRangeMin = other._freqRangeMin;
88 _freqRangeMax = other._freqRangeMax;
89 _freqRes = other._freqRes;
90 _freqUnits = other._freqUnits;
91 _attRangeMin = other._attRangeMin;
92 _attRangeMax = other._attRangeMax;
93 _attRes = other._attRes;
94 _numToneGen = other._numToneGen;
95 _toneGenIndexBase = other._toneGenIndexBase;
96 _frequency = other._frequency;
97 _attenuation = other._attenuation;
104 bool adjEnabled = enabled;
106 if ( _config.
hasKey(
"enable") )
120 this->
debug(
"[TransmitterComponent::setConfiguration] Called\n");
126 if ( cfg.
hasKey(
"frequency") && _config.
hasKey(
"frequency") )
130 double inFreq = boost::lexical_cast<
double>( cfg[
"frequency"] );
134 catch(std::exception& ex)
142 if ( cfg.
hasKey(
"attenuation") && _config.
hasKey(
"attenuation") )
146 double inAtten = boost::lexical_cast<
double>( cfg[
"attenuation"] );
150 catch(std::exception& ex)
158 this->
debug(
"[TransmitterComponent::setConfiguration] Returning %s\n",
debugBool(ret));
164 this->
debug(
"[TransmitterComponent::queryConfiguration] Called\n");
165 if ( _config.
hasKey(
"enable") )
169 if ( _config.
hasKey(
"frequency") )
173 if ( _config.
hasKey(
"attenuation") )
179 for ( CWToneGenComponentDict::iterator it = _cwToneGens.begin();
180 it != _cwToneGens.end(); it++)
182 it->second->queryConfiguration();
184 this->
debug(
"[TransmitterComponent::queryConfiguration] Returning\n");
194 double adjFreq = freq;
196 if ( _config.
hasKey(
"frequency") )
201 _frequency = adjFreq;
215 double adjAtten = atten;
217 if ( _config.
hasKey(
"attenuation") )
222 _attenuation = adjAtten;
232 ret.push_back(_freqRangeMin);
233 ret.push_back(_freqRangeMax);
250 ret.push_back(_attRangeMin);
251 ret.push_back(_attRangeMax);
262 return ( _numToneGen > 0 );
273 for (
int num = _toneGenIndexBase; num < _toneGenIndexBase + _numToneGen;
282 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
283 if ( it != _cwToneGens.end() )
284 ret = it->second->getFrequencyRange();
291 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
292 if ( it != _cwToneGens.end() )
293 ret = it->second->getFrequencyRes();
300 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
301 if ( it != _cwToneGens.end() )
302 ret = it->second->getAmplitudeRange();
309 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
310 if ( it != _cwToneGens.end() )
311 ret = it->second->getAmplitudeRes();
318 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
319 if ( it != _cwToneGens.end() )
320 ret = it->second->getPhaseRange();
327 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
328 if ( it != _cwToneGens.end() )
329 ret = it->second->getPhaseRes();
336 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
337 if ( it != _cwToneGens.end() )
338 ret = it->second->supportsSweep();
345 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
346 if ( it != _cwToneGens.end() )
347 ret = it->second->getSweepStartRange();
354 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
355 if ( it != _cwToneGens.end() )
356 ret = it->second->getSweepStartRes();
363 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
364 if ( it != _cwToneGens.end() )
365 ret = it->second->getSweepStopRange();
372 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
373 if ( it != _cwToneGens.end() )
374 ret = it->second->getSweepStopRes();
381 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
382 if ( it != _cwToneGens.end() )
383 ret = it->second->getSweepStepRange();
390 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
391 if ( it != _cwToneGens.end() )
392 ret = it->second->getSweepStepRes();
399 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
400 if ( it != _cwToneGens.end() )
401 ret = it->second->getDwellTimeRange();
408 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
409 if ( it != _cwToneGens.end() )
410 ret = it->second->getDwellTimeRes();
417 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
418 if ( it != _cwToneGens.end() )
419 ret = it->second->enable(enabled);
431 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
432 if ( it != _cwToneGens.end() )
433 ret = it->second->getConfiguration();
440 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
441 if ( it != _cwToneGens.end() )
442 ret = it->second->setConfiguration(cfg);
449 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
450 if ( it != _cwToneGens.end() )
451 ret = it->second->getFrequency();
458 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
459 if ( it != _cwToneGens.end() )
460 ret = it->second->setFrequency(freq);
467 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
468 if ( it != _cwToneGens.end() )
469 ret = it->second->getAmplitude();
476 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
477 if ( it != _cwToneGens.end() )
478 ret = it->second->setAmplitude(amp);
485 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
486 if ( it != _cwToneGens.end() )
487 ret = it->second->getPhase();
494 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
495 if ( it != _cwToneGens.end() )
496 ret = it->second->setPhase(phase);
503 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
504 if ( it != _cwToneGens.end() )
505 ret = it->second->supportsSweep();
512 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
513 if ( it != _cwToneGens.end() )
514 ret = it->second->getSweepStartFrequency();
521 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
522 if ( it != _cwToneGens.end() )
523 ret = it->second->getSweepStopFrequency();
530 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
531 if ( it != _cwToneGens.end() )
532 ret = it->second->getSweepFrequencyStep();
539 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
540 if ( it != _cwToneGens.end() )
541 ret = it->second->getSweepDwellTime();
546 double stop,
double step,
550 CWToneGenComponentDict::const_iterator it = _cwToneGens.begin();
551 if ( it != _cwToneGens.end() )
552 ret = it->second->setFrequencySweep(start, stop, step, dwell);
563 _config[
"frequency"] =
"";
564 _config[
"attenuation"] =
"";
570 this->
debug(
"[TransmitterComponent::updateConfigurationDict] Called\n");
572 if ( _config.
hasKey(
"frequency") )
576 if ( _config.
hasKey(
"attenuation") )
580 this->
debug(
"[TransmitterComponent::updateConfigurationDict] Returning\n");
587 if ( (_parent != NULL) && (_parent->
isConnected()) )
589 std::ostringstream oss;
590 oss <<
"TXP? " << index <<
"\n";
599 enabled = (boost::lexical_cast<
int>(vec[1]) == 1);
611 if ( (_parent != NULL) && (_parent->
isConnected()) )
613 std::ostringstream oss;
614 oss <<
"TXF? " << index <<
"\n";
623 freq = boost::lexical_cast<
double>(vec[1]) * _freqUnits;
634 if ( (_parent != NULL) && (_parent->
isConnected()) )
636 std::ostringstream oss;
637 oss <<
"TXA? " << index <<
"\n";
646 atten = boost::lexical_cast<
double>(vec[1]);
657 if ( (_parent != NULL) && (_parent->
isConnected()) )
659 std::ostringstream oss;
660 oss <<
"TXP " << index
661 <<
", " << (enabled ? 1 : 0)
676 if ( (_parent != NULL) && (_parent->
isConnected()) )
678 std::ostringstream oss;
679 oss <<
"TXF " << index
680 <<
", " << std::setprecision(6) << std::fixed << (freq / _freqUnits)
685 freq = (freq / _freqUnits);
696 if ( (_parent != NULL) && (_parent->
isConnected()) )
698 std::ostringstream oss;
699 oss <<
"TXA " << index
700 <<
", " << std::setprecision(1) << std::fixed << atten
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual bool executeFreqCommand(int index, double &freq)
Executes the tuner frequency set command.
virtual bool setCWConfiguration(int index, ConfigurationDict &cfg)
Sets the configuration dictionary for a given CW tone generator.
virtual double getCWAmplitude(int index) const
Gets the signal amplitude for a given CW tone generator.
virtual bool setFrequency(double freq)
Sets the transmitter center frequency.
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual bool supportsCWSweep() const
Gets whether the transmitter supports CW tone sweeping.
virtual bool executeAttenQuery(int index, double &atten)
Executes the tuner attenuation query command.
virtual bool setConfigurationValueToDbl(const std::string &key, const double value)
Sets a named configuration value to a double value.
virtual BasicIntList getCWIndexRange() const
Gets the range of indices for CW tone generators.
Base transmitter component class.
virtual double getCWFrequency(int index) const
Gets the constant frequency for a given CW tone generator.
Base hardware component class.
virtual bool hasKey(const std::string &key) const
Determines if the dictionary has the given key.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this component.
virtual BasicDoubleList getCWPhaseRange() const
Gets the CW phase range.
virtual bool enableCW(int index, bool enabled=true)
Enables a given CW tone generator.
BASIC_LIST_CONTAINER< double > BasicDoubleList
Type representing a list of doubles.
virtual bool executeEnableCommand(int index, bool &enabled)
Executes the tuner enable command.
virtual double getFrequency() const
Gets the transmitter center frequency.
virtual double getCWSweepFrequencyStep(int index) const
Gets the frequency step for a signal sweep for a given CW tone generator.
virtual double getCWSweepDwellTime(int index) const
Gets the dwell time for a signal sweep for a given CW tone generator.
virtual bool setCWPhase(int index, double phase)
Sets the signal phase for a given CW tone generator.
virtual double getCWSweepStartRes() const
Gets the CW start frequency resolution.
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 getCWSweepStopRes() const
Gets the CW stop frequency resolution.
virtual double getCWFrequencyRes() const
Gets the CW frequency resolution.
virtual BasicDoubleList getFrequencyRange() const
Gets the transmitter center frequency range.
virtual bool setCWFrequency(int index, double freq)
Sets the constant frequency for a given CW tone generator.
virtual double getCWSweepStartFrequency(int index) const
Gets the start frequency for a signal sweep for a given CW tone generator.
virtual void queryConfiguration()
Tells the component to query its hardware configuration in order to create its configuration dictiona...
virtual double getCWSweepDwellRes() const
Gets the CW dwell time resolution.
virtual bool setCWAmplitude(int index, double amp)
Sets the signal amplitude for a given CW tone generator.
virtual bool setCWFrequencySweep(int index, double start, double stop, double step, double dwell)
Sets the parameters for a frequency sweep for a given CW tone generator.
virtual BasicDoubleList getCWSweepStopRange() const
Gets the CW stop frequency range.
virtual bool enable(bool enabled=true)
Enables this component.
TransmitterComponent(const std::string &name="TX", 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=10.0, double attRes=1.0, int numToneGen=0, int toneGenIndexBase=1, double frequency=900e6, double attenuation=0.0)
Constructs a TransmitterComponent object.
virtual BasicDoubleList getCWAmplitudeRange() const
Gets the CW amplitude range.
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 double getCWSweepStopFrequency(int index) const
Gets the stop frequency for a signal sweep for a given CW tone generator.
virtual BasicDoubleList getCWSweepStepRange() const
Gets the CW frequency step range.
virtual int getCWNum() const
Gets the number of CW tone generators associated with this transmitter.
Generic radio handler class.
virtual bool disableCW(int index)
Disables a given CW tone generator.
virtual int debug(const char *format,...)
Outputs debug information.
virtual ConfigurationDict getCWConfiguration(int index) const
Gets the configuration for a given CW tone generator.
virtual double getCWAmplitudeRes() const
Gets the CW amplitude resolution.
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.
virtual bool supportsCW() const
Gets whether the transmitter supports CW tone generation.
virtual BasicDoubleList getCWSweepStartRange() const
Gets the CW start frequency range.
virtual bool executeEnableQuery(int index, bool &enabled)
Executes the tuner enabled query command.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
virtual ~TransmitterComponent()
Destroys a TransmitterComponent object.
Defines functionality for LibCyberRadio applications.
virtual double getAttenuation() const
Gets the attenuation.
virtual BasicDoubleList getAttenuationRange() const
Gets the attenuation range.
virtual bool executeAttenCommand(int index, double &atten)
Executes the tuner attenuation set command.
A configuration dictionary.
virtual double getCWPhaseRes() const
Gets the CW phase resolution.
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.
virtual TransmitterComponent & operator=(const TransmitterComponent &other)
Assignment operator for TransmitterComponent objects.
virtual double getAttenuationRes() const
Gets the attenuation resolution.
virtual BasicStringList sendCommand(const std::string &cmdString, double timeout=-1)
Sends a command to the radio.
virtual BasicDoubleList getCWSweepDwellRange() const
Gets the CW dwell time range.
BASIC_LIST_CONTAINER< int > BasicIntList
Type representing a list of integers.
virtual bool executeFreqQuery(int index, double &freq)
Executes the tuner frequency query command.
virtual bool enable(bool enabled=true)
Enables this component.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this component.
virtual double getFrequencyUnit() const
Gets the transmitter center frequency units.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
virtual double getFrequencyRes() const
Gets the transmitter center frequency resolution.
virtual BasicDoubleList getCWFrequencyRange() const
Gets the CW frequency range.
virtual double getCWSweepStepRes() const
Gets the CW frequency step resolution.
virtual double getCWPhase(int index) const
Gets the signal phase for a given CW tone generator.