11#include "LibCyberRadio/Driver/RadioHandler.h"
12#include "LibCyberRadio/Driver/DucComponent.h"
13#include "LibCyberRadio/Common/Pythonesque.h"
14#include <boost/lexical_cast.hpp>
25 const std::string& name,
42 unsigned int streamId) :
44 _freqRangeMin(freqRangeMin),
45 _freqRangeMax(freqRangeMax),
47 _freqUnits(freqUnits),
48 _attRangeMin(attRangeMin),
49 _attRangeMax(attRangeMax),
52 _frequency(frequency),
53 _attenuation(attenuation),
54 _rateIndex(rateIndex),
55 _txChannels(txChannels),
58 _supportsSnapLoad(false),
62 _supportsSnapTransmit(false),
63 _snapSinglePlayback(false),
64 _snapPauseUntilEnabled(false)
76 _freqRangeMin(other._freqRangeMin),
77 _freqRangeMax(other._freqRangeMax),
78 _freqRes(other._freqRes),
79 _freqUnits(other._freqUnits),
80 _attRangeMin(other._attRangeMin),
81 _attRangeMax(other._attRangeMax),
82 _attRes(other._attRes),
83 _dataPort(other._dataPort),
84 _frequency(other._frequency),
85 _attenuation(other._attenuation),
86 _rateIndex(other._rateIndex),
87 _txChannels(other._txChannels),
89 _streamId(other._streamId),
90 _supportsSnapLoad(other._supportsSnapLoad),
91 _snapFilename(other._snapFilename),
92 _snapStartSample(other._snapStartSample),
93 _snapSamples(other._snapSamples),
94 _supportsSnapTransmit(other._supportsSnapTransmit),
95 _snapSinglePlayback(other._snapSinglePlayback),
96 _snapPauseUntilEnabled(other._snapPauseUntilEnabled)
103 if (
this != &other )
105 _freqRangeMin = other._freqRangeMin;
106 _freqRangeMax = other._freqRangeMax;
107 _freqRes = other._freqRes;
108 _freqUnits = other._freqUnits;
109 _attRangeMin = other._attRangeMin;
110 _attRangeMax = other._attRangeMax;
111 _attRes = other._attRes;
112 _dataPort = other._dataPort;
113 _frequency = other._frequency;
114 _attenuation = other._attenuation;
115 _rateIndex = other._rateIndex;
116 _txChannels = other._txChannels;
118 _streamId = other._streamId;
119 _supportsSnapLoad = other._supportsSnapLoad;
120 _snapFilename = other._snapFilename;
121 _snapStartSample = other._snapStartSample;
122 _snapSamples = other._snapSamples;
123 _supportsSnapTransmit = other._supportsSnapTransmit;
124 _snapSinglePlayback = other._snapSinglePlayback;
125 _snapPauseUntilEnabled = other._snapPauseUntilEnabled;
137 this->
debug(
"[DucComponent::setConfiguration] Called\n");
144 int adjDataPort = _dataPort;
145 double adjFrequency = _frequency;
146 double adjAttenuation = _attenuation;
147 int adjRateIndex = _rateIndex;
148 int adjTxChannels = _txChannels;
150 unsigned int adjStreamId = _streamId;
151 bool ddcCmdNeedsExecuting =
false;
152 bool snapLoadCmdNeedsExecuting =
false;
153 bool snapTxCmdNeedsExecuting =
false;
154 if ( cfg.
hasKey(
"frequency") && _config.hasKey(
"frequency") )
157 ddcCmdNeedsExecuting =
true;
159 if ( cfg.
hasKey(
"attenuation") && _config.hasKey(
"attenuation") )
162 ddcCmdNeedsExecuting =
true;
164 if ( cfg.
hasKey(
"dataPort") && _config.hasKey(
"dataPort") )
167 ddcCmdNeedsExecuting =
true;
169 if ( cfg.
hasKey(
"rateIndex") && _config.hasKey(
"rateIndex") )
172 ddcCmdNeedsExecuting =
true;
174 if ( cfg.
hasKey(
"txChannels") && _config.hasKey(
"txChannels") )
177 ddcCmdNeedsExecuting =
true;
179 if ( cfg.
hasKey(
"mode") && _config.hasKey(
"mode") )
182 ddcCmdNeedsExecuting =
true;
184 if ( cfg.
hasKey(
"streamId") && _config.hasKey(
"streamId") )
187 ddcCmdNeedsExecuting =
true;
189 if ( cfg.
hasKey(
"filename") && _config.hasKey(
"filename") )
191 snapLoadCmdNeedsExecuting =
true;
193 if ( cfg.
hasKey(
"singlePlayback") && _config.hasKey(
"singlePlayback") )
195 snapTxCmdNeedsExecuting =
true;
197 if ( cfg.
hasKey(
"pauseUntilEnabled") && _config.hasKey(
"pauseUntilEnabled") )
199 snapTxCmdNeedsExecuting =
true;
201 if ( ddcCmdNeedsExecuting )
204 adjRateIndex, adjTxChannels, adjMode, adjStreamId);
206 if ( snapLoadCmdNeedsExecuting )
211 if ( snapTxCmdNeedsExecuting )
219 _dataPort = adjDataPort;
220 _frequency = adjFrequency;
221 _attenuation = adjAttenuation;
222 _rateIndex = adjRateIndex;
223 _txChannels = adjTxChannels;
225 _streamId = adjStreamId;
228 this->
debug(
"[DucComponent::setConfiguration] Returning\n");
235 this->
debug(
"[DucComponent::queryConfiguration] Called\n");
236 if ( _config.hasKey(
"frequency") &&
237 _config.hasKey(
"attenuation") &&
238 _config.hasKey(
"dataPort") &&
239 _config.hasKey(
"rateIndex") &&
240 _config.hasKey(
"txChannels") &&
241 _config.hasKey(
"mode") &&
242 _config.hasKey(
"streamId") &&
243 _config.hasKey(
"filename") &&
244 _config.hasKey(
"singlePlayback") &&
245 _config.hasKey(
"pauseUntilEnabled") )
248 _rateIndex, _txChannels, _mode, _streamId);
251 this->
debug(
"[DucComponent::queryConfiguration] Returning\n");
262 if ( _config.hasKey(
"dataPort") )
264 int adjDataPort = port;
265 double adjFrequency = _frequency;
266 double adjAttenuation = _attenuation;
267 int adjRateIndex = _rateIndex;
268 int adjTxChannels = _txChannels;
270 unsigned int adjStreamId = _streamId;
272 adjRateIndex, adjTxChannels, adjMode, adjStreamId);
275 _dataPort = adjDataPort;
290 if ( _config.hasKey(
"frequency") )
292 int adjDataPort = _dataPort;
293 double adjFrequency = freq;
294 double adjAttenuation = _attenuation;
295 int adjRateIndex = _rateIndex;
296 int adjTxChannels = _txChannels;
298 unsigned int adjStreamId = _streamId;
300 adjRateIndex, adjTxChannels, adjMode, adjStreamId);
303 _frequency = adjFrequency;
313 ret.push_back(_freqRangeMin);
314 ret.push_back(_freqRangeMax);
336 if ( _config.hasKey(
"attenuation") )
338 int adjDataPort = _dataPort;
339 double adjFrequency = _frequency;
340 double adjAttenuation = atten;
341 int adjRateIndex = _rateIndex;
342 int adjTxChannels = _txChannels;
344 unsigned int adjStreamId = _streamId;
346 adjRateIndex, adjTxChannels, adjMode, adjStreamId);
349 _attenuation = adjAttenuation;
359 ret.push_back(_attRangeMin);
360 ret.push_back(_attRangeMax);
377 if ( _config.hasKey(
"rateIndex") )
379 int adjDataPort = _dataPort;
380 double adjFrequency = _frequency;
381 double adjAttenuation = _attenuation;
382 int adjRateIndex = index;
383 int adjTxChannels = _txChannels;
385 unsigned int adjStreamId = _streamId;
387 adjRateIndex, adjTxChannels, adjMode, adjStreamId);
390 _rateIndex = adjRateIndex;
405 if ( _config.hasKey(
"txChannels") )
407 int adjDataPort = _dataPort;
408 double adjFrequency = _frequency;
409 double adjAttenuation = _attenuation;
410 int adjRateIndex = _rateIndex;
411 int adjTxChannels = txChannels;
413 unsigned int adjStreamId = _streamId;
415 adjRateIndex, adjTxChannels, adjMode, adjStreamId);
418 _txChannels = adjTxChannels;
433 if ( _config.hasKey(
"mode") )
435 int adjDataPort = _dataPort;
436 double adjFrequency = _frequency;
437 double adjAttenuation = _attenuation;
438 int adjRateIndex = _rateIndex;
439 int adjTxChannels = _txChannels;
441 unsigned int adjStreamId = _streamId;
443 adjRateIndex, adjTxChannels, adjMode, adjStreamId);
461 if ( _config.hasKey(
"streamId") )
463 int adjDataPort = _dataPort;
464 double adjFrequency = _frequency;
465 double adjAttenuation = _attenuation;
466 int adjRateIndex = _rateIndex;
467 int adjTxChannels = _txChannels;
469 unsigned int adjStreamId = sid;
471 adjRateIndex, adjTxChannels, adjMode, adjStreamId);
474 _streamId = adjStreamId;
495 for (WbddcRateSet::const_iterator it = _rateSet.begin(); it != _rateSet.end(); it++)
497 ret.push_back(it->second);
508 unsigned int startSample,
509 unsigned int samples)
512 startSample, samples);
515 _snapFilename = filename;
516 _snapStartSample = startSample;
517 _snapSamples = samples;
535 _config[
"dataPort"] =
"";
536 _config[
"frequency"] =
"";
537 _config[
"attenuation"] =
"";
538 _config[
"rateIndex"] =
"";
539 _config[
"txChannels"] =
"";
540 _config[
"mode"] =
"";
541 _config[
"streamId"] =
"";
542 _config[
"filename"] =
"";
543 _config[
"startSample"] =
"";
544 _config[
"samples"] =
"";
545 _config[
"singlePlayback"] =
"";
546 _config[
"pauseUntilEnabled"] =
"";
552 this->
debug(
"[DucComponent::updateConfigurationDict] Called\n");
554 if ( _config.hasKey(
"dataPort") )
556 if ( _config.hasKey(
"frequency") )
558 if ( _config.hasKey(
"attenuation") )
560 if ( _config.hasKey(
"rateIndex") )
562 if ( _config.hasKey(
"txChannels") )
564 if ( _config.hasKey(
"mode") )
566 if ( _config.hasKey(
"streamId") )
568 if ( _config.hasKey(
"filename") )
570 if ( _config.hasKey(
"startSample") )
572 if ( _config.hasKey(
"samples") )
574 if ( _config.hasKey(
"singlePlayback") )
576 if ( _config.hasKey(
"pauseUntilEnabled") )
578 this->
debug(
"[DucComponent::updateConfigurationDict] Returning\n");
588 unsigned int& streamId)
591 if ( (_parent != NULL) && (_parent->isConnected()) )
593 std::ostringstream oss;
594 oss <<
"DUC? " << index <<
"\n";
596 if ( _parent->getLastCommandErrorInfo() ==
"" )
603 dataPort = boost::lexical_cast<int>(vec[1]);
605 frequency = boost::lexical_cast<double>(vec[2]);
607 attenuation = boost::lexical_cast<double>(vec[3]);
609 rateIndex = boost::lexical_cast<int>(vec[4]);
611 txChannels = boost::lexical_cast<int>(vec[5]);
613 mode = boost::lexical_cast<int>(vec[6]);
615 streamId = boost::lexical_cast<unsigned int>(vec[7]);
629 unsigned int& streamId)
632 if ( (_parent != NULL) && (_parent->isConnected()) )
634 std::ostringstream oss;
635 oss <<
"DUC " << index
637 <<
", " << std::setprecision(1) << std::fixed << frequency
638 <<
", " << std::setprecision(1) << std::fixed << attenuation
640 <<
", " << txChannels
645 if ( _parent->getLastCommandErrorInfo() ==
"" )
654 const std::string& filename,
655 unsigned int startSample,
656 unsigned int samples)
659 if ( (_parent != NULL) && (_parent->isConnected()) )
661 std::ostringstream oss;
665 <<
", " << startSample;
668 oss <<
", " << samples;
672 if ( _parent->getLastCommandErrorInfo() ==
"" )
virtual int debug(const char *format,...)
Outputs debug information.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this object.
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 unsigned int getConfigurationValueAsUInt(const std::string &key) const
Gets a named configuration value as an unsigned integer 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 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.
virtual bool setConfigurationValueToBool(const std::string &key, const bool value)
Sets a named configuration value to a Boolean.
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 bool supportsSnapshotTransmit() const
Gets whether or not the DUC supports transmitting snapshots.
virtual double getAttenuation() const
Gets the attenuation.
virtual bool setAttenuation(double atten)
Sets the attenuation.
DucComponent(const std::string &name="DUC", int index=1, RadioHandler *parent=NULL, bool debug=false, double freqRangeMin=0.0, double freqRangeMax=0.0, double freqRes=1.0, double freqUnits=1.0, double attRangeMin=0.0, double attRangeMax=10.0, double attRes=1.0, int dataPort=0, double frequency=0.0, double attenuation=0.0, int rateIndex=0, int txChannels=0, int mode=0, unsigned int streamId=0)
Constructs a DucComponent object.
virtual ~DucComponent()
Destroys a DucComponent object.
virtual int getMode() const
Gets the DUC's mode.
virtual BasicDoubleList getFrequencyRange() const
Gets the tunable frequency range.
virtual bool setFrequency(double freq)
Sets the DUC tuned frequency.
virtual int getDataPort() const
Gets the DUC's data port.
virtual bool executeDucCommand(int index, int &dataPort, double &frequency, double &attenuation, int &rateIndex, int &txChannels, int &mode, unsigned int &streamId)
Executes the DUC configuration set command.
virtual double getFrequency() const
Gets the tuned frequency.
virtual bool loadSnapshot(const std::string &filename, unsigned int startSample=0, unsigned int samples=0)
Load a snapshot file into the DUC's memory block.
virtual BasicDoubleList getRateList() const
Gets the list of allowed sample rates, based on the rate set.
virtual unsigned int getStreamId() const
Gets the DUC's VITA 49 stream ID.
virtual int getTxChannelBitmap() const
Gets the DUC's transmit channel bitmap.
virtual int getRateIndex() const
Gets the DUC's rate index.
virtual bool supportsSnapshotLoad() const
Gets whether or not the DUC supports loading snapshot files.
virtual BasicDoubleList getAttenuationRange() const
Gets the attenuation range.
virtual DucComponent & operator=(const DucComponent &other)
Assignment operator for DucComponent objects.
virtual bool setTxChannelBitmap(int txChannels)
Sets the DUC's transmit channel bitmap.
virtual void queryConfiguration()
Tells the component to query its hardware configuration in order to create its configuration dictiona...
virtual bool executeSnapshotLoadCommand(int index, const std::string &filename, unsigned int startSample, unsigned int samples)
Executes the DUC snapshot load command.
virtual bool setDataPort(int port)
Sets the DUC's data port.
virtual bool setRateSet(const DucRateSet &set)
Sets the DUC rate set.
virtual bool setStreamId(unsigned int sid)
Sets the DUC's VITA 49 stream ID.
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual double getAttenuationRes() const
Gets the attenuation resolution.
virtual bool executeDucQuery(int index, int &dataPort, double &frequency, double &attenuation, int &rateIndex, int &txChannels, int &mode, unsigned int &streamId)
Executes the DUC configuration query command.
virtual DucRateSet getRateSet() const
Gets the DUC's rate set.
virtual bool setMode(int mode)
Sets the DUC's mode.
virtual bool setRateIndex(int index)
Sets the DUC's rate index.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
virtual double getFrequencyUnit() const
Gets the tuned frequency units.
virtual double getFrequencyRes() const
Gets the tuned frequency resolution.
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.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
Generic radio handler class.
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.
BASIC_DICT_CONTAINER< int, double > DucRateSet
A rate set for a DUC.
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.