GNU Radio's IIO Package
multi_source_impl.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2014 Analog Devices Inc.
4  * Author: Paul Cercueil <paul.cercueil@analog.com>
5  *
6  * This is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3, or (at your option)
9  * any later version.
10  *
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this software; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef INCLUDED_IIO_MULTI_SOURCE_IMPL_H
23 #define INCLUDED_IIO_MULTI_SOURCE_IMPL_H
24 
25 #include <string>
26 #include <vector>
27 #include <map>
28 
29 #include <iio.h>
30 #include <boost/thread.hpp>
31 #include <iio/multi_source.h>
32 
33 namespace gr {
34  namespace iio {
35 
36  static std::map<std::string,struct iio_context *> contexts;
37 
39  {
40  private:
41  void channel_read(const struct iio_channel *chn,
42  void *dst, size_t len);
43 
44  boost::mutex iio_mutex;
45  boost::condition_variable iio_cond, iio_cond2;
46  unsigned long items_in_buffer;
47  off_t byte_offset;
48  unsigned long sample_counter;
49  volatile bool please_refill_buffer, thread_stopped;
50  pmt::pmt_t port_id;
51 
52  boost::thread refill_thd;
53 
54  unsigned long timeout;
55 
56  void refill_thread();
57 
58  protected:
59  struct iio_context *ctx;
60  struct iio_device *dev, *phy1, *phy2;
61  struct iio_buffer *buf;
62  std::vector <struct iio_channel *> channel_list;
63  unsigned int buffer_size;
64  unsigned int decimation;
66 
67  public:
68  multi_source_impl(struct iio_context *ctx, bool destroy_ctx,
69  const std::string &device,
70  const std::vector<std::string> &channels,
71  const std::string &device_phy1,
72  const std::vector<std::string> &params1,
73  const std::string &device_phy2,
74  const std::vector<std::string> &params2,
75  unsigned int buffer_size = DEFAULT_BUFFER_SIZE,
76  unsigned int decimation = 0);
78 
79  static void set_params(struct iio_device *phy,
80  const std::vector<std::string> &params);
81 
82  void set_params0(const std::vector<std::string> &params);
83  void set_params1(const std::vector<std::string> &params);
84  void set_params2(const std::vector<std::string> &params);
85  void set_buffer_size(unsigned int buffer_size);
86  void set_timeout_ms(unsigned long timeout);
87 
88  // Where all the action really happens
89  int work(int noutput_items,
90  gr_vector_const_void_star &input_items,
91  gr_vector_void_star &output_items);
92 
93  bool start();
94  bool stop();
95 
96  static struct iio_context * get_context(const std::string &uri);
97  static bool load_fir_filter(std::string &filter, struct iio_device *phy);
98  };
99 
100  } // namespace iio
101 } // namespace gr
102 
103 #endif /* INCLUDED_IIO_MULTI_SOURCE_IMPL_H */
static struct iio_context * get_context(const std::string &uri)
multi_source_impl(struct iio_context *ctx, bool destroy_ctx, const std::string &device, const std::vector< std::string > &channels, const std::string &device_phy1, const std::vector< std::string > &params1, const std::string &device_phy2, const std::vector< std::string > &params2, unsigned int buffer_size=DEFAULT_BUFFER_SIZE, unsigned int decimation=0)
static bool load_fir_filter(std::string &filter, struct iio_device *phy)
unsigned int decimation
Definition: multi_source_impl.h:64
std::vector< struct iio_channel * > channel_list
Definition: multi_source_impl.h:62
#define DEFAULT_BUFFER_SIZE
Definition: device_sink.h:29
static std::vector< ctxInfo > contexts
Definition: device_source_impl.h:36
unsigned int buffer_size
Definition: multi_source_impl.h:63
static void set_params(struct iio_device *phy, const std::vector< std::string > &params)
struct iio_device * dev
Definition: multi_source_impl.h:60
void set_params1(const std::vector< std::string > &params)
Definition: attr_sink.h:29
void set_params0(const std::vector< std::string > &params)
struct iio_buffer * buf
Definition: multi_source_impl.h:61
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
bool destroy_ctx
Definition: multi_source_impl.h:65
Definition: multi_source_impl.h:38
struct iio_device * phy1
Definition: multi_source_impl.h:60
struct iio_context * ctx
Definition: multi_source_impl.h:59
void set_params2(const std::vector< std::string > &params)
<+description of block+>
Definition: multi_source.h:43
struct iio_device * phy2
Definition: multi_source_impl.h:60
void set_timeout_ms(unsigned long timeout)
void set_buffer_size(unsigned int buffer_size)