libcyberradio  22.01.24
StatusReceiver.h
1 /***************************************************************************
2  * \file StatusReceiver.h
3  *
4  * \brief NDR651 UDP status receiver.
5  *
6  * \author NH
7  * \author JVM
8  * \copyright Copyright (c) 2015-2021 CyberRadio Solutions, Inc.
9  *
10  */
11 
12 #ifndef INCLUDED_LIBCYBERRADIO_NDR651_STATUSRECEIVER_H_
13 #define INCLUDED_LIBCYBERRADIO_NDR651_STATUSRECEIVER_H_
14 
15 #include <boost/thread/mutex.hpp>
16 #include "LibCyberRadio/Common/Debuggable.h"
17 #include "LibCyberRadio/Common/Thread.h"
18 
19 #define MAX_RX_SIZE 8192
20 #define MAX_RADIO_BUFFSIZE 67108862 // (2^26)-2 samples
21 #define RADIO_BUFFER_RESERVE 1048576
22 
26 namespace LibCyberRadio
27 {
32  namespace NDR651
33  {
34 
39  {
40  public:
48  StatusReceiver(std::string ifname, unsigned int port, bool debug, bool updatePE);
52  virtual ~StatusReceiver();
56  virtual void run();
62  bool setStatusInterface(std::string ifname);
69  bool setStatusInterface(std::string ifname, bool makeSocketFlag);
75  bool setStatusPort(unsigned int port);
82  bool setStatusPort(unsigned int port, bool makeSocketFlag);
89  bool okToSend(long int pendingSamples, bool lockIfOk);
94  long int getFreeSpace(void);
100  bool sentNSamples(long int samplesSent);
101 
102  bool setUpdatePE(bool updatePE);
103  bool getUpdatePE(void) { return _updatePE; };
104  int setMaxFreeSpace(float fs, float maxLatency);
105  int getMaxFreeSpace(void) { return _freeSpaceMax; };
106  //~ bool setUdpPort(unsigned int port);
107  int getUdpPort(void) { return _port; };
108  void blockUntilAvailable(unsigned int numSamples);
109 
110  private:
111  int _sockfd;
112  char _rxbuff[MAX_RX_SIZE];
113  fd_set set;
114  bool _sendLock;
115  bool _shutdown;
116  bool _updatePE;
117 
118  std::string _ifname;
119  unsigned int _port;
120  uint64_t timeoutCount;
121 
122  int _651freeSpace;
123  int _freeSpaceMax;
124 
125  // Synchronization and signal mechanisms
126  boost::mutex objectAccessMutex;
127  boost::condition_variable waitCondition;
128 
129  bool _makeSocket(void);
130  bool _setFreeSpace(int, bool, bool, bool);
131  };
132 
133  } /* namespace NDR651 */
134 
135 } /* namespace LibCyberRadio */
136 
137 #endif /* INCLUDED_LIBCYBERRADIO_NDR651_STATUSRECEIVER_H_ */
bool okToSend(long int pendingSamples, bool lockIfOk)
Determines if it is OK to send data.
StatusReceiver(std::string ifname, unsigned int port, bool debug, bool updatePE)
Constructs a StatusReceiver object.
virtual void run()
Executes the main processing loop for the thread.
Class that supports debug output.
Definition: Debuggable.h:38
bool setStatusPort(unsigned int port)
Sets the UDP port.
bool setStatusInterface(std::string ifname)
Sets the interface name.
bool sentNSamples(long int samplesSent)
Updates status based on the number of samples sent.
virtual ~StatusReceiver()
Destroys a StatusReceiver object.
virtual int debug(const char *format,...)
Outputs debug information.
Definition: Debuggable.cpp:95
Defines functionality for LibCyberRadio applications.
Definition: App.h:23
long int getFreeSpace(void)
Gets the amount of free space available.
Base class for a thread object, based on Boost Threads.
Definition: Thread.h:48