From 5d69a524f81f234b3fbc41d49ba18d6f6886baba Mon Sep 17 00:00:00 2001 From: jcorgan Date: Thu, 3 Aug 2006 04:51:51 +0000 Subject: Houston, we have a trunk. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3122 221aa14e-8319-0410-a670-987f0aec2ac5 --- gr-comedi/src/comedi_source_s.cc | 229 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 gr-comedi/src/comedi_source_s.cc (limited to 'gr-comedi/src/comedi_source_s.cc') diff --git a/gr-comedi/src/comedi_source_s.cc b/gr-comedi/src/comedi_source_s.cc new file mode 100644 index 000000000..5041c9c30 --- /dev/null +++ b/gr-comedi/src/comedi_source_s.cc @@ -0,0 +1,229 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include +#include +#include +#include +#include + + +// FIXME these should query some kind of user preference + + +static std::string +default_device_name () +{ + return "/dev/comedi0"; +} + +// ---------------------------------------------------------------- + +comedi_source_s_sptr +comedi_make_source_s (int sampling_freq, const std::string dev) +{ + return comedi_source_s_sptr (new comedi_source_s (sampling_freq, dev)); +} + +comedi_source_s::comedi_source_s (int sampling_freq, + const std::string device_name) + : gr_sync_block ("comedi_source_s", + gr_make_io_signature (0, 0, 0), + gr_make_io_signature (0, 0, 0)), + d_sampling_freq (sampling_freq), + d_device_name (device_name.empty() ? default_device_name() : device_name), + d_dev (0), + d_subdevice (0/*COMEDI_SUBD_AI*/), + d_n_chan (1), // number of input channels + d_map (0), + d_buffer_size (0), + d_buf_front (0), + d_buf_back (0) +{ + int aref=AREF_GROUND; + int range=0; + + d_dev = comedi_open(d_device_name.c_str()); + if (d_dev == 0){ + comedi_perror(d_device_name.c_str()); + throw std::runtime_error ("comedi_source_s"); + } + + unsigned int chanlist[256]; + + for(int i=0; i d_n_chan) + throw std::runtime_error ("comedi_source_s"); + + return true; +} + +comedi_source_s::~comedi_source_s () +{ + if (d_map) { + munmap(d_map, d_buffer_size); + d_map = 0; + } + + comedi_close(d_dev); +} + +int +comedi_source_s::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + int ret; + + int work_left = noutput_items * sizeof(sampl_t) * d_n_chan; + sampl_t *pbuf = (sampl_t*)d_map; + + do { + + do { + ret = comedi_get_buffer_contents(d_dev,d_subdevice); + if (ret < 0) + bail ("comedi_get_buffer_contents", comedi_errno()); + + assert(ret % sizeof(sampl_t) == 0); + assert(work_left % sizeof(sampl_t) == 0); + + ret = std::min(ret, work_left); + d_buf_front += ret; + + assert(d_buffer_size%d_n_chan == 0); + if (d_buf_front-d_buf_back > (unsigned)d_buffer_size) { + d_buf_front+=d_buffer_size; + d_buf_back +=d_buffer_size; + } + + if(d_buf_front==d_buf_back){ + usleep(1000000*std::min(work_left,d_buffer_size/2)/(d_sampling_freq*sizeof(sampl_t)*d_n_chan)); + continue; + } + } while (d_buf_front==d_buf_back); + + for(unsigned i=d_buf_back/sizeof(sampl_t);i0); + + return noutput_items; +} + +void +comedi_source_s::output_error_msg (const char *msg, int err) +{ + fprintf (stderr, "comedi_source_s[%s]: %s: %s\n", + d_device_name.c_str(), msg, comedi_strerror(err)); +} + +void +comedi_source_s::bail (const char *msg, int err) throw (std::runtime_error) +{ + output_error_msg (msg, err); + throw std::runtime_error ("comedi_source_s"); +} -- cgit From 86f5c92427b3f4bb30536d76cf63c3fca388fb2f Mon Sep 17 00:00:00 2001 From: eb Date: Wed, 13 Sep 2006 21:30:04 +0000 Subject: Updated FSF address in all files. Fixes ticket:51 git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3534 221aa14e-8319-0410-a670-987f0aec2ac5 --- gr-comedi/src/comedi_source_s.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gr-comedi/src/comedi_source_s.cc') diff --git a/gr-comedi/src/comedi_source_s.cc b/gr-comedi/src/comedi_source_s.cc index 5041c9c30..f41f8ca39 100644 --- a/gr-comedi/src/comedi_source_s.cc +++ b/gr-comedi/src/comedi_source_s.cc @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H -- cgit From 937b719d2e57d0497293d603da10cac2532346f6 Mon Sep 17 00:00:00 2001 From: eb Date: Sat, 21 Jul 2007 03:44:38 +0000 Subject: Updated license from GPL version 2 or later to GPL version 3 or later. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6044 221aa14e-8319-0410-a670-987f0aec2ac5 --- gr-comedi/src/comedi_source_s.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gr-comedi/src/comedi_source_s.cc') diff --git a/gr-comedi/src/comedi_source_s.cc b/gr-comedi/src/comedi_source_s.cc index f41f8ca39..4e3980e76 100644 --- a/gr-comedi/src/comedi_source_s.cc +++ b/gr-comedi/src/comedi_source_s.cc @@ -6,7 +6,7 @@ * * GNU Radio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) + * the Free Software Foundation; either version 3, or (at your option) * any later version. * * GNU Radio is distributed in the hope that it will be useful, -- cgit From 0a9b999b5cce596f4de05828005f698047e14ce9 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Tue, 3 Aug 2010 13:36:18 -0700 Subject: Modify all block factories to use gnuradio::get_initial_sptr. --- gr-comedi/src/comedi_source_s.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gr-comedi/src/comedi_source_s.cc') diff --git a/gr-comedi/src/comedi_source_s.cc b/gr-comedi/src/comedi_source_s.cc index 4e3980e76..a52d04e2a 100644 --- a/gr-comedi/src/comedi_source_s.cc +++ b/gr-comedi/src/comedi_source_s.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2005,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -49,7 +49,7 @@ default_device_name () comedi_source_s_sptr comedi_make_source_s (int sampling_freq, const std::string dev) { - return comedi_source_s_sptr (new comedi_source_s (sampling_freq, dev)); + return gnuradio::get_initial_sptr(new comedi_source_s (sampling_freq, dev)); } comedi_source_s::comedi_source_s (int sampling_freq, -- cgit From 7f622fef32225552811ccffa6b55fa6b2ad08f23 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 23 Jul 2011 23:17:06 -0700 Subject: comedi: cmake build support for gr-comedi component (linux only) --- gr-comedi/src/comedi_source_s.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gr-comedi/src/comedi_source_s.cc') diff --git a/gr-comedi/src/comedi_source_s.cc b/gr-comedi/src/comedi_source_s.cc index a52d04e2a..5d9f2f6b0 100644 --- a/gr-comedi/src/comedi_source_s.cc +++ b/gr-comedi/src/comedi_source_s.cc @@ -85,7 +85,7 @@ comedi_source_s::comedi_source_s (int sampling_freq, comedi_cmd cmd; int ret; - ret = comedi_get_cmd_generic_timed(d_dev,d_subdevice,&cmd,(unsigned int)(1e9/sampling_freq)); + ret = comedi_get_cmd_generic_timed(d_dev,d_subdevice,&cmd,d_n_chan,(unsigned int)(1e9/sampling_freq)); if(ret<0) bail ("comedi_get_cmd_generic_timed", comedi_errno()); -- cgit From f919f9dcbb54a08e6e26d6c229ce92fb784fa1b2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 13 Apr 2012 18:36:53 -0400 Subject: Removed whitespace and added dtools/bin/remove-whitespace as a tool to do this in the future. The sed script was provided by Moritz Fischer. --- gr-comedi/src/comedi_source_s.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'gr-comedi/src/comedi_source_s.cc') diff --git a/gr-comedi/src/comedi_source_s.cc b/gr-comedi/src/comedi_source_s.cc index 5d9f2f6b0..517f1440b 100644 --- a/gr-comedi/src/comedi_source_s.cc +++ b/gr-comedi/src/comedi_source_s.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2005,2010 Free Software Foundation, Inc. - * + * * This file is part of GNU Radio - * + * * GNU Radio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3, or (at your option) * any later version. - * + * * GNU Radio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -38,7 +38,7 @@ // FIXME these should query some kind of user preference -static std::string +static std::string default_device_name () { return "/dev/comedi0"; @@ -197,7 +197,7 @@ comedi_source_s::work (int noutput_items, int o_idx = noutput_items-work_left/d_n_chan/sizeof(sampl_t)+(i-d_buf_back/sizeof(sampl_t))/d_n_chan; if (output_items[chan]) - ((short*)(output_items[chan]))[o_idx] = + ((short*)(output_items[chan]))[o_idx] = (int)pbuf[i%(d_buffer_size/sizeof(sampl_t))] - 32767; } -- cgit