libcyberradio  22.01.24
FlowControlClient.h
1 /***************************************************************************
2  * \file FlowControlClient.h
3  *
4  * \brief NDR651 flow control client.
5  *
6  * \author NH
7  * \copyright Copyright (c) 2015-2021 CyberRadio Solutions, Inc.
8  *
9  */
10 
11 #ifndef INCLUDED_LIBCYBERRADIO_NDR651_FLOWCONTROLCLIENT_H
12 #define INCLUDED_LIBCYBERRADIO_NDR651_FLOWCONTROLCLIENT_H
13 
14 #include "LibCyberRadio/Common/BasicList.h"
15 #include "LibCyberRadio/Common/Debuggable.h"
16 #include "LibCyberRadio/Common/Thread.h"
17 #include "LibCyberRadio/NDR651/ClientSocket.h"
18 #include "LibCyberRadio/NDR651/PacketTypes.h"
19 #include <boost/thread/mutex.hpp>
20 #include <boost/ptr_container/ptr_vector.hpp>
21 #include <vector>
22 
23 //#define TX_BUFFER_MAX_SIZE 67108862 // (2^26)-2
24 #define TX_BUFFER_MAX_SIZE 67108862 // (2^26)-2
25 #define TX_BUFFER_MIN_SIZE 0
26 
30 namespace LibCyberRadio
31 {
36  namespace NDR651
37  {
41  class FlowControlClient : public Thread, public Debuggable
42  {
43  public:
51  FlowControlClient(unsigned int ducChannel,
52  bool config_tx,
53  unsigned int updatesPerSecond,
54  bool debug = false);
58  virtual ~FlowControlClient();
62  virtual void run();
66  void update(void);
73  bool connectToRadio(const std::string& hostname, unsigned int port);
79  unsigned int setUpdateRate(unsigned int updatesPerSecond);
84  unsigned int getUpdateDelay() { return _fcUpdateDelay; };
89  void setDucChannel(unsigned int ducChannel);
94  bool isConnected(void) { return _mySocket->isConnected(); };
95  // bool tryBoostSocket(void);
100  bool disconnect(void);
104  void testQueries(void);
109  long unsigned int getUtc(void) {return _utc;};
115  std::string getRadioMac(unsigned int tenGbeIndex);
121  std::string getRadioIp(unsigned int tenGbeIndex);
126  bool disableDuc();// { return _sendDuc(false); };
127  //bool enableDuc() { return _setDucConfig(true); };
141  bool enableDuc(unsigned int rateIndex, unsigned int txChannel,
142  unsigned int streamId, unsigned int tenGbeIndex, float attenuation,
143  double txFreq, long ducFreq, unsigned int txAtten, bool ducEnable = true);
144  //bool enableDucChannel(unsigned int ducChannel, bool enable, unsigned int ducRate, unsigned int streamId, unsigned int tenGbeIndex, unsigned int ducTxChannel, float ducFreq, float ducAtten);
145  //bool enableDucChannel(unsigned int ducChannel, bool enable, unsigned int ducRate, unsigned int streamId, unsigned int tenGbeIndex, unsigned int ducTxChannel, float ducFreq, float ducAtten, bool enableTxChannels, float txFreq, unsigned int txAtten);
152  bool setTxFrequency(double txFreq, bool applySetting = true);
159  bool setTxAttenuation(unsigned int txAttenuation, bool applySetting = true);
166  bool setDucTxChannel(unsigned int txChannel, bool applySetting = true);
173  bool setDucRateIndex(unsigned int rateIndex, bool applySetting = true);
180  bool setDucStreamId(unsigned int streamId, bool applySetting = true);
187  bool setDucAttenuation(float attenuation, bool applySetting = true);
194  bool setDucFrequency(long ducFreq, bool applySetting = true);
201  bool setDucTxinvMode(unsigned int txinvMode, bool applySetting = true);
208  bool setDucEnable(bool ducEnable, bool applySetting = true);
215  bool setDucTenGbePort(unsigned int ducTenGbePort, bool applySetting = true);
222  bool okToSend(long int pendingSamples, bool lockIfOk);
223  // bool okToSend(long int pendingSamples, bool lockIfOk, unsigned int ducChannel);
228  long int getFreeSpace(void);
229  // long int getFreeSpace(unsigned int ducChannel);
235  bool sentNSamples(long int samplesSent);
236  // bool sentNSamples(long int samplesSent, unsigned int ducChannel);
237 
238  bool setDucDipStatusEntry(int dipIndex, std::string dip, std::string dmac, unsigned int ducStatusPort);
239  bool setDuchsParameters(unsigned int duchsFullThresh, unsigned int duchsEmptyThresh, unsigned int duchsPeriod);
240 
241  bool unpause(void);
242 
243  private:
244 
245  std::string _radioHostname;
246  unsigned int _radioTcpPort;
247 
248  struct TxStatusFrame _statusFrame;
249  int _statusSockfd;
250  socklen_t _statusDestLen; /* byte size of client's address */
251  struct sockaddr_in _statusDestAddr, _statusCopyAddr; /* client addr */
252 
253  unsigned int _tbsChannel;
254  unsigned int _tbsSpace;
255  unsigned int _tbsUnderrunFlag;
256  unsigned int _tbsUnderrunCount;
257  unsigned int _tbsOverrunFlag;
258  unsigned int _tbsOverrunCount;
259  unsigned int _tbsEmptyFlag;
260  unsigned int _tbsFullFlag;
261 
262  bool _validDucChannel, _multiChannel;
263  bool _ducEnable;
264  unsigned int _ducChannel;
265  unsigned int _ducRateIndex;
266  unsigned int _ducStreamId;
267  unsigned int _ducTxChannel;
268  unsigned int _ducTenGbePort;
269  unsigned int _ducDipIndex;
270  unsigned int _ducAttenuation;
271  unsigned int _txinvMode;
272  unsigned int _txAttenuation;
273  double _txFreq;
274  int _shfMode;
275  long _ducFreq;
276  bool _config_tx;
277 
278  unsigned int _duchsFullThresh;
279  unsigned int _duchsEmptyThresh;
280  unsigned int _duchsPeriod;
281  unsigned int _duchsUdpPort;
282 
283  BasicStringList _rspVec;
284 
285  boost::ptr_vector<boost::mutex> _fcMutexVector;
286  std::vector<long int> _freeSpaceVector;
287 
288  boost::mutex _fcMutex, _fcSendMutex, _fcUpdateMutex;
289  bool _sendLock;
290  unsigned int _fcUpdateRate, _fcUpdateDelay;
291  bool _firstUpdate;
292  // long int _651bufferSize;
293  unsigned long int _utc;
294  long int _651freeSpace;
295  long int _651freeSpaceArray[8];
296  long int _651freeSpaceLast;
297  long int _samplesPerUpdate;
298  // long int _651minFreeSpace;
299  //std::string _tqbaQuery, _tqouQuery;
300  std::string _tbsQuery;
301  ClientSocket * _mySocket;
302 
303 
304  bool _sendCmdAndQry(const std::string& cmd, const std::string& qry);
305  bool _setShfMode();
306  bool _sendShf();
307  bool _sendTxf();
308  bool _sendTxa();
309  bool _sendTxp();
310  bool _sendTxinv();
311  bool _sendWbduc();
312  bool _sendDuc();
313  bool _sendDucp();
314  bool _sendWba();
315  bool _sendWbf();
316  bool _sendDuchs();
317  bool _sendDip();
318 
319  bool _clearDucSettingsInRadio(void);
320 
321  void _initStatusFrame(void);
322  void _initStatusSocket(void);
323  void _initStatusAddress(void);
324  void _sendStatusFrame(void);
325 
326  //bool _setDucConfig(bool enable);
327  void _queryBufferState(void);
328  void _queryUtc(void);
329  void _queryStatus(void);
330  long _getDucSampleRate(void) const;
331 
332  };
333 
334  }
335 }
336 
337 #endif /* INCLUDED_LIBCYBERRADIO_NDR651_FLOWCONTROLCLIENT_H */
bool isConnected(void)
Gets whether or not the client is connected.
long unsigned int getUtc(void)
Gets the radio&#39;s UTC time.
std::string getRadioIp(unsigned int tenGbeIndex)
Gets the IP address of a 10GigE port on the radio.
bool setTxFrequency(double txFreq, bool applySetting=true)
Sets the transmitter frequency.
virtual ~FlowControlClient()
Destroys a FlowControlClient object.
bool isConnected(void)
Gets whether or not the socket is connected.
Definition: ClientSocket.h:62
bool enableDuc(unsigned int rateIndex, unsigned int txChannel, unsigned int streamId, unsigned int tenGbeIndex, float attenuation, double txFreq, long ducFreq, unsigned int txAtten, bool ducEnable=true)
Enables the DUC.
bool setDucRateIndex(unsigned int rateIndex, bool applySetting=true)
Sets the DUC rate index.
bool setDucStreamId(unsigned int streamId, bool applySetting=true)
Sets the Stream ID.
Class that supports debug output.
Definition: Debuggable.h:38
bool setTxAttenuation(unsigned int txAttenuation, bool applySetting=true)
Sets the transmitter attenuation.
std::string getRadioMac(unsigned int tenGbeIndex)
Gets the MAC address of a 10GigE port on the radio.
bool setDucTxChannel(unsigned int txChannel, bool applySetting=true)
Sets the DUC transmitter bitmap.
bool okToSend(long int pendingSamples, bool lockIfOk)
Determines if it is OK to send data.
bool disconnect(void)
Disconnects the flow control client.
virtual int debug(const char *format,...)
Outputs debug information.
Definition: Debuggable.cpp:95
bool setDucEnable(bool ducEnable, bool applySetting=true)
Sets whether or not the DUC is enabled.
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.
Definition: BasicList.h:25
bool setDucFrequency(long ducFreq, bool applySetting=true)
Sets the DUC frequency.
void testQueries(void)
Tests the flow control queries.
Defines functionality for LibCyberRadio applications.
Definition: App.h:23
virtual void run()
Executes the main processing loop for the thread.
bool connectToRadio(const std::string &hostname, unsigned int port)
Connects to the radio.
bool setDucAttenuation(float attenuation, bool applySetting=true)
Sets the DUC attenuation.
unsigned int getUpdateDelay()
Gets the update delay.
FlowControlClient(unsigned int ducChannel, bool config_tx, unsigned int updatesPerSecond, bool debug=false)
Constructs a FlowControlClient object.
Transmit status frame information.
Definition: PacketTypes.h:124
long int getFreeSpace(void)
Gets the amount of free space available.
bool setDucTxinvMode(unsigned int txinvMode, bool applySetting=true)
Sets the DUC TX Inversion Mode.
bool sentNSamples(long int samplesSent)
Updates status based on the number of samples sent.
void setDucChannel(unsigned int ducChannel)
Sets the DUC channel number.
Base class for a thread object, based on Boost Threads.
Definition: Thread.h:48
void update(void)
Updates the flow controller.
unsigned int setUpdateRate(unsigned int updatesPerSecond)
Sets the update rate.
bool setDucTenGbePort(unsigned int ducTenGbePort, bool applySetting=true)
Sets the 10GigE port used by the DUC.