GNU Radio 3.4.0 C++ API
comedi_source_s.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2005 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 #ifndef INCLUDED_COMEDI_SOURCE_S_H
00023 #define INCLUDED_COMEDI_SOURCE_S_H
00024 
00025 #include <gr_sync_block.h>
00026 #include <string>
00027 #include <comedilib.h>
00028 #include <stdexcept>
00029 
00030 class comedi_source_s;
00031 typedef boost::shared_ptr<comedi_source_s> comedi_source_s_sptr;
00032 
00033 /*!
00034  * \brief make a COMEDI source.
00035  *
00036  * \param sampling_freq sampling rate in Hz
00037  * \param dev COMEDI device name, e.g., "/dev/comedi0"
00038  */
00039 comedi_source_s_sptr
00040 comedi_make_source_s (int sampling_freq,
00041                       const std::string dev = "/dev/comedi0");
00042 
00043 /*!
00044  * \brief source using COMEDI
00045  *
00046  * The source has one to many input stream of signed short integers.
00047  *
00048  * Output samples will be in the range [-32768,32767].
00049  */
00050 class comedi_source_s : public gr_sync_block {
00051   friend comedi_source_s_sptr
00052   comedi_make_source_s (int sampling_freq, const std::string dev);
00053 
00054   // typedef for pointer to class work method
00055   typedef int (comedi_source_s::*work_t)(int noutput_items,
00056                                          gr_vector_const_void_star &input_items,
00057                                          gr_vector_void_star &output_items);
00058 
00059   unsigned int          d_sampling_freq;
00060   std::string           d_device_name;
00061 
00062   comedi_t              *d_dev;
00063   int                   d_subdevice;
00064   int                   d_n_chan;
00065   void                  *d_map;
00066   int                   d_buffer_size;
00067   unsigned              d_buf_front;
00068   unsigned              d_buf_back;
00069 
00070   // random stats
00071   int                   d_noverruns;            // count of overruns
00072 
00073   void output_error_msg (const char *msg, int err);
00074   void bail (const char *msg, int err) throw (std::runtime_error);
00075 
00076 
00077  protected:
00078   comedi_source_s (int sampling_freq, const std::string device_name);
00079 
00080  public:
00081   ~comedi_source_s ();
00082   
00083   bool check_topology (int ninputs, int noutputs);
00084 
00085   int work (int noutput_items,
00086             gr_vector_const_void_star &input_items,
00087             gr_vector_void_star &output_items);
00088 };
00089 
00090 #endif /* INCLUDED_COMEDI_SOURCE_S_H */