11 #include "LibCyberRadio/Driver/RadioHandler.h" 12 #include "LibCyberRadio/Driver/WbddcComponent.h" 13 #include "LibCyberRadio/Common/Pythonesque.h" 14 #include <boost/lexical_cast.hpp> 25 const std::string& name,
30 bool selectableSource,
31 bool selectableDataPort,
43 unsigned int streamId) :
46 _selectableSource(selectableSource),
47 _selectableDataPort(selectableDataPort),
49 _freqRangeMin(freqRangeMin),
50 _freqRangeMax(freqRangeMax),
52 _freqUnits(freqUnits),
55 _frequency(frequency),
56 _rateIndex(rateIndex),
57 _udpDestination(udpDestination),
58 _vitaEnable(vitaEnable),
70 _tunable(other._tunable),
71 _selectableSource(other._selectableSource),
72 _selectableDataPort(other._selectableDataPort),
74 _freqRangeMin(other._freqRangeMin),
75 _freqRangeMax(other._freqRangeMax),
76 _freqRes(other._freqRes),
77 _freqUnits(other._freqUnits),
78 _source(other._source),
79 _dataPort(other._dataPort),
80 _frequency(other._frequency),
81 _rateIndex(other._rateIndex),
82 _udpDestination(other._udpDestination),
83 _vitaEnable(other._vitaEnable),
84 _streamId(other._streamId)
93 _tunable = other._tunable;
94 _selectableSource = other._selectableSource;
95 _selectableDataPort = other._selectableDataPort;
97 _freqRangeMin = other._freqRangeMin;
98 _freqRangeMax = other._freqRangeMax;
99 _freqRes = other._freqRes;
100 _freqUnits = other._freqUnits;
101 _source = other._source;
102 _dataPort = other._dataPort;
103 _frequency = other._frequency;
104 _rateIndex = other._rateIndex;
105 _udpDestination = other._udpDestination;
106 _vitaEnable = other._vitaEnable;
107 _streamId = other._streamId;
115 if ( _config.
hasKey(
"enable") )
117 int adjRateIndex = _rateIndex;
118 int adjUdpDest = _udpDestination;
119 int adjVita = _vitaEnable;
120 unsigned int adjStream = _streamId;
121 bool adjEnabled = enabled;
122 ret =
executeWbddcCommand(_index, adjRateIndex, adjUdpDest, adjEnabled, adjVita, adjStream);
125 _enabled = adjEnabled;
134 this->
debug(
"[WbddcComponent::setConfiguration] Called\n");
141 int adjRateIndex = _rateIndex;
142 int adjUdpDest = _udpDestination;
143 int adjVita = _vitaEnable;
144 unsigned int adjStream = _streamId;
145 bool adjEnabled = _enabled;
146 double adjFreq = _frequency;
147 int adjSource = _source;
148 int adjDataPort = _dataPort;
149 bool ddcCmdNeedsExecuting =
false;
150 bool freqCmdNeedsExecuting =
false;
151 bool srcCmdNeedsExecuting =
false;
152 bool dpCmdNeedsExecuting =
false;
156 ddcCmdNeedsExecuting =
true;
158 if ( cfg.
hasKey(
"rateIndex") && _config.
hasKey(
"rateIndex") )
161 ddcCmdNeedsExecuting =
true;
163 if ( cfg.
hasKey(
"udpDestination") && _config.
hasKey(
"udpDestination") )
166 ddcCmdNeedsExecuting =
true;
168 if ( cfg.
hasKey(
"vitaEnable") && _config.
hasKey(
"vitaEnable") )
171 ddcCmdNeedsExecuting =
true;
173 if ( cfg.
hasKey(
"streamId") && _config.
hasKey(
"streamId") )
176 ddcCmdNeedsExecuting =
true;
180 if ( cfg.
hasKey(
"frequency") && _config.
hasKey(
"frequency") )
183 freqCmdNeedsExecuting =
true;
186 if ( _selectableSource )
191 srcCmdNeedsExecuting =
true;
194 if ( _selectableDataPort )
196 if ( cfg.
hasKey(
"dataPort") && _config.
hasKey(
"dataPort") )
199 dpCmdNeedsExecuting =
true;
202 if ( ddcCmdNeedsExecuting )
205 adjEnabled, adjVita, adjStream);
207 if ( freqCmdNeedsExecuting )
211 if ( srcCmdNeedsExecuting )
215 if ( dpCmdNeedsExecuting )
221 _rateIndex = adjRateIndex;
222 _udpDestination = adjUdpDest;
223 _vitaEnable = adjVita;
224 _streamId = adjStream;
225 _enabled = adjEnabled;
226 _frequency = adjFreq;
228 _dataPort = adjDataPort;
231 this->
debug(
"[WbddcComponent::setConfiguration] Returning\n");
237 this->
debug(
"[WbddcComponent::queryConfiguration] Called\n");
238 if ( _config.
hasKey(
"enable") &&
239 _config.
hasKey(
"rateIndex") &&
240 _config.
hasKey(
"udpDestination") &&
241 _config.
hasKey(
"vitaEnable") &&
242 _config.
hasKey(
"streamId") )
245 _vitaEnable, _streamId);
247 if ( _tunable && _config.
hasKey(
"frequency") )
251 if ( _selectableSource && _config.
hasKey(
"source") )
255 if ( _selectableDataPort && _config.
hasKey(
"dataPort") )
260 this->
debug(
"[WbddcComponent::queryConfiguration] Returning\n");
271 if ( _tunable && _config.
hasKey(
"frequency") )
273 double adjFreq = _frequency;
277 _frequency = adjFreq;
287 ret.push_back(_freqRangeMin);
288 ret.push_back(_freqRangeMax);
314 return _selectableSource;
325 if ( _selectableSource && _config.
hasKey(
"source") )
327 int adjSource = source;
346 if ( _config.
hasKey(
"rateIndex") )
348 int adjRateIndex = index;
349 int adjUdpDest = _udpDestination;
350 int adjVita = _vitaEnable;
351 unsigned int adjStream = _streamId;
352 bool adjEnabled = _enabled;
353 ret =
executeWbddcCommand(_index, adjRateIndex, adjUdpDest, adjEnabled, adjVita, adjStream);
356 _rateIndex = adjRateIndex;
365 return _udpDestination;
371 if ( _config.
hasKey(
"udpDestination") )
373 int adjRateIndex = _rateIndex;
374 int adjUdpDest = dest;
375 int adjVita = _vitaEnable;
376 unsigned int adjStream = _streamId;
377 bool adjEnabled = _enabled;
378 ret =
executeWbddcCommand(_index, adjRateIndex, adjUdpDest, adjEnabled, adjVita, adjStream);
381 _udpDestination = adjUdpDest;
396 if ( _config.
hasKey(
"vitaEnable") )
398 int adjRateIndex = _rateIndex;
399 int adjUdpDest = _udpDestination;
401 unsigned int adjStream = _streamId;
402 bool adjEnabled = _enabled;
403 ret =
executeWbddcCommand(_index, adjRateIndex, adjUdpDest, adjEnabled, adjVita, adjStream);
406 _vitaEnable = adjVita;
421 if ( _config.
hasKey(
"streamId") )
423 int adjRateIndex = _rateIndex;
424 int adjUdpDest = _udpDestination;
425 int adjVita = _vitaEnable;
426 unsigned int adjStream = sid;
427 bool adjEnabled = _enabled;
428 ret =
executeWbddcCommand(_index, adjRateIndex, adjUdpDest, adjEnabled, adjVita, adjStream);
431 _streamId = adjStream;
446 if ( _selectableDataPort && _config.
hasKey(
"dataPort") )
448 int adjDataPort = port;
452 _dataPort = adjDataPort;
473 for (WbddcRateSet::const_iterator it = _rateSet.begin(); it != _rateSet.end(); it++)
475 ret.push_back(it->second);
487 _config[
"rateIndex"] =
"";
488 _config[
"udpDestination"] =
"";
489 _config[
"vitaEnable"] =
"";
490 _config[
"streamId"] =
"";
493 _config[
"frequency"] =
"";
495 if ( _selectableSource )
497 _config[
"source"] =
"";
499 if ( _selectableDataPort )
501 _config[
"dataPort"] =
"";
508 this->
debug(
"[WbddcComponent::updateConfigurationDict] Called\n");
510 if ( _config.
hasKey(
"rateIndex") )
512 if ( _config.
hasKey(
"udpDestination") )
514 if ( _config.
hasKey(
"vitaEnable") )
516 if ( _config.
hasKey(
"streamId") )
518 if ( _tunable && _config.
hasKey(
"frequency") )
522 if ( _selectableSource && _config.
hasKey(
"source") )
526 if ( _selectableDataPort && _config.
hasKey(
"dataPort") )
530 this->
debug(
"[WbddcComponent::updateConfigurationDict] Returning\n");
536 int& udpDestination,
bool& enabled,
int& vitaEnable,
537 unsigned int& streamId)
540 if ( (_parent != NULL) && (_parent->
isConnected()) )
542 std::ostringstream oss;
543 oss <<
"WBDDC? " << index <<
"\n";
552 rateIndex = boost::lexical_cast<
int>(vec[1]);
553 udpDestination = boost::lexical_cast<
int>(vec[2]);
554 enabled = (boost::lexical_cast<
int>(vec[3]) == 1);
555 vitaEnable = boost::lexical_cast<
int>(vec[4]);
556 streamId = boost::lexical_cast<
unsigned int>(vec[5]);
566 int& udpDestination,
bool& enabled,
int& vitaEnable,
567 unsigned int& streamId)
570 if ( (_parent != NULL) && (_parent->
isConnected()) )
572 std::ostringstream oss;
573 oss <<
"WBDDC " << index
575 <<
", " << udpDestination
576 <<
", " << (enabled ? 1 : 0)
577 <<
", " << vitaEnable
623 if ( (_parent != NULL) && (_parent->
isConnected()) )
625 std::ostringstream oss;
626 oss <<
"WBDP? " << index <<
"\n";
635 dataPort = boost::lexical_cast<
int>(vec[1]);
647 if ( (_parent != NULL) && (_parent->
isConnected()) )
649 std::ostringstream oss;
650 oss <<
"WBDP " << index
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 ~WbddcComponent()
Destroys a WbddcComponent object.
virtual bool setDataPort(int port)
Sets the WBDDC's data port.
virtual WbddcComponent & operator=(const WbddcComponent &other)
Assignment operator for WbddcComponent objects.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
virtual BasicDoubleList getFrequencyRange() const
Gets the tunable frequency range.
virtual int getVitaEnable() const
Gets the WBDDC's VITA 49 setting.
virtual bool setSource(int source)
Sets the WBDDC's source (which tuner is supplying the signal).
virtual bool setConfigurationValueToDbl(const std::string &key, const double value)
Sets a named configuration value to a double value.
Base hardware component class.
virtual bool hasKey(const std::string &key) const
Determines if the dictionary has the given key.
virtual bool setRateIndex(int index)
Sets the WBDDC's rate index.
BASIC_LIST_CONTAINER< double > BasicDoubleList
Type representing a list of doubles.
virtual bool enable(bool enabled=true)
Enables this component.
virtual int getConfigurationValueAsInt(const std::string &key) const
Gets a named configuration value as an integer value.
virtual bool setStreamId(unsigned int sid)
Sets the WBDDC's VITA 49 stream ID.
virtual bool setFrequency(double freq)
Sets the WBDDC tuned frequency.
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 bool executeDataPortQuery(int index, int &dataPort)
Executes the WBDDC data port query command.
virtual int getRateIndex() const
Gets the WBDDC's rate index.
virtual bool executeFreqQuery(int index, double &freq)
Executes the WBDDC frequency query command.
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 executeFreqCommand(int index, double &freq)
Executes the WBDDC frequency set command.
virtual bool executeWbddcQuery(int index, int &rateIndex, int &udpDestination, bool &enabled, int &vitaEnable, unsigned int &streamId)
Executes the WBDDC configuration query command.
virtual bool setConfigurationValueToUInt(const std::string &key, const unsigned int value)
Sets a named configuration value to an unsigned integer value.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this component.
virtual bool isTunable() const
Gets whether or not the WBDDC is tunable.
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 executeWbddcCommand(int index, int &rateIndex, int &udpDestination, bool &enabled, int &vitaEnable, unsigned int &streamId)
Executes the WBDDC configuration set command.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
virtual int getDataPort() const
Gets the WBDDC's data port.
Defines functionality for LibCyberRadio applications.
WbddcComponent(const std::string &name="WBDDC", int index=1, RadioHandler *parent=NULL, bool debug=false, bool tunable=false, bool selectableSource=false, bool selectableDataPort=false, bool agc=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 WbddcComponent object.
Base WBDDC component class.
A configuration dictionary.
virtual bool setVitaEnable(int enable)
Sets the WBDDC's VITA 49 setting.
virtual std::string getLastCommandErrorInfo() const
Gets the error message from the last command attempted.
virtual bool setRateSet(const WbddcRateSet &set)
Sets the WBDDC rate set.
virtual BasicDoubleList getRateList() const
Gets the list of allowed sample rates, based on the rate set.
virtual bool executeSourceQuery(int index, int &source)
Executes the WBDDC source query command.
virtual bool executeSourceCommand(int index, int &source)
Executes the WBDDC source set command.
virtual bool isAgcSupported() const
Gets whether or not the WBDDC supports AGC.
virtual double getFrequencyRes() const
Gets the tuned frequency resolution.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this object.
virtual BasicStringList sendCommand(const std::string &cmdString, double timeout=-1)
Sends a command to the radio.
virtual void queryConfiguration()
Tells the component to query its hardware configuration in order to create its configuration dictiona...
BASIC_DICT_CONTAINER< int, double > WbddcRateSet
A rate set for a WBDDC.
virtual int getUdpDestination() const
Gets the WBDDC's UDP destination.
virtual int getSource() const
Gets the WBDDC's source (which tuner is supplying the signal).
virtual bool executeDataPortCommand(int index, int &dataPort)
Executes the WBDDC data port set command.
virtual double getFrequencyUnit() const
Gets the tuned frequency units.
virtual bool setUdpDestination(int dest)
Sets the WBDDC's UDP destination.
virtual double getConfigurationValueAsDbl(const std::string &key) const
Gets a named configuration value as a double value.
virtual unsigned int getStreamId() const
Gets the WBDDC's VITA 49 stream ID.
virtual unsigned int getConfigurationValueAsUInt(const std::string &key) const
Gets a named configuration value as an unsigned integer value.
virtual double getFrequency() const
Gets the tuned frequency.
virtual WbddcRateSet getRateSet() const
Gets the WBDDC's rate set.
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual bool setConfigurationValueToInt(const std::string &key, const int value)
Sets a named configuration value to an integer value.
virtual bool isSourceSelectable() const
Gets whether or not the WBDDC supports selectable source.