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") )
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";
351 if ( (_parent != NULL) && (_parent->
isConnected()) )
353 std::ostringstream oss;
354 oss <<
"SIP " << index
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";
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
449 if ( (_parent != NULL) && (_parent->
isConnected()) )
451 std::ostringstream oss;
452 oss <<
"TGBED? " << index <<
"\n";
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)
492 if ( (_parent != NULL) && (_parent->
isConnected()) )
494 std::ostringstream oss;
495 oss <<
"TGFC? " << index <<
"\n";
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)
virtual bool setDestSourcePort(int dipIndex, unsigned int sourcePort)
Sets the source UDP port number for a given entry in the destination IP table.
virtual bool setSourceIP(const std::string &ipAddr)
Sets the source IP address.
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.
static std::string Strip(const std::string &str, const std::string &chars=" \\\)
Strips both leading and trailing whitespace from the given string.
virtual bool hasKey(const std::string &key) const
Determines if the dictionary has the given key.
virtual bool executeFlowControlEnabledQuery(int index, bool &enabled)
Executes the flow control enabled query.
virtual bool setConfigurationValueToBool(const std::string &key, const bool value)
Sets a named configuration value to a Boolean.
virtual unsigned int getDestSourcePort(int dipIndex) const
Gets the source UDP port number for a given entry in the destination IP table.
virtual bool executeErrorEnabledCommand(int index, bool &enabled)
Executes the error enabled command.
virtual std::string getDestIPAddress(int dipIndex) const
Gets the IP address for a given entry in the destination IP table.
virtual BasicIntList getDestEntryIndexRange() const
Gets the list of destination IP table entry indices.
virtual bool isConnected() const
Gets whether or not the handler is connected.
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 enableFlowControl(bool enabled=true)
Enables flow control on the data port.
virtual bool disableFlowControl()
Disables flow control on the data port.
virtual void updateConfigurationDict()
Updates the configuration dictionary from object settings.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this object.
virtual bool setDestMACAddress(int dipIndex, const std::string &macAddr)
Sets the MAC address for a given entry in the destination IP table.
virtual bool disableErrors()
Disables errors on the data port.
virtual std::string getSourceIP() const
Gets the source IP address.
virtual bool enableErrors(bool enabled=true)
Enables errors on the data port.
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 unsigned int getDestDestPort(int dipIndex) const
Gets the destination UDP port number for a given entry in the destination IP table.
virtual bool executeSourceIPQuery(int index, std::string &ipAddr)
Executes the source IP query command.
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.
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.
virtual bool executeSourceIPCommand(int index, std::string &ipAddr)
Executes the source IP set command.
Defines functionality for LibCyberRadio applications.
A configuration dictionary.
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 std::string getLastCommandErrorInfo() const
Gets the error message from the last command attempted.
virtual ~DataPort()
Destroys a DataPort 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 Configurable & operator=(const Configurable &other)
Assignment operator for Configurable objects.
virtual DataPort & operator=(const DataPort &other)
Assignment operator for DataPort objects.
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 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.
Base configurable object class.
BASIC_LIST_CONTAINER< int > BasicIntList
Type representing a list of integers.
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 bool setDestIPAddress(int dipIndex, const std::string &ipAddr)
Sets the IP address for a given entry in the destination IP table.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
virtual int getNumDestEntries() const
Gets the number of destination IP table entries.
virtual bool setConfigurationValue(const std::string &key, const std::string &value)
Sets a named configuration value to a string.
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 void queryConfiguration()
Tells the object to create its configuration dictionary.
virtual std::string getDestMACAddress(int dipIndex) const
Gets the MAC address for a given entry in the destination IP table.