GNU Radio's CYBERRADIO Package
vita_iq_source_2_impl.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /***************************************************************************
3  * \file vita_iq_source_impl.h
4  *
5  * \brief Implementation of a generic VITA 49-compatible I/Q data source
6  * block.
7  *
8  * \author DA
9  * \copyright 2015 CyberRadio Solutions, Inc.
10  */
11 
12 #ifndef INCLUDED_CYBERRADIO_VITA_IQ_SOURCE_2_IMPL_H
13 #define INCLUDED_CYBERRADIO_VITA_IQ_SOURCE_2_IMPL_H
14 
16 #include <LibCyberRadio/Common/Vita49Packet.h>
17 #include <boost/asio.hpp>
18 #include <boost/format.hpp>
19 #include <boost/thread.hpp>
20 #include <stdio.h>
21 #include <string>
22 #include <sys/types.h>
23 #include <time.h>
24 #include <vector>
25 
27 
28 namespace gr {
29 namespace CyberRadio {
30 
32 public:
33  vita_iq_source_2_impl(int vitaType, size_t payloadSize, size_t vitaHeaderSize,
34  size_t vitaTailSize, bool byteSwapped, bool iqSwapped,
35  const std::string &host, int port, bool debug,
36  bool tagOutput, bool coherent);
38 
39  void connect(const std::string &host, int port);
40  void disconnect();
41 
42  void set_receive_buffer_size(int size);
43  int get_receive_buffer_size(void);
44  void set_scale_factor(int);
45  int get_scale_factor();
46 
47  // Where all the action really happens
48  int work(int noutput_items, gr_vector_const_void_star &input_items,
49  gr_vector_void_star &output_items);
50 
51 protected:
52  // Debug output helper
53  int debug(const char *format, ...);
54 
55 private:
56  int d_vitaType;
57  size_t d_payloadSize; // maximum transmission unit (packet length)
58  size_t d_vitaHeaderSize;
59  size_t d_vitaTailSize;
60  bool d_byteSwapped;
61  bool d_iqSwapped;
62  bool d_tagOutput;
63  bool d_coherent;
64  size_t d_packetSize;
65 
66  bool d_connected; // are we connected?
67  char *d_rxbuf; // get UDP buffer items
68  char *d_residbuf; // hold buffer between calls
69  ssize_t
70  d_residual; // hold information about number of bytes stored in residbuf
71  ssize_t d_sent; // track how much of d_residbuf we've outputted
72  size_t d_offset; // point to residbuf location offset
73  std::string d_host;
74  unsigned short d_port;
75  bool d_debug;
76  int d_scale;
77 
78  boost::asio::ip::udp::socket *d_socket;
79  boost::asio::ip::udp::endpoint d_endpoint;
80  boost::asio::ip::udp::endpoint d_endpoint_rcvd;
81  boost::asio::io_service d_io_service;
82 
83  size_t d_tmpbuf_size;
84  char *d_tmpbuf;
85  char *d_tmpbuf2;
86  uint32_t d_frame_count;
87  uint64_t d_dropped;
88  int d_skip_packets;
89 
90  gr::thread::condition_variable d_cond_wait;
91  gr::thread::mutex d_udp_mutex;
92  gr::thread::thread d_udp_thread;
93 
94  void start_receive();
95  void handle_read(const boost::system::error_code &error,
96  size_t bytes_transferred);
97  void run_io_service() { d_io_service.run(); }
98 
99  int _read_socket_data(int noutput_items, char *output_buffer);
100  int _parse_vita_and_tag(char *output_buffer, int number_of_packets);
101 };
102 
103 } // namespace CyberRadio
104 } // namespace gr
105 
106 #endif /* INCLUDED_CYBERRADIO_VITA_IQ_SOURCE_2_IMPL_H */
void set_receive_buffer_size(int size)
Change the size of the UDP receive buffer.
vita_iq_source_2_impl(int vitaType, size_t payloadSize, size_t vitaHeaderSize, size_t vitaTailSize, bool byteSwapped, bool iqSwapped, const std::string &host, int port, bool debug, bool tagOutput, bool coherent)
void disconnect()
Cut the connection if we have one set up.
Creates a VITA 49 and/or I/Q radio data source block for GNU Radio.
Definition: vita_iq_source_2.h:55
void set_scale_factor(int)
Set the scale factor used when converting from short to float. Default is 32767.
Provides GNU Radio blocks.
Definition: NDR651_duc_sink_mk2.h:21
int get_receive_buffer_size(void)
Get the size of the UDP receive buffer.
int get_scale_factor()
Get the scale factor used when converting from short to float.
LibCyberRadio::Vita49Packet Vita49Packet
Definition: vita_iq_source_2_impl.h:26
Definition: vita_iq_source_2_impl.h:31
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
void connect(const std::string &host, int port)
Change the connection to a new destination.