GNSS-SDR  0.0.19
An Open Source GNSS Software Defined Receiver
gr_complex_ip_packet_source.h
Go to the documentation of this file.
1 /*!
2  * \file gr_complex_ip_packet_source.h
3  *
4  * \brief Receives ip frames containing samples in UDP frame encapsulation
5  * using a high performance packet capture library (libpcap)
6  * \author Javier Arribas jarribas (at) cttc.es
7  *
8  * -----------------------------------------------------------------------------
9  *
10  * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
11  * This file is part of GNSS-SDR.
12  *
13  * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
14  * SPDX-License-Identifier: GPL-3.0-or-later
15  *
16  * -----------------------------------------------------------------------------
17  */
18 
19 
20 #ifndef GNSS_SDR_GR_COMPLEX_IP_PACKET_SOURCE_H
21 #define GNSS_SDR_GR_COMPLEX_IP_PACKET_SOURCE_H
22 
23 #include "gnss_block_interface.h"
24 #include <boost/thread.hpp>
25 #include <gnuradio/sync_block.h>
26 #include <arpa/inet.h>
27 #include <net/ethernet.h>
28 #include <net/if.h>
29 #include <netinet/if_ether.h>
30 #include <pcap.h>
31 #include <string>
32 #include <sys/ioctl.h>
33 
34 /** \addtogroup Signal_Source
35  * \{ */
36 /** \addtogroup Signal_Source_gnuradio_blocks signal_source_gr_blocks
37  * GNU Radio blocks for signal sources.
38  * \{ */
39 
40 
41 class Gr_Complex_Ip_Packet_Source : virtual public gr::sync_block
42 {
43 public:
44  using sptr = gnss_shared_ptr<Gr_Complex_Ip_Packet_Source>;
45  static sptr make(std::string src_device,
46  const std::string &origin_address,
47  int udp_port,
48  int udp_packet_size,
49  int n_baseband_channels,
50  const std::string &wire_sample_type,
51  size_t item_size,
52  bool IQ_swap_);
53  Gr_Complex_Ip_Packet_Source(std::string src_device,
54  const std::string &origin_address,
55  int udp_port,
56  int udp_packet_size,
57  int n_baseband_channels,
58  const std::string &wire_sample_type,
59  size_t item_size,
60  bool IQ_swap_);
62 
63  // Called by gnuradio to enable drivers, etc for i/o devices.
64  bool start();
65 
66  // Called by gnuradio to disable drivers, etc for i/o devices.
67  bool stop();
68 
69  // Where all the action really happens
70  int work(int noutput_items,
71  gr_vector_const_void_star &input_items,
72  gr_vector_void_star &output_items);
73 
74 private:
75  void demux_samples(const gr_vector_void_star &output_items, int num_samples_readed);
76  void my_pcap_loop_thread(pcap_t *pcap_handle);
77  void pcap_callback(u_char *args, const struct pcap_pkthdr *pkthdr, const u_char *packet);
78  static void static_pcap_callback(u_char *args, const struct pcap_pkthdr *pkthdr, const u_char *packet);
79  /*
80  * Opens the ethernet device using libpcap raw capture mode
81  * If any of these fail, the function returns the error and exits.
82  */
83  bool open();
84 
85  boost::thread *d_pcap_thread;
86  // boost::mutex d_mutex;
87  struct sockaddr_in si_me
88  {
89  };
90  std::string d_src_device;
91  std::string d_origin_address;
92  pcap_t *descr; // ethernet pcap device descriptor
93  char *fifo_buff;
94  int fifo_read_ptr;
95  int fifo_write_ptr;
96  int fifo_items;
97  int d_sock_raw;
98  int d_udp_port;
99  int d_n_baseband_channels;
100  int d_wire_sample_type;
101  float d_bytes_per_sample;
102  bool d_IQ_swap;
103 };
104 
105 
106 /** \} */
107 /** \} */
108 #endif // GNSS_SDR_GR_COMPLEX_IP_PACKET_SOURCE_H
This interface represents a GNSS block.