12#include "LibCyberRadio/Driver/DataPort.h"
13#include "LibCyberRadio/Driver/RadioHandler.h"
14#include "LibCyberRadio/Common/Pythonesque.h"
15#include <boost/lexical_cast.hpp>
29 const std::string& sourceIP,
30 int numDataPortDipEntries,
31 int dataPortDipEntryIndexBase) :
36 _numDipEntries(numDataPortDipEntries),
37 _dipEntryIndexBase(dataPortDipEntryIndexBase),
39 _flowControlEnabled(true)
51 _parent(other._parent),
52 _sourceIP(other._sourceIP),
53 _numDipEntries(other._numDipEntries),
54 _macAddresses(other._macAddresses),
55 _ipAddresses(other._ipAddresses),
56 _sourcePorts(other._sourcePorts),
57 _destPorts(other._destPorts),
58 _dipEntryIndexBase(other._dipEntryIndexBase),
59 _errorsEnabled(other._errorsEnabled),
60 _flowControlEnabled(other._flowControlEnabled)
69 _index = other._index;
70 _parent = other._parent;
71 _sourceIP = other._sourceIP;
72 _numDipEntries = other._numDipEntries;
73 _macAddresses = other._macAddresses;
74 _ipAddresses = other._ipAddresses;
75 _sourcePorts = other._sourcePorts;
76 _destPorts = other._destPorts;
77 _dipEntryIndexBase = other._dipEntryIndexBase;
78 _errorsEnabled = other._errorsEnabled;
79 _flowControlEnabled = other._flowControlEnabled;
86 this->
debug(
"[DataPort::setConfiguration] Called\n");
91 if ( cfg.
hasKey(
"sourceIP") && _config.hasKey(
"sourceIP") )
95 if ( cfg.
hasKey(
"errors") && _config.hasKey(
"errors") )
99 if ( cfg.
hasKey(
"flowControl") && _config.hasKey(
"flowControl") )
103 this->
debug(
"[DataPort::setConfiguration] Returning\n");
109 this->
debug(
"[DataPort::queryConfiguration] Called\n");
111 if ( _config.hasKey(
"sourceIP") )
113 if ( _config.hasKey(
"errors") )
115 if ( _config.hasKey(
"flowControl") )
117 for (
int dipIndex = _dipEntryIndexBase;
118 dipIndex < _dipEntryIndexBase + _numDipEntries;
122 _macAddresses[dipIndex],
123 _ipAddresses[dipIndex],
124 _sourcePorts[dipIndex],
125 _destPorts[dipIndex]);
128 this->
debug(
"[DataPort::queryConfiguration] Returning\n");
133 return _numDipEntries;
139 for (
int dipIndex = _dipEntryIndexBase;
140 dipIndex < _dipEntryIndexBase + _numDipEntries;
143 ret.push_back(dipIndex);
156 if ( _config.hasKey(
"sourceIP") )
158 std::string adjSourceIP = ipAddr;
162 _sourceIP = adjSourceIP;
172 if ( _macAddresses.find(dipIndex) != _macAddresses.end() )
173 ret = _macAddresses.at(dipIndex);
180 if ( _ipAddresses.find(dipIndex) != _ipAddresses.end() )
181 ret = _ipAddresses.at(dipIndex);
188 if ( _sourcePorts.find(dipIndex) != _sourcePorts.end() )
189 ret = _sourcePorts.at(dipIndex);
196 if ( _destPorts.find(dipIndex) != _destPorts.end() )
197 ret = _destPorts.at(dipIndex);
202 const std::string& ipAddr,
203 const std::string& macAddr,
204 unsigned int sourcePort,
205 unsigned int destPort)
207 std::string adjIp = ipAddr;
208 std::string adjMac = macAddr;
209 unsigned int adjSrc = sourcePort;
210 unsigned int adjDst = destPort;
215 _macAddresses[dipIndex] = adjMac;
216 _ipAddresses[dipIndex] = adjIp;
217 _sourcePorts[dipIndex] = adjSrc;
218 _destPorts[dipIndex] = adjDst;
227 _ipAddresses[dipIndex],
229 _sourcePorts[dipIndex],
230 _destPorts[dipIndex]);
237 _macAddresses[dipIndex],
238 _sourcePorts[dipIndex],
239 _destPorts[dipIndex]);
245 _ipAddresses[dipIndex],
246 _macAddresses[dipIndex],
248 _destPorts[dipIndex]);
254 _ipAddresses[dipIndex],
255 _macAddresses[dipIndex],
256 _sourcePorts[dipIndex],
263 if ( _config.hasKey(
"errors") )
265 bool adjEn = enabled;
268 _errorsEnabled = enabled;
284 if ( _config.hasKey(
"errors") )
286 bool adjEn = enabled;
289 _flowControlEnabled = enabled;
306 _config[
"sourceIP"] = _sourceIP;
307 _config[
"errors"] = _errorsEnabled;
308 _config[
"flowControl"] = _flowControlEnabled;
314 this->
debug(
"[DataPort::updateConfigurationDict] Called\n");
315 if ( _config.hasKey(
"sourceIP") )
317 if ( _config.hasKey(
"errors") )
319 if ( _config.hasKey(
"flowControl") )
321 this->
debug(
"[DataPort::updateConfigurationDict] Returning\n");
328 if ( (_parent != NULL) && (_parent->isConnected()) )
330 std::ostringstream oss;
331 oss <<
"SIP? " << index <<
"\n";
333 if ( _parent->getLastCommandErrorInfo() ==
"" )
351 if ( (_parent != NULL) && (_parent->isConnected()) )
353 std::ostringstream oss;
354 oss <<
"SIP " << index
358 if ( _parent->getLastCommandErrorInfo() ==
"" )
370 std::string& macAddr,
371 unsigned int& sourcePort,
372 unsigned int& destPort)
379 if ( (_parent != NULL) && (_parent->isConnected()) &&
380 ( _macAddresses.find(dipIndex) != _macAddresses.end()) )
382 std::ostringstream oss;
383 oss <<
"DIP? " << index <<
", " << dipIndex <<
"\n";
385 if ( _parent->getLastCommandErrorInfo() ==
"" )
421 std::string& macAddr,
422 unsigned int& sourcePort,
423 unsigned int& destPort)
426 if ( (_parent != NULL) && (_parent->isConnected()) )
428 std::ostringstream oss;
429 oss <<
"DIP " << index
433 <<
", " << sourcePort
437 if ( _parent->getLastCommandErrorInfo() ==
"" )
449 if ( (_parent != NULL) && (_parent->isConnected()) )
451 std::ostringstream oss;
452 oss <<
"TGBED? " << index <<
"\n";
454 if ( _parent->getLastCommandErrorInfo() ==
"" )
461 int ind = boost::lexical_cast<int>(vec[1]);
462 enabled = (ind == 0);
473 if ( (_parent != NULL) && (_parent->isConnected()) )
475 std::ostringstream oss;
476 oss <<
"TGBED " << index
477 <<
", " << (enabled ? 0 : 1)
480 if ( _parent->getLastCommandErrorInfo() ==
"" )
492 if ( (_parent != NULL) && (_parent->isConnected()) )
494 std::ostringstream oss;
495 oss <<
"TGFC? " << index <<
"\n";
497 if ( _parent->getLastCommandErrorInfo() ==
"" )
504 int ind = boost::lexical_cast<int>(vec[1]);
505 enabled = (ind == 1);
516 if ( (_parent != NULL) && (_parent->isConnected()) )
518 std::ostringstream oss;
519 oss <<
"TGFC " << index
520 <<
", " << (enabled ? 1 : 0)
523 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 Configurable & operator=(const Configurable &other)
Assignment operator for Configurable objects.
virtual bool setConfigurationValue(const std::string &key, const std::string &value)
Sets a named configuration value to a string.
Configurable(const std::string &name="<unknown>", bool debug=false)
Constructs a Configurable object.
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 setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this object.
virtual bool executeFlowControlEnabledCommand(int index, bool &enabled)
Executes the flow control enabled command.
virtual bool executeErrorEnabledQuery(int index, bool &enabled)
Executes the error enabled query.
virtual int getNumDestEntries() const
Gets the number of destination IP table entries.
virtual bool executeDestIPCommand(int index, int dipIndex, std::string &ipAddr, std::string &macAddr, unsigned int &sourcePort, unsigned int &destPort)
Executes the destination IP set command.
virtual bool executeDestIPQuery(int index, int dipIndex, std::string &ipAddr, std::string &macAddr, unsigned int &sourcePort, unsigned int &destPort)
Executes the destination IP query command.
virtual BasicIntList getDestEntryIndexRange() const
Gets the list of destination IP table entry indices.
virtual bool setDestInfo(int dipIndex, const std::string &ipAddr, const std::string &macAddr, unsigned int sourcePort, unsigned int destPort)
Sets the destination table information for a given entry in the DIP table.
virtual bool setSourceIP(const std::string &ipAddr)
Sets the source IP address.
DataPort(const std::string &name="DATAPORT", int index=0, RadioHandler *parent=NULL, bool debug=false, const std::string &sourceIP="0.0.0.0", int numDataPortDipEntries=0, int dataPortDipEntryIndexBase=0)
Constructs a DataPort object.
virtual bool setDestMACAddress(int dipIndex, const std::string &macAddr)
Sets the MAC address for a given entry in the destination IP table.
virtual DataPort & operator=(const DataPort &other)
Assignment operator for DataPort objects.
virtual std::string getSourceIP() const
Gets the source IP address.
virtual std::string getDestIPAddress(int dipIndex) const
Gets the IP address for a given entry in the destination IP table.
virtual std::string getDestMACAddress(int dipIndex) const
Gets the MAC address for a given entry in the destination IP table.
virtual ~DataPort()
Destroys a DataPort object.
virtual unsigned int getDestSourcePort(int dipIndex) const
Gets the source UDP port number for a given entry in the destination IP table.
virtual bool executeSourceIPCommand(int index, std::string &ipAddr)
Executes the source IP set command.
virtual bool disableErrors()
Disables errors on the data port.
virtual void queryConfiguration()
Tells the object to create its configuration dictionary.
virtual void updateConfigurationDict()
Updates the configuration dictionary from object settings.
virtual bool setDestIPAddress(int dipIndex, const std::string &ipAddr)
Sets the IP address for a given entry in the destination IP table.
virtual bool enableErrors(bool enabled=true)
Enables errors on the data port.
virtual bool executeSourceIPQuery(int index, std::string &ipAddr)
Executes the source IP query command.
virtual bool executeErrorEnabledCommand(int index, bool &enabled)
Executes the error enabled command.
virtual bool setDestDestPort(int dipIndex, unsigned int destPort)
Sets the destination UDP port number for a given entry in the destination IP table.
virtual bool disableFlowControl()
Disables flow control on the data port.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
virtual bool enableFlowControl(bool enabled=true)
Enables flow control on the data port.
virtual bool setDestSourcePort(int dipIndex, unsigned int sourcePort)
Sets the source UDP port number for a given entry in the destination IP table.
virtual unsigned int getDestDestPort(int dipIndex) const
Gets the destination UDP port number for a given entry in the destination IP table.
virtual bool executeFlowControlEnabledQuery(int index, bool &enabled)
Executes the flow control enabled query.
Generic radio handler class.
static std::string Strip(const std::string &str, const std::string &chars=" \r\n\t\v\f")
Strips both leading and trailing whitespace from the given string.
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 bool Startswith(const std::string &str, const std::string &prefix, int start=0, int end=INT_MAX)
Determines if the given string starts with the specified prefix.
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.
Defines functionality for LibCyberRadio applications.
BASIC_LIST_CONTAINER< int > BasicIntList
Type representing a list of integers.
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.