11#include "LibCyberRadio/Driver/RadioHandler.h"
12#include "LibCyberRadio/Driver/NbddcComponent.h"
13#include "LibCyberRadio/Common/Pythonesque.h"
14#include <boost/lexical_cast.hpp>
25 const std::string& name,
29 bool nbddcCommandSetsFreq,
30 bool nbddcCommandSetsSource,
31 bool selectableDataPort,
42 unsigned int streamId) :
44 _nbddcCommandSetsFreq(nbddcCommandSetsFreq),
45 _nbddcCommandSetsSource(nbddcCommandSetsSource),
46 _selectableDataPort(selectableDataPort),
47 _freqRangeMin(freqRangeMin),
48 _freqRangeMax(freqRangeMax),
50 _freqUnits(freqUnits),
53 _frequency(frequency),
54 _rateIndex(rateIndex),
55 _udpDestination(udpDestination),
56 _vitaEnable(vitaEnable),
68 _nbddcCommandSetsFreq(other._nbddcCommandSetsFreq),
69 _nbddcCommandSetsSource(other._nbddcCommandSetsSource),
70 _selectableDataPort(other._selectableDataPort),
71 _freqRangeMin(other._freqRangeMin),
72 _freqRangeMax(other._freqRangeMax),
73 _freqRes(other._freqRes),
74 _freqUnits(other._freqUnits),
75 _source(other._source),
76 _dataPort(other._dataPort),
77 _frequency(other._frequency),
78 _rateIndex(other._rateIndex),
79 _udpDestination(other._udpDestination),
80 _vitaEnable(other._vitaEnable),
81 _streamId(other._streamId)
90 _nbddcCommandSetsFreq = other._nbddcCommandSetsFreq;
91 _nbddcCommandSetsSource = other._nbddcCommandSetsSource;
92 _selectableDataPort = other._selectableDataPort;
93 _freqRangeMin = other._freqRangeMin;
94 _freqRangeMax = other._freqRangeMax;
95 _freqRes = other._freqRes;
96 _freqUnits = other._freqUnits;
97 _source = other._source;
98 _dataPort = other._dataPort;
99 _frequency = other._frequency;
100 _rateIndex = other._rateIndex;
101 _udpDestination = other._udpDestination;
102 _vitaEnable = other._vitaEnable;
103 _streamId = other._streamId;
111 if ( _config.hasKey(
"enable") )
113 int adjRateIndex = _rateIndex;
114 int adjUdpDest = _udpDestination;
115 int adjVita = _vitaEnable;
116 unsigned int adjStream = _streamId;
117 bool adjEnabled = enabled;
118 double adjFreq = _frequency;
119 int adjSource = _source;
121 adjVita, adjStream, adjFreq, adjSource);
124 _enabled = adjEnabled;
139 int adjRateIndex = _rateIndex;
140 int adjUdpDest = _udpDestination;
141 int adjVita = _vitaEnable;
142 unsigned int adjStream = _streamId;
143 bool adjEnabled = _enabled;
144 double adjFreq = _frequency;
145 int adjSource = _source;
146 int adjDataPort = _dataPort;
147 bool ddcCmdNeedsExecuting =
false;
148 bool freqCmdNeedsExecuting =
false;
149 bool srcCmdNeedsExecuting =
false;
150 bool dpCmdNeedsExecuting =
false;
151 if ( cfg.
hasKey(
"enable") && _config.hasKey(
"enable") )
154 ddcCmdNeedsExecuting =
true;
156 if ( cfg.
hasKey(
"rateIndex") && _config.hasKey(
"rateIndex") )
159 ddcCmdNeedsExecuting =
true;
161 if ( cfg.
hasKey(
"udpDestination") && _config.hasKey(
"udpDestination") )
164 ddcCmdNeedsExecuting =
true;
166 if ( cfg.
hasKey(
"vitaEnable") && _config.hasKey(
"vitaEnable") )
169 ddcCmdNeedsExecuting =
true;
171 if ( cfg.
hasKey(
"streamId") && _config.hasKey(
"streamId") )
174 ddcCmdNeedsExecuting =
true;
176 if ( cfg.
hasKey(
"frequency") && _config.hasKey(
"frequency") )
179 if ( _nbddcCommandSetsFreq )
180 ddcCmdNeedsExecuting =
true;
182 freqCmdNeedsExecuting =
true;
184 if ( cfg.
hasKey(
"source") && _config.hasKey(
"source") )
187 if ( _nbddcCommandSetsSource )
188 ddcCmdNeedsExecuting =
true;
190 srcCmdNeedsExecuting =
true;
192 if ( cfg.
hasKey(
"dataPort") && _config.hasKey(
"dataPort") )
195 if ( _selectableDataPort )
196 dpCmdNeedsExecuting =
true;
198 if ( ddcCmdNeedsExecuting )
201 adjEnabled, adjVita, adjStream,
204 if ( freqCmdNeedsExecuting )
208 if ( srcCmdNeedsExecuting )
212 if ( dpCmdNeedsExecuting )
218 _rateIndex = adjRateIndex;
219 _udpDestination = adjUdpDest;
220 _vitaEnable = adjVita;
221 _streamId = adjStream;
222 _enabled = adjEnabled;
223 _frequency = adjFreq;
225 _dataPort = adjDataPort;
233 this->
debug(
"[queryConfiguration] Called\n");
234 if ( _config.hasKey(
"enable") &&
235 _config.hasKey(
"rateIndex") &&
236 _config.hasKey(
"udpDestination") &&
237 _config.hasKey(
"vitaEnable") &&
238 _config.hasKey(
"streamId") &&
239 (!_nbddcCommandSetsFreq || _config.hasKey(
"frequency")) &&
240 (!_nbddcCommandSetsSource || _config.hasKey(
"source"))
244 _vitaEnable, _streamId, _frequency, _source);
246 if ( !_nbddcCommandSetsFreq && _config.hasKey(
"frequency") )
250 if ( !_nbddcCommandSetsSource && _config.hasKey(
"source") )
254 if ( _selectableDataPort && _config.hasKey(
"dataPort") )
269 if ( _config.hasKey(
"frequency") )
271 double adjFreq = freq;
272 if ( _nbddcCommandSetsFreq )
274 int adjRateIndex = _rateIndex;
275 int adjUdpDest = _udpDestination;
276 int adjVita = _vitaEnable;
277 unsigned int adjStream = _streamId;
278 bool adjEnabled = _enabled;
279 int adjSource = _source;
281 adjVita, adjStream, adjFreq, adjSource);
289 _frequency = adjFreq;
299 ret.push_back(_freqRangeMin);
300 ret.push_back(_freqRangeMax);
322 if ( _config.hasKey(
"source") )
324 int adjSource = source;
325 if ( _nbddcCommandSetsSource )
327 int adjRateIndex = _rateIndex;
328 int adjUdpDest = _udpDestination;
329 int adjVita = _vitaEnable;
330 unsigned int adjStream = _streamId;
331 bool adjEnabled = _enabled;
332 double adjFreq = _frequency;
334 adjVita, adjStream, adjFreq, adjSource);
357 if ( _config.hasKey(
"rateIndex") )
359 int adjRateIndex = index;
360 int adjUdpDest = _udpDestination;
361 int adjVita = _vitaEnable;
362 unsigned int adjStream = _streamId;
363 bool adjEnabled = _enabled;
364 double adjFreq = _frequency;
365 int adjSource = _source;
367 adjEnabled, adjVita, adjStream,
371 _rateIndex = adjRateIndex;
380 return _udpDestination;
386 if ( _config.hasKey(
"udpDestination") )
388 int adjRateIndex = _rateIndex;
389 int adjUdpDest = dest;
390 int adjVita = _vitaEnable;
391 unsigned int adjStream = _streamId;
392 bool adjEnabled = _enabled;
393 double adjFreq = _frequency;
394 int adjSource = _source;
396 adjEnabled, adjVita, adjStream,
400 _udpDestination = adjUdpDest;
415 if ( _config.hasKey(
"vitaEnable") )
417 int adjRateIndex = _rateIndex;
418 int adjUdpDest = _udpDestination;
420 unsigned int adjStream = _streamId;
421 bool adjEnabled = _enabled;
422 double adjFreq = _frequency;
423 int adjSource = _source;
425 adjEnabled, adjVita, adjStream,
429 _vitaEnable = adjVita;
444 if ( _config.hasKey(
"streamId") )
446 int adjRateIndex = _rateIndex;
447 int adjUdpDest = _udpDestination;
448 int adjVita = _vitaEnable;
449 unsigned int adjStream = sid;
450 bool adjEnabled = _enabled;
451 double adjFreq = _frequency;
452 int adjSource = _source;
454 adjEnabled, adjVita, adjStream,
458 _streamId = adjStream;
473 if ( _selectableDataPort && _config.hasKey(
"dataPort") )
475 int adjDataPort = port;
479 _dataPort = adjDataPort;
500 for (NbddcRateSet::const_iterator it = _rateSet.begin(); it != _rateSet.end(); it++)
502 ret.push_back(it->second);
511 _config[
"rateIndex"] =
"";
512 _config[
"udpDestination"] =
"";
513 _config[
"vitaEnable"] =
"";
514 _config[
"streamId"] =
"";
515 _config[
"frequency"] =
"";
516 _config[
"source"] =
"";
517 if ( _selectableDataPort )
519 _config[
"dataPort"] =
"";
525 this->
debug(
"[NbddcComponent::updateConfigurationDict] Called\n");
527 if ( _config.hasKey(
"rateIndex") )
529 if ( _config.hasKey(
"udpDestination") )
531 if ( _config.hasKey(
"vitaEnable") )
533 if ( _config.hasKey(
"streamId") )
535 if ( _config.hasKey(
"frequency") )
537 if ( _config.hasKey(
"source") )
539 if ( _selectableDataPort && _config.hasKey(
"dataPort") )
543 this->
debug(
"[NbddcComponent::updateConfigurationDict] Returning\n");
553 unsigned int& streamId,
558 if ( (_parent != NULL) && (_parent->isConnected()) )
560 std::ostringstream oss;
561 oss <<
"NBDDC? " << index <<
"\n";
563 if ( _parent->getLastCommandErrorInfo() ==
"" )
571 frequency = boost::lexical_cast<double>(vec[1]);
572 rateIndex = boost::lexical_cast<int>(vec[2]);
573 udpDestination = boost::lexical_cast<int>(vec[3]);
574 enabled = (boost::lexical_cast<int>(vec[4]) == 1);
575 vitaEnable = boost::lexical_cast<int>(vec[5]);
576 streamId = boost::lexical_cast<unsigned int>(vec[6]);
592 unsigned int& streamId,
597 if ( (_parent != NULL) && (_parent->isConnected()) )
599 std::ostringstream oss;
600 oss <<
"NBDDC " << index
603 <<
", " << udpDestination
604 <<
", " << (enabled ? 1 : 0)
605 <<
", " << vitaEnable
609 if ( _parent->getLastCommandErrorInfo() ==
"" )
636 if ( (_parent != NULL) && (_parent->isConnected()) )
638 std::ostringstream oss;
639 oss <<
"NBSS? " << index <<
"\n";
641 if ( _parent->getLastCommandErrorInfo() ==
"" )
648 source = boost::lexical_cast<int>(vec[1]);
660 if ( (_parent != NULL) && (_parent->isConnected()) )
662 std::ostringstream oss;
663 oss <<
"NBSS " << index
667 if ( _parent->getLastCommandErrorInfo() ==
"" )
680 if ( (_parent != NULL) && (_parent->isConnected()) )
682 std::ostringstream oss;
683 oss <<
"NBDP? " << index <<
"\n";
685 if ( _parent->getLastCommandErrorInfo() ==
"" )
692 dataPort = boost::lexical_cast<int>(vec[1]);
704 if ( (_parent != NULL) && (_parent->isConnected()) )
706 std::ostringstream oss;
707 oss <<
"NBDP " << index
711 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 bool getConfigurationValueAsBool(const std::string &key) const
Gets a named configuration value as a Boolean.
virtual unsigned int getConfigurationValueAsUInt(const std::string &key) const
Gets a named configuration value as an unsigned integer value.
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.
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 int getSource() const
Gets the NBDDC's source (which tuner is supplying the signal).
virtual bool executeNbddcQuery(int index, int &rateIndex, int &udpDestination, bool &enabled, int &vitaEnable, unsigned int &streamId, double &frequency, int &source)
Executes the NBDDC configuration query command.
virtual bool executeSourceQuery(int index, int &source)
Executes the NBDDC source query command.
virtual int getUdpDestination() const
Gets the NBDDC's UDP destination.
virtual BasicDoubleList getFrequencyRange() const
Gets the tunable frequency range.
virtual bool setVitaEnable(int enable)
Sets the NBDDC's VITA 49 setting.
virtual bool setFrequency(double freq)
Sets the NBDDC tuned frequency.
virtual bool executeSourceCommand(int index, int &source)
Executes the NBDDC source set command.
virtual int getDataPort() const
Gets the NBDDC's data port.
virtual double getFrequency() const
Gets the tuned frequency.
virtual BasicDoubleList getRateList() const
Gets the list of allowed sample rates, based on the rate set.
virtual bool executeFreqCommand(int index, double &freq)
Executes the NBDDC frequency set command.
virtual unsigned int getStreamId() const
Gets the NBDDC's VITA 49 stream ID.
virtual int getRateIndex() const
Gets the NBDDC's rate index.
virtual NbddcRateSet getRateSet() const
Gets the NBDDC's rate set.
virtual bool setUdpDestination(int dest)
Sets the NBDDC's UDP destination.
virtual void queryConfiguration()
Tells the component to query its hardware configuration in order to create its configuration dictiona...
virtual bool setDataPort(int port)
Sets the NBDDC's data port.
virtual bool setRateSet(const NbddcRateSet &set)
Sets the NBDDC rate set.
virtual bool executeFreqQuery(int index, double &freq)
Executes the NBDDC frequency query command.
virtual bool setStreamId(unsigned int sid)
Sets the NBDDC's VITA 49 stream ID.
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual bool executeNbddcCommand(int index, int &rateIndex, int &udpDestination, bool &enabled, int &vitaEnable, unsigned int &streamId, double &frequency, int &source)
Executes the NBDDC configuration set command.
virtual ~NbddcComponent()
Destroys a NbddcComponent object.
virtual bool setRateIndex(int index)
Sets the NBDDC's rate index.
virtual NbddcComponent & operator=(const NbddcComponent &other)
Assignment operator for NbddcComponent objects.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
virtual bool executeDataPortQuery(int index, int &dataPort)
Executes the NBDDC data port query command.
virtual double getFrequencyUnit() const
Gets the tuned frequency units.
NbddcComponent(const std::string &name="NBDDC", int index=1, RadioHandler *parent=NULL, bool debug=false, bool nbddcCommandSetsFreq=false, bool nbddcCommandSetsSource=false, bool selectableDataPort=false, double freqRangeMin=0.0, double freqRangeMax=0.0, double freqRes=1.0, double freqUnits=1.0, int source=1, int dataPort=1, double frequency=0.0, int rateIndex=0, int udpDestination=0, int vitaEnable=0, unsigned int streamId=0)
Constructs a NbddcComponent object.
virtual int getVitaEnable() const
Gets the NBDDC's VITA 49 setting.
virtual bool setSource(int source)
Sets the NBDDC's source (which tuner is supplying the signal).
virtual bool executeDataPortCommand(int index, int &dataPort)
Executes the NBDDC data port set command.
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 > NbddcRateSet
A rate set for a NBDDC.
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.