12 #include "LibCyberRadio/Driver/CWToneGenComponent.h" 13 #include "LibCyberRadio/Driver/RadioHandler.h" 14 #include "LibCyberRadio/Common/Pythonesque.h" 15 #include <boost/lexical_cast.hpp> 28 const std::string& name,
43 double sweepStartRangeMin,
44 double sweepStartRangeMax,
46 double sweepStopRangeMin,
47 double sweepStopRangeMax,
49 double sweepStepRangeMin,
50 double sweepStepRangeMax,
52 double dwellTimeRangeMin,
53 double dwellTimeRangeMax,
65 _freqRangeMin(freqRangeMin),
66 _freqRangeMax(freqRangeMax),
68 _freqUnits(freqUnits),
69 _ampRangeMin(ampRangeMin),
70 _ampRangeMax(ampRangeMax),
72 _phaseRangeMin(phaseRangeMin),
73 _phaseRangeMax(phaseRangeMax),
75 _sweepStartRangeMin(sweepStartRangeMin),
76 _sweepStartRangeMax(sweepStartRangeMax),
77 _sweepStartRes(sweepStartRes),
78 _sweepStopRangeMin(sweepStopRangeMin),
79 _sweepStopRangeMax(sweepStopRangeMax),
80 _sweepStopRes(sweepStopRes),
81 _sweepStepRangeMin(sweepStepRangeMin),
82 _sweepStepRangeMax(sweepStepRangeMax),
83 _sweepStepRes(sweepStepRes),
84 _dwellTimeRangeMin(dwellTimeRangeMin),
85 _dwellTimeRangeMax(dwellTimeRangeMax),
86 _dwellTimeRes(dwellTimeRes),
87 _frequency(frequency),
88 _amplitude(amplitude),
90 _sweepStart(sweepStart),
91 _sweepStop(sweepStop),
92 _sweepStep(sweepStep),
106 _txIndex(other._txIndex),
107 _freqRangeMin(other._freqRangeMin),
108 _freqRangeMax(other._freqRangeMax),
109 _freqRes(other._freqRes),
110 _freqUnits(other._freqUnits),
111 _ampRangeMin(other._ampRangeMin),
112 _ampRangeMax(other._ampRangeMax),
113 _ampRes(other._ampRes),
114 _phaseRangeMin(other._phaseRangeMin),
115 _phaseRangeMax(other._phaseRangeMax),
116 _phaseRes(other._phaseRes),
117 _sweepStartRangeMin(other._sweepStartRangeMin),
118 _sweepStartRangeMax(other._sweepStartRangeMax),
119 _sweepStartRes(other._sweepStartRes),
120 _sweepStopRangeMin(other._sweepStopRangeMin),
121 _sweepStopRangeMax(other._sweepStopRangeMax),
122 _sweepStopRes(other._sweepStopRes),
123 _sweepStepRangeMin(other._sweepStepRangeMin),
124 _sweepStepRangeMax(other._sweepStepRangeMax),
125 _sweepStepRes(other._sweepStepRes),
126 _dwellTimeRangeMin(other._dwellTimeRangeMin),
127 _dwellTimeRangeMax(other._dwellTimeRangeMax),
128 _dwellTimeRes(other._dwellTimeRes),
129 _frequency(other._frequency),
130 _amplitude(other._amplitude),
131 _phase(other._phase),
132 _sweepStart(other._sweepStart),
133 _sweepStop(other._sweepStop),
134 _sweepStep(other._sweepStep),
135 _dwellTime(other._dwellTime)
143 if (
this != &other )
145 _txIndex = other._txIndex;
146 _freqRangeMin = other._freqRangeMin;
147 _freqRangeMax = other._freqRangeMax;
148 _freqRes = other._freqRes;
149 _freqUnits = other._freqUnits;
150 _ampRangeMin = other._ampRangeMin;
151 _ampRangeMax = other._ampRangeMax;
152 _ampRes = other._ampRes;
153 _phaseRangeMin = other._phaseRangeMin;
154 _phaseRangeMax = other._phaseRangeMax;
155 _phaseRes = other._phaseRes;
156 _sweepStartRangeMin = other._sweepStartRangeMin;
157 _sweepStartRangeMax = other._sweepStartRangeMax;
158 _sweepStartRes = other._sweepStartRes;
159 _sweepStopRangeMin = other._sweepStopRangeMin;
160 _sweepStopRangeMax = other._sweepStopRangeMax;
161 _sweepStopRes = other._sweepStopRes;
162 _sweepStepRangeMin = other._sweepStepRangeMin;
163 _sweepStepRangeMax = other._sweepStepRangeMax;
164 _sweepStepRes = other._sweepStepRes;
165 _dwellTimeRangeMin = other._dwellTimeRangeMin;
166 _dwellTimeRangeMax = other._dwellTimeRangeMax;
167 _dwellTimeRes = other._dwellTimeRes;
168 _frequency = other._frequency;
169 _amplitude = other._amplitude;
170 _phase = other._phase;
171 _sweepStart = other._sweepStart;
172 _sweepStop = other._sweepStop;
173 _sweepStep = other._sweepStep;
174 _dwellTime = other._dwellTime;
186 this->
debug(
"[CWToneGenComponent::setConfiguration] Called\n");
193 double adjFrequency = _frequency;
194 double adjAmplitude = _amplitude;
195 double adjPhase = _phase;
196 double adjStart = _sweepStart;
197 double adjStop = _sweepStop;
198 double adjStep = _sweepStep;
199 double adjDwell = _dwellTime;
200 bool adjEnabled = _enabled;
201 bool toneCmdNeedsExecuting =
false;
202 bool sweepCmdNeedsExecuting =
false;
206 toneCmdNeedsExecuting =
true;
208 if ( cfg.
hasKey(
"cwFrequency") && _config.
hasKey(
"cwFrequency") )
211 toneCmdNeedsExecuting =
true;
213 if ( cfg.
hasKey(
"cwAmplitude") && _config.
hasKey(
"cwAmplitude") )
216 toneCmdNeedsExecuting =
true;
218 if ( cfg.
hasKey(
"cwPhase") && _config.
hasKey(
"cwPhase") )
221 toneCmdNeedsExecuting =
true;
223 if ( cfg.
hasKey(
"cwSweepStart") && _config.
hasKey(
"cwSweepStart") )
226 sweepCmdNeedsExecuting =
true;
228 if ( cfg.
hasKey(
"cwSweepStop") && _config.
hasKey(
"cwSweepStop") )
231 sweepCmdNeedsExecuting =
true;
233 if ( cfg.
hasKey(
"cwSweepStep") && _config.
hasKey(
"cwSweepStep") )
236 sweepCmdNeedsExecuting =
true;
238 if ( cfg.
hasKey(
"cwSweepDwell") && _config.
hasKey(
"cwSweepDwell") )
241 sweepCmdNeedsExecuting =
true;
243 if ( toneCmdNeedsExecuting )
248 if ( sweepCmdNeedsExecuting )
255 _enabled = adjEnabled;
256 _frequency = adjFrequency;
257 _amplitude = adjAmplitude;
259 _sweepStart = adjStart;
260 _sweepStop = adjStop;
261 _sweepStep = adjStep;
262 _dwellTime = adjDwell;
265 this->
debug(
"[CWToneGenComponent::setConfiguration] Returning\n");
271 this->
debug(
"[CWToneGenComponent::queryConfiguration] Called\n");
272 if ( _config.
hasKey(
"cwFrequency") &&
273 _config.
hasKey(
"cwAmplitude") &&
274 _config.
hasKey(
"cwPhase") )
278 if ( _config.
hasKey(
"cwSweepStart") &&
279 _config.
hasKey(
"cwSweepStop") &&
280 _config.
hasKey(
"cwSweepStep") &&
281 _config.
hasKey(
"cwSweepDwell") )
286 _enabled = (_amplitude != 0);
288 this->
debug(
"[CWToneGenComponent::queryConfiguration] Returning\n");
294 ret.push_back(_freqRangeMin);
295 ret.push_back(_freqRangeMax);
307 ret.push_back(_ampRangeMin);
308 ret.push_back(_ampRangeMax);
320 ret.push_back(_phaseRangeMin);
321 ret.push_back(_phaseRangeMax);
333 ret.push_back(_sweepStartRangeMin);
334 ret.push_back(_sweepStartRangeMax);
340 return _sweepStartRes;
346 ret.push_back(_sweepStopRangeMin);
347 ret.push_back(_sweepStopRangeMax);
353 return _sweepStopRes;
359 ret.push_back(_sweepStepRangeMin);
360 ret.push_back(_sweepStepRangeMax);
366 return _sweepStepRes;
372 ret.push_back(_dwellTimeRangeMin);
373 ret.push_back(_dwellTimeRangeMax);
379 return _dwellTimeRes;
390 if ( _config.
hasKey(
"frequency") )
392 double adjFrequency = freq;
393 double adjAmplitude = _amplitude;
394 double adjPhase = _phase;
398 _frequency = adjFrequency;
413 if ( _config.
hasKey(
"cwAmplitude") )
415 double adjFrequency = _frequency;
416 double adjAmplitude = amp;
417 double adjPhase = _phase;
421 _amplitude = adjAmplitude;
422 _enabled = (_amplitude != 0);
437 if ( _config.
hasKey(
"cwPhase") )
439 double adjFrequency = _frequency;
440 double adjAmplitude = _amplitude;
441 double adjPhase = phase;
454 bool ret = ( _sweepStartRangeMin != _sweepStartRangeMax );
479 double step,
double dwell)
482 if ( _config.
hasKey(
"cwSweepStart") &&
483 _config.
hasKey(
"cwSweepStop") &&
484 _config.
hasKey(
"cwSweepStep") &&
485 _config.
hasKey(
"cwSweepDwell") )
487 double adjStart = start;
488 double adjStop = stop;
489 double adjStep = step;
490 double adjDwell = dwell;
495 _sweepStart = adjStart;
496 _sweepStop = adjStop;
497 _sweepStep = adjStep;
498 _dwellTime = adjDwell;
512 _config[
"cwFrequency"] =
"0";
513 _config[
"cwAmplitude"] =
"0";
514 _config[
"cwPhase"] =
"0";
515 _config[
"cwSweepStart"] =
"0";
516 _config[
"cwSweepStop"] =
"0";
517 _config[
"cwSweepStep"] =
"0";
518 _config[
"cwSweepDwell"] =
"0";
524 this->
debug(
"[CWToneGenComponent::updateConfigurationDict] Called\n");
526 if ( _config.
hasKey(
"cwFrequency") )
528 if ( _config.
hasKey(
"cwAmplitude") )
530 if ( _config.
hasKey(
"cwPhase") )
532 if ( _config.
hasKey(
"cwSweepStart") )
534 if ( _config.
hasKey(
"cwSweepStop") )
536 if ( _config.
hasKey(
"cwSweepStep") )
538 if ( _config.
hasKey(
"cwSweepDwell") )
540 this->
debug(
"[CWToneGenComponent::updateConfigurationDict] Returning\n");
551 if ( (_parent != NULL) && (_parent->
isConnected()) )
553 std::ostringstream oss;
554 oss <<
"CWT? " << txIndex <<
", " << index <<
"\n";
564 freq = boost::lexical_cast<
double>(vec[2]);
566 amp = boost::lexical_cast<
double>(vec[3]);
568 phase = boost::lexical_cast<
double>(vec[4]);
583 if ( (_parent != NULL) && (_parent->
isConnected()) )
585 std::ostringstream oss;
586 oss <<
"CWT " << txIndex
588 <<
", " << std::setprecision(1) << std::fixed << freq
589 <<
", " << std::setprecision(1) << std::fixed << amp
590 <<
", " << std::setprecision(1) << std::fixed << phase
610 if ( (_parent != NULL) && (_parent->
isConnected()) )
612 std::ostringstream oss;
613 oss <<
"CWS? " << txIndex <<
", " << index <<
"\n";
623 sweepStart = boost::lexical_cast<
double>(vec[2]);
625 sweepStop = boost::lexical_cast<
double>(vec[3]);
627 sweepStep = boost::lexical_cast<
double>(vec[4]);
629 dwellTime = boost::lexical_cast<
double>(vec[5]);
645 if ( (_parent != NULL) && (_parent->
isConnected()) )
647 std::ostringstream oss;
648 oss <<
"CWS " << txIndex
650 <<
", " << std::setprecision(1) << std::fixed << sweepStart
651 <<
", " << std::setprecision(1) << std::fixed << sweepStop
652 <<
", " << std::setprecision(1) << std::fixed << sweepStep
653 <<
", " << std::setprecision(1) << std::fixed << dwellTime
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual bool getConfigurationValueAsBool(const std::string &key) const
Gets a named configuration value as a Boolean.
virtual BasicDoubleList getSweepStopRange() const
Gets the sweep stop range.
virtual double getFrequencyRes() const
Gets the frequency resolution.
virtual BasicDoubleList getSweepStartRange() const
Gets the sweep start range.
virtual bool setConfigurationValueToDbl(const std::string &key, const double value)
Sets a named configuration value to a double value.
virtual double getSweepStartFrequency() const
Gets the start frequency for a signal sweep.
Base hardware component class.
virtual bool hasKey(const std::string &key) const
Determines if the dictionary has the given key.
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.
virtual double getFrequency() const
Gets the constant frequency.
virtual double getSweepStopFrequency() const
Gets the stop frequency for a signal sweep.
virtual bool isConnected() const
Gets whether or not the handler is connected.
virtual RadioComponent & operator=(const RadioComponent &other)
Assignment operator for RadioComponent objects.
virtual bool setPhase(double phase)
Sets the signal phase.
virtual double getSweepStartRes() const
Gets the sweep start resolution.
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.
CWToneGenComponent(const std::string &name="CWTONE", int index=0, RadioHandler *parent=NULL, bool debug=false, int txIndex=0, double freqRangeMin=0.0, double freqRangeMax=0.0, double freqRes=0.0, double freqUnits=0.0, double ampRangeMin=0.0, double ampRangeMax=0.0, double ampRes=0.0, double phaseRangeMin=0.0, double phaseRangeMax=0.0, double phaseRes=0.0, double sweepStartRangeMin=0.0, double sweepStartRangeMax=0.0, double sweepStartRes=0.0, double sweepStopRangeMin=0.0, double sweepStopRangeMax=0.0, double sweepStopRes=0.0, double sweepStepRangeMin=0.0, double sweepStepRangeMax=0.0, double sweepStepRes=0.0, double dwellTimeRangeMin=0.0, double dwellTimeRangeMax=0.0, double dwellTimeRes=0.0, double frequency=0.0, double amplitude=0.0, double phase=0.0, double sweepStart=0.0, double sweepStop=0.0, double sweepStep=0.0, double dwellTime=0.0)
Constructs a CWToneGenComponent object.
virtual BasicDoubleList getFrequencyRange() const
Gets the frequency range.
virtual bool setFrequencySweep(double start, double stop, double step, double dwell)
Sets the parameters for a frequency sweep.
virtual bool executeSweepQuery(int index, int txIndex, double &sweepStart, double &sweepStop, double &sweepStep, double &dwellTime)
Executes the CW sweep query command.
virtual double getAmplitude() const
Gets the signal amplitude.
virtual double getSweepFrequencyStep() const
Gets the frequency step for a signal sweep.
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 CWToneGenComponent & operator=(const CWToneGenComponent &other)
Assignment operator for CWToneGenComponent objects.
virtual double getDwellTimeRes() const
Gets the dwell time resolution.
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 BasicDoubleList getSweepStepRange() const
Gets the sweep step range.
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
virtual bool executeToneQuery(int index, int txIndex, double &freq, double &, double &phase)
Executes the CW tone query command.
virtual bool supportsSweep() const
Gets whether or not the generator supports signal sweeps.
virtual BasicDoubleList getPhaseRange() const
Gets the phase range.
Defines functionality for LibCyberRadio applications.
virtual double getSweepDwellTime() const
Gets the dwell time for a signal sweep.
A configuration dictionary.
virtual std::string getLastCommandErrorInfo() const
Gets the error message from the last command attempted.
virtual double getAmplitudeRes() const
Gets the amplitude resolution.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this component.
virtual bool executeSweepCommand(int index, int txIndex, double &sweepStart, double &sweepStop, double &sweepStep, double &dwellTime)
Executes the CW sweep set command.
virtual BasicDoubleList getDwellTimeRange() const
Gets the dwell time range.
virtual double getPhaseRes() const
Gets the phase resolution.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this object.
virtual double getSweepStopRes() const
Gets the sweep stop resolution.
virtual BasicStringList sendCommand(const std::string &cmdString, double timeout=-1)
Sends a command to the radio.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
virtual double getPhase() const
Gets the signal phase.
virtual ~CWToneGenComponent()
Destroys a CWToneGenComponent object.
virtual bool setFrequency(double freq)
Sets the constant frequency.
virtual double getSweepStepRes() const
Gets the sweep step resolution.
virtual bool setAmplitude(double amp)
Sets the signal amplitude.
virtual double getConfigurationValueAsDbl(const std::string &key) const
Gets a named configuration value as a double value.
virtual bool enable(bool enabled=true)
Enables this component.
Base continuous-wave (CW) tone generator component class.
virtual BasicDoubleList getAmplitudeRange() const
Gets the amplitude range.
virtual void queryConfiguration()
Tells the component to query its hardware configuration in order to create its configuration dictiona...
virtual bool executeToneCommand(int index, int txIndex, double &freq, double &, double &phase)
Executes the CW tone set command.