GNU Radio 3.6.4.1 C++ API
comedi_sink_s.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2005 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 #ifndef INCLUDED_COMEDI_SINK_H
23 #define INCLUDED_COMEDI_SINK_H
24 
25 #include <gr_sync_block.h>
26 #include <string>
27 #include <comedilib.h>
28 #include <stdexcept>
29 
30 class comedi_sink_s;
32 
33 /*!
34  * \brief make a COMEDI sink.
35  *
36  * \param sampling_freq sampling rate in Hz
37  * \param dev COMEDI device name, e.g., "/dev/comedi0"
38  */
40 comedi_make_sink_s (int sampling_freq,
41  const std::string dev = "/dev/comedi0");
42 
43 /*!
44  * \brief sink using COMEDI
45  *
46  * The sink has one input stream of signed short integers.
47  *
48  * Input samples must be in the range [-32768,32767].
49  */
50 class comedi_sink_s : public gr_sync_block {
51  friend comedi_sink_s_sptr
52  comedi_make_sink_s (int sampling_freq, const std::string dev);
53 
54  // typedef for pointer to class work method
55  typedef int (comedi_sink_s::*work_t)(int noutput_items,
56  gr_vector_const_void_star &input_items,
57  gr_vector_void_star &output_items);
58 
59  unsigned int d_sampling_freq;
60  std::string d_device_name;
61 
62  comedi_t *d_dev;
63  int d_subdevice;
64  int d_n_chan;
65  void *d_map;
66  int d_buffer_size;
67  unsigned d_buf_front;
68  unsigned d_buf_back;
69 
70  // random stats
71  int d_nunderuns; // count of underruns
72 
73  void output_error_msg (const char *msg, int err);
74  void bail (const char *msg, int err) throw (std::runtime_error);
75 
76  protected:
77  comedi_sink_s (int sampling_freq, const std::string device_name);
78 
79  public:
80  ~comedi_sink_s ();
81 
82  bool check_topology (int ninputs, int noutputs);
83 
84  int work (int noutput_items,
85  gr_vector_const_void_star &input_items,
86  gr_vector_void_star &output_items);
87 };
88 
89 #endif /* INCLUDED_COMEDI_SINK_H */