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 --- gnuradio-core/src/lib/io/Makefile.am | 96 ++++++ .../src/lib/io/gr_file_descriptor_sink.cc | 83 +++++ gnuradio-core/src/lib/io/gr_file_descriptor_sink.h | 58 ++++ gnuradio-core/src/lib/io/gr_file_descriptor_sink.i | 35 ++ .../src/lib/io/gr_file_descriptor_source.cc | 146 ++++++++ .../src/lib/io/gr_file_descriptor_source.h | 67 ++++ .../src/lib/io/gr_file_descriptor_source.i | 35 ++ gnuradio-core/src/lib/io/gr_file_sink.cc | 144 ++++++++ gnuradio-core/src/lib/io/gr_file_sink.h | 75 ++++ gnuradio-core/src/lib/io/gr_file_sink.i | 45 +++ gnuradio-core/src/lib/io/gr_file_source.cc | 131 +++++++ gnuradio-core/src/lib/io/gr_file_source.h | 68 ++++ gnuradio-core/src/lib/io/gr_file_source.i | 43 +++ gnuradio-core/src/lib/io/gr_message_sink.cc | 78 +++++ gnuradio-core/src/lib/io/gr_message_sink.h | 62 ++++ gnuradio-core/src/lib/io/gr_message_sink.i | 36 ++ gnuradio-core/src/lib/io/gr_message_source.cc | 104 ++++++ gnuradio-core/src/lib/io/gr_message_source.h | 64 ++++ gnuradio-core/src/lib/io/gr_message_source.i | 36 ++ gnuradio-core/src/lib/io/gr_oscope_guts.cc | 382 +++++++++++++++++++++ gnuradio-core/src/lib/io/gr_oscope_guts.h | 116 +++++++ gnuradio-core/src/lib/io/gr_oscope_sink.i | 79 +++++ gnuradio-core/src/lib/io/gr_oscope_sink_f.cc | 80 +++++ gnuradio-core/src/lib/io/gr_oscope_sink_f.h | 65 ++++ gnuradio-core/src/lib/io/gr_oscope_sink_x.cc | 138 ++++++++ gnuradio-core/src/lib/io/gr_oscope_sink_x.h | 73 ++++ gnuradio-core/src/lib/io/gr_trigger_mode.h | 32 ++ gnuradio-core/src/lib/io/gri_logger.cc | 173 ++++++++++ gnuradio-core/src/lib/io/gri_logger.h | 55 +++ gnuradio-core/src/lib/io/i2c.cc | 28 ++ gnuradio-core/src/lib/io/i2c.h | 48 +++ gnuradio-core/src/lib/io/i2c_bbio.cc | 29 ++ gnuradio-core/src/lib/io/i2c_bbio.h | 49 +++ gnuradio-core/src/lib/io/i2c_bbio_pp.cc | 87 +++++ gnuradio-core/src/lib/io/i2c_bbio_pp.h | 55 +++ gnuradio-core/src/lib/io/i2c_bitbang.cc | 144 ++++++++ gnuradio-core/src/lib/io/i2c_bitbang.h | 63 ++++ gnuradio-core/src/lib/io/io.i | 52 +++ gnuradio-core/src/lib/io/microtune_4702.cc | 183 ++++++++++ gnuradio-core/src/lib/io/microtune_4702.h | 69 ++++ .../src/lib/io/microtune_4702_eval_board.cc | 88 +++++ .../src/lib/io/microtune_4702_eval_board.h | 47 +++ .../src/lib/io/microtune_4702_eval_board.i | 36 ++ gnuradio-core/src/lib/io/microtune_4937.cc | 146 ++++++++ gnuradio-core/src/lib/io/microtune_4937.h | 66 ++++ .../src/lib/io/microtune_4937_eval_board.cc | 97 ++++++ .../src/lib/io/microtune_4937_eval_board.h | 48 +++ .../src/lib/io/microtune_4937_eval_board.i | 36 ++ gnuradio-core/src/lib/io/microtune_eval_board.i | 95 +++++ .../src/lib/io/microtune_eval_board_defs.h | 71 ++++ gnuradio-core/src/lib/io/microtune_xxxx.cc | 41 +++ gnuradio-core/src/lib/io/microtune_xxxx.h | 64 ++++ .../src/lib/io/microtune_xxxx_eval_board.cc | 140 ++++++++ .../src/lib/io/microtune_xxxx_eval_board.h | 96 ++++++ .../src/lib/io/microtune_xxxx_eval_board.i | 58 ++++ gnuradio-core/src/lib/io/ppio.cc | 39 +++ gnuradio-core/src/lib/io/ppio.h | 61 ++++ gnuradio-core/src/lib/io/ppio.i | 48 +++ gnuradio-core/src/lib/io/ppio_ppdev.cc | 221 ++++++++++++ gnuradio-core/src/lib/io/ppio_ppdev.h | 60 ++++ gnuradio-core/src/lib/io/sdr_1000.cc | 65 ++++ gnuradio-core/src/lib/io/sdr_1000.h | 51 +++ gnuradio-core/src/lib/io/sdr_1000.i | 36 ++ 63 files changed, 5116 insertions(+) create mode 100644 gnuradio-core/src/lib/io/Makefile.am create mode 100644 gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc create mode 100644 gnuradio-core/src/lib/io/gr_file_descriptor_sink.h create mode 100644 gnuradio-core/src/lib/io/gr_file_descriptor_sink.i create mode 100644 gnuradio-core/src/lib/io/gr_file_descriptor_source.cc create mode 100644 gnuradio-core/src/lib/io/gr_file_descriptor_source.h create mode 100644 gnuradio-core/src/lib/io/gr_file_descriptor_source.i create mode 100644 gnuradio-core/src/lib/io/gr_file_sink.cc create mode 100644 gnuradio-core/src/lib/io/gr_file_sink.h create mode 100644 gnuradio-core/src/lib/io/gr_file_sink.i create mode 100644 gnuradio-core/src/lib/io/gr_file_source.cc create mode 100644 gnuradio-core/src/lib/io/gr_file_source.h create mode 100644 gnuradio-core/src/lib/io/gr_file_source.i create mode 100644 gnuradio-core/src/lib/io/gr_message_sink.cc create mode 100644 gnuradio-core/src/lib/io/gr_message_sink.h create mode 100644 gnuradio-core/src/lib/io/gr_message_sink.i create mode 100644 gnuradio-core/src/lib/io/gr_message_source.cc create mode 100644 gnuradio-core/src/lib/io/gr_message_source.h create mode 100644 gnuradio-core/src/lib/io/gr_message_source.i create mode 100644 gnuradio-core/src/lib/io/gr_oscope_guts.cc create mode 100644 gnuradio-core/src/lib/io/gr_oscope_guts.h create mode 100644 gnuradio-core/src/lib/io/gr_oscope_sink.i create mode 100644 gnuradio-core/src/lib/io/gr_oscope_sink_f.cc create mode 100644 gnuradio-core/src/lib/io/gr_oscope_sink_f.h create mode 100644 gnuradio-core/src/lib/io/gr_oscope_sink_x.cc create mode 100644 gnuradio-core/src/lib/io/gr_oscope_sink_x.h create mode 100644 gnuradio-core/src/lib/io/gr_trigger_mode.h create mode 100644 gnuradio-core/src/lib/io/gri_logger.cc create mode 100644 gnuradio-core/src/lib/io/gri_logger.h create mode 100644 gnuradio-core/src/lib/io/i2c.cc create mode 100644 gnuradio-core/src/lib/io/i2c.h create mode 100644 gnuradio-core/src/lib/io/i2c_bbio.cc create mode 100644 gnuradio-core/src/lib/io/i2c_bbio.h create mode 100644 gnuradio-core/src/lib/io/i2c_bbio_pp.cc create mode 100644 gnuradio-core/src/lib/io/i2c_bbio_pp.h create mode 100644 gnuradio-core/src/lib/io/i2c_bitbang.cc create mode 100644 gnuradio-core/src/lib/io/i2c_bitbang.h create mode 100644 gnuradio-core/src/lib/io/io.i create mode 100644 gnuradio-core/src/lib/io/microtune_4702.cc create mode 100644 gnuradio-core/src/lib/io/microtune_4702.h create mode 100644 gnuradio-core/src/lib/io/microtune_4702_eval_board.cc create mode 100644 gnuradio-core/src/lib/io/microtune_4702_eval_board.h create mode 100644 gnuradio-core/src/lib/io/microtune_4702_eval_board.i create mode 100644 gnuradio-core/src/lib/io/microtune_4937.cc create mode 100644 gnuradio-core/src/lib/io/microtune_4937.h create mode 100644 gnuradio-core/src/lib/io/microtune_4937_eval_board.cc create mode 100644 gnuradio-core/src/lib/io/microtune_4937_eval_board.h create mode 100644 gnuradio-core/src/lib/io/microtune_4937_eval_board.i create mode 100644 gnuradio-core/src/lib/io/microtune_eval_board.i create mode 100644 gnuradio-core/src/lib/io/microtune_eval_board_defs.h create mode 100644 gnuradio-core/src/lib/io/microtune_xxxx.cc create mode 100644 gnuradio-core/src/lib/io/microtune_xxxx.h create mode 100644 gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc create mode 100644 gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h create mode 100644 gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i create mode 100644 gnuradio-core/src/lib/io/ppio.cc create mode 100644 gnuradio-core/src/lib/io/ppio.h create mode 100644 gnuradio-core/src/lib/io/ppio.i create mode 100644 gnuradio-core/src/lib/io/ppio_ppdev.cc create mode 100644 gnuradio-core/src/lib/io/ppio_ppdev.h create mode 100644 gnuradio-core/src/lib/io/sdr_1000.cc create mode 100644 gnuradio-core/src/lib/io/sdr_1000.h create mode 100644 gnuradio-core/src/lib/io/sdr_1000.i (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am new file mode 100644 index 000000000..e390e1344 --- /dev/null +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -0,0 +1,96 @@ +# +# Copyright 2001,2003,2004 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. +# + +include $(top_srcdir)/Makefile.common + + +INCLUDES = $(STD_DEFINES_AND_INCLUDES) + +noinst_LTLIBRARIES = libio.la + + +libio_la_SOURCES = \ + gr_file_sink.cc \ + gr_file_source.cc \ + gr_file_descriptor_sink.cc \ + gr_file_descriptor_source.cc \ + gr_message_sink.cc \ + gr_message_source.cc \ + gr_oscope_guts.cc \ + gr_oscope_sink_f.cc \ + gr_oscope_sink_x.cc \ + gri_logger.cc \ + i2c.cc \ + i2c_bitbang.cc \ + i2c_bbio.cc \ + i2c_bbio_pp.cc \ + microtune_4702.cc \ + microtune_4937.cc \ + microtune_4702_eval_board.cc \ + microtune_4937_eval_board.cc \ + microtune_xxxx.cc \ + microtune_xxxx_eval_board.cc \ + ppio.cc \ + ppio_ppdev.cc \ + sdr_1000.cc + +grinclude_HEADERS = \ + gr_file_sink.h \ + gr_file_source.h \ + gr_file_descriptor_sink.h \ + gr_file_descriptor_source.h \ + gr_message_sink.h \ + gr_message_source.h \ + gr_oscope_guts.h \ + gr_oscope_sink_f.h \ + gr_oscope_sink_x.h \ + gr_trigger_mode.h \ + gri_logger.h \ + i2c.h \ + i2c_bitbang.h \ + i2c_bbio.h \ + i2c_bbio_pp.h \ + microtune_4702.h \ + microtune_4937.h \ + microtune_4702_eval_board.h \ + microtune_4937_eval_board.h \ + microtune_eval_board_defs.h \ + microtune_xxxx.h \ + microtune_xxxx_eval_board.h \ + ppio.h \ + ppio_ppdev.h \ + sdr_1000.h + + +swiginclude_HEADERS = \ + io.i \ + gr_file_sink.i \ + gr_file_source.i \ + gr_file_descriptor_sink.i \ + gr_file_descriptor_source.i \ + gr_message_sink.i \ + gr_message_source.i \ + gr_oscope_sink.i \ + microtune_xxxx_eval_board.i \ + microtune_4702_eval_board.i \ + microtune_4937_eval_board.i \ + ppio.i \ + sdr_1000.i diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc new file mode 100644 index 000000000..6a0b1ca4a --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc @@ -0,0 +1,83 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 + + +gr_file_descriptor_sink::gr_file_descriptor_sink (size_t itemsize, int fd) + : gr_sync_block ("file_descriptor_sink", + gr_make_io_signature (1, 1, itemsize), + gr_make_io_signature (0, 0, 0)), + d_itemsize (itemsize), d_fd (fd) +{ +} + +gr_file_descriptor_sink_sptr +gr_make_file_descriptor_sink (size_t itemsize, int fd) +{ + return gr_file_descriptor_sink_sptr (new gr_file_descriptor_sink (itemsize, fd)); +} + +gr_file_descriptor_sink::~gr_file_descriptor_sink () +{ + close (d_fd); +} + +int +gr_file_descriptor_sink::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + char *inbuf = (char *) input_items[0]; + unsigned long byte_size = noutput_items * d_itemsize; + + while (byte_size > 0){ + ssize_t r; + + r = write (d_fd, inbuf, byte_size); + if (r == -1){ + if (errno == EINTR) + continue; + else { + perror ("gr_file_descriptor_sink"); + return -1; // indicate we're done + } + } + else { + byte_size -= r; + inbuf += r; + } + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h new file mode 100644 index 000000000..a811ce705 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +#ifndef INCLUDED_GR_FILE_DESCRIPTOR_SINK_H +#define INCLUDED_GR_FILE_DESCRIPTOR_SINK_H + +#include + +class gr_file_descriptor_sink; +typedef boost::shared_ptr gr_file_descriptor_sink_sptr; + +gr_file_descriptor_sink_sptr gr_make_file_descriptor_sink (size_t itemsize, int fd); + +/*! + * \brief Write stream to file descriptor. + * \ingroup sink + */ + +class gr_file_descriptor_sink : public gr_sync_block +{ + friend gr_file_descriptor_sink_sptr gr_make_file_descriptor_sink (size_t itemsize, int fd); + + private: + size_t d_itemsize; + int d_fd; + + protected: + gr_file_descriptor_sink (size_t itemsize, int fd); + + public: + ~gr_file_descriptor_sink (); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + + +#endif /* INCLUDED_GR_FILE_DESCRIPTOR_SINK_H */ diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.i b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.i new file mode 100644 index 000000000..e05818656 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.i @@ -0,0 +1,35 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,file_descriptor_sink) + +gr_file_descriptor_sink_sptr +gr_make_file_descriptor_sink (size_t itemsize, int fd); + +class gr_file_descriptor_sink : public gr_sync_block +{ + protected: + gr_file_descriptor_sink (size_t itemsize, int fd); + + public: + ~gr_file_descriptor_sink (); +}; diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc b/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc new file mode 100644 index 000000000..38b9da010 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc @@ -0,0 +1,146 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,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 + + +gr_file_descriptor_source::gr_file_descriptor_source (size_t itemsize, + int fd, + bool repeat) + : gr_sync_block ("file_descriptor_source", + gr_make_io_signature (0, 0, 0), + gr_make_io_signature (1, 1, itemsize)), + d_itemsize (itemsize), d_fd (fd), d_repeat (repeat), + d_residue (new unsigned char[itemsize]), d_residue_len (0) +{ +} + +// public constructor that returns a shared_ptr + +gr_file_descriptor_source_sptr +gr_make_file_descriptor_source (size_t itemsize, int fd, bool repeat) +{ + return gr_file_descriptor_source_sptr ( + new gr_file_descriptor_source (itemsize, fd, repeat)); +} + +gr_file_descriptor_source::~gr_file_descriptor_source () +{ + close (d_fd); + delete [] d_residue; +} + +int +gr_file_descriptor_source::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + assert (noutput_items > 0); + + char *o = (char *) output_items[0]; + int nread = 0; + + while (1){ + int r = read_items (o, noutput_items - nread); + if (r == -1){ + if (errno == EINTR) + continue; + else { + perror ("file_descriptor_source[read]"); + return -1; + } + } + else if (r == 0){ // end of file + if (!d_repeat) + break; + else { + flush_residue (); + if (lseek (d_fd, 0, SEEK_SET) == -1){ + perror ("file_descriptor_source[lseek]"); + return -1; + } + } + } + else { + o += r * d_itemsize; + nread += r; + break; + } + } + + if (nread == 0) // EOF + return -1; + + return nread; +} + +int +gr_file_descriptor_source::read_items (char *buf, int nitems) +{ + assert (nitems > 0); + assert (d_residue_len < d_itemsize); + + int nbytes_read = 0; + + if (d_residue_len > 0){ + memcpy (buf, d_residue, d_residue_len); + nbytes_read = d_residue_len; + d_residue_len = 0; + } + + int r = read (d_fd, buf + nbytes_read, nitems * d_itemsize - nbytes_read); + if (r <= 0){ + handle_residue (buf, nbytes_read); + return r; + } + + r = handle_residue (buf, r + nbytes_read); + + if (r == 0) // block until we get something + return read_items (buf, nitems); + + return r; +} + +int +gr_file_descriptor_source::handle_residue (char *buf, int nbytes_read) +{ + assert (nbytes_read >= 0); + int nitems_read = nbytes_read / d_itemsize; + d_residue_len = nbytes_read % d_itemsize; + if (d_residue_len > 0){ + // fprintf (stderr, "handle_residue: %d\n", d_residue_len); + memcpy (d_residue, buf + nbytes_read - d_residue_len, d_residue_len); + } + return nitems_read; +} diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_source.h b/gnuradio-core/src/lib/io/gr_file_descriptor_source.h new file mode 100644 index 000000000..9f678dcf5 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_source.h @@ -0,0 +1,67 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +#ifndef INCLUDED_GR_FILE_DESCRIPTOR_SOURCE_H +#define INCLUDED_GR_FILE_DESCRIPTOR_SOURCE_H + +#include + +class gr_file_descriptor_source; +typedef boost::shared_ptr gr_file_descriptor_source_sptr; + +gr_file_descriptor_source_sptr +gr_make_file_descriptor_source (size_t itemsize, int fd, bool repeat = false); + +/*! + * \brief Read stream from file descriptor. + * \ingroup source + */ + +class gr_file_descriptor_source : public gr_sync_block +{ + friend gr_file_descriptor_source_sptr + gr_make_file_descriptor_source (size_t itemsize, int fd, bool repeat); + private: + size_t d_itemsize; + int d_fd; + bool d_repeat; + + unsigned char *d_residue; + unsigned long d_residue_len; + + protected: + gr_file_descriptor_source (size_t itemsize, int fd, bool repeat); + + int read_items (char *buf, int nitems); + int handle_residue (char *buf, int nbytes_read); + void flush_residue () { d_residue_len = 0; } + + + public: + ~gr_file_descriptor_source (); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_GR_FILE_DESCRIPTOR_SOURCE_H */ diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_source.i b/gnuradio-core/src/lib/io/gr_file_descriptor_source.i new file mode 100644 index 000000000..ba9b3894f --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_source.i @@ -0,0 +1,35 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,file_descriptor_source) + +gr_file_descriptor_source_sptr +gr_make_file_descriptor_source (size_t itemsize, int fd, bool repeat=false); + +class gr_file_descriptor_source : public gr_sync_block +{ + protected: + gr_file_descriptor_source (size_t itemsize, int fd, bool repeat); + + public: + ~gr_file_descriptor_source (); +}; diff --git a/gnuradio-core/src/lib/io/gr_file_sink.cc b/gnuradio-core/src/lib/io/gr_file_sink.cc new file mode 100644 index 000000000..d22488bf6 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_sink.cc @@ -0,0 +1,144 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2006 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 + +// win32 (mingw/msvc) specific +#ifdef HAVE_IO_H +#include +#endif +#ifdef O_BINARY +#define OUR_O_BINARY O_BINARY +#else +#define OUR_O_BINARY 0 +#endif + +// should be handled via configure +#ifdef O_LARGEFILE +#define OUR_O_LARGEFILE O_LARGEFILE +#else +#define OUR_O_LARGEFILE 0 +#endif + +gr_file_sink::gr_file_sink(size_t itemsize, const char *filename) + : gr_sync_block ("file_sink", + gr_make_io_signature(1, 1, itemsize), + gr_make_io_signature(0, 0, 0)), + d_itemsize(itemsize), d_fp(0), d_new_fp(0), d_updated(false) +{ + if (!open(filename)) + throw std::runtime_error ("can't open file"); +} + +gr_file_sink_sptr +gr_make_file_sink (size_t itemsize, const char *filename) +{ + return gr_file_sink_sptr (new gr_file_sink (itemsize, filename)); +} + +gr_file_sink::~gr_file_sink () +{ + close(); + if (d_fp){ + fclose((FILE *) d_fp); + d_fp = 0; + } +} + +bool +gr_file_sink::open(const char *filename) +{ + omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + + // we use the open system call to get access to the O_LARGEFILE flag. + int fd; + if ((fd = ::open (filename, + O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY, 0664)) < 0){ + perror (filename); + return false; + } + + if (d_new_fp){ // if we've already got a new one open, close it + fclose((FILE *) d_new_fp); + d_new_fp = 0; + } + + if ((d_new_fp = fdopen (fd, "wb")) == NULL){ + perror (filename); + ::close(fd); // don't leak file descriptor if fdopen fails. + } + + d_updated = true; + return d_new_fp != 0; +} + +void +gr_file_sink::close() +{ + omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + + if (d_new_fp){ + fclose((FILE *) d_new_fp); + d_new_fp = 0; + } + d_updated = true; +} + +int +gr_file_sink::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + char *inbuf = (char *) input_items[0]; + int nwritten = 0; + + if (d_updated){ + omni_mutex_lock l(d_mutex); // hold mutex for duration of this block + if (d_fp) + fclose((FILE *)d_fp); + d_fp = d_new_fp; // install new file pointer + d_new_fp = 0; + d_updated = false; + } + + if (!d_fp) + return noutput_items; // drop output on the floor + + while (nwritten < noutput_items){ + int count = fwrite (inbuf, d_itemsize, noutput_items - nwritten, (FILE *) d_fp); + if (count == 0) // FIXME add error handling + break; + nwritten += count; + inbuf += count * d_itemsize; + } + return nwritten; +} diff --git a/gnuradio-core/src/lib/io/gr_file_sink.h b/gnuradio-core/src/lib/io/gr_file_sink.h new file mode 100644 index 000000000..9c11bf72b --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_sink.h @@ -0,0 +1,75 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +#ifndef INCLUDED_GR_FILE_SINK_H +#define INCLUDED_GR_FILE_SINK_H + +#include +#include + +class gr_file_sink; +typedef boost::shared_ptr gr_file_sink_sptr; + +gr_file_sink_sptr gr_make_file_sink(size_t itemsize, const char *filename); + +/*! + * \brief Write stream to file. + * \ingroup sink + */ + +class gr_file_sink : public gr_sync_block +{ + friend gr_file_sink_sptr gr_make_file_sink(size_t itemsize, const char *filename); + + private: + size_t d_itemsize; + void *d_fp; // current FILE pointer + void *d_new_fp; // new FILE pointer + bool d_updated; // is there a new FILE pointer? + omni_mutex d_mutex; + + protected: + gr_file_sink(size_t itemsize, const char *filename); + + public: + ~gr_file_sink(); + + /*! + * \brief Open filename and begin output to it. + */ + bool open(const char *filename); + + /*! + * \brief Close current output file. + * + * Closes current output file and ignores any output until + * open is called to connect to another file. + */ + void close(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + + +#endif /* INCLUDED_GR_FILE_SINK_H */ diff --git a/gnuradio-core/src/lib/io/gr_file_sink.i b/gnuradio-core/src/lib/io/gr_file_sink.i new file mode 100644 index 000000000..ffcf02aa6 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_sink.i @@ -0,0 +1,45 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,file_sink) + +gr_file_sink_sptr +gr_make_file_sink (size_t itemsize, const char *filename); + +class gr_file_sink : public gr_sync_block +{ + protected: + gr_file_sink (size_t itemsize, const char *filename); + + public: + ~gr_file_sink (); + + /*! + * \brief open filename and begin output to it. + */ + bool open(const char *filename); + + /*! + * \brief close current output file. + */ + void close(); +}; diff --git a/gnuradio-core/src/lib/io/gr_file_source.cc b/gnuradio-core/src/lib/io/gr_file_source.cc new file mode 100644 index 000000000..2573a37e0 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_source.cc @@ -0,0 +1,131 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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 + +// win32 (mingw/msvc) specific +#ifdef HAVE_IO_H +#include +#endif +#ifdef O_BINARY +#define OUR_O_BINARY O_BINARY +#else +#define OUR_O_BINARY 0 +#endif +// should be handled via configure +#ifdef O_LARGEFILE +#define OUR_O_LARGEFILE O_LARGEFILE +#else +#define OUR_O_LARGEFILE 0 +#endif + +gr_file_source::gr_file_source (size_t itemsize, const char *filename, bool repeat) + : gr_sync_block ("file_source", + gr_make_io_signature (0, 0, 0), + gr_make_io_signature (1, 1, itemsize)), + d_itemsize (itemsize), d_fp (0), d_repeat (repeat) +{ + // we use "open" to use to the O_LARGEFILE flag + + int fd; + if ((fd = open (filename, O_RDONLY | OUR_O_LARGEFILE | OUR_O_BINARY)) < 0){ + perror (filename); + throw std::runtime_error ("can't open file"); + } + + if ((d_fp = fdopen (fd, "rb")) == NULL){ + perror (filename); + throw std::runtime_error ("can't open file"); + } +} + +// public constructor that returns a shared_ptr + +gr_file_source_sptr +gr_make_file_source (size_t itemsize, const char *filename, bool repeat) +{ + return gr_file_source_sptr (new gr_file_source (itemsize, filename, repeat)); +} + +gr_file_source::~gr_file_source () +{ + fclose ((FILE *) d_fp); +} + +int +gr_file_source::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + char *o = (char *) output_items[0]; + int i; + int size = noutput_items; + + while (size) { + i = fread(o, d_itemsize, size, (FILE *) d_fp); + + size -= i; + o += i * d_itemsize; + + if (size == 0) // done + break; + + if (i > 0) // short read, try again + continue; + + // We got a zero from fread. This is either EOF or error. In + // any event, if we're in repeat mode, seek back to the beginning + // of the file and try again, else break + + if (!d_repeat) + break; + + if (fseek ((FILE *) d_fp, 0, SEEK_SET) == -1) { + fprintf(stderr, "[%s] fseek failed\n", __FILE__); + exit(-1); + } + } + + if (size > 0){ // EOF or error + if (size == noutput_items) // we didn't read anything; say we're done + return -1; + return noutput_items - size; // else return partial result + } + + return noutput_items; +} + +bool +gr_file_source::seek (long seek_point, int whence) +{ + return fseek ((FILE *) d_fp, seek_point * d_itemsize, whence) == 0; +} diff --git a/gnuradio-core/src/lib/io/gr_file_source.h b/gnuradio-core/src/lib/io/gr_file_source.h new file mode 100644 index 000000000..6b635c53b --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_source.h @@ -0,0 +1,68 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +#ifndef INCLUDED_GR_FILE_SOURCE_H +#define INCLUDED_GR_FILE_SOURCE_H + +#include + +class gr_file_source; +typedef boost::shared_ptr gr_file_source_sptr; + +gr_file_source_sptr +gr_make_file_source (size_t itemsize, const char *filename, bool repeat = false); + +/*! + * \brief Read stream from file + * \ingroup source + */ + +class gr_file_source : public gr_sync_block +{ + friend gr_file_source_sptr gr_make_file_source (size_t itemsize, + const char *filename, + bool repeat); + private: + size_t d_itemsize; + void *d_fp; + bool d_repeat; + + protected: + gr_file_source (size_t itemsize, const char *filename, bool repeat); + + public: + ~gr_file_source (); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + /*! + * \brief seek file to \p seek_point relative to \p whence + * + * \param seek_point sample offset in file + * \param whence one of SEEK_SET, SEEK_CUR, SEEK_END (man fseek) + */ + bool seek (long seek_point, int whence); +}; + +#endif /* INCLUDED_GR_FILE_SOURCE_H */ diff --git a/gnuradio-core/src/lib/io/gr_file_source.i b/gnuradio-core/src/lib/io/gr_file_source.i new file mode 100644 index 000000000..08fdfaf93 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_source.i @@ -0,0 +1,43 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + + +%constant int SEEK_SET = 0; /* Seek from beginning of file. */ +%constant int SEEK_CUR = 1; /* Seek from current position. */ +%constant int SEEK_END = 2; /* Seek from end of file. */ + + +GR_SWIG_BLOCK_MAGIC(gr,file_source) + +gr_file_source_sptr +gr_make_file_source (size_t itemsize, const char *filename, bool repeat=false); + +class gr_file_source : public gr_sync_block +{ + protected: + gr_file_source (size_t itemsize, const char *filename, bool repeat); + + public: + ~gr_file_source (); + + bool seek (long seek_point, int whence); +}; diff --git a/gnuradio-core/src/lib/io/gr_message_sink.cc b/gnuradio-core/src/lib/io/gr_message_sink.cc new file mode 100644 index 000000000..8a0784ec4 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_sink.cc @@ -0,0 +1,78 @@ +/* -*- 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 + + +// public constructor that returns a shared_ptr + +gr_message_sink_sptr +gr_make_message_sink (size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block) +{ + return gr_message_sink_sptr(new gr_message_sink(itemsize, msgq, dont_block)); +} + +gr_message_sink::gr_message_sink (size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block) + : gr_sync_block("message_sink", + gr_make_io_signature(1, 1, itemsize), + gr_make_io_signature(0, 0, 0)), + d_itemsize(itemsize), d_msgq(msgq), d_dont_block(dont_block) +{ +} + +gr_message_sink::~gr_message_sink() +{ +} + +int +gr_message_sink::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const char *in = (const char *) input_items[0]; + + // if we'd block, drop the data on the floor and say everything is OK + if (d_dont_block && d_msgq->full_p()) + return noutput_items; + + // build a message to hold whatever we've got + gr_message_sptr msg = gr_make_message(0, // msg type + d_itemsize, // arg1 for other end + noutput_items, // arg2 for other end (redundant) + noutput_items * d_itemsize); // len of msg + memcpy(msg->msg(), in, noutput_items * d_itemsize); + + d_msgq->handle(msg); // send it + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/io/gr_message_sink.h b/gnuradio-core/src/lib/io/gr_message_sink.h new file mode 100644 index 000000000..8011ab290 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_sink.h @@ -0,0 +1,62 @@ +/* -*- 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. + */ + +#ifndef INCLUDED_GR_MESSAGE_SINK_H +#define INCLUDED_GR_MESSAGE_SINK_H + +#include +#include +#include + +class gr_message_sink; +typedef boost::shared_ptr gr_message_sink_sptr; + +gr_message_sink_sptr gr_make_message_sink (size_t itemsize, + gr_msg_queue_sptr msgq, + bool dont_block); + +/*! + * \brief Gather received items into messages and insert into msgq + * \ingroup sink + */ +class gr_message_sink : public gr_sync_block +{ + private: + size_t d_itemsize; + gr_msg_queue_sptr d_msgq; + bool d_dont_block; + + friend gr_message_sink_sptr + gr_make_message_sink(size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block); + + protected: + gr_message_sink (size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block); + + public: + ~gr_message_sink (); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_GR_MESSAGE_SINK_H */ diff --git a/gnuradio-core/src/lib/io/gr_message_sink.i b/gnuradio-core/src/lib/io/gr_message_sink.i new file mode 100644 index 000000000..ca73479c5 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_sink.i @@ -0,0 +1,36 @@ +/* -*- 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,message_sink); + +gr_message_sink_sptr gr_make_message_sink (size_t itemsize, + gr_msg_queue_sptr msgq, + bool dont_block); + +class gr_message_sink : public gr_sync_block +{ + protected: + gr_message_sink (size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block); + + public: + ~gr_message_sink (); +}; diff --git a/gnuradio-core/src/lib/io/gr_message_source.cc b/gnuradio-core/src/lib/io/gr_message_source.cc new file mode 100644 index 000000000..797433be5 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_source.cc @@ -0,0 +1,104 @@ +/* -*- 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 + + +// public constructor that returns a shared_ptr + +gr_message_source_sptr +gr_make_message_source(size_t itemsize, int msgq_limit) +{ + return gr_message_source_sptr(new gr_message_source(itemsize, msgq_limit)); +} + +gr_message_source::gr_message_source (size_t itemsize, int msgq_limit) + : gr_sync_block("message_source", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(1, 1, itemsize)), + d_itemsize(itemsize), d_msgq(gr_make_msg_queue(msgq_limit)), d_msg_offset(0), d_eof(false) +{ +} + +gr_message_source::~gr_message_source() +{ +} + +int +gr_message_source::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + char *out = (char *) output_items[0]; + int nn = 0; + + while (nn < noutput_items){ + if (d_msg){ + // + // Consume whatever we can from the current message + // + int mm = std::min(noutput_items - nn, (int)((d_msg->length() - d_msg_offset) / d_itemsize)); + memcpy (out, &(d_msg->msg()[d_msg_offset]), mm * d_itemsize); + + nn += mm; + out += mm * d_itemsize; + d_msg_offset += mm * d_itemsize; + assert(d_msg_offset <= d_msg->length()); + + if (d_msg_offset == d_msg->length()){ + if (d_msg->type() == 1) // type == 1 sets EOF + d_eof = true; + d_msg.reset(); + } + } + else { + // + // No current message + // + if (d_msgq->empty_p() && nn > 0){ // no more messages in the queue, return what we've got + break; + } + + if (d_eof) + return -1; + + d_msg = d_msgq->delete_head(); // block, waiting for a message + d_msg_offset = 0; + + if ((d_msg->length() % d_itemsize) != 0) + throw std::runtime_error("msg length is not a multiple of d_itemsize"); + } + } + + return nn; +} diff --git a/gnuradio-core/src/lib/io/gr_message_source.h b/gnuradio-core/src/lib/io/gr_message_source.h new file mode 100644 index 000000000..020601240 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_source.h @@ -0,0 +1,64 @@ +/* -*- 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. + */ + +#ifndef INCLUDED_GR_MESSAGE_SOURCE_H +#define INCLUDED_GR_MESSAGE_SOURCE_H + +#include +#include +#include + +class gr_message_source; +typedef boost::shared_ptr gr_message_source_sptr; + +gr_message_source_sptr gr_make_message_source (size_t itemsize, int msgq_limit=0); + +/*! + * \brief Turn received messages into a stream + * \ingroup source + */ +class gr_message_source : public gr_sync_block +{ + private: + size_t d_itemsize; + gr_msg_queue_sptr d_msgq; + gr_message_sptr d_msg; + unsigned d_msg_offset; + bool d_eof; + + friend gr_message_source_sptr + gr_make_message_source(size_t itemsize, int msgq_limit); + + protected: + gr_message_source (size_t itemsize, int msgq_limit); + + public: + ~gr_message_source (); + + gr_msg_queue_sptr msgq() const { return d_msgq; } + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_GR_MESSAGE_SOURCE_H */ diff --git a/gnuradio-core/src/lib/io/gr_message_source.i b/gnuradio-core/src/lib/io/gr_message_source.i new file mode 100644 index 000000000..369112eff --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_source.i @@ -0,0 +1,36 @@ +/* -*- 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,message_source); + +gr_message_source_sptr gr_make_message_source (size_t itemsize, int msgq_limit=0); + +class gr_message_source : public gr_sync_block +{ + protected: + gr_message_source (size_t itemsize, int msgq_limit); + + public: + ~gr_message_source (); + + gr_msg_queue_sptr msgq() const; +}; diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.cc b/gnuradio-core/src/lib/io/gr_oscope_guts.cc new file mode 100644 index 000000000..6636fff1c --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.cc @@ -0,0 +1,382 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003,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 +#endif +#include +#include +#include +#include +#include +#include +#include + +static const int OUTPUT_RECORD_SIZE = 2048; // must be power of 2 + +static inline int +wrap_bi (int buffer_index) // wrap buffer index +{ + return buffer_index & (OUTPUT_RECORD_SIZE - 1); +} + +static inline int +incr_bi (int buffer_index) // increment buffer index +{ + return wrap_bi (buffer_index + 1); +} + +static inline int +decr_bi (int buffer_index) // decrement buffer index +{ + return wrap_bi (buffer_index - 1); +} + +gr_oscope_guts::gr_oscope_guts (int nchannels, double sample_rate, gr_msg_queue_sptr msgq) + : d_nchannels (nchannels), + d_msgq (msgq), + d_trigger_mode (gr_TRIG_POS_SLOPE), + d_trigger_channel (0), + d_sample_rate (sample_rate), + d_update_rate (20), + d_trigger_level (0), + d_obi (0), + d_state (LOOK_FOR_TRIGGER), + d_decimator_count (0), + d_decimator_count_init (1), + d_hold_off_count (0), + d_hold_off_count_init (0), + d_post_trigger_count (0), + d_post_trigger_count_init (OUTPUT_RECORD_SIZE/2), + d_prev_sample (0) +{ + if (d_nchannels > MAX_CHANNELS){ + fprintf (stderr, "gr_oscope_guts: too many channels. MAX_CHANNELS = %d\n", MAX_CHANNELS); + throw std::runtime_error ("too many channels"); + } + + for (int i = 0; i < MAX_CHANNELS; i++) + d_buffer[i] = 0; + + for (int i = 0; i < d_nchannels; i++) + d_buffer[i] = new float [OUTPUT_RECORD_SIZE]; + + update_rate_or_decimation_changed (); + enter_look_for_trigger (); +} + +gr_oscope_guts::~gr_oscope_guts () +{ + for (int i = 0; i < MAX_CHANNELS; i++) + delete [] d_buffer[i]; +} + +// MANIPULATORS + +// \p channel_data points to nchannels float values. These are the values +// for each channel at this sample time. + +void +gr_oscope_guts::process_sample (const float *channel_data) +{ + d_decimator_count--; + if (d_decimator_count > 0) + return; + + d_decimator_count = d_decimator_count_init; + + for (int i = 0; i < d_nchannels; i++) + d_buffer[i][d_obi] = channel_data[i]; // copy data into buffer + + int trigger = 0; + + switch (d_state){ + case HOLD_OFF: + d_hold_off_count--; + if (d_hold_off_count <= 0) + enter_look_for_trigger (); + break; + + case LOOK_FOR_TRIGGER: + trigger = found_trigger (d_buffer[d_trigger_channel][d_obi]); + if (trigger != 0){ + enter_post_trigger (); + if (trigger < 0) // previous sample was closer + d_post_trigger_count--; + } + break; + + case POST_TRIGGER: + d_post_trigger_count--; + if (d_post_trigger_count <= 0){ + write_output_records (); + enter_hold_off (); + } + break; + + default: + assert (0); + } + + d_obi = incr_bi (d_obi); +} + +/* + * Functions called on state entry + */ + +void +gr_oscope_guts::enter_hold_off () +{ + d_state = HOLD_OFF; + d_hold_off_count = d_hold_off_count_init; +} + +void +gr_oscope_guts::enter_look_for_trigger () +{ + d_state = LOOK_FOR_TRIGGER; + d_prev_sample = d_buffer[d_trigger_channel][d_obi]; +} + +void +gr_oscope_guts::enter_post_trigger () +{ + d_state = POST_TRIGGER; + d_post_trigger_count = d_post_trigger_count_init; +} + +// ---------------------------------------------------------------- +// returns 0 if no trigger found. +// returns +1 if this sample is the trigger point +// returns -1 if the previous sample is the trigger point + +int +gr_oscope_guts::found_trigger (float new_sample) +{ + float prev_sample = d_prev_sample; + d_prev_sample = new_sample; + bool trig; + + switch (d_trigger_mode){ + + case gr_TRIG_AUTO: // always trigger + return +1; + + case gr_TRIG_POS_SLOPE: + trig = prev_sample < d_trigger_level && new_sample >= d_trigger_level; + if (trig){ + if (fabs (prev_sample - d_trigger_level) < fabs (new_sample - d_trigger_level)) + return -1; + else + return +1; + } + return 0; + + case gr_TRIG_NEG_SLOPE: + trig = prev_sample > d_trigger_level && new_sample <= d_trigger_level; + if (trig){ + if (fabs (prev_sample - d_trigger_level) < fabs (new_sample - d_trigger_level)) + return -1; + else + return +1; + } + return 0; + + default: + assert (0); + return 0; + } +} + +// ---------------------------------------------------------------- +// write output records (duh!) + +void +gr_oscope_guts::write_output_records () +{ + // if the output queue if full, drop the data on the ground. + if (d_msgq->full_p()) + return; + + // Build a message to hold the output records + gr_message_sptr msg = + gr_make_message(0, // msg type + d_nchannels, // arg1 for other side + OUTPUT_RECORD_SIZE, // arg2 for other side + d_nchannels * OUTPUT_RECORD_SIZE * sizeof(float)); // sizeof payload + + float *out = (float *)msg->msg(); // get pointer to raw message buffer + + for (int ch = 0; ch < d_nchannels; ch++){ + // note that d_obi points at the oldest sample in the buffer + for (int i = 0; i < OUTPUT_RECORD_SIZE; i++) + out[i] = d_buffer[ch][wrap_bi(d_obi + i)]; + + out += OUTPUT_RECORD_SIZE; + } + + d_msgq->handle(msg); // send the msg +} + +// ---------------------------------------------------------------- + +bool +gr_oscope_guts::set_update_rate (double update_rate) +{ + d_update_rate = std::min (std::max (1./10., update_rate), d_sample_rate); + update_rate_or_decimation_changed (); + return true; +} + +bool +gr_oscope_guts::set_decimation_count (int decimator_count) +{ + decimator_count = std::max (1, decimator_count); + d_decimator_count_init = decimator_count; + update_rate_or_decimation_changed (); + return true; +} + +bool +gr_oscope_guts::set_sample_rate(double sample_rate) +{ + d_sample_rate = sample_rate; + return set_update_rate(update_rate()); +} + + +void +gr_oscope_guts::update_rate_or_decimation_changed () +{ + d_hold_off_count_init = + (int) rint (d_sample_rate / d_update_rate / d_decimator_count_init); +} + +bool +gr_oscope_guts::set_trigger_channel (int channel) +{ + if (channel >= 0 && channel < d_nchannels){ + d_trigger_channel = channel; + trigger_changed (); + return true; + } + + return false; +} + +bool +gr_oscope_guts::set_trigger_mode (gr_trigger_mode mode) +{ + switch (mode){ + case gr_TRIG_POS_SLOPE: + case gr_TRIG_NEG_SLOPE: + case gr_TRIG_AUTO: + d_trigger_mode = mode; + trigger_changed (); + return true; + } + return false; +} + +bool +gr_oscope_guts::set_trigger_level (double trigger_level) +{ + d_trigger_level = trigger_level; + trigger_changed (); + return true; +} + +bool +gr_oscope_guts::set_trigger_level_auto () +{ + // find the level 1/2 way between the min and the max + + float min_v = d_buffer[d_trigger_channel][0]; + float max_v = d_buffer[d_trigger_channel][0]; + + for (int i = 1; i < OUTPUT_RECORD_SIZE; i++){ + min_v = std::min (min_v, d_buffer[d_trigger_channel][i]); + max_v = std::max (max_v, d_buffer[d_trigger_channel][i]); + } + + d_trigger_level = (min_v + max_v) * 0.5; + trigger_changed (); + return true; +} + +void +gr_oscope_guts::trigger_changed () +{ + // d_prev_sample = d_buffer[d_trigger_channel][decr_bi(d_obi)]; + enter_look_for_trigger (); +} + +// ACCESSORS + +int +gr_oscope_guts::num_channels () const +{ + return d_nchannels; +} + +double +gr_oscope_guts::sample_rate () const +{ + return d_sample_rate; +} + +double +gr_oscope_guts::update_rate () const +{ + return d_update_rate; +} + +int +gr_oscope_guts::get_decimation_count () const +{ + return d_decimator_count_init; +} + +int +gr_oscope_guts::get_trigger_channel () const +{ + return d_trigger_channel; +} + +gr_trigger_mode +gr_oscope_guts::get_trigger_mode () const +{ + return d_trigger_mode; +} + +double +gr_oscope_guts::get_trigger_level () const +{ + return d_trigger_level; +} + +int +gr_oscope_guts::get_samples_per_output_record () const +{ + return OUTPUT_RECORD_SIZE; +} diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.h b/gnuradio-core/src/lib/io/gr_oscope_guts.h new file mode 100644 index 000000000..4094a6530 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.h @@ -0,0 +1,116 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003,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. + */ + + +#ifndef INCLUDED_GR_OSCOPE_GUTS_H +#define INCLUDED_GR_OSCOPE_GUTS_H + +#include +#include + +/*! + * \brief guts of oscilloscope trigger and buffer module + * + * This module processes sets of samples provided the \p process_sample + * method. When appropriate given the updateRate, sampleRate and + * trigger conditions, process_sample will periodically write output + * records of captured data to output_fd. For each trigger event, + * nchannels records will be written. Each record consists of + * get_samples_per_output_record binary floats. The trigger instant + * occurs at the 1/2 way point in the buffer. Thus, output records + * consist of 50% pre-trigger data and 50% post-trigger data. + */ + +class gr_oscope_guts { +private: + static const int MAX_CHANNELS = 16; + enum scope_state { HOLD_OFF, LOOK_FOR_TRIGGER, POST_TRIGGER }; + + int d_nchannels; // how many channels + gr_msg_queue_sptr d_msgq; // message queue we stuff output records into + gr_trigger_mode d_trigger_mode; + int d_trigger_channel; // which channel to watch for trigger condition + double d_sample_rate; // input sample rate in Hz + double d_update_rate; // approx freq to produce an output record (Hz) + double d_trigger_level; + + int d_obi; // output buffer index + float *d_buffer[MAX_CHANNELS]; + + scope_state d_state; + int d_decimator_count; + int d_decimator_count_init; + int d_hold_off_count; + int d_hold_off_count_init; + int d_post_trigger_count; + int d_post_trigger_count_init; + float d_prev_sample; // used for trigger checking + + // NOT IMPLEMENTED + gr_oscope_guts (const gr_oscope_guts &rhs); // no copy constructor + gr_oscope_guts &operator= (const gr_oscope_guts &rhs); // no assignment operator + + void trigger_changed (); + void update_rate_or_decimation_changed (); + int found_trigger (float sample); // returns -1, 0, +1 + void write_output_records (); + + void enter_hold_off (); // called on state entry + void enter_look_for_trigger (); + void enter_post_trigger (); + +public: + // CREATORS + gr_oscope_guts (int nchannels, double sample_rate, gr_msg_queue_sptr msgq); + ~gr_oscope_guts (); + + // MANIPULATORS + + /*! + * \p channel_data points to nchannels float values. These are the values + * for each channel at this sample time. + */ + void process_sample (const float *channel_data); + + bool set_update_rate (double update_rate); + bool set_decimation_count (int decimation_count); + bool set_trigger_channel (int channel); + bool set_trigger_mode (gr_trigger_mode mode); + bool set_trigger_level (double trigger_level); + bool set_trigger_level_auto (); // set to 50% level + bool set_sample_rate(double sample_rate); + + + // ACCESSORS + int num_channels () const; + double sample_rate () const; + double update_rate () const; + int get_decimation_count () const; + int get_trigger_channel () const; + gr_trigger_mode get_trigger_mode () const; + double get_trigger_level () const; + + // # of samples written to each output record. + int get_samples_per_output_record () const; +}; + +#endif /* INCLUDED_GR_OSCOPE_GUTS_H */ diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink.i b/gnuradio-core/src/lib/io/gr_oscope_sink.i new file mode 100644 index 000000000..ea8419909 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_oscope_sink.i @@ -0,0 +1,79 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +enum gr_trigger_mode { + gr_TRIG_AUTO, // auto trigger (on anything) + gr_TRIG_POS_SLOPE, // trigger on positive slope across trigger level + gr_TRIG_NEG_SLOPE // trigger on negative slope across trigger level +}; + +// GR_SWIG_BLOCK_MAGIC(gr,oscope_sink_x) + +%ignore gr_oscope_sink_x; +class gr_oscope_sink_x : public gr_sync_block +{ + protected: + gr_oscope_sink_x (const std::string name, + gr_io_signature_sptr input_sig, + double sample_rate); + + public: + ~gr_oscope_sink_x (); + + bool set_update_rate (double update_rate); + bool set_decimation_count (int decimation_count); + bool set_trigger_channel (int channel); + bool set_trigger_mode (gr_trigger_mode mode); + bool set_trigger_level (double trigger_level); + bool set_trigger_level_auto (); // set to 50% level + bool set_sample_rate(double sample_rate); + + // ACCESSORS + int num_channels () const; + double sample_rate () const; + double update_rate () const; + int get_decimation_count () const; + int get_trigger_channel () const; + gr_trigger_mode get_trigger_mode () const; + double get_trigger_level () const; + + // # of samples written to each output record. + int get_samples_per_output_record () const; +}; + +// ---------------------------------------------------------------- + +GR_SWIG_BLOCK_MAGIC(gr,oscope_sink_f) + +gr_oscope_sink_f_sptr +gr_make_oscope_sink_f (double sample_rate, gr_msg_queue_sptr msgq); + +class gr_oscope_sink_f : public gr_oscope_sink_x +{ +private: + gr_oscope_sink_f (double sample_rate, gr_msg_queue_sptr msgq); + +public: + ~gr_oscope_sink_f (); +}; + +// ---------------------------------------------------------------- diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc b/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc new file mode 100644 index 000000000..b505381da --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc @@ -0,0 +1,80 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003,2004,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 + + +gr_oscope_sink_f_sptr +gr_make_oscope_sink_f (double sampling_rate, gr_msg_queue_sptr msgq) +{ + return gr_oscope_sink_f_sptr (new gr_oscope_sink_f (sampling_rate, msgq)); +} + + +gr_oscope_sink_f::gr_oscope_sink_f (double sampling_rate, gr_msg_queue_sptr msgq) + : gr_oscope_sink_x ("oscope_sink_f", + gr_make_io_signature (1, MAX_CHANNELS, sizeof (float)), + sampling_rate), + d_msgq(msgq) +{ +} + + +bool +gr_oscope_sink_f::check_topology (int ninputs, int noutputs) +{ + delete d_guts; + d_guts = 0; + d_guts = new gr_oscope_guts (ninputs, d_sampling_rate, d_msgq); + return true; +} + + +gr_oscope_sink_f::~gr_oscope_sink_f () +{ +} + +int +gr_oscope_sink_f::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + int ni = input_items.size (); + float tmp[MAX_CHANNELS]; + + for (int i = 0; i < noutput_items; i++){ + + // FIXME for now, copy the data. Fix later if reqd + for (int ch = 0; ch < ni; ch++) + tmp[ch] = ((const float *) input_items[ch])[i]; + + d_guts->process_sample (tmp); + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_f.h b/gnuradio-core/src/lib/io/gr_oscope_sink_f.h new file mode 100644 index 000000000..7b92a7850 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_f.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003,2004,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. + */ + +#ifndef INCLUDED_GR_OSCOPE_SINK_F_H +#define INCLUDED_GR_OSCOPE_SINK_F_H + +#include +#include + +class gr_oscope_sink_f; +typedef boost::shared_ptr gr_oscope_sink_f_sptr; + +gr_oscope_sink_f_sptr gr_make_oscope_sink_f (double sampling_rate, gr_msg_queue_sptr msgq); + + +/*! + * \brief Building block for python oscilloscope module. + * \ingroup sink + * + * Accepts 1 to 16 float streams. + */ +class gr_oscope_sink_f : public gr_oscope_sink_x +{ +public: + static const int MAX_CHANNELS = 16; + +private: + friend gr_oscope_sink_f_sptr + gr_make_oscope_sink_f (double sampling_rate, gr_msg_queue_sptr msgq); + + gr_oscope_sink_f (double sampling_rate, gr_msg_queue_sptr msgq); + + gr_msg_queue_sptr d_msgq; + + public: + ~gr_oscope_sink_f (); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + bool check_topology (int ninputs, int noutputs); +}; + +#endif /* INCLUDED_GR_OSCOPE_SINK_F_H */ + diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_x.cc b/gnuradio-core/src/lib/io/gr_oscope_sink_x.cc new file mode 100644 index 000000000..51c28678e --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_x.cc @@ -0,0 +1,138 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003,2004 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 + + +gr_oscope_sink_x::gr_oscope_sink_x (const std::string name, + gr_io_signature_sptr input_sig, + double sampling_rate) + : gr_sync_block (name, input_sig, gr_make_io_signature (0, 0, 0)), + d_sampling_rate (sampling_rate), d_guts (0) +{ +} + +gr_oscope_sink_x::~gr_oscope_sink_x () +{ + delete d_guts; +} + +// ---------------------------------------------------------------- + +bool +gr_oscope_sink_x::set_update_rate (double update_rate) +{ + return d_guts->set_update_rate (update_rate); +} + +bool +gr_oscope_sink_x::set_decimation_count (int decimation_count) +{ + return d_guts->set_decimation_count (decimation_count); +} + +bool +gr_oscope_sink_x::set_trigger_channel (int channel) +{ + return d_guts->set_trigger_channel (channel); +} + +bool +gr_oscope_sink_x::set_trigger_mode (gr_trigger_mode mode) +{ + return d_guts->set_trigger_mode (mode); +} + +bool +gr_oscope_sink_x::set_trigger_level (double trigger_level) +{ + return d_guts->set_trigger_level (trigger_level); +} + + +bool +gr_oscope_sink_x::set_trigger_level_auto () +{ + return d_guts->set_trigger_level_auto (); +} + +bool +gr_oscope_sink_x::set_sample_rate (double sample_rate) +{ + return d_guts->set_sample_rate (sample_rate); +} + +// ACCESSORS + +int +gr_oscope_sink_x::num_channels () const +{ + return d_guts->num_channels (); +} + +double +gr_oscope_sink_x::sample_rate () const +{ + return d_guts->sample_rate (); +} + +double +gr_oscope_sink_x::update_rate () const +{ + return d_guts->update_rate (); +} + +int +gr_oscope_sink_x::get_decimation_count () const +{ + return d_guts->get_decimation_count (); +} + +int +gr_oscope_sink_x::get_trigger_channel () const +{ + return d_guts->get_trigger_channel (); +} + +gr_trigger_mode +gr_oscope_sink_x::get_trigger_mode () const +{ + return d_guts->get_trigger_mode (); +} + +double +gr_oscope_sink_x::get_trigger_level () const +{ + return d_guts->get_trigger_level (); +} + +int +gr_oscope_sink_x::get_samples_per_output_record () const +{ + return d_guts->get_samples_per_output_record (); +} diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_x.h b/gnuradio-core/src/lib/io/gr_oscope_sink_x.h new file mode 100644 index 000000000..45cccc0d4 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_x.h @@ -0,0 +1,73 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003,2004 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. + */ + +#ifndef INCLUDED_GR_OSCOPE_SINK_X_H +#define INCLUDED_GR_OSCOPE_SINK_X_H + +#include +#include + +class gr_oscope_guts; + +/*! + * \brief Abstract class for python oscilloscope module. + * \ingroup sink + * + * Don't instantiate this. Use gr_oscope_sink_f or gr_oscope_sink_c instead. + */ +class gr_oscope_sink_x : public gr_sync_block +{ +protected: + double d_sampling_rate; + gr_oscope_guts *d_guts; + + gr_oscope_sink_x (const std::string name, + gr_io_signature_sptr input_sig, + double sampling_rate); + +public: + ~gr_oscope_sink_x (); + + bool set_update_rate (double update_rate); + bool set_decimation_count (int decimation_count); + bool set_trigger_channel (int channel); + bool set_trigger_mode (gr_trigger_mode mode); + bool set_trigger_level (double trigger_level); + bool set_trigger_level_auto (); // set to 50% level + bool set_sample_rate(double sample_rate); + + + // ACCESSORS + int num_channels () const; + double sample_rate () const; + double update_rate () const; + int get_decimation_count () const; + int get_trigger_channel () const; + gr_trigger_mode get_trigger_mode () const; + double get_trigger_level () const; + + // # of samples written to each output record. + int get_samples_per_output_record () const; + +}; + +#endif /* INCLUDED_GR_OSCOPE_SINK_X_H */ diff --git a/gnuradio-core/src/lib/io/gr_trigger_mode.h b/gnuradio-core/src/lib/io/gr_trigger_mode.h new file mode 100644 index 000000000..0928c6a34 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_trigger_mode.h @@ -0,0 +1,32 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003,2004 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. + */ + +#ifndef INCLUDED_GR_TRIGGER_MODE_H +#define INCLUDED_GR_TRIGGER_MODE_H + +enum gr_trigger_mode { + gr_TRIG_AUTO, // auto trigger (on anything) + gr_TRIG_POS_SLOPE, // trigger on positive slope across trigger level + gr_TRIG_NEG_SLOPE // trigger on negative slope across trigger level +}; + +#endif /* INCLUDED_GR_TRIGGER_MODE_H */ diff --git a/gnuradio-core/src/lib/io/gri_logger.cc b/gnuradio-core/src/lib/io/gri_logger.cc new file mode 100644 index 000000000..a1bdfb0e2 --- /dev/null +++ b/gnuradio-core/src/lib/io/gri_logger.cc @@ -0,0 +1,173 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 +#endif + +#include +#include +#include +#include +#include + + +/* + * This class creates the thread that reads from the ringbuffer and + * and writes to the file. This is opaque to the user. + */ +class gri_log_poster : public omni_thread +{ + FILE *d_fp; + gr_buffer_sptr d_writer; + gr_buffer_reader_sptr d_reader; + omni_semaphore d_ringbuffer_ready; + volatile bool d_time_to_die; + volatile bool d_writer_overrun; + + virtual void* run_undetached(void * arg); + +public: + gri_log_poster(const char *filename); + ~gri_log_poster(); + + void kill() { d_time_to_die = true; post(); } + gr_buffer_sptr writer() const { return d_writer; } + void post() { d_ringbuffer_ready.post(); } + void note_writer_overrun() { d_writer_overrun = true; } +}; + +gri_log_poster::gri_log_poster(const char *filename) + : omni_thread(), + d_ringbuffer_ready(1, 1), // binary semaphore + d_time_to_die(false), + d_writer_overrun(false) +{ + if ((d_fp = fopen(filename, "w")) == 0){ + perror (filename); + throw std::runtime_error("can't open file"); + } + + // Create a 1MB buffer. + d_writer = gr_make_buffer(1 * 1024 * 1024, sizeof(unsigned char)); + d_reader = gr_buffer_add_reader(d_writer, 0); + + start_undetached(); // start the thread +} + +gri_log_poster::~gri_log_poster() +{ + if (d_fp != 0){ + fclose(d_fp); + d_fp = 0; + } +} + +/* + * This is the body of the logging thread. + */ +void * +gri_log_poster::run_undetached(void *arg) +{ + int nbytes; + + //fprintf(stderr, "Enter: run_undetached!\n"); + + while (!d_time_to_die){ + while ((nbytes = d_reader->items_available()) > 0){ + fwrite(d_reader->read_pointer(), 1, nbytes, d_fp); + d_reader->update_read_pointer(nbytes); + } + fflush(d_fp); + d_ringbuffer_ready.wait(); + + if (d_writer_overrun){ + fputs(">>>>> gri_logger: writer overrun. Info lost <<<<<\n", d_fp); + d_writer_overrun = false; + } + } + + // fprintf(stderr, "Exit: run_undetached!\n"); + return 0; +} + +// ------------------------------------------------------------------------ + +static boost::weak_ptr s_singleton; // weak pointer IQ test ;-) +static omni_mutex s_singleton_mutex; + +gri_logger_sptr +gri_logger::singleton() +{ + omni_mutex_lock l(s_singleton_mutex); + gri_logger_sptr r; + + if (r = s_singleton.lock()) + return r; + + r = gri_logger_sptr(new gri_logger("gri_logger.log")); + s_singleton = r; + return r; +} + + +gri_logger::gri_logger(const char *filename) +{ + d_poster = new gri_log_poster(filename); +} + +gri_logger::~gri_logger() +{ + d_poster->kill(); + d_poster->join(NULL); +} + +void +gri_logger::write(const void *buf, size_t count) +{ + omni_mutex_lock l(d_write_mutex); + gr_buffer_sptr writer = d_poster->writer(); + + // either write it all, or drop it on the ground + if (count <= (size_t) writer->space_available()){ + memcpy(writer->write_pointer(), buf, count); + writer->update_write_pointer(count); + d_poster->post(); + } + else { + d_poster->note_writer_overrun(); + } +} + +void +gri_logger::printf(const char *format, ...) +{ + va_list ap; + char buf[4096]; + int n; + + va_start(ap, format); + n = vsnprintf(buf, sizeof(buf), format, ap); + va_end(ap); + if (n > -1 && n < (ssize_t) sizeof(buf)) + write(buf, n); +} diff --git a/gnuradio-core/src/lib/io/gri_logger.h b/gnuradio-core/src/lib/io/gri_logger.h new file mode 100644 index 000000000..ecbd3141e --- /dev/null +++ b/gnuradio-core/src/lib/io/gri_logger.h @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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. + */ +#ifndef INCLUDED_GRI_LOGGER_H +#define INCLUDED_GRI_LOGGER_H + +#include +#include +#include + +class gri_log_poster; +class gri_logger; +typedef boost::shared_ptr gri_logger_sptr; + + +/*! + * \brief non-blocking logging to a file. + * + * In reality, this may block, but only for a bounded time. + * Trust me, it's safe to use from portaudio and JACK callbacks. + */ +class gri_logger +{ + gri_log_poster *d_poster; + omni_mutex d_write_mutex; + +public: + static gri_logger_sptr singleton(); + + gri_logger(const char *filename); + ~gri_logger(); + + void write(const void *buf, size_t count); + void printf(const char *format, ...); +}; + +#endif /* INCLUDED_GRI_LOGGER_H */ diff --git a/gnuradio-core/src/lib/io/i2c.cc b/gnuradio-core/src/lib/io/i2c.cc new file mode 100644 index 000000000..9b9fbcd15 --- /dev/null +++ b/gnuradio-core/src/lib/io/i2c.cc @@ -0,0 +1,28 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2004 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. + */ + +#include "i2c.h" + +i2c::~i2c () +{ + // NOP +} diff --git a/gnuradio-core/src/lib/io/i2c.h b/gnuradio-core/src/lib/io/i2c.h new file mode 100644 index 000000000..88b3c9135 --- /dev/null +++ b/gnuradio-core/src/lib/io/i2c.h @@ -0,0 +1,48 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2004 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. + */ + +#ifndef INCLUDED_I2C_H +#define INCLUDED_I2C_H + +#include + +class i2c; +typedef boost::shared_ptr i2c_sptr; + +/*! + * \brief abstract class for controlling i2c bus + */ +class i2c { + public: + + i2c () {} + virtual ~i2c (); + + //! \returns true iff successful + virtual bool write (int addr, const unsigned char *buf, int nbytes) = 0; + + //! \returns number of bytes read or -1 if error + virtual int read (int addr, unsigned char *buf, int max_bytes) = 0; +}; + +#endif /* INCLUDED_I2C_H */ + diff --git a/gnuradio-core/src/lib/io/i2c_bbio.cc b/gnuradio-core/src/lib/io/i2c_bbio.cc new file mode 100644 index 000000000..8f3839768 --- /dev/null +++ b/gnuradio-core/src/lib/io/i2c_bbio.cc @@ -0,0 +1,29 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2004 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. + */ + +#include "i2c_bbio.h" + +i2c_bbio::~i2c_bbio () +{ + // NOP +} + diff --git a/gnuradio-core/src/lib/io/i2c_bbio.h b/gnuradio-core/src/lib/io/i2c_bbio.h new file mode 100644 index 000000000..f0ea3b664 --- /dev/null +++ b/gnuradio-core/src/lib/io/i2c_bbio.h @@ -0,0 +1,49 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2004 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. + */ + +#ifndef INCLUDED_I2C_BBIO_H +#define INCLUDED_I2C_BBIO_H + +#include + +class i2c_bbio; +typedef boost::shared_ptr i2c_bbio_sptr; + + +/*! + * \brief abstract class that implements bit banging i/o for i2c bus. + */ +class i2c_bbio { + public: + + i2c_bbio () {} + virtual ~i2c_bbio (); + + virtual void set_scl (bool state) = 0; + virtual void set_sda (bool state) = 0; + virtual bool get_sda () = 0; + + virtual void lock () = 0; + virtual void unlock () = 0; +}; + +#endif /* INCLUDED_I2C_BBIO_H */ diff --git a/gnuradio-core/src/lib/io/i2c_bbio_pp.cc b/gnuradio-core/src/lib/io/i2c_bbio_pp.cc new file mode 100644 index 000000000..125f01c33 --- /dev/null +++ b/gnuradio-core/src/lib/io/i2c_bbio_pp.cc @@ -0,0 +1,87 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2004 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. + */ + +#include "i2c_bbio_pp.h" +#include "microtune_eval_board_defs.h" + +i2c_bbio_pp::i2c_bbio_pp (ppio_sptr pp) +{ + d_pp = pp; + d_pp->lock (); + d_pp->write_control (d_pp->read_control () & ~UT_CP_MUST_BE_ZERO); // output, no interrupts + d_pp->unlock (); +} + +i2c_bbio_sptr +make_i2c_bbio_pp (ppio_sptr pp) +{ + return i2c_bbio_sptr (new i2c_bbio_pp (pp)); +} + +void +i2c_bbio_pp::set_scl (bool state) +{ + int r = d_pp->read_control(); + + if (!state){ // active low + d_pp->write_control (r | UT_CP_TUNER_SCL); + } + else { + d_pp->write_control (r & ~UT_CP_TUNER_SCL); + } + d_pp->read_control (); // use for 1us delay + d_pp->read_control (); // use for 1us delay +} + +void +i2c_bbio_pp::set_sda (bool state) +{ + int r = d_pp->read_data (); + + if (!state){ // active low + d_pp->write_data (r | UT_DP_TUNER_SDA_OUT); + } + else { + d_pp->write_data (r & ~UT_DP_TUNER_SDA_OUT); + } + d_pp->read_data (); // use for 1us delay + d_pp->read_data (); // use for 1us delay +} + +bool +i2c_bbio_pp::get_sda () +{ + int r = d_pp->read_status (); + return (r & UT_SP_TUNER_SDA_IN) == 0; // eval board has an inverter on it +} + +void +i2c_bbio_pp::lock () +{ + d_pp->lock (); +} + +void +i2c_bbio_pp::unlock () +{ + d_pp->unlock (); +} diff --git a/gnuradio-core/src/lib/io/i2c_bbio_pp.h b/gnuradio-core/src/lib/io/i2c_bbio_pp.h new file mode 100644 index 000000000..25af0cf42 --- /dev/null +++ b/gnuradio-core/src/lib/io/i2c_bbio_pp.h @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2004 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. + */ + +#ifndef INCLUDED_I2C_BBIO_PP_H +#define INCLUDED_I2C_BBIO_PP_H + +#include "i2c_bbio.h" +#include "ppio.h" + +/*! + * \brief concrete class that bit bangs eval board i2c bus using parallel port + * + * This class talks to the i2c bus on the microtune eval board using + * the parallel port. This works for both the 4937 and 4702 boards. + */ +class i2c_bbio_pp : public i2c_bbio { + friend i2c_bbio_sptr make_i2c_bbio_pp (ppio_sptr pp); + i2c_bbio_pp (ppio_sptr pp); + + public: + + virtual void set_scl (bool state); + virtual void set_sda (bool state); + virtual bool get_sda (); + + virtual void lock (); + virtual void unlock (); + + private: + ppio_sptr d_pp; +}; + +i2c_bbio_sptr make_i2c_bbio_pp (ppio_sptr pp); + + +#endif /* INCLUDED_I2C_BBIO_PP_H */ diff --git a/gnuradio-core/src/lib/io/i2c_bitbang.cc b/gnuradio-core/src/lib/io/i2c_bitbang.cc new file mode 100644 index 000000000..6bf37b604 --- /dev/null +++ b/gnuradio-core/src/lib/io/i2c_bitbang.cc @@ -0,0 +1,144 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2004 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. + */ + +#include "i2c_bitbang.h" + +i2c_bitbang::i2c_bitbang (i2c_bbio_sptr io) +{ + d_io = io; + d_io->lock (); + + stop (); // get bus in known state + + d_io->unlock (); +} + +i2c_sptr +make_i2c_bitbang (i2c_bbio_sptr io) +{ + return i2c_sptr (new i2c_bitbang (io)); +} + + +// start: +// entry: SCL = 1, SDA = 1 +// exit: SCL = 0, SDA = 0 + +void +i2c_bitbang::start () +{ + set_sda (1); + set_scl (1); + set_sda (0); // SDA high -> low while SCL high + set_scl (0); +} + + +// stop: +// entry: SCL = X, SDA = X +// exit: SCL = 1, SDA = 1 + +void +i2c_bitbang::stop () +{ + set_scl (0); + set_sda (0); + set_scl (1); + set_sda (1); // SDA low -> high while SCL high +} + + +// write_bit: +// entry: SCL = 0, SDA = X +// exit: SCL = 0, SDA = X + +void +i2c_bitbang::write_bit (bool bit) +{ + set_sda (bit); + set_scl (1); + set_scl (0); +} + + +// write_byte: +// entry: SCL = 0, SDA = X +// exit: SCL = 0, SDA = 1 + +bool +i2c_bitbang::write_byte (char t) +{ + int i; + bool ack_bit; + + for (i = 0; i < 8; i++){ + write_bit (t & 0x80); + t <<= 1; + } + + // clock #9. This is the ACK bit. + + set_sda (1); // tristate SDA + set_scl (1); + ack_bit = get_sda (); // slave should pull SDA line low + set_scl (0); + + return ack_bit == 0; +} + + +// write: the high level entry point... +// entry: SCL = 1, SDA = 1 +// exit: SCL = 1, SDA = 1 + +bool +i2c_bitbang::write (int addr, const unsigned char *buf, int nbytes) +{ + bool ok = true; + + d_io->lock (); + start (); + ok = write_byte ((addr << 1) | 0); // addr plus "read opcode" + + for (int i = 0; i < nbytes; i++) + ok &= write_byte (buf[i]); + + stop (); + d_io->unlock (); + return ok; +} + + +// read: the high level entry point... +// entry: SCL = 1, SDA = 1 +// exit: SCL = 1, SDA = 1 + +int +i2c_bitbang::read (int addr, unsigned char *buf, int max_bytes) +{ + d_io->lock (); + + // FIXME + + d_io->unlock (); + return -1; +} diff --git a/gnuradio-core/src/lib/io/i2c_bitbang.h b/gnuradio-core/src/lib/io/i2c_bitbang.h new file mode 100644 index 000000000..5196cd234 --- /dev/null +++ b/gnuradio-core/src/lib/io/i2c_bitbang.h @@ -0,0 +1,63 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2004 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. + */ + +#ifndef INCLUDED_I2C_BITBANG_H +#define INCLUDED_I2C_BITBANG_H + +#include +#include + +/*! + * \brief class for controlling i2c bus + */ +class i2c_bitbang : public i2c { + friend i2c_sptr make_i2c_bitbang (i2c_bbio_sptr io); + i2c_bitbang (i2c_bbio_sptr io); + + public: + ~i2c_bitbang () {} + + //! \returns true iff successful + bool write (int addr, const unsigned char *buf, int nbytes); + + //! \returns number of bytes read or -1 if error + int read (int addr, unsigned char *buf, int max_bytes); + + +private: + void start (); + void stop (); + void write_bit (bool bit); + bool write_byte (char byte); + + void set_sda (bool bit) { d_io->set_sda (bit); } + void set_scl (bool bit) { d_io->set_scl (bit); } + bool get_sda () { return d_io->get_sda (); } + + i2c_bbio_sptr d_io; +}; + +i2c_sptr make_i2c_bitbang (i2c_bbio_sptr io); + +#endif /* INCLUDED_I2C_BITBANG_H */ + + diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i new file mode 100644 index 000000000..ae4ca2682 --- /dev/null +++ b/gnuradio-core/src/lib/io/io.i @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +%{ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +%} + +%include "gr_file_sink.i" +%include "gr_file_source.i" +%include "gr_file_descriptor_sink.i" +%include "gr_file_descriptor_source.i" +%include "microtune_xxxx_eval_board.i" +%include "microtune_4702_eval_board.i" +%include "microtune_4937_eval_board.i" +%include "sdr_1000.i" +%include "gr_oscope_sink.i" +%include "ppio.i" +%include "gr_message_source.i" +%include "gr_message_sink.i" + diff --git a/gnuradio-core/src/lib/io/microtune_4702.cc b/gnuradio-core/src/lib/io/microtune_4702.cc new file mode 100644 index 000000000..9b180ff8b --- /dev/null +++ b/gnuradio-core/src/lib/io/microtune_4702.cc @@ -0,0 +1,183 @@ +/* -*- c++-*- */ +/* + * Copyright 2001,2003,2004 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. + */ + +#include "microtune_4702.h" +#include +#include +#include "i2c.h" + +static const double FIRST_IF = 36.00e6; + +// The tuner internally has 3 bands: VHF Low, VHF High & UHF. +// These are the recommened boundaries +static const double VHF_High_takeover = 174e6; +static const double UHF_takeover = 470e6; + +static int PLL_I2C_ADDR = 0x60; + +static unsigned char +control_byte_1 (bool prescaler, int reference_divisor) +{ + int c = 0x80; + //Note: Last two divider bits (bits 2 and 3 of this byte) determined later + if (prescaler) + c |= 0x10; + + switch (reference_divisor){ + case 2: + c |= 0x00; break; + case 4: + c |= 0x01; break; + case 8: + c |= 0x02; break; + case 16: + c |= 0x03; break; + case 32: + c |= 0x04; break; + case 64: + c |= 0x05; break; + case 128: + c |= 0x06; break; + case 256: + c |= 0x07; break; + case 24: + c |= 0x08; break; + case 5: + c |= 0x09; break; + case 10: + c |= 0x0A; break; + case 20: + c |= 0x0B; break; + case 40: + c |= 0x0C; break; + case 80: + c |= 0x0D; break; + case 160: + c |= 0x0E; break; + case 320: + c |= 0x0F; break; + default: + abort (); + } + return c; +} + +static unsigned char +control_byte_2 (double target_freq) +{ + int c; + + if (target_freq < VHF_High_takeover) // VHF low + c = 0x8E; + + else if (target_freq < UHF_takeover){ // VHF high + c = 0x05; + if (target_freq < 390e6) + c |= 0x40; + else + c |= 0x80; + } + else { // UHF + c = 0x03; + if (target_freq < 750e6) + c |= 0x80; + else + c |= 0xC0; + } + + return c; +} + + +microtune_4702::microtune_4702 (i2c_sptr i2c, int i2c_addr) +{ + d_i2c = i2c; + d_i2c_addr = i2c_addr; + d_reference_divider = 320; + d_prescaler = false; +} + +microtune_4702::~microtune_4702 () +{ + // nop +} + +/*! + * \brief select RF frequency to be tuned to output frequency. + * \p target_freq is the requested frequency in Hz, \p actual_freq + * is set to the actual frequency tuned. It takes about 100 ms + * for the PLL to settle. + * + * \returns true iff sucessful. + */ +bool +microtune_4702::set_RF_freq (double target_freq, double *p_actual_freq) +{ + unsigned char buf[4]; + + double target_f_osc = target_freq + FIRST_IF; + + double f_ref = 4e6 / d_reference_divider; + + //int divisor = (int) ((target_f_osc + (f_ref * 4)) / (f_ref * 8)); + + long int divisor = (long int) (target_f_osc / f_ref); + double actual_freq = (f_ref * divisor) - FIRST_IF; + if (p_actual_freq != 0) + *p_actual_freq = actual_freq; + + if ((divisor & ~0x1ffff) != 0) // >17 bit divisor + return false; + + buf[0] = ((divisor & 0x07f00) >> 8) & 0xff; // DB1 + buf[1] = divisor & 0xff; // DB2 + buf[2] = control_byte_1 (d_prescaler, d_reference_divider); + buf[2] = (buf[2]|(((divisor & 0x18000) >> 10)) & 0xff); + buf[3] = control_byte_2 (target_freq); + + printf ("%x\n", PLL_I2C_ADDR); +//#if 0 + printf ("set_RF_freq: target: %g MHz actual: %g MHz %02x %02x %02x %02x\n", + target_freq/1e6, actual_freq/1e6, buf[0], buf[1], buf[2], buf[3]); +//#endif + + return d_i2c->write (d_i2c_addr, buf, sizeof (buf)); +} + +/*! + * \returns true iff PLL is locked + */ +bool +microtune_4702::pll_locked_p () +{ + // FIXME + return true; +} + +/*! + * \returns the output frequency of the tuner in Hz. + */ +double +microtune_4702::get_output_freq () +{ + return FIRST_IF; +} diff --git a/gnuradio-core/src/lib/io/microtune_4702.h b/gnuradio-core/src/lib/io/microtune_4702.h new file mode 100644 index 000000000..b5890774f --- /dev/null +++ b/gnuradio-core/src/lib/io/microtune_4702.h @@ -0,0 +1,69 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2003 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. + */ + +#ifndef INCLUDED_MICROTUNE_4702_H +#define INCLUDED_MICROTUNE_4702_H + +#include + +/*! + * \brief class for controlling microtune 4702 tuner module + */ + +class microtune_4702 : public microtune_xxxx { +public: + microtune_4702 (i2c_sptr i2c, int i2c_addr); + + virtual ~microtune_4702 (); + + /*! + * \brief select RF frequency to be tuned to output frequency. + * \p freq is the requested frequency in Hz, \p actual_freq + * is set to the actual frequency tuned. It takes about 100 ms + * for the PLL to settle. + * + * \returns true iff sucessful. + */ + bool set_RF_freq (double freq, double *actual_freq); + + /*! + * \returns true iff PLL is locked + */ + bool pll_locked_p (); + + /*! + * \returns the output frequency of the tuner in Hz. + */ + double get_output_freq (); + + private: + + i2c_sptr d_i2c; + int d_i2c_addr; + int d_reference_divider; + bool d_prescaler; /* if set, higher charge pump current: + faster tuning, worse phase noise + for distance < 10kHz to the carrier */ +}; + +#endif /* INCLUDED_MICROTUNE_4702_H */ + diff --git a/gnuradio-core/src/lib/io/microtune_4702_eval_board.cc b/gnuradio-core/src/lib/io/microtune_4702_eval_board.cc new file mode 100644 index 000000000..88cf2b6a0 --- /dev/null +++ b/gnuradio-core/src/lib/io/microtune_4702_eval_board.cc @@ -0,0 +1,88 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2004 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. + */ + +#include "microtune_4702_eval_board.h" +#include "microtune_eval_board_defs.h" +#include "ppio.h" +#include "microtune_4702.h" + +static const int TUNER_I2C_ADDR = 0x60; + +microtune_4702_eval_board::microtune_4702_eval_board (int which_pp) + : microtune_xxxx_eval_board (which_pp) +{ + d_tuner = new microtune_4702 (d_i2c, TUNER_I2C_ADDR); +} + +microtune_4702_eval_board::~microtune_4702_eval_board () +{ + // default is OK +} + +static const float RF_MIN_V = 1.0; // RF AGC control voltages +static const float RF_MAX_V = 4.0; +static const float IF_MIN_V = 2.0; // IF AGC control voltages +static const float IF_MAX_V = 4.0; + +static const float MIN_AGC = 0; // bottom of synthetic range +static const float MAX_AGC = 1000; // top of synthetic range + +static const float CUTOVER_POINT = 667; + + +// linear is in the range MIN_AGC to MAX_AGC + +static float +linear_to_RF_AGC_voltage (float linear) +{ + if (linear >= CUTOVER_POINT) + return RF_MAX_V; + + float slope = (RF_MAX_V - RF_MIN_V) / CUTOVER_POINT; + return RF_MIN_V + linear * slope; +} + +static float +linear_to_IF_AGC_voltage (float linear) +{ + if (linear < CUTOVER_POINT) + return IF_MIN_V; + + float slope = (IF_MAX_V - IF_MIN_V) / (MAX_AGC - CUTOVER_POINT); + return IF_MIN_V + (linear - CUTOVER_POINT) * slope; +} + +void +microtune_4702_eval_board::set_AGC (float v) +{ + if (v < MIN_AGC) + v = MIN_AGC; + + if (v > MAX_AGC) + v = MAX_AGC; + + float rf_agc_voltage = linear_to_RF_AGC_voltage (v); + float if_agc_voltage = linear_to_IF_AGC_voltage (v); + + set_RF_AGC_voltage (rf_agc_voltage); + set_IF_AGC_voltage (if_agc_voltage); +} diff --git a/gnuradio-core/src/lib/io/microtune_4702_eval_board.h b/gnuradio-core/src/lib/io/microtune_4702_eval_board.h new file mode 100644 index 000000000..9fc2914ed --- /dev/null +++ b/gnuradio-core/src/lib/io/microtune_4702_eval_board.h @@ -0,0 +1,47 @@ +/* -*- C++ -*- */ +/* + * Copyright 2001,2004 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. + */ + +#ifndef INCLUDED_MICROTUNE_4702_EVAL_BOARD_H +#define INCLUDED_MICROTUNE_4702_EVAL_BOARD_H + +#include "microtune_xxxx_eval_board.h" + +/*! + * \brief control microtune 4702 eval board + */ + +class microtune_4702_eval_board : public microtune_xxxx_eval_board { +public: + microtune_4702_eval_board (int which_pp = 0); + ~microtune_4702_eval_board (); + + /*! + * \brief set RF and IF AGC levels together (scale [0, 1000]) + * + * This provides a simple linear interface for adjusting both + * the RF and IF gain in consort. This is the easy to use interface. + * 0 corresponds to minimum gain. 1000 corresponds to maximum gain. + */ + virtual void set_AGC (float value_0_1000); +}; + +#endif /* INCLUDED_MICROTUNE_4702_EVAL_BOARD_H */ diff --git a/gnuradio-core/src/lib/io/microtune_4702_eval_board.i b/gnuradio-core/src/lib/io/microtune_4702_eval_board.i new file mode 100644 index 000000000..6205c9303 --- /dev/null +++ b/gnuradio-core/src/lib/io/microtune_4702_eval_board.i @@ -0,0 +1,36 @@ +/* -*- C++ -*- */ +/* + * Copyright 2001,2004 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. + */ + +class microtune_4702_eval_board : public microtune_xxxx_eval_board { +public: + microtune_4702_eval_board (int which_pp = 0); + ~microtune_4702_eval_board (); + + /*! + * \brief set RF and IF AGC levels together (scale [0, 1000]) + * + * This provides a simple linear interface for adjusting both + * the RF and IF gain in consort. This is the easy to use interface. + * 0 corresponds to minimum gain. 1000 corresponds to maximum gain. + */ + virtual void set_AGC (float value_0_1000); +}; diff --git a/gnuradio-core/src/lib/io/microtune_4937.cc b/gnuradio-core/src/lib/io/microtune_4937.cc new file mode 100644 index 000000000..c05f63c11 --- /dev/null +++ b/gnuradio-core/src/lib/io/microtune_4937.cc @@ -0,0 +1,146 @@ +/* -*- c++-*- */ +/* + * Copyright 2001,2003 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. + */ + +#include "microtune_4937.h" +#include +#include +#include + +static const double first_IF = 43.75e6; + +// The tuner internally has 3 bands: VHF Low, VHF High & UHF. +// These are the recommened boundaries +static const double VHF_High_takeover = 158e6; +static const double UHF_takeover = 464e6; + + +static unsigned char +control_byte_1 (bool fast_tuning_p, int reference_divisor) +{ + int c = 0x88; + + if (fast_tuning_p) + c |= 0x40; + + switch (reference_divisor){ + case 512: + c |= 0x3 << 1; break; + case 640: + c |= 0x0 << 1; break; + case 1024: + c |= 0x1 << 1; break; + default: + abort (); + } + return c; +} + +static unsigned char +control_byte_2 (double target_freq, bool shutdown_tx_PGA) +{ + int c; + + if (target_freq < VHF_High_takeover) // VHF low + c = 0xa0; + else if (target_freq < UHF_takeover) // VHF high + c = 0x90; + else // UHF + c = 0x30; + + if (shutdown_tx_PGA) + c |= 0x08; + + return c; +} + +microtune_4937::microtune_4937 (i2c_sptr i2c, int i2c_addr) +{ + d_i2c = i2c; + d_i2c_addr = i2c_addr; + d_reference_divider = 640; + d_fast_tuning_p = false; +} + +microtune_4937::~microtune_4937 () +{ + // nop +} + +/*! + * \brief select RF frequency to be tuned to output frequency. + * \p target_freq is the requested frequency in Hz, \p actual_freq + * is set to the actual frequency tuned. It takes about 100 ms + * for the PLL to settle. + * + * \returns true iff sucessful. + */ +bool +microtune_4937::set_RF_freq (double target_freq, double *p_actual_freq) +{ + unsigned char buf[4]; + + double target_f_osc = target_freq + first_IF; + + double f_ref = 4e6 / d_reference_divider; + + // f_osc = f_ref * 8 * divisor + // divisor = f_osc / (f_ref * 8) + + int divisor = (int) ((target_f_osc + (f_ref * 4)) / (f_ref * 8)); + double actual_freq = (f_ref * 8 * divisor) - first_IF; + if (p_actual_freq != 0) + *p_actual_freq = actual_freq; + + if ((divisor & ~0x7fff) != 0) // 15 bit divisor + return false; + + buf[0] = (divisor >> 8) & 0xff; // DB1 + buf[1] = divisor & 0xff; // DB2 + buf[2] = control_byte_1 (d_fast_tuning_p, d_reference_divider); + buf[3] = control_byte_2 (target_freq, true); + +#if 0 + printf ("set_RF_freq: target: %g MHz actual: %g MHz %02x %02x %02x %02x\n", + target_freq/1e6, actual_freq/1e6, buf[0], buf[1], buf[2], buf[3]); +#endif + + return d_i2c->write (d_i2c_addr, buf, 4); +} + +/*! + * \returns true iff PLL is locked + */ +bool +microtune_4937::pll_locked_p () +{ + // FIXME + return true; +} + +/*! + * \returns the output frequency of the tuner in Hz. + */ +double +microtune_4937::get_output_freq () +{ + return 5.75e6; // 3x7702 +} diff --git a/gnuradio-core/src/lib/io/microtune_4937.h b/gnuradio-core/src/lib/io/microtune_4937.h new file mode 100644 index 000000000..84c8d6112 --- /dev/null +++ b/gnuradio-core/src/lib/io/microtune_4937.h @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2003 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. + */ + +#ifndef INCLUDED_MICROTUNE_4937_H +#define INCLUDED_MICROTUNE_4937_H + +#include + +/*! + * \brief class for controlling microtune 4937 tuner module + */ +class microtune_4937 : public microtune_xxxx { +public: + microtune_4937 (i2c_sptr i2c, int i2c_addr = 0x61); + virtual ~microtune_4937 (); + + /*! + * \brief select RF frequency to be tuned to output frequency. + * \p freq is the requested frequency in Hz, \p actual_freq + * is set to the actual frequency tuned. It takes about 100 ms + * for the PLL to settle. + * + * \returns true iff sucessful. + */ + bool set_RF_freq (double freq, double *actual_freq); + + /*! + * \returns true iff PLL is locked + */ + bool pll_locked_p (); + + /*! + * \returns the output frequency (IF center freq) of the tuner in Hz. + */ + double get_output_freq (); + + private: + + i2c_sptr d_i2c; + int d_i2c_addr; + int d_reference_divider; + bool d_fast_tuning_p; /* if set, higher charge pump current: + faster tuning, worse phase noise + for distance < 10kHz to the carrier */ +}; + +#endif /* INCLUDED_MICROTUNE_4937_H */ diff --git a/gnuradio-core/src/lib/io/microtune_4937_eval_board.cc b/gnuradio-core/src/lib/io/microtune_4937_eval_board.cc new file mode 100644 index 000000000..82a03740c --- /dev/null +++ b/gnuradio-core/src/lib/io/microtune_4937_eval_board.cc @@ -0,0 +1,97 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2004 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. + */ + +#include "microtune_4937_eval_board.h" +#include "microtune_eval_board_defs.h" +#include "ppio.h" +#include "microtune_4937.h" + +static const int TUNER_I2C_ADDR = 0x61; + +microtune_4937_eval_board::microtune_4937_eval_board (int which_pp) + : microtune_xxxx_eval_board (which_pp) +{ + d_tuner = new microtune_4937 (d_i2c, TUNER_I2C_ADDR); + + // disable upstream amplifier + d_ppio->lock (); + int t = d_ppio->read_data (); + t &= ~(UT_DP_TX_ENABLE | UT_DP_TX_SDA | UT_DP_TX_SCL); + t |= UT_DP_TX_AS; + d_ppio->write_data (t); + d_ppio->unlock (); +} + +microtune_4937_eval_board::~microtune_4937_eval_board () +{ + // Default action is OK +} + + +static const float RF_MIN_V = 1.5; // RF AGC control voltages +static const float RF_MAX_V = 4.0; +static const float IF_MIN_V = 2.0; // IF AGC control voltages +static const float IF_MAX_V = 4.0; + +static const float MIN_AGC = 0; // bottom of synthetic range +static const float MAX_AGC = 1000; // top of synthetic range + +static const float CUTOVER_POINT = 667; + + +// linear is in the range MIN_AGC to MAX_AGC + +static float +linear_to_RF_AGC_voltage (float linear) +{ + if (linear >= CUTOVER_POINT) + return RF_MAX_V; + + float slope = (RF_MAX_V - RF_MIN_V) / CUTOVER_POINT; + return RF_MIN_V + linear * slope; +} + +static float +linear_to_IF_AGC_voltage (float linear) +{ + if (linear < CUTOVER_POINT) + return IF_MIN_V; + + float slope = (IF_MAX_V - IF_MIN_V) / (MAX_AGC - CUTOVER_POINT); + return IF_MIN_V + (linear - CUTOVER_POINT) * slope; +} + +void +microtune_4937_eval_board::set_AGC (float v) +{ + if (v < MIN_AGC) + v = MIN_AGC; + + if (v > MAX_AGC) + v = MAX_AGC; + + float rf_agc_voltage = linear_to_RF_AGC_voltage (v); + float if_agc_voltage = linear_to_IF_AGC_voltage (v); + + set_RF_AGC_voltage (rf_agc_voltage); + set_IF_AGC_voltage (if_agc_voltage); +} diff --git a/gnuradio-core/src/lib/io/microtune_4937_eval_board.h b/gnuradio-core/src/lib/io/microtune_4937_eval_board.h new file mode 100644 index 000000000..8a8f46b06 --- /dev/null +++ b/gnuradio-core/src/lib/io/microtune_4937_eval_board.h @@ -0,0 +1,48 @@ +/* -*- C++ -*- */ +/* + * Copyright 2001,2004 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. + */ + +#ifndef INCLUDED_MICROTUNE_4937_EVAL_BOARD_H +#define INCLUDED_MICROTUNE_4937_EVAL_BOARD_H + +#include "microtune_xxxx_eval_board.h" + +/*! + * \brief control microtune 4937 eval board + */ + +class microtune_4937_eval_board : public microtune_xxxx_eval_board { +public: + microtune_4937_eval_board (int which_pp = 0); + ~microtune_4937_eval_board (); + + /*! + * \brief set RF and IF AGC levels together (scale [0, 1000]) + * + * This provides a simple linear interface for adjusting both + * the RF and IF gain in consort. This is the easy to use interface. + * 0 corresponds to minimum gain. 1000 corresponds to maximum gain. + */ + virtual void set_AGC (float value_0_1000); +}; + + +#endif /* INCLUDED_MICROTUNE_4937_EVAL_BOARD_H */ diff --git a/gnuradio-core/src/lib/io/microtune_4937_eval_board.i b/gnuradio-core/src/lib/io/microtune_4937_eval_board.i new file mode 100644 index 000000000..106832e3d --- /dev/null +++ b/gnuradio-core/src/lib/io/microtune_4937_eval_board.i @@ -0,0 +1,36 @@ +/* -*- C++ -*- */ +/* + * Copyright 2001,2004 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. + */ + +class microtune_4937_eval_board : public microtune_xxxx_eval_board { +public: + microtune_4937_eval_board (int which_pp = 0); + ~microtune_4937_eval_board (); + + /*! + * \brief set RF and IF AGC levels together (scale [0, 1000]) + * + * This provides a simple linear interface for adjusting both + * the RF and IF gain in consort. This is the easy to use interface. + * 0 corresponds to minimum gain. 1000 corresponds to maximum gain. + */ + virtual void set_AGC (float value_0_1000); +}; diff --git a/gnuradio-core/src/lib/io/microtune_eval_board.i b/gnuradio-core/src/lib/io/microtune_eval_board.i new file mode 100644 index 000000000..7c673e3a5 --- /dev/null +++ b/gnuradio-core/src/lib/io/microtune_eval_board.i @@ -0,0 +1,95 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003 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. + */ + +/* + * SWIG interface defs for Microtune 4937 and eval board with Eric's daughterboard + */ + +/*! + * \brief abstract class for controlling microtune 4937 tuner module + */ +class microtune_4937 { +public: + microtune_4937 (); + + virtual ~microtune_4937 (); + + // returns actual freq or 0 if error (easier interface for SWIG) + double set_RF_freq (double freq); + + /*! + * \returns true iff PLL is locked + */ + bool pll_locked_p (); + + /*! + * \returns the output frequency (IF center freq) of the tuner in Hz. + */ + double get_output_freq (); + + + private: + //! \returns true iff successful + virtual bool i2c_write (int addr, const unsigned char *buf, int nbytes) = 0; + + //! \returns number of bytes read or -1 if error + virtual int i2c_read (int addr, unsigned char *buf, int max_bytes) = 0; + + int d_reference_divider; + bool d_fast_tuning_p; /* if set, higher charge pump current: + faster tuning, worse phase noise + for distance < 10kHz to the carrier */ +}; + +/*! + * \brief concrete class for controlling microtune 4937 eval board attached to parallel port + */ +class microtune_eval_board : public microtune_4937 { +public: + microtune_eval_board (int which_pp = 0); + ~microtune_eval_board (); + + //! is the eval board present? + bool board_present_p (); + + /*! + * \brief set RF and IF AGC control voltages ([0, 5] volts) + */ + void set_RF_AGC_voltage (float volts); + void set_IF_AGC_voltage (float volts); + + /*! + * \brief set RF and IF AGC levels together (scale [0, 1000]) + * + * This provides a simple linear interface for adjusting both + * the RF and IF gain in consort. This is the easy to use interface. + * 0 corresponds to minimum gain. 1000 corresponds to maximum gain. + */ + void set_AGC (float value_0_1000); + +private: + //! \returns true iff successful + virtual bool i2c_write (int addr, const unsigned char *buf, int nbytes); + + //! \returns number of bytes read or -1 if error + virtual int i2c_read (int addr, unsigned char *buf, int max_bytes); +}; diff --git a/gnuradio-core/src/lib/io/microtune_eval_board_defs.h b/gnuradio-core/src/lib/io/microtune_eval_board_defs.h new file mode 100644 index 000000000..5245fd5ce --- /dev/null +++ b/gnuradio-core/src/lib/io/microtune_eval_board_defs.h @@ -0,0 +1,71 @@ +/* -*-C-*- +******************************************************************************* +* +* File: microtune_eval_board_defs.h +* Description: defines for parallel port control of eval board +* +******************************************************************************* +*/ + +/* + * Copyright 2001 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. + */ + +#ifndef _MICROTUNE_EVAL_BOARD_DEFS_H_ +#define _MICROTUNE_EVAL_BOARD_DEFS_H_ + +/* + * The Microtune 4937DI5 cable modem tuner eval board is controlled + * by bit banging the PC parallel port. This file defines the relevant + * bits. + * + * The parallel port has an 8 bit data port (output), + * an 8 bit control port (output) and + * an 8 bit status port (input). + * + * Not all bits of the control and status ports may be arbitrarily used. + */ + + +// parallel port data port constants (output) + +static const int UT_DP_TX_SDA = 0x01; // upstream control bus +static const int UT_DP_TX_SCL = 0x02; // upstream control bus +static const int UT_DP_TX_AS = 0x04; // upstream control bus +static const int UT_DP_TX_ENABLE = 0x08; // upstream h/w enable +// bits 4,5,6 not used +static const int UT_DP_TUNER_SDA_OUT = 0x80; // tuner i2c bus data + +// parallel port control port constants (output) + +static const int UT_CP_TUNER_SCL = 0x08; // tuner i2c bus clock +static const int UT_CP_MUST_BE_ZERO = 0xf0; // must be zero + +// parallel port status port constants (input) + +// bits 0,1,2 not used +static const int UT_SP_TUNER_SCL_LOOP_BACK= 0x08; // inverted SCL loop back +static const int UT_SP_SHOULD_BE_ZERO = 0x10; // reads as zero +static const int UT_SP_SHOULD_BE_ONE = 0x20; // reads as one +// bit 6 not used +static const int UT_SP_TUNER_SDA_IN = 0x80; + + +#endif /* _MICROTUNE_EVAL_BOARD_DEFS_H_ */ diff --git a/gnuradio-core/src/lib/io/microtune_xxxx.cc b/gnuradio-core/src/lib/io/microtune_xxxx.cc new file mode 100644 index 000000000..8633b111b --- /dev/null +++ b/gnuradio-core/src/lib/io/microtune_xxxx.cc @@ -0,0 +1,41 @@ +/* -*- c++-*- */ +/* + * Copyright 2001,2003,2004 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. + */ + +#include "microtune_xxxx.h" + +microtune_xxxx::~microtune_xxxx () +{ + // nop +} + +double +microtune_xxxx::set_RF_freq (double target_freq) +{ + double actual_freq = 0.0; + + if (set_RF_freq (target_freq, &actual_freq)) + return actual_freq; + + return 0.0; +} + + diff --git a/gnuradio-core/src/lib/io/microtune_xxxx.h b/gnuradio-core/src/lib/io/microtune_xxxx.h new file mode 100644 index 000000000..8fac06d8f --- /dev/null +++ b/gnuradio-core/src/lib/io/microtune_xxxx.h @@ -0,0 +1,64 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2003,2004 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. + */ + +#ifndef INCLUDED_MICROTUNE_XXXX_H +#define INCLUDED_MICROTUNE_XXXX_H + +#include + +class i2c; +typedef boost::shared_ptr i2c_sptr; + +/*! + * \brief abstract class for controlling microtune {4937,4702} tuner modules + */ +class microtune_xxxx { +public: + microtune_xxxx () {} + virtual ~microtune_xxxx (); + + /*! + * \brief select RF frequency to be tuned to output frequency. + * \p freq is the requested frequency in Hz, \p actual_freq + * is set to the actual frequency tuned. It takes about 100 ms + * for the PLL to settle. + * + * \returns true iff sucessful. + */ + virtual bool set_RF_freq (double freq, double *actual_freq) = 0; + + // returns actual freq or 0 if error (easier interface for SWIG) + double set_RF_freq (double freq); + + /*! + * \returns true iff PLL is locked + */ + virtual bool pll_locked_p () = 0; + + /*! + * \returns the output frequency (IF center freq) of the tuner in Hz. + */ + virtual double get_output_freq () = 0; + +}; + +#endif /* INCLUDED_MICROTUNE_XXXX_H */ diff --git a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc new file mode 100644 index 000000000..a7ea98d6f --- /dev/null +++ b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc @@ -0,0 +1,140 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2004 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. + */ + +#include "microtune_xxxx_eval_board.h" +#include "microtune_eval_board_defs.h" +#include "microtune_xxxx.h" +#include "ppio.h" +#include "i2c_bitbang.h" +#include "i2c_bbio_pp.h" +#include + +static int AGC_DAC_I2C_ADDR = 0x2C; + +microtune_xxxx_eval_board::microtune_xxxx_eval_board (int which_pp) +{ + d_ppio = make_ppio (which_pp); + d_i2c = make_i2c_bitbang (make_i2c_bbio_pp (d_ppio)); + d_tuner = 0; +} + +microtune_xxxx_eval_board::~microtune_xxxx_eval_board () +{ + delete d_tuner; + d_tuner = 0; +} + + +//! is the eval board present? +bool +microtune_xxxx_eval_board::board_present_p () +{ + bool result = true; + d_ppio->lock (); + + int t = d_ppio->read_status (); + if ((t & UT_SP_SHOULD_BE_ZERO) != 0 + || (t & UT_SP_SHOULD_BE_ONE) != UT_SP_SHOULD_BE_ONE) + result = false; + + // could also see if SCL is looped back or not, but that seems like overkill + + d_ppio->unlock (); + return result; +} + +/* + * ---------------------------------------------------------------- + * AGC stuff + * + * We're using a MAX518 8-bit 5V dual dac for setting the AGC's + * ---------------------------------------------------------------- + */ +void +microtune_xxxx_eval_board::write_dac (int which, int value) +{ + unsigned char cmd[2]; + cmd[0] = which & 1; + cmd[1] = value; + d_i2c->write (AGC_DAC_I2C_ADDR, cmd, sizeof (cmd)); +} + +void +microtune_xxxx_eval_board::write_both_dacs (int value0, int value1) +{ + unsigned char cmd[4]; + cmd[0] = 0; + cmd[1] = value0; + cmd[2] = 1; + cmd[3] = value1; + d_i2c->write (AGC_DAC_I2C_ADDR, cmd, sizeof (cmd)); +} + +static int scale_volts (float volts) +{ + int n; + n = (int) rint (volts * (256 / 5.0)); + if (n < 0) + n = 0; + if (n > 255) + n = 255; + + return n; +} + +void +microtune_xxxx_eval_board::set_RF_AGC_voltage (float volts) +{ + write_dac (0, scale_volts (volts)); +} + +void +microtune_xxxx_eval_board::set_IF_AGC_voltage (float volts) +{ + write_dac (1, scale_volts (volts)); +} + +// delegate to tuner + +bool +microtune_xxxx_eval_board::set_RF_freq (double freq, double *actual_freq) +{ + return d_tuner->set_RF_freq (freq, actual_freq); +} + +double +microtune_xxxx_eval_board::set_RF_freq (double freq) +{ + return d_tuner->set_RF_freq (freq); +} + +bool +microtune_xxxx_eval_board::pll_locked_p () +{ + return d_tuner->pll_locked_p (); +} + +double +microtune_xxxx_eval_board::get_output_freq () +{ + return d_tuner->get_output_freq (); +} diff --git a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h new file mode 100644 index 000000000..3a817b698 --- /dev/null +++ b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h @@ -0,0 +1,96 @@ +/* -*- C++ -*- */ +/* + * Copyright 2001,2004 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. + */ + +#ifndef INCLUDED_MICROTUNE_XXXX_EVAL_BOARD_H +#define INCLUDED_MICROTUNE_XXXX_EVAL_BOARD_H + +#include + +class microtune_xxxx; + +class ppio; +typedef boost::shared_ptr ppio_sptr; + +class i2c; +typedef boost::shared_ptr i2c_sptr; + +/*! + * \brief abstract class for controlling microtune xxxx eval board + */ +class microtune_xxxx_eval_board { +public: + microtune_xxxx_eval_board (int which_pp = 0); + virtual ~microtune_xxxx_eval_board (); + + //! is the eval board present? + bool board_present_p (); + + /*! + * \brief set RF and IF AGC control voltages ([0, 5] volts) + */ + void set_RF_AGC_voltage (float volts); + void set_IF_AGC_voltage (float volts); + + /*! + * \brief set RF and IF AGC levels together (scale [0, 1000]) + * + * This provides a simple linear interface for adjusting both + * the RF and IF gain in consort. This is the easy to use interface. + * 0 corresponds to minimum gain. 1000 corresponds to maximum gain. + */ + virtual void set_AGC (float value_0_1000) = 0; + + /*! + * \brief select RF frequency to be tuned to output frequency. + * \p freq is the requested frequency in Hz, \p actual_freq + * is set to the actual frequency tuned. It takes about 100 ms + * for the PLL to settle. + * + * \returns true iff sucessful. + */ + bool set_RF_freq (double freq, double *actual_freq); + + // returns actual freq or 0 if error (easier interface for SWIG) + double set_RF_freq (double freq); + + /*! + * \returns true iff PLL is locked + */ + bool pll_locked_p (); + + /*! + * \returns the output frequency (IF center freq) of the tuner in Hz. + */ + double get_output_freq (); + + +private: + void write_dac (int which, int value); + void write_both_dacs (int val0, int val1); + +protected: + ppio_sptr d_ppio; + i2c_sptr d_i2c; + microtune_xxxx *d_tuner; +}; + +#endif /* INCLUDED_MICROTUNE_XXXX_EVAL_BOARD_H */ diff --git a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i new file mode 100644 index 000000000..2e43f27aa --- /dev/null +++ b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +class microtune_xxxx_eval_board { +public: + microtune_xxxx_eval_board (int which_pp = 0); + virtual ~microtune_xxxx_eval_board (); + + //! is the eval board present? + bool board_present_p (); + + /*! + * \brief set RF and IF AGC control voltages ([0, 5] volts) + */ + void set_RF_AGC_voltage (float volts); + void set_IF_AGC_voltage (float volts); + + /*! + * \brief set RF and IF AGC levels together (scale [0, 1000]) + * + * This provides a simple linear interface for adjusting both + * the RF and IF gain in consort. This is the easy to use interface. + * 0 corresponds to minimum gain. 1000 corresponds to maximum gain. + */ + virtual void set_AGC (float value_0_1000) = 0; + + // returns actual freq or 0 if error (easier interface for SWIG) + double set_RF_freq (double freq); + + /*! + * \returns true iff PLL is locked + */ + bool pll_locked_p (); + + /*! + * \returns the output frequency (IF center freq) of the tuner in Hz. + */ + double get_output_freq (); +}; diff --git a/gnuradio-core/src/lib/io/ppio.cc b/gnuradio-core/src/lib/io/ppio.cc new file mode 100644 index 000000000..86f402bbf --- /dev/null +++ b/gnuradio-core/src/lib/io/ppio.cc @@ -0,0 +1,39 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003 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. + */ + +#include +#include + +ppio::~ppio () +{ +} + +// Factory method. +// +// Right now, we've only got one subclass we like. If there were more, +// we'd instantiate the "right one" here. + +ppio_sptr +make_ppio (int which_pp) +{ + return make_ppio_ppdev (which_pp); +} diff --git a/gnuradio-core/src/lib/io/ppio.h b/gnuradio-core/src/lib/io/ppio.h new file mode 100644 index 000000000..418138705 --- /dev/null +++ b/gnuradio-core/src/lib/io/ppio.h @@ -0,0 +1,61 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2003 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. + */ + +#ifndef INCLUDED_PPIO_H +#define INCLUDED_PPIO_H + +#include + +class ppio; +typedef boost::shared_ptr ppio_sptr; + + +/*! + * \brief abstract class that provides low level access to parallel port bits + */ + +class ppio { + public: + ppio () {} + virtual ~ppio (); + + virtual void write_data (unsigned char v) = 0; + virtual unsigned char read_data () = 0; + virtual void write_control (unsigned char v) = 0; + virtual unsigned char read_control () = 0; + virtual unsigned char read_status () = 0; + + virtual void lock () = 0; + virtual void unlock () = 0; +}; + +/*! + * \brief Factory method. + * + * Split out from class to make life easier for SWIG + */ + +ppio_sptr make_ppio (int which_pp); + + +#endif /* INCLUDED_PPIO_H */ + diff --git a/gnuradio-core/src/lib/io/ppio.i b/gnuradio-core/src/lib/io/ppio.i new file mode 100644 index 000000000..2eaddc204 --- /dev/null +++ b/gnuradio-core/src/lib/io/ppio.i @@ -0,0 +1,48 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +class ppio; +typedef boost::shared_ptr ppio_sptr; + +%template(ppio_sptr) boost::shared_ptr; + +/*! + * \brief abstract class that provides low level access to parallel port bits + */ + +class ppio { + public: + ppio () {} + virtual ~ppio (); + + virtual void write_data (unsigned char v) = 0; + virtual unsigned char read_data () = 0; + virtual void write_control (unsigned char v) = 0; + virtual unsigned char read_control () = 0; + virtual unsigned char read_status () = 0; + + virtual void lock () = 0; + virtual void unlock () = 0; +}; + + +ppio_sptr make_ppio (int which_pp); diff --git a/gnuradio-core/src/lib/io/ppio_ppdev.cc b/gnuradio-core/src/lib/io/ppio_ppdev.cc new file mode 100644 index 000000000..bfdaa3de0 --- /dev/null +++ b/gnuradio-core/src/lib/io/ppio_ppdev.cc @@ -0,0 +1,221 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2003,2004 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 +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_LINUX_PPDEV_H +#include +#include +#include +#include +#else +// #warn "ppio_ppdev is not functional on this platform" +#endif + +// These control port bits are active low. +// We toggle them so that this weirdness doesn't get get propagated +// through our interface. + +static int CP_ACTIVE_LOW_BITS = 0x0B; + +// These status port bits are active low. +// We toggle them so that this weirdness doesn't get get propagated +// through our interface. + +static int SP_ACTIVE_LOW_BITS = 0x80; + +#ifndef HAVE_LINUX_PPDEV_H // use stubs + +ppio_ppdev::ppio_ppdev (int which) +{ + std::cerr << "ppio_ppdev: Not implemented on this platform\n"; + throw std::runtime_error ("not implmeneted"); +} + +ppio_ppdev::~ppio_ppdev () +{ +} + +void +ppio_ppdev::write_data (unsigned char v) +{ +} + +unsigned char +ppio_ppdev::read_data () +{ + return 0; +} + +void +ppio_ppdev::write_control (unsigned char v) +{ +} + +unsigned char +ppio_ppdev::read_control () +{ + return 0; +} + +unsigned char +ppio_ppdev::read_status () +{ + return 0; +} + +void +ppio_ppdev::lock () +{ +} + +void +ppio_ppdev::unlock () +{ +} + +#else + +// The real code... + +ppio_ppdev::ppio_ppdev (int which) +{ + std::ostringstream filename; + filename << "/dev/parport" << which; + const char *c_filename = filename.str().c_str(); + + if ((d_fd = open (c_filename, O_RDWR)) < 0){ + int my_errno = errno; + perror (c_filename); + if (my_errno == ENOENT){ + std::cerr << "Does the device file " << c_filename << " exist?\n"; + std::cerr << "If not, as root execute: \n"; + std::cerr << " # mknod " << c_filename << " c 99 0\n"; + std::cerr << " # chmod 666 " << c_filename << std::endl; + } + throw std::runtime_error ("open"); + } + + int mode = IEEE1284_MODE_COMPAT; + if (ioctl (d_fd, PPSETMODE, &mode) != 0){ + perror ("ppio_ppdev: PPSETMODE"); + close (d_fd); + throw std::runtime_error ("PPSETMODE"); + } +} + +ppio_ppdev::~ppio_ppdev () +{ + close (d_fd); +} + + +void +ppio_ppdev::write_data (unsigned char v) +{ + if (ioctl (d_fd, PPWDATA, &v) != 0){ + perror ("ppio_ppdev: PPWDATA"); + throw std::runtime_error ("PPWDATA"); + } +} + +unsigned char +ppio_ppdev::read_data () +{ + unsigned char v; + + if (ioctl (d_fd, PPRDATA, &v) != 0){ + perror ("ppio_ppdev: PPRDATA"); + throw std::runtime_error ("PPRDATA"); + } + return v; +} + +void +ppio_ppdev::write_control (unsigned char v) +{ + unsigned char ctrl = v ^ CP_ACTIVE_LOW_BITS; + if (ioctl (d_fd, PPWCONTROL, &ctrl) != 0){ + perror ("ppio_ppdev: PPWCONTROL"); + throw std::runtime_error ("PPWCONTROL"); + } +} + +unsigned char +ppio_ppdev::read_control () +{ + unsigned char ctrl; + if (ioctl (d_fd, PPRCONTROL, &ctrl) != 0){ + perror ("ppio_ppdev: PPRCONTROL"); + throw std::runtime_error ("PPRCONTROL"); + } + + return ctrl ^ CP_ACTIVE_LOW_BITS; +} + +unsigned char +ppio_ppdev::read_status () +{ + unsigned char status; + if (ioctl (d_fd, PPRSTATUS, &status) != 0){ + perror ("ppio_ppdev: PPRSTATUS"); + throw std::runtime_error ("PPRSTATUS"); + } + + return status ^ SP_ACTIVE_LOW_BITS; +} + +void +ppio_ppdev::lock () +{ + if (ioctl (d_fd, PPCLAIM) != 0){ + perror ("ppio_ppdev: PPCLAIM"); + throw std::runtime_error ("PPCLAIM"); + } +} + +void +ppio_ppdev::unlock () +{ + if (ioctl (d_fd, PPRELEASE) != 0){ + perror ("ppio_ppdev: PPRELEASE"); + throw std::runtime_error ("PPRELEASE"); + } +} + +#endif + +ppio_ppdev_sptr +make_ppio_ppdev (int which) +{ + return ppio_ppdev_sptr (new ppio_ppdev (which)); +} diff --git a/gnuradio-core/src/lib/io/ppio_ppdev.h b/gnuradio-core/src/lib/io/ppio_ppdev.h new file mode 100644 index 000000000..8ac4a35de --- /dev/null +++ b/gnuradio-core/src/lib/io/ppio_ppdev.h @@ -0,0 +1,60 @@ +/* -*- c++ -*- */ +/* + * Copyright 2001,2003 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. + */ + +#ifndef INCLUDED_PPIO_PPDEV_H +#define INCLUDED_PPIO_PPDEV_H + +#include + +class ppio_ppdev; +typedef boost::shared_ptr ppio_ppdev_sptr; + +/*! + * \brief access to parallel port bits using the linux ppdev interface + */ + +class ppio_ppdev : public ppio { + friend ppio_ppdev_sptr make_ppio_ppdev (int which = 0); + ppio_ppdev (int which = 0); + + public: + virtual ~ppio_ppdev (); + + virtual void write_data (unsigned char v); + virtual unsigned char read_data (); + virtual void write_control (unsigned char v); + virtual unsigned char read_control (); + virtual unsigned char read_status (); + + virtual void lock (); + virtual void unlock (); + + private: + int d_fd; +}; + +ppio_ppdev_sptr +make_ppio_ppdev (int which); + + +#endif /* INCLUDED_PPIO_PPDEV_H */ + diff --git a/gnuradio-core/src/lib/io/sdr_1000.cc b/gnuradio-core/src/lib/io/sdr_1000.cc new file mode 100644 index 000000000..1cb9b9afb --- /dev/null +++ b/gnuradio-core/src/lib/io/sdr_1000.cc @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003 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. + */ + +#include +#include + +sdr_1000_base::sdr_1000_base (int which_pp) +{ + d_ppio = make_ppio (which_pp); + d_shadow[0] = 0; + d_shadow[1] = 0; + d_shadow[2] = 0; + d_shadow[3] = 0; + reset (); +} + +sdr_1000_base::~sdr_1000_base () +{ +} + +void +sdr_1000_base::reset () +{ + d_ppio->lock (); + d_ppio->write_control (0x0F); + d_ppio->unlock (); + write_latch (L_EXT, 0x00, 0xff); + write_latch (L_BAND, 0x00, 0xff); + write_latch (L_DDS0, 0x80, 0xff); // hold DDS in reset + write_latch (L_DDS1, 0x00, 0xff); +} + + +void +sdr_1000_base::write_latch (int which, int value, int mask) +{ + if (!(0 <= which && which <= 3)) + return; + + d_ppio->lock (); + d_shadow[which] = (d_shadow[which] & ~mask) | (value & mask); + d_ppio->write_data (d_shadow[which]); + d_ppio->write_control (0x0F ^ (1 << which)); + d_ppio->write_control (0x0F); + d_ppio->unlock (); +} diff --git a/gnuradio-core/src/lib/io/sdr_1000.h b/gnuradio-core/src/lib/io/sdr_1000.h new file mode 100644 index 000000000..f9ddb35cc --- /dev/null +++ b/gnuradio-core/src/lib/io/sdr_1000.h @@ -0,0 +1,51 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003,2004 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. + */ + +#ifndef INCLUDED_SDR_1000_H +#define INCLUDED_SDR_1000_H + +#include + +class ppio; +typedef boost::shared_ptr ppio_sptr; + + +enum { L_EXT = 0, L_BAND = 1, L_DDS0 = 2, L_DDS1 = 3 }; + +/*! + * \brief Very low level interface to SDR 1000 xcvr hardware + * \sa sdr_1000.py for a higher level interface. + */ +class sdr_1000_base { + ppio_sptr d_ppio; + int d_shadow[4]; // shadow latches + +public: + + sdr_1000_base (int which_pp); + ~sdr_1000_base (); + + void reset (); + void write_latch (int which, int value, int mask); +}; + +#endif /* INCLUDED_SDR_1000_H */ diff --git a/gnuradio-core/src/lib/io/sdr_1000.i b/gnuradio-core/src/lib/io/sdr_1000.i new file mode 100644 index 000000000..46690e0ce --- /dev/null +++ b/gnuradio-core/src/lib/io/sdr_1000.i @@ -0,0 +1,36 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +const int L_EXT = 0; +const int L_BAND = 1; +const int L_DDS0 = 2; +const int L_DDS1 = 3; + +class sdr_1000_base { +public: + + sdr_1000_base (int which_pp); + ~sdr_1000_base (); + + void reset (); + void write_latch (int which, int value, int mask); +}; -- 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 --- gnuradio-core/src/lib/io/Makefile.am | 4 ++-- gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc | 4 ++-- gnuradio-core/src/lib/io/gr_file_descriptor_sink.h | 4 ++-- gnuradio-core/src/lib/io/gr_file_descriptor_sink.i | 4 ++-- gnuradio-core/src/lib/io/gr_file_descriptor_source.cc | 4 ++-- gnuradio-core/src/lib/io/gr_file_descriptor_source.h | 4 ++-- gnuradio-core/src/lib/io/gr_file_descriptor_source.i | 4 ++-- gnuradio-core/src/lib/io/gr_file_sink.cc | 4 ++-- gnuradio-core/src/lib/io/gr_file_sink.h | 4 ++-- gnuradio-core/src/lib/io/gr_file_sink.i | 4 ++-- gnuradio-core/src/lib/io/gr_file_source.cc | 4 ++-- gnuradio-core/src/lib/io/gr_file_source.h | 4 ++-- gnuradio-core/src/lib/io/gr_file_source.i | 4 ++-- gnuradio-core/src/lib/io/gr_message_sink.cc | 4 ++-- gnuradio-core/src/lib/io/gr_message_sink.h | 4 ++-- gnuradio-core/src/lib/io/gr_message_sink.i | 4 ++-- gnuradio-core/src/lib/io/gr_message_source.cc | 4 ++-- gnuradio-core/src/lib/io/gr_message_source.h | 4 ++-- gnuradio-core/src/lib/io/gr_message_source.i | 4 ++-- gnuradio-core/src/lib/io/gr_oscope_guts.cc | 4 ++-- gnuradio-core/src/lib/io/gr_oscope_guts.h | 4 ++-- gnuradio-core/src/lib/io/gr_oscope_sink.i | 4 ++-- gnuradio-core/src/lib/io/gr_oscope_sink_f.cc | 4 ++-- gnuradio-core/src/lib/io/gr_oscope_sink_f.h | 4 ++-- gnuradio-core/src/lib/io/gr_oscope_sink_x.cc | 4 ++-- gnuradio-core/src/lib/io/gr_oscope_sink_x.h | 4 ++-- gnuradio-core/src/lib/io/gr_trigger_mode.h | 4 ++-- gnuradio-core/src/lib/io/gri_logger.cc | 4 ++-- gnuradio-core/src/lib/io/gri_logger.h | 4 ++-- gnuradio-core/src/lib/io/i2c.cc | 4 ++-- gnuradio-core/src/lib/io/i2c.h | 4 ++-- gnuradio-core/src/lib/io/i2c_bbio.cc | 4 ++-- gnuradio-core/src/lib/io/i2c_bbio.h | 4 ++-- gnuradio-core/src/lib/io/i2c_bbio_pp.cc | 4 ++-- gnuradio-core/src/lib/io/i2c_bbio_pp.h | 4 ++-- gnuradio-core/src/lib/io/i2c_bitbang.cc | 4 ++-- gnuradio-core/src/lib/io/i2c_bitbang.h | 4 ++-- gnuradio-core/src/lib/io/io.i | 4 ++-- gnuradio-core/src/lib/io/microtune_4702.cc | 4 ++-- gnuradio-core/src/lib/io/microtune_4702.h | 4 ++-- gnuradio-core/src/lib/io/microtune_4702_eval_board.cc | 4 ++-- gnuradio-core/src/lib/io/microtune_4702_eval_board.h | 4 ++-- gnuradio-core/src/lib/io/microtune_4702_eval_board.i | 4 ++-- gnuradio-core/src/lib/io/microtune_4937.cc | 4 ++-- gnuradio-core/src/lib/io/microtune_4937.h | 4 ++-- gnuradio-core/src/lib/io/microtune_4937_eval_board.cc | 4 ++-- gnuradio-core/src/lib/io/microtune_4937_eval_board.h | 4 ++-- gnuradio-core/src/lib/io/microtune_4937_eval_board.i | 4 ++-- gnuradio-core/src/lib/io/microtune_eval_board.i | 4 ++-- gnuradio-core/src/lib/io/microtune_eval_board_defs.h | 4 ++-- gnuradio-core/src/lib/io/microtune_xxxx.cc | 4 ++-- gnuradio-core/src/lib/io/microtune_xxxx.h | 4 ++-- gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc | 4 ++-- gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h | 4 ++-- gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i | 4 ++-- gnuradio-core/src/lib/io/ppio.cc | 4 ++-- gnuradio-core/src/lib/io/ppio.h | 4 ++-- gnuradio-core/src/lib/io/ppio.i | 4 ++-- gnuradio-core/src/lib/io/ppio_ppdev.cc | 4 ++-- gnuradio-core/src/lib/io/ppio_ppdev.h | 4 ++-- gnuradio-core/src/lib/io/sdr_1000.cc | 4 ++-- gnuradio-core/src/lib/io/sdr_1000.h | 4 ++-- gnuradio-core/src/lib/io/sdr_1000.i | 4 ++-- 63 files changed, 126 insertions(+), 126 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index e390e1344..d935619a1 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -15,8 +15,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. # include $(top_srcdir)/Makefile.common diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc index 6a0b1ca4a..0fa0ee266 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.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 diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h index a811ce705..e680674d8 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h @@ -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. */ #ifndef INCLUDED_GR_FILE_DESCRIPTOR_SINK_H diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.i b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.i index e05818656..547f81f5d 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.i +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.i @@ -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. */ GR_SWIG_BLOCK_MAGIC(gr,file_descriptor_sink) diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc b/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc index 38b9da010..fbd13c8da 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_source.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 diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_source.h b/gnuradio-core/src/lib/io/gr_file_descriptor_source.h index 9f678dcf5..9e1590000 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_source.h +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_source.h @@ -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. */ #ifndef INCLUDED_GR_FILE_DESCRIPTOR_SOURCE_H diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_source.i b/gnuradio-core/src/lib/io/gr_file_descriptor_source.i index ba9b3894f..84f87b0f7 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_source.i +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_source.i @@ -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. */ GR_SWIG_BLOCK_MAGIC(gr,file_descriptor_source) diff --git a/gnuradio-core/src/lib/io/gr_file_sink.cc b/gnuradio-core/src/lib/io/gr_file_sink.cc index d22488bf6..b7cf6c24e 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink.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 diff --git a/gnuradio-core/src/lib/io/gr_file_sink.h b/gnuradio-core/src/lib/io/gr_file_sink.h index 9c11bf72b..c289a150c 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_sink.h @@ -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. */ #ifndef INCLUDED_GR_FILE_SINK_H diff --git a/gnuradio-core/src/lib/io/gr_file_sink.i b/gnuradio-core/src/lib/io/gr_file_sink.i index ffcf02aa6..80f869562 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.i +++ b/gnuradio-core/src/lib/io/gr_file_sink.i @@ -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. */ GR_SWIG_BLOCK_MAGIC(gr,file_sink) diff --git a/gnuradio-core/src/lib/io/gr_file_source.cc b/gnuradio-core/src/lib/io/gr_file_source.cc index 2573a37e0..a38d8f8b6 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_source.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 diff --git a/gnuradio-core/src/lib/io/gr_file_source.h b/gnuradio-core/src/lib/io/gr_file_source.h index 6b635c53b..488798144 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.h +++ b/gnuradio-core/src/lib/io/gr_file_source.h @@ -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. */ #ifndef INCLUDED_GR_FILE_SOURCE_H diff --git a/gnuradio-core/src/lib/io/gr_file_source.i b/gnuradio-core/src/lib/io/gr_file_source.i index 08fdfaf93..85a32361a 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.i +++ b/gnuradio-core/src/lib/io/gr_file_source.i @@ -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. */ diff --git a/gnuradio-core/src/lib/io/gr_message_sink.cc b/gnuradio-core/src/lib/io/gr_message_sink.cc index 8a0784ec4..9c607af1a 100644 --- a/gnuradio-core/src/lib/io/gr_message_sink.cc +++ b/gnuradio-core/src/lib/io/gr_message_sink.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 diff --git a/gnuradio-core/src/lib/io/gr_message_sink.h b/gnuradio-core/src/lib/io/gr_message_sink.h index 8011ab290..eaa52df81 100644 --- a/gnuradio-core/src/lib/io/gr_message_sink.h +++ b/gnuradio-core/src/lib/io/gr_message_sink.h @@ -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. */ #ifndef INCLUDED_GR_MESSAGE_SINK_H diff --git a/gnuradio-core/src/lib/io/gr_message_sink.i b/gnuradio-core/src/lib/io/gr_message_sink.i index ca73479c5..8559c1026 100644 --- a/gnuradio-core/src/lib/io/gr_message_sink.i +++ b/gnuradio-core/src/lib/io/gr_message_sink.i @@ -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. */ GR_SWIG_BLOCK_MAGIC(gr,message_sink); diff --git a/gnuradio-core/src/lib/io/gr_message_source.cc b/gnuradio-core/src/lib/io/gr_message_source.cc index 797433be5..4ce0e4292 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.cc +++ b/gnuradio-core/src/lib/io/gr_message_source.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 diff --git a/gnuradio-core/src/lib/io/gr_message_source.h b/gnuradio-core/src/lib/io/gr_message_source.h index 020601240..735b3d656 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.h +++ b/gnuradio-core/src/lib/io/gr_message_source.h @@ -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. */ #ifndef INCLUDED_GR_MESSAGE_SOURCE_H diff --git a/gnuradio-core/src/lib/io/gr_message_source.i b/gnuradio-core/src/lib/io/gr_message_source.i index 369112eff..961f4d44e 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.i +++ b/gnuradio-core/src/lib/io/gr_message_source.i @@ -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. */ GR_SWIG_BLOCK_MAGIC(gr,message_source); diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.cc b/gnuradio-core/src/lib/io/gr_oscope_guts.cc index 6636fff1c..5a2123fbd 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.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 diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.h b/gnuradio-core/src/lib/io/gr_oscope_guts.h index 4094a6530..0e1d5836f 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.h +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.h @@ -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. */ diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink.i b/gnuradio-core/src/lib/io/gr_oscope_sink.i index ea8419909..114c71f34 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink.i +++ b/gnuradio-core/src/lib/io/gr_oscope_sink.i @@ -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. */ enum gr_trigger_mode { diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc b/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc index b505381da..01c9343b5 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_f.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 diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_f.h b/gnuradio-core/src/lib/io/gr_oscope_sink_f.h index 7b92a7850..b07ac615e 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_f.h +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_f.h @@ -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. */ #ifndef INCLUDED_GR_OSCOPE_SINK_F_H diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_x.cc b/gnuradio-core/src/lib/io/gr_oscope_sink_x.cc index 51c28678e..f10b8c552 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_x.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_x.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 diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_x.h b/gnuradio-core/src/lib/io/gr_oscope_sink_x.h index 45cccc0d4..d58cf5511 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_x.h +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_x.h @@ -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. */ #ifndef INCLUDED_GR_OSCOPE_SINK_X_H diff --git a/gnuradio-core/src/lib/io/gr_trigger_mode.h b/gnuradio-core/src/lib/io/gr_trigger_mode.h index 0928c6a34..dd8030bc2 100644 --- a/gnuradio-core/src/lib/io/gr_trigger_mode.h +++ b/gnuradio-core/src/lib/io/gr_trigger_mode.h @@ -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. */ #ifndef INCLUDED_GR_TRIGGER_MODE_H diff --git a/gnuradio-core/src/lib/io/gri_logger.cc b/gnuradio-core/src/lib/io/gri_logger.cc index a1bdfb0e2..d07793ac5 100644 --- a/gnuradio-core/src/lib/io/gri_logger.cc +++ b/gnuradio-core/src/lib/io/gri_logger.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 diff --git a/gnuradio-core/src/lib/io/gri_logger.h b/gnuradio-core/src/lib/io/gri_logger.h index ecbd3141e..cc36b1a6c 100644 --- a/gnuradio-core/src/lib/io/gri_logger.h +++ b/gnuradio-core/src/lib/io/gri_logger.h @@ -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. */ #ifndef INCLUDED_GRI_LOGGER_H #define INCLUDED_GRI_LOGGER_H diff --git a/gnuradio-core/src/lib/io/i2c.cc b/gnuradio-core/src/lib/io/i2c.cc index 9b9fbcd15..9312b5b74 100644 --- a/gnuradio-core/src/lib/io/i2c.cc +++ b/gnuradio-core/src/lib/io/i2c.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. */ #include "i2c.h" diff --git a/gnuradio-core/src/lib/io/i2c.h b/gnuradio-core/src/lib/io/i2c.h index 88b3c9135..46145455c 100644 --- a/gnuradio-core/src/lib/io/i2c.h +++ b/gnuradio-core/src/lib/io/i2c.h @@ -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. */ #ifndef INCLUDED_I2C_H diff --git a/gnuradio-core/src/lib/io/i2c_bbio.cc b/gnuradio-core/src/lib/io/i2c_bbio.cc index 8f3839768..841ce0d5d 100644 --- a/gnuradio-core/src/lib/io/i2c_bbio.cc +++ b/gnuradio-core/src/lib/io/i2c_bbio.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. */ #include "i2c_bbio.h" diff --git a/gnuradio-core/src/lib/io/i2c_bbio.h b/gnuradio-core/src/lib/io/i2c_bbio.h index f0ea3b664..0fca8cf5b 100644 --- a/gnuradio-core/src/lib/io/i2c_bbio.h +++ b/gnuradio-core/src/lib/io/i2c_bbio.h @@ -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. */ #ifndef INCLUDED_I2C_BBIO_H diff --git a/gnuradio-core/src/lib/io/i2c_bbio_pp.cc b/gnuradio-core/src/lib/io/i2c_bbio_pp.cc index 125f01c33..c817186c2 100644 --- a/gnuradio-core/src/lib/io/i2c_bbio_pp.cc +++ b/gnuradio-core/src/lib/io/i2c_bbio_pp.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. */ #include "i2c_bbio_pp.h" diff --git a/gnuradio-core/src/lib/io/i2c_bbio_pp.h b/gnuradio-core/src/lib/io/i2c_bbio_pp.h index 25af0cf42..d171aa9ea 100644 --- a/gnuradio-core/src/lib/io/i2c_bbio_pp.h +++ b/gnuradio-core/src/lib/io/i2c_bbio_pp.h @@ -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. */ #ifndef INCLUDED_I2C_BBIO_PP_H diff --git a/gnuradio-core/src/lib/io/i2c_bitbang.cc b/gnuradio-core/src/lib/io/i2c_bitbang.cc index 6bf37b604..08fe01f41 100644 --- a/gnuradio-core/src/lib/io/i2c_bitbang.cc +++ b/gnuradio-core/src/lib/io/i2c_bitbang.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. */ #include "i2c_bitbang.h" diff --git a/gnuradio-core/src/lib/io/i2c_bitbang.h b/gnuradio-core/src/lib/io/i2c_bitbang.h index 5196cd234..b87a49f99 100644 --- a/gnuradio-core/src/lib/io/i2c_bitbang.h +++ b/gnuradio-core/src/lib/io/i2c_bitbang.h @@ -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. */ #ifndef INCLUDED_I2C_BITBANG_H diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index ae4ca2682..015e20801 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -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. */ %{ diff --git a/gnuradio-core/src/lib/io/microtune_4702.cc b/gnuradio-core/src/lib/io/microtune_4702.cc index 9b180ff8b..8d14c7780 100644 --- a/gnuradio-core/src/lib/io/microtune_4702.cc +++ b/gnuradio-core/src/lib/io/microtune_4702.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. */ #include "microtune_4702.h" diff --git a/gnuradio-core/src/lib/io/microtune_4702.h b/gnuradio-core/src/lib/io/microtune_4702.h index b5890774f..4656bd8fb 100644 --- a/gnuradio-core/src/lib/io/microtune_4702.h +++ b/gnuradio-core/src/lib/io/microtune_4702.h @@ -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. */ #ifndef INCLUDED_MICROTUNE_4702_H diff --git a/gnuradio-core/src/lib/io/microtune_4702_eval_board.cc b/gnuradio-core/src/lib/io/microtune_4702_eval_board.cc index 88cf2b6a0..f031290b0 100644 --- a/gnuradio-core/src/lib/io/microtune_4702_eval_board.cc +++ b/gnuradio-core/src/lib/io/microtune_4702_eval_board.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. */ #include "microtune_4702_eval_board.h" diff --git a/gnuradio-core/src/lib/io/microtune_4702_eval_board.h b/gnuradio-core/src/lib/io/microtune_4702_eval_board.h index 9fc2914ed..754b32683 100644 --- a/gnuradio-core/src/lib/io/microtune_4702_eval_board.h +++ b/gnuradio-core/src/lib/io/microtune_4702_eval_board.h @@ -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. */ #ifndef INCLUDED_MICROTUNE_4702_EVAL_BOARD_H diff --git a/gnuradio-core/src/lib/io/microtune_4702_eval_board.i b/gnuradio-core/src/lib/io/microtune_4702_eval_board.i index 6205c9303..fe341bfeb 100644 --- a/gnuradio-core/src/lib/io/microtune_4702_eval_board.i +++ b/gnuradio-core/src/lib/io/microtune_4702_eval_board.i @@ -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. */ class microtune_4702_eval_board : public microtune_xxxx_eval_board { diff --git a/gnuradio-core/src/lib/io/microtune_4937.cc b/gnuradio-core/src/lib/io/microtune_4937.cc index c05f63c11..0f1a08de3 100644 --- a/gnuradio-core/src/lib/io/microtune_4937.cc +++ b/gnuradio-core/src/lib/io/microtune_4937.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. */ #include "microtune_4937.h" diff --git a/gnuradio-core/src/lib/io/microtune_4937.h b/gnuradio-core/src/lib/io/microtune_4937.h index 84c8d6112..8294f76fd 100644 --- a/gnuradio-core/src/lib/io/microtune_4937.h +++ b/gnuradio-core/src/lib/io/microtune_4937.h @@ -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. */ #ifndef INCLUDED_MICROTUNE_4937_H diff --git a/gnuradio-core/src/lib/io/microtune_4937_eval_board.cc b/gnuradio-core/src/lib/io/microtune_4937_eval_board.cc index 82a03740c..782b0091e 100644 --- a/gnuradio-core/src/lib/io/microtune_4937_eval_board.cc +++ b/gnuradio-core/src/lib/io/microtune_4937_eval_board.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. */ #include "microtune_4937_eval_board.h" diff --git a/gnuradio-core/src/lib/io/microtune_4937_eval_board.h b/gnuradio-core/src/lib/io/microtune_4937_eval_board.h index 8a8f46b06..a7629859c 100644 --- a/gnuradio-core/src/lib/io/microtune_4937_eval_board.h +++ b/gnuradio-core/src/lib/io/microtune_4937_eval_board.h @@ -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. */ #ifndef INCLUDED_MICROTUNE_4937_EVAL_BOARD_H diff --git a/gnuradio-core/src/lib/io/microtune_4937_eval_board.i b/gnuradio-core/src/lib/io/microtune_4937_eval_board.i index 106832e3d..216561e12 100644 --- a/gnuradio-core/src/lib/io/microtune_4937_eval_board.i +++ b/gnuradio-core/src/lib/io/microtune_4937_eval_board.i @@ -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. */ class microtune_4937_eval_board : public microtune_xxxx_eval_board { diff --git a/gnuradio-core/src/lib/io/microtune_eval_board.i b/gnuradio-core/src/lib/io/microtune_eval_board.i index 7c673e3a5..088c1957d 100644 --- a/gnuradio-core/src/lib/io/microtune_eval_board.i +++ b/gnuradio-core/src/lib/io/microtune_eval_board.i @@ -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. */ /* diff --git a/gnuradio-core/src/lib/io/microtune_eval_board_defs.h b/gnuradio-core/src/lib/io/microtune_eval_board_defs.h index 5245fd5ce..21f836980 100644 --- a/gnuradio-core/src/lib/io/microtune_eval_board_defs.h +++ b/gnuradio-core/src/lib/io/microtune_eval_board_defs.h @@ -24,8 +24,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. */ #ifndef _MICROTUNE_EVAL_BOARD_DEFS_H_ diff --git a/gnuradio-core/src/lib/io/microtune_xxxx.cc b/gnuradio-core/src/lib/io/microtune_xxxx.cc index 8633b111b..ad714735e 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx.cc +++ b/gnuradio-core/src/lib/io/microtune_xxxx.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. */ #include "microtune_xxxx.h" diff --git a/gnuradio-core/src/lib/io/microtune_xxxx.h b/gnuradio-core/src/lib/io/microtune_xxxx.h index 8fac06d8f..36d5be323 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx.h +++ b/gnuradio-core/src/lib/io/microtune_xxxx.h @@ -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. */ #ifndef INCLUDED_MICROTUNE_XXXX_H diff --git a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc index a7ea98d6f..0530ff121 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc +++ b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.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. */ #include "microtune_xxxx_eval_board.h" diff --git a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h index 3a817b698..80c47aa8a 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h +++ b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h @@ -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. */ #ifndef INCLUDED_MICROTUNE_XXXX_EVAL_BOARD_H diff --git a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i index 2e43f27aa..d9bf17a70 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i +++ b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i @@ -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. */ class microtune_xxxx_eval_board { diff --git a/gnuradio-core/src/lib/io/ppio.cc b/gnuradio-core/src/lib/io/ppio.cc index 86f402bbf..a608b58cf 100644 --- a/gnuradio-core/src/lib/io/ppio.cc +++ b/gnuradio-core/src/lib/io/ppio.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. */ #include diff --git a/gnuradio-core/src/lib/io/ppio.h b/gnuradio-core/src/lib/io/ppio.h index 418138705..ba2301e38 100644 --- a/gnuradio-core/src/lib/io/ppio.h +++ b/gnuradio-core/src/lib/io/ppio.h @@ -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. */ #ifndef INCLUDED_PPIO_H diff --git a/gnuradio-core/src/lib/io/ppio.i b/gnuradio-core/src/lib/io/ppio.i index 2eaddc204..e9ac7542a 100644 --- a/gnuradio-core/src/lib/io/ppio.i +++ b/gnuradio-core/src/lib/io/ppio.i @@ -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. */ class ppio; diff --git a/gnuradio-core/src/lib/io/ppio_ppdev.cc b/gnuradio-core/src/lib/io/ppio_ppdev.cc index bfdaa3de0..27a8e3352 100644 --- a/gnuradio-core/src/lib/io/ppio_ppdev.cc +++ b/gnuradio-core/src/lib/io/ppio_ppdev.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 diff --git a/gnuradio-core/src/lib/io/ppio_ppdev.h b/gnuradio-core/src/lib/io/ppio_ppdev.h index 8ac4a35de..abf27e3cc 100644 --- a/gnuradio-core/src/lib/io/ppio_ppdev.h +++ b/gnuradio-core/src/lib/io/ppio_ppdev.h @@ -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. */ #ifndef INCLUDED_PPIO_PPDEV_H diff --git a/gnuradio-core/src/lib/io/sdr_1000.cc b/gnuradio-core/src/lib/io/sdr_1000.cc index 1cb9b9afb..1687a75ee 100644 --- a/gnuradio-core/src/lib/io/sdr_1000.cc +++ b/gnuradio-core/src/lib/io/sdr_1000.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. */ #include diff --git a/gnuradio-core/src/lib/io/sdr_1000.h b/gnuradio-core/src/lib/io/sdr_1000.h index f9ddb35cc..f55b68912 100644 --- a/gnuradio-core/src/lib/io/sdr_1000.h +++ b/gnuradio-core/src/lib/io/sdr_1000.h @@ -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. */ #ifndef INCLUDED_SDR_1000_H diff --git a/gnuradio-core/src/lib/io/sdr_1000.i b/gnuradio-core/src/lib/io/sdr_1000.i index 46690e0ce..b19c6a3e8 100644 --- a/gnuradio-core/src/lib/io/sdr_1000.i +++ b/gnuradio-core/src/lib/io/sdr_1000.i @@ -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. */ const int L_EXT = 0; -- cgit From 800c7af01e745900c0b12474c9b9ef5090f9d25a Mon Sep 17 00:00:00 2001 From: jcorgan Date: Tue, 19 Sep 2006 00:59:01 +0000 Subject: Really fix ticket:68. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3573 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/gr_oscope_guts.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.cc b/gnuradio-core/src/lib/io/gr_oscope_guts.cc index 5a2123fbd..2a152b95a 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.cc @@ -54,7 +54,7 @@ decr_bi (int buffer_index) // decrement buffer index gr_oscope_guts::gr_oscope_guts (int nchannels, double sample_rate, gr_msg_queue_sptr msgq) : d_nchannels (nchannels), d_msgq (msgq), - d_trigger_mode (gr_TRIG_POS_SLOPE), + d_trigger_mode (gr_TRIG_AUTO), d_trigger_channel (0), d_sample_rate (sample_rate), d_update_rate (20), -- cgit From 81d3ab82071b3c24f1e750f5f33753436b58fc2d Mon Sep 17 00:00:00 2001 From: eb Date: Tue, 19 Dec 2006 19:45:52 +0000 Subject: Fix for ticket:104, huge initial value plotted. Problem was due to uninitialized internal buffer, combined with incorrect initial state. Thanks for the patch, Don. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4149 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/gr_oscope_guts.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.cc b/gnuradio-core/src/lib/io/gr_oscope_guts.cc index 2a152b95a..83b523254 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.cc @@ -60,11 +60,11 @@ gr_oscope_guts::gr_oscope_guts (int nchannels, double sample_rate, gr_msg_queue_ d_update_rate (20), d_trigger_level (0), d_obi (0), - d_state (LOOK_FOR_TRIGGER), + d_state (HOLD_OFF), d_decimator_count (0), d_decimator_count_init (1), d_hold_off_count (0), - d_hold_off_count_init (0), + d_hold_off_count_init (OUTPUT_RECORD_SIZE/2), d_post_trigger_count (0), d_post_trigger_count_init (OUTPUT_RECORD_SIZE/2), d_prev_sample (0) @@ -77,11 +77,14 @@ gr_oscope_guts::gr_oscope_guts (int nchannels, double sample_rate, gr_msg_queue_ for (int i = 0; i < MAX_CHANNELS; i++) d_buffer[i] = 0; - for (int i = 0; i < d_nchannels; i++) + for (int i = 0; i < d_nchannels; i++){ d_buffer[i] = new float [OUTPUT_RECORD_SIZE]; + for (int j = 0; j < OUTPUT_RECORD_SIZE; j++) + d_buffer[i][j] = 0.0; + } + enter_hold_off (); update_rate_or_decimation_changed (); - enter_look_for_trigger (); } gr_oscope_guts::~gr_oscope_guts () -- cgit From 0fea2400127392cbb313627720468211ba759577 Mon Sep 17 00:00:00 2001 From: eb Date: Tue, 19 Dec 2006 20:11:38 +0000 Subject: backed out partial fix for ticket:104 git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4150 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/gr_oscope_guts.cc | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.cc b/gnuradio-core/src/lib/io/gr_oscope_guts.cc index 83b523254..2a152b95a 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.cc @@ -60,11 +60,11 @@ gr_oscope_guts::gr_oscope_guts (int nchannels, double sample_rate, gr_msg_queue_ d_update_rate (20), d_trigger_level (0), d_obi (0), - d_state (HOLD_OFF), + d_state (LOOK_FOR_TRIGGER), d_decimator_count (0), d_decimator_count_init (1), d_hold_off_count (0), - d_hold_off_count_init (OUTPUT_RECORD_SIZE/2), + d_hold_off_count_init (0), d_post_trigger_count (0), d_post_trigger_count_init (OUTPUT_RECORD_SIZE/2), d_prev_sample (0) @@ -77,14 +77,11 @@ gr_oscope_guts::gr_oscope_guts (int nchannels, double sample_rate, gr_msg_queue_ for (int i = 0; i < MAX_CHANNELS; i++) d_buffer[i] = 0; - for (int i = 0; i < d_nchannels; i++){ + for (int i = 0; i < d_nchannels; i++) d_buffer[i] = new float [OUTPUT_RECORD_SIZE]; - for (int j = 0; j < OUTPUT_RECORD_SIZE; j++) - d_buffer[i][j] = 0.0; - } - enter_hold_off (); update_rate_or_decimation_changed (); + enter_look_for_trigger (); } gr_oscope_guts::~gr_oscope_guts () -- cgit From f7400ffb7619ad96e5d23830408179093818568f Mon Sep 17 00:00:00 2001 From: eb Date: Tue, 19 Dec 2006 20:22:25 +0000 Subject: ''Real'' fix for ticket:104. I should have just applied it all the first time around ;) Thanks Don for the patch. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4151 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/gr_oscope_guts.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.cc b/gnuradio-core/src/lib/io/gr_oscope_guts.cc index 2a152b95a..286a7d1fb 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.cc @@ -60,11 +60,11 @@ gr_oscope_guts::gr_oscope_guts (int nchannels, double sample_rate, gr_msg_queue_ d_update_rate (20), d_trigger_level (0), d_obi (0), - d_state (LOOK_FOR_TRIGGER), + d_state (HOLD_OFF), d_decimator_count (0), d_decimator_count_init (1), d_hold_off_count (0), - d_hold_off_count_init (0), + d_hold_off_count_init (OUTPUT_RECORD_SIZE/2-1), d_post_trigger_count (0), d_post_trigger_count_init (OUTPUT_RECORD_SIZE/2), d_prev_sample (0) @@ -77,11 +77,15 @@ gr_oscope_guts::gr_oscope_guts (int nchannels, double sample_rate, gr_msg_queue_ for (int i = 0; i < MAX_CHANNELS; i++) d_buffer[i] = 0; - for (int i = 0; i < d_nchannels; i++) + for (int i = 0; i < d_nchannels; i++){ d_buffer[i] = new float [OUTPUT_RECORD_SIZE]; + for (int j = 0; j < OUTPUT_RECORD_SIZE; j++) + d_buffer[i][j] = 0.0; + } + // be sure buffer is full before first write + enter_hold_off (); update_rate_or_decimation_changed (); - enter_look_for_trigger (); } gr_oscope_guts::~gr_oscope_guts () @@ -228,9 +232,9 @@ gr_oscope_guts::write_output_records () float *out = (float *)msg->msg(); // get pointer to raw message buffer for (int ch = 0; ch < d_nchannels; ch++){ - // note that d_obi points at the oldest sample in the buffer + // note that d_obi + 1 points at the oldest sample in the buffer for (int i = 0; i < OUTPUT_RECORD_SIZE; i++) - out[i] = d_buffer[ch][wrap_bi(d_obi + i)]; + out[i] = d_buffer[ch][wrap_bi(d_obi + 1 + i)]; out += OUTPUT_RECORD_SIZE; } -- cgit From 3bb7b864dd0be5d9c55d5c1be5024bcc823f60ff Mon Sep 17 00:00:00 2001 From: trondeau Date: Fri, 26 Jan 2007 19:24:06 +0000 Subject: merged changeset r4281:4292 on trondeau/ethernet into trunk git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4293 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/Makefile.am | 8 +- gnuradio-core/src/lib/io/gr_udp_sink.cc | 157 +++++++++++++++++++++++++++++ gnuradio-core/src/lib/io/gr_udp_sink.h | 103 +++++++++++++++++++ gnuradio-core/src/lib/io/gr_udp_sink.i | 47 +++++++++ gnuradio-core/src/lib/io/gr_udp_source.cc | 160 ++++++++++++++++++++++++++++++ gnuradio-core/src/lib/io/gr_udp_source.h | 92 +++++++++++++++++ gnuradio-core/src/lib/io/gr_udp_source.i | 43 ++++++++ gnuradio-core/src/lib/io/io.i | 4 + 8 files changed, 612 insertions(+), 2 deletions(-) create mode 100644 gnuradio-core/src/lib/io/gr_udp_sink.cc create mode 100644 gnuradio-core/src/lib/io/gr_udp_sink.h create mode 100644 gnuradio-core/src/lib/io/gr_udp_sink.i create mode 100644 gnuradio-core/src/lib/io/gr_udp_source.cc create mode 100644 gnuradio-core/src/lib/io/gr_udp_source.h create mode 100644 gnuradio-core/src/lib/io/gr_udp_source.i (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index d935619a1..6891f3807 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -50,7 +50,9 @@ libio_la_SOURCES = \ microtune_xxxx_eval_board.cc \ ppio.cc \ ppio_ppdev.cc \ - sdr_1000.cc + sdr_1000.cc \ + gr_udp_sink.cc \ + gr_udp_source.cc grinclude_HEADERS = \ gr_file_sink.h \ @@ -93,4 +95,6 @@ swiginclude_HEADERS = \ microtune_4702_eval_board.i \ microtune_4937_eval_board.i \ ppio.i \ - sdr_1000.i + sdr_1000.i \ + gr_udp_sink.i \ + gr_udp_source.i diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc new file mode 100644 index 000000000..f5eefdc73 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -0,0 +1,157 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include + +#define SNK_VERBOSE 0 + +gr_udp_sink::gr_udp_sink (size_t itemsize, + const char *ipaddrl, unsigned short portl, + const char *ipaddrr, unsigned short portr, + unsigned int mtu) + : gr_sync_block ("udp_sink", + gr_make_io_signature (1, 1, itemsize), + gr_make_io_signature (0, 0, 0)), + d_itemsize (itemsize), d_updated(false), d_mtu(mtu) +{ + // Set up the address stucture for the local address and port numbers + inet_aton(ipaddrl, &d_ipaddr_local); // format IP address + inet_aton(ipaddrr, &d_ipaddr_remote); // format IP address + d_port_local = htons(portl); // format port number + d_port_remote = htons(portr); // format port number + + d_sockaddr_local.sin_family = AF_INET; + d_sockaddr_local.sin_addr = d_ipaddr_local; + d_sockaddr_local.sin_port = d_port_local; + + d_sockaddr_remote.sin_family = AF_INET; + d_sockaddr_remote.sin_addr = d_ipaddr_remote; + d_sockaddr_remote.sin_port = d_port_remote; + + open(); +} + +// public constructor that returns a shared_ptr + +gr_udp_sink_sptr +gr_make_udp_sink (size_t itemsize, + const char *ipaddrl, unsigned short portl, + const char *ipaddrr, unsigned short portr, + unsigned int mtu) +{ + return gr_udp_sink_sptr (new gr_udp_sink (itemsize, + ipaddrl, portl, + ipaddrr, portr, + mtu)); +} + +gr_udp_sink::~gr_udp_sink () +{ + close(); +} + +bool +gr_udp_sink::open() +{ + omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + + // create socket + if((d_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == NULL) { + perror("socket open"); + throw std::runtime_error("can't open socket"); + } + + // Turn on reuse address + bool opt_val = true; + if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(int))) { + perror("SO_REUSEADDR"); + throw std::runtime_error("can't set socket option SO_REUSEADDR"); + } + + // Don't wait when shutting down + linger lngr; + lngr.l_onoff = 1; + lngr.l_linger = 0; + if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (void*)&lngr, sizeof(linger))) { + perror("SO_LINGER"); + throw std::runtime_error("can't set socket option SO_LINGER"); + } + + // bind socket to an address and port number to listen on + if(bind (d_socket, (sockaddr*)&d_sockaddr_local, sizeof(struct sockaddr))) { + perror("socket bind"); + throw std::runtime_error("can't bind socket"); + } + + // Not sure if we should throw here or allow retries + if(connect(d_socket, (sockaddr*)&d_sockaddr_remote, sizeof(struct sockaddr))) { + perror("socket connect"); + throw std::runtime_error("can't connect to socket"); + } + + d_updated = true; + return d_socket != 0; +} + +void +gr_udp_sink::close() +{ + omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + + if (d_socket){ + shutdown(d_socket, SHUT_RDWR); + d_socket = 0; + } + d_updated = true; +} + +int +gr_udp_sink::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + char *in = (char *) input_items[0]; + socklen_t bytes=0, bytes_sent=0, bytes_to_send=0; + unsigned int total_size = noutput_items*d_itemsize; + + while(bytes_sent < total_size) { + bytes_to_send = (bytes_sent+d_mtu < total_size ? d_mtu : total_size-bytes_sent); + bytes =send(d_socket, (in+bytes_sent), bytes_to_send, MSG_DONTWAIT); + bytes_sent += bytes; + } + + #if SNK_VERBOSE + printf("Sent: %d bytes (noutput_items: %d)\n", bytes_sent, noutput_items); + #endif + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.h b/gnuradio-core/src/lib/io/gr_udp_sink.h new file mode 100644 index 000000000..f3ededa52 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_udp_sink.h @@ -0,0 +1,103 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_UDP_SINK_H +#define INCLUDED_GR_UDP_SINK_H + +#include +#include +#include +#include + +class gr_udp_sink; +typedef boost::shared_ptr gr_udp_sink_sptr; + +/*! + * \brief Write stream to an Udp port (over UDP). + * \ingroup sink + */ + +gr_udp_sink_sptr +gr_make_udp_sink (size_t itemsize, + const char *ipaddrl, unsigned short portl, + const char *ipaddrr, unsigned short portr, + unsigned int mtu=540); + +class gr_udp_sink : public gr_sync_block +{ + friend gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize, + const char *ipaddrl, unsigned short portl, + const char *ipaddrr, unsigned short portr, + unsigned int mtu); + private: + size_t d_itemsize; + bool d_updated; + omni_mutex d_mutex; + + unsigned int d_mtu; // maximum transmission unit (packet length) + int d_socket; // handle to socket + int d_socket_rcv; // handle to socket retuned in the accept call + struct in_addr d_ipaddr_local; // store the local IP address to use + struct in_addr d_ipaddr_remote; // store the remote IP address that connected to us + unsigned short d_port_local; // the port number to open for connections to this service + unsigned short d_port_remote; // port number of the remove system + sockaddr_in d_sockaddr_local; // store the local sockaddr data (formatted IP address and port number) + sockaddr_in d_sockaddr_remote; // store the remote sockaddr data (formatted IP address and port number) + + protected: + gr_udp_sink (size_t itemsize, + const char *ipaddrl, unsigned short portl, + const char *ipaddrr, unsigned short portr, + unsigned int mtu); + + public: + ~gr_udp_sink (); + + /*! + * \brief open a socket specified by the port and ip address info + * + * Opens a socket, binds to the address, and makes connectionless association + * over UDP. If any of these fail, the fuction retuns the error and exits. + */ + bool open(); + + /*! + * \brief Close current socket. + * + * Shuts down read/write on the socket + */ + void close(); + + /*! \brief set the MTU of the socket */ + void set_mtu(unsigned int mtu) { d_mtu = mtu; } + + /*! \brief return the MTU of the socket */ + unsigned int mtu() { return d_mtu; } + + // should we export anything else? + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_GR_UDP_SINK_H */ diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.i b/gnuradio-core/src/lib/io/gr_udp_sink.i new file mode 100644 index 000000000..59c828dd6 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_udp_sink.i @@ -0,0 +1,47 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + + +GR_SWIG_BLOCK_MAGIC(gr,udp_sink) + +gr_udp_sink_sptr +gr_make_udp_sink (size_t itemsize, + const char *ipaddrl, unsigned short portl, + const char *ipaddrr, unsigned short portr, + unsigned int mtu=540); + +class gr_udp_sink : public gr_sync_block +{ + protected: + gr_udp_sink (size_t itemsize, + const char *ipaddrl, unsigned short portl, + const char *ipaddrr, unsigned short portr, + unsigned int mtu); + + bool open(); + void close(); + void set_mtu(unsigned int mtu) { d_mtu = mtu; } + unsigned int mtu() { return d_mtu; } + + public: + ~gr_udp_sink (); +}; diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc new file mode 100644 index 000000000..426830924 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -0,0 +1,160 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2006 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include + +#define SRC_VERBOSE 0 + +gr_udp_source::gr_udp_source(size_t itemsize, const char *ipaddr, + unsigned short port, unsigned int mtu) + : gr_sync_block ("udp_source", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(1, 1, itemsize)), + d_itemsize(itemsize), d_updated(false), d_mtu(mtu) +{ + // Set up the address stucture for the local address and port numbers + inet_aton(ipaddr, &d_ipaddr_local); // format IP address + d_port_local = htons(port); // format port number + + d_sockaddr_local.sin_family = AF_INET; + d_sockaddr_local.sin_addr = d_ipaddr_local; + d_sockaddr_local.sin_port = d_port_local; + + open(); +} + +gr_udp_source_sptr +gr_make_udp_source (size_t itemsize, const char *ipaddr, + unsigned short port, unsigned int mtu) +{ + return gr_udp_source_sptr (new gr_udp_source (itemsize, ipaddr, + port, mtu)); +} + +gr_udp_source::~gr_udp_source () +{ + close(); +} + +bool +gr_udp_source::open() +{ + omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + + // create socket + d_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if(d_socket == 0) { + perror("socket open"); + throw std::runtime_error("can't open socket"); + } + + // Turn on reuse address + bool opt_val = true; + if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(int))) { + perror("SO_REUSEADDR"); + throw std::runtime_error("can't set socket option SO_REUSEADDR"); + } + + // Don't wait when shutting down + linger lngr; + lngr.l_onoff = 1; + lngr.l_linger = 0; + if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (void*)&lngr, sizeof(linger))) { + perror("SO_LINGER"); + throw std::runtime_error("can't set socket option SO_LINGER"); + } + + // Set a timeout on the receive function to not block indefinitely + // This value can (and probably should) be changed + timeval timeout; + timeout.tv_sec = 1; + timeout.tv_usec = 0; + if(setsockopt(d_socket, SOL_SOCKET, SO_RCVTIMEO, (void*)&timeout, sizeof(timeout))) { + perror("SO_RCVTIMEO"); + throw std::runtime_error("can't set socket option SO_RCVTIMEO"); + } + + // bind socket to an address and port number to listen on + if(bind (d_socket, (sockaddr*)&d_sockaddr_local, sizeof(struct sockaddr))) { + perror("socket bind"); + throw std::runtime_error("can't bind socket"); + } + + d_updated = true; + return d_socket != 0; +} + +void +gr_udp_source::close() +{ + omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + + if (d_socket){ + shutdown(d_socket, SHUT_RDWR); + d_socket = 0; + } + d_updated = true; +} + +int +gr_udp_source::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + char *out = (char *) output_items[0]; + socklen_t bytes_to_receive=0, bytes_received=0; + int bytes=0; + + while((bytes_received < (unsigned)noutput_items) && (bytes>-1)) { + // caclulate the number of byte left if we can fit in all d_mtu bytes + bytes_to_receive = (bytes_received+d_mtu < noutput_items ? + d_mtu : noutput_items-bytes_received); + + // get the data into our output buffer and record the number of bytes + // This is a blocking call, but it's timeout has been set in the constructor + bytes = recv(d_socket, out, bytes_to_receive, 0); + + if(bytes > 0) { + // keep track of the total number of bytes received + bytes_received += bytes; + + // increment the pointer + out += bytes; + } + } + + #if SRC_VERBOSE + printf("\nTotal Bytes Received: %d (noutput_items=%d)\n", bytes_received, noutput_items); + #endif + + return int(bytes_received / d_itemsize); +} diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h new file mode 100644 index 000000000..162eef7d6 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_udp_source.h @@ -0,0 +1,92 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_UDP_SOURCE_H +#define INCLUDED_GR_UDP_SOURCE_H + +#include +#include +#include +#include + +class gr_udp_source; +typedef boost::shared_ptr gr_udp_source_sptr; + +gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *ipaddr, + unsigned short port, unsigned int mtu=540); + +class gr_udp_source : public gr_sync_block +{ + friend gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *ipaddr, + unsigned short port, unsigned int mtu); + + private: + size_t d_itemsize; + bool d_updated; + omni_mutex d_mutex; + + unsigned int d_mtu; // maximum transmission unit (packet length) + int d_socket; // handle to socket + int d_socket_rcv; // handle to socket retuned in the accept call + struct in_addr d_ipaddr_local; // store the local IP address to use + struct in_addr d_ipaddr_remote; // store the remote IP address that connected to us + unsigned short d_port_local; // the port number to open for connections to this service + unsigned short d_port_remote; // port number of the remove system + sockaddr_in d_sockaddr_local; // store the local sockaddr data (formatted IP address and port number) + sockaddr_in d_sockaddr_remote; // store the remote sockaddr data (formatted IP address and port number) + + protected: + gr_udp_source(size_t itemsize, const char *ipaddr, unsigned short port, unsigned int mtu); + + public: + ~gr_udp_source(); + + /*! + * \brief open a socket specified by the port and ip address info + * + * Opens a socket, binds to the address, and waits for a connection + * over UDP. If any of these fail, the fuction retuns the error and exits. + */ + bool open(); + + /*! + * \brief Close current socket. + * + * Shuts down read/write on the socket + */ + void close(); + + /*! \brief set the MTU of the socket */ + void set_mtu(unsigned int mtu) { d_mtu = mtu; } + + /*! \brief return the MTU of the socket */ + unsigned int mtu() { return d_mtu; } + + // should we export anything else? + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + + +#endif /* INCLUDED_GR_UDP_SOURCE_H */ diff --git a/gnuradio-core/src/lib/io/gr_udp_source.i b/gnuradio-core/src/lib/io/gr_udp_source.i new file mode 100644 index 000000000..e1e9c2023 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_udp_source.i @@ -0,0 +1,43 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,udp_source) + +gr_udp_source_sptr +gr_make_udp_source (size_t itemsize, const char *ipaddr, + unsigned short port, unsigned int mtu=540); + +class gr_udp_source : public gr_sync_block +{ + protected: + gr_udp_source (size_t itemsize, const char *ipaddr, + unsigned short port, unsigned int mtu); + + public: + ~gr_udp_source (); + + bool open(); + void close(); + void set_mtu(unsigned int mtu) { d_mtu = mtu; } + unsigned int mtu() { return d_mtu; } + +}; diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index 015e20801..e6ed4c6a1 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -34,6 +34,8 @@ #include #include #include +#include +#include %} @@ -49,4 +51,6 @@ %include "ppio.i" %include "gr_message_source.i" %include "gr_message_sink.i" +%include "gr_udp_sink.i" +%include "gr_udp_source.i" -- cgit From d52c8fc348f5667e2ca7e074844d91af53ae96d4 Mon Sep 17 00:00:00 2001 From: trondeau Date: Fri, 26 Jan 2007 20:02:22 +0000 Subject: updated copyright info, and snuck a little something else in (you didn't see anything...) git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4294 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/Makefile.am | 6 ++++-- gnuradio-core/src/lib/io/gr_udp_sink.cc | 2 +- gnuradio-core/src/lib/io/gr_udp_sink.h | 2 +- gnuradio-core/src/lib/io/gr_udp_sink.i | 2 +- gnuradio-core/src/lib/io/gr_udp_source.cc | 2 +- gnuradio-core/src/lib/io/gr_udp_source.h | 2 +- gnuradio-core/src/lib/io/gr_udp_source.i | 2 +- 7 files changed, 10 insertions(+), 8 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index 6891f3807..8320375c7 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2001,2003,2004 Free Software Foundation, Inc. +# Copyright 2001,2003,2004,2006 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -79,7 +79,9 @@ grinclude_HEADERS = \ microtune_xxxx_eval_board.h \ ppio.h \ ppio_ppdev.h \ - sdr_1000.h + sdr_1000.h \ + gr_udp_sink.h \ + gr_udp_source.h swiginclude_HEADERS = \ diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index f5eefdc73..a664615f1 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2006 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.h b/gnuradio-core/src/lib/io/gr_udp_sink.h index f3ededa52..ee346f40c 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.h +++ b/gnuradio-core/src/lib/io/gr_udp_sink.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2006 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.i b/gnuradio-core/src/lib/io/gr_udp_sink.i index 59c828dd6..bd4accb3e 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.i +++ b/gnuradio-core/src/lib/io/gr_udp_sink.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2006 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index 426830924..70b2f8f98 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2006 Free Software Foundation, Inc. + * Copyright 2006 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h index 162eef7d6..c57f4fc8f 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.h +++ b/gnuradio-core/src/lib/io/gr_udp_source.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2006 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/io/gr_udp_source.i b/gnuradio-core/src/lib/io/gr_udp_source.i index e1e9c2023..1d6f4c904 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.i +++ b/gnuradio-core/src/lib/io/gr_udp_source.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2006 Free Software Foundation, Inc. * * This file is part of GNU Radio * -- cgit From 2d452df22ba3225a5560b5044f30f09c96a95342 Mon Sep 17 00:00:00 2001 From: eb Date: Sat, 27 Jan 2007 18:21:55 +0000 Subject: fixed error handling and warning git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4297 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/gr_udp_sink.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index a664615f1..43d0dd664 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -85,14 +85,14 @@ gr_udp_sink::open() omni_mutex_lock l(d_mutex); // hold mutex for duration of this function // create socket - if((d_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == NULL) { + if((d_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { perror("socket open"); throw std::runtime_error("can't open socket"); } // Turn on reuse address bool opt_val = true; - if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(int))) { + if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(int)) == -1) { perror("SO_REUSEADDR"); throw std::runtime_error("can't set socket option SO_REUSEADDR"); } @@ -101,19 +101,19 @@ gr_udp_sink::open() linger lngr; lngr.l_onoff = 1; lngr.l_linger = 0; - if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (void*)&lngr, sizeof(linger))) { + if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (void*)&lngr, sizeof(linger)) == -1) { perror("SO_LINGER"); throw std::runtime_error("can't set socket option SO_LINGER"); } // bind socket to an address and port number to listen on - if(bind (d_socket, (sockaddr*)&d_sockaddr_local, sizeof(struct sockaddr))) { + if(bind (d_socket, (sockaddr*)&d_sockaddr_local, sizeof(struct sockaddr)) == -1) { perror("socket bind"); throw std::runtime_error("can't bind socket"); } // Not sure if we should throw here or allow retries - if(connect(d_socket, (sockaddr*)&d_sockaddr_remote, sizeof(struct sockaddr))) { + if(connect(d_socket, (sockaddr*)&d_sockaddr_remote, sizeof(struct sockaddr)) == -1) { perror("socket connect"); throw std::runtime_error("can't connect to socket"); } @@ -145,7 +145,7 @@ gr_udp_sink::work (int noutput_items, while(bytes_sent < total_size) { bytes_to_send = (bytes_sent+d_mtu < total_size ? d_mtu : total_size-bytes_sent); - bytes =send(d_socket, (in+bytes_sent), bytes_to_send, MSG_DONTWAIT); + bytes = send(d_socket, (in+bytes_sent), bytes_to_send, MSG_DONTWAIT); bytes_sent += bytes; } -- cgit From f8af5803ca8b87aa6c5f8c97d5abbabe2b837619 Mon Sep 17 00:00:00 2001 From: eb Date: Sat, 27 Jan 2007 18:39:31 +0000 Subject: cleaned up error checking git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4298 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/gr_udp_source.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index 70b2f8f98..e2def4c37 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -72,14 +72,14 @@ gr_udp_source::open() // create socket d_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if(d_socket == 0) { + if(d_socket == -1) { perror("socket open"); throw std::runtime_error("can't open socket"); } // Turn on reuse address bool opt_val = true; - if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(int))) { + if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(int)) == -1) { perror("SO_REUSEADDR"); throw std::runtime_error("can't set socket option SO_REUSEADDR"); } @@ -88,7 +88,7 @@ gr_udp_source::open() linger lngr; lngr.l_onoff = 1; lngr.l_linger = 0; - if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (void*)&lngr, sizeof(linger))) { + if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (void*)&lngr, sizeof(linger)) == -1) { perror("SO_LINGER"); throw std::runtime_error("can't set socket option SO_LINGER"); } @@ -98,13 +98,13 @@ gr_udp_source::open() timeval timeout; timeout.tv_sec = 1; timeout.tv_usec = 0; - if(setsockopt(d_socket, SOL_SOCKET, SO_RCVTIMEO, (void*)&timeout, sizeof(timeout))) { + if(setsockopt(d_socket, SOL_SOCKET, SO_RCVTIMEO, (void*)&timeout, sizeof(timeout)) == -1) { perror("SO_RCVTIMEO"); throw std::runtime_error("can't set socket option SO_RCVTIMEO"); } // bind socket to an address and port number to listen on - if(bind (d_socket, (sockaddr*)&d_sockaddr_local, sizeof(struct sockaddr))) { + if(bind (d_socket, (sockaddr*)&d_sockaddr_local, sizeof(struct sockaddr)) == -1) { perror("socket bind"); throw std::runtime_error("can't bind socket"); } @@ -143,6 +143,8 @@ gr_udp_source::work (int noutput_items, // This is a blocking call, but it's timeout has been set in the constructor bytes = recv(d_socket, out, bytes_to_receive, 0); + // FIXME if bytes < 0 bail + if(bytes > 0) { // keep track of the total number of bytes received bytes_received += bytes; @@ -156,5 +158,6 @@ gr_udp_source::work (int noutput_items, printf("\nTotal Bytes Received: %d (noutput_items=%d)\n", bytes_received, noutput_items); #endif + // FIXME what if (bytes_received % d_itemsize) != 0 ??? return int(bytes_received / d_itemsize); } -- cgit From 4d84dd43e1dd5056a49b6c8d4caa638ece7a6cff Mon Sep 17 00:00:00 2001 From: eb Date: Tue, 30 Jan 2007 03:59:34 +0000 Subject: Fixes ticket:134. Unlikely offender was inclusion of gr_udp_sink/source code io.i. omnithread.h was also including which is a no-no. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4333 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/io.i | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index e6ed4c6a1..7baf94ef0 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -34,8 +34,8 @@ #include #include #include -#include -#include +#include +#include %} -- cgit From 3e7f3d33cfbd4f64a90aa43c8e8505213362faee Mon Sep 17 00:00:00 2001 From: trondeau Date: Fri, 9 Feb 2007 22:49:09 +0000 Subject: merging r4318:4437 to fix ticket:131 from branche trondeau/udp udp source/sink pairs working git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4438 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/gr_udp_sink.cc | 116 ++++++++++++++++--------- gnuradio-core/src/lib/io/gr_udp_sink.h | 72 +++++++++------ gnuradio-core/src/lib/io/gr_udp_sink.i | 17 ++-- gnuradio-core/src/lib/io/gr_udp_source.cc | 140 +++++++++++++++++++++--------- gnuradio-core/src/lib/io/gr_udp_source.h | 59 +++++++++---- gnuradio-core/src/lib/io/gr_udp_source.i | 13 ++- 6 files changed, 274 insertions(+), 143 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index 43d0dd664..d799262b4 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -20,42 +20,59 @@ * Boston, MA 02110-1301, USA. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include #include -#include -#include -#include -#include #include +#include #define SNK_VERBOSE 0 gr_udp_sink::gr_udp_sink (size_t itemsize, - const char *ipaddrl, unsigned short portl, - const char *ipaddrr, unsigned short portr, - unsigned int mtu) + const char *src, unsigned short port_src, + const char *dst, unsigned short port_dst, + int payload_size) : gr_sync_block ("udp_sink", gr_make_io_signature (1, 1, itemsize), gr_make_io_signature (0, 0, 0)), - d_itemsize (itemsize), d_updated(false), d_mtu(mtu) + d_itemsize (itemsize), d_updated(false), d_payload_size(payload_size) { - // Set up the address stucture for the local address and port numbers - inet_aton(ipaddrl, &d_ipaddr_local); // format IP address - inet_aton(ipaddrr, &d_ipaddr_remote); // format IP address - d_port_local = htons(portl); // format port number - d_port_remote = htons(portr); // format port number - - d_sockaddr_local.sin_family = AF_INET; - d_sockaddr_local.sin_addr = d_ipaddr_local; - d_sockaddr_local.sin_port = d_port_local; - - d_sockaddr_remote.sin_family = AF_INET; - d_sockaddr_remote.sin_addr = d_ipaddr_remote; - d_sockaddr_remote.sin_port = d_port_remote; + int ret = 0; + + // Set up the address stucture for the source address and port numbers + // Get the source IP address from the host name + struct hostent *hsrc = gethostbyname(src); + if(hsrc) { // if the source was provided as a host namex + d_ip_src = *(struct in_addr*)hsrc->h_addr_list[0]; + } + else { // assume it was specified as an IP address + if((ret=inet_aton(src, &d_ip_src)) == 0) { // format IP address + perror("Not a valid source IP address or host name"); + throw std::runtime_error("can't initialize source socket"); + } + } + + // Get the destination IP address from the host name + struct hostent *hdst = gethostbyname(dst); + if(hdst) { // if the source was provided as a host namex + d_ip_dst = *(struct in_addr*)hdst->h_addr_list[0]; + } + else { // assume it was specified as an IP address + if((ret=inet_aton(dst, &d_ip_dst)) == 0) { // format IP address + perror("Not a valid destination IP address or host name"); + throw std::runtime_error("can't initialize destination socket"); + } + } + + d_port_src = htons(port_src); // format port number + d_port_dst = htons(port_dst); // format port number + + d_sockaddr_src.sin_family = AF_INET; + d_sockaddr_src.sin_addr = d_ip_src; + d_sockaddr_src.sin_port = d_port_src; + + d_sockaddr_dst.sin_family = AF_INET; + d_sockaddr_dst.sin_addr = d_ip_dst; + d_sockaddr_dst.sin_port = d_port_dst; open(); } @@ -64,14 +81,14 @@ gr_udp_sink::gr_udp_sink (size_t itemsize, gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize, - const char *ipaddrl, unsigned short portl, - const char *ipaddrr, unsigned short portr, - unsigned int mtu) + const char *src, unsigned short port_src, + const char *dst, unsigned short port_dst, + int payload_size) { return gr_udp_sink_sptr (new gr_udp_sink (itemsize, - ipaddrl, portl, - ipaddrr, portr, - mtu)); + src, port_src, + dst, port_dst, + payload_size)); } gr_udp_sink::~gr_udp_sink () @@ -91,7 +108,7 @@ gr_udp_sink::open() } // Turn on reuse address - bool opt_val = true; + int opt_val = true; if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(int)) == -1) { perror("SO_REUSEADDR"); throw std::runtime_error("can't set socket option SO_REUSEADDR"); @@ -107,13 +124,13 @@ gr_udp_sink::open() } // bind socket to an address and port number to listen on - if(bind (d_socket, (sockaddr*)&d_sockaddr_local, sizeof(struct sockaddr)) == -1) { + if(bind (d_socket, (sockaddr*)&d_sockaddr_src, sizeof(struct sockaddr)) == -1) { perror("socket bind"); throw std::runtime_error("can't bind socket"); } // Not sure if we should throw here or allow retries - if(connect(d_socket, (sockaddr*)&d_sockaddr_remote, sizeof(struct sockaddr)) == -1) { + if(connect(d_socket, (sockaddr*)&d_sockaddr_dst, sizeof(struct sockaddr)) == -1) { perror("socket connect"); throw std::runtime_error("can't connect to socket"); } @@ -139,14 +156,27 @@ gr_udp_sink::work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - char *in = (char *) input_items[0]; - socklen_t bytes=0, bytes_sent=0, bytes_to_send=0; - unsigned int total_size = noutput_items*d_itemsize; - - while(bytes_sent < total_size) { - bytes_to_send = (bytes_sent+d_mtu < total_size ? d_mtu : total_size-bytes_sent); - bytes = send(d_socket, (in+bytes_sent), bytes_to_send, MSG_DONTWAIT); - bytes_sent += bytes; + const char *in = (const char *) input_items[0]; + ssize_t r=0, bytes_sent=0, bytes_to_send=0; + ssize_t total_size = noutput_items*d_itemsize; + + #if SNK_VERBOSE + printf("Entered upd_sink\n"); + #endif + + while(bytes_sent < total_size) { + bytes_to_send = std::min(d_payload_size, (total_size-bytes_sent)); + + r = send(d_socket, (in+bytes_sent), bytes_to_send, 0); + if(r == -1) { // error on send command + perror("udp_sink"); // there should be no error case where this function + return -1; // should not exit immediately + } + bytes_sent += r; + + #if SNK_VERBOSE + printf("\tbyte sent: %d bytes\n", bytes); + #endif } #if SNK_VERBOSE diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.h b/gnuradio-core/src/lib/io/gr_udp_sink.h index ee346f40c..9263ade79 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.h +++ b/gnuradio-core/src/lib/io/gr_udp_sink.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -31,43 +31,66 @@ class gr_udp_sink; typedef boost::shared_ptr gr_udp_sink_sptr; +gr_udp_sink_sptr +gr_make_udp_sink (size_t itemsize, + const char *src, unsigned short port_src, + const char *dst, unsigned short port_dst, + int payload_size=1472); + /*! - * \brief Write stream to an Udp port (over UDP). + * \brief Write stream to an UDP socket. * \ingroup sink + * + * \param itemsize The size (in bytes) of the item datatype + * \param src The source address as either the host name or the 'numbers-and-dots' + * IP address + * \param port_src Destination port to bind to (0 allows socket to choose an appropriate port) + * \param dst The destination address as either the host name or the 'numbers-and-dots' + * IP address + * \param port_dst Destination port to connect to + * \param payload_size UDP payload size by default set to + * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header)) */ -gr_udp_sink_sptr -gr_make_udp_sink (size_t itemsize, - const char *ipaddrl, unsigned short portl, - const char *ipaddrr, unsigned short portr, - unsigned int mtu=540); - class gr_udp_sink : public gr_sync_block { friend gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize, - const char *ipaddrl, unsigned short portl, - const char *ipaddrr, unsigned short portr, - unsigned int mtu); + const char *src, unsigned short port_src, + const char *dst, unsigned short port_dst, + int payload_size); private: size_t d_itemsize; bool d_updated; omni_mutex d_mutex; - unsigned int d_mtu; // maximum transmission unit (packet length) + int d_payload_size; // maximum transmission unit (packet length) int d_socket; // handle to socket int d_socket_rcv; // handle to socket retuned in the accept call - struct in_addr d_ipaddr_local; // store the local IP address to use - struct in_addr d_ipaddr_remote; // store the remote IP address that connected to us - unsigned short d_port_local; // the port number to open for connections to this service - unsigned short d_port_remote; // port number of the remove system - sockaddr_in d_sockaddr_local; // store the local sockaddr data (formatted IP address and port number) - sockaddr_in d_sockaddr_remote; // store the remote sockaddr data (formatted IP address and port number) + struct in_addr d_ip_src; // store the source ip info + struct in_addr d_ip_dst; // store the destination ip info + unsigned short d_port_src; // the port number to open for connections to this service + unsigned short d_port_dst; // port number of the remove system + sockaddr_in d_sockaddr_src; // store the source sockaddr data (formatted IP address and port number) + sockaddr_in d_sockaddr_dst; // store the destination sockaddr data (formatted IP address and port number) protected: + /*! + * \brief UDP Sink Constructor + * + * \param itemsize The size (in bytes) of the item datatype + * \param src The source address as either the host name or the 'numbers-and-dots' + * IP address + * \param port_src Destination port to bind to (0 allows socket to choose an appropriate port) + * \param dst The destination address as either the host name or the 'numbers-and-dots' + * IP address + * \param port_dst Destination port to connect to + * \param payload_size UDP payload size by default set to + * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header)) + */ gr_udp_sink (size_t itemsize, - const char *ipaddrl, unsigned short portl, - const char *ipaddrr, unsigned short portr, - unsigned int mtu); + const char *src, unsigned short port_src, + const char *dst, unsigned short port_dst, + int payload_size); public: ~gr_udp_sink (); @@ -87,11 +110,8 @@ class gr_udp_sink : public gr_sync_block */ void close(); - /*! \brief set the MTU of the socket */ - void set_mtu(unsigned int mtu) { d_mtu = mtu; } - - /*! \brief return the MTU of the socket */ - unsigned int mtu() { return d_mtu; } + /*! \brief return the PAYLOAD_SIZE of the socket */ + int payload_size() { return d_payload_size; } // should we export anything else? diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.i b/gnuradio-core/src/lib/io/gr_udp_sink.i index bd4accb3e..ad3a452d0 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.i +++ b/gnuradio-core/src/lib/io/gr_udp_sink.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -25,22 +25,21 @@ GR_SWIG_BLOCK_MAGIC(gr,udp_sink) gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize, - const char *ipaddrl, unsigned short portl, - const char *ipaddrr, unsigned short portr, - unsigned int mtu=540); + const char *src, unsigned short port_src, + const char *dst, unsigned short port_dst, + int payload_size=1472); class gr_udp_sink : public gr_sync_block { protected: gr_udp_sink (size_t itemsize, - const char *ipaddrl, unsigned short portl, - const char *ipaddrr, unsigned short portr, - unsigned int mtu); + const char *src, unsigned short port_src, + const char *dst, unsigned short port_dst, + int payload_size); bool open(); void close(); - void set_mtu(unsigned int mtu) { d_mtu = mtu; } - unsigned int mtu() { return d_mtu; } + int payload_size() { return d_payload_size; } public: ~gr_udp_sink (); diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index e2def4c37..e12d33b80 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -20,48 +20,58 @@ * Boston, MA 02110-1301, USA. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include #include -#include -#include -#include -#include #include +#include +#include #define SRC_VERBOSE 0 -gr_udp_source::gr_udp_source(size_t itemsize, const char *ipaddr, - unsigned short port, unsigned int mtu) +gr_udp_source::gr_udp_source(size_t itemsize, const char *src, + unsigned short port_src, int payload_size) : gr_sync_block ("udp_source", gr_make_io_signature(0, 0, 0), gr_make_io_signature(1, 1, itemsize)), - d_itemsize(itemsize), d_updated(false), d_mtu(mtu) + d_itemsize(itemsize), d_updated(false), d_payload_size(payload_size), d_residual(0), d_temp_offset(0) { - // Set up the address stucture for the local address and port numbers - inet_aton(ipaddr, &d_ipaddr_local); // format IP address - d_port_local = htons(port); // format port number + int ret = 0; + + // Set up the address stucture for the source address and port numbers + // Get the source IP address from the host name + struct hostent *hsrc = gethostbyname(src); + if(hsrc) { // if the source was provided as a host namex + d_ip_src = *(struct in_addr*)hsrc->h_addr_list[0]; + } + else { // assume it was specified as an IP address + if((ret=inet_aton(src, &d_ip_src)) == 0) { // format IP address + perror("Not a valid source IP address or host name"); + throw std::runtime_error("can't initialize source socket"); + } + } + + d_port_src = htons(port_src); // format port number - d_sockaddr_local.sin_family = AF_INET; - d_sockaddr_local.sin_addr = d_ipaddr_local; - d_sockaddr_local.sin_port = d_port_local; + d_sockaddr_src.sin_family = AF_INET; + d_sockaddr_src.sin_addr = d_ip_src; + d_sockaddr_src.sin_port = d_port_src; + + d_temp_buff = new char[d_payload_size]; // allow it to hold up to payload_size bytes open(); } gr_udp_source_sptr gr_make_udp_source (size_t itemsize, const char *ipaddr, - unsigned short port, unsigned int mtu) + unsigned short port, int payload_size) { return gr_udp_source_sptr (new gr_udp_source (itemsize, ipaddr, - port, mtu)); + port, payload_size)); } gr_udp_source::~gr_udp_source () { + delete [] d_temp_buff; close(); } @@ -69,16 +79,15 @@ bool gr_udp_source::open() { omni_mutex_lock l(d_mutex); // hold mutex for duration of this function - // create socket - d_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + d_socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); if(d_socket == -1) { perror("socket open"); throw std::runtime_error("can't open socket"); } // Turn on reuse address - bool opt_val = true; + int opt_val = 1; if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(int)) == -1) { perror("SO_REUSEADDR"); throw std::runtime_error("can't set socket option SO_REUSEADDR"); @@ -104,7 +113,7 @@ gr_udp_source::open() } // bind socket to an address and port number to listen on - if(bind (d_socket, (sockaddr*)&d_sockaddr_local, sizeof(struct sockaddr)) == -1) { + if(bind (d_socket, (sockaddr*)&d_sockaddr_src, sizeof(struct sockaddr)) == -1) { perror("socket bind"); throw std::runtime_error("can't bind socket"); } @@ -131,33 +140,86 @@ gr_udp_source::work (int noutput_items, gr_vector_void_star &output_items) { char *out = (char *) output_items[0]; - socklen_t bytes_to_receive=0, bytes_received=0; - int bytes=0; + ssize_t r=0, nbytes=0, bytes_received=0; + ssize_t total_bytes = (ssize_t)(d_itemsize*noutput_items); + + #if SRC_VERBOSE + printf("\nEntered udp_source\n"); + #endif - while((bytes_received < (unsigned)noutput_items) && (bytes>-1)) { - // caclulate the number of byte left if we can fit in all d_mtu bytes - bytes_to_receive = (bytes_received+d_mtu < noutput_items ? - d_mtu : noutput_items-bytes_received); + // Remove items from temp buffer if they are in there + if(d_residual) { + nbytes = std::min(d_residual, total_bytes); + memcpy(out, d_temp_buff+d_temp_offset, nbytes); + bytes_received = nbytes; + + #if SRC_VERBOSE + printf("\tTemp buff size: %d offset: %d (bytes_received: %d) (noutput_items: %d)\n", + d_residual, d_temp_offset, bytes_received, noutput_items); + #endif + + // Increment pointer + out += bytes_received; + // Update indexing of amount of bytes left in the buffer + d_residual -= nbytes; + d_temp_offset = d_temp_offset+d_residual; + } + + while(1) { // get the data into our output buffer and record the number of bytes - // This is a blocking call, but it's timeout has been set in the constructor - bytes = recv(d_socket, out, bytes_to_receive, 0); + // This is a non-blocking call with a timeout set in the constructor + r = recv(d_socket, d_temp_buff, d_payload_size, 0); // get the entire payload or the what's available + + // Check if there was a problem; forget it if the operation just timed out + if(r == -1) { + if(errno == EAGAIN) { // handle non-blocking call timeout + #if SRC_VERBOSE + printf("UDP receive timed out\n"); + #endif + + // Break here to allow the rest of the flow graph time to run and so ctrl-C breaks + break; + } + else { + perror("udp_source"); + return -1; + } + } + else { + // Calculate the number of bytes we can take from the buffer in this call + nbytes = std::min(r, total_bytes-bytes_received); + + // adjust the total number of bytes we have to round down to nearest integer of an itemsize + nbytes -= ((bytes_received+nbytes) % d_itemsize); - // FIXME if bytes < 0 bail + // copy the number of bytes we want to look at here + memcpy(out, d_temp_buff, nbytes); + + d_residual = r - nbytes; // save the number of bytes stored + d_temp_offset=nbytes; // reset buffer index - if(bytes > 0) { // keep track of the total number of bytes received - bytes_received += bytes; + bytes_received += nbytes; // increment the pointer - out += bytes; + out += nbytes; + + // Immediately return when data comes in + break; } + + #if SNK_VERBOSE + printf("\tbytes received: %d bytes (nbytes: %d)\n", bytes, nbytes); + #endif } #if SRC_VERBOSE - printf("\nTotal Bytes Received: %d (noutput_items=%d)\n", bytes_received, noutput_items); + printf("Total Bytes Received: %d (bytes_received / noutput_items = %d / %d)\n", + bytes_received, bytes_received, noutput_items); #endif - // FIXME what if (bytes_received % d_itemsize) != 0 ??? - return int(bytes_received / d_itemsize); + // bytes_received is already set to some integer multiple of itemsize + return bytes_received/d_itemsize; } + diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h index c57f4fc8f..5e4a81cb7 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.h +++ b/gnuradio-core/src/lib/io/gr_udp_source.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -31,31 +31,55 @@ class gr_udp_source; typedef boost::shared_ptr gr_udp_source_sptr; -gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *ipaddr, - unsigned short port, unsigned int mtu=540); +gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *src, + unsigned short port_src, int payload_size=1472); + +/*! + * \brief Read stream from an UDP socket. + * \ingroup sink + * + * \param itemsize The size (in bytes) of the item datatype + * \param src The source address as either the host name or the 'numbers-and-dots' + * IP address + * \param port_src The port number on which the socket listens for data + * \param payload_size UDP payload size by default set to + * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header)) + * +*/ class gr_udp_source : public gr_sync_block { - friend gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *ipaddr, - unsigned short port, unsigned int mtu); + friend gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *src, + unsigned short port_src, int payload_size); private: size_t d_itemsize; bool d_updated; omni_mutex d_mutex; - unsigned int d_mtu; // maximum transmission unit (packet length) + int d_payload_size; // maximum transmission unit (packet length) int d_socket; // handle to socket int d_socket_rcv; // handle to socket retuned in the accept call - struct in_addr d_ipaddr_local; // store the local IP address to use - struct in_addr d_ipaddr_remote; // store the remote IP address that connected to us - unsigned short d_port_local; // the port number to open for connections to this service - unsigned short d_port_remote; // port number of the remove system - sockaddr_in d_sockaddr_local; // store the local sockaddr data (formatted IP address and port number) - sockaddr_in d_sockaddr_remote; // store the remote sockaddr data (formatted IP address and port number) - + struct in_addr d_ip_src; // store the source IP address to use + unsigned short d_port_src; // the port number to open for connections to this service + sockaddr_in d_sockaddr_src; // store the source sockaddr data (formatted IP address and port number) + + char *d_temp_buff; // hold buffer between calls + ssize_t d_residual; // hold information about number of bytes stored in the temp buffer + size_t d_temp_offset; // point to temp buffer location offset + protected: - gr_udp_source(size_t itemsize, const char *ipaddr, unsigned short port, unsigned int mtu); + /*! + * \brief UDP Source Constructor + * + * \param itemsize The size (in bytes) of the item datatype + * \param src The source address as either the host name or the 'numbers-and-dots' + * IP address + * \param port_src The port number on which the socket listens for data + * \param payload_size UDP payload size by default set to + * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header)) + */ + gr_udp_source(size_t itemsize, const char *src, unsigned short port_src, int payload_size); public: ~gr_udp_source(); @@ -75,11 +99,8 @@ class gr_udp_source : public gr_sync_block */ void close(); - /*! \brief set the MTU of the socket */ - void set_mtu(unsigned int mtu) { d_mtu = mtu; } - - /*! \brief return the MTU of the socket */ - unsigned int mtu() { return d_mtu; } + /*! \brief return the PAYLOAD_SIZE of the socket */ + int payload_size() { return d_payload_size; } // should we export anything else? diff --git a/gnuradio-core/src/lib/io/gr_udp_source.i b/gnuradio-core/src/lib/io/gr_udp_source.i index 1d6f4c904..5661f6e7d 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.i +++ b/gnuradio-core/src/lib/io/gr_udp_source.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,21 +23,20 @@ GR_SWIG_BLOCK_MAGIC(gr,udp_source) gr_udp_source_sptr -gr_make_udp_source (size_t itemsize, const char *ipaddr, - unsigned short port, unsigned int mtu=540); +gr_make_udp_source (size_t itemsize, const char *src, + unsigned short port_src, int payload_size=1472); class gr_udp_source : public gr_sync_block { protected: - gr_udp_source (size_t itemsize, const char *ipaddr, - unsigned short port, unsigned int mtu); + gr_udp_source (size_t itemsize, const char *src, + unsigned short port_src, int payload_size); public: ~gr_udp_source (); bool open(); void close(); - void set_mtu(unsigned int mtu) { d_mtu = mtu; } - unsigned int mtu() { return d_mtu; } + int payload_size() { return d_payload_size; } }; -- cgit From d37f0144d85d17d8a7d5dbda6200a24484aacde8 Mon Sep 17 00:00:00 2001 From: trondeau Date: Fri, 16 Feb 2007 02:33:22 +0000 Subject: quick fix for std::min error on 64-bit systems git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4489 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/gr_udp_sink.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index d799262b4..7a5d51e0b 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -165,7 +165,7 @@ gr_udp_sink::work (int noutput_items, #endif while(bytes_sent < total_size) { - bytes_to_send = std::min(d_payload_size, (total_size-bytes_sent)); + bytes_to_send = std::min((ssize_t)d_payload_size, (total_size-bytes_sent)); r = send(d_socket, (in+bytes_sent), bytes_to_send, 0); if(r == -1) { // error on send command -- cgit From 43819f0f33498239970b4479684f12aa080859e6 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Thu, 26 Apr 2007 22:51:48 +0000 Subject: Merged r4518:5130 from developer branch n4hy/ofdm into trunk, passes distcheck. Adds incomplete OFDM implementation, further work to be completed in the features/ofdm branch. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@5131 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/Makefile.am | 6 +- gnuradio-core/src/lib/io/gr_frame.h | 41 +++++++++ .../src/lib/io/gr_message_vector_source.cc | 97 ++++++++++++++++++++++ .../src/lib/io/gr_message_vector_source.h | 63 ++++++++++++++ .../src/lib/io/gr_message_vector_source.i | 36 ++++++++ gnuradio-core/src/lib/io/io.i | 6 +- 6 files changed, 246 insertions(+), 3 deletions(-) create mode 100644 gnuradio-core/src/lib/io/gr_frame.h create mode 100644 gnuradio-core/src/lib/io/gr_message_vector_source.cc create mode 100644 gnuradio-core/src/lib/io/gr_message_vector_source.h create mode 100644 gnuradio-core/src/lib/io/gr_message_vector_source.i (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index 8320375c7..049e6984a 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2001,2003,2004,2006 Free Software Foundation, Inc. +# Copyright 2001,2003,2004,2006,2007 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -34,6 +34,7 @@ libio_la_SOURCES = \ gr_file_descriptor_source.cc \ gr_message_sink.cc \ gr_message_source.cc \ + gr_message_vector_source.cc \ gr_oscope_guts.cc \ gr_oscope_sink_f.cc \ gr_oscope_sink_x.cc \ @@ -59,8 +60,10 @@ grinclude_HEADERS = \ gr_file_source.h \ gr_file_descriptor_sink.h \ gr_file_descriptor_source.h \ + gr_frame.h \ gr_message_sink.h \ gr_message_source.h \ + gr_message_vector_source.h \ gr_oscope_guts.h \ gr_oscope_sink_f.h \ gr_oscope_sink_x.h \ @@ -92,6 +95,7 @@ swiginclude_HEADERS = \ gr_file_descriptor_source.i \ gr_message_sink.i \ gr_message_source.i \ + gr_message_vector_source.i \ gr_oscope_sink.i \ microtune_xxxx_eval_board.i \ microtune_4702_eval_board.i \ diff --git a/gnuradio-core/src/lib/io/gr_frame.h b/gnuradio-core/src/lib/io/gr_frame.h new file mode 100644 index 000000000..07317e9df --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_frame.h @@ -0,0 +1,41 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_FRAME_H +#define INCLUDED_GR_FRAME_H + +#include + +class gr_frame +{ + public: + gr_frame(unsigned int mtu) + : mtu(mtu), length(0) + { } + + unsigned int mtu; + unsigned int length; + unsigned char data[]; +}; + +#endif + diff --git a/gnuradio-core/src/lib/io/gr_message_vector_source.cc b/gnuradio-core/src/lib/io/gr_message_vector_source.cc new file mode 100644 index 000000000..69e2bc8df --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_vector_source.cc @@ -0,0 +1,97 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + + +// public constructor that returns a shared_ptr + +gr_message_vector_source_sptr +gr_make_message_vector_source(size_t max_msg_size, int msgq_limit) +{ + return gr_message_vector_source_sptr(new gr_message_vector_source(max_msg_size,msgq_limit)); +} + +gr_message_vector_source::gr_message_vector_source (size_t max_msg_size, int msgq_limit) + : gr_sync_block("message_vector_source", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(1, 1, 2*sizeof(int) + max_msg_size * sizeof(char))), // Make room for length fields + d_max_msg_size(max_msg_size), d_msgq(gr_make_msg_queue(msgq_limit)), d_eof(false) +{ +} + +gr_message_vector_source::~gr_message_vector_source() +{ +} + +int +gr_message_vector_source::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + /* + char *out = (char *) output_items[0]; + + if (d_eof) + return -1; + + gr_message_sptr msg = d_msgq->delete_head(); + + if (msg->type() == 1) { // type == 1 sets EOF + d_eof = true; + } + + assert(msg->length() <= d_max_msg_size); + memset((int*)out, msg->length(), 1); + memcpy (&out[4], (msg->msg()), msg->length()); + */ + + char *out = (char *) output_items[0]; + gr_frame *myframe = (gr_frame*)out; + + if (d_eof) + return -1; + + gr_message_sptr msg = d_msgq->delete_head(); + + if (msg->type() == 1) { // type == 1 sets EOF + d_eof = true; + } + + assert(msg->length() <= d_max_msg_size); + myframe->length = msg->length(); + myframe->mtu = d_max_msg_size; + memcpy (myframe->data, (msg->msg()), msg->length()); + + return 1; +} diff --git a/gnuradio-core/src/lib/io/gr_message_vector_source.h b/gnuradio-core/src/lib/io/gr_message_vector_source.h new file mode 100644 index 000000000..8b3465355 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_vector_source.h @@ -0,0 +1,63 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_MESSAGE_VECTOR_SOURCE_H +#define INCLUDED_GR_MESSAGE_VECTOR_SOURCE_H + +#include +#include +#include +#include + +class gr_message_vector_source; +typedef boost::shared_ptr gr_message_vector_source_sptr; + +gr_message_vector_source_sptr gr_make_message_vector_source (size_t max_msg_size, int msgq_limit=0); + +/*! + * \brief Turn received messages into vectors + * \ingroup source + */ +class gr_message_vector_source : public gr_sync_block +{ + private: + size_t d_max_msg_size; + gr_msg_queue_sptr d_msgq; + bool d_eof; + + friend gr_message_vector_source_sptr + gr_make_message_vector_source(size_t max_msg_size, int msgq_limit); + + protected: + gr_message_vector_source (size_t max_msg_size, int msgq_limit); + + public: + ~gr_message_vector_source (); + + gr_msg_queue_sptr msgq() const { return d_msgq; } + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_GR_MESSAGE_VECTOR_SOURCE_H */ diff --git a/gnuradio-core/src/lib/io/gr_message_vector_source.i b/gnuradio-core/src/lib/io/gr_message_vector_source.i new file mode 100644 index 000000000..ff8bd5de5 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_vector_source.i @@ -0,0 +1,36 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,message_vector_source); + +gr_message_vector_source_sptr gr_make_message_vector_source (size_t max_msg_size, int msgq_limit=0); + +class gr_message_vector_source : public gr_sync_block +{ + protected: + gr_message_vector_source (size_t itemsize, int msgq_limit); + + public: + ~gr_message_vector_source (); + + gr_msg_queue_sptr msgq() const; +}; diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index 7baf94ef0..d80f66369 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -34,8 +34,9 @@ #include #include #include -#include -#include +#include +#include +#include %} @@ -50,6 +51,7 @@ %include "gr_oscope_sink.i" %include "ppio.i" %include "gr_message_source.i" +%include "gr_message_vector_source.i" %include "gr_message_sink.i" %include "gr_udp_sink.i" %include "gr_udp_source.i" -- cgit From 7961e0f99c9b24aa347f3943333470f643e7f9bc Mon Sep 17 00:00:00 2001 From: jcorgan Date: Mon, 30 Apr 2007 18:02:39 +0000 Subject: Fix incorrect include file reference. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@5193 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/io.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index d80f66369..806e83e1f 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -35,8 +35,8 @@ #include #include #include -#include -#include +#include +#include %} -- cgit From c7dbfcc7d78275f76d8c2a8ef21e3100721874be Mon Sep 17 00:00:00 2001 From: trondeau Date: Mon, 4 Jun 2007 16:08:44 +0000 Subject: merge ordm/receiver branch -r5574:5659. Reworks OFDM receiver with refactored OFDM blocks. A few bug fixes for other blocks have also been slipped in. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@5661 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/Makefile.am | 7 +- gnuradio-core/src/lib/io/gr_file_sink.cc | 90 ++-------------- gnuradio-core/src/lib/io/gr_file_sink.h | 24 +---- gnuradio-core/src/lib/io/gr_file_sink.i | 2 +- gnuradio-core/src/lib/io/gr_file_sink_base.cc | 118 +++++++++++++++++++++ gnuradio-core/src/lib/io/gr_file_sink_base.h | 67 ++++++++++++ gnuradio-core/src/lib/io/gr_file_sink_base.i | 46 ++++++++ gnuradio-core/src/lib/io/gr_frame.h | 41 ------- .../src/lib/io/gr_message_vector_source.cc | 97 ----------------- .../src/lib/io/gr_message_vector_source.h | 63 ----------- .../src/lib/io/gr_message_vector_source.i | 36 ------- gnuradio-core/src/lib/io/io.i | 3 +- 12 files changed, 249 insertions(+), 345 deletions(-) create mode 100644 gnuradio-core/src/lib/io/gr_file_sink_base.cc create mode 100644 gnuradio-core/src/lib/io/gr_file_sink_base.h create mode 100644 gnuradio-core/src/lib/io/gr_file_sink_base.i delete mode 100644 gnuradio-core/src/lib/io/gr_frame.h delete mode 100644 gnuradio-core/src/lib/io/gr_message_vector_source.cc delete mode 100644 gnuradio-core/src/lib/io/gr_message_vector_source.h delete mode 100644 gnuradio-core/src/lib/io/gr_message_vector_source.i (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index 049e6984a..4835c68c2 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -29,12 +29,12 @@ noinst_LTLIBRARIES = libio.la libio_la_SOURCES = \ gr_file_sink.cc \ + gr_file_sink_base.cc \ gr_file_source.cc \ gr_file_descriptor_sink.cc \ gr_file_descriptor_source.cc \ gr_message_sink.cc \ gr_message_source.cc \ - gr_message_vector_source.cc \ gr_oscope_guts.cc \ gr_oscope_sink_f.cc \ gr_oscope_sink_x.cc \ @@ -57,13 +57,12 @@ libio_la_SOURCES = \ grinclude_HEADERS = \ gr_file_sink.h \ + gr_file_sink_base.h \ gr_file_source.h \ gr_file_descriptor_sink.h \ gr_file_descriptor_source.h \ - gr_frame.h \ gr_message_sink.h \ gr_message_source.h \ - gr_message_vector_source.h \ gr_oscope_guts.h \ gr_oscope_sink_f.h \ gr_oscope_sink_x.h \ @@ -90,12 +89,12 @@ grinclude_HEADERS = \ swiginclude_HEADERS = \ io.i \ gr_file_sink.i \ + gr_file_sink_base.i \ gr_file_source.i \ gr_file_descriptor_sink.i \ gr_file_descriptor_source.i \ gr_message_sink.i \ gr_message_source.i \ - gr_message_vector_source.i \ gr_oscope_sink.i \ microtune_xxxx_eval_board.i \ microtune_4702_eval_board.i \ diff --git a/gnuradio-core/src/lib/io/gr_file_sink.cc b/gnuradio-core/src/lib/io/gr_file_sink.cc index b7cf6c24e..0994fd2ba 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2006 Free Software Foundation, Inc. + * Copyright 2004,2006,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,91 +26,28 @@ #include #include -#include -#include -#include -#include #include -// win32 (mingw/msvc) specific -#ifdef HAVE_IO_H -#include -#endif -#ifdef O_BINARY -#define OUR_O_BINARY O_BINARY -#else -#define OUR_O_BINARY 0 -#endif -// should be handled via configure -#ifdef O_LARGEFILE -#define OUR_O_LARGEFILE O_LARGEFILE -#else -#define OUR_O_LARGEFILE 0 -#endif +gr_file_sink_sptr +gr_make_file_sink (size_t itemsize, const char *filename) +{ + return gr_file_sink_sptr (new gr_file_sink (itemsize, filename)); +} gr_file_sink::gr_file_sink(size_t itemsize, const char *filename) : gr_sync_block ("file_sink", gr_make_io_signature(1, 1, itemsize), gr_make_io_signature(0, 0, 0)), - d_itemsize(itemsize), d_fp(0), d_new_fp(0), d_updated(false) + gr_file_sink_base(filename, true), + d_itemsize(itemsize) { if (!open(filename)) throw std::runtime_error ("can't open file"); } -gr_file_sink_sptr -gr_make_file_sink (size_t itemsize, const char *filename) -{ - return gr_file_sink_sptr (new gr_file_sink (itemsize, filename)); -} - gr_file_sink::~gr_file_sink () { - close(); - if (d_fp){ - fclose((FILE *) d_fp); - d_fp = 0; - } -} - -bool -gr_file_sink::open(const char *filename) -{ - omni_mutex_lock l(d_mutex); // hold mutex for duration of this function - - // we use the open system call to get access to the O_LARGEFILE flag. - int fd; - if ((fd = ::open (filename, - O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY, 0664)) < 0){ - perror (filename); - return false; - } - - if (d_new_fp){ // if we've already got a new one open, close it - fclose((FILE *) d_new_fp); - d_new_fp = 0; - } - - if ((d_new_fp = fdopen (fd, "wb")) == NULL){ - perror (filename); - ::close(fd); // don't leak file descriptor if fdopen fails. - } - - d_updated = true; - return d_new_fp != 0; -} - -void -gr_file_sink::close() -{ - omni_mutex_lock l(d_mutex); // hold mutex for duration of this function - - if (d_new_fp){ - fclose((FILE *) d_new_fp); - d_new_fp = 0; - } - d_updated = true; } int @@ -121,20 +58,13 @@ gr_file_sink::work (int noutput_items, char *inbuf = (char *) input_items[0]; int nwritten = 0; - if (d_updated){ - omni_mutex_lock l(d_mutex); // hold mutex for duration of this block - if (d_fp) - fclose((FILE *)d_fp); - d_fp = d_new_fp; // install new file pointer - d_new_fp = 0; - d_updated = false; - } + do_update(); // update d_fp is reqd if (!d_fp) return noutput_items; // drop output on the floor while (nwritten < noutput_items){ - int count = fwrite (inbuf, d_itemsize, noutput_items - nwritten, (FILE *) d_fp); + int count = fwrite (inbuf, d_itemsize, noutput_items - nwritten, d_fp); if (count == 0) // FIXME add error handling break; nwritten += count; diff --git a/gnuradio-core/src/lib/io/gr_file_sink.h b/gnuradio-core/src/lib/io/gr_file_sink.h index c289a150c..fd0cd6f62 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_sink.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,7 +24,7 @@ #define INCLUDED_GR_FILE_SINK_H #include -#include +#include class gr_file_sink; typedef boost::shared_ptr gr_file_sink_sptr; @@ -36,16 +36,12 @@ gr_file_sink_sptr gr_make_file_sink(size_t itemsize, const char *filename); * \ingroup sink */ -class gr_file_sink : public gr_sync_block +class gr_file_sink : public gr_sync_block, public gr_file_sink_base { friend gr_file_sink_sptr gr_make_file_sink(size_t itemsize, const char *filename); private: size_t d_itemsize; - void *d_fp; // current FILE pointer - void *d_new_fp; // new FILE pointer - bool d_updated; // is there a new FILE pointer? - omni_mutex d_mutex; protected: gr_file_sink(size_t itemsize, const char *filename); @@ -53,23 +49,9 @@ class gr_file_sink : public gr_sync_block public: ~gr_file_sink(); - /*! - * \brief Open filename and begin output to it. - */ - bool open(const char *filename); - - /*! - * \brief Close current output file. - * - * Closes current output file and ignores any output until - * open is called to connect to another file. - */ - void close(); - int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); }; - #endif /* INCLUDED_GR_FILE_SINK_H */ diff --git a/gnuradio-core/src/lib/io/gr_file_sink.i b/gnuradio-core/src/lib/io/gr_file_sink.i index 80f869562..202ab9317 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.i +++ b/gnuradio-core/src/lib/io/gr_file_sink.i @@ -25,7 +25,7 @@ GR_SWIG_BLOCK_MAGIC(gr,file_sink) gr_file_sink_sptr gr_make_file_sink (size_t itemsize, const char *filename); -class gr_file_sink : public gr_sync_block +class gr_file_sink : public gr_sync_block, public gr_file_sink_base { protected: gr_file_sink (size_t itemsize, const char *filename); diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.cc b/gnuradio-core/src/lib/io/gr_file_sink_base.cc new file mode 100644 index 000000000..44d01ba8d --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.cc @@ -0,0 +1,118 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2006,2007 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include + +// win32 (mingw/msvc) specific +#ifdef HAVE_IO_H +#include +#endif +#ifdef O_BINARY +#define OUR_O_BINARY O_BINARY +#else +#define OUR_O_BINARY 0 +#endif + +// should be handled via configure +#ifdef O_LARGEFILE +#define OUR_O_LARGEFILE O_LARGEFILE +#else +#define OUR_O_LARGEFILE 0 +#endif + +gr_file_sink_base::gr_file_sink_base(const char *filename, bool is_binary) + : d_fp(0), d_new_fp(0), d_updated(false), d_is_binary(is_binary) +{ + if (!open(filename)) + throw std::runtime_error ("can't open file"); +} + +gr_file_sink_base::~gr_file_sink_base () +{ + close(); + if (d_fp){ + fclose(d_fp); + d_fp = 0; + } +} + +bool +gr_file_sink_base::open(const char *filename) +{ + omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + + // we use the open system call to get access to the O_LARGEFILE flag. + int fd; + if ((fd = ::open (filename, + O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY, + 0664)) < 0){ + perror (filename); + return false; + } + + if (d_new_fp){ // if we've already got a new one open, close it + fclose(d_new_fp); + d_new_fp = 0; + } + + if ((d_new_fp = fdopen (fd, d_is_binary ? "wb" : "w")) == NULL){ + perror (filename); + ::close(fd); // don't leak file descriptor if fdopen fails. + } + + d_updated = true; + return d_new_fp != 0; +} + +void +gr_file_sink_base::close() +{ + omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + + if (d_new_fp){ + fclose(d_new_fp); + d_new_fp = 0; + } + d_updated = true; +} + +void +gr_file_sink_base::do_update() +{ + if (d_updated){ + omni_mutex_lock l(d_mutex); // hold mutex for duration of this block + if (d_fp) + fclose(d_fp); + d_fp = d_new_fp; // install new file pointer + d_new_fp = 0; + d_updated = false; + } +} diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.h b/gnuradio-core/src/lib/io/gr_file_sink_base.h new file mode 100644 index 000000000..98fc7b652 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.h @@ -0,0 +1,67 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2007 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., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_FILE_SINK_BASE_H +#define INCLUDED_GR_FILE_SINK_BASE_H + +#include +#include + +/*! + * \brief Common base class for file sinks + */ +class gr_file_sink_base +{ + protected: + FILE *d_fp; // current FILE pointer + FILE *d_new_fp; // new FILE pointer + bool d_updated; // is there a new FILE pointer? + bool d_is_binary; + omni_mutex d_mutex; + + protected: + gr_file_sink_base(const char *filename, bool is_binary); + + public: + ~gr_file_sink_base(); + + /*! + * \brief Open filename and begin output to it. + */ + bool open(const char *filename); + + /*! + * \brief Close current output file. + * + * Closes current output file and ignores any output until + * open is called to connect to another file. + */ + void close(); + + /*! + * \brief if we've had an update, do it now. + */ + void do_update(); +}; + + +#endif /* INCLUDED_GR_FILE_SINK_BASE_H */ diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.i b/gnuradio-core/src/lib/io/gr_file_sink_base.i new file mode 100644 index 000000000..b83f251e1 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.i @@ -0,0 +1,46 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 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 this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +class gr_file_sink_base +{ + protected: + gr_file_sink_base(const char *filename, bool is_binary); + + public: + ~gr_file_sink_base(); + + /*! + * \brief Open filename and begin output to it. + */ + bool open(const char *filename); + + /*! + * \brief Close current output file. + * + * Closes current output file and ignores any output until + * open is called to connect to another file. + */ + void close(); + + /*! + * \brief if we've had an update, do it now. + */ + void do_update(); +}; diff --git a/gnuradio-core/src/lib/io/gr_frame.h b/gnuradio-core/src/lib/io/gr_frame.h deleted file mode 100644 index 07317e9df..000000000 --- a/gnuradio-core/src/lib/io/gr_frame.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 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., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GR_FRAME_H -#define INCLUDED_GR_FRAME_H - -#include - -class gr_frame -{ - public: - gr_frame(unsigned int mtu) - : mtu(mtu), length(0) - { } - - unsigned int mtu; - unsigned int length; - unsigned char data[]; -}; - -#endif - diff --git a/gnuradio-core/src/lib/io/gr_message_vector_source.cc b/gnuradio-core/src/lib/io/gr_message_vector_source.cc deleted file mode 100644 index 69e2bc8df..000000000 --- a/gnuradio-core/src/lib/io/gr_message_vector_source.cc +++ /dev/null @@ -1,97 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 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., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - - -// public constructor that returns a shared_ptr - -gr_message_vector_source_sptr -gr_make_message_vector_source(size_t max_msg_size, int msgq_limit) -{ - return gr_message_vector_source_sptr(new gr_message_vector_source(max_msg_size,msgq_limit)); -} - -gr_message_vector_source::gr_message_vector_source (size_t max_msg_size, int msgq_limit) - : gr_sync_block("message_vector_source", - gr_make_io_signature(0, 0, 0), - gr_make_io_signature(1, 1, 2*sizeof(int) + max_msg_size * sizeof(char))), // Make room for length fields - d_max_msg_size(max_msg_size), d_msgq(gr_make_msg_queue(msgq_limit)), d_eof(false) -{ -} - -gr_message_vector_source::~gr_message_vector_source() -{ -} - -int -gr_message_vector_source::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - /* - char *out = (char *) output_items[0]; - - if (d_eof) - return -1; - - gr_message_sptr msg = d_msgq->delete_head(); - - if (msg->type() == 1) { // type == 1 sets EOF - d_eof = true; - } - - assert(msg->length() <= d_max_msg_size); - memset((int*)out, msg->length(), 1); - memcpy (&out[4], (msg->msg()), msg->length()); - */ - - char *out = (char *) output_items[0]; - gr_frame *myframe = (gr_frame*)out; - - if (d_eof) - return -1; - - gr_message_sptr msg = d_msgq->delete_head(); - - if (msg->type() == 1) { // type == 1 sets EOF - d_eof = true; - } - - assert(msg->length() <= d_max_msg_size); - myframe->length = msg->length(); - myframe->mtu = d_max_msg_size; - memcpy (myframe->data, (msg->msg()), msg->length()); - - return 1; -} diff --git a/gnuradio-core/src/lib/io/gr_message_vector_source.h b/gnuradio-core/src/lib/io/gr_message_vector_source.h deleted file mode 100644 index 8b3465355..000000000 --- a/gnuradio-core/src/lib/io/gr_message_vector_source.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 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., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GR_MESSAGE_VECTOR_SOURCE_H -#define INCLUDED_GR_MESSAGE_VECTOR_SOURCE_H - -#include -#include -#include -#include - -class gr_message_vector_source; -typedef boost::shared_ptr gr_message_vector_source_sptr; - -gr_message_vector_source_sptr gr_make_message_vector_source (size_t max_msg_size, int msgq_limit=0); - -/*! - * \brief Turn received messages into vectors - * \ingroup source - */ -class gr_message_vector_source : public gr_sync_block -{ - private: - size_t d_max_msg_size; - gr_msg_queue_sptr d_msgq; - bool d_eof; - - friend gr_message_vector_source_sptr - gr_make_message_vector_source(size_t max_msg_size, int msgq_limit); - - protected: - gr_message_vector_source (size_t max_msg_size, int msgq_limit); - - public: - ~gr_message_vector_source (); - - gr_msg_queue_sptr msgq() const { return d_msgq; } - - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); -}; - -#endif /* INCLUDED_GR_MESSAGE_VECTOR_SOURCE_H */ diff --git a/gnuradio-core/src/lib/io/gr_message_vector_source.i b/gnuradio-core/src/lib/io/gr_message_vector_source.i deleted file mode 100644 index ff8bd5de5..000000000 --- a/gnuradio-core/src/lib/io/gr_message_vector_source.i +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 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., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -GR_SWIG_BLOCK_MAGIC(gr,message_vector_source); - -gr_message_vector_source_sptr gr_make_message_vector_source (size_t max_msg_size, int msgq_limit=0); - -class gr_message_vector_source : public gr_sync_block -{ - protected: - gr_message_vector_source (size_t itemsize, int msgq_limit); - - public: - ~gr_message_vector_source (); - - gr_msg_queue_sptr msgq() const; -}; diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index 806e83e1f..c6344051e 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -34,12 +34,12 @@ #include #include #include -#include #include #include %} +%include "gr_file_sink_base.i" %include "gr_file_sink.i" %include "gr_file_source.i" %include "gr_file_descriptor_sink.i" @@ -51,7 +51,6 @@ %include "gr_oscope_sink.i" %include "ppio.i" %include "gr_message_source.i" -%include "gr_message_vector_source.i" %include "gr_message_sink.i" %include "gr_udp_sink.i" %include "gr_udp_source.i" -- 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 --- gnuradio-core/src/lib/io/Makefile.am | 2 +- gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc | 2 +- gnuradio-core/src/lib/io/gr_file_descriptor_sink.h | 2 +- gnuradio-core/src/lib/io/gr_file_descriptor_sink.i | 2 +- gnuradio-core/src/lib/io/gr_file_descriptor_source.cc | 2 +- gnuradio-core/src/lib/io/gr_file_descriptor_source.h | 2 +- gnuradio-core/src/lib/io/gr_file_descriptor_source.i | 2 +- gnuradio-core/src/lib/io/gr_file_sink.cc | 2 +- gnuradio-core/src/lib/io/gr_file_sink.h | 2 +- gnuradio-core/src/lib/io/gr_file_sink.i | 2 +- gnuradio-core/src/lib/io/gr_file_sink_base.cc | 2 +- gnuradio-core/src/lib/io/gr_file_sink_base.h | 2 +- gnuradio-core/src/lib/io/gr_file_sink_base.i | 2 +- gnuradio-core/src/lib/io/gr_file_source.cc | 2 +- gnuradio-core/src/lib/io/gr_file_source.h | 2 +- gnuradio-core/src/lib/io/gr_file_source.i | 2 +- gnuradio-core/src/lib/io/gr_message_sink.cc | 2 +- gnuradio-core/src/lib/io/gr_message_sink.h | 2 +- gnuradio-core/src/lib/io/gr_message_sink.i | 2 +- gnuradio-core/src/lib/io/gr_message_source.cc | 2 +- gnuradio-core/src/lib/io/gr_message_source.h | 2 +- gnuradio-core/src/lib/io/gr_message_source.i | 2 +- gnuradio-core/src/lib/io/gr_oscope_guts.cc | 2 +- gnuradio-core/src/lib/io/gr_oscope_guts.h | 2 +- gnuradio-core/src/lib/io/gr_oscope_sink.i | 2 +- gnuradio-core/src/lib/io/gr_oscope_sink_f.cc | 2 +- gnuradio-core/src/lib/io/gr_oscope_sink_f.h | 2 +- gnuradio-core/src/lib/io/gr_oscope_sink_x.cc | 2 +- gnuradio-core/src/lib/io/gr_oscope_sink_x.h | 2 +- gnuradio-core/src/lib/io/gr_trigger_mode.h | 2 +- gnuradio-core/src/lib/io/gr_udp_sink.cc | 2 +- gnuradio-core/src/lib/io/gr_udp_sink.h | 2 +- gnuradio-core/src/lib/io/gr_udp_sink.i | 2 +- gnuradio-core/src/lib/io/gr_udp_source.cc | 2 +- gnuradio-core/src/lib/io/gr_udp_source.h | 2 +- gnuradio-core/src/lib/io/gr_udp_source.i | 2 +- gnuradio-core/src/lib/io/gri_logger.cc | 2 +- gnuradio-core/src/lib/io/gri_logger.h | 2 +- gnuradio-core/src/lib/io/i2c.cc | 2 +- gnuradio-core/src/lib/io/i2c.h | 2 +- gnuradio-core/src/lib/io/i2c_bbio.cc | 2 +- gnuradio-core/src/lib/io/i2c_bbio.h | 2 +- gnuradio-core/src/lib/io/i2c_bbio_pp.cc | 2 +- gnuradio-core/src/lib/io/i2c_bbio_pp.h | 2 +- gnuradio-core/src/lib/io/i2c_bitbang.cc | 2 +- gnuradio-core/src/lib/io/i2c_bitbang.h | 2 +- gnuradio-core/src/lib/io/io.i | 2 +- gnuradio-core/src/lib/io/microtune_4702.cc | 2 +- gnuradio-core/src/lib/io/microtune_4702.h | 2 +- gnuradio-core/src/lib/io/microtune_4702_eval_board.cc | 2 +- gnuradio-core/src/lib/io/microtune_4702_eval_board.h | 2 +- gnuradio-core/src/lib/io/microtune_4702_eval_board.i | 2 +- gnuradio-core/src/lib/io/microtune_4937.cc | 2 +- gnuradio-core/src/lib/io/microtune_4937.h | 2 +- gnuradio-core/src/lib/io/microtune_4937_eval_board.cc | 2 +- gnuradio-core/src/lib/io/microtune_4937_eval_board.h | 2 +- gnuradio-core/src/lib/io/microtune_4937_eval_board.i | 2 +- gnuradio-core/src/lib/io/microtune_eval_board.i | 2 +- gnuradio-core/src/lib/io/microtune_eval_board_defs.h | 2 +- gnuradio-core/src/lib/io/microtune_xxxx.cc | 2 +- gnuradio-core/src/lib/io/microtune_xxxx.h | 2 +- gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc | 2 +- gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h | 2 +- gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i | 2 +- gnuradio-core/src/lib/io/ppio.cc | 2 +- gnuradio-core/src/lib/io/ppio.h | 2 +- gnuradio-core/src/lib/io/ppio.i | 2 +- gnuradio-core/src/lib/io/ppio_ppdev.cc | 2 +- gnuradio-core/src/lib/io/ppio_ppdev.h | 2 +- gnuradio-core/src/lib/io/sdr_1000.cc | 2 +- gnuradio-core/src/lib/io/sdr_1000.h | 2 +- gnuradio-core/src/lib/io/sdr_1000.i | 2 +- 72 files changed, 72 insertions(+), 72 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index 4835c68c2..626ddb07a 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -5,7 +5,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, diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc index 0fa0ee266..a3a9a8c0e 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.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, diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h index e680674d8..4b5ceff31 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.i b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.i index 547f81f5d..14c37f68e 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.i +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.i @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc b/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc index fbd13c8da..b2d7c6bfb 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_source.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, diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_source.h b/gnuradio-core/src/lib/io/gr_file_descriptor_source.h index 9e1590000..b233580c6 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_source.h +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_source.h @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_source.i b/gnuradio-core/src/lib/io/gr_file_descriptor_source.i index 84f87b0f7..cee0b5765 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_source.i +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_source.i @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_file_sink.cc b/gnuradio-core/src/lib/io/gr_file_sink.cc index 0994fd2ba..d40235fab 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink.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, diff --git a/gnuradio-core/src/lib/io/gr_file_sink.h b/gnuradio-core/src/lib/io/gr_file_sink.h index fd0cd6f62..16cd4befc 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_sink.h @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_file_sink.i b/gnuradio-core/src/lib/io/gr_file_sink.i index 202ab9317..64260392c 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.i +++ b/gnuradio-core/src/lib/io/gr_file_sink.i @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.cc b/gnuradio-core/src/lib/io/gr_file_sink_base.cc index 44d01ba8d..1ce84fa88 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.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, diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.h b/gnuradio-core/src/lib/io/gr_file_sink_base.h index 98fc7b652..c848818f8 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.h +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.h @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.i b/gnuradio-core/src/lib/io/gr_file_sink_base.i index b83f251e1..05a3353bb 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.i +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.i @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_file_source.cc b/gnuradio-core/src/lib/io/gr_file_source.cc index a38d8f8b6..95d1c0aca 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_source.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, diff --git a/gnuradio-core/src/lib/io/gr_file_source.h b/gnuradio-core/src/lib/io/gr_file_source.h index 488798144..bf490040b 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.h +++ b/gnuradio-core/src/lib/io/gr_file_source.h @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_file_source.i b/gnuradio-core/src/lib/io/gr_file_source.i index 85a32361a..f538ea3ae 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.i +++ b/gnuradio-core/src/lib/io/gr_file_source.i @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_message_sink.cc b/gnuradio-core/src/lib/io/gr_message_sink.cc index 9c607af1a..0cb1c0029 100644 --- a/gnuradio-core/src/lib/io/gr_message_sink.cc +++ b/gnuradio-core/src/lib/io/gr_message_sink.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, diff --git a/gnuradio-core/src/lib/io/gr_message_sink.h b/gnuradio-core/src/lib/io/gr_message_sink.h index eaa52df81..9126358cb 100644 --- a/gnuradio-core/src/lib/io/gr_message_sink.h +++ b/gnuradio-core/src/lib/io/gr_message_sink.h @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_message_sink.i b/gnuradio-core/src/lib/io/gr_message_sink.i index 8559c1026..a42cb7eca 100644 --- a/gnuradio-core/src/lib/io/gr_message_sink.i +++ b/gnuradio-core/src/lib/io/gr_message_sink.i @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_message_source.cc b/gnuradio-core/src/lib/io/gr_message_source.cc index 4ce0e4292..bf45318de 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.cc +++ b/gnuradio-core/src/lib/io/gr_message_source.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, diff --git a/gnuradio-core/src/lib/io/gr_message_source.h b/gnuradio-core/src/lib/io/gr_message_source.h index 735b3d656..4a1378c2b 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.h +++ b/gnuradio-core/src/lib/io/gr_message_source.h @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_message_source.i b/gnuradio-core/src/lib/io/gr_message_source.i index 961f4d44e..fdc74741e 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.i +++ b/gnuradio-core/src/lib/io/gr_message_source.i @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.cc b/gnuradio-core/src/lib/io/gr_oscope_guts.cc index 286a7d1fb..2272aa0f7 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.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, diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.h b/gnuradio-core/src/lib/io/gr_oscope_guts.h index 0e1d5836f..ee3bbc31e 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.h +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.h @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink.i b/gnuradio-core/src/lib/io/gr_oscope_sink.i index 114c71f34..7802dac8a 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink.i +++ b/gnuradio-core/src/lib/io/gr_oscope_sink.i @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc b/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc index 01c9343b5..5e0e30660 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_f.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, diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_f.h b/gnuradio-core/src/lib/io/gr_oscope_sink_f.h index b07ac615e..620aac374 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_f.h +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_f.h @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_x.cc b/gnuradio-core/src/lib/io/gr_oscope_sink_x.cc index f10b8c552..f2c2d4371 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_x.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_x.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, diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_x.h b/gnuradio-core/src/lib/io/gr_oscope_sink_x.h index d58cf5511..6dc0d6335 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_x.h +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_x.h @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_trigger_mode.h b/gnuradio-core/src/lib/io/gr_trigger_mode.h index dd8030bc2..18d49ecfd 100644 --- a/gnuradio-core/src/lib/io/gr_trigger_mode.h +++ b/gnuradio-core/src/lib/io/gr_trigger_mode.h @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index 7a5d51e0b..2b60c534e 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.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, diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.h b/gnuradio-core/src/lib/io/gr_udp_sink.h index 9263ade79..606dcfc78 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.h +++ b/gnuradio-core/src/lib/io/gr_udp_sink.h @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.i b/gnuradio-core/src/lib/io/gr_udp_sink.i index ad3a452d0..0f37b477b 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.i +++ b/gnuradio-core/src/lib/io/gr_udp_sink.i @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index e12d33b80..fa7d43d1b 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.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, diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h index 5e4a81cb7..70e071e5b 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.h +++ b/gnuradio-core/src/lib/io/gr_udp_source.h @@ -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, diff --git a/gnuradio-core/src/lib/io/gr_udp_source.i b/gnuradio-core/src/lib/io/gr_udp_source.i index 5661f6e7d..fb39dad68 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.i +++ b/gnuradio-core/src/lib/io/gr_udp_source.i @@ -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, diff --git a/gnuradio-core/src/lib/io/gri_logger.cc b/gnuradio-core/src/lib/io/gri_logger.cc index d07793ac5..dbaace689 100644 --- a/gnuradio-core/src/lib/io/gri_logger.cc +++ b/gnuradio-core/src/lib/io/gri_logger.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, diff --git a/gnuradio-core/src/lib/io/gri_logger.h b/gnuradio-core/src/lib/io/gri_logger.h index cc36b1a6c..da54e56a2 100644 --- a/gnuradio-core/src/lib/io/gri_logger.h +++ b/gnuradio-core/src/lib/io/gri_logger.h @@ -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, diff --git a/gnuradio-core/src/lib/io/i2c.cc b/gnuradio-core/src/lib/io/i2c.cc index 9312b5b74..65d426f7f 100644 --- a/gnuradio-core/src/lib/io/i2c.cc +++ b/gnuradio-core/src/lib/io/i2c.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, diff --git a/gnuradio-core/src/lib/io/i2c.h b/gnuradio-core/src/lib/io/i2c.h index 46145455c..e959f59a8 100644 --- a/gnuradio-core/src/lib/io/i2c.h +++ b/gnuradio-core/src/lib/io/i2c.h @@ -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, diff --git a/gnuradio-core/src/lib/io/i2c_bbio.cc b/gnuradio-core/src/lib/io/i2c_bbio.cc index 841ce0d5d..453681d8a 100644 --- a/gnuradio-core/src/lib/io/i2c_bbio.cc +++ b/gnuradio-core/src/lib/io/i2c_bbio.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, diff --git a/gnuradio-core/src/lib/io/i2c_bbio.h b/gnuradio-core/src/lib/io/i2c_bbio.h index 0fca8cf5b..2777e747f 100644 --- a/gnuradio-core/src/lib/io/i2c_bbio.h +++ b/gnuradio-core/src/lib/io/i2c_bbio.h @@ -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, diff --git a/gnuradio-core/src/lib/io/i2c_bbio_pp.cc b/gnuradio-core/src/lib/io/i2c_bbio_pp.cc index c817186c2..fda225ec8 100644 --- a/gnuradio-core/src/lib/io/i2c_bbio_pp.cc +++ b/gnuradio-core/src/lib/io/i2c_bbio_pp.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, diff --git a/gnuradio-core/src/lib/io/i2c_bbio_pp.h b/gnuradio-core/src/lib/io/i2c_bbio_pp.h index d171aa9ea..000b5b91e 100644 --- a/gnuradio-core/src/lib/io/i2c_bbio_pp.h +++ b/gnuradio-core/src/lib/io/i2c_bbio_pp.h @@ -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, diff --git a/gnuradio-core/src/lib/io/i2c_bitbang.cc b/gnuradio-core/src/lib/io/i2c_bitbang.cc index 08fe01f41..401c76b0d 100644 --- a/gnuradio-core/src/lib/io/i2c_bitbang.cc +++ b/gnuradio-core/src/lib/io/i2c_bitbang.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, diff --git a/gnuradio-core/src/lib/io/i2c_bitbang.h b/gnuradio-core/src/lib/io/i2c_bitbang.h index b87a49f99..97c497fbe 100644 --- a/gnuradio-core/src/lib/io/i2c_bitbang.h +++ b/gnuradio-core/src/lib/io/i2c_bitbang.h @@ -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, diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index c6344051e..73a3ad993 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -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, diff --git a/gnuradio-core/src/lib/io/microtune_4702.cc b/gnuradio-core/src/lib/io/microtune_4702.cc index 8d14c7780..01fe450fd 100644 --- a/gnuradio-core/src/lib/io/microtune_4702.cc +++ b/gnuradio-core/src/lib/io/microtune_4702.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, diff --git a/gnuradio-core/src/lib/io/microtune_4702.h b/gnuradio-core/src/lib/io/microtune_4702.h index 4656bd8fb..1f41ee0a1 100644 --- a/gnuradio-core/src/lib/io/microtune_4702.h +++ b/gnuradio-core/src/lib/io/microtune_4702.h @@ -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, diff --git a/gnuradio-core/src/lib/io/microtune_4702_eval_board.cc b/gnuradio-core/src/lib/io/microtune_4702_eval_board.cc index f031290b0..f6c68726b 100644 --- a/gnuradio-core/src/lib/io/microtune_4702_eval_board.cc +++ b/gnuradio-core/src/lib/io/microtune_4702_eval_board.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, diff --git a/gnuradio-core/src/lib/io/microtune_4702_eval_board.h b/gnuradio-core/src/lib/io/microtune_4702_eval_board.h index 754b32683..e0e2f9c65 100644 --- a/gnuradio-core/src/lib/io/microtune_4702_eval_board.h +++ b/gnuradio-core/src/lib/io/microtune_4702_eval_board.h @@ -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, diff --git a/gnuradio-core/src/lib/io/microtune_4702_eval_board.i b/gnuradio-core/src/lib/io/microtune_4702_eval_board.i index fe341bfeb..832a722fa 100644 --- a/gnuradio-core/src/lib/io/microtune_4702_eval_board.i +++ b/gnuradio-core/src/lib/io/microtune_4702_eval_board.i @@ -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, diff --git a/gnuradio-core/src/lib/io/microtune_4937.cc b/gnuradio-core/src/lib/io/microtune_4937.cc index 0f1a08de3..1369df514 100644 --- a/gnuradio-core/src/lib/io/microtune_4937.cc +++ b/gnuradio-core/src/lib/io/microtune_4937.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, diff --git a/gnuradio-core/src/lib/io/microtune_4937.h b/gnuradio-core/src/lib/io/microtune_4937.h index 8294f76fd..2d0f2be6c 100644 --- a/gnuradio-core/src/lib/io/microtune_4937.h +++ b/gnuradio-core/src/lib/io/microtune_4937.h @@ -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, diff --git a/gnuradio-core/src/lib/io/microtune_4937_eval_board.cc b/gnuradio-core/src/lib/io/microtune_4937_eval_board.cc index 782b0091e..f7a586075 100644 --- a/gnuradio-core/src/lib/io/microtune_4937_eval_board.cc +++ b/gnuradio-core/src/lib/io/microtune_4937_eval_board.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, diff --git a/gnuradio-core/src/lib/io/microtune_4937_eval_board.h b/gnuradio-core/src/lib/io/microtune_4937_eval_board.h index a7629859c..c6ab5b84e 100644 --- a/gnuradio-core/src/lib/io/microtune_4937_eval_board.h +++ b/gnuradio-core/src/lib/io/microtune_4937_eval_board.h @@ -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, diff --git a/gnuradio-core/src/lib/io/microtune_4937_eval_board.i b/gnuradio-core/src/lib/io/microtune_4937_eval_board.i index 216561e12..1fe92c0f0 100644 --- a/gnuradio-core/src/lib/io/microtune_4937_eval_board.i +++ b/gnuradio-core/src/lib/io/microtune_4937_eval_board.i @@ -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, diff --git a/gnuradio-core/src/lib/io/microtune_eval_board.i b/gnuradio-core/src/lib/io/microtune_eval_board.i index 088c1957d..3ad7eb61b 100644 --- a/gnuradio-core/src/lib/io/microtune_eval_board.i +++ b/gnuradio-core/src/lib/io/microtune_eval_board.i @@ -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, diff --git a/gnuradio-core/src/lib/io/microtune_eval_board_defs.h b/gnuradio-core/src/lib/io/microtune_eval_board_defs.h index 21f836980..5cba50bdf 100644 --- a/gnuradio-core/src/lib/io/microtune_eval_board_defs.h +++ b/gnuradio-core/src/lib/io/microtune_eval_board_defs.h @@ -14,7 +14,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, diff --git a/gnuradio-core/src/lib/io/microtune_xxxx.cc b/gnuradio-core/src/lib/io/microtune_xxxx.cc index ad714735e..f9ce44b2b 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx.cc +++ b/gnuradio-core/src/lib/io/microtune_xxxx.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, diff --git a/gnuradio-core/src/lib/io/microtune_xxxx.h b/gnuradio-core/src/lib/io/microtune_xxxx.h index 36d5be323..554503561 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx.h +++ b/gnuradio-core/src/lib/io/microtune_xxxx.h @@ -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, diff --git a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc index 0530ff121..668f04cad 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc +++ b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.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, diff --git a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h index 80c47aa8a..18e50d60c 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h +++ b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h @@ -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, diff --git a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i index d9bf17a70..d6000ea08 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i +++ b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i @@ -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, diff --git a/gnuradio-core/src/lib/io/ppio.cc b/gnuradio-core/src/lib/io/ppio.cc index a608b58cf..9f0ed62de 100644 --- a/gnuradio-core/src/lib/io/ppio.cc +++ b/gnuradio-core/src/lib/io/ppio.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, diff --git a/gnuradio-core/src/lib/io/ppio.h b/gnuradio-core/src/lib/io/ppio.h index ba2301e38..da5ba70ce 100644 --- a/gnuradio-core/src/lib/io/ppio.h +++ b/gnuradio-core/src/lib/io/ppio.h @@ -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, diff --git a/gnuradio-core/src/lib/io/ppio.i b/gnuradio-core/src/lib/io/ppio.i index e9ac7542a..8d9571e28 100644 --- a/gnuradio-core/src/lib/io/ppio.i +++ b/gnuradio-core/src/lib/io/ppio.i @@ -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, diff --git a/gnuradio-core/src/lib/io/ppio_ppdev.cc b/gnuradio-core/src/lib/io/ppio_ppdev.cc index 27a8e3352..61591ad1b 100644 --- a/gnuradio-core/src/lib/io/ppio_ppdev.cc +++ b/gnuradio-core/src/lib/io/ppio_ppdev.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, diff --git a/gnuradio-core/src/lib/io/ppio_ppdev.h b/gnuradio-core/src/lib/io/ppio_ppdev.h index abf27e3cc..d5acfefc0 100644 --- a/gnuradio-core/src/lib/io/ppio_ppdev.h +++ b/gnuradio-core/src/lib/io/ppio_ppdev.h @@ -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, diff --git a/gnuradio-core/src/lib/io/sdr_1000.cc b/gnuradio-core/src/lib/io/sdr_1000.cc index 1687a75ee..df26237ef 100644 --- a/gnuradio-core/src/lib/io/sdr_1000.cc +++ b/gnuradio-core/src/lib/io/sdr_1000.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, diff --git a/gnuradio-core/src/lib/io/sdr_1000.h b/gnuradio-core/src/lib/io/sdr_1000.h index f55b68912..2867c1ba9 100644 --- a/gnuradio-core/src/lib/io/sdr_1000.h +++ b/gnuradio-core/src/lib/io/sdr_1000.h @@ -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, diff --git a/gnuradio-core/src/lib/io/sdr_1000.i b/gnuradio-core/src/lib/io/sdr_1000.i index b19c6a3e8..fbdef85e5 100644 --- a/gnuradio-core/src/lib/io/sdr_1000.i +++ b/gnuradio-core/src/lib/io/sdr_1000.i @@ -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 7b14a03f48984d20d0ff969eaa327078cd2773cb Mon Sep 17 00:00:00 2001 From: eb Date: Wed, 16 Jan 2008 20:38:04 +0000 Subject: Merged -r7436:7453 eb/freebsd into trunk. This is a part of a set of patches from Diane Bruce for FreeBSD. Still need to resolve the issue of where/how to include config.h in all swig code and how to select wx version on systems with more than one version installed. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@7454 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/gr_udp_sink.cc | 5 +- gnuradio-core/src/lib/io/gr_udp_sink.h | 10 +- gnuradio-core/src/lib/io/gr_udp_source.cc | 5 +- gnuradio-core/src/lib/io/gr_udp_source.h | 8 +- gnuradio-core/src/lib/io/ppio_ppdev.cc | 184 +++++++++++++++++++++++------- 5 files changed, 162 insertions(+), 50 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index 2b60c534e..15bcf9a83 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007 Free Software Foundation, Inc. + * Copyright 2007,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -20,6 +20,9 @@ * Boston, MA 02110-1301, USA. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include #include #include diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.h b/gnuradio-core/src/lib/io/gr_udp_sink.h index 606dcfc78..4f08136ec 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.h +++ b/gnuradio-core/src/lib/io/gr_udp_sink.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007 Free Software Foundation, Inc. + * Copyright 2007,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -27,6 +27,10 @@ #include #include #include +#include +#if defined(HAVE_NETINET_IN_H) +#include +#endif class gr_udp_sink; typedef boost::shared_ptr gr_udp_sink_sptr; @@ -70,8 +74,8 @@ class gr_udp_sink : public gr_sync_block struct in_addr d_ip_dst; // store the destination ip info unsigned short d_port_src; // the port number to open for connections to this service unsigned short d_port_dst; // port number of the remove system - sockaddr_in d_sockaddr_src; // store the source sockaddr data (formatted IP address and port number) - sockaddr_in d_sockaddr_dst; // store the destination sockaddr data (formatted IP address and port number) + struct sockaddr_in d_sockaddr_src; // store the source sockaddr data (formatted IP address and port number) + struct sockaddr_in d_sockaddr_dst; // store the destination sockaddr data (formatted IP address and port number) protected: /*! diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index fa7d43d1b..f7f04d3cf 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007 Free Software Foundation, Inc. + * Copyright 2007,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -20,6 +20,9 @@ * Boston, MA 02110-1301, USA. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include #include #include diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h index 70e071e5b..83bebf84d 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.h +++ b/gnuradio-core/src/lib/io/gr_udp_source.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007 Free Software Foundation, Inc. + * Copyright 2007,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -27,6 +27,9 @@ #include #include #include +#if defined(HAVE_NETINET_IN_H) +#include +#endif class gr_udp_source; typedef boost::shared_ptr gr_udp_source_sptr; @@ -62,8 +65,7 @@ class gr_udp_source : public gr_sync_block int d_socket_rcv; // handle to socket retuned in the accept call struct in_addr d_ip_src; // store the source IP address to use unsigned short d_port_src; // the port number to open for connections to this service - sockaddr_in d_sockaddr_src; // store the source sockaddr data (formatted IP address and port number) - + struct sockaddr_in d_sockaddr_src; // store the source sockaddr data (formatted IP address and port number) char *d_temp_buff; // hold buffer between calls ssize_t d_residual; // hold information about number of bytes stored in the temp buffer size_t d_temp_offset; // point to temp buffer location offset diff --git a/gnuradio-core/src/lib/io/ppio_ppdev.cc b/gnuradio-core/src/lib/io/ppio_ppdev.cc index 61591ad1b..074de1aa1 100644 --- a/gnuradio-core/src/lib/io/ppio_ppdev.cc +++ b/gnuradio-core/src/lib/io/ppio_ppdev.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2001,2003,2004 Free Software Foundation, Inc. + * Copyright 2001,2003,2004,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -32,11 +32,16 @@ #include #include #include -#ifdef HAVE_LINUX_PPDEV_H +#if defined(HAVE_LINUX_PPDEV_H) #include #include #include #include +#elif defined(HAVE_DEV_PPBUS_PPI_H) +#include +#include +#include +#include #else // #warn "ppio_ppdev is not functional on this platform" #endif @@ -53,84 +58,138 @@ static int CP_ACTIVE_LOW_BITS = 0x0B; static int SP_ACTIVE_LOW_BITS = 0x80; -#ifndef HAVE_LINUX_PPDEV_H // use stubs +#if defined(HAVE_LINUX_PPDEV_H) + +// The real Linux code... ppio_ppdev::ppio_ppdev (int which) { - std::cerr << "ppio_ppdev: Not implemented on this platform\n"; - throw std::runtime_error ("not implmeneted"); + std::ostringstream filename; + filename << "/dev/parport" << which; + const char *c_filename = filename.str().c_str(); + + if ((d_fd = open (c_filename, O_RDWR)) < 0){ + int my_errno = errno; + perror (c_filename); + if (my_errno == ENOENT){ + std::cerr << "Does the device file " << c_filename << " exist?\n"; + std::cerr << "If not, as root execute: \n"; + std::cerr << " # mknod " << c_filename << " c 99 0\n"; + std::cerr << " # chmod 666 " << c_filename << std::endl; + } + throw std::runtime_error ("open"); + } + + int mode = IEEE1284_MODE_COMPAT; + if (ioctl (d_fd, PPSETMODE, &mode) != 0){ + perror ("ppio_ppdev: PPSETMODE"); + close (d_fd); + throw std::runtime_error ("PPSETMODE"); + } } ppio_ppdev::~ppio_ppdev () { + close (d_fd); } + void ppio_ppdev::write_data (unsigned char v) { + if (ioctl (d_fd, PPWDATA, &v) != 0){ + perror ("ppio_ppdev: PPWDATA"); + throw std::runtime_error ("PPWDATA"); + } } unsigned char ppio_ppdev::read_data () { - return 0; + unsigned char v; + + if (ioctl (d_fd, PPRDATA, &v) != 0){ + perror ("ppio_ppdev: PPRDATA"); + throw std::runtime_error ("PPRDATA"); + } + return v; } void ppio_ppdev::write_control (unsigned char v) { + unsigned char ctrl = v ^ CP_ACTIVE_LOW_BITS; + if (ioctl (d_fd, PPWCONTROL, &ctrl) != 0){ + perror ("ppio_ppdev: PPWCONTROL"); + throw std::runtime_error ("PPWCONTROL"); + } } unsigned char ppio_ppdev::read_control () { - return 0; + unsigned char ctrl; + if (ioctl (d_fd, PPRCONTROL, &ctrl) != 0){ + perror ("ppio_ppdev: PPRCONTROL"); + throw std::runtime_error ("PPRCONTROL"); + } + + return ctrl ^ CP_ACTIVE_LOW_BITS; } unsigned char ppio_ppdev::read_status () { - return 0; + unsigned char status; + if (ioctl (d_fd, PPRSTATUS, &status) != 0){ + perror ("ppio_ppdev: PPRSTATUS"); + throw std::runtime_error ("PPRSTATUS"); + } + + return status ^ SP_ACTIVE_LOW_BITS; } void ppio_ppdev::lock () { + if (ioctl (d_fd, PPCLAIM) != 0){ + perror ("ppio_ppdev: PPCLAIM"); + throw std::runtime_error ("PPCLAIM"); + } } void ppio_ppdev::unlock () { + if (ioctl (d_fd, PPRELEASE) != 0){ + perror ("ppio_ppdev: PPRELEASE"); + throw std::runtime_error ("PPRELEASE"); + } } -#else +#elif defined(HAVE_DEV_PPBUS_PPI_H) -// The real code... +// The real FreeBSD code... (Could work on other BSDs as well) ppio_ppdev::ppio_ppdev (int which) { std::ostringstream filename; - filename << "/dev/parport" << which; + filename << "/dev/ppi" << which; const char *c_filename = filename.str().c_str(); - if ((d_fd = open (c_filename, O_RDWR)) < 0){ int my_errno = errno; perror (c_filename); - if (my_errno == ENOENT){ - std::cerr << "Does the device file " << c_filename << " exist?\n"; - std::cerr << "If not, as root execute: \n"; - std::cerr << " # mknod " << c_filename << " c 99 0\n"; - std::cerr << " # chmod 666 " << c_filename << std::endl; - } throw std::runtime_error ("open"); } +#if 0 int mode = IEEE1284_MODE_COMPAT; if (ioctl (d_fd, PPSETMODE, &mode) != 0){ perror ("ppio_ppdev: PPSETMODE"); close (d_fd); throw std::runtime_error ("PPSETMODE"); } +#endif } ppio_ppdev::~ppio_ppdev () @@ -142,9 +201,9 @@ ppio_ppdev::~ppio_ppdev () void ppio_ppdev::write_data (unsigned char v) { - if (ioctl (d_fd, PPWDATA, &v) != 0){ - perror ("ppio_ppdev: PPWDATA"); - throw std::runtime_error ("PPWDATA"); + if (ioctl (d_fd, PPISDATA, &v) != 0){ + perror ("ppio_ppdev: PPISDATA"); + throw std::runtime_error ("PPISDATA"); } } @@ -153,9 +212,9 @@ ppio_ppdev::read_data () { unsigned char v; - if (ioctl (d_fd, PPRDATA, &v) != 0){ - perror ("ppio_ppdev: PPRDATA"); - throw std::runtime_error ("PPRDATA"); + if (ioctl (d_fd, PPIGDATA, &v) != 0){ + perror ("ppio_ppdev: PPIGDATA"); + throw std::runtime_error ("PPIGDATA"); } return v; } @@ -164,9 +223,9 @@ void ppio_ppdev::write_control (unsigned char v) { unsigned char ctrl = v ^ CP_ACTIVE_LOW_BITS; - if (ioctl (d_fd, PPWCONTROL, &ctrl) != 0){ - perror ("ppio_ppdev: PPWCONTROL"); - throw std::runtime_error ("PPWCONTROL"); + if (ioctl (d_fd, PPISCTRL, &ctrl) != 0){ + perror ("ppio_ppdev: PPISCTRL"); + throw std::runtime_error ("PPISCTRL"); } } @@ -174,9 +233,9 @@ unsigned char ppio_ppdev::read_control () { unsigned char ctrl; - if (ioctl (d_fd, PPRCONTROL, &ctrl) != 0){ - perror ("ppio_ppdev: PPRCONTROL"); - throw std::runtime_error ("PPRCONTROL"); + if (ioctl (d_fd, PPIGCTRL, &ctrl) != 0){ + perror ("ppio_ppdev: PPIGCTRL"); + throw std::runtime_error ("PPIGCTRL"); } return ctrl ^ CP_ACTIVE_LOW_BITS; @@ -186,30 +245,71 @@ unsigned char ppio_ppdev::read_status () { unsigned char status; - if (ioctl (d_fd, PPRSTATUS, &status) != 0){ - perror ("ppio_ppdev: PPRSTATUS"); - throw std::runtime_error ("PPRSTATUS"); + if (ioctl (d_fd, PPIGSTATUS, &status) != 0){ + perror ("ppio_ppdev: PPIGSTATUS"); + throw std::runtime_error ("PPIGSTATUS"); } - return status ^ SP_ACTIVE_LOW_BITS; } void ppio_ppdev::lock () { - if (ioctl (d_fd, PPCLAIM) != 0){ - perror ("ppio_ppdev: PPCLAIM"); - throw std::runtime_error ("PPCLAIM"); - } } void ppio_ppdev::unlock () { - if (ioctl (d_fd, PPRELEASE) != 0){ - perror ("ppio_ppdev: PPRELEASE"); - throw std::runtime_error ("PPRELEASE"); - } +} +#else +/* Apparently, non real code */ + +ppio_ppdev::ppio_ppdev (int which) +{ + std::cerr << "ppio_ppdev: Not implemented on this platform\n"; + throw std::runtime_error ("not implmeneted"); +} + +ppio_ppdev::~ppio_ppdev () +{ +} + +void +ppio_ppdev::write_data (unsigned char v) +{ +} + +unsigned char +ppio_ppdev::read_data () +{ + return 0; +} + +void +ppio_ppdev::write_control (unsigned char v) +{ +} + +unsigned char +ppio_ppdev::read_control () +{ + return 0; +} + +unsigned char +ppio_ppdev::read_status () +{ + return 0; +} + +void +ppio_ppdev::lock () +{ +} + +void +ppio_ppdev::unlock () +{ } #endif -- cgit From cda71d951ef0cb2126719fed029d459b23a02fe9 Mon Sep 17 00:00:00 2001 From: eb Date: Thu, 24 Jan 2008 16:29:09 +0000 Subject: Doc fixes from Firas. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@7504 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/i2c_bbio.h | 1 + gnuradio-core/src/lib/io/i2c_bbio_pp.h | 1 + gnuradio-core/src/lib/io/i2c_bitbang.h | 1 + gnuradio-core/src/lib/io/microtune_4702.h | 1 + gnuradio-core/src/lib/io/microtune_4702_eval_board.h | 1 + gnuradio-core/src/lib/io/microtune_4937.h | 1 + gnuradio-core/src/lib/io/microtune_4937_eval_board.h | 1 + gnuradio-core/src/lib/io/microtune_xxxx.h | 1 + gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h | 1 + gnuradio-core/src/lib/io/ppio.h | 1 + gnuradio-core/src/lib/io/ppio_ppdev.h | 1 + gnuradio-core/src/lib/io/sdr_1000.h | 1 + 12 files changed, 12 insertions(+) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/i2c_bbio.h b/gnuradio-core/src/lib/io/i2c_bbio.h index 2777e747f..c6b226e39 100644 --- a/gnuradio-core/src/lib/io/i2c_bbio.h +++ b/gnuradio-core/src/lib/io/i2c_bbio.h @@ -31,6 +31,7 @@ typedef boost::shared_ptr i2c_bbio_sptr; /*! * \brief abstract class that implements bit banging i/o for i2c bus. + * \ingroup base */ class i2c_bbio { public: diff --git a/gnuradio-core/src/lib/io/i2c_bbio_pp.h b/gnuradio-core/src/lib/io/i2c_bbio_pp.h index 000b5b91e..5a99cdcd1 100644 --- a/gnuradio-core/src/lib/io/i2c_bbio_pp.h +++ b/gnuradio-core/src/lib/io/i2c_bbio_pp.h @@ -29,6 +29,7 @@ /*! * \brief concrete class that bit bangs eval board i2c bus using parallel port * + * \ingroup base * This class talks to the i2c bus on the microtune eval board using * the parallel port. This works for both the 4937 and 4702 boards. */ diff --git a/gnuradio-core/src/lib/io/i2c_bitbang.h b/gnuradio-core/src/lib/io/i2c_bitbang.h index 97c497fbe..c9deb38ba 100644 --- a/gnuradio-core/src/lib/io/i2c_bitbang.h +++ b/gnuradio-core/src/lib/io/i2c_bitbang.h @@ -28,6 +28,7 @@ /*! * \brief class for controlling i2c bus + * \ingroup base */ class i2c_bitbang : public i2c { friend i2c_sptr make_i2c_bitbang (i2c_bbio_sptr io); diff --git a/gnuradio-core/src/lib/io/microtune_4702.h b/gnuradio-core/src/lib/io/microtune_4702.h index 1f41ee0a1..95c64abe7 100644 --- a/gnuradio-core/src/lib/io/microtune_4702.h +++ b/gnuradio-core/src/lib/io/microtune_4702.h @@ -27,6 +27,7 @@ /*! * \brief class for controlling microtune 4702 tuner module + * \ingroup hardware */ class microtune_4702 : public microtune_xxxx { diff --git a/gnuradio-core/src/lib/io/microtune_4702_eval_board.h b/gnuradio-core/src/lib/io/microtune_4702_eval_board.h index e0e2f9c65..6e9726917 100644 --- a/gnuradio-core/src/lib/io/microtune_4702_eval_board.h +++ b/gnuradio-core/src/lib/io/microtune_4702_eval_board.h @@ -27,6 +27,7 @@ /*! * \brief control microtune 4702 eval board + * \ingroup hardware */ class microtune_4702_eval_board : public microtune_xxxx_eval_board { diff --git a/gnuradio-core/src/lib/io/microtune_4937.h b/gnuradio-core/src/lib/io/microtune_4937.h index 2d0f2be6c..b263ceb0f 100644 --- a/gnuradio-core/src/lib/io/microtune_4937.h +++ b/gnuradio-core/src/lib/io/microtune_4937.h @@ -27,6 +27,7 @@ /*! * \brief class for controlling microtune 4937 tuner module + * \ingroup hardware */ class microtune_4937 : public microtune_xxxx { public: diff --git a/gnuradio-core/src/lib/io/microtune_4937_eval_board.h b/gnuradio-core/src/lib/io/microtune_4937_eval_board.h index c6ab5b84e..154a7281a 100644 --- a/gnuradio-core/src/lib/io/microtune_4937_eval_board.h +++ b/gnuradio-core/src/lib/io/microtune_4937_eval_board.h @@ -27,6 +27,7 @@ /*! * \brief control microtune 4937 eval board + * \ingroup hardware */ class microtune_4937_eval_board : public microtune_xxxx_eval_board { diff --git a/gnuradio-core/src/lib/io/microtune_xxxx.h b/gnuradio-core/src/lib/io/microtune_xxxx.h index 554503561..4d5074a85 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx.h +++ b/gnuradio-core/src/lib/io/microtune_xxxx.h @@ -30,6 +30,7 @@ typedef boost::shared_ptr i2c_sptr; /*! * \brief abstract class for controlling microtune {4937,4702} tuner modules + * \ingroup base */ class microtune_xxxx { public: diff --git a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h index 18e50d60c..808075e55 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h +++ b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h @@ -35,6 +35,7 @@ typedef boost::shared_ptr i2c_sptr; /*! * \brief abstract class for controlling microtune xxxx eval board + * \ingroup hardware */ class microtune_xxxx_eval_board { public: diff --git a/gnuradio-core/src/lib/io/ppio.h b/gnuradio-core/src/lib/io/ppio.h index da5ba70ce..e1a62e2a3 100644 --- a/gnuradio-core/src/lib/io/ppio.h +++ b/gnuradio-core/src/lib/io/ppio.h @@ -31,6 +31,7 @@ typedef boost::shared_ptr ppio_sptr; /*! * \brief abstract class that provides low level access to parallel port bits + * \ingroup hardware */ class ppio { diff --git a/gnuradio-core/src/lib/io/ppio_ppdev.h b/gnuradio-core/src/lib/io/ppio_ppdev.h index d5acfefc0..b5abe3f0a 100644 --- a/gnuradio-core/src/lib/io/ppio_ppdev.h +++ b/gnuradio-core/src/lib/io/ppio_ppdev.h @@ -30,6 +30,7 @@ typedef boost::shared_ptr ppio_ppdev_sptr; /*! * \brief access to parallel port bits using the linux ppdev interface + * \ingroup hardware */ class ppio_ppdev : public ppio { diff --git a/gnuradio-core/src/lib/io/sdr_1000.h b/gnuradio-core/src/lib/io/sdr_1000.h index 2867c1ba9..113e85deb 100644 --- a/gnuradio-core/src/lib/io/sdr_1000.h +++ b/gnuradio-core/src/lib/io/sdr_1000.h @@ -34,6 +34,7 @@ enum { L_EXT = 0, L_BAND = 1, L_DDS0 = 2, L_DDS1 = 3 }; /*! * \brief Very low level interface to SDR 1000 xcvr hardware * \sa sdr_1000.py for a higher level interface. + * \ingroup hardware */ class sdr_1000_base { ppio_sptr d_ppio; -- cgit From 42d9c6f495503d3d9d2db47a9979036c9233f976 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Fri, 8 Feb 2008 23:32:10 +0000 Subject: Merged r7478:7608 from michaelld/t186 into trunk. Adds ability to compile GNU Radio modules individually, using already installed dependent libraries and include files. New functionality is enabled using --with-* on configure command line; existing build options should remain unchanged. Nice work by Michael Dickens, still needs documentation update on wiki. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@7617 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index 626ddb07a..fb527da73 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2001,2003,2004,2006,2007 Free Software Foundation, Inc. +# Copyright 2001,2003,2004,2006,2007,2008 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -22,7 +22,7 @@ include $(top_srcdir)/Makefile.common -INCLUDES = $(STD_DEFINES_AND_INCLUDES) +INCLUDES = $(STD_DEFINES_AND_INCLUDES) $(WITH_INCLUDES) noinst_LTLIBRARIES = libio.la -- cgit From e7fda5b546fb804a735b7880530b76018519faa6 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Mon, 18 Feb 2008 06:27:50 +0000 Subject: Merged -r7723:7729 from jcorgan/wav into trunk, with added example program. Adds Martin Braun's gr.wavfile_source and gr.wavfile_sink blocks. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@7730 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/Makefile.am | 17 +- gnuradio-core/src/lib/io/gr_wavfile_sink.cc | 278 +++++++++++++++++++++++ gnuradio-core/src/lib/io/gr_wavfile_sink.h | 137 +++++++++++ gnuradio-core/src/lib/io/gr_wavfile_sink.i | 47 ++++ gnuradio-core/src/lib/io/gr_wavfile_source.cc | 172 ++++++++++++++ gnuradio-core/src/lib/io/gr_wavfile_source.h | 93 ++++++++ gnuradio-core/src/lib/io/gr_wavfile_source.i | 42 ++++ gnuradio-core/src/lib/io/gri_wavfile.cc | 312 ++++++++++++++++++++++++++ gnuradio-core/src/lib/io/gri_wavfile.h | 100 +++++++++ gnuradio-core/src/lib/io/io.i | 4 + 10 files changed, 1199 insertions(+), 3 deletions(-) create mode 100644 gnuradio-core/src/lib/io/gr_wavfile_sink.cc create mode 100644 gnuradio-core/src/lib/io/gr_wavfile_sink.h create mode 100644 gnuradio-core/src/lib/io/gr_wavfile_sink.i create mode 100644 gnuradio-core/src/lib/io/gr_wavfile_source.cc create mode 100644 gnuradio-core/src/lib/io/gr_wavfile_source.h create mode 100644 gnuradio-core/src/lib/io/gr_wavfile_source.i create mode 100644 gnuradio-core/src/lib/io/gri_wavfile.cc create mode 100644 gnuradio-core/src/lib/io/gri_wavfile.h (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index fb527da73..c94683735 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -53,7 +53,10 @@ libio_la_SOURCES = \ ppio_ppdev.cc \ sdr_1000.cc \ gr_udp_sink.cc \ - gr_udp_source.cc + gr_udp_source.cc \ + gr_wavfile_sink.cc \ + gr_wavfile_source.cc \ + gri_wavfile.cc grinclude_HEADERS = \ gr_file_sink.h \ @@ -83,7 +86,12 @@ grinclude_HEADERS = \ ppio_ppdev.h \ sdr_1000.h \ gr_udp_sink.h \ - gr_udp_source.h + gr_udp_source.h \ + gr_wavfile_source.h \ + gr_wavfile_sink.h \ + gri_wavfile.h + + swiginclude_HEADERS = \ @@ -102,4 +110,7 @@ swiginclude_HEADERS = \ ppio.i \ sdr_1000.i \ gr_udp_sink.i \ - gr_udp_source.i + gr_udp_source.i \ + gr_wavfile_source.i \ + gr_wavfile_sink.i + diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc new file mode 100644 index 000000000..f06c33d5c --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc @@ -0,0 +1,278 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2006,2007,2008 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, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +// win32 (mingw/msvc) specific +#ifdef HAVE_IO_H +#include +#endif +#ifdef O_BINARY +#define OUR_O_BINARY O_BINARY +#else +#define OUR_O_BINARY 0 +#endif + +// should be handled via configure +#ifdef O_LARGEFILE +#define OUR_O_LARGEFILE O_LARGEFILE +#else +#define OUR_O_LARGEFILE 0 +#endif + + +gr_wavfile_sink_sptr +gr_make_wavfile_sink(const char *filename, + int n_channels, + unsigned int sample_rate, + int bits_per_sample) +{ + return gr_wavfile_sink_sptr (new gr_wavfile_sink (filename, + n_channels, + sample_rate, + bits_per_sample)); +} + +gr_wavfile_sink::gr_wavfile_sink(const char *filename, + int n_channels, + unsigned int sample_rate, + int bits_per_sample) + : gr_sync_block ("wavfile_sink", + gr_make_io_signature(1, n_channels, sizeof(float)), + gr_make_io_signature(0, 0, 0)), + d_sample_rate(sample_rate), d_nchans(n_channels), + d_fp(0), d_new_fp(0), d_updated(false) +{ + if (bits_per_sample != 8 && bits_per_sample != 16) { + throw std::runtime_error("Invalid bits per sample (supports 8 and 16)"); + } + d_bytes_per_sample = bits_per_sample / 8; + d_bytes_per_sample_new = d_bytes_per_sample; + + if (!open(filename)) { + throw std::runtime_error ("can't open file"); + } + + if (bits_per_sample == 8) { + d_max_sample_val = 0xFF; + d_min_sample_val = 0; + d_normalize_fac = d_max_sample_val/2; + d_normalize_shift = 1; + } else { + d_max_sample_val = 0x7FFF; + d_min_sample_val = -0x7FFF; + d_normalize_fac = d_max_sample_val; + d_normalize_shift = 0; + if (bits_per_sample != 16) { + fprintf(stderr, "Invalid bits per sample value requested, using 16"); + } + } +} + + +bool +gr_wavfile_sink::open(const char* filename) +{ + omni_mutex_lock l(d_mutex); + + // we use the open system call to get access to the O_LARGEFILE flag. + int fd; + if ((fd = ::open (filename, + O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY, + 0664)) < 0){ + perror (filename); + return false; + } + + if (d_new_fp) { // if we've already got a new one open, close it + fclose(d_new_fp); + d_new_fp = 0; + } + + if ((d_new_fp = fdopen (fd, "wb")) == NULL) { + perror (filename); + ::close(fd); // don't leak file descriptor if fdopen fails. + return false; + } + d_updated = true; + + if (!gri_wavheader_write(d_new_fp, + d_sample_rate, + d_nchans, + d_bytes_per_sample_new)) { + fprintf(stderr, "[%s] could not write to WAV file\n", __FILE__); + exit(-1); + } + + return true; +} + + +void +gr_wavfile_sink::close() +{ + omni_mutex_lock l(d_mutex); + + if (!d_fp) + return; + + close_wav(); +} + +void gr_wavfile_sink::close_wav() +{ + unsigned int byte_count = d_sample_count * d_bytes_per_sample; + + gri_wavheader_complete(d_fp, byte_count); + + fclose(d_fp); + d_fp = NULL; +} + + +gr_wavfile_sink::~gr_wavfile_sink () +{ + if (d_new_fp) { + fclose(d_new_fp); + } + + close(); +} + + +int +gr_wavfile_sink::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + float **in = (float **) &input_items[0]; + int n_in_chans = input_items.size(); + + short int sample_buf_s; + + int nwritten; + + do_update(); // update: d_fp is reqd + if (!d_fp) // drop output on the floor + return noutput_items; + + for (nwritten = 0; nwritten < noutput_items; nwritten++) { + for (int chan = 0; chan < d_nchans; chan++) { + // Write zeros to channels which are in the WAV file + // but don't have any inputs here + if (chan < n_in_chans) { + sample_buf_s = + convert_to_short(in[chan][nwritten]); + } else { + sample_buf_s = 0; + } + + gri_wav_write_sample(d_fp, sample_buf_s, d_bytes_per_sample); + + if (feof(d_fp) || ferror(d_fp)) { + fprintf(stderr, "[%s] file i/o error\n", __FILE__); + close(); + exit(-1); + } + d_sample_count++; + } + } + + return nwritten; +} + + +short int +gr_wavfile_sink::convert_to_short(float sample) +{ + sample += d_normalize_shift; + sample *= d_normalize_fac; + if (sample > d_max_sample_val) { + sample = d_max_sample_val; + } else if (sample < d_min_sample_val) { + sample = d_min_sample_val; + } + + return (short int) roundf(sample); +} + + +void +gr_wavfile_sink::set_bits_per_sample(int bits_per_sample) +{ + omni_mutex_lock l(d_mutex); + if (bits_per_sample == 8 || bits_per_sample == 16) { + d_bytes_per_sample_new = bits_per_sample / 8; + } +} + + +void +gr_wavfile_sink::set_sample_rate(unsigned int sample_rate) +{ + omni_mutex_lock l(d_mutex); + d_sample_rate = sample_rate; +} + + +void +gr_wavfile_sink::do_update() +{ + if (!d_updated) { + return; + } + + omni_mutex_lock l(d_mutex); // hold mutex for duration of this block + if (d_fp) { + close_wav(); + } + + d_fp = d_new_fp; // install new file pointer + d_new_fp = 0; + d_sample_count = 0; + d_bytes_per_sample = d_bytes_per_sample_new; + + if (d_bytes_per_sample == 1) { + d_max_sample_val = UCHAR_MAX; + d_min_sample_val = 0; + d_normalize_fac = d_max_sample_val/2; + d_normalize_shift = 1; + } else if (d_bytes_per_sample == 2) { + d_max_sample_val = SHRT_MAX; + d_min_sample_val = SHRT_MIN; + d_normalize_fac = d_max_sample_val; + d_normalize_shift = 0; + } + + d_updated = false; +} diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.h b/gnuradio-core/src/lib/io/gr_wavfile_sink.h new file mode 100644 index 000000000..3fa06f202 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.h @@ -0,0 +1,137 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 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, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_WAVFILE_SINK_H +#define INCLUDED_GR_WAVFILE_SINK_H + +#include +#include +#include + +class gr_wavfile_sink; +typedef boost::shared_ptr gr_wavfile_sink_sptr; + +/* + * \p filename The .wav file to be opened + * \p n_channels Number of channels (2 = stereo or I/Q output) + * \p sample_rate Sample rate [S/s] + * \p bits_per_sample 16 or 8 bit, default is 16 + */ +gr_wavfile_sink_sptr +gr_make_wavfile_sink (const char *filename, + int n_channels, + unsigned int sample_rate, + int bits_per_sample = 16); + +/*! + * \brief Read stream from a Microsoft PCM (.wav) file, output floats + * + * Values are within [-1;1]. + * Check gr_make_wavfile_source() for extra info. + * + * \ingroup sink + */ +class gr_wavfile_sink : public gr_sync_block +{ +private: + friend gr_wavfile_sink_sptr gr_make_wavfile_sink (const char *filename, + int n_channels, + unsigned int sample_rate, + int bits_per_sample); + + gr_wavfile_sink(const char *filename, + int n_channels, + unsigned int sample_rate, + int bits_per_sample); + + unsigned d_sample_rate; + int d_nchans; + unsigned d_sample_count; + int d_bytes_per_sample; + int d_bytes_per_sample_new; + int d_max_sample_val; + int d_min_sample_val; + int d_normalize_shift; + int d_normalize_fac; + + FILE *d_fp; + FILE *d_new_fp; + bool d_updated; + omni_mutex d_mutex; + + /*! + * \brief Convert a sample value within [-1;+1] to a corresponding + * short integer value + */ + short convert_to_short(float sample); + + /*! + * \brief Writes information to the WAV header which is not available + * a-priori (chunk size etc.) and closes the file. Not thread-safe and + * assumes d_fp is a valid file pointer, should thus only be called by + * other methods. + */ + void close_wav(); + +public: + ~gr_wavfile_sink (); + + /*! + * \brief Opens a new file and writes a WAV header. Thread-safe. + */ + bool open(const char* filename); + + /*! + * \brief Closes the currently active file and completes the WAV + * header. Thread-safe. + */ + void close(); + + /*! + * \brief If any file changes have occurred, update now. This is called + * internally by work() and thus doesn't usually need to be called by + * hand. + */ + void do_update(); + + /*! + * \brief Set the sample rate. This will not affect the WAV file + * currently opened. Any following open() calls will use this new + * sample rate. + */ + void set_sample_rate(unsigned int sample_rate); + + /*! + * \brief Set bits per sample. This will not affect the WAV file + * currently opened (see set_sample_rate()). If the value is neither + * 8 nor 16, the call is ignored and the current value is kept. + */ + void set_bits_per_sample(int bits_per_sample); + + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + +}; + +#endif /* INCLUDED_GR_WAVFILE_SINK_H */ diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.i b/gnuradio-core/src/lib/io/gr_wavfile_sink.i new file mode 100644 index 000000000..7ccad1978 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.i @@ -0,0 +1,47 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 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, + * Boston, MA 02110-1301, USA. + */ + + +GR_SWIG_BLOCK_MAGIC(gr,wavfile_sink); + +gr_wavfile_sink_sptr +gr_make_wavfile_sink (const char *filename, + int n_channels, + unsigned int sample_rate, + int bits_per_sample = 16) throw (std::runtime_error); + +class gr_wavfile_sink : public gr_sync_block +{ +protected: + gr_wavfile_sink(const char *filename, + int n_channels, + unsigned int sample_rate, + int bits_per_sample) throw (std::runtime_error); + +public: + ~gr_wavfile_sink (); + bool open(const char* filename); + void close(); + void set_sample_rate(unsigned int sample_rate); + void set_bits_per_sample(int bits_per_sample); +}; + diff --git a/gnuradio-core/src/lib/io/gr_wavfile_source.cc b/gnuradio-core/src/lib/io/gr_wavfile_source.cc new file mode 100644 index 000000000..900f84efd --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_wavfile_source.cc @@ -0,0 +1,172 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2008 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, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include + +// win32 (mingw/msvc) specific +#ifdef HAVE_IO_H +#include +#endif +#ifdef O_BINARY +#define OUR_O_BINARY O_BINARY +#else +#define OUR_O_BINARY 0 +#endif +// should be handled via configure +#ifdef O_LARGEFILE +#define OUR_O_LARGEFILE O_LARGEFILE +#else +#define OUR_O_LARGEFILE 0 +#endif + + +gr_wavfile_source_sptr +gr_make_wavfile_source (const char *filename, bool repeat) +{ + return gr_wavfile_source_sptr (new gr_wavfile_source (filename, repeat)); +} + + +gr_wavfile_source::gr_wavfile_source (const char *filename, bool repeat) + : gr_sync_block ("wavfile_source", + gr_make_io_signature (0, 0, 0), + gr_make_io_signature (1, 2, sizeof(float))), + d_fp(NULL), d_repeat(repeat), + d_sample_rate(1), d_nchans(1), d_bytes_per_sample(2), d_first_sample_pos(0), + d_samples_per_chan(0), d_sample_idx(0) +{ + // we use "open" to use to the O_LARGEFILE flag + + int fd; + if ((fd = open (filename, O_RDONLY | OUR_O_LARGEFILE | OUR_O_BINARY)) < 0) { + perror (filename); + throw std::runtime_error ("can't open file"); + } + + if ((d_fp = fdopen (fd, "rb")) == NULL) { + perror (filename); + throw std::runtime_error ("can't open file"); + } + + // Scan headers, check file validity + if (!gri_wavheader_parse(d_fp, + d_sample_rate, + d_nchans, + d_bytes_per_sample, + d_first_sample_pos, + d_samples_per_chan)) { + throw std::runtime_error("is not a valid wav file"); + } + + if (d_samples_per_chan == 0) { + throw std::runtime_error("WAV file does not contain any samples"); + } + + if (d_bytes_per_sample == 1) { + d_normalize_fac = 128; + d_normalize_shift = 1; + } else { + d_normalize_fac = 0x7FFF; + d_normalize_shift = 0; + } + + // Re-set the output signature + set_output_signature(gr_make_io_signature(1, d_nchans, sizeof(float))); +} + + +gr_wavfile_source::~gr_wavfile_source () +{ + fclose(d_fp); +} + + +int +gr_wavfile_source::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + float **out = (float **) &output_items[0]; + int n_out_chans = output_items.size(); + + int i; + short sample; + + for (i = 0; i < noutput_items; i++) { + if (d_sample_idx >= d_samples_per_chan) { + if (!d_repeat) { + // if nothing was read at all, say we're done. + return i ? i : -1; + } + + if (fseek (d_fp, d_first_sample_pos, SEEK_SET) == -1) { + fprintf(stderr, "[%s] fseek failed\n", __FILE__); + exit(-1); + } + + d_sample_idx = 0; + } + + for (int chan = 0; chan < d_nchans; chan++) { + sample = gri_wav_read_sample(d_fp, d_bytes_per_sample); + + if (chan < n_out_chans) { + out[chan][i] = convert_to_float(sample); + } + } + + d_sample_idx++; + + // OK, EOF is not necessarily an error. But we're not going to + // deal with handling corrupt wav files, so if they give us any + // trouble they won't be processed. Serves them bloody right. + if (feof(d_fp) || ferror(d_fp)) { + if (i == 0) { + fprintf(stderr, "[%s] WAV file has corrupted header or i/o error\n", __FILE__); + return -1; + } + return i; + } + } + + return noutput_items; +} + + +float +gr_wavfile_source::convert_to_float(short int sample) +{ + float sample_out = (float) sample; + sample_out /= d_normalize_fac; + sample_out -= d_normalize_shift; + return sample_out; +} diff --git a/gnuradio-core/src/lib/io/gr_wavfile_source.h b/gnuradio-core/src/lib/io/gr_wavfile_source.h new file mode 100644 index 000000000..d737b441b --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_wavfile_source.h @@ -0,0 +1,93 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2008 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, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_WAVFILE_SOURCE_H +#define INCLUDED_GR_WAVFILE_SOURCE_H + +#include + +class gr_wavfile_source; +typedef boost::shared_ptr gr_wavfile_source_sptr; + +gr_wavfile_source_sptr +gr_make_wavfile_source (const char *filename, bool repeat = false); + +/*! + * \brief Read stream from a Microsoft PCM (.wav) file, output floats + * + * Unless otherwise called, values are within [-1;1]. + * Check gr_make_wavfile_source() for extra info. + * + * \ingroup source + */ + +class gr_wavfile_source : public gr_sync_block +{ +private: + friend gr_wavfile_source_sptr gr_make_wavfile_source (const char *filename, + bool repeat); + gr_wavfile_source(const char *filename, bool repeat); + + FILE *d_fp; + bool d_repeat; + + unsigned d_sample_rate; + int d_nchans; + int d_bytes_per_sample; + int d_first_sample_pos; + unsigned d_samples_per_chan; + unsigned d_sample_idx; + int d_normalize_shift; + int d_normalize_fac; + + /*! + * \brief Convert an integer sample value to a float value within [-1;1] + */ + float convert_to_float(short int sample); + +public: + ~gr_wavfile_source (); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + /*! + * \brief Read the sample rate as specified in the wav file header + */ + unsigned int sample_rate() const { return d_sample_rate; }; + + /*! + * \brief Return the number of bits per sample as specified in the wav + * file header. Only 8 or 16 bit are supported here. + */ + int bits_per_sample() const { return d_bytes_per_sample * 8; }; + + /*! + * \brief Return the number of channels in the wav file as specified in + * the wav file header. This is also the max number of outputs you can + * have. + */ + int channels() const { return d_nchans; }; +}; + +#endif /* INCLUDED_GR_WAVFILE_SOURCE_H */ diff --git a/gnuradio-core/src/lib/io/gr_wavfile_source.i b/gnuradio-core/src/lib/io/gr_wavfile_source.i new file mode 100644 index 000000000..5af2224f1 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_wavfile_source.i @@ -0,0 +1,42 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 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, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,wavfile_source); + +gr_wavfile_source_sptr +gr_make_wavfile_source (const char *filename, + bool repeat = false) throw (std::runtime_error); + +class gr_wavfile_source : public gr_sync_block +{ +private: + gr_wavfile_source(const char *filename, + bool repeat) throw (std::runtime_error); + +public: + ~gr_wavfile_source(); + + unsigned int sample_rate(); + int bits_per_sample(); + int channels(); +}; + diff --git a/gnuradio-core/src/lib/io/gri_wavfile.cc b/gnuradio-core/src/lib/io/gri_wavfile.cc new file mode 100644 index 000000000..4a9db61d8 --- /dev/null +++ b/gnuradio-core/src/lib/io/gri_wavfile.cc @@ -0,0 +1,312 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2008 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, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +# define VALID_COMPRESSION_TYPE 0x0001 + +// WAV files are always little-endian, so we need some byte switching macros + +// FIXME: These need to be refactored into a separate endianess header file +// as they duplicate routines defined in usrp/host/lib/legacy/usrp_bytesex.h + +#ifdef WORDS_BIGENDIAN + +#ifdef HAVE_BYTESWAP_H +#include +#else +#warning Using non-portable code (likely wrong other than ILP32). + +static inline short int +bswap_16 (unsigned short int x) +{ + return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)); +} + +static inline unsigned int +bswap_32 (unsigned int x) +{ + return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \ + | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)); +} +#endif // HAVE_BYTESWAP_H + +static inline uint32_t +host_to_wav(uint32_t x) +{ + return bswap_32(x); +} + +static inline uint16_t +host_to_wav(uint16_t x) +{ + return bswap_16(x); +} + +static inline int16_t +host_to_wav(int16_t x) +{ + return bswap_32(x); +} + +static inline uint32_t +wav_to_host(uint32_t x) +{ + return bswap_32(x); +} + +static inline uint16_t +wav_to_host(uint16_t x) +{ + return bswap_16(x); +} + +static inline int16_t +wav_to_host(int16_t x) +{ + return bswap_32(x); +} + +#else + +static inline uint32_t +host_to_wav(uint32_t x) +{ + return x; +} + +static inline uint16_t +host_to_wav(uint16_t x) +{ + return x; +} + +static inline int16_t +host_to_wav(int16_t x) +{ + return x; +} + +static inline uint32_t +wav_to_host(uint32_t x) +{ + return x; +} + +static inline uint16_t +wav_to_host(uint16_t x) +{ + return x; +} + +static inline int16_t +wav_to_host(int16_t x) +{ + return x; +} + +#endif // WORDS_BIGENDIAN + + +bool +gri_wavheader_parse(FILE *fp, + unsigned int &sample_rate_o, + int &nchans_o, + int &bytes_per_sample_o, + int &first_sample_pos_o, + unsigned int &samples_per_chan_o) +{ + // _o variables take return values + char str_buf[8] = {0}; + + uint32_t file_size; + uint32_t fmt_hdr_skip; + uint16_t compression_type; + uint16_t nchans; + uint32_t sample_rate; + uint32_t avg_bytes_per_sec; + uint16_t block_align; + uint16_t bits_per_sample; + uint32_t chunk_size; + + size_t fresult; + + fresult = fread(str_buf, 1, 4, fp); + if (fresult != 4 || strncmp(str_buf, "RIFF", 4) || feof(fp)) { + return false; + } + + fread(&file_size, 1, 4, fp); + + fresult = fread(str_buf, 1, 8, fp); + if (fresult != 8 || strncmp(str_buf, "WAVEfmt ", 8) || feof(fp)) { + return false; + } + + fread(&fmt_hdr_skip, 1, 4, fp); + + fread(&compression_type, 1, 2, fp); + if (wav_to_host(compression_type) != VALID_COMPRESSION_TYPE) { + return false; + } + + fread(&nchans, 1, 2, fp); + fread(&sample_rate, 1, 4, fp); + fread(&avg_bytes_per_sec, 1, 4, fp); + fread(&block_align, 1, 2, fp); + fread(&bits_per_sample, 1, 2, fp); + + if (ferror(fp)) { + return false; + } + + fmt_hdr_skip = wav_to_host(fmt_hdr_skip); + nchans = wav_to_host(nchans); + sample_rate = wav_to_host(sample_rate); + bits_per_sample = wav_to_host(bits_per_sample); + + if (bits_per_sample != 8 && bits_per_sample != 16) { + return false; + } + + fmt_hdr_skip -= 16; + if (fmt_hdr_skip) { + fseek(fp, fmt_hdr_skip, SEEK_CUR); + } + + // data chunk + fresult = fread(str_buf, 1, 4, fp); + if (strncmp(str_buf, "data", 4)) { + return false; + } + + fread(&chunk_size, 1, 4, fp); + if (ferror(fp)) { + return false; + } + + // More byte swapping + chunk_size = wav_to_host(chunk_size); + + // Output values + sample_rate_o = (unsigned) sample_rate; + nchans_o = (int) nchans; + bytes_per_sample_o = (int) (bits_per_sample / 8); + first_sample_pos_o = (int) ftell(fp); + samples_per_chan_o = (unsigned) (chunk_size / (bytes_per_sample_o * nchans)); + return true; +} + + +short int +gri_wav_read_sample(FILE *fp, int bytes_per_sample) +{ + int16_t buf = 0; + fread(&buf, bytes_per_sample, 1, fp); + + return (short) wav_to_host(buf); +} + + +bool +gri_wavheader_write(FILE *fp, + unsigned int sample_rate, + int nchans, + int bytes_per_sample) +{ + const int header_len = 44; + char wav_hdr[header_len] = "RIFF\0\0\0\0WAVEfmt \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0data\0\0\0"; + uint16_t nchans_f = (uint16_t) nchans; + uint32_t sample_rate_f = (uint32_t) sample_rate; + uint16_t block_align = bytes_per_sample * nchans; + uint32_t avg_bytes = sample_rate * block_align; + uint16_t bits_per_sample = bytes_per_sample * 8; + + nchans_f = host_to_wav(nchans_f); + sample_rate_f = host_to_wav(sample_rate_f); + block_align = host_to_wav(block_align); + avg_bytes = host_to_wav(avg_bytes); + bits_per_sample = host_to_wav(bits_per_sample); + + wav_hdr[16] = 0x10; // no extra bytes + wav_hdr[20] = 0x01; // no compression + memcpy((void *) (wav_hdr + 22), (void *) &nchans_f, 2); + memcpy((void *) (wav_hdr + 24), (void *) &sample_rate_f, 4); + memcpy((void *) (wav_hdr + 28), (void *) &avg_bytes, 4); + memcpy((void *) (wav_hdr + 32), (void *) &block_align, 2); + memcpy((void *) (wav_hdr + 34), (void *) &bits_per_sample, 2); + + fwrite(&wav_hdr, 1, header_len, fp); + if (ferror(fp)) { + return false; + } + + return true; +} + + +void +gri_wav_write_sample(FILE *fp, short int sample, int bytes_per_sample) +{ + void *data_ptr; + unsigned char buf_8bit; + int16_t buf_16bit; + + if (bytes_per_sample == 1) { + buf_8bit = (unsigned char) sample; + data_ptr = (void *) &buf_8bit; + } else { + buf_16bit = host_to_wav((int16_t) sample); + data_ptr = (void *) &buf_16bit; + } + + fwrite(data_ptr, 1, bytes_per_sample, fp); +} + + +bool +gri_wavheader_complete(FILE *fp, unsigned int byte_count) +{ + uint32_t chunk_size = (uint32_t) byte_count; + chunk_size = host_to_wav(chunk_size); + + fseek(fp, 40, SEEK_SET); + fwrite(&chunk_size, 1, 4, fp); + + chunk_size = (uint32_t) byte_count + 36; // fmt chunk and data header + chunk_size = host_to_wav(chunk_size); + fseek(fp, 4, SEEK_SET); + + fwrite(&chunk_size, 1, 4, fp); + + if (ferror(fp)) { + return false; + } + + return true; +} diff --git a/gnuradio-core/src/lib/io/gri_wavfile.h b/gnuradio-core/src/lib/io/gri_wavfile.h new file mode 100644 index 000000000..2c7c1207c --- /dev/null +++ b/gnuradio-core/src/lib/io/gri_wavfile.h @@ -0,0 +1,100 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 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, + * Boston, MA 02110-1301, USA. + */ + +// This file stores all the RIFF file type knowledge for the gr_wavfile_* +// blocks. + +#include + +/*! + * \brief Read signal information from a given WAV file. + * + * \p fp File pointer to an opened, empty file. + * \p sample_rate Stores the sample rate [S/s] + * \p nchans Number of channels + * \p bytes_per_sample Bytes per sample, can either be 1 or 2 (corresponding to + * 8 or 16 bit samples, respectively) + * \p first_sample_pos Number of the first byte containing a sample. Use this + * with fseek() to jump from the end of the file to the first sample + * when in repeat mode. + * \p samples_per_chan Number of samples per channel + * \p normalize_fac The normalization factor with which you need to divide the + * integer values of the samples to get them within [-1;1] + * \p normalize_shift The value by which the sample values need to be shifted + * after normalization (reason being, 8-bit WAV files store samples as + * unsigned char and 16-bit as signed short int) + * \return True on a successful read, false if the file could not be read or is + * not a valid WAV file. + */ +bool +gri_wavheader_parse(FILE *fp, + unsigned int &sample_rate, + int &nchans, + int &bytes_per_sample, + int &first_sample_pos, + unsigned int &samples_per_chan); + + +/*! + * \brief Read one sample from an open WAV file at the current position. + * + * Takes care of endianness. + */ +short int +gri_wav_read_sample(FILE *fp, int bytes_per_sample); + + +/*! + * \brief Write a valid RIFF file header + * + * Note: Some header values are kept blank because they're usually not known + * a-priori (file and chunk lengths). Use gri_wavheader_complete() to fill + * these in. + */ +bool +gri_wavheader_write(FILE *fp, + unsigned int sample_rate, + int nchans, + int bytes_per_sample); + +/*! + * \brief Write one sample to an open WAV file at the current position. + * + * Takes care of endianness. + */ +void +gri_wav_write_sample(FILE *fp, short int sample, int bytes_per_sample); + + +/*! + * \brief Complete a WAV header + * + * Note: The stream position is changed during this function. If anything + * needs to be written to the WAV file after calling this function (which + * shouldn't happen), you need to fseek() to the end of the file (or + * whereever). + * + * \p fp File pointer to an open WAV file with a blank header + * \p byte_count Length of all samples written to the file in bytes. + */ +bool +gri_wavheader_complete(FILE *fp, unsigned int byte_count); diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index 73a3ad993..63dd979ff 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -36,6 +36,8 @@ #include #include #include +#include +#include %} @@ -54,4 +56,6 @@ %include "gr_message_sink.i" %include "gr_udp_sink.i" %include "gr_udp_source.i" +%include "gr_wavfile_sink.i" +%include "gr_wavfile_source.i" -- cgit From 776da31eb84e146a8adf1e3ca7e017c1d9992ce3 Mon Sep 17 00:00:00 2001 From: michaelld Date: Thu, 21 Feb 2008 19:16:45 +0000 Subject: Merged build_config branch into trunk: 1) Modified top-level run_tests.sh script: a) to execute code for setting or changing the library search path in Darwin (DYLD_LIBRARY_PATH) or Windows (PATH) on those host OSs only, not on other host OSs. b) Added local (to the component making check) library paths to those same search paths, since libtool doesn't do it (unlike in Linux). 2) In all AM Makefiles -except those dealing with USRP firmware-, changes INCLUDES to AM_CPPFLAGS since the former is deprecated. 3) Changed AM_CPPFLAGS to FW_INCLUDES for commands .c.rel in USRP firmware. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@7769 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index c94683735..c307be133 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -22,7 +22,7 @@ include $(top_srcdir)/Makefile.common -INCLUDES = $(STD_DEFINES_AND_INCLUDES) $(WITH_INCLUDES) +AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(WITH_INCLUDES) noinst_LTLIBRARIES = libio.la -- cgit From 5a477a01798fa49a6d0d69debfb2e64c1ded5083 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Mon, 24 Mar 2008 15:58:45 +0000 Subject: Fixed gr.udp_source,sink for use on Win32 (Don Ward) git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8097 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/gr_udp_sink.cc | 11 +++++++++-- gnuradio-core/src/lib/io/gr_udp_sink.h | 6 +++++- gnuradio-core/src/lib/io/gr_udp_source.cc | 13 ++++++++++--- gnuradio-core/src/lib/io/gr_udp_source.h | 5 +++++ gnuradio-core/src/lib/io/io.i | 4 ++++ 5 files changed, 33 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index 15bcf9a83..82cd5c29f 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -26,7 +26,14 @@ #include #include #include +#if defined(HAVE_SOCKET) #include +typedef void* optval_t; +#else +#define SHUT_RDWR 2 +#define inet_aton(N,A) ( (A)->s_addr = inet_addr(N), ( (A)->s_addr != INADDR_NONE ) ) +typedef char* optval_t; +#endif #define SNK_VERBOSE 0 @@ -112,7 +119,7 @@ gr_udp_sink::open() // Turn on reuse address int opt_val = true; - if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(int)) == -1) { + if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (optval_t)&opt_val, sizeof(int)) == -1) { perror("SO_REUSEADDR"); throw std::runtime_error("can't set socket option SO_REUSEADDR"); } @@ -121,7 +128,7 @@ gr_udp_sink::open() linger lngr; lngr.l_onoff = 1; lngr.l_linger = 0; - if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (void*)&lngr, sizeof(linger)) == -1) { + if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (optval_t)&lngr, sizeof(linger)) == -1) { perror("SO_LINGER"); throw std::runtime_error("can't set socket option SO_LINGER"); } diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.h b/gnuradio-core/src/lib/io/gr_udp_sink.h index 4f08136ec..e59380011 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.h +++ b/gnuradio-core/src/lib/io/gr_udp_sink.h @@ -25,9 +25,13 @@ #include #include +#if defined(HAVE_SOCKET) #include #include -#include +#elif defined(HAVE_WINDOWS_H) +#include +#include +#endif #if defined(HAVE_NETINET_IN_H) #include #endif diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index f7f04d3cf..c65947ba6 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -27,7 +27,14 @@ #include #include #include +#if defined(HAVE_SOCKET) #include +typedef void* optval_t; +#else +#define SHUT_RDWR 2 +#define inet_aton(N,A) ( (A)->s_addr = inet_addr(N), ( (A)->s_addr != INADDR_NONE ) ) +typedef char* optval_t; +#endif #define SRC_VERBOSE 0 @@ -91,7 +98,7 @@ gr_udp_source::open() // Turn on reuse address int opt_val = 1; - if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(int)) == -1) { + if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (optval_t)&opt_val, sizeof(int)) == -1) { perror("SO_REUSEADDR"); throw std::runtime_error("can't set socket option SO_REUSEADDR"); } @@ -100,7 +107,7 @@ gr_udp_source::open() linger lngr; lngr.l_onoff = 1; lngr.l_linger = 0; - if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (void*)&lngr, sizeof(linger)) == -1) { + if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (optval_t)&lngr, sizeof(linger)) == -1) { perror("SO_LINGER"); throw std::runtime_error("can't set socket option SO_LINGER"); } @@ -110,7 +117,7 @@ gr_udp_source::open() timeval timeout; timeout.tv_sec = 1; timeout.tv_usec = 0; - if(setsockopt(d_socket, SOL_SOCKET, SO_RCVTIMEO, (void*)&timeout, sizeof(timeout)) == -1) { + if(setsockopt(d_socket, SOL_SOCKET, SO_RCVTIMEO, (optval_t)&timeout, sizeof(timeout)) == -1) { perror("SO_RCVTIMEO"); throw std::runtime_error("can't set socket option SO_RCVTIMEO"); } diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h index 83bebf84d..a4403c3d6 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.h +++ b/gnuradio-core/src/lib/io/gr_udp_source.h @@ -25,8 +25,13 @@ #include #include +#if defined(HAVE_SOCKET) #include #include +#elif defined(HAVE_WINDOWS_H) +#include +#include +#endif #if defined(HAVE_NETINET_IN_H) #include #endif diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index 63dd979ff..ed7feb49d 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -22,6 +22,10 @@ %{ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include -- cgit From 873a61258e6e8456b5d48a264e9a28d1246bf149 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Wed, 9 Apr 2008 15:26:29 +0000 Subject: Fixes ticket:238. (Tim Meehan) git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8163 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/gri_wavfile.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gri_wavfile.cc b/gnuradio-core/src/lib/io/gri_wavfile.cc index 4a9db61d8..c1a2b7c73 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.cc +++ b/gnuradio-core/src/lib/io/gri_wavfile.cc @@ -71,7 +71,7 @@ host_to_wav(uint16_t x) static inline int16_t host_to_wav(int16_t x) { - return bswap_32(x); + return bswap_16(x); } static inline uint32_t @@ -89,7 +89,7 @@ wav_to_host(uint16_t x) static inline int16_t wav_to_host(int16_t x) { - return bswap_32(x); + return bswap_16(x); } #else -- cgit From 38ea3a576a20820e574c6cb37607aeafe07f34b4 Mon Sep 17 00:00:00 2001 From: eb Date: Wed, 30 Apr 2008 02:24:06 +0000 Subject: Tweaks for gcc 4.3 based on patch from Marek Mahut . git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8292 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc | 1 + gnuradio-core/src/lib/io/gr_file_descriptor_source.cc | 2 ++ gnuradio-core/src/lib/io/gr_file_sink_base.cc | 1 + gnuradio-core/src/lib/io/gr_file_source.cc | 1 + gnuradio-core/src/lib/io/gr_message_sink.cc | 1 + gnuradio-core/src/lib/io/gr_message_source.cc | 1 + gnuradio-core/src/lib/io/gr_udp_sink.cc | 1 + gnuradio-core/src/lib/io/gr_udp_source.cc | 2 ++ gnuradio-core/src/lib/io/gri_logger.cc | 1 + 9 files changed, 11 insertions(+) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc index a3a9a8c0e..2da66b7ae 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc @@ -32,6 +32,7 @@ #include #include #include +#include gr_file_descriptor_sink::gr_file_descriptor_sink (size_t itemsize, int fd) diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc b/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc index b2d7c6bfb..700ad4aef 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc @@ -32,6 +32,8 @@ #include #include #include +#include +#include gr_file_descriptor_source::gr_file_descriptor_source (size_t itemsize, diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.cc b/gnuradio-core/src/lib/io/gr_file_sink_base.cc index 1ce84fa88..29ac0dbb1 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.cc @@ -30,6 +30,7 @@ #include #include #include +#include // win32 (mingw/msvc) specific #ifdef HAVE_IO_H diff --git a/gnuradio-core/src/lib/io/gr_file_source.cc b/gnuradio-core/src/lib/io/gr_file_source.cc index 95d1c0aca..5591826d0 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_source.cc @@ -31,6 +31,7 @@ #include #include #include +#include // win32 (mingw/msvc) specific #ifdef HAVE_IO_H diff --git a/gnuradio-core/src/lib/io/gr_message_sink.cc b/gnuradio-core/src/lib/io/gr_message_sink.cc index 0cb1c0029..b9e0cc382 100644 --- a/gnuradio-core/src/lib/io/gr_message_sink.cc +++ b/gnuradio-core/src/lib/io/gr_message_sink.cc @@ -32,6 +32,7 @@ #include #include #include +#include // public constructor that returns a shared_ptr diff --git a/gnuradio-core/src/lib/io/gr_message_source.cc b/gnuradio-core/src/lib/io/gr_message_source.cc index bf45318de..3fbe3708e 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.cc +++ b/gnuradio-core/src/lib/io/gr_message_source.cc @@ -32,6 +32,7 @@ #include #include #include +#include // public constructor that returns a shared_ptr diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index 82cd5c29f..215eaf8d5 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -28,6 +28,7 @@ #include #if defined(HAVE_SOCKET) #include +#include typedef void* optval_t; #else #define SHUT_RDWR 2 diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index c65947ba6..9b6ee6e7d 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -27,6 +27,8 @@ #include #include #include +#include +#include #if defined(HAVE_SOCKET) #include typedef void* optval_t; diff --git a/gnuradio-core/src/lib/io/gri_logger.cc b/gnuradio-core/src/lib/io/gri_logger.cc index dbaace689..c085a93c8 100644 --- a/gnuradio-core/src/lib/io/gri_logger.cc +++ b/gnuradio-core/src/lib/io/gri_logger.cc @@ -29,6 +29,7 @@ #include #include #include +#include /* -- cgit From 0aa33cf5c22e3721c6809ef0db54cfbe9ebe4db7 Mon Sep 17 00:00:00 2001 From: eb Date: Sun, 31 Aug 2008 23:22:43 +0000 Subject: removed some warnings git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9475 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/microtune_4702.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/microtune_4702.cc b/gnuradio-core/src/lib/io/microtune_4702.cc index 01fe450fd..59c88e26e 100644 --- a/gnuradio-core/src/lib/io/microtune_4702.cc +++ b/gnuradio-core/src/lib/io/microtune_4702.cc @@ -151,7 +151,7 @@ microtune_4702::set_RF_freq (double target_freq, double *p_actual_freq) buf[0] = ((divisor & 0x07f00) >> 8) & 0xff; // DB1 buf[1] = divisor & 0xff; // DB2 buf[2] = control_byte_1 (d_prescaler, d_reference_divider); - buf[2] = (buf[2]|(((divisor & 0x18000) >> 10)) & 0xff); + buf[2] = buf[2] | (((divisor & 0x18000) >> 10) & 0xff); buf[3] = control_byte_2 (target_freq); printf ("%x\n", PLL_I2C_ADDR); -- cgit From c48f42b58c67eefd19ea1a803329bcf62eac06e9 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Wed, 25 Feb 2009 19:04:35 +0000 Subject: Merged r10501:10505 from michaelld/omnithread into trunk. Moves omnithread header files into /gnuradio. Trunk passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10506 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/gr_file_sink_base.h | 2 +- gnuradio-core/src/lib/io/gr_udp_sink.h | 2 +- gnuradio-core/src/lib/io/gr_udp_source.h | 2 +- gnuradio-core/src/lib/io/gr_wavfile_sink.h | 2 +- gnuradio-core/src/lib/io/gri_logger.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.h b/gnuradio-core/src/lib/io/gr_file_sink_base.h index c848818f8..f36f5ac97 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.h +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.h @@ -23,7 +23,7 @@ #ifndef INCLUDED_GR_FILE_SINK_BASE_H #define INCLUDED_GR_FILE_SINK_BASE_H -#include +#include #include /*! diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.h b/gnuradio-core/src/lib/io/gr_udp_sink.h index e59380011..99f1b2935 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.h +++ b/gnuradio-core/src/lib/io/gr_udp_sink.h @@ -24,7 +24,7 @@ #define INCLUDED_GR_UDP_SINK_H #include -#include +#include #if defined(HAVE_SOCKET) #include #include diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h index a4403c3d6..049740159 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.h +++ b/gnuradio-core/src/lib/io/gr_udp_source.h @@ -24,7 +24,7 @@ #define INCLUDED_GR_UDP_SOURCE_H #include -#include +#include #if defined(HAVE_SOCKET) #include #include diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.h b/gnuradio-core/src/lib/io/gr_wavfile_sink.h index 3fa06f202..9429165f6 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.h +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.h @@ -25,7 +25,7 @@ #include #include -#include +#include class gr_wavfile_sink; typedef boost::shared_ptr gr_wavfile_sink_sptr; diff --git a/gnuradio-core/src/lib/io/gri_logger.h b/gnuradio-core/src/lib/io/gri_logger.h index da54e56a2..e5caf7d06 100644 --- a/gnuradio-core/src/lib/io/gri_logger.h +++ b/gnuradio-core/src/lib/io/gri_logger.h @@ -23,7 +23,7 @@ #define INCLUDED_GRI_LOGGER_H #include -#include +#include #include class gri_log_poster; -- cgit From d9744799b7df6c09180778540bf55eb9dc84281b Mon Sep 17 00:00:00 2001 From: jcorgan Date: Fri, 20 Mar 2009 02:16:20 +0000 Subject: Merged r10463:10658 from jblum/gui_guts into trunk. Trunk passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10660 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/Makefile.am | 3 + gnuradio-core/src/lib/io/gr_histo_sink.i | 39 ++++++ gnuradio-core/src/lib/io/gr_histo_sink_f.cc | 169 ++++++++++++++++++++++++++ gnuradio-core/src/lib/io/gr_histo_sink_f.h | 70 +++++++++++ gnuradio-core/src/lib/io/gr_oscope_guts.cc | 170 ++++++++++++++------------- gnuradio-core/src/lib/io/gr_oscope_guts.h | 16 ++- gnuradio-core/src/lib/io/gr_oscope_sink.i | 8 +- gnuradio-core/src/lib/io/gr_oscope_sink_f.cc | 10 +- gnuradio-core/src/lib/io/gr_oscope_sink_f.h | 5 +- gnuradio-core/src/lib/io/gr_oscope_sink_x.cc | 18 +++ gnuradio-core/src/lib/io/gr_oscope_sink_x.h | 3 + gnuradio-core/src/lib/io/gr_trigger_mode.h | 11 +- gnuradio-core/src/lib/io/io.i | 2 + 13 files changed, 420 insertions(+), 104 deletions(-) create mode 100644 gnuradio-core/src/lib/io/gr_histo_sink.i create mode 100644 gnuradio-core/src/lib/io/gr_histo_sink_f.cc create mode 100644 gnuradio-core/src/lib/io/gr_histo_sink_f.h (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index c307be133..4583a033c 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -33,6 +33,7 @@ libio_la_SOURCES = \ gr_file_source.cc \ gr_file_descriptor_sink.cc \ gr_file_descriptor_source.cc \ + gr_histo_sink_f.cc \ gr_message_sink.cc \ gr_message_source.cc \ gr_oscope_guts.cc \ @@ -64,6 +65,7 @@ grinclude_HEADERS = \ gr_file_source.h \ gr_file_descriptor_sink.h \ gr_file_descriptor_source.h \ + gr_histo_sink_f.h \ gr_message_sink.h \ gr_message_source.h \ gr_oscope_guts.h \ @@ -101,6 +103,7 @@ swiginclude_HEADERS = \ gr_file_source.i \ gr_file_descriptor_sink.i \ gr_file_descriptor_source.i \ + gr_histo_sink.i \ gr_message_sink.i \ gr_message_source.i \ gr_oscope_sink.i \ diff --git a/gnuradio-core/src/lib/io/gr_histo_sink.i b/gnuradio-core/src/lib/io/gr_histo_sink.i new file mode 100644 index 000000000..544d772fb --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_histo_sink.i @@ -0,0 +1,39 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 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, + * Boston, MA 02110-1301, USA. + */ + + +GR_SWIG_BLOCK_MAGIC(gr,histo_sink_f) + +gr_histo_sink_f_sptr gr_make_histo_sink_f (gr_msg_queue_sptr msgq); + +class gr_histo_sink_f : public gr_sync_block +{ +public: + ~gr_histo_sink_f (void); + + unsigned int get_frame_size(void); + unsigned int get_num_bins(void); + + void set_frame_size(unsigned int frame_size); + void set_num_bins(unsigned int num_bins); + +}; diff --git a/gnuradio-core/src/lib/io/gr_histo_sink_f.cc b/gnuradio-core/src/lib/io/gr_histo_sink_f.cc new file mode 100644 index 000000000..a923a7e45 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_histo_sink_f.cc @@ -0,0 +1,169 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 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, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +static float get_clean_num(float num){ + if (num == 0) return 0; + /* extract sign and exponent from num */ + int sign = (num < 0) ? -1 : 1; num = fabs(num); + float exponent = floor(log10(num)); + /* search for closest number with base 1, 2, 5, 10 */ + float closest_num = 10*pow(10, exponent); + if (fabs(num - 1*pow(10, exponent)) < fabs(num - closest_num)) + closest_num = 1*pow(10, exponent); + if (fabs(num - 2*pow(10, exponent)) < fabs(num - closest_num)) + closest_num = 2*pow(10, exponent); + if (fabs(num - 5*pow(10, exponent)) < fabs(num - closest_num)) + closest_num = 5*pow(10, exponent); + return sign*closest_num; +} + +gr_histo_sink_f_sptr +gr_make_histo_sink_f (gr_msg_queue_sptr msgq) +{ + return gr_histo_sink_f_sptr (new gr_histo_sink_f (msgq)); +} + +gr_histo_sink_f::gr_histo_sink_f (gr_msg_queue_sptr msgq) + : gr_sync_block ("histo_sink_f", gr_make_io_signature (1, 1, sizeof (float)), gr_make_io_signature (0, 0, 0)), + d_msgq (msgq), d_num_bins(11), d_frame_size(1000), d_sample_count(0), d_bins(NULL), d_samps(NULL) +{ + pthread_mutex_init(&d_mutex, 0); + //allocate arrays and clear + set_num_bins(d_num_bins); + set_frame_size(d_frame_size); +} + +gr_histo_sink_f::~gr_histo_sink_f (void) +{ + pthread_mutex_destroy(&d_mutex); + delete [] d_samps; + delete [] d_bins; +} + +int +gr_histo_sink_f::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const float *in = (const float *) input_items[0]; + pthread_mutex_lock(&d_mutex); + for (unsigned int i = 0; i < (unsigned int)noutput_items; i++){ + d_samps[d_sample_count] = in[i]; + d_sample_count++; + /* processed a frame? */ + if (d_sample_count == d_frame_size){ + send_frame(); + clear(); + } + } + pthread_mutex_unlock(&d_mutex); + return noutput_items; +} + +void +gr_histo_sink_f::send_frame(void){ + /* output queue full, drop the data */ + if (d_msgq->full_p()) return; + /* find the minimum and maximum */ + float minimum = d_samps[0]; + float maximum = d_samps[0]; + for (unsigned int i = 0; i < d_frame_size; i++){ + if (d_samps[i] < minimum) minimum = d_samps[i]; + if (d_samps[i] > maximum) maximum = d_samps[i]; + } + minimum = get_clean_num(minimum); + maximum = get_clean_num(maximum); + if (minimum == maximum || minimum > maximum) return; //useless data or screw up? + /* load the bins */ + int index; + float bin_width = (maximum - minimum)/(d_num_bins-1); + for (unsigned int i = 0; i < d_sample_count; i++){ + index = round((d_samps[i] - minimum)/bin_width); + /* ensure the index range in case a small floating point error is involed */ + if (index < 0) index = 0; + if (index >= (int)d_num_bins) index = d_num_bins-1; + d_bins[index]++; + } + /* Build a message to hold the output records */ + gr_message_sptr msg = gr_make_message(0, minimum, maximum, d_num_bins*sizeof(float)); + float *out = (float *)msg->msg(); // get pointer to raw message buffer + /* normalize the bins and put into message */ + for (unsigned int i = 0; i < d_num_bins; i++){ + out[i] = ((float)d_bins[i])/d_frame_size; + } + /* send the message */ + d_msgq->handle(msg); +} + +void +gr_histo_sink_f::clear(void){ + d_sample_count = 0; + /* zero the bins */ + for (unsigned int i = 0; i < d_num_bins; i++){ + d_bins[i] = 0; + } +} + +/************************************************** + * Getters + **************************************************/ +unsigned int +gr_histo_sink_f::get_frame_size(void){ + return d_frame_size; +} + +unsigned int +gr_histo_sink_f::get_num_bins(void){ + return d_num_bins; +} + +/************************************************** + * Setters + **************************************************/ +void +gr_histo_sink_f::set_frame_size(unsigned int frame_size){ + pthread_mutex_lock(&d_mutex); + d_frame_size = frame_size; + /* allocate a new sample array */ + delete [] d_samps; + d_samps = new float[d_frame_size]; + clear(); + pthread_mutex_unlock(&d_mutex); +} + +void +gr_histo_sink_f::set_num_bins(unsigned int num_bins){ + pthread_mutex_lock(&d_mutex); + d_num_bins = num_bins; + /* allocate a new bin array */ + delete [] d_bins; + d_bins = new unsigned int[d_num_bins]; + clear(); + pthread_mutex_unlock(&d_mutex); +} diff --git a/gnuradio-core/src/lib/io/gr_histo_sink_f.h b/gnuradio-core/src/lib/io/gr_histo_sink_f.h new file mode 100644 index 000000000..ae34d302d --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_histo_sink_f.h @@ -0,0 +1,70 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 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, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_HISTO_SINK_F_H +#define INCLUDED_GR_HISTO_SINK_F_H + +#include +#include +#include + +class gr_histo_sink_f; +typedef boost::shared_ptr gr_histo_sink_f_sptr; + +gr_histo_sink_f_sptr gr_make_histo_sink_f (gr_msg_queue_sptr msgq); + +/*! + * \brief Histogram module. + * \ingroup sink + */ +class gr_histo_sink_f : public gr_sync_block +{ +private: + gr_msg_queue_sptr d_msgq; + unsigned int d_num_bins; + unsigned int d_frame_size; + unsigned int d_sample_count; + unsigned int *d_bins; + float *d_samps; + pthread_mutex_t d_mutex; + + friend gr_histo_sink_f_sptr gr_make_histo_sink_f (gr_msg_queue_sptr msgq); + gr_histo_sink_f (gr_msg_queue_sptr msgq); + void send_frame(void); + void clear(void); + +public: + ~gr_histo_sink_f (void); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + unsigned int get_frame_size(void); + unsigned int get_num_bins(void); + + void set_frame_size(unsigned int frame_size); + void set_num_bins(unsigned int num_bins); + +}; + +#endif /* INCLUDED_GR_HISTO_SINK_F_H */ diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.cc b/gnuradio-core/src/lib/io/gr_oscope_guts.cc index 2272aa0f7..80f78240d 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.cc @@ -31,30 +31,31 @@ #include #include -static const int OUTPUT_RECORD_SIZE = 2048; // must be power of 2 +static const int OUTPUT_RECORD_SIZE = 2048; // must be power of 2 static inline int -wrap_bi (int buffer_index) // wrap buffer index +wrap_bi (int buffer_index) // wrap buffer index { return buffer_index & (OUTPUT_RECORD_SIZE - 1); } static inline int -incr_bi (int buffer_index) // increment buffer index +incr_bi (int buffer_index) // increment buffer index { return wrap_bi (buffer_index + 1); } static inline int -decr_bi (int buffer_index) // decrement buffer index +decr_bi (int buffer_index) // decrement buffer index { return wrap_bi (buffer_index - 1); } -gr_oscope_guts::gr_oscope_guts (int nchannels, double sample_rate, gr_msg_queue_sptr msgq) - : d_nchannels (nchannels), +gr_oscope_guts::gr_oscope_guts (double sample_rate, gr_msg_queue_sptr msgq) + : d_nchannels (1), d_msgq (msgq), - d_trigger_mode (gr_TRIG_AUTO), + d_trigger_mode (gr_TRIG_MODE_AUTO), + d_trigger_slope (gr_TRIG_SLOPE_POS), d_trigger_channel (0), d_sample_rate (sample_rate), d_update_rate (20), @@ -65,19 +66,14 @@ gr_oscope_guts::gr_oscope_guts (int nchannels, double sample_rate, gr_msg_queue_ d_decimator_count_init (1), d_hold_off_count (0), d_hold_off_count_init (OUTPUT_RECORD_SIZE/2-1), + d_pre_trigger_count (0), d_post_trigger_count (0), - d_post_trigger_count_init (OUTPUT_RECORD_SIZE/2), - d_prev_sample (0) + d_post_trigger_count_init (OUTPUT_RECORD_SIZE/2) { - if (d_nchannels > MAX_CHANNELS){ - fprintf (stderr, "gr_oscope_guts: too many channels. MAX_CHANNELS = %d\n", MAX_CHANNELS); - throw std::runtime_error ("too many channels"); - } - for (int i = 0; i < MAX_CHANNELS; i++) d_buffer[i] = 0; - for (int i = 0; i < d_nchannels; i++){ + for (int i = 0; i < MAX_CHANNELS; i++){ d_buffer[i] = new float [OUTPUT_RECORD_SIZE]; for (int j = 0; j < OUTPUT_RECORD_SIZE; j++) d_buffer[i][j] = 0.0; @@ -109,10 +105,8 @@ gr_oscope_guts::process_sample (const float *channel_data) d_decimator_count = d_decimator_count_init; for (int i = 0; i < d_nchannels; i++) - d_buffer[i][d_obi] = channel_data[i]; // copy data into buffer + d_buffer[i][d_obi] = channel_data[i]; // copy data into buffer - int trigger = 0; - switch (d_state){ case HOLD_OFF: d_hold_off_count--; @@ -121,12 +115,8 @@ gr_oscope_guts::process_sample (const float *channel_data) break; case LOOK_FOR_TRIGGER: - trigger = found_trigger (d_buffer[d_trigger_channel][d_obi]); - if (trigger != 0){ + if (found_trigger ()) enter_post_trigger (); - if (trigger < 0) // previous sample was closer - d_post_trigger_count--; - } break; case POST_TRIGGER: @@ -158,8 +148,8 @@ gr_oscope_guts::enter_hold_off () void gr_oscope_guts::enter_look_for_trigger () { + d_pre_trigger_count = 0; d_state = LOOK_FOR_TRIGGER; - d_prev_sample = d_buffer[d_trigger_channel][d_obi]; } void @@ -167,48 +157,49 @@ gr_oscope_guts::enter_post_trigger () { d_state = POST_TRIGGER; d_post_trigger_count = d_post_trigger_count_init; + //ensure that the trigger offset is no more than than half a sample + if (d_trigger_off > .5) d_trigger_off -= 1; + else d_post_trigger_count--; } // ---------------------------------------------------------------- -// returns 0 if no trigger found. -// returns +1 if this sample is the trigger point -// returns -1 if the previous sample is the trigger point +// returns true if trigger found -int -gr_oscope_guts::found_trigger (float new_sample) +bool +gr_oscope_guts::found_trigger () { - float prev_sample = d_prev_sample; - d_prev_sample = new_sample; - bool trig; + float prev_sample = d_buffer[d_trigger_channel][decr_bi(d_obi)]; + float new_sample = d_buffer[d_trigger_channel][d_obi]; switch (d_trigger_mode){ - case gr_TRIG_AUTO: // always trigger - return +1; - - case gr_TRIG_POS_SLOPE: - trig = prev_sample < d_trigger_level && new_sample >= d_trigger_level; - if (trig){ - if (fabs (prev_sample - d_trigger_level) < fabs (new_sample - d_trigger_level)) - return -1; - else - return +1; - } - return 0; - - case gr_TRIG_NEG_SLOPE: - trig = prev_sample > d_trigger_level && new_sample <= d_trigger_level; - if (trig){ - if (fabs (prev_sample - d_trigger_level) < fabs (new_sample - d_trigger_level)) - return -1; - else - return +1; + case gr_TRIG_MODE_AUTO: //too many samples without a trigger + d_pre_trigger_count++; + if (d_pre_trigger_count > OUTPUT_RECORD_SIZE/2) return true; + + case gr_TRIG_MODE_NORM: //look for trigger + switch (d_trigger_slope){ + + case gr_TRIG_SLOPE_POS: //trigger point in pos slope? + if (new_sample < d_trigger_level || prev_sample >= d_trigger_level) return false; + break; + + case gr_TRIG_SLOPE_NEG: //trigger point in neg slope? + if (new_sample > d_trigger_level || prev_sample <= d_trigger_level) return false; + break; } - return 0; + + //calculate the trigger offset in % sample + d_trigger_off = (d_trigger_level - prev_sample)/(new_sample - prev_sample); + return true; + + case gr_TRIG_MODE_FREE: //free run mode, always trigger + d_trigger_off = 0; + return true; default: assert (0); - return 0; + return false; } } @@ -218,28 +209,30 @@ gr_oscope_guts::found_trigger (float new_sample) void gr_oscope_guts::write_output_records () { - // if the output queue if full, drop the data on the ground. + // if the output queue if full, drop the data like its hot. if (d_msgq->full_p()) return; - - // Build a message to hold the output records + // Build a message to hold the output records gr_message_sptr msg = - gr_make_message(0, // msg type - d_nchannels, // arg1 for other side - OUTPUT_RECORD_SIZE, // arg2 for other side - d_nchannels * OUTPUT_RECORD_SIZE * sizeof(float)); // sizeof payload + gr_make_message(0, // msg type + d_nchannels, // arg1 for other side + OUTPUT_RECORD_SIZE, // arg2 for other side + ((d_nchannels * OUTPUT_RECORD_SIZE) + 1) * sizeof(float)); // sizeof payload - float *out = (float *)msg->msg(); // get pointer to raw message buffer + float *out = (float *)msg->msg(); // get pointer to raw message buffer for (int ch = 0; ch < d_nchannels; ch++){ // note that d_obi + 1 points at the oldest sample in the buffer - for (int i = 0; i < OUTPUT_RECORD_SIZE; i++) + for (int i = 0; i < OUTPUT_RECORD_SIZE; i++){ out[i] = d_buffer[ch][wrap_bi(d_obi + 1 + i)]; - + } out += OUTPUT_RECORD_SIZE; } - - d_msgq->handle(msg); // send the msg + //Set the last sample as the trigger offset: + // The non gl scope sink will not look at this last sample. + // The gl scope sink will use this last sample as an offset. + out[0] = d_trigger_off; + d_msgq->handle(msg); // send the msg } // ---------------------------------------------------------------- @@ -291,15 +284,17 @@ gr_oscope_guts::set_trigger_channel (int channel) bool gr_oscope_guts::set_trigger_mode (gr_trigger_mode mode) { - switch (mode){ - case gr_TRIG_POS_SLOPE: - case gr_TRIG_NEG_SLOPE: - case gr_TRIG_AUTO: - d_trigger_mode = mode; - trigger_changed (); - return true; - } - return false; + d_trigger_mode = mode; + trigger_changed (); + return true; +} + +bool +gr_oscope_guts::set_trigger_slope (gr_trigger_slope slope) +{ + d_trigger_slope = slope; + trigger_changed (); + return true; } bool @@ -315,23 +310,30 @@ gr_oscope_guts::set_trigger_level_auto () { // find the level 1/2 way between the min and the max - float min_v = d_buffer[d_trigger_channel][0]; - float max_v = d_buffer[d_trigger_channel][0]; + float min_v = d_buffer[d_trigger_channel][0]; + float max_v = d_buffer[d_trigger_channel][0]; for (int i = 1; i < OUTPUT_RECORD_SIZE; i++){ min_v = std::min (min_v, d_buffer[d_trigger_channel][i]); max_v = std::max (max_v, d_buffer[d_trigger_channel][i]); } + return set_trigger_level((min_v + max_v) * 0.5); +} - d_trigger_level = (min_v + max_v) * 0.5; - trigger_changed (); - return true; +bool +gr_oscope_guts::set_num_channels(int nchannels) +{ + if (nchannels > 0 && nchannels <= MAX_CHANNELS){ + d_nchannels = nchannels; + return true; + } + return false; } + void gr_oscope_guts::trigger_changed () { - // d_prev_sample = d_buffer[d_trigger_channel][decr_bi(d_obi)]; enter_look_for_trigger (); } @@ -373,6 +375,12 @@ gr_oscope_guts::get_trigger_mode () const return d_trigger_mode; } +gr_trigger_slope +gr_oscope_guts::get_trigger_slope () const +{ + return d_trigger_slope; +} + double gr_oscope_guts::get_trigger_level () const { diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.h b/gnuradio-core/src/lib/io/gr_oscope_guts.h index ee3bbc31e..f39db62f6 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.h +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.h @@ -41,13 +41,15 @@ */ class gr_oscope_guts { +public: + static const int MAX_CHANNELS = 8; private: - static const int MAX_CHANNELS = 16; enum scope_state { HOLD_OFF, LOOK_FOR_TRIGGER, POST_TRIGGER }; int d_nchannels; // how many channels gr_msg_queue_sptr d_msgq; // message queue we stuff output records into - gr_trigger_mode d_trigger_mode; + gr_trigger_mode d_trigger_mode; + gr_trigger_slope d_trigger_slope; int d_trigger_channel; // which channel to watch for trigger condition double d_sample_rate; // input sample rate in Hz double d_update_rate; // approx freq to produce an output record (Hz) @@ -61,9 +63,10 @@ private: int d_decimator_count_init; int d_hold_off_count; int d_hold_off_count_init; + int d_pre_trigger_count; int d_post_trigger_count; int d_post_trigger_count_init; - float d_prev_sample; // used for trigger checking + float d_trigger_off; //%sample trigger is off // NOT IMPLEMENTED gr_oscope_guts (const gr_oscope_guts &rhs); // no copy constructor @@ -71,7 +74,7 @@ private: void trigger_changed (); void update_rate_or_decimation_changed (); - int found_trigger (float sample); // returns -1, 0, +1 + bool found_trigger (); // returns true if found void write_output_records (); void enter_hold_off (); // called on state entry @@ -80,7 +83,7 @@ private: public: // CREATORS - gr_oscope_guts (int nchannels, double sample_rate, gr_msg_queue_sptr msgq); + gr_oscope_guts (double sample_rate, gr_msg_queue_sptr msgq); ~gr_oscope_guts (); // MANIPULATORS @@ -95,9 +98,11 @@ public: bool set_decimation_count (int decimation_count); bool set_trigger_channel (int channel); bool set_trigger_mode (gr_trigger_mode mode); + bool set_trigger_slope (gr_trigger_slope slope); bool set_trigger_level (double trigger_level); bool set_trigger_level_auto (); // set to 50% level bool set_sample_rate(double sample_rate); + bool set_num_channels(int nchannels); // ACCESSORS @@ -107,6 +112,7 @@ public: int get_decimation_count () const; int get_trigger_channel () const; gr_trigger_mode get_trigger_mode () const; + gr_trigger_slope get_trigger_slope () const; double get_trigger_level () const; // # of samples written to each output record. diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink.i b/gnuradio-core/src/lib/io/gr_oscope_sink.i index 7802dac8a..9d634193b 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink.i +++ b/gnuradio-core/src/lib/io/gr_oscope_sink.i @@ -20,11 +20,7 @@ * Boston, MA 02110-1301, USA. */ -enum gr_trigger_mode { - gr_TRIG_AUTO, // auto trigger (on anything) - gr_TRIG_POS_SLOPE, // trigger on positive slope across trigger level - gr_TRIG_NEG_SLOPE // trigger on negative slope across trigger level -}; +%include gr_trigger_mode.h // GR_SWIG_BLOCK_MAGIC(gr,oscope_sink_x) @@ -43,6 +39,7 @@ class gr_oscope_sink_x : public gr_sync_block bool set_decimation_count (int decimation_count); bool set_trigger_channel (int channel); bool set_trigger_mode (gr_trigger_mode mode); + bool set_trigger_slope (gr_trigger_slope slope); bool set_trigger_level (double trigger_level); bool set_trigger_level_auto (); // set to 50% level bool set_sample_rate(double sample_rate); @@ -54,6 +51,7 @@ class gr_oscope_sink_x : public gr_sync_block int get_decimation_count () const; int get_trigger_channel () const; gr_trigger_mode get_trigger_mode () const; + gr_trigger_slope get_trigger_slope () const; double get_trigger_level () const; // # of samples written to each output record. diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc b/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc index 5e0e30660..cb401699e 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc @@ -38,20 +38,18 @@ gr_make_oscope_sink_f (double sampling_rate, gr_msg_queue_sptr msgq) gr_oscope_sink_f::gr_oscope_sink_f (double sampling_rate, gr_msg_queue_sptr msgq) : gr_oscope_sink_x ("oscope_sink_f", - gr_make_io_signature (1, MAX_CHANNELS, sizeof (float)), + gr_make_io_signature (1, gr_oscope_guts::MAX_CHANNELS, sizeof (float)), sampling_rate), d_msgq(msgq) { + d_guts = new gr_oscope_guts (d_sampling_rate, d_msgq); } bool gr_oscope_sink_f::check_topology (int ninputs, int noutputs) { - delete d_guts; - d_guts = 0; - d_guts = new gr_oscope_guts (ninputs, d_sampling_rate, d_msgq); - return true; + return d_guts->set_num_channels(ninputs); } @@ -65,7 +63,7 @@ gr_oscope_sink_f::work (int noutput_items, gr_vector_void_star &output_items) { int ni = input_items.size (); - float tmp[MAX_CHANNELS]; + float tmp[gr_oscope_guts::MAX_CHANNELS]; for (int i = 0; i < noutput_items; i++){ diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_f.h b/gnuradio-core/src/lib/io/gr_oscope_sink_f.h index 620aac374..22d145c54 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_f.h +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_f.h @@ -36,13 +36,10 @@ gr_oscope_sink_f_sptr gr_make_oscope_sink_f (double sampling_rate, gr_msg_queue_ * \brief Building block for python oscilloscope module. * \ingroup sink * - * Accepts 1 to 16 float streams. + * Accepts multiple float streams. */ class gr_oscope_sink_f : public gr_oscope_sink_x { -public: - static const int MAX_CHANNELS = 16; - private: friend gr_oscope_sink_f_sptr gr_make_oscope_sink_f (double sampling_rate, gr_msg_queue_sptr msgq); diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_x.cc b/gnuradio-core/src/lib/io/gr_oscope_sink_x.cc index f2c2d4371..2bbd57463 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_x.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_x.cc @@ -68,6 +68,12 @@ gr_oscope_sink_x::set_trigger_mode (gr_trigger_mode mode) return d_guts->set_trigger_mode (mode); } +bool +gr_oscope_sink_x::set_trigger_slope (gr_trigger_slope slope) +{ + return d_guts->set_trigger_slope (slope); +} + bool gr_oscope_sink_x::set_trigger_level (double trigger_level) { @@ -87,6 +93,12 @@ gr_oscope_sink_x::set_sample_rate (double sample_rate) return d_guts->set_sample_rate (sample_rate); } +bool +gr_oscope_sink_x::set_num_channels (int nchannels) +{ + return d_guts->set_num_channels (nchannels); +} + // ACCESSORS int @@ -125,6 +137,12 @@ gr_oscope_sink_x::get_trigger_mode () const return d_guts->get_trigger_mode (); } +gr_trigger_slope +gr_oscope_sink_x::get_trigger_slope () const +{ + return d_guts->get_trigger_slope (); +} + double gr_oscope_sink_x::get_trigger_level () const { diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_x.h b/gnuradio-core/src/lib/io/gr_oscope_sink_x.h index 6dc0d6335..408979eb6 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_x.h +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_x.h @@ -51,9 +51,11 @@ public: bool set_decimation_count (int decimation_count); bool set_trigger_channel (int channel); bool set_trigger_mode (gr_trigger_mode mode); + bool set_trigger_slope (gr_trigger_slope slope); bool set_trigger_level (double trigger_level); bool set_trigger_level_auto (); // set to 50% level bool set_sample_rate(double sample_rate); + bool set_num_channels (int nchannels); // ACCESSORS @@ -63,6 +65,7 @@ public: int get_decimation_count () const; int get_trigger_channel () const; gr_trigger_mode get_trigger_mode () const; + gr_trigger_slope get_trigger_slope () const; double get_trigger_level () const; // # of samples written to each output record. diff --git a/gnuradio-core/src/lib/io/gr_trigger_mode.h b/gnuradio-core/src/lib/io/gr_trigger_mode.h index 18d49ecfd..63f6b1c98 100644 --- a/gnuradio-core/src/lib/io/gr_trigger_mode.h +++ b/gnuradio-core/src/lib/io/gr_trigger_mode.h @@ -24,9 +24,14 @@ #define INCLUDED_GR_TRIGGER_MODE_H enum gr_trigger_mode { - gr_TRIG_AUTO, // auto trigger (on anything) - gr_TRIG_POS_SLOPE, // trigger on positive slope across trigger level - gr_TRIG_NEG_SLOPE // trigger on negative slope across trigger level + gr_TRIG_MODE_FREE, + gr_TRIG_MODE_AUTO, + gr_TRIG_MODE_NORM, +}; + +enum gr_trigger_slope { + gr_TRIG_SLOPE_POS, + gr_TRIG_SLOPE_NEG, }; #endif /* INCLUDED_GR_TRIGGER_MODE_H */ diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index ed7feb49d..3538942ca 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +51,7 @@ %include "gr_file_source.i" %include "gr_file_descriptor_sink.i" %include "gr_file_descriptor_source.i" +%include "gr_histo_sink.i" %include "microtune_xxxx_eval_board.i" %include "microtune_4702_eval_board.i" %include "microtune_4937_eval_board.i" -- cgit From ed236703145cb56e7e69c5605c5fbf01a1ab3878 Mon Sep 17 00:00:00 2001 From: eb Date: Fri, 22 May 2009 16:11:15 +0000 Subject: doc fixes! work-in-progress git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11085 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/gr_file_descriptor_sink.h | 2 +- gnuradio-core/src/lib/io/gr_file_descriptor_source.h | 2 +- gnuradio-core/src/lib/io/gr_file_sink.h | 2 +- gnuradio-core/src/lib/io/gr_file_source.h | 2 +- gnuradio-core/src/lib/io/gr_histo_sink_f.h | 2 +- gnuradio-core/src/lib/io/gr_message_sink.h | 2 +- gnuradio-core/src/lib/io/gr_message_source.h | 2 +- gnuradio-core/src/lib/io/gr_oscope_sink_f.h | 2 +- gnuradio-core/src/lib/io/gr_oscope_sink_x.h | 2 +- gnuradio-core/src/lib/io/gr_udp_sink.h | 2 +- gnuradio-core/src/lib/io/gr_udp_source.h | 2 +- gnuradio-core/src/lib/io/gr_wavfile_sink.h | 2 +- gnuradio-core/src/lib/io/gr_wavfile_source.h | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h index 4b5ceff31..fa8fa3f05 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h @@ -32,7 +32,7 @@ gr_file_descriptor_sink_sptr gr_make_file_descriptor_sink (size_t itemsize, int /*! * \brief Write stream to file descriptor. - * \ingroup sink + * \ingroup sink_blk */ class gr_file_descriptor_sink : public gr_sync_block diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_source.h b/gnuradio-core/src/lib/io/gr_file_descriptor_source.h index b233580c6..a9f117286 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_source.h +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_source.h @@ -33,7 +33,7 @@ gr_make_file_descriptor_source (size_t itemsize, int fd, bool repeat = false); /*! * \brief Read stream from file descriptor. - * \ingroup source + * \ingroup source_blk */ class gr_file_descriptor_source : public gr_sync_block diff --git a/gnuradio-core/src/lib/io/gr_file_sink.h b/gnuradio-core/src/lib/io/gr_file_sink.h index 16cd4befc..b9ad06cd6 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_sink.h @@ -33,7 +33,7 @@ gr_file_sink_sptr gr_make_file_sink(size_t itemsize, const char *filename); /*! * \brief Write stream to file. - * \ingroup sink + * \ingroup sink_blk */ class gr_file_sink : public gr_sync_block, public gr_file_sink_base diff --git a/gnuradio-core/src/lib/io/gr_file_source.h b/gnuradio-core/src/lib/io/gr_file_source.h index bf490040b..5f5c2564e 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.h +++ b/gnuradio-core/src/lib/io/gr_file_source.h @@ -33,7 +33,7 @@ gr_make_file_source (size_t itemsize, const char *filename, bool repeat = false) /*! * \brief Read stream from file - * \ingroup source + * \ingroup source_blk */ class gr_file_source : public gr_sync_block diff --git a/gnuradio-core/src/lib/io/gr_histo_sink_f.h b/gnuradio-core/src/lib/io/gr_histo_sink_f.h index ae34d302d..640398c60 100644 --- a/gnuradio-core/src/lib/io/gr_histo_sink_f.h +++ b/gnuradio-core/src/lib/io/gr_histo_sink_f.h @@ -34,7 +34,7 @@ gr_histo_sink_f_sptr gr_make_histo_sink_f (gr_msg_queue_sptr msgq); /*! * \brief Histogram module. - * \ingroup sink + * \ingroup sink_blk */ class gr_histo_sink_f : public gr_sync_block { diff --git a/gnuradio-core/src/lib/io/gr_message_sink.h b/gnuradio-core/src/lib/io/gr_message_sink.h index 9126358cb..5f1e5f91f 100644 --- a/gnuradio-core/src/lib/io/gr_message_sink.h +++ b/gnuradio-core/src/lib/io/gr_message_sink.h @@ -36,7 +36,7 @@ gr_message_sink_sptr gr_make_message_sink (size_t itemsize, /*! * \brief Gather received items into messages and insert into msgq - * \ingroup sink + * \ingroup sink_blk */ class gr_message_sink : public gr_sync_block { diff --git a/gnuradio-core/src/lib/io/gr_message_source.h b/gnuradio-core/src/lib/io/gr_message_source.h index 4a1378c2b..5a5c6a5d8 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.h +++ b/gnuradio-core/src/lib/io/gr_message_source.h @@ -34,7 +34,7 @@ gr_message_source_sptr gr_make_message_source (size_t itemsize, int msgq_limit=0 /*! * \brief Turn received messages into a stream - * \ingroup source + * \ingroup source_blk */ class gr_message_source : public gr_sync_block { diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_f.h b/gnuradio-core/src/lib/io/gr_oscope_sink_f.h index 22d145c54..1a8022b89 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_f.h +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_f.h @@ -34,7 +34,7 @@ gr_oscope_sink_f_sptr gr_make_oscope_sink_f (double sampling_rate, gr_msg_queue_ /*! * \brief Building block for python oscilloscope module. - * \ingroup sink + * \ingroup sink_blk * * Accepts multiple float streams. */ diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_x.h b/gnuradio-core/src/lib/io/gr_oscope_sink_x.h index 408979eb6..62cf65100 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_x.h +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_x.h @@ -30,7 +30,7 @@ class gr_oscope_guts; /*! * \brief Abstract class for python oscilloscope module. - * \ingroup sink + * \ingroup sink_blk * * Don't instantiate this. Use gr_oscope_sink_f or gr_oscope_sink_c instead. */ diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.h b/gnuradio-core/src/lib/io/gr_udp_sink.h index 99f1b2935..13b2befc9 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.h +++ b/gnuradio-core/src/lib/io/gr_udp_sink.h @@ -47,7 +47,7 @@ gr_make_udp_sink (size_t itemsize, /*! * \brief Write stream to an UDP socket. - * \ingroup sink + * \ingroup sink_blk * * \param itemsize The size (in bytes) of the item datatype * \param src The source address as either the host name or the 'numbers-and-dots' diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h index 049740159..afc41a45a 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.h +++ b/gnuradio-core/src/lib/io/gr_udp_source.h @@ -44,7 +44,7 @@ gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *src, /*! * \brief Read stream from an UDP socket. - * \ingroup sink + * \ingroup source_blk * * \param itemsize The size (in bytes) of the item datatype * \param src The source address as either the host name or the 'numbers-and-dots' diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.h b/gnuradio-core/src/lib/io/gr_wavfile_sink.h index 9429165f6..fd1d0bf6f 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.h +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.h @@ -48,7 +48,7 @@ gr_make_wavfile_sink (const char *filename, * Values are within [-1;1]. * Check gr_make_wavfile_source() for extra info. * - * \ingroup sink + * \ingroup sink_blk */ class gr_wavfile_sink : public gr_sync_block { diff --git a/gnuradio-core/src/lib/io/gr_wavfile_source.h b/gnuradio-core/src/lib/io/gr_wavfile_source.h index d737b441b..0c663f0a0 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_source.h +++ b/gnuradio-core/src/lib/io/gr_wavfile_source.h @@ -37,7 +37,7 @@ gr_make_wavfile_source (const char *filename, bool repeat = false); * Unless otherwise called, values are within [-1;1]. * Check gr_make_wavfile_source() for extra info. * - * \ingroup source + * \ingroup source_blk */ class gr_wavfile_source : public gr_sync_block -- cgit From 40b8a57d69b4b85f207fb0408347c210e23202cc Mon Sep 17 00:00:00 2001 From: jcorgan Date: Wed, 27 May 2009 01:54:41 +0000 Subject: Merged r11123:11148 from jcorgan/np into trunk. Adds --enable-python option to configure (defaults to yes). Using --disable-python or --enable-python=no will cause only C++ API targets to be created and installed. Several new shared libraries are now created. Where in the past, the C++ objects of the actual gnuradio blocks that were in a component were hidden inside their corresponding Python extension modules, these are now split out into a libgnuradio-foo.so library, and the _foo.so Python module is linked to that. This has been the way several top- level components have operated for some time, such as gr-audio-alsa and gr-usrp and gr-usrp2. This changeset applies that pattern to all components. C++ API users can use pkg-config to discover the cflags and libs parameters needed to include and link against these libraries. These components have not been tested: gr-comedi gr-audio-osx gr-audio-windows Passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11150 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/Makefile.am | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index 4583a033c..9eacd137d 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -93,9 +93,7 @@ grinclude_HEADERS = \ gr_wavfile_sink.h \ gri_wavfile.h - - - +if PYTHON swiginclude_HEADERS = \ io.i \ gr_file_sink.i \ @@ -116,4 +114,4 @@ swiginclude_HEADERS = \ gr_udp_source.i \ gr_wavfile_source.i \ gr_wavfile_sink.i - +endif -- cgit From c276a4ffee9314d2528166547abfd2c09d29713f Mon Sep 17 00:00:00 2001 From: jcorgan Date: Thu, 9 Jul 2009 02:55:51 +0000 Subject: Merged r11377:11390 from jcorgan/usrp-headers in to trunk. * Public USRP(1) header files are now in their own source directory and install into $(includedir)/usrp. This was done to avoid name clashes in the top-level include directory. Only users who are developing directly to libusrp in C++ are affected; the GNU Radio C++ and Python APIs are unchanged. The simple change required by this update is to change: #include to #include ...in your source code. * Removed usrp-inband code from tree (put into limbo directory.) This code has become unmaintained and has started to suffer from bitrot. A checkpoint tag has been made for anyone still needing to use it: http://gnuradio.org/svn/gnuradio/tags/checkpoints/trunk-20090708-pre-usrp-reorg The plan during the 3.2->3.3 development cycle is to replace the functions done by the in-band code with extensions to the existing gr-usrp blocks using the new message passing architecture. The USRP hardware FPGA code that provided the inband interface has not been removed; however, it too has become unmaintained and will likely be rewritten/replaced during the 3.3 timeframe. The trunk passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11394 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/gri_wavfile.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gri_wavfile.cc b/gnuradio-core/src/lib/io/gri_wavfile.cc index c1a2b7c73..b8375edc2 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.cc +++ b/gnuradio-core/src/lib/io/gri_wavfile.cc @@ -32,8 +32,7 @@ // WAV files are always little-endian, so we need some byte switching macros -// FIXME: These need to be refactored into a separate endianess header file -// as they duplicate routines defined in usrp/host/lib/legacy/usrp_bytesex.h +// FIXME: Use libgruel versions #ifdef WORDS_BIGENDIAN -- cgit From 4b4da4852482546157abbf8589f2a85bac6c3509 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sat, 25 Jul 2009 17:39:00 +0000 Subject: Merge r11462:11485 from jcorgan/omni into trunk. Removes dependency on omnithreads from gnuradio-core. Trunk passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11486 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/gr_file_sink_base.cc | 9 +++++---- gnuradio-core/src/lib/io/gr_file_sink_base.h | 6 +++--- gnuradio-core/src/lib/io/gr_udp_sink.cc | 8 +++++--- gnuradio-core/src/lib/io/gr_udp_sink.h | 8 +++++--- gnuradio-core/src/lib/io/gr_udp_source.cc | 6 +++--- gnuradio-core/src/lib/io/gr_udp_source.h | 7 ++++--- gnuradio-core/src/lib/io/gr_wavfile_sink.cc | 13 +++++++------ gnuradio-core/src/lib/io/gr_wavfile_sink.h | 6 +++--- gnuradio-core/src/lib/io/gri_logger.cc | 6 +++++- gnuradio-core/src/lib/io/gri_logger.h | 6 +++++- 10 files changed, 45 insertions(+), 30 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.cc b/gnuradio-core/src/lib/io/gr_file_sink_base.cc index 29ac0dbb1..5ddeeb4d5 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2006,2007 Free Software Foundation, Inc. + * Copyright 2004,2006,2007,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -31,6 +31,7 @@ #include #include #include +#include // win32 (mingw/msvc) specific #ifdef HAVE_IO_H @@ -68,7 +69,7 @@ gr_file_sink_base::~gr_file_sink_base () bool gr_file_sink_base::open(const char *filename) { - omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function // we use the open system call to get access to the O_LARGEFILE flag. int fd; @@ -96,7 +97,7 @@ gr_file_sink_base::open(const char *filename) void gr_file_sink_base::close() { - omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function if (d_new_fp){ fclose(d_new_fp); @@ -109,7 +110,7 @@ void gr_file_sink_base::do_update() { if (d_updated){ - omni_mutex_lock l(d_mutex); // hold mutex for duration of this block + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this block if (d_fp) fclose(d_fp); d_fp = d_new_fp; // install new file pointer diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.h b/gnuradio-core/src/lib/io/gr_file_sink_base.h index f36f5ac97..0c028d7fd 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.h +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2007 Free Software Foundation, Inc. + * Copyright 2004,2007,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,7 +23,7 @@ #ifndef INCLUDED_GR_FILE_SINK_BASE_H #define INCLUDED_GR_FILE_SINK_BASE_H -#include +#include #include /*! @@ -36,7 +36,7 @@ class gr_file_sink_base FILE *d_new_fp; // new FILE pointer bool d_updated; // is there a new FILE pointer? bool d_is_binary; - omni_mutex d_mutex; + boost::mutex d_mutex; protected: gr_file_sink_base(const char *filename, bool is_binary); diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index 215eaf8d5..d37adfb8a 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008 Free Software Foundation, Inc. + * Copyright 2007,2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -36,6 +36,8 @@ typedef void* optval_t; typedef char* optval_t; #endif +#include + #define SNK_VERBOSE 0 gr_udp_sink::gr_udp_sink (size_t itemsize, @@ -110,7 +112,7 @@ gr_udp_sink::~gr_udp_sink () bool gr_udp_sink::open() { - omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function // create socket if((d_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { @@ -153,7 +155,7 @@ gr_udp_sink::open() void gr_udp_sink::close() { - omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function if (d_socket){ shutdown(d_socket, SHUT_RDWR); diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.h b/gnuradio-core/src/lib/io/gr_udp_sink.h index 13b2befc9..f22b92dd0 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.h +++ b/gnuradio-core/src/lib/io/gr_udp_sink.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008 Free Software Foundation, Inc. + * Copyright 2007,2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,7 +24,7 @@ #define INCLUDED_GR_UDP_SINK_H #include -#include +#include #if defined(HAVE_SOCKET) #include #include @@ -36,6 +36,8 @@ #include #endif +#include + class gr_udp_sink; typedef boost::shared_ptr gr_udp_sink_sptr; @@ -69,7 +71,7 @@ class gr_udp_sink : public gr_sync_block private: size_t d_itemsize; bool d_updated; - omni_mutex d_mutex; + gruel::mutex d_mutex; int d_payload_size; // maximum transmission unit (packet length) int d_socket; // handle to socket diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index 9b6ee6e7d..d76d0ee32 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008 Free Software Foundation, Inc. + * Copyright 2007,2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -90,7 +90,7 @@ gr_udp_source::~gr_udp_source () bool gr_udp_source::open() { - omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function // create socket d_socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); if(d_socket == -1) { @@ -137,7 +137,7 @@ gr_udp_source::open() void gr_udp_source::close() { - omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function if (d_socket){ shutdown(d_socket, SHUT_RDWR); diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h index afc41a45a..61d719e4d 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.h +++ b/gnuradio-core/src/lib/io/gr_udp_source.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008 Free Software Foundation, Inc. + * Copyright 2007,2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,7 +24,6 @@ #define INCLUDED_GR_UDP_SOURCE_H #include -#include #if defined(HAVE_SOCKET) #include #include @@ -36,6 +35,8 @@ #include #endif +#include + class gr_udp_source; typedef boost::shared_ptr gr_udp_source_sptr; @@ -63,7 +64,7 @@ class gr_udp_source : public gr_sync_block private: size_t d_itemsize; bool d_updated; - omni_mutex d_mutex; + gruel::mutex d_mutex; int d_payload_size; // maximum transmission unit (packet length) int d_socket; // handle to socket diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc index f06c33d5c..72e4ef51e 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2006,2007,2008 Free Software Foundation, Inc. + * Copyright 2004,2006,2007,2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -32,6 +32,7 @@ #include #include #include +#include // win32 (mingw/msvc) specific #ifdef HAVE_IO_H @@ -103,7 +104,7 @@ gr_wavfile_sink::gr_wavfile_sink(const char *filename, bool gr_wavfile_sink::open(const char* filename) { - omni_mutex_lock l(d_mutex); + gruel::scoped_lock guard(d_mutex); // we use the open system call to get access to the O_LARGEFILE flag. int fd; @@ -141,7 +142,7 @@ gr_wavfile_sink::open(const char* filename) void gr_wavfile_sink::close() { - omni_mutex_lock l(d_mutex); + gruel::scoped_lock guard(d_mutex); if (!d_fp) return; @@ -230,7 +231,7 @@ gr_wavfile_sink::convert_to_short(float sample) void gr_wavfile_sink::set_bits_per_sample(int bits_per_sample) { - omni_mutex_lock l(d_mutex); + gruel::scoped_lock guard(d_mutex); if (bits_per_sample == 8 || bits_per_sample == 16) { d_bytes_per_sample_new = bits_per_sample / 8; } @@ -240,7 +241,7 @@ gr_wavfile_sink::set_bits_per_sample(int bits_per_sample) void gr_wavfile_sink::set_sample_rate(unsigned int sample_rate) { - omni_mutex_lock l(d_mutex); + gruel::scoped_lock guard(d_mutex); d_sample_rate = sample_rate; } @@ -252,7 +253,7 @@ gr_wavfile_sink::do_update() return; } - omni_mutex_lock l(d_mutex); // hold mutex for duration of this block + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this block if (d_fp) { close_wav(); } diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.h b/gnuradio-core/src/lib/io/gr_wavfile_sink.h index fd1d0bf6f..a1d6ed527 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.h +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008 Free Software Foundation, Inc. + * Copyright 2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -25,7 +25,7 @@ #include #include -#include +#include class gr_wavfile_sink; typedef boost::shared_ptr gr_wavfile_sink_sptr; @@ -76,7 +76,7 @@ private: FILE *d_fp; FILE *d_new_fp; bool d_updated; - omni_mutex d_mutex; + boost::mutex d_mutex; /*! * \brief Convert a sample value within [-1;+1] to a corresponding diff --git a/gnuradio-core/src/lib/io/gri_logger.cc b/gnuradio-core/src/lib/io/gri_logger.cc index c085a93c8..473a7c5ed 100644 --- a/gnuradio-core/src/lib/io/gri_logger.cc +++ b/gnuradio-core/src/lib/io/gri_logger.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,6 +24,8 @@ #include #endif +#if 0 // This needs reimplementation with boost threads and synchronization + #include #include #include @@ -172,3 +174,5 @@ gri_logger::printf(const char *format, ...) if (n > -1 && n < (ssize_t) sizeof(buf)) write(buf, n); } + +#endif diff --git a/gnuradio-core/src/lib/io/gri_logger.h b/gnuradio-core/src/lib/io/gri_logger.h index e5caf7d06..0a1414540 100644 --- a/gnuradio-core/src/lib/io/gri_logger.h +++ b/gnuradio-core/src/lib/io/gri_logger.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -22,6 +22,8 @@ #ifndef INCLUDED_GRI_LOGGER_H #define INCLUDED_GRI_LOGGER_H +#if 0 // This needs reimplementation with boost threads and synchronization + #include #include #include @@ -52,4 +54,6 @@ public: void printf(const char *format, ...); }; +#endif + #endif /* INCLUDED_GRI_LOGGER_H */ -- cgit From 4e843330290a3fd4354d5ab3acc599b7f7465587 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Thu, 6 Aug 2009 23:21:38 +0000 Subject: Adds constructor for gr.message_source that takes existing msgq. A gr.message_source object can now be created in one of two ways: blk = gr.message_source(itemsize, limit) msgq = gr.msg_queue(limit) blk = gr.message_source(itemsize, msgq) git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11541 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/gr_message_source.cc | 15 +++++++++++++++ gnuradio-core/src/lib/io/gr_message_source.h | 4 ++++ gnuradio-core/src/lib/io/gr_message_source.i | 2 ++ 3 files changed, 21 insertions(+) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_message_source.cc b/gnuradio-core/src/lib/io/gr_message_source.cc index 3fbe3708e..3efc5b321 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.cc +++ b/gnuradio-core/src/lib/io/gr_message_source.cc @@ -43,6 +43,13 @@ gr_make_message_source(size_t itemsize, int msgq_limit) return gr_message_source_sptr(new gr_message_source(itemsize, msgq_limit)); } +// public constructor that takes existing message queue +gr_message_source_sptr +gr_make_message_source(size_t itemsize, gr_msg_queue_sptr msgq) +{ + return gr_message_source_sptr(new gr_message_source(itemsize, msgq)); +} + gr_message_source::gr_message_source (size_t itemsize, int msgq_limit) : gr_sync_block("message_source", gr_make_io_signature(0, 0, 0), @@ -51,6 +58,14 @@ gr_message_source::gr_message_source (size_t itemsize, int msgq_limit) { } +gr_message_source::gr_message_source (size_t itemsize, gr_msg_queue_sptr msgq) + : gr_sync_block("message_source", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(1, 1, itemsize)), + d_itemsize(itemsize), d_msgq(msgq), d_msg_offset(0), d_eof(false) +{ +} + gr_message_source::~gr_message_source() { } diff --git a/gnuradio-core/src/lib/io/gr_message_source.h b/gnuradio-core/src/lib/io/gr_message_source.h index 5a5c6a5d8..46a808754 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.h +++ b/gnuradio-core/src/lib/io/gr_message_source.h @@ -31,6 +31,7 @@ class gr_message_source; typedef boost::shared_ptr gr_message_source_sptr; gr_message_source_sptr gr_make_message_source (size_t itemsize, int msgq_limit=0); +gr_message_source_sptr gr_make_message_source (size_t itemsize, gr_msg_queue_sptr msgq); /*! * \brief Turn received messages into a stream @@ -47,9 +48,12 @@ class gr_message_source : public gr_sync_block friend gr_message_source_sptr gr_make_message_source(size_t itemsize, int msgq_limit); + friend gr_message_source_sptr + gr_make_message_source(size_t itemsize, gr_msg_queue_sptr msgq); protected: gr_message_source (size_t itemsize, int msgq_limit); + gr_message_source (size_t itemsize, gr_msg_queue_sptr msgq); public: ~gr_message_source (); diff --git a/gnuradio-core/src/lib/io/gr_message_source.i b/gnuradio-core/src/lib/io/gr_message_source.i index fdc74741e..8a9c762d0 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.i +++ b/gnuradio-core/src/lib/io/gr_message_source.i @@ -23,11 +23,13 @@ GR_SWIG_BLOCK_MAGIC(gr,message_source); gr_message_source_sptr gr_make_message_source (size_t itemsize, int msgq_limit=0); +gr_message_source_sptr gr_make_message_source (size_t itemsize, gr_msg_queue_sptr msgq); class gr_message_source : public gr_sync_block { protected: gr_message_source (size_t itemsize, int msgq_limit); + gr_message_source (size_t itemsize, gr_msg_queue_sptr msgq); public: ~gr_message_source (); -- cgit From 253018c6cdb114f5662a2d7ba8ed748c6e68e3a7 Mon Sep 17 00:00:00 2001 From: git Date: Fri, 14 Aug 2009 18:10:11 +0000 Subject: Added git ignore files auto created from svn:ignore properties. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11592 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/io/.gitignore | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 gnuradio-core/src/lib/io/.gitignore (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/.gitignore b/gnuradio-core/src/lib/io/.gitignore new file mode 100644 index 000000000..a02b6ff73 --- /dev/null +++ b/gnuradio-core/src/lib/io/.gitignore @@ -0,0 +1,8 @@ +/Makefile +/Makefile.in +/.la +/.lo +/.deps +/.libs +/*.la +/*.lo -- cgit From 36c3f0a064cdce1524e85147ac754c5a9621f372 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 10 Oct 2009 16:39:49 -0700 Subject: Use gruel::mutex instead of pthread_mutex in gr_histo_sink_f. Patch-by: Don Ward --- gnuradio-core/src/lib/io/gr_histo_sink_f.cc | 11 +++-------- gnuradio-core/src/lib/io/gr_histo_sink_f.h | 4 ++-- 2 files changed, 5 insertions(+), 10 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_histo_sink_f.cc b/gnuradio-core/src/lib/io/gr_histo_sink_f.cc index a923a7e45..2885fe428 100644 --- a/gnuradio-core/src/lib/io/gr_histo_sink_f.cc +++ b/gnuradio-core/src/lib/io/gr_histo_sink_f.cc @@ -53,7 +53,6 @@ gr_histo_sink_f::gr_histo_sink_f (gr_msg_queue_sptr msgq) : gr_sync_block ("histo_sink_f", gr_make_io_signature (1, 1, sizeof (float)), gr_make_io_signature (0, 0, 0)), d_msgq (msgq), d_num_bins(11), d_frame_size(1000), d_sample_count(0), d_bins(NULL), d_samps(NULL) { - pthread_mutex_init(&d_mutex, 0); //allocate arrays and clear set_num_bins(d_num_bins); set_frame_size(d_frame_size); @@ -61,7 +60,6 @@ gr_histo_sink_f::gr_histo_sink_f (gr_msg_queue_sptr msgq) gr_histo_sink_f::~gr_histo_sink_f (void) { - pthread_mutex_destroy(&d_mutex); delete [] d_samps; delete [] d_bins; } @@ -72,7 +70,7 @@ gr_histo_sink_f::work (int noutput_items, gr_vector_void_star &output_items) { const float *in = (const float *) input_items[0]; - pthread_mutex_lock(&d_mutex); + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function for (unsigned int i = 0; i < (unsigned int)noutput_items; i++){ d_samps[d_sample_count] = in[i]; d_sample_count++; @@ -82,7 +80,6 @@ gr_histo_sink_f::work (int noutput_items, clear(); } } - pthread_mutex_unlock(&d_mutex); return noutput_items; } @@ -148,22 +145,20 @@ gr_histo_sink_f::get_num_bins(void){ **************************************************/ void gr_histo_sink_f::set_frame_size(unsigned int frame_size){ - pthread_mutex_lock(&d_mutex); + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function d_frame_size = frame_size; /* allocate a new sample array */ delete [] d_samps; d_samps = new float[d_frame_size]; clear(); - pthread_mutex_unlock(&d_mutex); } void gr_histo_sink_f::set_num_bins(unsigned int num_bins){ - pthread_mutex_lock(&d_mutex); + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function d_num_bins = num_bins; /* allocate a new bin array */ delete [] d_bins; d_bins = new unsigned int[d_num_bins]; clear(); - pthread_mutex_unlock(&d_mutex); } diff --git a/gnuradio-core/src/lib/io/gr_histo_sink_f.h b/gnuradio-core/src/lib/io/gr_histo_sink_f.h index 640398c60..8ba45ec55 100644 --- a/gnuradio-core/src/lib/io/gr_histo_sink_f.h +++ b/gnuradio-core/src/lib/io/gr_histo_sink_f.h @@ -25,7 +25,7 @@ #include #include -#include +#include class gr_histo_sink_f; typedef boost::shared_ptr gr_histo_sink_f_sptr; @@ -45,7 +45,7 @@ private: unsigned int d_sample_count; unsigned int *d_bins; float *d_samps; - pthread_mutex_t d_mutex; + gruel::mutex d_mutex; friend gr_histo_sink_f_sptr gr_make_histo_sink_f (gr_msg_queue_sptr msgq); gr_histo_sink_f (gr_msg_queue_sptr msgq); -- cgit From b0d32c6c20cadaa544aeaa7b5257919674e8d0ad Mon Sep 17 00:00:00 2001 From: Don Ward Date: Thu, 15 Apr 2010 14:37:04 -0400 Subject: Ignore ENOPROTOOPT return from setsockopt(SO_LINGER) SO_LINGER is not valid for SOCK_DGRAM sockets on Windows, so we expect setsockopt to return ENOPROTOOPT (invalid option for protocol) on Cygwin and MinGW. If it happens on any other system it should probably be ignored there, too. --- gnuradio-core/src/lib/io/gr_udp_sink.cc | 6 ++++-- gnuradio-core/src/lib/io/gr_udp_source.cc | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) mode change 100644 => 100755 gnuradio-core/src/lib/io/gr_udp_sink.cc mode change 100644 => 100755 gnuradio-core/src/lib/io/gr_udp_source.cc (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc old mode 100644 new mode 100755 index d37adfb8a..a837e731e --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -132,8 +132,10 @@ gr_udp_sink::open() lngr.l_onoff = 1; lngr.l_linger = 0; if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (optval_t)&lngr, sizeof(linger)) == -1) { - perror("SO_LINGER"); - throw std::runtime_error("can't set socket option SO_LINGER"); + if(errno != ENOPROTOOPT) { // no SO_LINGER for SOCK_DGRAM on Windows + perror("SO_LINGER"); + throw std::runtime_error("can't set socket option SO_LINGER"); + } } // bind socket to an address and port number to listen on diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc old mode 100644 new mode 100755 index d76d0ee32..fed5b6142 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -110,8 +110,10 @@ gr_udp_source::open() lngr.l_onoff = 1; lngr.l_linger = 0; if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (optval_t)&lngr, sizeof(linger)) == -1) { - perror("SO_LINGER"); - throw std::runtime_error("can't set socket option SO_LINGER"); + if(errno != ENOPROTOOPT) { // no SO_LINGER for SOCK_DGRAM on Windows + perror("SO_LINGER"); + throw std::runtime_error("can't set socket option SO_LINGER"); + } } // Set a timeout on the receive function to not block indefinitely -- cgit From 545901e335f27600c460f749b66d60155a179492 Mon Sep 17 00:00:00 2001 From: U-DON-WORKBENCH\Don Date: Sun, 18 Apr 2010 10:19:30 -0400 Subject: Changes to gr_udp_{source,sink} for MinGW Initialize and cleanup after winsock DLL. Interpret winsock error codes. Use DWORD instead of timeval for setting timeout. --- gnuradio-core/src/lib/io/gr_udp_sink.cc | 80 +++++++++++++++++++++++------- gnuradio-core/src/lib/io/gr_udp_source.cc | 82 +++++++++++++++++++++++++------ 2 files changed, 130 insertions(+), 32 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index a837e731e..dff066288 100755 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -31,15 +31,52 @@ #include typedef void* optval_t; #else +#define USING_WINSOCK #define SHUT_RDWR 2 #define inet_aton(N,A) ( (A)->s_addr = inet_addr(N), ( (A)->s_addr != INADDR_NONE ) ) typedef char* optval_t; +#define ENOPROTOOPT 109 #endif #include #define SNK_VERBOSE 0 +static int is_error( int perr ) +{ + // Compare error to posix error code; return nonzero if match. +#if defined(USING_WINSOCK) + // All codes to be checked for must be defined below + int werr = WSAGetLastError(); + switch( werr ) { + case WSAETIMEDOUT: + return( perr == EAGAIN ); + case WSAENOPROTOOPT: + return( perr == ENOPROTOOPT ); + default: + fprintf(stderr,"gr_udp_source/is_error: unknown error %d\n", perr ); + throw std::runtime_error("internal error"); + } + return 0; +#else + return( perr == errno ); +#endif +} + +static void report_error( char *msg1, char *msg2 ) +{ + // Deal with errors, both posix and winsock +#if defined(USING_WINSOCK) + int werr = WSAGetLastError(); + fprintf(stderr, "%s: winsock error %d\n", msg1, werr ); +#else + perror(msg1); +#endif + if( msg2 != NULL ) + throw std::runtime_error(msg2); + return; +} + gr_udp_sink::gr_udp_sink (size_t itemsize, const char *src, unsigned short port_src, const char *dst, unsigned short port_dst, @@ -50,6 +87,15 @@ gr_udp_sink::gr_udp_sink (size_t itemsize, d_itemsize (itemsize), d_updated(false), d_payload_size(payload_size) { int ret = 0; + +#if !defined(HAVE_SOCKET) // for Windows (with MinGW) + // initialize winsock DLL + WSADATA wsaData; + int iResult = WSAStartup( MAKEWORD(2,2), &wsaData ); + if( iResult != NO_ERROR ) { + report_error( "gr_udp_source WSAStartup", "can't open socket" ); + } +#endif // Set up the address stucture for the source address and port numbers // Get the source IP address from the host name @@ -59,8 +105,8 @@ gr_udp_sink::gr_udp_sink (size_t itemsize, } else { // assume it was specified as an IP address if((ret=inet_aton(src, &d_ip_src)) == 0) { // format IP address - perror("Not a valid source IP address or host name"); - throw std::runtime_error("can't initialize source socket"); + report_error("Not a valid source IP address or host name", + "can't initialize source socket"); } } @@ -71,8 +117,8 @@ gr_udp_sink::gr_udp_sink (size_t itemsize, } else { // assume it was specified as an IP address if((ret=inet_aton(dst, &d_ip_dst)) == 0) { // format IP address - perror("Not a valid destination IP address or host name"); - throw std::runtime_error("can't initialize destination socket"); + report_error("Not a valid destination IP address or host name", + "can't initialize destination socket"); } } @@ -107,6 +153,11 @@ gr_make_udp_sink (size_t itemsize, gr_udp_sink::~gr_udp_sink () { close(); + +#if !defined(HAVE_SOCKET) // for Windows (with MinGW) + // free winsock resources + WSACleanup(); +#endif } bool @@ -116,15 +167,13 @@ gr_udp_sink::open() // create socket if((d_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { - perror("socket open"); - throw std::runtime_error("can't open socket"); + report_error("socket open","can't open socket"); } // Turn on reuse address int opt_val = true; if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (optval_t)&opt_val, sizeof(int)) == -1) { - perror("SO_REUSEADDR"); - throw std::runtime_error("can't set socket option SO_REUSEADDR"); + report_error("SO_REUSEADDR","can't set socket option SO_REUSEADDR"); } // Don't wait when shutting down @@ -132,22 +181,19 @@ gr_udp_sink::open() lngr.l_onoff = 1; lngr.l_linger = 0; if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (optval_t)&lngr, sizeof(linger)) == -1) { - if(errno != ENOPROTOOPT) { // no SO_LINGER for SOCK_DGRAM on Windows - perror("SO_LINGER"); - throw std::runtime_error("can't set socket option SO_LINGER"); + if( !is_error(ENOPROTOOPT) ) { // no SO_LINGER for SOCK_DGRAM on Windows + report_error("SO_LINGER","can't set socket option SO_LINGER"); } } // bind socket to an address and port number to listen on if(bind (d_socket, (sockaddr*)&d_sockaddr_src, sizeof(struct sockaddr)) == -1) { - perror("socket bind"); - throw std::runtime_error("can't bind socket"); + report_error("socket bind","can't bind socket"); } // Not sure if we should throw here or allow retries if(connect(d_socket, (sockaddr*)&d_sockaddr_dst, sizeof(struct sockaddr)) == -1) { - perror("socket connect"); - throw std::runtime_error("can't connect to socket"); + report_error("socket connect","can't connect to socket"); } d_updated = true; @@ -184,8 +230,8 @@ gr_udp_sink::work (int noutput_items, r = send(d_socket, (in+bytes_sent), bytes_to_send, 0); if(r == -1) { // error on send command - perror("udp_sink"); // there should be no error case where this function - return -1; // should not exit immediately + report_error("udp_sink",NULL); // there should be no error case where + return -1; // this function should not exit immediately } bytes_sent += r; diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index fed5b6142..9df47da2e 100755 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -33,13 +33,51 @@ #include typedef void* optval_t; #else +// Not posix, assume winsock +#define USING_WINSOCK #define SHUT_RDWR 2 #define inet_aton(N,A) ( (A)->s_addr = inet_addr(N), ( (A)->s_addr != INADDR_NONE ) ) typedef char* optval_t; +#define ENOPROTOOPT 109 #endif #define SRC_VERBOSE 0 +static int is_error( int perr ) +{ + // Compare error to posix error code; return nonzero if match. +#if defined(USING_WINSOCK) + // All codes to be checked for must be defined below + int werr = WSAGetLastError(); + switch( werr ) { + case WSAETIMEDOUT: + return( perr == EAGAIN ); + case WSAENOPROTOOPT: + return( perr == ENOPROTOOPT ); + default: + fprintf(stderr,"gr_udp_source/is_error: unknown error %d\n", perr ); + throw std::runtime_error("internal error"); + } + return 0; +#else + return( perr == errno ); +#endif +} + +static void report_error( char *msg1, char *msg2 ) +{ + // Deal with errors, both posix and winsock +#if defined(USING_WINSOCK) + int werr = WSAGetLastError(); + fprintf(stderr, "%s: winsock error %d\n", msg1, werr ); +#else + perror(msg1); +#endif + if( msg2 != NULL ) + throw std::runtime_error(msg2); + return; +} + gr_udp_source::gr_udp_source(size_t itemsize, const char *src, unsigned short port_src, int payload_size) : gr_sync_block ("udp_source", @@ -48,6 +86,15 @@ gr_udp_source::gr_udp_source(size_t itemsize, const char *src, d_itemsize(itemsize), d_updated(false), d_payload_size(payload_size), d_residual(0), d_temp_offset(0) { int ret = 0; + +#if !defined(HAVE_SOCKET) // for Windows (with MinGW) + // initialize winsock DLL + WSADATA wsaData; + int iResult = WSAStartup( MAKEWORD(2,2), &wsaData ); + if( iResult != NO_ERROR ) { + report_error( "gr_udp_source WSAStartup", "can't open socket" ); + } +#endif // Set up the address stucture for the source address and port numbers // Get the source IP address from the host name @@ -57,8 +104,8 @@ gr_udp_source::gr_udp_source(size_t itemsize, const char *src, } else { // assume it was specified as an IP address if((ret=inet_aton(src, &d_ip_src)) == 0) { // format IP address - perror("Not a valid source IP address or host name"); - throw std::runtime_error("can't initialize source socket"); + report_error("Not a valid source IP address or host name", + "can't initialize source socket"); } } @@ -85,6 +132,11 @@ gr_udp_source::~gr_udp_source () { delete [] d_temp_buff; close(); + +#if !defined(HAVE_SOCKET) // for Windows (with MinGW) + // free winsock resources + WSACleanup(); +#endif } bool @@ -94,15 +146,13 @@ gr_udp_source::open() // create socket d_socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); if(d_socket == -1) { - perror("socket open"); - throw std::runtime_error("can't open socket"); + report_error("socket open","can't open socket"); } // Turn on reuse address int opt_val = 1; if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (optval_t)&opt_val, sizeof(int)) == -1) { - perror("SO_REUSEADDR"); - throw std::runtime_error("can't set socket option SO_REUSEADDR"); + report_error("SO_REUSEADDR","can't set socket option SO_REUSEADDR"); } // Don't wait when shutting down @@ -110,26 +160,28 @@ gr_udp_source::open() lngr.l_onoff = 1; lngr.l_linger = 0; if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (optval_t)&lngr, sizeof(linger)) == -1) { - if(errno != ENOPROTOOPT) { // no SO_LINGER for SOCK_DGRAM on Windows - perror("SO_LINGER"); - throw std::runtime_error("can't set socket option SO_LINGER"); + if( !is_error(ENOPROTOOPT) ) { // no SO_LINGER for SOCK_DGRAM on Windows + report_error("SO_LINGER","can't set socket option SO_LINGER"); } } // Set a timeout on the receive function to not block indefinitely // This value can (and probably should) be changed + // Ignored on Cygwin +#if defined(USING_WINSOCK) + DWORD timeout = 1000; // milliseconds +#else timeval timeout; timeout.tv_sec = 1; timeout.tv_usec = 0; +#endif if(setsockopt(d_socket, SOL_SOCKET, SO_RCVTIMEO, (optval_t)&timeout, sizeof(timeout)) == -1) { - perror("SO_RCVTIMEO"); - throw std::runtime_error("can't set socket option SO_RCVTIMEO"); + report_error("SO_RCVTIMEO","can't set socket option SO_RCVTIMEO"); } // bind socket to an address and port number to listen on if(bind (d_socket, (sockaddr*)&d_sockaddr_src, sizeof(struct sockaddr)) == -1) { - perror("socket bind"); - throw std::runtime_error("can't bind socket"); + report_error("socket bind","can't bind socket"); } d_updated = true; @@ -187,7 +239,7 @@ gr_udp_source::work (int noutput_items, // Check if there was a problem; forget it if the operation just timed out if(r == -1) { - if(errno == EAGAIN) { // handle non-blocking call timeout + if( is_error(EAGAIN) ) { // handle non-blocking call timeout #if SRC_VERBOSE printf("UDP receive timed out\n"); #endif @@ -196,7 +248,7 @@ gr_udp_source::work (int noutput_items, break; } else { - perror("udp_source"); + report_error("udp_source",NULL); return -1; } } -- cgit From d1ae6560ab2b8b5d474e58f865314a6cf18b958c Mon Sep 17 00:00:00 2001 From: Don Ward Date: Sun, 18 Apr 2010 19:01:56 -0400 Subject: Use getaddrinfo in gr_udp_{source,sink} Using getaddrinfo allows more common code between posix and winsock systems. Remove unused variables and #include files. Close sockets when done. --- gnuradio-core/src/lib/io/gr_udp_sink.cc | 69 ++++++++++++++----------------- gnuradio-core/src/lib/io/gr_udp_sink.h | 21 +++------- gnuradio-core/src/lib/io/gr_udp_source.cc | 46 ++++++++++----------- gnuradio-core/src/lib/io/gr_udp_source.h | 16 +++---- 4 files changed, 66 insertions(+), 86 deletions(-) mode change 100644 => 100755 gnuradio-core/src/lib/io/gr_udp_source.h (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index dff066288..3d8d65145 100755 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -26,14 +26,15 @@ #include #include #include -#if defined(HAVE_SOCKET) -#include +#include #include +#include +#if defined(HAVE_NETDB_H) typedef void* optval_t; #else +// if not posix, assume winsock #define USING_WINSOCK #define SHUT_RDWR 2 -#define inet_aton(N,A) ( (A)->s_addr = inet_addr(N), ( (A)->s_addr != INADDR_NONE ) ) typedef char* optval_t; #define ENOPROTOOPT 109 #endif @@ -99,39 +100,24 @@ gr_udp_sink::gr_udp_sink (size_t itemsize, // Set up the address stucture for the source address and port numbers // Get the source IP address from the host name - struct hostent *hsrc = gethostbyname(src); - if(hsrc) { // if the source was provided as a host namex - d_ip_src = *(struct in_addr*)hsrc->h_addr_list[0]; - } - else { // assume it was specified as an IP address - if((ret=inet_aton(src, &d_ip_src)) == 0) { // format IP address - report_error("Not a valid source IP address or host name", - "can't initialize source socket"); - } - } + struct addrinfo hints; + memset( (void*)&hints, 0, sizeof(hints) ); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_DGRAM; + hints.ai_protocol = IPPROTO_UDP; + char port_str[7]; + sprintf( port_str, "%d", port_src ); + ret = getaddrinfo( src, port_str, &hints, &d_ip_src ); + if( ret != 0 ) + report_error("gr_udp_source/getaddrinfo", + "can't initialize source socket" ); // Get the destination IP address from the host name - struct hostent *hdst = gethostbyname(dst); - if(hdst) { // if the source was provided as a host namex - d_ip_dst = *(struct in_addr*)hdst->h_addr_list[0]; - } - else { // assume it was specified as an IP address - if((ret=inet_aton(dst, &d_ip_dst)) == 0) { // format IP address - report_error("Not a valid destination IP address or host name", - "can't initialize destination socket"); - } - } - - d_port_src = htons(port_src); // format port number - d_port_dst = htons(port_dst); // format port number - - d_sockaddr_src.sin_family = AF_INET; - d_sockaddr_src.sin_addr = d_ip_src; - d_sockaddr_src.sin_port = d_port_src; - - d_sockaddr_dst.sin_family = AF_INET; - d_sockaddr_dst.sin_addr = d_ip_dst; - d_sockaddr_dst.sin_port = d_port_dst; + sprintf( port_str, "%d", port_dst ); + ret = getaddrinfo( dst, port_str, &hints, &d_ip_dst ); + if( ret != 0 ) + report_error("gr_udp_source/getaddrinfo", + "can't initialize destination socket" ); open(); } @@ -152,6 +138,8 @@ gr_make_udp_sink (size_t itemsize, gr_udp_sink::~gr_udp_sink () { + freeaddrinfo(d_ip_src); + freeaddrinfo(d_ip_dst); close(); #if !defined(HAVE_SOCKET) // for Windows (with MinGW) @@ -166,7 +154,9 @@ gr_udp_sink::open() gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function // create socket - if((d_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { + d_socket = socket(d_ip_src->ai_family, d_ip_src->ai_socktype, + d_ip_src->ai_protocol); + if(d_socket == -1) { report_error("socket open","can't open socket"); } @@ -187,12 +177,12 @@ gr_udp_sink::open() } // bind socket to an address and port number to listen on - if(bind (d_socket, (sockaddr*)&d_sockaddr_src, sizeof(struct sockaddr)) == -1) { + if(bind (d_socket, d_ip_src->ai_addr, d_ip_src->ai_addrlen) == -1) { report_error("socket bind","can't bind socket"); } // Not sure if we should throw here or allow retries - if(connect(d_socket, (sockaddr*)&d_sockaddr_dst, sizeof(struct sockaddr)) == -1) { + if(connect(d_socket, d_ip_dst->ai_addr, d_ip_dst->ai_addrlen) == -1) { report_error("socket connect","can't connect to socket"); } @@ -207,6 +197,11 @@ gr_udp_sink::close() if (d_socket){ shutdown(d_socket, SHUT_RDWR); +#if defined(USING_WINSOCK) + closesocket(d_socket); +#else + ::close(d_socket); +#endif d_socket = 0; } d_updated = true; diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.h b/gnuradio-core/src/lib/io/gr_udp_sink.h index f22b92dd0..9f50ed7f0 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.h +++ b/gnuradio-core/src/lib/io/gr_udp_sink.h @@ -24,16 +24,12 @@ #define INCLUDED_GR_UDP_SINK_H #include -#include -#if defined(HAVE_SOCKET) -#include -#include +#if defined(HAVE_NETDB_H) +#include +#include // usually #included by ? #elif defined(HAVE_WINDOWS_H) #include -#include -#endif -#if defined(HAVE_NETINET_IN_H) -#include +#include #endif #include @@ -75,13 +71,8 @@ class gr_udp_sink : public gr_sync_block int d_payload_size; // maximum transmission unit (packet length) int d_socket; // handle to socket - int d_socket_rcv; // handle to socket retuned in the accept call - struct in_addr d_ip_src; // store the source ip info - struct in_addr d_ip_dst; // store the destination ip info - unsigned short d_port_src; // the port number to open for connections to this service - unsigned short d_port_dst; // port number of the remove system - struct sockaddr_in d_sockaddr_src; // store the source sockaddr data (formatted IP address and port number) - struct sockaddr_in d_sockaddr_dst; // store the destination sockaddr data (formatted IP address and port number) + struct addrinfo *d_ip_src; // store the source ip info + struct addrinfo *d_ip_dst; // store the destination ip info protected: /*! diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index 9df47da2e..f459e7f13 100755 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -29,14 +29,12 @@ #include #include #include -#if defined(HAVE_SOCKET) -#include +#if defined(HAVE_NETDB_H) typedef void* optval_t; #else -// Not posix, assume winsock +// if not posix, assume winsock #define USING_WINSOCK #define SHUT_RDWR 2 -#define inet_aton(N,A) ( (A)->s_addr = inet_addr(N), ( (A)->s_addr != INADDR_NONE ) ) typedef char* optval_t; #define ENOPROTOOPT 109 #endif @@ -98,22 +96,17 @@ gr_udp_source::gr_udp_source(size_t itemsize, const char *src, // Set up the address stucture for the source address and port numbers // Get the source IP address from the host name - struct hostent *hsrc = gethostbyname(src); - if(hsrc) { // if the source was provided as a host namex - d_ip_src = *(struct in_addr*)hsrc->h_addr_list[0]; - } - else { // assume it was specified as an IP address - if((ret=inet_aton(src, &d_ip_src)) == 0) { // format IP address - report_error("Not a valid source IP address or host name", - "can't initialize source socket"); - } - } - - d_port_src = htons(port_src); // format port number - - d_sockaddr_src.sin_family = AF_INET; - d_sockaddr_src.sin_addr = d_ip_src; - d_sockaddr_src.sin_port = d_port_src; + struct addrinfo hints; + memset( (void*)&hints, 0, sizeof(hints) ); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_DGRAM; + hints.ai_protocol = IPPROTO_UDP; + char port_str[7]; + sprintf( port_str, "%d", port_src ); + ret = getaddrinfo( src, port_str, &hints, &d_ip_src ); + if( ret != 0 ) + report_error("gr_udp_source/getaddrinfo", + "can't initialize source socket" ); d_temp_buff = new char[d_payload_size]; // allow it to hold up to payload_size bytes @@ -130,6 +123,7 @@ gr_make_udp_source (size_t itemsize, const char *ipaddr, gr_udp_source::~gr_udp_source () { + freeaddrinfo(d_ip_src); delete [] d_temp_buff; close(); @@ -144,7 +138,8 @@ gr_udp_source::open() { gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function // create socket - d_socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); + d_socket = socket(d_ip_src->ai_family, d_ip_src->ai_socktype, + d_ip_src->ai_protocol); if(d_socket == -1) { report_error("socket open","can't open socket"); } @@ -180,10 +175,10 @@ gr_udp_source::open() } // bind socket to an address and port number to listen on - if(bind (d_socket, (sockaddr*)&d_sockaddr_src, sizeof(struct sockaddr)) == -1) { + if(bind (d_socket, d_ip_src->ai_addr, d_ip_src->ai_addrlen) == -1) { report_error("socket bind","can't bind socket"); } - + d_updated = true; return d_socket != 0; } @@ -195,6 +190,11 @@ gr_udp_source::close() if (d_socket){ shutdown(d_socket, SHUT_RDWR); +#if defined(USING_WINSOCK) + closesocket(d_socket); +#else + ::close(d_socket); +#endif d_socket = 0; } d_updated = true; diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h old mode 100644 new mode 100755 index 61d719e4d..14d521dac --- a/gnuradio-core/src/lib/io/gr_udp_source.h +++ b/gnuradio-core/src/lib/io/gr_udp_source.h @@ -24,15 +24,12 @@ #define INCLUDED_GR_UDP_SOURCE_H #include -#if defined(HAVE_SOCKET) -#include -#include +#if defined(HAVE_NETDB_H) +#include +#include // usually #included by ? #elif defined(HAVE_WINDOWS_H) #include -#include -#endif -#if defined(HAVE_NETINET_IN_H) -#include +#include #endif #include @@ -68,10 +65,7 @@ class gr_udp_source : public gr_sync_block int d_payload_size; // maximum transmission unit (packet length) int d_socket; // handle to socket - int d_socket_rcv; // handle to socket retuned in the accept call - struct in_addr d_ip_src; // store the source IP address to use - unsigned short d_port_src; // the port number to open for connections to this service - struct sockaddr_in d_sockaddr_src; // store the source sockaddr data (formatted IP address and port number) + struct addrinfo *d_ip_src; // store the source IP address to use char *d_temp_buff; // hold buffer between calls ssize_t d_residual; // hold information about number of bytes stored in the temp buffer size_t d_temp_offset; // point to temp buffer location offset -- cgit From 3b8fcaa640d75573d314fb8616969ad2adf2a099 Mon Sep 17 00:00:00 2001 From: Don Ward Date: Mon, 19 Apr 2010 17:02:14 -0400 Subject: Discard data in gr_udp_sink until receiver is started. Also fixes warnings from gcc 4.3 and adds for usrp2. --- gnuradio-core/src/lib/io/gr_udp_sink.cc | 17 ++++++++++++----- gnuradio-core/src/lib/io/gr_udp_source.cc | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index 3d8d65145..b447dd3b3 100755 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -36,7 +36,6 @@ typedef void* optval_t; #define USING_WINSOCK #define SHUT_RDWR 2 typedef char* optval_t; -#define ENOPROTOOPT 109 #endif #include @@ -47,6 +46,8 @@ static int is_error( int perr ) { // Compare error to posix error code; return nonzero if match. #if defined(USING_WINSOCK) +#define ENOPROTOOPT 109 +#define ECONNREFUSED 111 // All codes to be checked for must be defined below int werr = WSAGetLastError(); switch( werr ) { @@ -54,6 +55,8 @@ static int is_error( int perr ) return( perr == EAGAIN ); case WSAENOPROTOOPT: return( perr == ENOPROTOOPT ); + case WSAECONNREFUSED: + return( perr == ECONNREFUSED ); default: fprintf(stderr,"gr_udp_source/is_error: unknown error %d\n", perr ); throw std::runtime_error("internal error"); @@ -64,7 +67,7 @@ static int is_error( int perr ) #endif } -static void report_error( char *msg1, char *msg2 ) +static void report_error( const char *msg1, const char *msg2 ) { // Deal with errors, both posix and winsock #if defined(USING_WINSOCK) @@ -217,7 +220,7 @@ gr_udp_sink::work (int noutput_items, ssize_t total_size = noutput_items*d_itemsize; #if SNK_VERBOSE - printf("Entered upd_sink\n"); + printf("Entered udp_sink\n"); #endif while(bytes_sent < total_size) { @@ -225,8 +228,12 @@ gr_udp_sink::work (int noutput_items, r = send(d_socket, (in+bytes_sent), bytes_to_send, 0); if(r == -1) { // error on send command - report_error("udp_sink",NULL); // there should be no error case where - return -1; // this function should not exit immediately + if( is_error(ECONNREFUSED) ) + r = bytes_to_send; // discard data until receiver is started + else { + report_error("udp_sink",NULL); // there should be no error case where + return -1; // this function should not exit immediately + } } bytes_sent += r; diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index f459e7f13..56499258c 100755 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -36,7 +36,6 @@ typedef void* optval_t; #define USING_WINSOCK #define SHUT_RDWR 2 typedef char* optval_t; -#define ENOPROTOOPT 109 #endif #define SRC_VERBOSE 0 @@ -45,6 +44,7 @@ static int is_error( int perr ) { // Compare error to posix error code; return nonzero if match. #if defined(USING_WINSOCK) +#define ENOPROTOOPT 109 // All codes to be checked for must be defined below int werr = WSAGetLastError(); switch( werr ) { -- cgit From a178f23be75489c1507060a8b0e9e59cd358dfba Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Mon, 26 Apr 2010 22:13:34 -0700 Subject: Convert gr-audio-portaudio to Boost via gruel Remove omnithread dependency in build for gr-audio-portaudio Remove unused debugging utility class in gnuradio-core (gri_logger) --- gnuradio-core/src/lib/io/Makefile.am | 2 - gnuradio-core/src/lib/io/gri_logger.cc | 178 --------------------------------- gnuradio-core/src/lib/io/gri_logger.h | 59 ----------- 3 files changed, 239 deletions(-) delete mode 100644 gnuradio-core/src/lib/io/gri_logger.cc delete mode 100644 gnuradio-core/src/lib/io/gri_logger.h (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index 9eacd137d..c52554645 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -39,7 +39,6 @@ libio_la_SOURCES = \ gr_oscope_guts.cc \ gr_oscope_sink_f.cc \ gr_oscope_sink_x.cc \ - gri_logger.cc \ i2c.cc \ i2c_bitbang.cc \ i2c_bbio.cc \ @@ -72,7 +71,6 @@ grinclude_HEADERS = \ gr_oscope_sink_f.h \ gr_oscope_sink_x.h \ gr_trigger_mode.h \ - gri_logger.h \ i2c.h \ i2c_bitbang.h \ i2c_bbio.h \ diff --git a/gnuradio-core/src/lib/io/gri_logger.cc b/gnuradio-core/src/lib/io/gri_logger.cc deleted file mode 100644 index 473a7c5ed..000000000 --- a/gnuradio-core/src/lib/io/gri_logger.cc +++ /dev/null @@ -1,178 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2009 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, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#if 0 // This needs reimplementation with boost threads and synchronization - -#include -#include -#include -#include -#include -#include - - -/* - * This class creates the thread that reads from the ringbuffer and - * and writes to the file. This is opaque to the user. - */ -class gri_log_poster : public omni_thread -{ - FILE *d_fp; - gr_buffer_sptr d_writer; - gr_buffer_reader_sptr d_reader; - omni_semaphore d_ringbuffer_ready; - volatile bool d_time_to_die; - volatile bool d_writer_overrun; - - virtual void* run_undetached(void * arg); - -public: - gri_log_poster(const char *filename); - ~gri_log_poster(); - - void kill() { d_time_to_die = true; post(); } - gr_buffer_sptr writer() const { return d_writer; } - void post() { d_ringbuffer_ready.post(); } - void note_writer_overrun() { d_writer_overrun = true; } -}; - -gri_log_poster::gri_log_poster(const char *filename) - : omni_thread(), - d_ringbuffer_ready(1, 1), // binary semaphore - d_time_to_die(false), - d_writer_overrun(false) -{ - if ((d_fp = fopen(filename, "w")) == 0){ - perror (filename); - throw std::runtime_error("can't open file"); - } - - // Create a 1MB buffer. - d_writer = gr_make_buffer(1 * 1024 * 1024, sizeof(unsigned char)); - d_reader = gr_buffer_add_reader(d_writer, 0); - - start_undetached(); // start the thread -} - -gri_log_poster::~gri_log_poster() -{ - if (d_fp != 0){ - fclose(d_fp); - d_fp = 0; - } -} - -/* - * This is the body of the logging thread. - */ -void * -gri_log_poster::run_undetached(void *arg) -{ - int nbytes; - - //fprintf(stderr, "Enter: run_undetached!\n"); - - while (!d_time_to_die){ - while ((nbytes = d_reader->items_available()) > 0){ - fwrite(d_reader->read_pointer(), 1, nbytes, d_fp); - d_reader->update_read_pointer(nbytes); - } - fflush(d_fp); - d_ringbuffer_ready.wait(); - - if (d_writer_overrun){ - fputs(">>>>> gri_logger: writer overrun. Info lost <<<<<\n", d_fp); - d_writer_overrun = false; - } - } - - // fprintf(stderr, "Exit: run_undetached!\n"); - return 0; -} - -// ------------------------------------------------------------------------ - -static boost::weak_ptr s_singleton; // weak pointer IQ test ;-) -static omni_mutex s_singleton_mutex; - -gri_logger_sptr -gri_logger::singleton() -{ - omni_mutex_lock l(s_singleton_mutex); - gri_logger_sptr r; - - if (r = s_singleton.lock()) - return r; - - r = gri_logger_sptr(new gri_logger("gri_logger.log")); - s_singleton = r; - return r; -} - - -gri_logger::gri_logger(const char *filename) -{ - d_poster = new gri_log_poster(filename); -} - -gri_logger::~gri_logger() -{ - d_poster->kill(); - d_poster->join(NULL); -} - -void -gri_logger::write(const void *buf, size_t count) -{ - omni_mutex_lock l(d_write_mutex); - gr_buffer_sptr writer = d_poster->writer(); - - // either write it all, or drop it on the ground - if (count <= (size_t) writer->space_available()){ - memcpy(writer->write_pointer(), buf, count); - writer->update_write_pointer(count); - d_poster->post(); - } - else { - d_poster->note_writer_overrun(); - } -} - -void -gri_logger::printf(const char *format, ...) -{ - va_list ap; - char buf[4096]; - int n; - - va_start(ap, format); - n = vsnprintf(buf, sizeof(buf), format, ap); - va_end(ap); - if (n > -1 && n < (ssize_t) sizeof(buf)) - write(buf, n); -} - -#endif diff --git a/gnuradio-core/src/lib/io/gri_logger.h b/gnuradio-core/src/lib/io/gri_logger.h deleted file mode 100644 index 0a1414540..000000000 --- a/gnuradio-core/src/lib/io/gri_logger.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2009 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, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDED_GRI_LOGGER_H -#define INCLUDED_GRI_LOGGER_H - -#if 0 // This needs reimplementation with boost threads and synchronization - -#include -#include -#include - -class gri_log_poster; -class gri_logger; -typedef boost::shared_ptr gri_logger_sptr; - - -/*! - * \brief non-blocking logging to a file. - * - * In reality, this may block, but only for a bounded time. - * Trust me, it's safe to use from portaudio and JACK callbacks. - */ -class gri_logger -{ - gri_log_poster *d_poster; - omni_mutex d_write_mutex; - -public: - static gri_logger_sptr singleton(); - - gri_logger(const char *filename); - ~gri_logger(); - - void write(const void *buf, size_t count); - void printf(const char *format, ...); -}; - -#endif - -#endif /* INCLUDED_GRI_LOGGER_H */ -- cgit From 3ff43f7487b43436cd0f49de80ebff2c1ff1a188 Mon Sep 17 00:00:00 2001 From: Don Ward Date: Fri, 30 Apr 2010 14:48:56 -0400 Subject: Updates to udp source/sink (select(), wait, cleanup) Use select() to avoid blocking on recv() in gr_udp_source (only known way to avoid blocking on Cygwin). Add wait argument to gr_udp_source to allow waiting for connection or accepting lack of connection as EOF; add --no-wait option to dial_tone_sink.py. Remove system dependencies from .h files; remove unused data members and (useless?) public open and close functions. --- gnuradio-core/src/lib/io/gr_udp_sink.cc | 85 +++++++++------------- gnuradio-core/src/lib/io/gr_udp_sink.h | 21 +----- gnuradio-core/src/lib/io/gr_udp_source.cc | 117 ++++++++++++++++++------------ gnuradio-core/src/lib/io/gr_udp_source.h | 32 +++----- gnuradio-core/src/lib/io/gr_udp_source.i | 7 +- 5 files changed, 121 insertions(+), 141 deletions(-) mode change 100644 => 100755 gnuradio-core/src/lib/io/gr_udp_source.i (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index b447dd3b3..263d3dd4f 100755 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. + * Copyright 2007,2008,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -31,9 +31,11 @@ #include #if defined(HAVE_NETDB_H) typedef void* optval_t; -#else +#elif defined(HAVE_WINDOWS_H) // if not posix, assume winsock #define USING_WINSOCK +#include +#include #define SHUT_RDWR 2 typedef char* optval_t; #endif @@ -88,11 +90,13 @@ gr_udp_sink::gr_udp_sink (size_t itemsize, : gr_sync_block ("udp_sink", gr_make_io_signature (1, 1, itemsize), gr_make_io_signature (0, 0, 0)), - d_itemsize (itemsize), d_updated(false), d_payload_size(payload_size) + d_itemsize (itemsize), d_payload_size(payload_size) { int ret = 0; + struct addrinfo *ip_src; // store the source ip info + struct addrinfo *ip_dst; // store the destination ip info -#if !defined(HAVE_SOCKET) // for Windows (with MinGW) +#if defined(USING_WINSOCK) // for Windows (with MinGW) // initialize winsock DLL WSADATA wsaData; int iResult = WSAStartup( MAKEWORD(2,2), &wsaData ); @@ -110,55 +114,21 @@ gr_udp_sink::gr_udp_sink (size_t itemsize, hints.ai_protocol = IPPROTO_UDP; char port_str[7]; sprintf( port_str, "%d", port_src ); - ret = getaddrinfo( src, port_str, &hints, &d_ip_src ); + ret = getaddrinfo( src, port_str, &hints, &ip_src ); if( ret != 0 ) report_error("gr_udp_source/getaddrinfo", "can't initialize source socket" ); // Get the destination IP address from the host name sprintf( port_str, "%d", port_dst ); - ret = getaddrinfo( dst, port_str, &hints, &d_ip_dst ); + ret = getaddrinfo( dst, port_str, &hints, &ip_dst ); if( ret != 0 ) report_error("gr_udp_source/getaddrinfo", "can't initialize destination socket" ); - - open(); -} - -// public constructor that returns a shared_ptr - -gr_udp_sink_sptr -gr_make_udp_sink (size_t itemsize, - const char *src, unsigned short port_src, - const char *dst, unsigned short port_dst, - int payload_size) -{ - return gr_udp_sink_sptr (new gr_udp_sink (itemsize, - src, port_src, - dst, port_dst, - payload_size)); -} - -gr_udp_sink::~gr_udp_sink () -{ - freeaddrinfo(d_ip_src); - freeaddrinfo(d_ip_dst); - close(); - -#if !defined(HAVE_SOCKET) // for Windows (with MinGW) - // free winsock resources - WSACleanup(); -#endif -} - -bool -gr_udp_sink::open() -{ - gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function // create socket - d_socket = socket(d_ip_src->ai_family, d_ip_src->ai_socktype, - d_ip_src->ai_protocol); + d_socket = socket(ip_src->ai_family, ip_src->ai_socktype, + ip_src->ai_protocol); if(d_socket == -1) { report_error("socket open","can't open socket"); } @@ -180,24 +150,35 @@ gr_udp_sink::open() } // bind socket to an address and port number to listen on - if(bind (d_socket, d_ip_src->ai_addr, d_ip_src->ai_addrlen) == -1) { + if(bind (d_socket, ip_src->ai_addr, ip_src->ai_addrlen) == -1) { report_error("socket bind","can't bind socket"); } // Not sure if we should throw here or allow retries - if(connect(d_socket, d_ip_dst->ai_addr, d_ip_dst->ai_addrlen) == -1) { + if(connect(d_socket, ip_dst->ai_addr, ip_dst->ai_addrlen) == -1) { report_error("socket connect","can't connect to socket"); } - d_updated = true; - return d_socket != 0; + freeaddrinfo(ip_src); + freeaddrinfo(ip_dst); } -void -gr_udp_sink::close() +// public constructor that returns a shared_ptr + +gr_udp_sink_sptr +gr_make_udp_sink (size_t itemsize, + const char *src, unsigned short port_src, + const char *dst, unsigned short port_dst, + int payload_size) { - gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function + return gr_udp_sink_sptr (new gr_udp_sink (itemsize, + src, port_src, + dst, port_dst, + payload_size)); +} +gr_udp_sink::~gr_udp_sink () +{ if (d_socket){ shutdown(d_socket, SHUT_RDWR); #if defined(USING_WINSOCK) @@ -207,7 +188,11 @@ gr_udp_sink::close() #endif d_socket = 0; } - d_updated = true; + +#if defined(USING_WINSOCK) // for Windows (with MinGW) + // free winsock resources + WSACleanup(); +#endif } int diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.h b/gnuradio-core/src/lib/io/gr_udp_sink.h index 9f50ed7f0..6b6ee40fe 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.h +++ b/gnuradio-core/src/lib/io/gr_udp_sink.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. + * Copyright 2007,2008,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -66,13 +66,9 @@ class gr_udp_sink : public gr_sync_block int payload_size); private: size_t d_itemsize; - bool d_updated; - gruel::mutex d_mutex; int d_payload_size; // maximum transmission unit (packet length) int d_socket; // handle to socket - struct addrinfo *d_ip_src; // store the source ip info - struct addrinfo *d_ip_dst; // store the destination ip info protected: /*! @@ -96,21 +92,6 @@ class gr_udp_sink : public gr_sync_block public: ~gr_udp_sink (); - /*! - * \brief open a socket specified by the port and ip address info - * - * Opens a socket, binds to the address, and makes connectionless association - * over UDP. If any of these fail, the fuction retuns the error and exits. - */ - bool open(); - - /*! - * \brief Close current socket. - * - * Shuts down read/write on the socket - */ - void close(); - /*! \brief return the PAYLOAD_SIZE of the socket */ int payload_size() { return d_payload_size; } diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index 56499258c..ce870d481 100755 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. + * Copyright 2007,2008,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -30,14 +30,19 @@ #include #include #if defined(HAVE_NETDB_H) +#include typedef void* optval_t; -#else +#elif defined(HAVE_WINDOWS_H) // if not posix, assume winsock #define USING_WINSOCK +#include +#include #define SHUT_RDWR 2 typedef char* optval_t; #endif +#define USE_SELECT 1 // non-blocking receive on all platforms +#define USE_RCV_TIMEO 0 // non-blocking receive on all but Cygwin #define SRC_VERBOSE 0 static int is_error( int perr ) @@ -77,15 +82,17 @@ static void report_error( char *msg1, char *msg2 ) } gr_udp_source::gr_udp_source(size_t itemsize, const char *src, - unsigned short port_src, int payload_size) + unsigned short port_src, int payload_size, + bool wait) : gr_sync_block ("udp_source", gr_make_io_signature(0, 0, 0), gr_make_io_signature(1, 1, itemsize)), - d_itemsize(itemsize), d_updated(false), d_payload_size(payload_size), d_residual(0), d_temp_offset(0) + d_itemsize(itemsize), d_payload_size(payload_size), d_wait(wait), d_residual(0), d_temp_offset(0) { int ret = 0; + struct addrinfo *ip_src; // store the source IP address to use -#if !defined(HAVE_SOCKET) // for Windows (with MinGW) +#if defined(USING_WINSOCK) // for Windows (with MinGW) // initialize winsock DLL WSADATA wsaData; int iResult = WSAStartup( MAKEWORD(2,2), &wsaData ); @@ -103,43 +110,16 @@ gr_udp_source::gr_udp_source(size_t itemsize, const char *src, hints.ai_protocol = IPPROTO_UDP; char port_str[7]; sprintf( port_str, "%d", port_src ); - ret = getaddrinfo( src, port_str, &hints, &d_ip_src ); + ret = getaddrinfo( src, port_str, &hints, &ip_src ); if( ret != 0 ) report_error("gr_udp_source/getaddrinfo", "can't initialize source socket" ); d_temp_buff = new char[d_payload_size]; // allow it to hold up to payload_size bytes - - open(); -} - -gr_udp_source_sptr -gr_make_udp_source (size_t itemsize, const char *ipaddr, - unsigned short port, int payload_size) -{ - return gr_udp_source_sptr (new gr_udp_source (itemsize, ipaddr, - port, payload_size)); -} - -gr_udp_source::~gr_udp_source () -{ - freeaddrinfo(d_ip_src); - delete [] d_temp_buff; - close(); -#if !defined(HAVE_SOCKET) // for Windows (with MinGW) - // free winsock resources - WSACleanup(); -#endif -} - -bool -gr_udp_source::open() -{ - gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function // create socket - d_socket = socket(d_ip_src->ai_family, d_ip_src->ai_socktype, - d_ip_src->ai_protocol); + d_socket = socket(ip_src->ai_family, ip_src->ai_socktype, + ip_src->ai_protocol); if(d_socket == -1) { report_error("socket open","can't open socket"); } @@ -160,6 +140,7 @@ gr_udp_source::open() } } +#if USE_RCV_TIMEO // Set a timeout on the receive function to not block indefinitely // This value can (and probably should) be changed // Ignored on Cygwin @@ -173,20 +154,27 @@ gr_udp_source::open() if(setsockopt(d_socket, SOL_SOCKET, SO_RCVTIMEO, (optval_t)&timeout, sizeof(timeout)) == -1) { report_error("SO_RCVTIMEO","can't set socket option SO_RCVTIMEO"); } +#endif // USE_RCV_TIMEO // bind socket to an address and port number to listen on - if(bind (d_socket, d_ip_src->ai_addr, d_ip_src->ai_addrlen) == -1) { + if(bind (d_socket, ip_src->ai_addr, ip_src->ai_addrlen) == -1) { report_error("socket bind","can't bind socket"); } + freeaddrinfo(ip_src); - d_updated = true; - return d_socket != 0; } -void -gr_udp_source::close() +gr_udp_source_sptr +gr_make_udp_source (size_t itemsize, const char *ipaddr, + unsigned short port, int payload_size, bool wait) { - gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function + return gr_udp_source_sptr (new gr_udp_source (itemsize, ipaddr, + port, payload_size, wait)); +} + +gr_udp_source::~gr_udp_source () +{ + delete [] d_temp_buff; if (d_socket){ shutdown(d_socket, SHUT_RDWR); @@ -197,7 +185,11 @@ gr_udp_source::close() #endif d_socket = 0; } - d_updated = true; + +#if defined(USING_WINSOCK) // for Windows (with MinGW) + // free winsock resources + WSACleanup(); +#endif } int @@ -232,8 +224,38 @@ gr_udp_source::work (int noutput_items, d_temp_offset = d_temp_offset+d_residual; } +#if USE_SELECT + // Use select() to determine when socket is readable + fd_set readfds; + timeval timeout; + timeout.tv_sec = 1; + timeout.tv_usec = 0; +#endif + while(1) { // get the data into our output buffer and record the number of bytes + +#if USE_SELECT + // RCV_TIMEO doesn't work on all systems (e.g., Cygwin) + // use select() instead of, or in addition to RCV_TIMEO + FD_ZERO(&readfds); + FD_SET(d_socket, &readfds); + r = select(FD_SETSIZE, &readfds, NULL, NULL, &timeout); + if(r < 0) { + report_error("udp_source/select",NULL); + return -1; + } + else if(r == 0 ) { // timed out + if( d_wait ) { + // Allow boost thread interrupt, then try again + boost::this_thread::interruption_point(); + continue; + } + else + return -1; + } +#endif // USE_SELECT + // This is a non-blocking call with a timeout set in the constructor r = recv(d_socket, d_temp_buff, d_payload_size, 0); // get the entire payload or the what's available @@ -244,11 +266,16 @@ gr_udp_source::work (int noutput_items, printf("UDP receive timed out\n"); #endif - // Break here to allow the rest of the flow graph time to run and so ctrl-C breaks - break; + if( d_wait ) { + // Allow boost thread interrupt, then try again + boost::this_thread::interruption_point(); + continue; + } + else + return -1; } else { - report_error("udp_source",NULL); + report_error("udp_source/recv",NULL); return -1; } } diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h index 14d521dac..b06536d6a 100755 --- a/gnuradio-core/src/lib/io/gr_udp_source.h +++ b/gnuradio-core/src/lib/io/gr_udp_source.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. + * Copyright 2007,2008,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -38,7 +38,8 @@ class gr_udp_source; typedef boost::shared_ptr gr_udp_source_sptr; gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *src, - unsigned short port_src, int payload_size=1472); + unsigned short port_src, + int payload_size=1472, bool wait=true); /*! * \brief Read stream from an UDP socket. @@ -50,22 +51,22 @@ gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *src, * \param port_src The port number on which the socket listens for data * \param payload_size UDP payload size by default set to * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header)) + * \param wait Wait for data if not immediately available (default: true) * */ class gr_udp_source : public gr_sync_block { friend gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *src, - unsigned short port_src, int payload_size); + unsigned short port_src, + int payload_size, bool wait); private: size_t d_itemsize; - bool d_updated; - gruel::mutex d_mutex; int d_payload_size; // maximum transmission unit (packet length) + bool d_wait; // wait if data if not immediately available int d_socket; // handle to socket - struct addrinfo *d_ip_src; // store the source IP address to use char *d_temp_buff; // hold buffer between calls ssize_t d_residual; // hold information about number of bytes stored in the temp buffer size_t d_temp_offset; // point to temp buffer location offset @@ -80,27 +81,14 @@ class gr_udp_source : public gr_sync_block * \param port_src The port number on which the socket listens for data * \param payload_size UDP payload size by default set to * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header)) + * \param wait Wait for data if not immediately available (default: true) */ - gr_udp_source(size_t itemsize, const char *src, unsigned short port_src, int payload_size); + gr_udp_source(size_t itemsize, const char *src, unsigned short port_src, + int payload_size, bool wait); public: ~gr_udp_source(); - /*! - * \brief open a socket specified by the port and ip address info - * - * Opens a socket, binds to the address, and waits for a connection - * over UDP. If any of these fail, the fuction retuns the error and exits. - */ - bool open(); - - /*! - * \brief Close current socket. - * - * Shuts down read/write on the socket - */ - void close(); - /*! \brief return the PAYLOAD_SIZE of the socket */ int payload_size() { return d_payload_size; } diff --git a/gnuradio-core/src/lib/io/gr_udp_source.i b/gnuradio-core/src/lib/io/gr_udp_source.i old mode 100644 new mode 100755 index fb39dad68..efaa57c27 --- a/gnuradio-core/src/lib/io/gr_udp_source.i +++ b/gnuradio-core/src/lib/io/gr_udp_source.i @@ -24,19 +24,18 @@ GR_SWIG_BLOCK_MAGIC(gr,udp_source) gr_udp_source_sptr gr_make_udp_source (size_t itemsize, const char *src, - unsigned short port_src, int payload_size=1472); + unsigned short port_src, int payload_size=1472, + bool wait=true); class gr_udp_source : public gr_sync_block { protected: gr_udp_source (size_t itemsize, const char *src, - unsigned short port_src, int payload_size); + unsigned short port_src, int payload_size, bool wait); public: ~gr_udp_source (); - bool open(); - void close(); int payload_size() { return d_payload_size; } }; -- cgit From d702e27d1f3b0e76ef3734ee6b5b6ac1333cdbff Mon Sep 17 00:00:00 2001 From: Don Ward Date: Tue, 4 May 2010 12:41:52 -0400 Subject: Rework UDP source and sink, with incompatible API changes Remove source address specifications for sink; add connect() and disconnect() to sink; add get_port() to source; add optional EOF signaling (using zero-length packets) to sink and source; modify dial_tone, vector, and audio examples to match new code; add qa test case. --- gnuradio-core/src/lib/io/gr_udp_sink.cc | 161 ++++++++++++++++++------------ gnuradio-core/src/lib/io/gr_udp_sink.h | 72 +++++++------ gnuradio-core/src/lib/io/gr_udp_sink.i | 21 ++-- gnuradio-core/src/lib/io/gr_udp_source.cc | 62 ++++++++++-- gnuradio-core/src/lib/io/gr_udp_source.h | 70 +++++++------ gnuradio-core/src/lib/io/gr_udp_source.i | 14 +-- 6 files changed, 243 insertions(+), 157 deletions(-) mode change 100644 => 100755 gnuradio-core/src/lib/io/gr_udp_sink.h mode change 100644 => 100755 gnuradio-core/src/lib/io/gr_udp_sink.i (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index 263d3dd4f..a9cb87a21 100755 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -30,6 +30,8 @@ #include #include #if defined(HAVE_NETDB_H) +#include +#include //usually included by ? typedef void* optval_t; #elif defined(HAVE_WINDOWS_H) // if not posix, assume winsock @@ -84,18 +86,14 @@ static void report_error( const char *msg1, const char *msg2 ) } gr_udp_sink::gr_udp_sink (size_t itemsize, - const char *src, unsigned short port_src, - const char *dst, unsigned short port_dst, - int payload_size) + const char *host, unsigned short port, + int payload_size, bool eof) : gr_sync_block ("udp_sink", gr_make_io_signature (1, 1, itemsize), gr_make_io_signature (0, 0, 0)), - d_itemsize (itemsize), d_payload_size(payload_size) + d_itemsize (itemsize), d_payload_size(payload_size), d_eof(eof), + d_connected(false) { - int ret = 0; - struct addrinfo *ip_src; // store the source ip info - struct addrinfo *ip_dst; // store the destination ip info - #if defined(USING_WINSOCK) // for Windows (with MinGW) // initialize winsock DLL WSADATA wsaData; @@ -104,41 +102,13 @@ gr_udp_sink::gr_udp_sink (size_t itemsize, report_error( "gr_udp_source WSAStartup", "can't open socket" ); } #endif - - // Set up the address stucture for the source address and port numbers - // Get the source IP address from the host name - struct addrinfo hints; - memset( (void*)&hints, 0, sizeof(hints) ); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_DGRAM; - hints.ai_protocol = IPPROTO_UDP; - char port_str[7]; - sprintf( port_str, "%d", port_src ); - ret = getaddrinfo( src, port_str, &hints, &ip_src ); - if( ret != 0 ) - report_error("gr_udp_source/getaddrinfo", - "can't initialize source socket" ); - - // Get the destination IP address from the host name - sprintf( port_str, "%d", port_dst ); - ret = getaddrinfo( dst, port_str, &hints, &ip_dst ); - if( ret != 0 ) - report_error("gr_udp_source/getaddrinfo", - "can't initialize destination socket" ); // create socket - d_socket = socket(ip_src->ai_family, ip_src->ai_socktype, - ip_src->ai_protocol); + d_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if(d_socket == -1) { report_error("socket open","can't open socket"); } - // Turn on reuse address - int opt_val = true; - if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (optval_t)&opt_val, sizeof(int)) == -1) { - report_error("SO_REUSEADDR","can't set socket option SO_REUSEADDR"); - } - // Don't wait when shutting down linger lngr; lngr.l_onoff = 1; @@ -149,36 +119,27 @@ gr_udp_sink::gr_udp_sink (size_t itemsize, } } - // bind socket to an address and port number to listen on - if(bind (d_socket, ip_src->ai_addr, ip_src->ai_addrlen) == -1) { - report_error("socket bind","can't bind socket"); - } - - // Not sure if we should throw here or allow retries - if(connect(d_socket, ip_dst->ai_addr, ip_dst->ai_addrlen) == -1) { - report_error("socket connect","can't connect to socket"); - } - - freeaddrinfo(ip_src); - freeaddrinfo(ip_dst); + // Get the destination address + connect(host, port); } // public constructor that returns a shared_ptr gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize, - const char *src, unsigned short port_src, - const char *dst, unsigned short port_dst, - int payload_size) + const char *host, unsigned short port, + int payload_size, bool eof) { return gr_udp_sink_sptr (new gr_udp_sink (itemsize, - src, port_src, - dst, port_dst, - payload_size)); + host, port, + payload_size, eof)); } gr_udp_sink::~gr_udp_sink () { + if (d_connected) + disconnect(); + if (d_socket){ shutdown(d_socket, SHUT_RDWR); #if defined(USING_WINSOCK) @@ -208,22 +169,28 @@ gr_udp_sink::work (int noutput_items, printf("Entered udp_sink\n"); #endif + gruel::scoped_lock guard(d_mutex); // protect d_socket + while(bytes_sent < total_size) { bytes_to_send = std::min((ssize_t)d_payload_size, (total_size-bytes_sent)); - r = send(d_socket, (in+bytes_sent), bytes_to_send, 0); - if(r == -1) { // error on send command - if( is_error(ECONNREFUSED) ) - r = bytes_to_send; // discard data until receiver is started - else { - report_error("udp_sink",NULL); // there should be no error case where - return -1; // this function should not exit immediately + if(d_connected) { + r = send(d_socket, (in+bytes_sent), bytes_to_send, 0); + if(r == -1) { // error on send command + if( is_error(ECONNREFUSED) ) + r = bytes_to_send; // discard data until receiver is started + else { + report_error("udp_sink",NULL); // there should be no error case where + return -1; // this function should not exit immediately + } } } + else + r = bytes_to_send; // discarded for lack of connection bytes_sent += r; #if SNK_VERBOSE - printf("\tbyte sent: %d bytes\n", bytes); + printf("\tbyte sent: %d bytes\n", r); #endif } @@ -233,3 +200,71 @@ gr_udp_sink::work (int noutput_items, return noutput_items; } + +void gr_udp_sink::connect( const char *host, unsigned short port ) +{ + if(d_connected) + disconnect(); + + if(host != NULL ) { + // Get the destination address + struct addrinfo *ip_dst; + struct addrinfo hints; + memset( (void*)&hints, 0, sizeof(hints) ); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_DGRAM; + hints.ai_protocol = IPPROTO_UDP; + char port_str[12]; + sprintf( port_str, "%d", port ); + int ret = getaddrinfo( host, port_str, &hints, &ip_dst ); + if( ret != 0 ) + report_error("gr_udp_source/getaddrinfo", + "can't initialize destination socket" ); + + // don't need d_mutex lock when !d_connected + if(::connect(d_socket, ip_dst->ai_addr, ip_dst->ai_addrlen) == -1) { + report_error("socket connect","can't connect to socket"); + } + d_connected = true; + + freeaddrinfo(ip_dst); + } + + return; +} + +void gr_udp_sink::disconnect() +{ + if(!d_connected) + return; + + #if SNK_VERBOSE + printf("gr_udp_sink disconnecting\n"); + #endif + + gruel::scoped_lock guard(d_mutex); // protect d_socket from work() + + // Send a few zero-length packets to signal receiver we are done + if(d_eof) { + int i; + for( i = 0; i < 3; i++ ) + (void) send( d_socket, NULL, 0, 0 ); // ignore errors + } + + // Since I can't find any way to disconnect a datagram socket in Cygwin, + // we just leave it connected but disable sending. +#if 0 + // zeroed address structure should reset connection + struct sockaddr addr; + memset( (void*)&addr, 0, sizeof(addr) ); + // addr.sa_family = AF_UNSPEC; // doesn't work on Cygwin + // addr.sa_family = AF_INET; // doesn't work on Cygwin + + if(::connect(d_socket, &addr, sizeof(addr)) == -1) + report_error("socket connect","can't connect to socket"); +#endif + + d_connected = false; + + return; +} diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.h b/gnuradio-core/src/lib/io/gr_udp_sink.h old mode 100644 new mode 100755 index 6b6ee40fe..421d514a4 --- a/gnuradio-core/src/lib/io/gr_udp_sink.h +++ b/gnuradio-core/src/lib/io/gr_udp_sink.h @@ -24,14 +24,6 @@ #define INCLUDED_GR_UDP_SINK_H #include -#if defined(HAVE_NETDB_H) -#include -#include // usually #included by ? -#elif defined(HAVE_WINDOWS_H) -#include -#include -#endif - #include class gr_udp_sink; @@ -39,55 +31,52 @@ typedef boost::shared_ptr gr_udp_sink_sptr; gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize, - const char *src, unsigned short port_src, - const char *dst, unsigned short port_dst, - int payload_size=1472); + const char *host, unsigned short port, + int payload_size=1472, bool eof=true); /*! * \brief Write stream to an UDP socket. * \ingroup sink_blk * * \param itemsize The size (in bytes) of the item datatype - * \param src The source address as either the host name or the 'numbers-and-dots' - * IP address - * \param port_src Destination port to bind to (0 allows socket to choose an appropriate port) - * \param dst The destination address as either the host name or the 'numbers-and-dots' - * IP address - * \param port_dst Destination port to connect to - * \param payload_size UDP payload size by default set to - * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header)) + * \param host The name or IP address of the receiving host; use + * NULL or None for no connection + * \param port Destination port to connect to on receiving host + * \param payload_size UDP payload size by default set to 1472 = + * (1500 MTU - (8 byte UDP header) - (20 byte IP header)) + * \param eof Send zero-length packet on disconnect */ class gr_udp_sink : public gr_sync_block { friend gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize, - const char *src, unsigned short port_src, - const char *dst, unsigned short port_dst, - int payload_size); + const char *host, + unsigned short port, + int payload_size, bool eof); private: size_t d_itemsize; - int d_payload_size; // maximum transmission unit (packet length) - int d_socket; // handle to socket + int d_payload_size; // maximum transmission unit (packet length) + bool d_eof; // send zero-length packet on disconnect + int d_socket; // handle to socket + bool d_connected; // are we connected? + gruel::mutex d_mutex; // protects d_socket and d_connected protected: /*! * \brief UDP Sink Constructor * * \param itemsize The size (in bytes) of the item datatype - * \param src The source address as either the host name or the 'numbers-and-dots' - * IP address - * \param port_src Destination port to bind to (0 allows socket to choose an appropriate port) - * \param dst The destination address as either the host name or the 'numbers-and-dots' - * IP address - * \param port_dst Destination port to connect to + * \param host The name or IP address of the receiving host; use + * NULL or None for no connection + * \param port Destination port to connect to on receiving host * \param payload_size UDP payload size by default set to * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header)) + * \param eof Send zero-length packet on disconnect */ gr_udp_sink (size_t itemsize, - const char *src, unsigned short port_src, - const char *dst, unsigned short port_dst, - int payload_size); + const char *host, unsigned short port, + int payload_size, bool eof); public: ~gr_udp_sink (); @@ -95,6 +84,23 @@ class gr_udp_sink : public gr_sync_block /*! \brief return the PAYLOAD_SIZE of the socket */ int payload_size() { return d_payload_size; } + /*! \brief Change the connection to a new destination + * + * \param host The name or IP address of the receiving host; use + * NULL or None to break the connection without closing + * \param port Destination port to connect to on receiving host + * + * Calls disconnect() to terminate any current connection first. + */ + void connect( const char *host, unsigned short port ); + + /*! \brief Send zero-length packet (if eof is requested) then stop sending + * + * Zero-byte packets can be interpreted as EOF by gr_udp_source. Note that + * disconnect occurs automatically when the sink is destroyed, but not when + * its top_block stops.*/ + void disconnect(); + // should we export anything else? int work (int noutput_items, diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.i b/gnuradio-core/src/lib/io/gr_udp_sink.i old mode 100644 new mode 100755 index 0f37b477b..fc8059f36 --- a/gnuradio-core/src/lib/io/gr_udp_sink.i +++ b/gnuradio-core/src/lib/io/gr_udp_sink.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007 Free Software Foundation, Inc. + * Copyright 2007,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -25,22 +25,21 @@ GR_SWIG_BLOCK_MAGIC(gr,udp_sink) gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize, - const char *src, unsigned short port_src, - const char *dst, unsigned short port_dst, - int payload_size=1472); + const char *host, unsigned short port, + int payload_size=1472, bool eof=true); class gr_udp_sink : public gr_sync_block { protected: gr_udp_sink (size_t itemsize, - const char *src, unsigned short port_src, - const char *dst, unsigned short port_dst, - int payload_size); - - bool open(); - void close(); - int payload_size() { return d_payload_size; } + const char *host, unsigned short port, + int payload_size, bool eof); public: ~gr_udp_sink (); + + int payload_size() { return d_payload_size; } + void connect( const char *host, unsigned short port ); + void disconnect(); + }; diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index ce870d481..880388e5e 100755 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -29,9 +29,19 @@ #include #include #include + #if defined(HAVE_NETDB_H) #include typedef void* optval_t; + +// ntohs() on FreeBSD may require both netinet/in.h and arpa/inet.h, in order +#if defined(HAVE_NETINET_IN_H) +#include +#endif +#if defined(HAVE_ARPA_INET_H) +#include +#endif + #elif defined(HAVE_WINDOWS_H) // if not posix, assume winsock #define USING_WINSOCK @@ -67,7 +77,7 @@ static int is_error( int perr ) #endif } -static void report_error( char *msg1, char *msg2 ) +static void report_error( const char *msg1, const char *msg2 ) { // Deal with errors, both posix and winsock #if defined(USING_WINSOCK) @@ -81,16 +91,16 @@ static void report_error( char *msg1, char *msg2 ) return; } -gr_udp_source::gr_udp_source(size_t itemsize, const char *src, - unsigned short port_src, int payload_size, - bool wait) +gr_udp_source::gr_udp_source(size_t itemsize, const char *host, + unsigned short port, int payload_size, + bool eof, bool wait) : gr_sync_block ("udp_source", gr_make_io_signature(0, 0, 0), gr_make_io_signature(1, 1, itemsize)), - d_itemsize(itemsize), d_payload_size(payload_size), d_wait(wait), d_residual(0), d_temp_offset(0) + d_itemsize(itemsize), d_payload_size(payload_size), + d_eof(eof), d_wait(wait), d_residual(0), d_temp_offset(0) { int ret = 0; - struct addrinfo *ip_src; // store the source IP address to use #if defined(USING_WINSOCK) // for Windows (with MinGW) // initialize winsock DLL @@ -103,14 +113,16 @@ gr_udp_source::gr_udp_source(size_t itemsize, const char *src, // Set up the address stucture for the source address and port numbers // Get the source IP address from the host name + struct addrinfo *ip_src; // store the source IP address to use struct addrinfo hints; memset( (void*)&hints, 0, sizeof(hints) ); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_DGRAM; hints.ai_protocol = IPPROTO_UDP; - char port_str[7]; - sprintf( port_str, "%d", port_src ); - ret = getaddrinfo( src, port_str, &hints, &ip_src ); + hints.ai_flags = AI_PASSIVE; + char port_str[12]; + sprintf( port_str, "%d", port ); + ret = getaddrinfo( host, port_str, &hints, &ip_src ); if( ret != 0 ) report_error("gr_udp_source/getaddrinfo", "can't initialize source socket" ); @@ -166,10 +178,10 @@ gr_udp_source::gr_udp_source(size_t itemsize, const char *src, gr_udp_source_sptr gr_make_udp_source (size_t itemsize, const char *ipaddr, - unsigned short port, int payload_size, bool wait) + unsigned short port, int payload_size, bool eof, bool wait) { return gr_udp_source_sptr (new gr_udp_source (itemsize, ipaddr, - port, payload_size, wait)); + port, payload_size, eof, wait)); } gr_udp_source::~gr_udp_source () @@ -279,6 +291,22 @@ gr_udp_source::work (int noutput_items, return -1; } } + else if(r==0) { + if(d_eof) { + // zero-length packet interpreted as EOF + + #if SNK_VERBOSE + printf("\tzero-length packet received; returning EOF\n"); + #endif + + return -1; + } + else{ + // do we need to allow boost thread interrupt? + boost::this_thread::interruption_point(); + continue; + } + } else { // Calculate the number of bytes we can take from the buffer in this call nbytes = std::min(r, total_bytes-bytes_received); @@ -316,3 +344,15 @@ gr_udp_source::work (int noutput_items, return bytes_received/d_itemsize; } +// Return port number of d_socket +int gr_udp_source::get_port(void) +{ + sockaddr_in name; + socklen_t len = sizeof(name); + int ret = getsockname( d_socket, (sockaddr*)&name, &len ); + if( ret ) { + report_error("gr_udp_source/getsockname",NULL); + return -1; + } + return ntohs(name.sin_port); +} diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h index b06536d6a..e23231aa7 100755 --- a/gnuradio-core/src/lib/io/gr_udp_source.h +++ b/gnuradio-core/src/lib/io/gr_udp_source.h @@ -24,49 +24,48 @@ #define INCLUDED_GR_UDP_SOURCE_H #include -#if defined(HAVE_NETDB_H) -#include -#include // usually #included by ? -#elif defined(HAVE_WINDOWS_H) -#include -#include -#endif - #include class gr_udp_source; typedef boost::shared_ptr gr_udp_source_sptr; -gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *src, - unsigned short port_src, - int payload_size=1472, bool wait=true); +gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *host, + unsigned short port, + int payload_size=1472, + bool eof=true, bool wait=true); /*! * \brief Read stream from an UDP socket. * \ingroup source_blk * * \param itemsize The size (in bytes) of the item datatype - * \param src The source address as either the host name or the 'numbers-and-dots' - * IP address - * \param port_src The port number on which the socket listens for data - * \param payload_size UDP payload size by default set to - * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header)) - * \param wait Wait for data if not immediately available (default: true) + * \param host The name or IP address of the receiving host; can be + * NULL, None, or "0.0.0.0" to allow reading from any + * interface on the host + * \param port The port number on which to receive data; use 0 to + * have the system assign an unused port number + * \param payload_size UDP payload size by default set to 1472 = + * (1500 MTU - (8 byte UDP header) - (20 byte IP header)) + * \param eof Interpret zero-length packet as EOF (default: true) + * \param wait Wait for data if not immediately available + * (default: true) * */ class gr_udp_source : public gr_sync_block { - friend gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *src, - unsigned short port_src, - int payload_size, bool wait); + friend gr_udp_source_sptr gr_make_udp_source(size_t itemsize, + const char *host, + unsigned short port, + int payload_size, + bool eof, bool wait); private: size_t d_itemsize; - - int d_payload_size; // maximum transmission unit (packet length) - bool d_wait; // wait if data if not immediately available - int d_socket; // handle to socket + int d_payload_size; // maximum transmission unit (packet length) + bool d_eof; // zero-length packet is EOF + bool d_wait; // wait if data if not immediately available + int d_socket; // handle to socket char *d_temp_buff; // hold buffer between calls ssize_t d_residual; // hold information about number of bytes stored in the temp buffer size_t d_temp_offset; // point to temp buffer location offset @@ -76,15 +75,19 @@ class gr_udp_source : public gr_sync_block * \brief UDP Source Constructor * * \param itemsize The size (in bytes) of the item datatype - * \param src The source address as either the host name or the 'numbers-and-dots' - * IP address - * \param port_src The port number on which the socket listens for data - * \param payload_size UDP payload size by default set to - * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header)) - * \param wait Wait for data if not immediately available (default: true) + * \param host The name or IP address of the receiving host; can be + * NULL, None, or "0.0.0.0" to allow reading from any + * interface on the host + * \param port The port number on which to receive data; use 0 to + * have the system assign an unused port number + * \param payload_size UDP payload size by default set to 1472 = + * (1500 MTU - (8 byte UDP header) - (20 byte IP header)) + * \param eof Interpret zero-length packet as EOF (default: true) + * \param wait Wait for data if not immediately available + * (default: true) */ - gr_udp_source(size_t itemsize, const char *src, unsigned short port_src, - int payload_size, bool wait); + gr_udp_source(size_t itemsize, const char *host, unsigned short port, + int payload_size, bool eof, bool wait); public: ~gr_udp_source(); @@ -92,6 +95,9 @@ class gr_udp_source : public gr_sync_block /*! \brief return the PAYLOAD_SIZE of the socket */ int payload_size() { return d_payload_size; } + /*! \breif return the port number of the socket */ + int get_port(); + // should we export anything else? int work(int noutput_items, diff --git a/gnuradio-core/src/lib/io/gr_udp_source.i b/gnuradio-core/src/lib/io/gr_udp_source.i index efaa57c27..e1b23074d 100755 --- a/gnuradio-core/src/lib/io/gr_udp_source.i +++ b/gnuradio-core/src/lib/io/gr_udp_source.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007 Free Software Foundation, Inc. + * Copyright 2007,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,19 +23,19 @@ GR_SWIG_BLOCK_MAGIC(gr,udp_source) gr_udp_source_sptr -gr_make_udp_source (size_t itemsize, const char *src, - unsigned short port_src, int payload_size=1472, - bool wait=true); +gr_make_udp_source (size_t itemsize, const char *host, + unsigned short port, int payload_size=1472, + bool eof=true, bool wait=true); class gr_udp_source : public gr_sync_block { protected: - gr_udp_source (size_t itemsize, const char *src, - unsigned short port_src, int payload_size, bool wait); + gr_udp_source (size_t itemsize, const char *host, + unsigned short port, int payload_size, bool eof, bool wait); public: ~gr_udp_source (); int payload_size() { return d_payload_size; } - + int get_port(); }; -- cgit From a61fc516f5deeef67b48a704c5426c3969d36248 Mon Sep 17 00:00:00 2001 From: Don Ward Date: Thu, 6 May 2010 10:02:35 -0400 Subject: Flush pending errors in gr_udp_sink on disconnect() On some systems (e.g., Debian/lenny) UDP errors are reported on the following send() or recv() call. To avoid having errors (such as ECONNREFUSED) from an old connection showing up on the first write to a new connection, we do a recv() on disconnect() to flush them. This may not work for all errors on all systems, but it works in some simple cases of interest. --- gnuradio-core/src/lib/io/gr_udp_sink.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index a9cb87a21..a323aef98 100755 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -251,6 +251,31 @@ void gr_udp_sink::disconnect() (void) send( d_socket, NULL, 0, 0 ); // ignore errors } + // Sending EOF can produce ERRCONNREFUSED errors that won't show up + // until the next send or recv, which might confuse us if it happens + // on a new connection. The following does a nonblocking recv to + // clear any such errors. + timeval timeout; + timeout.tv_sec = 0; // zero time for immediate return + timeout.tv_usec = 0; + fd_set readfds; + FD_ZERO(&readfds); + FD_SET(d_socket, &readfds); + int r = select(FD_SETSIZE, &readfds, NULL, NULL, &timeout); + if(r < 0) { + #if SNK_VERBOSE + report_error("udp_sink/select",NULL); + #endif + } + else if(r > 0) { // call recv() to get error return + r = recv(d_socket, (char*)&readfds, sizeof(readfds), 0); + if(r < 0) { + #if SNK_VERBOSE + report_error("udp_sink/recv",NULL); + #endif + } + } + // Since I can't find any way to disconnect a datagram socket in Cygwin, // we just leave it connected but disable sending. #if 0 -- cgit From 277e1c0a0881b359f9d597e1cb6a4e3725356387 Mon Sep 17 00:00:00 2001 From: Marcus D Leech Date: Sun, 16 May 2010 08:38:30 -0700 Subject: gnuradio-core: adds configurable flush to file sink --- gnuradio-core/src/lib/io/gr_file_sink.cc | 3 +++ gnuradio-core/src/lib/io/gr_file_sink_base.cc | 6 ++++++ gnuradio-core/src/lib/io/gr_file_sink_base.h | 7 +++++++ gnuradio-core/src/lib/io/gr_file_sink_base.i | 5 +++++ 4 files changed, 21 insertions(+) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_sink.cc b/gnuradio-core/src/lib/io/gr_file_sink.cc index d40235fab..d2c43aac7 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink.cc @@ -70,5 +70,8 @@ gr_file_sink::work (int noutput_items, nwritten += count; inbuf += count * d_itemsize; } + if (d_unbuffered) + fflush (d_fp); + return nwritten; } diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.cc b/gnuradio-core/src/lib/io/gr_file_sink_base.cc index 5ddeeb4d5..c43304b0d 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.cc @@ -118,3 +118,9 @@ gr_file_sink_base::do_update() d_updated = false; } } + +void +gr_file_sink_base::set_unbuffered(bool unbuffered) +{ + d_unbuffered = unbuffered; +} diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.h b/gnuradio-core/src/lib/io/gr_file_sink_base.h index 0c028d7fd..7b96cdb7f 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.h +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.h @@ -37,6 +37,7 @@ class gr_file_sink_base bool d_updated; // is there a new FILE pointer? bool d_is_binary; boost::mutex d_mutex; + bool d_unbuffered; protected: gr_file_sink_base(const char *filename, bool is_binary); @@ -61,6 +62,12 @@ class gr_file_sink_base * \brief if we've had an update, do it now. */ void do_update(); + + + /*! + * \brief turn on unbuffered writes for slower outputs + */ + void set_unbuffered(bool unbuffered); }; diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.i b/gnuradio-core/src/lib/io/gr_file_sink_base.i index 05a3353bb..ed4342482 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.i +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.i @@ -43,4 +43,9 @@ class gr_file_sink_base * \brief if we've had an update, do it now. */ void do_update(); + + /*! + *\brief turn on unbuffered mode for slow outputs + */ + void set_unbuffered(bool unbuffered); }; -- cgit From dc79a11cb809b33f397603e7641b155120be9ee8 Mon Sep 17 00:00:00 2001 From: Marcus D Leech Date: Sun, 16 May 2010 08:44:16 -0700 Subject: gr-wxgui: adds stripchart trigger mode to graphics sinks --- gnuradio-core/src/lib/io/gr_oscope_guts.cc | 69 ++++++++++++++++++------------ gnuradio-core/src/lib/io/gr_trigger_mode.h | 1 + 2 files changed, 43 insertions(+), 27 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.cc b/gnuradio-core/src/lib/io/gr_oscope_guts.cc index 80f78240d..ce7feca13 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.cc @@ -104,34 +104,49 @@ gr_oscope_guts::process_sample (const float *channel_data) d_decimator_count = d_decimator_count_init; - for (int i = 0; i < d_nchannels; i++) - d_buffer[i][d_obi] = channel_data[i]; // copy data into buffer - - switch (d_state){ - case HOLD_OFF: - d_hold_off_count--; - if (d_hold_off_count <= 0) - enter_look_for_trigger (); - break; - - case LOOK_FOR_TRIGGER: - if (found_trigger ()) - enter_post_trigger (); - break; - - case POST_TRIGGER: - d_post_trigger_count--; - if (d_post_trigger_count <= 0){ - write_output_records (); - enter_hold_off (); - } - break; - - default: - assert (0); + if (d_trigger_mode != gr_TRIG_MODE_STRIPCHART) + { + for (int i = 0; i < d_nchannels; i++) + d_buffer[i][d_obi] = channel_data[i]; // copy data into buffer + + switch (d_state){ + case HOLD_OFF: + d_hold_off_count--; + if (d_hold_off_count <= 0) + enter_look_for_trigger (); + break; + + case LOOK_FOR_TRIGGER: + if (found_trigger ()) + enter_post_trigger (); + break; + + case POST_TRIGGER: + d_post_trigger_count--; + if (d_post_trigger_count <= 0){ + write_output_records (); + enter_hold_off (); + } + break; + + default: + assert (0); + } + + d_obi = incr_bi (d_obi); + } + else + { + for (int i = 0; i < d_nchannels; i++) + { + for (int j = OUTPUT_RECORD_SIZE-1; j >= 0; j--) + { + d_buffer[i][j] = d_buffer[i][j-1]; + } + d_buffer[i][0] = channel_data[i]; + } + write_output_records(); } - - d_obi = incr_bi (d_obi); } /* diff --git a/gnuradio-core/src/lib/io/gr_trigger_mode.h b/gnuradio-core/src/lib/io/gr_trigger_mode.h index 63f6b1c98..8e1222856 100644 --- a/gnuradio-core/src/lib/io/gr_trigger_mode.h +++ b/gnuradio-core/src/lib/io/gr_trigger_mode.h @@ -27,6 +27,7 @@ enum gr_trigger_mode { gr_TRIG_MODE_FREE, gr_TRIG_MODE_AUTO, gr_TRIG_MODE_NORM, + gr_TRIG_MODE_STRIPCHART, }; enum gr_trigger_slope { -- cgit From 68ce6b4a9b90d4d53310c4271e6011b796fc1bff Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Wed, 19 May 2010 19:57:10 -0700 Subject: Add additional conditionalization of networking includes --- gnuradio-core/src/lib/io/gr_udp_sink.cc | 5 +++++ gnuradio-core/src/lib/io/gr_udp_source.cc | 6 ++++++ 2 files changed, 11 insertions(+) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index a323aef98..73e6d0283 100755 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -31,7 +31,12 @@ #include #if defined(HAVE_NETDB_H) #include +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H #include //usually included by ? +#endif typedef void* optval_t; #elif defined(HAVE_WINDOWS_H) // if not posix, assume winsock diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index 880388e5e..15f83892c 100755 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -32,6 +32,12 @@ #if defined(HAVE_NETDB_H) #include +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif typedef void* optval_t; // ntohs() on FreeBSD may require both netinet/in.h and arpa/inet.h, in order -- cgit From 0058f55926c8e9f6ecb37f153ff7464b93838484 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Wed, 19 May 2010 20:02:26 -0700 Subject: Use -1 as file descriptor "not open" value instead of 0 --- gnuradio-core/src/lib/io/gr_udp_sink.cc | 6 +++--- gnuradio-core/src/lib/io/gr_udp_source.cc | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index 73e6d0283..2ee16b79f 100755 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -97,7 +97,7 @@ gr_udp_sink::gr_udp_sink (size_t itemsize, gr_make_io_signature (1, 1, itemsize), gr_make_io_signature (0, 0, 0)), d_itemsize (itemsize), d_payload_size(payload_size), d_eof(eof), - d_connected(false) + d_socket(-1), d_connected(false) { #if defined(USING_WINSOCK) // for Windows (with MinGW) // initialize winsock DLL @@ -145,14 +145,14 @@ gr_udp_sink::~gr_udp_sink () if (d_connected) disconnect(); - if (d_socket){ + if (d_socket != -1){ shutdown(d_socket, SHUT_RDWR); #if defined(USING_WINSOCK) closesocket(d_socket); #else ::close(d_socket); #endif - d_socket = 0; + d_socket = -1; } #if defined(USING_WINSOCK) // for Windows (with MinGW) diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index 15f83892c..b1c25382c 100755 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -104,7 +104,7 @@ gr_udp_source::gr_udp_source(size_t itemsize, const char *host, gr_make_io_signature(0, 0, 0), gr_make_io_signature(1, 1, itemsize)), d_itemsize(itemsize), d_payload_size(payload_size), - d_eof(eof), d_wait(wait), d_residual(0), d_temp_offset(0) + d_eof(eof), d_wait(wait), d_socket(-1), d_residual(0), d_temp_offset(0) { int ret = 0; @@ -194,14 +194,14 @@ gr_udp_source::~gr_udp_source () { delete [] d_temp_buff; - if (d_socket){ + if (d_socket != -1){ shutdown(d_socket, SHUT_RDWR); #if defined(USING_WINSOCK) closesocket(d_socket); #else ::close(d_socket); #endif - d_socket = 0; + d_socket = -1; } #if defined(USING_WINSOCK) // for Windows (with MinGW) -- cgit From 99a39a4351ca250dcbeeface0ab7b9de6e301d49 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Wed, 19 May 2010 20:06:26 -0700 Subject: Identify memory leaks that occur on error conditions --- gnuradio-core/src/lib/io/gr_udp_sink.cc | 2 ++ gnuradio-core/src/lib/io/gr_udp_source.cc | 3 +++ 2 files changed, 5 insertions(+) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index 2ee16b79f..3084a848b 100755 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -221,6 +221,8 @@ void gr_udp_sink::connect( const char *host, unsigned short port ) hints.ai_protocol = IPPROTO_UDP; char port_str[12]; sprintf( port_str, "%d", port ); + + // FIXME leaks if report_error throws below int ret = getaddrinfo( host, port_str, &hints, &ip_dst ); if( ret != 0 ) report_error("gr_udp_source/getaddrinfo", diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index b1c25382c..063cd7b50 100755 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -128,11 +128,14 @@ gr_udp_source::gr_udp_source(size_t itemsize, const char *host, hints.ai_flags = AI_PASSIVE; char port_str[12]; sprintf( port_str, "%d", port ); + + // FIXME leaks if report_error throws below ret = getaddrinfo( host, port_str, &hints, &ip_src ); if( ret != 0 ) report_error("gr_udp_source/getaddrinfo", "can't initialize source socket" ); + // FIXME leaks if report_error throws below d_temp_buff = new char[d_payload_size]; // allow it to hold up to payload_size bytes // create socket -- cgit From 1e963cd9b6e2a1687bbff86df66c5efbcb2be363 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Wed, 19 May 2010 20:11:35 -0700 Subject: Correct update of d_temp_offset (parallel construction) --- gnuradio-core/src/lib/io/gr_udp_source.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index 063cd7b50..cc9849280 100755 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -242,7 +242,8 @@ gr_udp_source::work (int noutput_items, // Update indexing of amount of bytes left in the buffer d_residual -= nbytes; - d_temp_offset = d_temp_offset+d_residual; + d_temp_offset += nbytes; + // FIXME? Returning here could simplify life... } #if USE_SELECT -- cgit From 34e0be1f96cb24e302269c008444bc18e418b653 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Wed, 19 May 2010 20:15:41 -0700 Subject: Move initialization of select timeout --- gnuradio-core/src/lib/io/gr_udp_source.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index cc9849280..f8727c4dc 100755 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -250,8 +250,6 @@ gr_udp_source::work (int noutput_items, // Use select() to determine when socket is readable fd_set readfds; timeval timeout; - timeout.tv_sec = 1; - timeout.tv_usec = 0; #endif while(1) { @@ -260,6 +258,8 @@ gr_udp_source::work (int noutput_items, #if USE_SELECT // RCV_TIMEO doesn't work on all systems (e.g., Cygwin) // use select() instead of, or in addition to RCV_TIMEO + timeout.tv_sec = 1; // Init timeout each iteration. Select can modify it. + timeout.tv_usec = 0; FD_ZERO(&readfds); FD_SET(d_socket, &readfds); r = select(FD_SETSIZE, &readfds, NULL, NULL, &timeout); -- cgit From 4267b714f4276671f718136a1279f681a4231aee Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Wed, 19 May 2010 20:27:10 -0700 Subject: Defend against a peer that sends an invalid message length. --- gnuradio-core/src/lib/io/gr_udp_source.cc | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index f8727c4dc..1197a0c43 100755 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -281,6 +281,11 @@ gr_udp_source::work (int noutput_items, // This is a non-blocking call with a timeout set in the constructor r = recv(d_socket, d_temp_buff, d_payload_size, 0); // get the entire payload or the what's available + // If r > 0, round it down to a multiple of d_itemsize + // (If sender is broken, don't propagate problem) + if (r > 0) + r = (r/d_itemsize) * d_itemsize; + // Check if there was a problem; forget it if the operation just timed out if(r == -1) { if( is_error(EAGAIN) ) { // handle non-blocking call timeout -- cgit From 91054ed9fe7f08cac9738a6a6af5a9ad476ba24b Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Wed, 19 May 2010 20:38:17 -0700 Subject: Return immediately when using d_residual. (Otherwise recv may overwrite valid data in d_temp_buff.) --- gnuradio-core/src/lib/io/gr_udp_source.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index 1197a0c43..da5b8a191 100755 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -243,7 +243,10 @@ gr_udp_source::work (int noutput_items, // Update indexing of amount of bytes left in the buffer d_residual -= nbytes; d_temp_offset += nbytes; - // FIXME? Returning here could simplify life... + + // Return now with what we've got. + assert(nbytes % d_itemsize == 0); + return nbytes/d_itemsize; } #if USE_SELECT -- cgit From 26185e9077e5e20f71fb515c0e847a5dfd57986c Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Wed, 19 May 2010 20:43:48 -0700 Subject: Simplify USE_SELECT usage --- gnuradio-core/src/lib/io/gr_udp_source.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index da5b8a191..fea9a26ba 100755 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -249,18 +249,14 @@ gr_udp_source::work (int noutput_items, return nbytes/d_itemsize; } -#if USE_SELECT - // Use select() to determine when socket is readable - fd_set readfds; - timeval timeout; -#endif - while(1) { // get the data into our output buffer and record the number of bytes #if USE_SELECT // RCV_TIMEO doesn't work on all systems (e.g., Cygwin) // use select() instead of, or in addition to RCV_TIMEO + fd_set readfds; + timeval timeout; timeout.tv_sec = 1; // Init timeout each iteration. Select can modify it. timeout.tv_usec = 0; FD_ZERO(&readfds); -- cgit From 625a12540792512c968a6f45418a694a5f6aef76 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Fri, 21 May 2010 17:23:06 -0700 Subject: gnuradio-core: allow swig to handle exceptions in UDP source/sink --- gnuradio-core/src/lib/io/gr_udp_sink.i | 5 +++-- gnuradio-core/src/lib/io/gr_udp_source.i | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.i b/gnuradio-core/src/lib/io/gr_udp_sink.i index fc8059f36..a71006ae0 100755 --- a/gnuradio-core/src/lib/io/gr_udp_sink.i +++ b/gnuradio-core/src/lib/io/gr_udp_sink.i @@ -26,14 +26,15 @@ GR_SWIG_BLOCK_MAGIC(gr,udp_sink) gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize, const char *host, unsigned short port, - int payload_size=1472, bool eof=true); + int payload_size=1472, bool eof=true) throw (std::runtime_error); class gr_udp_sink : public gr_sync_block { protected: gr_udp_sink (size_t itemsize, const char *host, unsigned short port, - int payload_size, bool eof); + int payload_size, bool eof) + throw (std::runtime_error); public: ~gr_udp_sink (); diff --git a/gnuradio-core/src/lib/io/gr_udp_source.i b/gnuradio-core/src/lib/io/gr_udp_source.i index e1b23074d..2001f33e9 100755 --- a/gnuradio-core/src/lib/io/gr_udp_source.i +++ b/gnuradio-core/src/lib/io/gr_udp_source.i @@ -25,13 +25,13 @@ GR_SWIG_BLOCK_MAGIC(gr,udp_source) gr_udp_source_sptr gr_make_udp_source (size_t itemsize, const char *host, unsigned short port, int payload_size=1472, - bool eof=true, bool wait=true); + bool eof=true, bool wait=true) throw (std::runtime_error); class gr_udp_source : public gr_sync_block { protected: gr_udp_source (size_t itemsize, const char *host, - unsigned short port, int payload_size, bool eof, bool wait); + unsigned short port, int payload_size, bool eof, bool wait) throw (std::runtime_error); public: ~gr_udp_source (); -- cgit From 45ff82b3d099e39e435f829413923abbcfacfd58 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Tue, 1 Jun 2010 09:16:23 -0700 Subject: gnuradio-core: fix typo in doxygen header --- gnuradio-core/src/lib/io/gr_udp_source.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h index e23231aa7..5d30fad30 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.h +++ b/gnuradio-core/src/lib/io/gr_udp_source.h @@ -95,7 +95,7 @@ class gr_udp_source : public gr_sync_block /*! \brief return the PAYLOAD_SIZE of the socket */ int payload_size() { return d_payload_size; } - /*! \breif return the port number of the socket */ + /*! \brief return the port number of the socket */ int get_port(); // should we export anything else? -- 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. --- gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc | 4 ++-- gnuradio-core/src/lib/io/gr_file_sink.cc | 4 ++-- gnuradio-core/src/lib/io/gr_file_source.cc | 4 ++-- gnuradio-core/src/lib/io/gr_histo_sink_f.cc | 4 ++-- gnuradio-core/src/lib/io/gr_message_sink.cc | 4 ++-- gnuradio-core/src/lib/io/gr_message_source.cc | 6 +++--- gnuradio-core/src/lib/io/gr_oscope_sink_f.cc | 4 ++-- gnuradio-core/src/lib/io/gr_udp_sink.cc | 2 +- gnuradio-core/src/lib/io/gr_udp_source.cc | 2 +- gnuradio-core/src/lib/io/gr_wavfile_sink.cc | 4 ++-- gnuradio-core/src/lib/io/gr_wavfile_source.cc | 4 ++-- 11 files changed, 21 insertions(+), 21 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc index 2da66b7ae..09fb6c826 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -46,7 +46,7 @@ gr_file_descriptor_sink::gr_file_descriptor_sink (size_t itemsize, int fd) gr_file_descriptor_sink_sptr gr_make_file_descriptor_sink (size_t itemsize, int fd) { - return gr_file_descriptor_sink_sptr (new gr_file_descriptor_sink (itemsize, fd)); + return gnuradio::get_initial_sptr(new gr_file_descriptor_sink (itemsize, fd)); } gr_file_descriptor_sink::~gr_file_descriptor_sink () diff --git a/gnuradio-core/src/lib/io/gr_file_sink.cc b/gnuradio-core/src/lib/io/gr_file_sink.cc index d40235fab..706837c7a 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2006,2007 Free Software Foundation, Inc. + * Copyright 2004,2006,2007,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -32,7 +32,7 @@ gr_file_sink_sptr gr_make_file_sink (size_t itemsize, const char *filename) { - return gr_file_sink_sptr (new gr_file_sink (itemsize, filename)); + return gnuradio::get_initial_sptr(new gr_file_sink (itemsize, filename)); } gr_file_sink::gr_file_sink(size_t itemsize, const char *filename) diff --git a/gnuradio-core/src/lib/io/gr_file_source.cc b/gnuradio-core/src/lib/io/gr_file_source.cc index 5591826d0..d045e26b3 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_source.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -74,7 +74,7 @@ gr_file_source::gr_file_source (size_t itemsize, const char *filename, bool repe gr_file_source_sptr gr_make_file_source (size_t itemsize, const char *filename, bool repeat) { - return gr_file_source_sptr (new gr_file_source (itemsize, filename, repeat)); + return gnuradio::get_initial_sptr(new gr_file_source (itemsize, filename, repeat)); } gr_file_source::~gr_file_source () diff --git a/gnuradio-core/src/lib/io/gr_histo_sink_f.cc b/gnuradio-core/src/lib/io/gr_histo_sink_f.cc index 2885fe428..a37189c24 100644 --- a/gnuradio-core/src/lib/io/gr_histo_sink_f.cc +++ b/gnuradio-core/src/lib/io/gr_histo_sink_f.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2009 Free Software Foundation, Inc. + * Copyright 2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -46,7 +46,7 @@ static float get_clean_num(float num){ gr_histo_sink_f_sptr gr_make_histo_sink_f (gr_msg_queue_sptr msgq) { - return gr_histo_sink_f_sptr (new gr_histo_sink_f (msgq)); + return gnuradio::get_initial_sptr(new gr_histo_sink_f (msgq)); } gr_histo_sink_f::gr_histo_sink_f (gr_msg_queue_sptr msgq) diff --git a/gnuradio-core/src/lib/io/gr_message_sink.cc b/gnuradio-core/src/lib/io/gr_message_sink.cc index b9e0cc382..8881e97f4 100644 --- a/gnuradio-core/src/lib/io/gr_message_sink.cc +++ b/gnuradio-core/src/lib/io/gr_message_sink.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 * @@ -40,7 +40,7 @@ gr_message_sink_sptr gr_make_message_sink (size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block) { - return gr_message_sink_sptr(new gr_message_sink(itemsize, msgq, dont_block)); + return gnuradio::get_initial_sptr(new gr_message_sink(itemsize, msgq, dont_block)); } gr_message_sink::gr_message_sink (size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block) diff --git a/gnuradio-core/src/lib/io/gr_message_source.cc b/gnuradio-core/src/lib/io/gr_message_source.cc index 3efc5b321..0fa24f2f9 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.cc +++ b/gnuradio-core/src/lib/io/gr_message_source.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 * @@ -40,14 +40,14 @@ gr_message_source_sptr gr_make_message_source(size_t itemsize, int msgq_limit) { - return gr_message_source_sptr(new gr_message_source(itemsize, msgq_limit)); + return gnuradio::get_initial_sptr(new gr_message_source(itemsize, msgq_limit)); } // public constructor that takes existing message queue gr_message_source_sptr gr_make_message_source(size_t itemsize, gr_msg_queue_sptr msgq) { - return gr_message_source_sptr(new gr_message_source(itemsize, msgq)); + return gnuradio::get_initial_sptr(new gr_message_source(itemsize, msgq)); } gr_message_source::gr_message_source (size_t itemsize, int msgq_limit) diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc b/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc index cb401699e..eca0f6dc6 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2003,2004,2005 Free Software Foundation, Inc. + * Copyright 2003,2004,2005,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -32,7 +32,7 @@ gr_oscope_sink_f_sptr gr_make_oscope_sink_f (double sampling_rate, gr_msg_queue_sptr msgq) { - return gr_oscope_sink_f_sptr (new gr_oscope_sink_f (sampling_rate, msgq)); + return gnuradio::get_initial_sptr(new gr_oscope_sink_f (sampling_rate, msgq)); } diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index 3084a848b..36b4cbe36 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -135,7 +135,7 @@ gr_make_udp_sink (size_t itemsize, const char *host, unsigned short port, int payload_size, bool eof) { - return gr_udp_sink_sptr (new gr_udp_sink (itemsize, + return gnuradio::get_initial_sptr(new gr_udp_sink (itemsize, host, port, payload_size, eof)); } diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index fea9a26ba..ca31233de 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -189,7 +189,7 @@ gr_udp_source_sptr gr_make_udp_source (size_t itemsize, const char *ipaddr, unsigned short port, int payload_size, bool eof, bool wait) { - return gr_udp_source_sptr (new gr_udp_source (itemsize, ipaddr, + return gnuradio::get_initial_sptr(new gr_udp_source (itemsize, ipaddr, port, payload_size, eof, wait)); } diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc index 72e4ef51e..b60a6e3ab 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright 2004,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -58,7 +58,7 @@ gr_make_wavfile_sink(const char *filename, unsigned int sample_rate, int bits_per_sample) { - return gr_wavfile_sink_sptr (new gr_wavfile_sink (filename, + return gnuradio::get_initial_sptr(new gr_wavfile_sink (filename, n_channels, sample_rate, bits_per_sample)); diff --git a/gnuradio-core/src/lib/io/gr_wavfile_source.cc b/gnuradio-core/src/lib/io/gr_wavfile_source.cc index 900f84efd..d00dd3028 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_source.cc +++ b/gnuradio-core/src/lib/io/gr_wavfile_source.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008 Free Software Foundation, Inc. + * Copyright 2004,2008,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -52,7 +52,7 @@ gr_wavfile_source_sptr gr_make_wavfile_source (const char *filename, bool repeat) { - return gr_wavfile_source_sptr (new gr_wavfile_source (filename, repeat)); + return gnuradio::get_initial_sptr(new gr_wavfile_source (filename, repeat)); } -- cgit From 2a6649f9eafd467dbb5467e2a4d46affffc1afbd Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Fri, 29 Oct 2010 03:56:48 -0700 Subject: Disable gr_message_source until later... --- gnuradio-core/src/lib/io/gr_message_source.i | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_message_source.i b/gnuradio-core/src/lib/io/gr_message_source.i index 8a9c762d0..3566ee5a7 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.i +++ b/gnuradio-core/src/lib/io/gr_message_source.i @@ -20,6 +20,10 @@ * Boston, MA 02110-1301, USA. */ +#ifdef SWIGGUILE +#warning "gr_message_source.i: FIXME being ignored by swig/guile for now" +#else + GR_SWIG_BLOCK_MAGIC(gr,message_source); gr_message_source_sptr gr_make_message_source (size_t itemsize, int msgq_limit=0); @@ -36,3 +40,4 @@ class gr_message_source : public gr_sync_block gr_msg_queue_sptr msgq() const; }; +#endif -- cgit From f43d2a4759e0ecd6519c0ac0aa4afbc54e70ea65 Mon Sep 17 00:00:00 2001 From: Rob Savoye Date: Wed, 10 Nov 2010 17:57:11 -0700 Subject: add the .i files as dependencies --- gnuradio-core/src/lib/io/Makefile.am | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index c52554645..0ab9ac135 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -113,3 +113,17 @@ swiginclude_HEADERS = \ gr_wavfile_source.i \ gr_wavfile_sink.i endif + +# Produce a list of the file names with the .cc stripped off +files = $(foreach HFILE,$(libio_la_SOURCES), $(patsubst %.cc,%,$(HFILE))) + +# All .lo files depend on the .i file of the same name +define template +-include $(DEPDIR)/$(1).d +$(DEPDIR)/$(1).d: + @echo "$(1).lo: \\" > $(DEPDIR)/$(1).d + @cat ../swig/guile/gnuradio_core_io.Std | sed -e '1d;' >> $(DEPDIR)/$(1).d +endef + +# Generate all the dependencies at runtime +$(foreach prog,$(files),$(eval $(call template,$(prog)))) -- cgit From 5783b693279b6c64ef800f6e8294ec68a2869b29 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Wed, 10 Nov 2010 18:21:50 -0800 Subject: Revert "add the .i files as dependencies" This reverts commit f43d2a4759e0ecd6519c0ac0aa4afbc54e70ea65. The dependencies doesn't make any sense. There's an attempt to run sed on files that haven't been generated yet. --- gnuradio-core/src/lib/io/Makefile.am | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index 0ab9ac135..c52554645 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -113,17 +113,3 @@ swiginclude_HEADERS = \ gr_wavfile_source.i \ gr_wavfile_sink.i endif - -# Produce a list of the file names with the .cc stripped off -files = $(foreach HFILE,$(libio_la_SOURCES), $(patsubst %.cc,%,$(HFILE))) - -# All .lo files depend on the .i file of the same name -define template --include $(DEPDIR)/$(1).d -$(DEPDIR)/$(1).d: - @echo "$(1).lo: \\" > $(DEPDIR)/$(1).d - @cat ../swig/guile/gnuradio_core_io.Std | sed -e '1d;' >> $(DEPDIR)/$(1).d -endef - -# Generate all the dependencies at runtime -$(foreach prog,$(files),$(eval $(call template,$(prog)))) -- cgit From a41e9987f2c9544f38cea7e367bfc81fafea38cc Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 16 Nov 2010 21:40:48 -0800 Subject: New file sink to handle tagged bursts of data. --- gnuradio-core/src/lib/io/Makefile.am | 9 +- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 167 ++++++++++++++++++++++++ gnuradio-core/src/lib/io/gr_tagged_file_sink.h | 65 +++++++++ gnuradio-core/src/lib/io/gr_tagged_file_sink.i | 35 +++++ gnuradio-core/src/lib/io/io.i | 3 +- 5 files changed, 275 insertions(+), 4 deletions(-) create mode 100644 gnuradio-core/src/lib/io/gr_tagged_file_sink.cc create mode 100644 gnuradio-core/src/lib/io/gr_tagged_file_sink.h create mode 100644 gnuradio-core/src/lib/io/gr_tagged_file_sink.i (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index c52554645..8ce740afd 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -56,7 +56,8 @@ libio_la_SOURCES = \ gr_udp_source.cc \ gr_wavfile_sink.cc \ gr_wavfile_source.cc \ - gri_wavfile.cc + gri_wavfile.cc \ + gr_tagged_file_sink.cc grinclude_HEADERS = \ gr_file_sink.h \ @@ -89,7 +90,8 @@ grinclude_HEADERS = \ gr_udp_source.h \ gr_wavfile_source.h \ gr_wavfile_sink.h \ - gri_wavfile.h + gri_wavfile.h \ + gr_tagged_file_sink.h if PYTHON swiginclude_HEADERS = \ @@ -111,5 +113,6 @@ swiginclude_HEADERS = \ gr_udp_sink.i \ gr_udp_source.i \ gr_wavfile_source.i \ - gr_wavfile_sink.i + gr_wavfile_sink.i \ + gr_tagged_file_sink.i endif diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc new file mode 100644 index 000000000..1cd0a9a4b --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -0,0 +1,167 @@ +/* -*- c++ -*- */ +/* + * Copyright 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, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef O_BINARY +#define OUR_O_BINARY O_BINARY +#else +#define OUR_O_BINARY 0 +#endif + +// should be handled via configure +#ifdef O_LARGEFILE +#define OUR_O_LARGEFILE O_LARGEFILE +#else +#define OUR_O_LARGEFILE 0 +#endif + + +gr_tagged_file_sink::gr_tagged_file_sink (size_t itemsize) + : gr_sync_block ("tagged_file_sink", + gr_make_io_signature (1, 1, itemsize), + gr_make_io_signature (0, 0, 0)), + d_itemsize (itemsize) +{ + d_state = NOT_IN_BURST; +} + +gr_tagged_file_sink_sptr +gr_make_tagged_file_sink (size_t itemsize) +{ + return gnuradio::get_initial_sptr(new gr_tagged_file_sink (itemsize)); +} + +gr_tagged_file_sink::~gr_tagged_file_sink () +{ +} + +bool pmtcompare(pmt::pmt_t x, pmt::pmt_t y) +{ + uint64_t t_x, t_y; + t_x = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(x, 0)); + t_y = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(y, 0)); + return t_x < t_y; +} + +int +gr_tagged_file_sink::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + char *inbuf = (char *) input_items[0]; + + uint64_t start_N = nitems_read(0); + uint64_t end_N = start_N + (uint64_t)(noutput_items); + pmt::pmt_t bkey = pmt::pmt_string_to_symbol("burst"); + pmt::pmt_t tkey = pmt::pmt_string_to_symbol("packet_time_stamp"); + std::vector all_tags = get_tags_in_range(0, start_N, end_N); + std::sort(all_tags.begin(), all_tags.end(), pmtcompare); + + std::vector::iterator vitr = all_tags.begin(); + + int idx = 0, idx_stop = 0; + while(idx < noutput_items) { + if(d_state == NOT_IN_BURST) { + while(vitr != all_tags.end()) { + if((pmt::pmt_eqv(pmt::pmt_tuple_ref(*vitr, 2), bkey)) && + pmt::pmt_is_true(pmt::pmt_tuple_ref(*vitr,3))) { + uint64_t N = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*vitr, 0)) - start_N; + idx = (int)N; + d_state = IN_BURST; + + std::cout << "Found start of burst: " << N << std::endl; + + std::stringstream filename; + filename << "file" << d_n << ".dat"; + d_n++; + + int fd; + if ((fd = ::open (filename.str().c_str(), + O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY, + 0664)) < 0){ + perror (filename.str().c_str()); + return -1; + } + + // FIXME: + //if ((d_handle = fdopen (fd, d_is_binary ? "wb" : "w")) == NULL){ + if ((d_handle = fdopen (fd, "wb")) == NULL){ + perror (filename.str().c_str()); + ::close(fd); // don't leak file descriptor if fdopen fails. + } + + std::cout << "Created new file: " << filename.str() << std::endl; + + break; + } + + vitr++; + } + return noutput_items; + } + else { // In burst + while(vitr != all_tags.end()) { + if((pmt::pmt_eqv(pmt::pmt_tuple_ref(*vitr, 2), bkey)) && + pmt::pmt_is_false(pmt::pmt_tuple_ref(*vitr,3))) { + uint64_t N = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*vitr, 0)) - start_N; + idx_stop = (int)N; + + std::cout << "Found end of burst: " << N << std::endl; + + int count = fwrite (&inbuf[idx], d_itemsize, idx_stop-idx, d_handle); + if (count == 0) + break; + idx = idx_stop; + d_state = NOT_IN_BURST; + vitr++; + fclose(d_handle); + break; + } else { + vitr++; + } + } + if(d_state == IN_BURST) { + std::cout << "writing part of burst: " << idx << std::endl; + int count = fwrite (&inbuf[idx], d_itemsize, noutput_items-idx, d_handle); + if (count == 0) + break; + idx = noutput_items; + } + + } + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.h b/gnuradio-core/src/lib/io/gr_tagged_file_sink.h new file mode 100644 index 000000000..c657e6a75 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.h @@ -0,0 +1,65 @@ +/* -*- c++ -*- */ +/* + * Copyright 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, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_TAGGED_FILE_SINK_H +#define INCLUDED_GR_TAGGED_FILE_SINK_H + +#include + +class gr_tagged_file_sink; +typedef boost::shared_ptr gr_tagged_file_sink_sptr; + +gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize); + +/*! + * \brief Write stream to file descriptor. + * \ingroup sink_blk + */ + +class gr_tagged_file_sink : public gr_sync_block +{ + friend gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize); + + private: + enum { + NOT_IN_BURST = 0, + IN_BURST + }; + + size_t d_itemsize; + int d_state; + FILE *d_handle; + int d_n; + + protected: + gr_tagged_file_sink (size_t itemsize); + + public: + ~gr_tagged_file_sink (); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + + +#endif /* INCLUDED_GR_TAGGED_FILE_SINK_H */ diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.i b/gnuradio-core/src/lib/io/gr_tagged_file_sink.i new file mode 100644 index 000000000..92248e5dd --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.i @@ -0,0 +1,35 @@ +/* -*- c++ -*- */ +/* + * Copyright 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, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,tagged_file_sink) + +gr_tagged_file_sink_sptr +gr_make_tagged_file_sink (size_t itemsize); + +class gr_tagged_file_sink : public gr_sync_block +{ + protected: + gr_tagged_file_sink (size_t itemsize); + + public: + ~gr_tagged_file_sink (); +}; diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index 3538942ca..365577cd4 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -43,7 +43,7 @@ #include #include #include - +#include %} %include "gr_file_sink_base.i" @@ -64,4 +64,5 @@ %include "gr_udp_source.i" %include "gr_wavfile_sink.i" %include "gr_wavfile_source.i" +%include "gr_tagged_file_sink.i" -- cgit From 5ef9a41c9ddfae56a77c118c1dcf2b0af2973207 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 16 Nov 2010 22:31:52 -0800 Subject: Fixed tagging sink. --- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index 1cd0a9a4b..8dfde25cc 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -52,7 +52,7 @@ gr_tagged_file_sink::gr_tagged_file_sink (size_t itemsize) : gr_sync_block ("tagged_file_sink", gr_make_io_signature (1, 1, itemsize), gr_make_io_signature (0, 0, 0)), - d_itemsize (itemsize) + d_itemsize (itemsize),d_n(0) { d_state = NOT_IN_BURST; } @@ -88,6 +88,7 @@ gr_tagged_file_sink::work (int noutput_items, pmt::pmt_t tkey = pmt::pmt_string_to_symbol("packet_time_stamp"); std::vector all_tags = get_tags_in_range(0, start_N, end_N); std::sort(all_tags.begin(), all_tags.end(), pmtcompare); + std::cout << "Number of tags: " << all_tags.size() << std::endl; std::vector::iterator vitr = all_tags.begin(); @@ -95,13 +96,15 @@ gr_tagged_file_sink::work (int noutput_items, while(idx < noutput_items) { if(d_state == NOT_IN_BURST) { while(vitr != all_tags.end()) { + //std::cout << "\tNot in burst: " << *vitr << std::endl; + if((pmt::pmt_eqv(pmt::pmt_tuple_ref(*vitr, 2), bkey)) && pmt::pmt_is_true(pmt::pmt_tuple_ref(*vitr,3))) { + uint64_t N = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*vitr, 0)) - start_N; idx = (int)N; - d_state = IN_BURST; - std::cout << "Found start of burst: " << N << std::endl; + std::cout << std::endl << "Found start of burst: " << N << ", " << N+start_N << std::endl; std::stringstream filename; filename << "file" << d_n << ".dat"; @@ -124,23 +127,27 @@ gr_tagged_file_sink::work (int noutput_items, std::cout << "Created new file: " << filename.str() << std::endl; + d_state = IN_BURST; break; } vitr++; } - return noutput_items; + if(d_state == NOT_IN_BURST) + return noutput_items; } else { // In burst while(vitr != all_tags.end()) { + //std::cout << "\tin burst: " << *vitr << std::endl; + if((pmt::pmt_eqv(pmt::pmt_tuple_ref(*vitr, 2), bkey)) && pmt::pmt_is_false(pmt::pmt_tuple_ref(*vitr,3))) { uint64_t N = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*vitr, 0)) - start_N; idx_stop = (int)N; - std::cout << "Found end of burst: " << N << std::endl; + std::cout << "Found end of burst: " << N << ", " << N+start_N << std::endl; - int count = fwrite (&inbuf[idx], d_itemsize, idx_stop-idx, d_handle); + int count = fwrite (&inbuf[d_itemsize*idx], d_itemsize, idx_stop-idx, d_handle); if (count == 0) break; idx = idx_stop; @@ -153,7 +160,7 @@ gr_tagged_file_sink::work (int noutput_items, } } if(d_state == IN_BURST) { - std::cout << "writing part of burst: " << idx << std::endl; + std::cout << "writing part of burst: " << noutput_items-idx << std::endl; int count = fwrite (&inbuf[idx], d_itemsize, noutput_items-idx, d_handle); if (count == 0) break; -- cgit From b8da2172d0b10f5de04a12b942b48439a7aae8ae Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 17 Nov 2010 15:59:43 -0800 Subject: Changing blocks to use new get_tags api and tag convinience functions. --- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index 8dfde25cc..9b5ae70a6 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef O_BINARY #define OUR_O_BINARY O_BINARY @@ -85,8 +86,11 @@ gr_tagged_file_sink::work (int noutput_items, uint64_t start_N = nitems_read(0); uint64_t end_N = start_N + (uint64_t)(noutput_items); pmt::pmt_t bkey = pmt::pmt_string_to_symbol("burst"); - pmt::pmt_t tkey = pmt::pmt_string_to_symbol("packet_time_stamp"); - std::vector all_tags = get_tags_in_range(0, start_N, end_N); + //pmt::pmt_t tkey = pmt::pmt_string_to_symbol("time"); // use gr_tags::s_key_time + + std::vector all_tags; + get_tags_in_range(all_tags, 0, start_N, end_N); + std::sort(all_tags.begin(), all_tags.end(), pmtcompare); std::cout << "Number of tags: " << all_tags.size() << std::endl; @@ -98,10 +102,10 @@ gr_tagged_file_sink::work (int noutput_items, while(vitr != all_tags.end()) { //std::cout << "\tNot in burst: " << *vitr << std::endl; - if((pmt::pmt_eqv(pmt::pmt_tuple_ref(*vitr, 2), bkey)) && - pmt::pmt_is_true(pmt::pmt_tuple_ref(*vitr,3))) { + if((pmt::pmt_eqv(gr_tags::get_key(*vitr), bkey)) && + pmt::pmt_is_true(gr_tags::get_value(*vitr))) { - uint64_t N = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*vitr, 0)) - start_N; + uint64_t N = gr_tags::get_nitems(*vitr) - start_N; idx = (int)N; std::cout << std::endl << "Found start of burst: " << N << ", " << N+start_N << std::endl; @@ -140,9 +144,9 @@ gr_tagged_file_sink::work (int noutput_items, while(vitr != all_tags.end()) { //std::cout << "\tin burst: " << *vitr << std::endl; - if((pmt::pmt_eqv(pmt::pmt_tuple_ref(*vitr, 2), bkey)) && - pmt::pmt_is_false(pmt::pmt_tuple_ref(*vitr,3))) { - uint64_t N = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(*vitr, 0)) - start_N; + if((pmt::pmt_eqv(gr_tags::get_key(*vitr), bkey)) && + pmt::pmt_is_false(gr_tags::get_value(*vitr))) { + uint64_t N = gr_tags::get_nitems(*vitr) - start_N; idx_stop = (int)N; std::cout << "Found end of burst: " << N << ", " << N+start_N << std::endl; -- cgit From f60c4420e1fdef24687ffed6baf4fd7fa5ca5cf8 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Thu, 18 Nov 2010 17:33:05 -0800 Subject: Fix guile related problems with gr_message_{sink,source}. --- gnuradio-core/src/lib/io/gr_message_source.i | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_message_source.i b/gnuradio-core/src/lib/io/gr_message_source.i index 3566ee5a7..e4e2016d0 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.i +++ b/gnuradio-core/src/lib/io/gr_message_source.i @@ -20,12 +20,16 @@ * Boston, MA 02110-1301, USA. */ -#ifdef SWIGGUILE -#warning "gr_message_source.i: FIXME being ignored by swig/guile for now" -#else - GR_SWIG_BLOCK_MAGIC(gr,message_source); +#ifdef SWIGGUILE +// Rename these. Without this, the primitive bindings are OK, but the +// goops bindings try to create a bogus generic-function... +// See core.scm for the second part of the workaround. +%rename(message_source_limit_ctor) gr_make_message_source(size_t itemsize, int msgq_limit); +%rename(message_source_msgq_ctor) gr_make_message_source(size_t itemsize, gr_msg_queue_sptr msgq); +#endif + gr_message_source_sptr gr_make_message_source (size_t itemsize, int msgq_limit=0); gr_message_source_sptr gr_make_message_source (size_t itemsize, gr_msg_queue_sptr msgq); @@ -40,4 +44,3 @@ class gr_message_source : public gr_sync_block gr_msg_queue_sptr msgq() const; }; -#endif -- cgit From 8f2b07591c404c78c9fc7b9532d3fb6c27165981 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 21 Nov 2010 19:40:35 -0500 Subject: Tagging file source takes in sample rate and uses it to find the last time tag and adjust the time between these tags and the burst start by the sample rate. Also added a function to gr_tag_info that can be used to sort tags based on nitems using std::sort. --- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 77 ++++++++++++++++--------- gnuradio-core/src/lib/io/gr_tagged_file_sink.h | 13 +++-- gnuradio-core/src/lib/io/gr_tagged_file_sink.i | 4 +- 3 files changed, 61 insertions(+), 33 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index 9b5ae70a6..500a359b3 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -49,33 +49,27 @@ #endif -gr_tagged_file_sink::gr_tagged_file_sink (size_t itemsize) +gr_tagged_file_sink::gr_tagged_file_sink (size_t itemsize, double samp_rate) : gr_sync_block ("tagged_file_sink", gr_make_io_signature (1, 1, itemsize), gr_make_io_signature (0, 0, 0)), - d_itemsize (itemsize),d_n(0) + d_itemsize (itemsize), d_n(0), d_sample_rate(samp_rate) { d_state = NOT_IN_BURST; + d_last_N = 0; + d_timeval = 0; } gr_tagged_file_sink_sptr -gr_make_tagged_file_sink (size_t itemsize) +gr_make_tagged_file_sink (size_t itemsize, double samp_rate) { - return gnuradio::get_initial_sptr(new gr_tagged_file_sink (itemsize)); + return gnuradio::get_initial_sptr(new gr_tagged_file_sink (itemsize, samp_rate)); } gr_tagged_file_sink::~gr_tagged_file_sink () { } -bool pmtcompare(pmt::pmt_t x, pmt::pmt_t y) -{ - uint64_t t_x, t_y; - t_x = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(x, 0)); - t_y = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(y, 0)); - return t_x < t_y; -} - int gr_tagged_file_sink::work (int noutput_items, gr_vector_const_void_star &input_items, @@ -86,13 +80,12 @@ gr_tagged_file_sink::work (int noutput_items, uint64_t start_N = nitems_read(0); uint64_t end_N = start_N + (uint64_t)(noutput_items); pmt::pmt_t bkey = pmt::pmt_string_to_symbol("burst"); - //pmt::pmt_t tkey = pmt::pmt_string_to_symbol("time"); // use gr_tags::s_key_time + //pmt::pmt_t tkey = pmt::pmt_string_to_symbol("time"); // use gr_tags::key_time std::vector all_tags; get_tags_in_range(all_tags, 0, start_N, end_N); - std::sort(all_tags.begin(), all_tags.end(), pmtcompare); - std::cout << "Number of tags: " << all_tags.size() << std::endl; + std::sort(all_tags.begin(), all_tags.end(), gr_tags::nitems_compare); std::vector::iterator vitr = all_tags.begin(); @@ -100,18 +93,53 @@ gr_tagged_file_sink::work (int noutput_items, while(idx < noutput_items) { if(d_state == NOT_IN_BURST) { while(vitr != all_tags.end()) { - //std::cout << "\tNot in burst: " << *vitr << std::endl; - if((pmt::pmt_eqv(gr_tags::get_key(*vitr), bkey)) && pmt::pmt_is_true(gr_tags::get_value(*vitr))) { - uint64_t N = gr_tags::get_nitems(*vitr) - start_N; - idx = (int)N; - - std::cout << std::endl << "Found start of burst: " << N << ", " << N+start_N << std::endl; + uint64_t N = gr_tags::get_nitems(*vitr); + idx = (int)(N - start_N); + + std::cout << std::endl << "Found start of burst: " + << idx << ", " << N << std::endl; + + // Find time burst occurred by getting latest time tag and extrapolating + // to new time based on sample rate of this block. + std::vector time_tags; + get_tags_in_range(time_tags, 0, d_last_N, N, gr_tags::key_time); + if(time_tags.size() > 0) { + pmt::pmt_t tag = time_tags[time_tags.size()-1]; + + uint64_t time_nitems = gr_tags::get_nitems(tag); + + // Get time based on last time tag from USRP + pmt::pmt_t time = gr_tags::get_value(tag); + int tsecs = pmt::pmt_to_long(pmt::pmt_tuple_ref(time, 0)); + double tfrac = pmt::pmt_to_double(pmt::pmt_tuple_ref(time, 1)); + + // Get new time from last time tag + difference in time to when + // burst tag occured based on the sample rate + double delta = (double)(N - time_nitems) / d_sample_rate; + d_timeval = (double)tsecs + tfrac + delta; + + std::cout.setf(std::ios::fixed, std::ios::floatfield); + std::cout.precision(8); + std::cout << "Time found: " << (double)tsecs + tfrac << std::endl; + std::cout << " time: " << d_timeval << std::endl; + std::cout << " time at N = " << time_nitems << " burst N = " << N << std::endl; + } + else { + // if no time tag, use last seen tag and update time based on + // sample rate of the block + d_timeval += (double)(N - d_last_N) / d_sample_rate; + std::cout << "Time not found" << std::endl; + std::cout << " time: " << d_timeval << std::endl; + } + d_last_N = N; std::stringstream filename; - filename << "file" << d_n << ".dat"; + filename.setf(std::ios::fixed, std::ios::floatfield); + filename.precision(8); + filename << "file" << d_n << "_" << d_timeval << ".dat"; d_n++; int fd; @@ -142,15 +170,11 @@ gr_tagged_file_sink::work (int noutput_items, } else { // In burst while(vitr != all_tags.end()) { - //std::cout << "\tin burst: " << *vitr << std::endl; - if((pmt::pmt_eqv(gr_tags::get_key(*vitr), bkey)) && pmt::pmt_is_false(gr_tags::get_value(*vitr))) { uint64_t N = gr_tags::get_nitems(*vitr) - start_N; idx_stop = (int)N; - std::cout << "Found end of burst: " << N << ", " << N+start_N << std::endl; - int count = fwrite (&inbuf[d_itemsize*idx], d_itemsize, idx_stop-idx, d_handle); if (count == 0) break; @@ -164,7 +188,6 @@ gr_tagged_file_sink::work (int noutput_items, } } if(d_state == IN_BURST) { - std::cout << "writing part of burst: " << noutput_items-idx << std::endl; int count = fwrite (&inbuf[idx], d_itemsize, noutput_items-idx, d_handle); if (count == 0) break; diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.h b/gnuradio-core/src/lib/io/gr_tagged_file_sink.h index c657e6a75..956340f8d 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.h +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.h @@ -28,7 +28,8 @@ class gr_tagged_file_sink; typedef boost::shared_ptr gr_tagged_file_sink_sptr; -gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize); +gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize, + double samp_rate); /*! * \brief Write stream to file descriptor. @@ -37,7 +38,8 @@ gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize); class gr_tagged_file_sink : public gr_sync_block { - friend gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize); + friend gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize, + double samp_rate); private: enum { @@ -49,9 +51,12 @@ class gr_tagged_file_sink : public gr_sync_block int d_state; FILE *d_handle; int d_n; - + double d_sample_rate; + uint64_t d_last_N; + double d_timeval; + protected: - gr_tagged_file_sink (size_t itemsize); + gr_tagged_file_sink (size_t itemsize, double samp_rate); public: ~gr_tagged_file_sink (); diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.i b/gnuradio-core/src/lib/io/gr_tagged_file_sink.i index 92248e5dd..1408adfc1 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.i +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.i @@ -23,12 +23,12 @@ GR_SWIG_BLOCK_MAGIC(gr,tagged_file_sink) gr_tagged_file_sink_sptr -gr_make_tagged_file_sink (size_t itemsize); +gr_make_tagged_file_sink (size_t itemsize, double samp_rate); class gr_tagged_file_sink : public gr_sync_block { protected: - gr_tagged_file_sink (size_t itemsize); + gr_tagged_file_sink (size_t itemsize, double samp_rate); public: ~gr_tagged_file_sink (); -- cgit From 9217bbcafe547fd5815265758370b07c375d72c9 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 21 Nov 2010 21:17:42 -0500 Subject: Fixed file tagger error handling so it doesn't prematurely exit under certain, but correct, conditions. --- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index 500a359b3..371d6268c 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -172,28 +172,37 @@ gr_tagged_file_sink::work (int noutput_items, while(vitr != all_tags.end()) { if((pmt::pmt_eqv(gr_tags::get_key(*vitr), bkey)) && pmt::pmt_is_false(gr_tags::get_value(*vitr))) { - uint64_t N = gr_tags::get_nitems(*vitr) - start_N; - idx_stop = (int)N; + uint64_t N = gr_tags::get_nitems(*vitr); + idx_stop = (int)N - start_N; + + std::cout << "Found end of burst: " + << idx_stop << ", " << N << std::endl; int count = fwrite (&inbuf[d_itemsize*idx], d_itemsize, idx_stop-idx, d_handle); - if (count == 0) - break; + if (count == 0) { + if(ferror(d_handle)) { + perror("gr_tagged_file_sink: error writing file"); + } + } idx = idx_stop; d_state = NOT_IN_BURST; vitr++; fclose(d_handle); break; - } else { + } + else { vitr++; } } if(d_state == IN_BURST) { int count = fwrite (&inbuf[idx], d_itemsize, noutput_items-idx, d_handle); - if (count == 0) - break; + if (count == 0) { + if(ferror(d_handle)) { + perror("gr_tagged_file_sink: error writing file"); + } + } idx = noutput_items; } - } } -- cgit From 7c5dc0920240f566ad4482f47ca8b9095479f04e Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 21 Nov 2010 21:23:31 -0500 Subject: Removed comments to stdout from file tagger; made it easir to go from internally generated bursts to detected bursts (which needs work). --- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index 371d6268c..55c42eaff 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -99,8 +99,8 @@ gr_tagged_file_sink::work (int noutput_items, uint64_t N = gr_tags::get_nitems(*vitr); idx = (int)(N - start_N); - std::cout << std::endl << "Found start of burst: " - << idx << ", " << N << std::endl; + //std::cout << std::endl << "Found start of burst: " + // << idx << ", " << N << std::endl; // Find time burst occurred by getting latest time tag and extrapolating // to new time based on sample rate of this block. @@ -121,18 +121,18 @@ gr_tagged_file_sink::work (int noutput_items, double delta = (double)(N - time_nitems) / d_sample_rate; d_timeval = (double)tsecs + tfrac + delta; - std::cout.setf(std::ios::fixed, std::ios::floatfield); - std::cout.precision(8); - std::cout << "Time found: " << (double)tsecs + tfrac << std::endl; - std::cout << " time: " << d_timeval << std::endl; - std::cout << " time at N = " << time_nitems << " burst N = " << N << std::endl; + //std::cout.setf(std::ios::fixed, std::ios::floatfield); + //std::cout.precision(8); + //std::cout << "Time found: " << (double)tsecs + tfrac << std::endl; + //std::cout << " time: " << d_timeval << std::endl; + //std::cout << " time at N = " << time_nitems << " burst N = " << N << std::endl; } else { // if no time tag, use last seen tag and update time based on // sample rate of the block d_timeval += (double)(N - d_last_N) / d_sample_rate; - std::cout << "Time not found" << std::endl; - std::cout << " time: " << d_timeval << std::endl; + //std::cout << "Time not found" << std::endl; + //std::cout << " time: " << d_timeval << std::endl; } d_last_N = N; @@ -157,7 +157,7 @@ gr_tagged_file_sink::work (int noutput_items, ::close(fd); // don't leak file descriptor if fdopen fails. } - std::cout << "Created new file: " << filename.str() << std::endl; + //std::cout << "Created new file: " << filename.str() << std::endl; d_state = IN_BURST; break; @@ -175,8 +175,8 @@ gr_tagged_file_sink::work (int noutput_items, uint64_t N = gr_tags::get_nitems(*vitr); idx_stop = (int)N - start_N; - std::cout << "Found end of burst: " - << idx_stop << ", " << N << std::endl; + //std::cout << "Found end of burst: " + // << idx_stop << ", " << N << std::endl; int count = fwrite (&inbuf[d_itemsize*idx], d_itemsize, idx_stop-idx, d_handle); if (count == 0) { -- cgit From 34a9654fa10efcf360fde9c42c624739abaabbc5 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 29 Nov 2010 12:59:54 -0500 Subject: Removing global pmt constants. Were causing segfaults during make check. Must fix this later. --- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index 55c42eaff..c76ede542 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -105,7 +105,9 @@ gr_tagged_file_sink::work (int noutput_items, // Find time burst occurred by getting latest time tag and extrapolating // to new time based on sample rate of this block. std::vector time_tags; - get_tags_in_range(time_tags, 0, d_last_N, N, gr_tags::key_time); + //get_tags_in_range(time_tags, 0, d_last_N, N, gr_tags::key_time); + get_tags_in_range(time_tags, 0, d_last_N, N, + pmt::pmt_string_to_symbol("time")); if(time_tags.size() > 0) { pmt::pmt_t tag = time_tags[time_tags.size()-1]; -- cgit From 9911a8d9edcde54b9a18810f37799a58a6895310 Mon Sep 17 00:00:00 2001 From: Eric Blossom Date: Tue, 7 Dec 2010 13:35:54 -0800 Subject: Remove incorrect if PYTHON around swiginclude_HEADERS --- gnuradio-core/src/lib/io/Makefile.am | 2 -- 1 file changed, 2 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index 8ce740afd..442d5e3a9 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -93,7 +93,6 @@ grinclude_HEADERS = \ gri_wavfile.h \ gr_tagged_file_sink.h -if PYTHON swiginclude_HEADERS = \ io.i \ gr_file_sink.i \ @@ -115,4 +114,3 @@ swiginclude_HEADERS = \ gr_wavfile_source.i \ gr_wavfile_sink.i \ gr_tagged_file_sink.i -endif -- cgit From 239c5860be82936e00cfec16a4e1f06f1a004c59 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 26 Feb 2011 14:49:53 -0800 Subject: use boost::math::iround in gr_histo_sink_f.cc and gr_wavfile_sink.cc this provides a round implementation on platforms w/o c99 standard --- gnuradio-core/src/lib/io/gr_histo_sink_f.cc | 5 +++-- gnuradio-core/src/lib/io/gr_wavfile_sink.cc | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_histo_sink_f.cc b/gnuradio-core/src/lib/io/gr_histo_sink_f.cc index a37189c24..fc0c12ce6 100644 --- a/gnuradio-core/src/lib/io/gr_histo_sink_f.cc +++ b/gnuradio-core/src/lib/io/gr_histo_sink_f.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2009,2010 Free Software Foundation, Inc. + * Copyright 2009,2010,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,6 +26,7 @@ #include #include +#include static float get_clean_num(float num){ if (num == 0) return 0; @@ -101,7 +102,7 @@ gr_histo_sink_f::send_frame(void){ int index; float bin_width = (maximum - minimum)/(d_num_bins-1); for (unsigned int i = 0; i < d_sample_count; i++){ - index = round((d_samps[i] - minimum)/bin_width); + index = boost::math::iround((d_samps[i] - minimum)/bin_width); /* ensure the index range in case a small floating point error is involed */ if (index < 0) index = 0; if (index >= (int)d_num_bins) index = d_num_bins-1; diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc index b60a6e3ab..a96aadc72 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2006,2007,2008,2009,2010 Free Software Foundation, Inc. + * Copyright 2004,2006,2007,2008,2009,2010,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -33,6 +33,7 @@ #include #include #include +#include // win32 (mingw/msvc) specific #ifdef HAVE_IO_H @@ -224,7 +225,7 @@ gr_wavfile_sink::convert_to_short(float sample) sample = d_min_sample_val; } - return (short int) roundf(sample); + return (short int) boost::math::iround(sample); } -- cgit From 64dac6a1f62fb8484e879f0d20ee60bc02da179c Mon Sep 17 00:00:00 2001 From: Don Ward Date: Fri, 25 Mar 2011 11:53:04 -0400 Subject: Fixing missing include files and various other patches for Windows build issues. --- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 1 - gnuradio-core/src/lib/io/gr_tagged_file_sink.h | 1 + gnuradio-core/src/lib/io/gr_wavfile_source.cc | 1 - gnuradio-core/src/lib/io/gr_wavfile_source.h | 1 + 4 files changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index c76ede542..154611c32 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -26,7 +26,6 @@ #include #include -#include #include #include #include diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.h b/gnuradio-core/src/lib/io/gr_tagged_file_sink.h index 956340f8d..2e0a5c63a 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.h +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.h @@ -24,6 +24,7 @@ #define INCLUDED_GR_TAGGED_FILE_SINK_H #include +#include // for FILE class gr_tagged_file_sink; typedef boost::shared_ptr gr_tagged_file_sink_sptr; diff --git a/gnuradio-core/src/lib/io/gr_wavfile_source.cc b/gnuradio-core/src/lib/io/gr_wavfile_source.cc index d00dd3028..136e52611 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_source.cc +++ b/gnuradio-core/src/lib/io/gr_wavfile_source.cc @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/gnuradio-core/src/lib/io/gr_wavfile_source.h b/gnuradio-core/src/lib/io/gr_wavfile_source.h index 0c663f0a0..e434a6b4c 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_source.h +++ b/gnuradio-core/src/lib/io/gr_wavfile_source.h @@ -24,6 +24,7 @@ #define INCLUDED_GR_WAVFILE_SOURCE_H #include +#include // for FILE class gr_wavfile_source; typedef boost::shared_ptr gr_wavfile_source_sptr; -- cgit From 34488d41f4bb066fb506f6851e92daf02609262b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 9 Jul 2011 19:30:40 -0700 Subject: core: added missing config.h includes on cc files Added to the cc files which were missing config.h and required compatibility functions defined in config.h. Applies to compiling under MSVC with cmake work branch. --- gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc index 668f04cad..14f2b8589 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc +++ b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc @@ -20,6 +20,10 @@ * Boston, MA 02110-1301, USA. */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include "microtune_xxxx_eval_board.h" #include "microtune_eval_board_defs.h" #include "microtune_xxxx.h" -- cgit From 08936428827ff801db174e8a2db1cf26ecff857c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 9 Jul 2011 19:39:30 -0700 Subject: core: added missing io.h includes on cc files Added to the cc files which were missing io.h and required compatibility declarations in io.h to compile. Applies to compiling under MSVC with cmake work branch. --- gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc | 3 +++ gnuradio-core/src/lib/io/gr_file_descriptor_source.cc | 3 +++ gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 4 ++++ 3 files changed, 10 insertions(+) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc index 09fb6c826..11e0a8eb9 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc @@ -34,6 +34,9 @@ #include #include +#ifdef HAVE_IO_H +#include +#endif gr_file_descriptor_sink::gr_file_descriptor_sink (size_t itemsize, int fd) : gr_sync_block ("file_descriptor_sink", diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc b/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc index 700ad4aef..334a57848 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc @@ -35,6 +35,9 @@ #include #include +#ifdef HAVE_IO_H +#include +#endif gr_file_descriptor_source::gr_file_descriptor_source (size_t itemsize, int fd, diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index 154611c32..91618bad6 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -34,6 +34,10 @@ #include #include +#ifdef HAVE_IO_H +#include +#endif + #ifdef O_BINARY #define OUR_O_BINARY O_BINARY #else -- cgit From f914499f4a96fe69ab9cd8dba48f8e3bfc7a54e5 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 20 Jul 2011 18:38:36 -0700 Subject: core: API declaration macros for core class and function symbols --- gnuradio-core/src/lib/io/gr_file_descriptor_sink.h | 7 ++++--- gnuradio-core/src/lib/io/gr_file_descriptor_source.h | 7 ++++--- gnuradio-core/src/lib/io/gr_file_sink.h | 7 ++++--- gnuradio-core/src/lib/io/gr_file_sink_base.h | 3 ++- gnuradio-core/src/lib/io/gr_file_source.h | 7 ++++--- gnuradio-core/src/lib/io/gr_histo_sink_f.h | 7 ++++--- gnuradio-core/src/lib/io/gr_message_sink.h | 7 ++++--- gnuradio-core/src/lib/io/gr_message_source.h | 11 ++++++----- gnuradio-core/src/lib/io/gr_oscope_guts.h | 3 ++- gnuradio-core/src/lib/io/gr_oscope_sink_f.h | 7 ++++--- gnuradio-core/src/lib/io/gr_oscope_sink_x.h | 3 ++- gnuradio-core/src/lib/io/gr_tagged_file_sink.h | 7 ++++--- gnuradio-core/src/lib/io/gr_udp_sink.h | 7 ++++--- gnuradio-core/src/lib/io/gr_udp_source.h | 7 ++++--- gnuradio-core/src/lib/io/gr_wavfile_sink.h | 7 ++++--- gnuradio-core/src/lib/io/gr_wavfile_source.h | 7 ++++--- gnuradio-core/src/lib/io/gri_wavfile.h | 1 + gnuradio-core/src/lib/io/i2c.h | 3 ++- gnuradio-core/src/lib/io/i2c_bbio.h | 3 ++- gnuradio-core/src/lib/io/i2c_bbio_pp.h | 7 ++++--- gnuradio-core/src/lib/io/i2c_bitbang.h | 7 ++++--- gnuradio-core/src/lib/io/microtune_4702.h | 3 ++- gnuradio-core/src/lib/io/microtune_4702_eval_board.h | 3 ++- gnuradio-core/src/lib/io/microtune_4937.h | 3 ++- gnuradio-core/src/lib/io/microtune_4937_eval_board.h | 3 ++- gnuradio-core/src/lib/io/microtune_xxxx.h | 3 ++- gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h | 3 ++- gnuradio-core/src/lib/io/ppio.h | 5 +++-- gnuradio-core/src/lib/io/ppio_ppdev.h | 5 +++-- gnuradio-core/src/lib/io/sdr_1000.h | 3 ++- 30 files changed, 93 insertions(+), 63 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h index fa8fa3f05..5e4cc6505 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h @@ -23,21 +23,22 @@ #ifndef INCLUDED_GR_FILE_DESCRIPTOR_SINK_H #define INCLUDED_GR_FILE_DESCRIPTOR_SINK_H +#include #include class gr_file_descriptor_sink; typedef boost::shared_ptr gr_file_descriptor_sink_sptr; -gr_file_descriptor_sink_sptr gr_make_file_descriptor_sink (size_t itemsize, int fd); +GR_CORE_API gr_file_descriptor_sink_sptr gr_make_file_descriptor_sink (size_t itemsize, int fd); /*! * \brief Write stream to file descriptor. * \ingroup sink_blk */ -class gr_file_descriptor_sink : public gr_sync_block +class GR_CORE_API gr_file_descriptor_sink : public gr_sync_block { - friend gr_file_descriptor_sink_sptr gr_make_file_descriptor_sink (size_t itemsize, int fd); + friend GR_CORE_API gr_file_descriptor_sink_sptr gr_make_file_descriptor_sink (size_t itemsize, int fd); private: size_t d_itemsize; diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_source.h b/gnuradio-core/src/lib/io/gr_file_descriptor_source.h index a9f117286..fa513fd25 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_source.h +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_source.h @@ -23,12 +23,13 @@ #ifndef INCLUDED_GR_FILE_DESCRIPTOR_SOURCE_H #define INCLUDED_GR_FILE_DESCRIPTOR_SOURCE_H +#include #include class gr_file_descriptor_source; typedef boost::shared_ptr gr_file_descriptor_source_sptr; -gr_file_descriptor_source_sptr +GR_CORE_API gr_file_descriptor_source_sptr gr_make_file_descriptor_source (size_t itemsize, int fd, bool repeat = false); /*! @@ -36,9 +37,9 @@ gr_make_file_descriptor_source (size_t itemsize, int fd, bool repeat = false); * \ingroup source_blk */ -class gr_file_descriptor_source : public gr_sync_block +class GR_CORE_API gr_file_descriptor_source : public gr_sync_block { - friend gr_file_descriptor_source_sptr + friend GR_CORE_API gr_file_descriptor_source_sptr gr_make_file_descriptor_source (size_t itemsize, int fd, bool repeat); private: size_t d_itemsize; diff --git a/gnuradio-core/src/lib/io/gr_file_sink.h b/gnuradio-core/src/lib/io/gr_file_sink.h index b9ad06cd6..180cbef2a 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_sink.h @@ -23,22 +23,23 @@ #ifndef INCLUDED_GR_FILE_SINK_H #define INCLUDED_GR_FILE_SINK_H +#include #include #include class gr_file_sink; typedef boost::shared_ptr gr_file_sink_sptr; -gr_file_sink_sptr gr_make_file_sink(size_t itemsize, const char *filename); +GR_CORE_API gr_file_sink_sptr gr_make_file_sink(size_t itemsize, const char *filename); /*! * \brief Write stream to file. * \ingroup sink_blk */ -class gr_file_sink : public gr_sync_block, public gr_file_sink_base +class GR_CORE_API gr_file_sink : public gr_sync_block, public gr_file_sink_base { - friend gr_file_sink_sptr gr_make_file_sink(size_t itemsize, const char *filename); + friend GR_CORE_API gr_file_sink_sptr gr_make_file_sink(size_t itemsize, const char *filename); private: size_t d_itemsize; diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.h b/gnuradio-core/src/lib/io/gr_file_sink_base.h index 7b96cdb7f..6765dbad8 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.h +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.h @@ -23,13 +23,14 @@ #ifndef INCLUDED_GR_FILE_SINK_BASE_H #define INCLUDED_GR_FILE_SINK_BASE_H +#include #include #include /*! * \brief Common base class for file sinks */ -class gr_file_sink_base +class GR_CORE_API gr_file_sink_base { protected: FILE *d_fp; // current FILE pointer diff --git a/gnuradio-core/src/lib/io/gr_file_source.h b/gnuradio-core/src/lib/io/gr_file_source.h index 5f5c2564e..6e8fc4074 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.h +++ b/gnuradio-core/src/lib/io/gr_file_source.h @@ -23,12 +23,13 @@ #ifndef INCLUDED_GR_FILE_SOURCE_H #define INCLUDED_GR_FILE_SOURCE_H +#include #include class gr_file_source; typedef boost::shared_ptr gr_file_source_sptr; -gr_file_source_sptr +GR_CORE_API gr_file_source_sptr gr_make_file_source (size_t itemsize, const char *filename, bool repeat = false); /*! @@ -36,9 +37,9 @@ gr_make_file_source (size_t itemsize, const char *filename, bool repeat = false) * \ingroup source_blk */ -class gr_file_source : public gr_sync_block +class GR_CORE_API gr_file_source : public gr_sync_block { - friend gr_file_source_sptr gr_make_file_source (size_t itemsize, + friend GR_CORE_API gr_file_source_sptr gr_make_file_source (size_t itemsize, const char *filename, bool repeat); private: diff --git a/gnuradio-core/src/lib/io/gr_histo_sink_f.h b/gnuradio-core/src/lib/io/gr_histo_sink_f.h index 8ba45ec55..934066ba2 100644 --- a/gnuradio-core/src/lib/io/gr_histo_sink_f.h +++ b/gnuradio-core/src/lib/io/gr_histo_sink_f.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_HISTO_SINK_F_H #define INCLUDED_GR_HISTO_SINK_F_H +#include #include #include #include @@ -30,13 +31,13 @@ class gr_histo_sink_f; typedef boost::shared_ptr gr_histo_sink_f_sptr; -gr_histo_sink_f_sptr gr_make_histo_sink_f (gr_msg_queue_sptr msgq); +GR_CORE_API gr_histo_sink_f_sptr gr_make_histo_sink_f (gr_msg_queue_sptr msgq); /*! * \brief Histogram module. * \ingroup sink_blk */ -class gr_histo_sink_f : public gr_sync_block +class GR_CORE_API gr_histo_sink_f : public gr_sync_block { private: gr_msg_queue_sptr d_msgq; @@ -47,7 +48,7 @@ private: float *d_samps; gruel::mutex d_mutex; - friend gr_histo_sink_f_sptr gr_make_histo_sink_f (gr_msg_queue_sptr msgq); + friend GR_CORE_API gr_histo_sink_f_sptr gr_make_histo_sink_f (gr_msg_queue_sptr msgq); gr_histo_sink_f (gr_msg_queue_sptr msgq); void send_frame(void); void clear(void); diff --git a/gnuradio-core/src/lib/io/gr_message_sink.h b/gnuradio-core/src/lib/io/gr_message_sink.h index 5f1e5f91f..180055261 100644 --- a/gnuradio-core/src/lib/io/gr_message_sink.h +++ b/gnuradio-core/src/lib/io/gr_message_sink.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_MESSAGE_SINK_H #define INCLUDED_GR_MESSAGE_SINK_H +#include #include #include #include @@ -30,7 +31,7 @@ class gr_message_sink; typedef boost::shared_ptr gr_message_sink_sptr; -gr_message_sink_sptr gr_make_message_sink (size_t itemsize, +GR_CORE_API gr_message_sink_sptr gr_make_message_sink (size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block); @@ -38,14 +39,14 @@ gr_message_sink_sptr gr_make_message_sink (size_t itemsize, * \brief Gather received items into messages and insert into msgq * \ingroup sink_blk */ -class gr_message_sink : public gr_sync_block +class GR_CORE_API gr_message_sink : public gr_sync_block { private: size_t d_itemsize; gr_msg_queue_sptr d_msgq; bool d_dont_block; - friend gr_message_sink_sptr + friend GR_CORE_API gr_message_sink_sptr gr_make_message_sink(size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block); protected: diff --git a/gnuradio-core/src/lib/io/gr_message_source.h b/gnuradio-core/src/lib/io/gr_message_source.h index 46a808754..16a0f4474 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.h +++ b/gnuradio-core/src/lib/io/gr_message_source.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_MESSAGE_SOURCE_H #define INCLUDED_GR_MESSAGE_SOURCE_H +#include #include #include #include @@ -30,14 +31,14 @@ class gr_message_source; typedef boost::shared_ptr gr_message_source_sptr; -gr_message_source_sptr gr_make_message_source (size_t itemsize, int msgq_limit=0); -gr_message_source_sptr gr_make_message_source (size_t itemsize, gr_msg_queue_sptr msgq); +GR_CORE_API gr_message_source_sptr gr_make_message_source (size_t itemsize, int msgq_limit=0); +GR_CORE_API gr_message_source_sptr gr_make_message_source (size_t itemsize, gr_msg_queue_sptr msgq); /*! * \brief Turn received messages into a stream * \ingroup source_blk */ -class gr_message_source : public gr_sync_block +class GR_CORE_API gr_message_source : public gr_sync_block { private: size_t d_itemsize; @@ -46,9 +47,9 @@ class gr_message_source : public gr_sync_block unsigned d_msg_offset; bool d_eof; - friend gr_message_source_sptr + friend GR_CORE_API gr_message_source_sptr gr_make_message_source(size_t itemsize, int msgq_limit); - friend gr_message_source_sptr + friend GR_CORE_API gr_message_source_sptr gr_make_message_source(size_t itemsize, gr_msg_queue_sptr msgq); protected: diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.h b/gnuradio-core/src/lib/io/gr_oscope_guts.h index f39db62f6..3223d4e38 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.h +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.h @@ -24,6 +24,7 @@ #ifndef INCLUDED_GR_OSCOPE_GUTS_H #define INCLUDED_GR_OSCOPE_GUTS_H +#include #include #include @@ -40,7 +41,7 @@ * consist of 50% pre-trigger data and 50% post-trigger data. */ -class gr_oscope_guts { +class GR_CORE_API gr_oscope_guts { public: static const int MAX_CHANNELS = 8; private: diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_f.h b/gnuradio-core/src/lib/io/gr_oscope_sink_f.h index 1a8022b89..e3d1f65e5 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_f.h +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_f.h @@ -23,13 +23,14 @@ #ifndef INCLUDED_GR_OSCOPE_SINK_F_H #define INCLUDED_GR_OSCOPE_SINK_F_H +#include #include #include class gr_oscope_sink_f; typedef boost::shared_ptr gr_oscope_sink_f_sptr; -gr_oscope_sink_f_sptr gr_make_oscope_sink_f (double sampling_rate, gr_msg_queue_sptr msgq); +GR_CORE_API gr_oscope_sink_f_sptr gr_make_oscope_sink_f (double sampling_rate, gr_msg_queue_sptr msgq); /*! @@ -38,10 +39,10 @@ gr_oscope_sink_f_sptr gr_make_oscope_sink_f (double sampling_rate, gr_msg_queue_ * * Accepts multiple float streams. */ -class gr_oscope_sink_f : public gr_oscope_sink_x +class GR_CORE_API gr_oscope_sink_f : public gr_oscope_sink_x { private: - friend gr_oscope_sink_f_sptr + friend GR_CORE_API gr_oscope_sink_f_sptr gr_make_oscope_sink_f (double sampling_rate, gr_msg_queue_sptr msgq); gr_oscope_sink_f (double sampling_rate, gr_msg_queue_sptr msgq); diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_x.h b/gnuradio-core/src/lib/io/gr_oscope_sink_x.h index 62cf65100..aaff5870b 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_x.h +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_x.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_OSCOPE_SINK_X_H #define INCLUDED_GR_OSCOPE_SINK_X_H +#include #include #include @@ -34,7 +35,7 @@ class gr_oscope_guts; * * Don't instantiate this. Use gr_oscope_sink_f or gr_oscope_sink_c instead. */ -class gr_oscope_sink_x : public gr_sync_block +class GR_CORE_API gr_oscope_sink_x : public gr_sync_block { protected: double d_sampling_rate; diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.h b/gnuradio-core/src/lib/io/gr_tagged_file_sink.h index 2e0a5c63a..da12dca78 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.h +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.h @@ -23,13 +23,14 @@ #ifndef INCLUDED_GR_TAGGED_FILE_SINK_H #define INCLUDED_GR_TAGGED_FILE_SINK_H +#include #include #include // for FILE class gr_tagged_file_sink; typedef boost::shared_ptr gr_tagged_file_sink_sptr; -gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize, +GR_CORE_API gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize, double samp_rate); /*! @@ -37,9 +38,9 @@ gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize, * \ingroup sink_blk */ -class gr_tagged_file_sink : public gr_sync_block +class GR_CORE_API gr_tagged_file_sink : public gr_sync_block { - friend gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize, + friend GR_CORE_API gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize, double samp_rate); private: diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.h b/gnuradio-core/src/lib/io/gr_udp_sink.h index 421d514a4..e9d4f8c73 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.h +++ b/gnuradio-core/src/lib/io/gr_udp_sink.h @@ -23,13 +23,14 @@ #ifndef INCLUDED_GR_UDP_SINK_H #define INCLUDED_GR_UDP_SINK_H +#include #include #include class gr_udp_sink; typedef boost::shared_ptr gr_udp_sink_sptr; -gr_udp_sink_sptr +GR_CORE_API gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize, const char *host, unsigned short port, int payload_size=1472, bool eof=true); @@ -47,9 +48,9 @@ gr_make_udp_sink (size_t itemsize, * \param eof Send zero-length packet on disconnect */ -class gr_udp_sink : public gr_sync_block +class GR_CORE_API gr_udp_sink : public gr_sync_block { - friend gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize, + friend GR_CORE_API gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize, const char *host, unsigned short port, int payload_size, bool eof); diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h index 5d30fad30..e2898981d 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.h +++ b/gnuradio-core/src/lib/io/gr_udp_source.h @@ -23,13 +23,14 @@ #ifndef INCLUDED_GR_UDP_SOURCE_H #define INCLUDED_GR_UDP_SOURCE_H +#include #include #include class gr_udp_source; typedef boost::shared_ptr gr_udp_source_sptr; -gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *host, +GR_CORE_API gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *host, unsigned short port, int payload_size=1472, bool eof=true, bool wait=true); @@ -52,9 +53,9 @@ gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *host, * */ -class gr_udp_source : public gr_sync_block +class GR_CORE_API gr_udp_source : public gr_sync_block { - friend gr_udp_source_sptr gr_make_udp_source(size_t itemsize, + friend GR_CORE_API gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *host, unsigned short port, int payload_size, diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.h b/gnuradio-core/src/lib/io/gr_wavfile_sink.h index a1d6ed527..5fd3eaadc 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.h +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_GR_WAVFILE_SINK_H #define INCLUDED_GR_WAVFILE_SINK_H +#include #include #include #include @@ -36,7 +37,7 @@ typedef boost::shared_ptr gr_wavfile_sink_sptr; * \p sample_rate Sample rate [S/s] * \p bits_per_sample 16 or 8 bit, default is 16 */ -gr_wavfile_sink_sptr +GR_CORE_API gr_wavfile_sink_sptr gr_make_wavfile_sink (const char *filename, int n_channels, unsigned int sample_rate, @@ -50,10 +51,10 @@ gr_make_wavfile_sink (const char *filename, * * \ingroup sink_blk */ -class gr_wavfile_sink : public gr_sync_block +class GR_CORE_API gr_wavfile_sink : public gr_sync_block { private: - friend gr_wavfile_sink_sptr gr_make_wavfile_sink (const char *filename, + friend GR_CORE_API gr_wavfile_sink_sptr gr_make_wavfile_sink (const char *filename, int n_channels, unsigned int sample_rate, int bits_per_sample); diff --git a/gnuradio-core/src/lib/io/gr_wavfile_source.h b/gnuradio-core/src/lib/io/gr_wavfile_source.h index e434a6b4c..b300f2808 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_source.h +++ b/gnuradio-core/src/lib/io/gr_wavfile_source.h @@ -23,13 +23,14 @@ #ifndef INCLUDED_GR_WAVFILE_SOURCE_H #define INCLUDED_GR_WAVFILE_SOURCE_H +#include #include #include // for FILE class gr_wavfile_source; typedef boost::shared_ptr gr_wavfile_source_sptr; -gr_wavfile_source_sptr +GR_CORE_API gr_wavfile_source_sptr gr_make_wavfile_source (const char *filename, bool repeat = false); /*! @@ -41,10 +42,10 @@ gr_make_wavfile_source (const char *filename, bool repeat = false); * \ingroup source_blk */ -class gr_wavfile_source : public gr_sync_block +class GR_CORE_API gr_wavfile_source : public gr_sync_block { private: - friend gr_wavfile_source_sptr gr_make_wavfile_source (const char *filename, + friend GR_CORE_API gr_wavfile_source_sptr gr_make_wavfile_source (const char *filename, bool repeat); gr_wavfile_source(const char *filename, bool repeat); diff --git a/gnuradio-core/src/lib/io/gri_wavfile.h b/gnuradio-core/src/lib/io/gri_wavfile.h index 2c7c1207c..2268474fb 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.h +++ b/gnuradio-core/src/lib/io/gri_wavfile.h @@ -23,6 +23,7 @@ // This file stores all the RIFF file type knowledge for the gr_wavfile_* // blocks. +#include #include /*! diff --git a/gnuradio-core/src/lib/io/i2c.h b/gnuradio-core/src/lib/io/i2c.h index e959f59a8..7d446dfa3 100644 --- a/gnuradio-core/src/lib/io/i2c.h +++ b/gnuradio-core/src/lib/io/i2c.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_I2C_H #define INCLUDED_I2C_H +#include #include class i2c; @@ -31,7 +32,7 @@ typedef boost::shared_ptr i2c_sptr; /*! * \brief abstract class for controlling i2c bus */ -class i2c { +class GR_CORE_API i2c { public: i2c () {} diff --git a/gnuradio-core/src/lib/io/i2c_bbio.h b/gnuradio-core/src/lib/io/i2c_bbio.h index c6b226e39..110a56555 100644 --- a/gnuradio-core/src/lib/io/i2c_bbio.h +++ b/gnuradio-core/src/lib/io/i2c_bbio.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_I2C_BBIO_H #define INCLUDED_I2C_BBIO_H +#include #include class i2c_bbio; @@ -33,7 +34,7 @@ typedef boost::shared_ptr i2c_bbio_sptr; * \brief abstract class that implements bit banging i/o for i2c bus. * \ingroup base */ -class i2c_bbio { +class GR_CORE_API i2c_bbio { public: i2c_bbio () {} diff --git a/gnuradio-core/src/lib/io/i2c_bbio_pp.h b/gnuradio-core/src/lib/io/i2c_bbio_pp.h index 5a99cdcd1..4a311a2c9 100644 --- a/gnuradio-core/src/lib/io/i2c_bbio_pp.h +++ b/gnuradio-core/src/lib/io/i2c_bbio_pp.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_I2C_BBIO_PP_H #define INCLUDED_I2C_BBIO_PP_H +#include #include "i2c_bbio.h" #include "ppio.h" @@ -33,8 +34,8 @@ * This class talks to the i2c bus on the microtune eval board using * the parallel port. This works for both the 4937 and 4702 boards. */ -class i2c_bbio_pp : public i2c_bbio { - friend i2c_bbio_sptr make_i2c_bbio_pp (ppio_sptr pp); +class GR_CORE_API i2c_bbio_pp : public i2c_bbio { + friend GR_CORE_API i2c_bbio_sptr make_i2c_bbio_pp (ppio_sptr pp); i2c_bbio_pp (ppio_sptr pp); public: @@ -50,7 +51,7 @@ class i2c_bbio_pp : public i2c_bbio { ppio_sptr d_pp; }; -i2c_bbio_sptr make_i2c_bbio_pp (ppio_sptr pp); +GR_CORE_API i2c_bbio_sptr make_i2c_bbio_pp (ppio_sptr pp); #endif /* INCLUDED_I2C_BBIO_PP_H */ diff --git a/gnuradio-core/src/lib/io/i2c_bitbang.h b/gnuradio-core/src/lib/io/i2c_bitbang.h index c9deb38ba..feb23b787 100644 --- a/gnuradio-core/src/lib/io/i2c_bitbang.h +++ b/gnuradio-core/src/lib/io/i2c_bitbang.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_I2C_BITBANG_H #define INCLUDED_I2C_BITBANG_H +#include #include #include @@ -30,8 +31,8 @@ * \brief class for controlling i2c bus * \ingroup base */ -class i2c_bitbang : public i2c { - friend i2c_sptr make_i2c_bitbang (i2c_bbio_sptr io); +class GR_CORE_API i2c_bitbang : public i2c { + friend GR_CORE_API i2c_sptr make_i2c_bitbang (i2c_bbio_sptr io); i2c_bitbang (i2c_bbio_sptr io); public: @@ -57,7 +58,7 @@ private: i2c_bbio_sptr d_io; }; -i2c_sptr make_i2c_bitbang (i2c_bbio_sptr io); +GR_CORE_API i2c_sptr make_i2c_bitbang (i2c_bbio_sptr io); #endif /* INCLUDED_I2C_BITBANG_H */ diff --git a/gnuradio-core/src/lib/io/microtune_4702.h b/gnuradio-core/src/lib/io/microtune_4702.h index 95c64abe7..fd8d89305 100644 --- a/gnuradio-core/src/lib/io/microtune_4702.h +++ b/gnuradio-core/src/lib/io/microtune_4702.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_MICROTUNE_4702_H #define INCLUDED_MICROTUNE_4702_H +#include #include /*! @@ -30,7 +31,7 @@ * \ingroup hardware */ -class microtune_4702 : public microtune_xxxx { +class GR_CORE_API microtune_4702 : public microtune_xxxx { public: microtune_4702 (i2c_sptr i2c, int i2c_addr); diff --git a/gnuradio-core/src/lib/io/microtune_4702_eval_board.h b/gnuradio-core/src/lib/io/microtune_4702_eval_board.h index 6e9726917..e3c07fdf9 100644 --- a/gnuradio-core/src/lib/io/microtune_4702_eval_board.h +++ b/gnuradio-core/src/lib/io/microtune_4702_eval_board.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_MICROTUNE_4702_EVAL_BOARD_H #define INCLUDED_MICROTUNE_4702_EVAL_BOARD_H +#include #include "microtune_xxxx_eval_board.h" /*! @@ -30,7 +31,7 @@ * \ingroup hardware */ -class microtune_4702_eval_board : public microtune_xxxx_eval_board { +class GR_CORE_API microtune_4702_eval_board : public microtune_xxxx_eval_board { public: microtune_4702_eval_board (int which_pp = 0); ~microtune_4702_eval_board (); diff --git a/gnuradio-core/src/lib/io/microtune_4937.h b/gnuradio-core/src/lib/io/microtune_4937.h index b263ceb0f..bc8a26c64 100644 --- a/gnuradio-core/src/lib/io/microtune_4937.h +++ b/gnuradio-core/src/lib/io/microtune_4937.h @@ -23,13 +23,14 @@ #ifndef INCLUDED_MICROTUNE_4937_H #define INCLUDED_MICROTUNE_4937_H +#include #include /*! * \brief class for controlling microtune 4937 tuner module * \ingroup hardware */ -class microtune_4937 : public microtune_xxxx { +class GR_CORE_API microtune_4937 : public microtune_xxxx { public: microtune_4937 (i2c_sptr i2c, int i2c_addr = 0x61); virtual ~microtune_4937 (); diff --git a/gnuradio-core/src/lib/io/microtune_4937_eval_board.h b/gnuradio-core/src/lib/io/microtune_4937_eval_board.h index 154a7281a..09c00d116 100644 --- a/gnuradio-core/src/lib/io/microtune_4937_eval_board.h +++ b/gnuradio-core/src/lib/io/microtune_4937_eval_board.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_MICROTUNE_4937_EVAL_BOARD_H #define INCLUDED_MICROTUNE_4937_EVAL_BOARD_H +#include #include "microtune_xxxx_eval_board.h" /*! @@ -30,7 +31,7 @@ * \ingroup hardware */ -class microtune_4937_eval_board : public microtune_xxxx_eval_board { +class GR_CORE_API microtune_4937_eval_board : public microtune_xxxx_eval_board { public: microtune_4937_eval_board (int which_pp = 0); ~microtune_4937_eval_board (); diff --git a/gnuradio-core/src/lib/io/microtune_xxxx.h b/gnuradio-core/src/lib/io/microtune_xxxx.h index 4d5074a85..8b6ec25aa 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx.h +++ b/gnuradio-core/src/lib/io/microtune_xxxx.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_MICROTUNE_XXXX_H #define INCLUDED_MICROTUNE_XXXX_H +#include #include class i2c; @@ -32,7 +33,7 @@ typedef boost::shared_ptr i2c_sptr; * \brief abstract class for controlling microtune {4937,4702} tuner modules * \ingroup base */ -class microtune_xxxx { +class GR_CORE_API microtune_xxxx { public: microtune_xxxx () {} virtual ~microtune_xxxx (); diff --git a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h index 808075e55..08aa438c0 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h +++ b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_MICROTUNE_XXXX_EVAL_BOARD_H #define INCLUDED_MICROTUNE_XXXX_EVAL_BOARD_H +#include #include class microtune_xxxx; @@ -37,7 +38,7 @@ typedef boost::shared_ptr i2c_sptr; * \brief abstract class for controlling microtune xxxx eval board * \ingroup hardware */ -class microtune_xxxx_eval_board { +class GR_CORE_API microtune_xxxx_eval_board { public: microtune_xxxx_eval_board (int which_pp = 0); virtual ~microtune_xxxx_eval_board (); diff --git a/gnuradio-core/src/lib/io/ppio.h b/gnuradio-core/src/lib/io/ppio.h index e1a62e2a3..f7d14d52e 100644 --- a/gnuradio-core/src/lib/io/ppio.h +++ b/gnuradio-core/src/lib/io/ppio.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_PPIO_H #define INCLUDED_PPIO_H +#include #include class ppio; @@ -34,7 +35,7 @@ typedef boost::shared_ptr ppio_sptr; * \ingroup hardware */ -class ppio { +class GR_CORE_API ppio { public: ppio () {} virtual ~ppio (); @@ -55,7 +56,7 @@ class ppio { * Split out from class to make life easier for SWIG */ -ppio_sptr make_ppio (int which_pp); +GR_CORE_API ppio_sptr make_ppio (int which_pp); #endif /* INCLUDED_PPIO_H */ diff --git a/gnuradio-core/src/lib/io/ppio_ppdev.h b/gnuradio-core/src/lib/io/ppio_ppdev.h index b5abe3f0a..5d082d784 100644 --- a/gnuradio-core/src/lib/io/ppio_ppdev.h +++ b/gnuradio-core/src/lib/io/ppio_ppdev.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_PPIO_PPDEV_H #define INCLUDED_PPIO_PPDEV_H +#include #include class ppio_ppdev; @@ -33,8 +34,8 @@ typedef boost::shared_ptr ppio_ppdev_sptr; * \ingroup hardware */ -class ppio_ppdev : public ppio { - friend ppio_ppdev_sptr make_ppio_ppdev (int which = 0); +class GR_CORE_API ppio_ppdev : public ppio { + friend GR_CORE_API ppio_ppdev_sptr make_ppio_ppdev (int which = 0); ppio_ppdev (int which = 0); public: diff --git a/gnuradio-core/src/lib/io/sdr_1000.h b/gnuradio-core/src/lib/io/sdr_1000.h index 113e85deb..6647fbba5 100644 --- a/gnuradio-core/src/lib/io/sdr_1000.h +++ b/gnuradio-core/src/lib/io/sdr_1000.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_SDR_1000_H #define INCLUDED_SDR_1000_H +#include #include class ppio; @@ -36,7 +37,7 @@ enum { L_EXT = 0, L_BAND = 1, L_DDS0 = 2, L_DDS1 = 3 }; * \sa sdr_1000.py for a higher level interface. * \ingroup hardware */ -class sdr_1000_base { +class GR_CORE_API sdr_1000_base { ppio_sptr d_ppio; int d_shadow[4]; // shadow latches -- cgit From accb9f2fe8fd8f6a1e114adac5b15304b0e0012d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 20 Jul 2011 19:04:32 -0700 Subject: gr: squashed cmakelists.txt into one commit --- gnuradio-core/src/lib/io/CMakeLists.txt | 108 ++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 gnuradio-core/src/lib/io/CMakeLists.txt (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/CMakeLists.txt b/gnuradio-core/src/lib/io/CMakeLists.txt new file mode 100644 index 000000000..7ffe8306e --- /dev/null +++ b/gnuradio-core/src/lib/io/CMakeLists.txt @@ -0,0 +1,108 @@ +# Copyright 2010-2011 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, +# Boston, MA 02110-1301, USA. + +######################################################################## +# This file included, use CMake directory variables +######################################################################## + +######################################################################## +# Append gnuradio-core library sources +######################################################################## +LIST(APPEND gnuradio_core_sources + ${CMAKE_CURRENT_SOURCE_DIR}/gr_histo_sink_f.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_oscope_guts.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_oscope_sink_f.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_oscope_sink_x.cc + ${CMAKE_CURRENT_SOURCE_DIR}/i2c.cc + ${CMAKE_CURRENT_SOURCE_DIR}/i2c_bitbang.cc + ${CMAKE_CURRENT_SOURCE_DIR}/i2c_bbio.cc + ${CMAKE_CURRENT_SOURCE_DIR}/i2c_bbio_pp.cc + ${CMAKE_CURRENT_SOURCE_DIR}/microtune_4702.cc + ${CMAKE_CURRENT_SOURCE_DIR}/microtune_4937.cc + ${CMAKE_CURRENT_SOURCE_DIR}/microtune_xxxx.cc + ${CMAKE_CURRENT_SOURCE_DIR}/ppio_ppdev.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gri_wavfile.cc +) + +######################################################################## +# Install runtime headers +######################################################################## +INSTALL(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/gr_histo_sink_f.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_oscope_guts.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_oscope_sink_f.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_oscope_sink_x.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_trigger_mode.h + ${CMAKE_CURRENT_SOURCE_DIR}/i2c.h + ${CMAKE_CURRENT_SOURCE_DIR}/i2c_bitbang.h + ${CMAKE_CURRENT_SOURCE_DIR}/i2c_bbio.h + ${CMAKE_CURRENT_SOURCE_DIR}/i2c_bbio_pp.h + ${CMAKE_CURRENT_SOURCE_DIR}/microtune_4702.h + ${CMAKE_CURRENT_SOURCE_DIR}/microtune_4937.h + ${CMAKE_CURRENT_SOURCE_DIR}/microtune_eval_board_defs.h + ${CMAKE_CURRENT_SOURCE_DIR}/microtune_xxxx.h + ${CMAKE_CURRENT_SOURCE_DIR}/ppio_ppdev.h + ${CMAKE_CURRENT_SOURCE_DIR}/gri_wavfile.h + DESTINATION ${GR_INCLUDE_DIR}/gnuradio + COMPONENT "core_devel" +) + +######################################################################## +# Install swig headers +######################################################################## +IF(ENABLE_PYTHON) +INSTALL(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/io.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_histo_sink.i + ${CMAKE_CURRENT_SOURCE_DIR}/gr_oscope_sink.i + DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig + COMPONENT "core_swig" +) +ENDIF(ENABLE_PYTHON) + +######################################################################## +# Handle triple-threat files that have cc, h, and i +######################################################################## +SET(gr_core_io_triple_threats + gr_file_sink + gr_file_sink_base + gr_file_source + gr_file_descriptor_sink + gr_file_descriptor_source + gr_message_sink + gr_message_source + microtune_xxxx_eval_board + microtune_4702_eval_board + microtune_4937_eval_board + ppio + sdr_1000 + gr_udp_sink + gr_udp_source + gr_wavfile_source + gr_wavfile_sink + gr_tagged_file_sink +) + +FOREACH(file_tt ${gr_core_io_triple_threats}) + LIST(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/${file_tt}.cc) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${file_tt}.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio COMPONENT "core_devel") + IF(ENABLE_PYTHON) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${file_tt}.i DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig COMPONENT "core_swig") + ENDIF(ENABLE_PYTHON) +ENDFOREACH(file_tt ${gr_core_io_triple_threats}) -- cgit From e4c4e9c9567e669b78b145975daa0c1ad00182ca Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 9 Jul 2011 19:30:40 -0700 Subject: core: added missing config.h includes on cc files Added to the cc files which were missing config.h and required compatibility functions defined in config.h. Applies to compiling under MSVC with cmake work branch. --- gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc index 668f04cad..14f2b8589 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc +++ b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc @@ -20,6 +20,10 @@ * Boston, MA 02110-1301, USA. */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include "microtune_xxxx_eval_board.h" #include "microtune_eval_board_defs.h" #include "microtune_xxxx.h" -- cgit From 12719c3632c5c09e759aa9ad9baaa95f672cee46 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 9 Jul 2011 19:39:30 -0700 Subject: core: added missing io.h includes on cc files Added to the cc files which were missing io.h and required compatibility declarations in io.h to compile. Applies to compiling under MSVC with cmake work branch. --- gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc | 3 +++ gnuradio-core/src/lib/io/gr_file_descriptor_source.cc | 3 +++ gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 4 ++++ 3 files changed, 10 insertions(+) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc index 09fb6c826..11e0a8eb9 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc @@ -34,6 +34,9 @@ #include #include +#ifdef HAVE_IO_H +#include +#endif gr_file_descriptor_sink::gr_file_descriptor_sink (size_t itemsize, int fd) : gr_sync_block ("file_descriptor_sink", diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc b/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc index 700ad4aef..334a57848 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc @@ -35,6 +35,9 @@ #include #include +#ifdef HAVE_IO_H +#include +#endif gr_file_descriptor_source::gr_file_descriptor_source (size_t itemsize, int fd, diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index 154611c32..91618bad6 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -34,6 +34,10 @@ #include #include +#ifdef HAVE_IO_H +#include +#endif + #ifdef O_BINARY #define OUR_O_BINARY O_BINARY #else -- cgit From b623dff43ad12b7539184950074ba5b0ecbf34fb Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 26 Jul 2011 21:59:27 -0400 Subject: Fixed return warnings. --- gnuradio-core/src/lib/io/gri_wavfile.cc | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gri_wavfile.cc b/gnuradio-core/src/lib/io/gri_wavfile.cc index b8375edc2..8f1c6a2bb 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.cc +++ b/gnuradio-core/src/lib/io/gri_wavfile.cc @@ -160,25 +160,25 @@ gri_wavheader_parse(FILE *fp, return false; } - fread(&file_size, 1, 4, fp); + fresult = fread(&file_size, 1, 4, fp); fresult = fread(str_buf, 1, 8, fp); if (fresult != 8 || strncmp(str_buf, "WAVEfmt ", 8) || feof(fp)) { return false; } - fread(&fmt_hdr_skip, 1, 4, fp); + fresult = fread(&fmt_hdr_skip, 1, 4, fp); - fread(&compression_type, 1, 2, fp); + fresult = fread(&compression_type, 1, 2, fp); if (wav_to_host(compression_type) != VALID_COMPRESSION_TYPE) { return false; } - fread(&nchans, 1, 2, fp); - fread(&sample_rate, 1, 4, fp); - fread(&avg_bytes_per_sec, 1, 4, fp); - fread(&block_align, 1, 2, fp); - fread(&bits_per_sample, 1, 2, fp); + fresult = fread(&nchans, 1, 2, fp); + fresult = fread(&sample_rate, 1, 4, fp); + fresult = fread(&avg_bytes_per_sec, 1, 4, fp); + fresult = fread(&block_align, 1, 2, fp); + fresult = fread(&bits_per_sample, 1, 2, fp); if (ferror(fp)) { return false; @@ -204,7 +204,7 @@ gri_wavheader_parse(FILE *fp, return false; } - fread(&chunk_size, 1, 4, fp); + fresult = fread(&chunk_size, 1, 4, fp); if (ferror(fp)) { return false; } @@ -226,7 +226,9 @@ short int gri_wav_read_sample(FILE *fp, int bytes_per_sample) { int16_t buf = 0; - fread(&buf, bytes_per_sample, 1, fp); + size_t fresult; + + fresult = fread(&buf, bytes_per_sample, 1, fp); return (short) wav_to_host(buf); } -- cgit From 2c0a3dc882306e772ede8a69925c23227bfcaf96 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 9 Sep 2011 16:34:11 -0400 Subject: tags: fixed fwrite line for the right item size number. --- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index 91618bad6..67184b9c5 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -183,7 +183,8 @@ gr_tagged_file_sink::work (int noutput_items, //std::cout << "Found end of burst: " // << idx_stop << ", " << N << std::endl; - int count = fwrite (&inbuf[d_itemsize*idx], d_itemsize, idx_stop-idx, d_handle); + int count = fwrite (&inbuf[d_itemsize*idx], d_itemsize, + idx_stop-idx, d_handle); if (count == 0) { if(ferror(d_handle)) { perror("gr_tagged_file_sink: error writing file"); @@ -200,7 +201,8 @@ gr_tagged_file_sink::work (int noutput_items, } } if(d_state == IN_BURST) { - int count = fwrite (&inbuf[idx], d_itemsize, noutput_items-idx, d_handle); + int count = fwrite (&inbuf[d_itemsize*idx], d_itemsize, + noutput_items-idx, d_handle); if (count == 0) { if(ferror(d_handle)) { perror("gr_tagged_file_sink: error writing file"); -- cgit From 71c0f14a46f85027b95f2f5f6d3d219cc9e3783e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 8 Oct 2011 17:11:12 -0700 Subject: gr: the CMakeLists.txt took a chill pill --- gnuradio-core/src/lib/io/CMakeLists.txt | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/CMakeLists.txt b/gnuradio-core/src/lib/io/CMakeLists.txt index 7ffe8306e..af9d7583c 100644 --- a/gnuradio-core/src/lib/io/CMakeLists.txt +++ b/gnuradio-core/src/lib/io/CMakeLists.txt @@ -24,7 +24,7 @@ ######################################################################## # Append gnuradio-core library sources ######################################################################## -LIST(APPEND gnuradio_core_sources +list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/gr_histo_sink_f.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_oscope_guts.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_oscope_sink_f.cc @@ -43,7 +43,7 @@ LIST(APPEND gnuradio_core_sources ######################################################################## # Install runtime headers ######################################################################## -INSTALL(FILES +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gr_histo_sink_f.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_oscope_guts.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_oscope_sink_f.h @@ -66,20 +66,20 @@ INSTALL(FILES ######################################################################## # Install swig headers ######################################################################## -IF(ENABLE_PYTHON) -INSTALL(FILES +if(ENABLE_PYTHON) +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/io.i ${CMAKE_CURRENT_SOURCE_DIR}/gr_histo_sink.i ${CMAKE_CURRENT_SOURCE_DIR}/gr_oscope_sink.i DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig COMPONENT "core_swig" ) -ENDIF(ENABLE_PYTHON) +endif(ENABLE_PYTHON) ######################################################################## # Handle triple-threat files that have cc, h, and i ######################################################################## -SET(gr_core_io_triple_threats +set(gr_core_io_triple_threats gr_file_sink gr_file_sink_base gr_file_source @@ -99,10 +99,10 @@ SET(gr_core_io_triple_threats gr_tagged_file_sink ) -FOREACH(file_tt ${gr_core_io_triple_threats}) - LIST(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/${file_tt}.cc) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${file_tt}.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio COMPONENT "core_devel") - IF(ENABLE_PYTHON) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${file_tt}.i DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig COMPONENT "core_swig") - ENDIF(ENABLE_PYTHON) -ENDFOREACH(file_tt ${gr_core_io_triple_threats}) +foreach(file_tt ${gr_core_io_triple_threats}) + list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/${file_tt}.cc) + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${file_tt}.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio COMPONENT "core_devel") + if(ENABLE_PYTHON) + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${file_tt}.i DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig COMPONENT "core_swig") + endif(ENABLE_PYTHON) +endforeach(file_tt ${gr_core_io_triple_threats}) -- cgit From c1721c76bd67962a1d29e520dfea0789a14d0aa9 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 19 Oct 2011 13:35:46 -0700 Subject: tags: made tags object oriented --- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 27 ++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index 67184b9c5..4ac8c3512 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -32,7 +32,6 @@ #include #include #include -#include #ifdef HAVE_IO_H #include @@ -85,21 +84,21 @@ gr_tagged_file_sink::work (int noutput_items, pmt::pmt_t bkey = pmt::pmt_string_to_symbol("burst"); //pmt::pmt_t tkey = pmt::pmt_string_to_symbol("time"); // use gr_tags::key_time - std::vector all_tags; + std::vector all_tags; get_tags_in_range(all_tags, 0, start_N, end_N); - std::sort(all_tags.begin(), all_tags.end(), gr_tags::nitems_compare); + std::sort(all_tags.begin(), all_tags.end(), gr_tag_t::offset_compare); - std::vector::iterator vitr = all_tags.begin(); + std::vector::iterator vitr = all_tags.begin(); int idx = 0, idx_stop = 0; while(idx < noutput_items) { if(d_state == NOT_IN_BURST) { while(vitr != all_tags.end()) { - if((pmt::pmt_eqv(gr_tags::get_key(*vitr), bkey)) && - pmt::pmt_is_true(gr_tags::get_value(*vitr))) { + if((pmt::pmt_eqv((*vitr).key, bkey)) && + pmt::pmt_is_true((*vitr).value)) { - uint64_t N = gr_tags::get_nitems(*vitr); + uint64_t N = (*vitr).offset; idx = (int)(N - start_N); //std::cout << std::endl << "Found start of burst: " @@ -107,17 +106,17 @@ gr_tagged_file_sink::work (int noutput_items, // Find time burst occurred by getting latest time tag and extrapolating // to new time based on sample rate of this block. - std::vector time_tags; + std::vector time_tags; //get_tags_in_range(time_tags, 0, d_last_N, N, gr_tags::key_time); get_tags_in_range(time_tags, 0, d_last_N, N, pmt::pmt_string_to_symbol("time")); if(time_tags.size() > 0) { - pmt::pmt_t tag = time_tags[time_tags.size()-1]; + const gr_tag_t tag = time_tags[time_tags.size()-1]; - uint64_t time_nitems = gr_tags::get_nitems(tag); + uint64_t time_nitems = tag.offset; // Get time based on last time tag from USRP - pmt::pmt_t time = gr_tags::get_value(tag); + pmt::pmt_t time = tag.value; int tsecs = pmt::pmt_to_long(pmt::pmt_tuple_ref(time, 0)); double tfrac = pmt::pmt_to_double(pmt::pmt_tuple_ref(time, 1)); @@ -175,9 +174,9 @@ gr_tagged_file_sink::work (int noutput_items, } else { // In burst while(vitr != all_tags.end()) { - if((pmt::pmt_eqv(gr_tags::get_key(*vitr), bkey)) && - pmt::pmt_is_false(gr_tags::get_value(*vitr))) { - uint64_t N = gr_tags::get_nitems(*vitr); + if((pmt::pmt_eqv((*vitr).key, bkey)) && + pmt::pmt_is_false((*vitr).value)) { + uint64_t N = (*vitr).offset; idx_stop = (int)N - start_N; //std::cout << "Found end of burst: " -- cgit From 00420d32081d8252bb37142b2be19a8a7c4dc4c4 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Thu, 8 Dec 2011 13:48:48 -0800 Subject: Removed autotools, gr-waveform, some cleanup Nick Foster owes Nick Corgan a six-pack of beer! --- gnuradio-core/src/lib/io/.gitignore | 8 --- gnuradio-core/src/lib/io/Makefile.am | 116 ----------------------------------- 2 files changed, 124 deletions(-) delete mode 100644 gnuradio-core/src/lib/io/.gitignore delete mode 100644 gnuradio-core/src/lib/io/Makefile.am (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/.gitignore b/gnuradio-core/src/lib/io/.gitignore deleted file mode 100644 index a02b6ff73..000000000 --- a/gnuradio-core/src/lib/io/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -/Makefile -/Makefile.in -/.la -/.lo -/.deps -/.libs -/*.la -/*.lo diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am deleted file mode 100644 index 442d5e3a9..000000000 --- a/gnuradio-core/src/lib/io/Makefile.am +++ /dev/null @@ -1,116 +0,0 @@ -# -# Copyright 2001,2003,2004,2006,2007,2008 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, -# Boston, MA 02110-1301, USA. -# - -include $(top_srcdir)/Makefile.common - - -AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(WITH_INCLUDES) - -noinst_LTLIBRARIES = libio.la - - -libio_la_SOURCES = \ - gr_file_sink.cc \ - gr_file_sink_base.cc \ - gr_file_source.cc \ - gr_file_descriptor_sink.cc \ - gr_file_descriptor_source.cc \ - gr_histo_sink_f.cc \ - gr_message_sink.cc \ - gr_message_source.cc \ - gr_oscope_guts.cc \ - gr_oscope_sink_f.cc \ - gr_oscope_sink_x.cc \ - i2c.cc \ - i2c_bitbang.cc \ - i2c_bbio.cc \ - i2c_bbio_pp.cc \ - microtune_4702.cc \ - microtune_4937.cc \ - microtune_4702_eval_board.cc \ - microtune_4937_eval_board.cc \ - microtune_xxxx.cc \ - microtune_xxxx_eval_board.cc \ - ppio.cc \ - ppio_ppdev.cc \ - sdr_1000.cc \ - gr_udp_sink.cc \ - gr_udp_source.cc \ - gr_wavfile_sink.cc \ - gr_wavfile_source.cc \ - gri_wavfile.cc \ - gr_tagged_file_sink.cc - -grinclude_HEADERS = \ - gr_file_sink.h \ - gr_file_sink_base.h \ - gr_file_source.h \ - gr_file_descriptor_sink.h \ - gr_file_descriptor_source.h \ - gr_histo_sink_f.h \ - gr_message_sink.h \ - gr_message_source.h \ - gr_oscope_guts.h \ - gr_oscope_sink_f.h \ - gr_oscope_sink_x.h \ - gr_trigger_mode.h \ - i2c.h \ - i2c_bitbang.h \ - i2c_bbio.h \ - i2c_bbio_pp.h \ - microtune_4702.h \ - microtune_4937.h \ - microtune_4702_eval_board.h \ - microtune_4937_eval_board.h \ - microtune_eval_board_defs.h \ - microtune_xxxx.h \ - microtune_xxxx_eval_board.h \ - ppio.h \ - ppio_ppdev.h \ - sdr_1000.h \ - gr_udp_sink.h \ - gr_udp_source.h \ - gr_wavfile_source.h \ - gr_wavfile_sink.h \ - gri_wavfile.h \ - gr_tagged_file_sink.h - -swiginclude_HEADERS = \ - io.i \ - gr_file_sink.i \ - gr_file_sink_base.i \ - gr_file_source.i \ - gr_file_descriptor_sink.i \ - gr_file_descriptor_source.i \ - gr_histo_sink.i \ - gr_message_sink.i \ - gr_message_source.i \ - gr_oscope_sink.i \ - microtune_xxxx_eval_board.i \ - microtune_4702_eval_board.i \ - microtune_4937_eval_board.i \ - ppio.i \ - sdr_1000.i \ - gr_udp_sink.i \ - gr_udp_source.i \ - gr_wavfile_source.i \ - gr_wavfile_sink.i \ - gr_tagged_file_sink.i -- cgit From 73538627386205c25b87f7657ab6e8dd774f4cd3 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 13 Dec 2011 21:08:15 -0500 Subject: core: WAV sink is now threadsafe; do_update() therefore must be private. --- gnuradio-core/src/lib/io/gr_wavfile_sink.cc | 2 +- gnuradio-core/src/lib/io/gr_wavfile_sink.h | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc index a96aadc72..88b232343 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc @@ -184,6 +184,7 @@ gr_wavfile_sink::work (int noutput_items, int nwritten; + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this block do_update(); // update: d_fp is reqd if (!d_fp) // drop output on the floor return noutput_items; @@ -254,7 +255,6 @@ gr_wavfile_sink::do_update() return; } - gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this block if (d_fp) { close_wav(); } diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.h b/gnuradio-core/src/lib/io/gr_wavfile_sink.h index 5fd3eaadc..6a6b7ebf0 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.h +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.h @@ -85,6 +85,13 @@ private: */ short convert_to_short(float sample); + /*! + * \brief If any file changes have occurred, update now. This is called + * internally by work() and thus doesn't usually need to be called by + * hand. + */ + void do_update(); + /*! * \brief Writes information to the WAV header which is not available * a-priori (chunk size etc.) and closes the file. Not thread-safe and @@ -107,13 +114,6 @@ public: */ void close(); - /*! - * \brief If any file changes have occurred, update now. This is called - * internally by work() and thus doesn't usually need to be called by - * hand. - */ - void do_update(); - /*! * \brief Set the sample rate. This will not affect the WAV file * currently opened. Any following open() calls will use this new -- cgit From 2ed887b69a3b15840830998c4e6157176d427f60 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 31 Dec 2011 13:06:01 -0800 Subject: core: fix gr_udp_sink by including asio --- gnuradio-core/src/lib/io/gr_udp_sink.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index 36b4cbe36..9fc4da0ae 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -20,6 +20,8 @@ * Boston, MA 02110-1301, USA. */ +#include + #ifdef HAVE_CONFIG_H #include "config.h" #endif -- cgit From 2a2411a598c222e2ef82b857c0b53e0a9d1daf3f Mon Sep 17 00:00:00 2001 From: Marcus Leech Date: Sun, 15 Jan 2012 23:49:52 -0500 Subject: core: fix for off-by-one issue in strip chart. Increases buffer size for longer displays. --- gnuradio-core/src/lib/io/gr_oscope_guts.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.cc b/gnuradio-core/src/lib/io/gr_oscope_guts.cc index ce7feca13..f1bdeb9c1 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.cc @@ -31,8 +31,7 @@ #include #include -static const int OUTPUT_RECORD_SIZE = 2048; // must be power of 2 - +static const int OUTPUT_RECORD_SIZE = 16384; // Must be power of 2 static inline int wrap_bi (int buffer_index) // wrap buffer index { @@ -139,7 +138,7 @@ gr_oscope_guts::process_sample (const float *channel_data) { for (int i = 0; i < d_nchannels; i++) { - for (int j = OUTPUT_RECORD_SIZE-1; j >= 0; j--) + for (int j = OUTPUT_RECORD_SIZE-1; j > 0; j--) { d_buffer[i][j] = d_buffer[i][j-1]; } -- cgit From e9ba60e518193ddcbfb069270bb674b4e7964f25 Mon Sep 17 00:00:00 2001 From: Marcus Leech Date: Sun, 15 Jan 2012 23:49:52 -0500 Subject: core: fix for off-by-one issue in strip chart. Increases buffer size for longer displays. --- gnuradio-core/src/lib/io/gr_oscope_guts.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.cc b/gnuradio-core/src/lib/io/gr_oscope_guts.cc index ce7feca13..f1bdeb9c1 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.cc @@ -31,8 +31,7 @@ #include #include -static const int OUTPUT_RECORD_SIZE = 2048; // must be power of 2 - +static const int OUTPUT_RECORD_SIZE = 16384; // Must be power of 2 static inline int wrap_bi (int buffer_index) // wrap buffer index { @@ -139,7 +138,7 @@ gr_oscope_guts::process_sample (const float *channel_data) { for (int i = 0; i < d_nchannels; i++) { - for (int j = OUTPUT_RECORD_SIZE-1; j >= 0; j--) + for (int j = OUTPUT_RECORD_SIZE-1; j > 0; j--) { d_buffer[i][j] = d_buffer[i][j-1]; } -- cgit From d6126a670383791dc8e24926b0d84e1c1fbefdac Mon Sep 17 00:00:00 2001 From: Marcus Leech Date: Mon, 6 Feb 2012 10:45:07 -0500 Subject: io: fix triggering and performance issues with oscope; specifically for the strip-chart features. --- gnuradio-core/src/lib/io/gr_oscope_guts.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.cc b/gnuradio-core/src/lib/io/gr_oscope_guts.cc index f1bdeb9c1..7bdc53ab0 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.cc @@ -31,7 +31,7 @@ #include #include -static const int OUTPUT_RECORD_SIZE = 16384; // Must be power of 2 +static const int OUTPUT_RECORD_SIZE = 8192; // Must be power of 2 static inline int wrap_bi (int buffer_index) // wrap buffer index { @@ -144,6 +144,7 @@ gr_oscope_guts::process_sample (const float *channel_data) } d_buffer[i][0] = channel_data[i]; } + d_trigger_off = 0; write_output_records(); } } -- cgit From 35b689eb88a3534025848054d629c0bb368b66f0 Mon Sep 17 00:00:00 2001 From: Marcus Leech Date: Mon, 6 Feb 2012 22:23:06 -0500 Subject: gui: better handling of buffers in oscope for stripchart/non-stripchart. --- gnuradio-core/src/lib/io/gr_oscope_guts.cc | 64 +++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 18 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.cc b/gnuradio-core/src/lib/io/gr_oscope_guts.cc index 7bdc53ab0..8b0d1e632 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.cc @@ -31,23 +31,36 @@ #include #include -static const int OUTPUT_RECORD_SIZE = 8192; // Must be power of 2 +/* + * Bad performance if it's large, and flaky triggering if it's too small + */ +static const int OUTPUT_RECORD_SIZE = 1024; // Must be power of 2 + +/* + * For (slow-updated) STRIPCHART triggering, we make the record size larger, since we + * potentially want to be able to "see" hours of data. This works as long as the + * update rates to a STRIPCHART are low, which they generally are--that's rather what + * a stripchart is all about! + */ +static const int SCHART_MULT = 8; + + static inline int -wrap_bi (int buffer_index) // wrap buffer index +wrap_bi (int buffer_index, int mx) // wrap buffer index { - return buffer_index & (OUTPUT_RECORD_SIZE - 1); + return buffer_index & (mx - 1); } static inline int -incr_bi (int buffer_index) // increment buffer index +incr_bi (int buffer_index, int mx) // increment buffer index { - return wrap_bi (buffer_index + 1); + return wrap_bi (buffer_index + 1, mx); } static inline int -decr_bi (int buffer_index) // decrement buffer index +decr_bi (int buffer_index, int mx) // decrement buffer index { - return wrap_bi (buffer_index - 1); + return wrap_bi (buffer_index - 1, mx); } gr_oscope_guts::gr_oscope_guts (double sample_rate, gr_msg_queue_sptr msgq) @@ -73,8 +86,8 @@ gr_oscope_guts::gr_oscope_guts (double sample_rate, gr_msg_queue_sptr msgq) d_buffer[i] = 0; for (int i = 0; i < MAX_CHANNELS; i++){ - d_buffer[i] = new float [OUTPUT_RECORD_SIZE]; - for (int j = 0; j < OUTPUT_RECORD_SIZE; j++) + d_buffer[i] = new float [OUTPUT_RECORD_SIZE*SCHART_MULT]; + for (int j = 0; j < OUTPUT_RECORD_SIZE*SCHART_MULT; j++) d_buffer[i][j] = 0.0; } @@ -132,13 +145,13 @@ gr_oscope_guts::process_sample (const float *channel_data) assert (0); } - d_obi = incr_bi (d_obi); + d_obi = incr_bi (d_obi, OUTPUT_RECORD_SIZE); } else { for (int i = 0; i < d_nchannels; i++) { - for (int j = OUTPUT_RECORD_SIZE-1; j > 0; j--) + for (int j = (OUTPUT_RECORD_SIZE*SCHART_MULT)-1; j > 0; j--) { d_buffer[i][j] = d_buffer[i][j-1]; } @@ -183,7 +196,10 @@ gr_oscope_guts::enter_post_trigger () bool gr_oscope_guts::found_trigger () { - float prev_sample = d_buffer[d_trigger_channel][decr_bi(d_obi)]; + int mx = d_trigger_mode == gr_TRIG_MODE_STRIPCHART ? OUTPUT_RECORD_SIZE*SCHART_MULT : + OUTPUT_RECORD_SIZE; + + float prev_sample = d_buffer[d_trigger_channel][decr_bi(d_obi, mx)]; float new_sample = d_buffer[d_trigger_channel][d_obi]; switch (d_trigger_mode){ @@ -224,6 +240,11 @@ gr_oscope_guts::found_trigger () void gr_oscope_guts::write_output_records () { + int mx; + + mx = d_trigger_mode == gr_TRIG_MODE_STRIPCHART ? + OUTPUT_RECORD_SIZE*SCHART_MULT : OUTPUT_RECORD_SIZE; + // if the output queue if full, drop the data like its hot. if (d_msgq->full_p()) return; @@ -231,17 +252,17 @@ gr_oscope_guts::write_output_records () gr_message_sptr msg = gr_make_message(0, // msg type d_nchannels, // arg1 for other side - OUTPUT_RECORD_SIZE, // arg2 for other side - ((d_nchannels * OUTPUT_RECORD_SIZE) + 1) * sizeof(float)); // sizeof payload + mx, // arg2 for other side + ((d_nchannels * mx) + 1) * sizeof(float)); // sizeof payload float *out = (float *)msg->msg(); // get pointer to raw message buffer for (int ch = 0; ch < d_nchannels; ch++){ // note that d_obi + 1 points at the oldest sample in the buffer - for (int i = 0; i < OUTPUT_RECORD_SIZE; i++){ - out[i] = d_buffer[ch][wrap_bi(d_obi + 1 + i)]; + for (int i = 0; i < mx; i++){ + out[i] = d_buffer[ch][wrap_bi(d_obi + 1 + i, mx)]; } - out += OUTPUT_RECORD_SIZE; + out += mx; } //Set the last sample as the trigger offset: // The non gl scope sink will not look at this last sample. @@ -405,5 +426,12 @@ gr_oscope_guts::get_trigger_level () const int gr_oscope_guts::get_samples_per_output_record () const { - return OUTPUT_RECORD_SIZE; + int mx; + + mx = OUTPUT_RECORD_SIZE; + if (d_trigger_mode == gr_TRIG_MODE_STRIPCHART) + { + mx = OUTPUT_RECORD_SIZE*SCHART_MULT; + } + return mx; } -- cgit From c774e6efb5f715c5f8b5f20bd8dea0051da667fd Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 27 Mar 2012 22:04:44 -0400 Subject: doc: fix documentation for wavsink (thanks to John Coppens for point it out). --- gnuradio-core/src/lib/io/gr_wavfile_sink.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.h b/gnuradio-core/src/lib/io/gr_wavfile_sink.h index 5fd3eaadc..348f789ae 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.h +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.h @@ -44,10 +44,10 @@ gr_make_wavfile_sink (const char *filename, int bits_per_sample = 16); /*! - * \brief Read stream from a Microsoft PCM (.wav) file, output floats + * \brief Write stream to a Microsoft PCM (.wav) file. * - * Values are within [-1;1]. - * Check gr_make_wavfile_source() for extra info. + * Values must be floats within [-1;1]. + * Check gr_make_wavfile_sink() for extra info. * * \ingroup sink_blk */ -- cgit From 2bf64459036916258dcf3269cec47904fdeba8f6 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 1 Apr 2012 16:13:42 -0400 Subject: Removes all references to guile and scheme, which are no longer needed. The remaining pmt_serial_tags.scm is parsed by Python already. Future modifications could change this format to not confuse the point. --- gnuradio-core/src/lib/io/gr_message_source.i | 8 -------- 1 file changed, 8 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_message_source.i b/gnuradio-core/src/lib/io/gr_message_source.i index e4e2016d0..8a9c762d0 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.i +++ b/gnuradio-core/src/lib/io/gr_message_source.i @@ -22,14 +22,6 @@ GR_SWIG_BLOCK_MAGIC(gr,message_source); -#ifdef SWIGGUILE -// Rename these. Without this, the primitive bindings are OK, but the -// goops bindings try to create a bogus generic-function... -// See core.scm for the second part of the workaround. -%rename(message_source_limit_ctor) gr_make_message_source(size_t itemsize, int msgq_limit); -%rename(message_source_msgq_ctor) gr_make_message_source(size_t itemsize, gr_msg_queue_sptr msgq); -#endif - gr_message_source_sptr gr_make_message_source (size_t itemsize, int msgq_limit=0); gr_message_source_sptr gr_make_message_source (size_t itemsize, gr_msg_queue_sptr msgq); -- 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. --- .../src/lib/io/gr_file_descriptor_sink.cc | 10 ++--- gnuradio-core/src/lib/io/gr_file_descriptor_sink.h | 8 ++-- gnuradio-core/src/lib/io/gr_file_descriptor_sink.i | 10 ++--- .../src/lib/io/gr_file_descriptor_source.cc | 12 ++--- .../src/lib/io/gr_file_descriptor_source.h | 8 ++-- .../src/lib/io/gr_file_descriptor_source.i | 10 ++--- gnuradio-core/src/lib/io/gr_file_sink.cc | 14 +++--- gnuradio-core/src/lib/io/gr_file_sink.h | 8 ++-- gnuradio-core/src/lib/io/gr_file_sink.i | 12 ++--- gnuradio-core/src/lib/io/gr_file_sink_base.cc | 10 ++--- gnuradio-core/src/lib/io/gr_file_sink_base.h | 14 +++--- gnuradio-core/src/lib/io/gr_file_sink_base.i | 12 ++--- gnuradio-core/src/lib/io/gr_file_source.cc | 14 +++--- gnuradio-core/src/lib/io/gr_file_source.h | 8 ++-- gnuradio-core/src/lib/io/gr_file_source.i | 10 ++--- gnuradio-core/src/lib/io/gr_histo_sink.i | 8 ++-- gnuradio-core/src/lib/io/gr_message_sink.cc | 10 ++--- gnuradio-core/src/lib/io/gr_message_sink.h | 8 ++-- gnuradio-core/src/lib/io/gr_message_sink.i | 8 ++-- gnuradio-core/src/lib/io/gr_message_source.cc | 8 ++-- gnuradio-core/src/lib/io/gr_message_source.h | 8 ++-- gnuradio-core/src/lib/io/gr_message_source.i | 8 ++-- gnuradio-core/src/lib/io/gr_oscope_guts.cc | 24 +++++----- gnuradio-core/src/lib/io/gr_oscope_guts.h | 10 ++--- gnuradio-core/src/lib/io/gr_oscope_sink.i | 8 ++-- gnuradio-core/src/lib/io/gr_oscope_sink_f.cc | 10 ++--- gnuradio-core/src/lib/io/gr_oscope_sink_f.h | 8 ++-- gnuradio-core/src/lib/io/gr_oscope_sink_x.cc | 8 ++-- gnuradio-core/src/lib/io/gr_oscope_sink_x.h | 12 ++--- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 20 ++++----- gnuradio-core/src/lib/io/gr_tagged_file_sink.h | 8 ++-- gnuradio-core/src/lib/io/gr_tagged_file_sink.i | 10 ++--- gnuradio-core/src/lib/io/gr_trigger_mode.h | 8 ++-- gnuradio-core/src/lib/io/gr_udp_sink.cc | 20 ++++----- gnuradio-core/src/lib/io/gr_udp_sink.h | 20 ++++----- gnuradio-core/src/lib/io/gr_udp_sink.i | 16 +++---- gnuradio-core/src/lib/io/gr_udp_source.cc | 34 +++++++------- gnuradio-core/src/lib/io/gr_udp_source.h | 16 +++---- gnuradio-core/src/lib/io/gr_udp_source.i | 14 +++--- gnuradio-core/src/lib/io/gr_wavfile_sink.cc | 40 ++++++++--------- gnuradio-core/src/lib/io/gr_wavfile_sink.h | 20 ++++----- gnuradio-core/src/lib/io/gr_wavfile_sink.i | 2 +- gnuradio-core/src/lib/io/gr_wavfile_source.cc | 8 ++-- gnuradio-core/src/lib/io/gr_wavfile_source.h | 16 +++---- gnuradio-core/src/lib/io/gri_wavfile.cc | 52 +++++++++++----------- gnuradio-core/src/lib/io/gri_wavfile.h | 2 +- gnuradio-core/src/lib/io/i2c.cc | 8 ++-- gnuradio-core/src/lib/io/i2c.h | 12 ++--- gnuradio-core/src/lib/io/i2c_bbio.cc | 8 ++-- gnuradio-core/src/lib/io/i2c_bbio.h | 10 ++--- gnuradio-core/src/lib/io/i2c_bbio_pp.cc | 8 ++-- gnuradio-core/src/lib/io/i2c_bbio_pp.h | 8 ++-- gnuradio-core/src/lib/io/i2c_bitbang.cc | 20 ++++----- gnuradio-core/src/lib/io/i2c_bitbang.h | 12 ++--- gnuradio-core/src/lib/io/io.i | 8 ++-- gnuradio-core/src/lib/io/microtune_4702.cc | 6 +-- gnuradio-core/src/lib/io/microtune_4702.h | 10 ++--- .../src/lib/io/microtune_4702_eval_board.h | 8 ++-- .../src/lib/io/microtune_4702_eval_board.i | 8 ++-- gnuradio-core/src/lib/io/microtune_4937.cc | 12 ++--- gnuradio-core/src/lib/io/microtune_4937.h | 12 ++--- .../src/lib/io/microtune_4937_eval_board.cc | 8 ++-- .../src/lib/io/microtune_4937_eval_board.h | 8 ++-- .../src/lib/io/microtune_4937_eval_board.i | 8 ++-- gnuradio-core/src/lib/io/microtune_eval_board.i | 12 ++--- .../src/lib/io/microtune_eval_board_defs.h | 8 ++-- gnuradio-core/src/lib/io/microtune_xxxx.cc | 10 ++--- gnuradio-core/src/lib/io/microtune_xxxx.h | 12 ++--- .../src/lib/io/microtune_xxxx_eval_board.cc | 18 ++++---- .../src/lib/io/microtune_xxxx_eval_board.h | 14 +++--- .../src/lib/io/microtune_xxxx_eval_board.i | 10 ++--- gnuradio-core/src/lib/io/ppio.cc | 8 ++-- gnuradio-core/src/lib/io/ppio.h | 10 ++--- gnuradio-core/src/lib/io/ppio.i | 8 ++-- gnuradio-core/src/lib/io/ppio_ppdev.cc | 20 ++++----- gnuradio-core/src/lib/io/ppio_ppdev.h | 8 ++-- gnuradio-core/src/lib/io/sdr_1000.cc | 12 ++--- gnuradio-core/src/lib/io/sdr_1000.h | 12 ++--- gnuradio-core/src/lib/io/sdr_1000.i | 8 ++-- 79 files changed, 474 insertions(+), 474 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc index 11e0a8eb9..099d46dbd 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,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, @@ -57,7 +57,7 @@ gr_file_descriptor_sink::~gr_file_descriptor_sink () close (d_fd); } -int +int gr_file_descriptor_sink::work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h index 5e4cc6505..3b1c1167f 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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, diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.i b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.i index 14c37f68e..2c256e44d 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_sink.i +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_sink.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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, @@ -22,7 +22,7 @@ GR_SWIG_BLOCK_MAGIC(gr,file_descriptor_sink) -gr_file_descriptor_sink_sptr +gr_file_descriptor_sink_sptr gr_make_file_descriptor_sink (size_t itemsize, int fd); class gr_file_descriptor_sink : public gr_sync_block diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc b/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc index 334a57848..a63abf96b 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_source.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,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 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, @@ -133,9 +133,9 @@ gr_file_descriptor_source::read_items (char *buf, int nitems) if (r == 0) // block until we get something return read_items (buf, nitems); - + return r; -} +} int gr_file_descriptor_source::handle_residue (char *buf, int nbytes_read) diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_source.h b/gnuradio-core/src/lib/io/gr_file_descriptor_source.h index fa513fd25..ebabd81ed 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_source.h +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_source.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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, diff --git a/gnuradio-core/src/lib/io/gr_file_descriptor_source.i b/gnuradio-core/src/lib/io/gr_file_descriptor_source.i index cee0b5765..3ca082522 100644 --- a/gnuradio-core/src/lib/io/gr_file_descriptor_source.i +++ b/gnuradio-core/src/lib/io/gr_file_descriptor_source.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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, @@ -22,7 +22,7 @@ GR_SWIG_BLOCK_MAGIC(gr,file_descriptor_source) -gr_file_descriptor_source_sptr +gr_file_descriptor_source_sptr gr_make_file_descriptor_source (size_t itemsize, int fd, bool repeat=false); class gr_file_descriptor_source : public gr_sync_block diff --git a/gnuradio-core/src/lib/io/gr_file_sink.cc b/gnuradio-core/src/lib/io/gr_file_sink.cc index aab0158e7..5d147fcfe 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,2006,2007,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, @@ -50,7 +50,7 @@ gr_file_sink::~gr_file_sink () { } -int +int gr_file_sink::work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) @@ -59,7 +59,7 @@ gr_file_sink::work (int noutput_items, int nwritten = 0; do_update(); // update d_fp is reqd - + if (!d_fp) return noutput_items; // drop output on the floor @@ -72,6 +72,6 @@ gr_file_sink::work (int noutput_items, } if (d_unbuffered) fflush (d_fp); - + return nwritten; } diff --git a/gnuradio-core/src/lib/io/gr_file_sink.h b/gnuradio-core/src/lib/io/gr_file_sink.h index 180cbef2a..e40ec9ab8 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_sink.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,2007 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, diff --git a/gnuradio-core/src/lib/io/gr_file_sink.i b/gnuradio-core/src/lib/io/gr_file_sink.i index 64260392c..47ab9e964 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.i +++ b/gnuradio-core/src/lib/io/gr_file_sink.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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, @@ -22,7 +22,7 @@ GR_SWIG_BLOCK_MAGIC(gr,file_sink) -gr_file_sink_sptr +gr_file_sink_sptr gr_make_file_sink (size_t itemsize, const char *filename); class gr_file_sink : public gr_sync_block, public gr_file_sink_base @@ -33,7 +33,7 @@ class gr_file_sink : public gr_sync_block, public gr_file_sink_base public: ~gr_file_sink (); - /*! + /*! * \brief open filename and begin output to it. */ bool open(const char *filename); diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.cc b/gnuradio-core/src/lib/io/gr_file_sink_base.cc index c43304b0d..b2dcc1be5 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,2006,2007,2009 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, @@ -117,7 +117,7 @@ gr_file_sink_base::do_update() d_new_fp = 0; d_updated = false; } -} +} void gr_file_sink_base::set_unbuffered(bool unbuffered) diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.h b/gnuradio-core/src/lib/io/gr_file_sink_base.h index 6765dbad8..8a70cee76 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.h +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,2007,2008 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, @@ -46,7 +46,7 @@ class GR_CORE_API gr_file_sink_base public: ~gr_file_sink_base(); - /*! + /*! * \brief Open filename and begin output to it. */ bool open(const char *filename); @@ -63,8 +63,8 @@ class GR_CORE_API gr_file_sink_base * \brief if we've had an update, do it now. */ void do_update(); - - + + /*! * \brief turn on unbuffered writes for slower outputs */ diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.i b/gnuradio-core/src/lib/io/gr_file_sink_base.i index ed4342482..993dba277 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.i +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.i @@ -1,24 +1,24 @@ /* -*- c++ -*- */ /* * Copyright 2006 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 this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -class gr_file_sink_base +class gr_file_sink_base { protected: gr_file_sink_base(const char *filename, bool is_binary); @@ -26,7 +26,7 @@ class gr_file_sink_base public: ~gr_file_sink_base(); - /*! + /*! * \brief Open filename and begin output to it. */ bool open(const char *filename); diff --git a/gnuradio-core/src/lib/io/gr_file_source.cc b/gnuradio-core/src/lib/io/gr_file_source.cc index d045e26b3..3f06a8244 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_source.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,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, @@ -56,7 +56,7 @@ gr_file_source::gr_file_source (size_t itemsize, const char *filename, bool repe d_itemsize (itemsize), d_fp (0), d_repeat (repeat) { // we use "open" to use to the O_LARGEFILE flag - + int fd; if ((fd = open (filename, O_RDONLY | OUR_O_LARGEFILE | OUR_O_BINARY)) < 0){ perror (filename); @@ -82,7 +82,7 @@ gr_file_source::~gr_file_source () fclose ((FILE *) d_fp); } -int +int gr_file_source::work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) @@ -93,7 +93,7 @@ gr_file_source::work (int noutput_items, while (size) { i = fread(o, d_itemsize, size, (FILE *) d_fp); - + size -= i; o += i * d_itemsize; diff --git a/gnuradio-core/src/lib/io/gr_file_source.h b/gnuradio-core/src/lib/io/gr_file_source.h index 6e8fc4074..1cc44a3b1 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.h +++ b/gnuradio-core/src/lib/io/gr_file_source.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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, diff --git a/gnuradio-core/src/lib/io/gr_file_source.i b/gnuradio-core/src/lib/io/gr_file_source.i index f538ea3ae..9bf44691d 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.i +++ b/gnuradio-core/src/lib/io/gr_file_source.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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, @@ -28,7 +28,7 @@ GR_SWIG_BLOCK_MAGIC(gr,file_source) -gr_file_source_sptr +gr_file_source_sptr gr_make_file_source (size_t itemsize, const char *filename, bool repeat=false); class gr_file_source : public gr_sync_block diff --git a/gnuradio-core/src/lib/io/gr_histo_sink.i b/gnuradio-core/src/lib/io/gr_histo_sink.i index 544d772fb..14079e190 100644 --- a/gnuradio-core/src/lib/io/gr_histo_sink.i +++ b/gnuradio-core/src/lib/io/gr_histo_sink.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2009 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, diff --git a/gnuradio-core/src/lib/io/gr_message_sink.cc b/gnuradio-core/src/lib/io/gr_message_sink.cc index 8881e97f4..ae0b5c764 100644 --- a/gnuradio-core/src/lib/io/gr_message_sink.cc +++ b/gnuradio-core/src/lib/io/gr_message_sink.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, @@ -37,7 +37,7 @@ // public constructor that returns a shared_ptr -gr_message_sink_sptr +gr_message_sink_sptr gr_make_message_sink (size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block) { return gnuradio::get_initial_sptr(new gr_message_sink(itemsize, msgq, dont_block)); diff --git a/gnuradio-core/src/lib/io/gr_message_sink.h b/gnuradio-core/src/lib/io/gr_message_sink.h index 180055261..84005694a 100644 --- a/gnuradio-core/src/lib/io/gr_message_sink.h +++ b/gnuradio-core/src/lib/io/gr_message_sink.h @@ -1,19 +1,19 @@ /* -*- 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 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, diff --git a/gnuradio-core/src/lib/io/gr_message_sink.i b/gnuradio-core/src/lib/io/gr_message_sink.i index a42cb7eca..8415cbd66 100644 --- a/gnuradio-core/src/lib/io/gr_message_sink.i +++ b/gnuradio-core/src/lib/io/gr_message_sink.i @@ -1,19 +1,19 @@ /* -*- 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 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, diff --git a/gnuradio-core/src/lib/io/gr_message_source.cc b/gnuradio-core/src/lib/io/gr_message_source.cc index 0fa24f2f9..fb3da89a8 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.cc +++ b/gnuradio-core/src/lib/io/gr_message_source.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, diff --git a/gnuradio-core/src/lib/io/gr_message_source.h b/gnuradio-core/src/lib/io/gr_message_source.h index 16a0f4474..c510d1775 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.h +++ b/gnuradio-core/src/lib/io/gr_message_source.h @@ -1,19 +1,19 @@ /* -*- 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 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, diff --git a/gnuradio-core/src/lib/io/gr_message_source.i b/gnuradio-core/src/lib/io/gr_message_source.i index 8a9c762d0..9ee9157e8 100644 --- a/gnuradio-core/src/lib/io/gr_message_source.i +++ b/gnuradio-core/src/lib/io/gr_message_source.i @@ -1,19 +1,19 @@ /* -*- 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 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, diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.cc b/gnuradio-core/src/lib/io/gr_oscope_guts.cc index 8b0d1e632..a5ea3002a 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003,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 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, @@ -65,7 +65,7 @@ decr_bi (int buffer_index, int mx) // decrement buffer index gr_oscope_guts::gr_oscope_guts (double sample_rate, gr_msg_queue_sptr msgq) : d_nchannels (1), - d_msgq (msgq), + d_msgq (msgq), d_trigger_mode (gr_TRIG_MODE_AUTO), d_trigger_slope (gr_TRIG_SLOPE_POS), d_trigger_channel (0), @@ -115,7 +115,7 @@ gr_oscope_guts::process_sample (const float *channel_data) return; d_decimator_count = d_decimator_count_init; - + if (d_trigger_mode != gr_TRIG_MODE_STRIPCHART) { for (int i = 0; i < d_nchannels; i++) @@ -198,7 +198,7 @@ gr_oscope_guts::found_trigger () { int mx = d_trigger_mode == gr_TRIG_MODE_STRIPCHART ? OUTPUT_RECORD_SIZE*SCHART_MULT : OUTPUT_RECORD_SIZE; - + float prev_sample = d_buffer[d_trigger_channel][decr_bi(d_obi, mx)]; float new_sample = d_buffer[d_trigger_channel][d_obi]; @@ -241,15 +241,15 @@ void gr_oscope_guts::write_output_records () { int mx; - - mx = d_trigger_mode == gr_TRIG_MODE_STRIPCHART ? + + mx = d_trigger_mode == gr_TRIG_MODE_STRIPCHART ? OUTPUT_RECORD_SIZE*SCHART_MULT : OUTPUT_RECORD_SIZE; - + // if the output queue if full, drop the data like its hot. if (d_msgq->full_p()) return; // Build a message to hold the output records - gr_message_sptr msg = + gr_message_sptr msg = gr_make_message(0, // msg type d_nchannels, // arg1 for other side mx, // arg2 for other side @@ -427,7 +427,7 @@ int gr_oscope_guts::get_samples_per_output_record () const { int mx; - + mx = OUTPUT_RECORD_SIZE; if (d_trigger_mode == gr_TRIG_MODE_STRIPCHART) { diff --git a/gnuradio-core/src/lib/io/gr_oscope_guts.h b/gnuradio-core/src/lib/io/gr_oscope_guts.h index 3223d4e38..bc9513c7e 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_guts.h +++ b/gnuradio-core/src/lib/io/gr_oscope_guts.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003,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 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, @@ -56,7 +56,7 @@ private: double d_update_rate; // approx freq to produce an output record (Hz) double d_trigger_level; - int d_obi; // output buffer index + int d_obi; // output buffer index float *d_buffer[MAX_CHANNELS]; scope_state d_state; diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink.i b/gnuradio-core/src/lib/io/gr_oscope_sink.i index 9d634193b..3d7072ed4 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink.i +++ b/gnuradio-core/src/lib/io/gr_oscope_sink.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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, diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc b/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc index eca0f6dc6..493a25e81 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_f.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003,2004,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, @@ -68,7 +68,7 @@ gr_oscope_sink_f::work (int noutput_items, for (int i = 0; i < noutput_items; i++){ // FIXME for now, copy the data. Fix later if reqd - for (int ch = 0; ch < ni; ch++) + for (int ch = 0; ch < ni; ch++) tmp[ch] = ((const float *) input_items[ch])[i]; d_guts->process_sample (tmp); diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_f.h b/gnuradio-core/src/lib/io/gr_oscope_sink_f.h index e3d1f65e5..8d434d2bc 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_f.h +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_f.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003,2004,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 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, diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_x.cc b/gnuradio-core/src/lib/io/gr_oscope_sink_x.cc index 2bbd57463..9580dbf6a 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_x.cc +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_x.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003,2004 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, diff --git a/gnuradio-core/src/lib/io/gr_oscope_sink_x.h b/gnuradio-core/src/lib/io/gr_oscope_sink_x.h index aaff5870b..153d0937a 100644 --- a/gnuradio-core/src/lib/io/gr_oscope_sink_x.h +++ b/gnuradio-core/src/lib/io/gr_oscope_sink_x.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003,2004 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, @@ -40,7 +40,7 @@ class GR_CORE_API gr_oscope_sink_x : public gr_sync_block protected: double d_sampling_rate; gr_oscope_guts *d_guts; - + gr_oscope_sink_x (const std::string name, gr_io_signature_sptr input_sig, double sampling_rate); @@ -71,7 +71,7 @@ public: // # of samples written to each output record. int get_samples_per_output_record () const; - + }; #endif /* INCLUDED_GR_OSCOPE_SINK_X_H */ diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index 4ac8c3512..d69892762 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 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, @@ -72,7 +72,7 @@ gr_tagged_file_sink::~gr_tagged_file_sink () { } -int +int gr_tagged_file_sink::work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) @@ -112,7 +112,7 @@ gr_tagged_file_sink::work (int noutput_items, pmt::pmt_string_to_symbol("time")); if(time_tags.size() > 0) { const gr_tag_t tag = time_tags[time_tags.size()-1]; - + uint64_t time_nitems = tag.offset; // Get time based on last time tag from USRP @@ -139,13 +139,13 @@ gr_tagged_file_sink::work (int noutput_items, //std::cout << " time: " << d_timeval << std::endl; } d_last_N = N; - + std::stringstream filename; filename.setf(std::ios::fixed, std::ios::floatfield); filename.precision(8); filename << "file" << d_n << "_" << d_timeval << ".dat"; d_n++; - + int fd; if ((fd = ::open (filename.str().c_str(), O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY, @@ -153,7 +153,7 @@ gr_tagged_file_sink::work (int noutput_items, perror (filename.str().c_str()); return -1; } - + // FIXME: //if ((d_handle = fdopen (fd, d_is_binary ? "wb" : "w")) == NULL){ if ((d_handle = fdopen (fd, "wb")) == NULL){ @@ -166,7 +166,7 @@ gr_tagged_file_sink::work (int noutput_items, d_state = IN_BURST; break; } - + vitr++; } if(d_state == NOT_IN_BURST) diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.h b/gnuradio-core/src/lib/io/gr_tagged_file_sink.h index da12dca78..d6f931a67 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.h +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 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, diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.i b/gnuradio-core/src/lib/io/gr_tagged_file_sink.i index 1408adfc1..2f2596e12 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.i +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 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, @@ -22,7 +22,7 @@ GR_SWIG_BLOCK_MAGIC(gr,tagged_file_sink) -gr_tagged_file_sink_sptr +gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize, double samp_rate); class gr_tagged_file_sink : public gr_sync_block diff --git a/gnuradio-core/src/lib/io/gr_trigger_mode.h b/gnuradio-core/src/lib/io/gr_trigger_mode.h index 8e1222856..be131686b 100644 --- a/gnuradio-core/src/lib/io/gr_trigger_mode.h +++ b/gnuradio-core/src/lib/io/gr_trigger_mode.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003,2004 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, diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index 9fc4da0ae..6b1d34ef7 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2007,2008,2009,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, @@ -92,7 +92,7 @@ static void report_error( const char *msg1, const char *msg2 ) return; } -gr_udp_sink::gr_udp_sink (size_t itemsize, +gr_udp_sink::gr_udp_sink (size_t itemsize, const char *host, unsigned short port, int payload_size, bool eof) : gr_sync_block ("udp_sink", @@ -133,11 +133,11 @@ gr_udp_sink::gr_udp_sink (size_t itemsize, // public constructor that returns a shared_ptr gr_udp_sink_sptr -gr_make_udp_sink (size_t itemsize, +gr_make_udp_sink (size_t itemsize, const char *host, unsigned short port, int payload_size, bool eof) { - return gnuradio::get_initial_sptr(new gr_udp_sink (itemsize, + return gnuradio::get_initial_sptr(new gr_udp_sink (itemsize, host, port, payload_size, eof)); } @@ -163,7 +163,7 @@ gr_udp_sink::~gr_udp_sink () #endif } -int +int gr_udp_sink::work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) @@ -180,7 +180,7 @@ gr_udp_sink::work (int noutput_items, while(bytes_sent < total_size) { bytes_to_send = std::min((ssize_t)d_payload_size, (total_size-bytes_sent)); - + if(d_connected) { r = send(d_socket, (in+bytes_sent), bytes_to_send, 0); if(r == -1) { // error on send command @@ -195,7 +195,7 @@ gr_udp_sink::work (int noutput_items, else r = bytes_to_send; // discarded for lack of connection bytes_sent += r; - + #if SNK_VERBOSE printf("\tbyte sent: %d bytes\n", r); #endif diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.h b/gnuradio-core/src/lib/io/gr_udp_sink.h index e9d4f8c73..bf042a6d1 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.h +++ b/gnuradio-core/src/lib/io/gr_udp_sink.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2007,2008,2009,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, @@ -31,14 +31,14 @@ class gr_udp_sink; typedef boost::shared_ptr gr_udp_sink_sptr; GR_CORE_API gr_udp_sink_sptr -gr_make_udp_sink (size_t itemsize, +gr_make_udp_sink (size_t itemsize, const char *host, unsigned short port, int payload_size=1472, bool eof=true); /*! * \brief Write stream to an UDP socket. * \ingroup sink_blk - * + * * \param itemsize The size (in bytes) of the item datatype * \param host The name or IP address of the receiving host; use * NULL or None for no connection @@ -50,7 +50,7 @@ gr_make_udp_sink (size_t itemsize, class GR_CORE_API gr_udp_sink : public gr_sync_block { - friend GR_CORE_API gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize, + friend GR_CORE_API gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize, const char *host, unsigned short port, int payload_size, bool eof); @@ -66,16 +66,16 @@ class GR_CORE_API gr_udp_sink : public gr_sync_block protected: /*! * \brief UDP Sink Constructor - * + * * \param itemsize The size (in bytes) of the item datatype * \param host The name or IP address of the receiving host; use * NULL or None for no connection * \param port Destination port to connect to on receiving host - * \param payload_size UDP payload size by default set to + * \param payload_size UDP payload size by default set to * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header)) * \param eof Send zero-length packet on disconnect */ - gr_udp_sink (size_t itemsize, + gr_udp_sink (size_t itemsize, const char *host, unsigned short port, int payload_size, bool eof); diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.i b/gnuradio-core/src/lib/io/gr_udp_sink.i index a71006ae0..ba7043937 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.i +++ b/gnuradio-core/src/lib/io/gr_udp_sink.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2007,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, @@ -23,17 +23,17 @@ GR_SWIG_BLOCK_MAGIC(gr,udp_sink) -gr_udp_sink_sptr -gr_make_udp_sink (size_t itemsize, +gr_udp_sink_sptr +gr_make_udp_sink (size_t itemsize, const char *host, unsigned short port, int payload_size=1472, bool eof=true) throw (std::runtime_error); class gr_udp_sink : public gr_sync_block { protected: - gr_udp_sink (size_t itemsize, + gr_udp_sink (size_t itemsize, const char *host, unsigned short port, - int payload_size, bool eof) + int payload_size, bool eof) throw (std::runtime_error); public: diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index ca31233de..af41159ee 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2007,2008,2009,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, @@ -97,7 +97,7 @@ static void report_error( const char *msg1, const char *msg2 ) return; } -gr_udp_source::gr_udp_source(size_t itemsize, const char *host, +gr_udp_source::gr_udp_source(size_t itemsize, const char *host, unsigned short port, int payload_size, bool eof, bool wait) : gr_sync_block ("udp_source", @@ -116,7 +116,7 @@ gr_udp_source::gr_udp_source(size_t itemsize, const char *host, report_error( "gr_udp_source WSAStartup", "can't open socket" ); } #endif - + // Set up the address stucture for the source address and port numbers // Get the source IP address from the host name struct addrinfo *ip_src; // store the source IP address to use @@ -186,10 +186,10 @@ gr_udp_source::gr_udp_source(size_t itemsize, const char *host, } gr_udp_source_sptr -gr_make_udp_source (size_t itemsize, const char *ipaddr, +gr_make_udp_source (size_t itemsize, const char *ipaddr, unsigned short port, int payload_size, bool eof, bool wait) { - return gnuradio::get_initial_sptr(new gr_udp_source (itemsize, ipaddr, + return gnuradio::get_initial_sptr(new gr_udp_source (itemsize, ipaddr, port, payload_size, eof, wait)); } @@ -213,7 +213,7 @@ gr_udp_source::~gr_udp_source () #endif } -int +int gr_udp_source::work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) @@ -233,13 +233,13 @@ gr_udp_source::work (int noutput_items, bytes_received = nbytes; #if SRC_VERBOSE - printf("\tTemp buff size: %d offset: %d (bytes_received: %d) (noutput_items: %d)\n", + printf("\tTemp buff size: %d offset: %d (bytes_received: %d) (noutput_items: %d)\n", d_residual, d_temp_offset, bytes_received, noutput_items); #endif // Increment pointer out += bytes_received; - + // Update indexing of amount of bytes left in the buffer d_residual -= nbytes; d_temp_offset += nbytes; @@ -280,7 +280,7 @@ gr_udp_source::work (int noutput_items, // This is a non-blocking call with a timeout set in the constructor r = recv(d_socket, d_temp_buff, d_payload_size, 0); // get the entire payload or the what's available - // If r > 0, round it down to a multiple of d_itemsize + // If r > 0, round it down to a multiple of d_itemsize // (If sender is broken, don't propagate problem) if (r > 0) r = (r/d_itemsize) * d_itemsize; @@ -289,7 +289,7 @@ gr_udp_source::work (int noutput_items, if(r == -1) { if( is_error(EAGAIN) ) { // handle non-blocking call timeout #if SRC_VERBOSE - printf("UDP receive timed out\n"); + printf("UDP receive timed out\n"); #endif if( d_wait ) { @@ -324,12 +324,12 @@ gr_udp_source::work (int noutput_items, else { // Calculate the number of bytes we can take from the buffer in this call nbytes = std::min(r, total_bytes-bytes_received); - + // adjust the total number of bytes we have to round down to nearest integer of an itemsize - nbytes -= ((bytes_received+nbytes) % d_itemsize); + nbytes -= ((bytes_received+nbytes) % d_itemsize); // copy the number of bytes we want to look at here - memcpy(out, d_temp_buff, nbytes); + memcpy(out, d_temp_buff, nbytes); d_residual = r - nbytes; // save the number of bytes stored d_temp_offset=nbytes; // reset buffer index @@ -350,7 +350,7 @@ gr_udp_source::work (int noutput_items, } #if SRC_VERBOSE - printf("Total Bytes Received: %d (bytes_received / noutput_items = %d / %d)\n", + printf("Total Bytes Received: %d (bytes_received / noutput_items = %d / %d)\n", bytes_received, bytes_received, noutput_items); #endif diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h index e2898981d..56dcb3c0a 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.h +++ b/gnuradio-core/src/lib/io/gr_udp_source.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2007,2008,2009,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, @@ -30,12 +30,12 @@ class gr_udp_source; typedef boost::shared_ptr gr_udp_source_sptr; -GR_CORE_API gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *host, +GR_CORE_API gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *host, unsigned short port, int payload_size=1472, bool eof=true, bool wait=true); -/*! +/*! * \brief Read stream from an UDP socket. * \ingroup source_blk * @@ -56,7 +56,7 @@ GR_CORE_API gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *h class GR_CORE_API gr_udp_source : public gr_sync_block { friend GR_CORE_API gr_udp_source_sptr gr_make_udp_source(size_t itemsize, - const char *host, + const char *host, unsigned short port, int payload_size, bool eof, bool wait); @@ -74,7 +74,7 @@ class GR_CORE_API gr_udp_source : public gr_sync_block protected: /*! * \brief UDP Source Constructor - * + * * \param itemsize The size (in bytes) of the item datatype * \param host The name or IP address of the receiving host; can be * NULL, None, or "0.0.0.0" to allow reading from any diff --git a/gnuradio-core/src/lib/io/gr_udp_source.i b/gnuradio-core/src/lib/io/gr_udp_source.i index 2001f33e9..18823a356 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.i +++ b/gnuradio-core/src/lib/io/gr_udp_source.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2007,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, @@ -22,15 +22,15 @@ GR_SWIG_BLOCK_MAGIC(gr,udp_source) -gr_udp_source_sptr -gr_make_udp_source (size_t itemsize, const char *host, +gr_udp_source_sptr +gr_make_udp_source (size_t itemsize, const char *host, unsigned short port, int payload_size=1472, bool eof=true, bool wait=true) throw (std::runtime_error); class gr_udp_source : public gr_sync_block { protected: - gr_udp_source (size_t itemsize, const char *host, + gr_udp_source (size_t itemsize, const char *host, unsigned short port, int payload_size, bool eof, bool wait) throw (std::runtime_error); public: diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc index 88b232343..8526032f6 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc @@ -80,7 +80,7 @@ gr_wavfile_sink::gr_wavfile_sink(const char *filename, } d_bytes_per_sample = bits_per_sample / 8; d_bytes_per_sample_new = d_bytes_per_sample; - + if (!open(filename)) { throw std::runtime_error ("can't open file"); } @@ -106,7 +106,7 @@ bool gr_wavfile_sink::open(const char* filename) { gruel::scoped_lock guard(d_mutex); - + // we use the open system call to get access to the O_LARGEFILE flag. int fd; if ((fd = ::open (filename, @@ -120,14 +120,14 @@ gr_wavfile_sink::open(const char* filename) fclose(d_new_fp); d_new_fp = 0; } - + if ((d_new_fp = fdopen (fd, "wb")) == NULL) { perror (filename); ::close(fd); // don't leak file descriptor if fdopen fails. return false; } d_updated = true; - + if (!gri_wavheader_write(d_new_fp, d_sample_rate, d_nchans, @@ -135,7 +135,7 @@ gr_wavfile_sink::open(const char* filename) fprintf(stderr, "[%s] could not write to WAV file\n", __FILE__); exit(-1); } - + return true; } @@ -144,19 +144,19 @@ void gr_wavfile_sink::close() { gruel::scoped_lock guard(d_mutex); - + if (!d_fp) return; - + close_wav(); } void gr_wavfile_sink::close_wav() { unsigned int byte_count = d_sample_count * d_bytes_per_sample; - + gri_wavheader_complete(d_fp, byte_count); - + fclose(d_fp); d_fp = NULL; } @@ -179,29 +179,29 @@ gr_wavfile_sink::work (int noutput_items, { float **in = (float **) &input_items[0]; int n_in_chans = input_items.size(); - + short int sample_buf_s; - + int nwritten; - + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this block do_update(); // update: d_fp is reqd if (!d_fp) // drop output on the floor return noutput_items; - + for (nwritten = 0; nwritten < noutput_items; nwritten++) { for (int chan = 0; chan < d_nchans; chan++) { // Write zeros to channels which are in the WAV file // but don't have any inputs here if (chan < n_in_chans) { - sample_buf_s = + sample_buf_s = convert_to_short(in[chan][nwritten]); } else { sample_buf_s = 0; } - + gri_wav_write_sample(d_fp, sample_buf_s, d_bytes_per_sample); - + if (feof(d_fp) || ferror(d_fp)) { fprintf(stderr, "[%s] file i/o error\n", __FILE__); close(); @@ -210,7 +210,7 @@ gr_wavfile_sink::work (int noutput_items, d_sample_count++; } } - + return nwritten; } @@ -225,7 +225,7 @@ gr_wavfile_sink::convert_to_short(float sample) } else if (sample < d_min_sample_val) { sample = d_min_sample_val; } - + return (short int) boost::math::iround(sample); } @@ -254,7 +254,7 @@ gr_wavfile_sink::do_update() if (!d_updated) { return; } - + if (d_fp) { close_wav(); } @@ -275,6 +275,6 @@ gr_wavfile_sink::do_update() d_normalize_fac = d_max_sample_val; d_normalize_shift = 0; } - + d_updated = false; } diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.h b/gnuradio-core/src/lib/io/gr_wavfile_sink.h index 6d06d74e9..162151b7a 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.h +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2008,2009 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, @@ -78,7 +78,7 @@ private: FILE *d_new_fp; bool d_updated; boost::mutex d_mutex; - + /*! * \brief Convert a sample value within [-1;+1] to a corresponding * short integer value @@ -91,7 +91,7 @@ private: * hand. */ void do_update(); - + /*! * \brief Writes information to the WAV header which is not available * a-priori (chunk size etc.) and closes the file. Not thread-safe and @@ -120,19 +120,19 @@ public: * sample rate. */ void set_sample_rate(unsigned int sample_rate); - + /*! * \brief Set bits per sample. This will not affect the WAV file * currently opened (see set_sample_rate()). If the value is neither * 8 nor 16, the call is ignored and the current value is kept. */ void set_bits_per_sample(int bits_per_sample); - - + + int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); - + }; #endif /* INCLUDED_GR_WAVFILE_SINK_H */ diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.i b/gnuradio-core/src/lib/io/gr_wavfile_sink.i index 7ccad1978..48d1130bd 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.i +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.i @@ -36,7 +36,7 @@ protected: int n_channels, unsigned int sample_rate, int bits_per_sample) throw (std::runtime_error); - + public: ~gr_wavfile_sink (); bool open(const char* filename); diff --git a/gnuradio-core/src/lib/io/gr_wavfile_source.cc b/gnuradio-core/src/lib/io/gr_wavfile_source.cc index 136e52611..c8372868b 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_source.cc +++ b/gnuradio-core/src/lib/io/gr_wavfile_source.cc @@ -85,7 +85,7 @@ gr_wavfile_source::gr_wavfile_source (const char *filename, bool repeat) d_samples_per_chan)) { throw std::runtime_error("is not a valid wav file"); } - + if (d_samples_per_chan == 0) { throw std::runtime_error("WAV file does not contain any samples"); } @@ -134,7 +134,7 @@ gr_wavfile_source::work(int noutput_items, d_sample_idx = 0; } - + for (int chan = 0; chan < d_nchans; chan++) { sample = gri_wav_read_sample(d_fp, d_bytes_per_sample); @@ -144,7 +144,7 @@ gr_wavfile_source::work(int noutput_items, } d_sample_idx++; - + // OK, EOF is not necessarily an error. But we're not going to // deal with handling corrupt wav files, so if they give us any // trouble they won't be processed. Serves them bloody right. @@ -156,7 +156,7 @@ gr_wavfile_source::work(int noutput_items, return i; } } - + return noutput_items; } diff --git a/gnuradio-core/src/lib/io/gr_wavfile_source.h b/gnuradio-core/src/lib/io/gr_wavfile_source.h index b300f2808..02e6e3678 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_source.h +++ b/gnuradio-core/src/lib/io/gr_wavfile_source.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,2008 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, @@ -51,7 +51,7 @@ private: FILE *d_fp; bool d_repeat; - + unsigned d_sample_rate; int d_nchans; int d_bytes_per_sample; @@ -60,7 +60,7 @@ private: unsigned d_sample_idx; int d_normalize_shift; int d_normalize_fac; - + /*! * \brief Convert an integer sample value to a float value within [-1;1] */ @@ -68,7 +68,7 @@ private: public: ~gr_wavfile_source (); - + int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); @@ -83,7 +83,7 @@ public: * file header. Only 8 or 16 bit are supported here. */ int bits_per_sample() const { return d_bytes_per_sample * 8; }; - + /*! * \brief Return the number of channels in the wav file as specified in * the wav file header. This is also the max number of outputs you can diff --git a/gnuradio-core/src/lib/io/gri_wavfile.cc b/gnuradio-core/src/lib/io/gri_wavfile.cc index 8f1c6a2bb..e316a0825 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.cc +++ b/gnuradio-core/src/lib/io/gri_wavfile.cc @@ -142,7 +142,7 @@ gri_wavheader_parse(FILE *fp, { // _o variables take return values char str_buf[8] = {0}; - + uint32_t file_size; uint32_t fmt_hdr_skip; uint16_t compression_type; @@ -152,52 +152,52 @@ gri_wavheader_parse(FILE *fp, uint16_t block_align; uint16_t bits_per_sample; uint32_t chunk_size; - + size_t fresult; fresult = fread(str_buf, 1, 4, fp); if (fresult != 4 || strncmp(str_buf, "RIFF", 4) || feof(fp)) { return false; } - + fresult = fread(&file_size, 1, 4, fp); - + fresult = fread(str_buf, 1, 8, fp); if (fresult != 8 || strncmp(str_buf, "WAVEfmt ", 8) || feof(fp)) { return false; } - + fresult = fread(&fmt_hdr_skip, 1, 4, fp); - + fresult = fread(&compression_type, 1, 2, fp); if (wav_to_host(compression_type) != VALID_COMPRESSION_TYPE) { return false; } - + fresult = fread(&nchans, 1, 2, fp); fresult = fread(&sample_rate, 1, 4, fp); fresult = fread(&avg_bytes_per_sec, 1, 4, fp); fresult = fread(&block_align, 1, 2, fp); fresult = fread(&bits_per_sample, 1, 2, fp); - + if (ferror(fp)) { return false; } - + fmt_hdr_skip = wav_to_host(fmt_hdr_skip); nchans = wav_to_host(nchans); sample_rate = wav_to_host(sample_rate); bits_per_sample = wav_to_host(bits_per_sample); - + if (bits_per_sample != 8 && bits_per_sample != 16) { return false; } - + fmt_hdr_skip -= 16; if (fmt_hdr_skip) { fseek(fp, fmt_hdr_skip, SEEK_CUR); } - + // data chunk fresult = fread(str_buf, 1, 4, fp); if (strncmp(str_buf, "data", 4)) { @@ -208,10 +208,10 @@ gri_wavheader_parse(FILE *fp, if (ferror(fp)) { return false; } - + // More byte swapping chunk_size = wav_to_host(chunk_size); - + // Output values sample_rate_o = (unsigned) sample_rate; nchans_o = (int) nchans; @@ -229,7 +229,7 @@ gri_wav_read_sample(FILE *fp, int bytes_per_sample) size_t fresult; fresult = fread(&buf, bytes_per_sample, 1, fp); - + return (short) wav_to_host(buf); } @@ -247,13 +247,13 @@ gri_wavheader_write(FILE *fp, uint16_t block_align = bytes_per_sample * nchans; uint32_t avg_bytes = sample_rate * block_align; uint16_t bits_per_sample = bytes_per_sample * 8; - + nchans_f = host_to_wav(nchans_f); sample_rate_f = host_to_wav(sample_rate_f); block_align = host_to_wav(block_align); avg_bytes = host_to_wav(avg_bytes); bits_per_sample = host_to_wav(bits_per_sample); - + wav_hdr[16] = 0x10; // no extra bytes wav_hdr[20] = 0x01; // no compression memcpy((void *) (wav_hdr + 22), (void *) &nchans_f, 2); @@ -261,12 +261,12 @@ gri_wavheader_write(FILE *fp, memcpy((void *) (wav_hdr + 28), (void *) &avg_bytes, 4); memcpy((void *) (wav_hdr + 32), (void *) &block_align, 2); memcpy((void *) (wav_hdr + 34), (void *) &bits_per_sample, 2); - + fwrite(&wav_hdr, 1, header_len, fp); if (ferror(fp)) { return false; } - + return true; } @@ -277,7 +277,7 @@ gri_wav_write_sample(FILE *fp, short int sample, int bytes_per_sample) void *data_ptr; unsigned char buf_8bit; int16_t buf_16bit; - + if (bytes_per_sample == 1) { buf_8bit = (unsigned char) sample; data_ptr = (void *) &buf_8bit; @@ -285,7 +285,7 @@ gri_wav_write_sample(FILE *fp, short int sample, int bytes_per_sample) buf_16bit = host_to_wav((int16_t) sample); data_ptr = (void *) &buf_16bit; } - + fwrite(data_ptr, 1, bytes_per_sample, fp); } @@ -295,19 +295,19 @@ gri_wavheader_complete(FILE *fp, unsigned int byte_count) { uint32_t chunk_size = (uint32_t) byte_count; chunk_size = host_to_wav(chunk_size); - + fseek(fp, 40, SEEK_SET); fwrite(&chunk_size, 1, 4, fp); - + chunk_size = (uint32_t) byte_count + 36; // fmt chunk and data header chunk_size = host_to_wav(chunk_size); fseek(fp, 4, SEEK_SET); - + fwrite(&chunk_size, 1, 4, fp); - + if (ferror(fp)) { return false; } - + return true; } diff --git a/gnuradio-core/src/lib/io/gri_wavfile.h b/gnuradio-core/src/lib/io/gri_wavfile.h index 2268474fb..c757be26b 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.h +++ b/gnuradio-core/src/lib/io/gri_wavfile.h @@ -91,7 +91,7 @@ gri_wav_write_sample(FILE *fp, short int sample, int bytes_per_sample); * * Note: The stream position is changed during this function. If anything * needs to be written to the WAV file after calling this function (which - * shouldn't happen), you need to fseek() to the end of the file (or + * shouldn't happen), you need to fseek() to the end of the file (or * whereever). * * \p fp File pointer to an open WAV file with a blank header diff --git a/gnuradio-core/src/lib/io/i2c.cc b/gnuradio-core/src/lib/io/i2c.cc index 65d426f7f..02dd47b53 100644 --- a/gnuradio-core/src/lib/io/i2c.cc +++ b/gnuradio-core/src/lib/io/i2c.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2001,2004 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, diff --git a/gnuradio-core/src/lib/io/i2c.h b/gnuradio-core/src/lib/io/i2c.h index 7d446dfa3..6b7f25a29 100644 --- a/gnuradio-core/src/lib/io/i2c.h +++ b/gnuradio-core/src/lib/io/i2c.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2001,2004 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, @@ -34,10 +34,10 @@ typedef boost::shared_ptr i2c_sptr; */ class GR_CORE_API i2c { public: - + i2c () {} virtual ~i2c (); - + //! \returns true iff successful virtual bool write (int addr, const unsigned char *buf, int nbytes) = 0; diff --git a/gnuradio-core/src/lib/io/i2c_bbio.cc b/gnuradio-core/src/lib/io/i2c_bbio.cc index 453681d8a..ddd00290d 100644 --- a/gnuradio-core/src/lib/io/i2c_bbio.cc +++ b/gnuradio-core/src/lib/io/i2c_bbio.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2001,2004 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, diff --git a/gnuradio-core/src/lib/io/i2c_bbio.h b/gnuradio-core/src/lib/io/i2c_bbio.h index 110a56555..6bf47b9cd 100644 --- a/gnuradio-core/src/lib/io/i2c_bbio.h +++ b/gnuradio-core/src/lib/io/i2c_bbio.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2001,2004 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, @@ -39,7 +39,7 @@ class GR_CORE_API i2c_bbio { i2c_bbio () {} virtual ~i2c_bbio (); - + virtual void set_scl (bool state) = 0; virtual void set_sda (bool state) = 0; virtual bool get_sda () = 0; diff --git a/gnuradio-core/src/lib/io/i2c_bbio_pp.cc b/gnuradio-core/src/lib/io/i2c_bbio_pp.cc index fda225ec8..382bb6b37 100644 --- a/gnuradio-core/src/lib/io/i2c_bbio_pp.cc +++ b/gnuradio-core/src/lib/io/i2c_bbio_pp.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2001,2004 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, diff --git a/gnuradio-core/src/lib/io/i2c_bbio_pp.h b/gnuradio-core/src/lib/io/i2c_bbio_pp.h index 4a311a2c9..2391bc1fc 100644 --- a/gnuradio-core/src/lib/io/i2c_bbio_pp.h +++ b/gnuradio-core/src/lib/io/i2c_bbio_pp.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2001,2004 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, diff --git a/gnuradio-core/src/lib/io/i2c_bitbang.cc b/gnuradio-core/src/lib/io/i2c_bitbang.cc index 401c76b0d..eb801c68f 100644 --- a/gnuradio-core/src/lib/io/i2c_bitbang.cc +++ b/gnuradio-core/src/lib/io/i2c_bitbang.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2001,2004 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, @@ -32,7 +32,7 @@ i2c_bitbang::i2c_bitbang (i2c_bbio_sptr io) d_io->unlock (); } -i2c_sptr +i2c_sptr make_i2c_bitbang (i2c_bbio_sptr io) { return i2c_sptr (new i2c_bitbang (io)); @@ -43,7 +43,7 @@ make_i2c_bitbang (i2c_bbio_sptr io) // entry: SCL = 1, SDA = 1 // exit: SCL = 0, SDA = 0 -void +void i2c_bitbang::start () { set_sda (1); @@ -53,11 +53,11 @@ i2c_bitbang::start () } -// stop: +// stop: // entry: SCL = X, SDA = X // exit: SCL = 1, SDA = 1 -void +void i2c_bitbang::stop () { set_scl (0); @@ -71,7 +71,7 @@ i2c_bitbang::stop () // entry: SCL = 0, SDA = X // exit: SCL = 0, SDA = X -void +void i2c_bitbang::write_bit (bool bit) { set_sda (bit); @@ -114,7 +114,7 @@ bool i2c_bitbang::write (int addr, const unsigned char *buf, int nbytes) { bool ok = true; - + d_io->lock (); start (); ok = write_byte ((addr << 1) | 0); // addr plus "read opcode" diff --git a/gnuradio-core/src/lib/io/i2c_bitbang.h b/gnuradio-core/src/lib/io/i2c_bitbang.h index feb23b787..1d6fe5044 100644 --- a/gnuradio-core/src/lib/io/i2c_bitbang.h +++ b/gnuradio-core/src/lib/io/i2c_bitbang.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2001,2004 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, @@ -37,7 +37,7 @@ class GR_CORE_API i2c_bitbang : public i2c { public: ~i2c_bitbang () {} - + //! \returns true iff successful bool write (int addr, const unsigned char *buf, int nbytes); @@ -50,7 +50,7 @@ private: void stop (); void write_bit (bool bit); bool write_byte (char byte); - + void set_sda (bool bit) { d_io->set_sda (bit); } void set_scl (bool bit) { d_io->set_scl (bit); } bool get_sda () { return d_io->get_sda (); } diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index 365577cd4..eab1346f1 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004,2007 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, diff --git a/gnuradio-core/src/lib/io/microtune_4702.cc b/gnuradio-core/src/lib/io/microtune_4702.cc index 59c88e26e..3ec072d51 100644 --- a/gnuradio-core/src/lib/io/microtune_4702.cc +++ b/gnuradio-core/src/lib/io/microtune_4702.cc @@ -1,7 +1,7 @@ /* -*- c++-*- */ /* * Copyright 2001,2003,2004 Free Software Foundation, Inc. - * + * * This file is part of GNU Radio * * GNU Radio is free software; you can redistribute it and/or modify @@ -13,7 +13,7 @@ * 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, @@ -166,7 +166,7 @@ microtune_4702::set_RF_freq (double target_freq, double *p_actual_freq) /*! * \returns true iff PLL is locked */ -bool +bool microtune_4702::pll_locked_p () { // FIXME diff --git a/gnuradio-core/src/lib/io/microtune_4702.h b/gnuradio-core/src/lib/io/microtune_4702.h index fd8d89305..ccc66db71 100644 --- a/gnuradio-core/src/lib/io/microtune_4702.h +++ b/gnuradio-core/src/lib/io/microtune_4702.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2001,2003 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, @@ -51,7 +51,7 @@ public: * \returns true iff PLL is locked */ bool pll_locked_p (); - + /*! * \returns the output frequency of the tuner in Hz. */ diff --git a/gnuradio-core/src/lib/io/microtune_4702_eval_board.h b/gnuradio-core/src/lib/io/microtune_4702_eval_board.h index e3c07fdf9..d866a4b94 100644 --- a/gnuradio-core/src/lib/io/microtune_4702_eval_board.h +++ b/gnuradio-core/src/lib/io/microtune_4702_eval_board.h @@ -1,19 +1,19 @@ /* -*- C++ -*- */ /* * Copyright 2001,2004 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, diff --git a/gnuradio-core/src/lib/io/microtune_4702_eval_board.i b/gnuradio-core/src/lib/io/microtune_4702_eval_board.i index 832a722fa..fc085a975 100644 --- a/gnuradio-core/src/lib/io/microtune_4702_eval_board.i +++ b/gnuradio-core/src/lib/io/microtune_4702_eval_board.i @@ -1,19 +1,19 @@ /* -*- C++ -*- */ /* * Copyright 2001,2004 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, diff --git a/gnuradio-core/src/lib/io/microtune_4937.cc b/gnuradio-core/src/lib/io/microtune_4937.cc index 1369df514..72ddd4bb6 100644 --- a/gnuradio-core/src/lib/io/microtune_4937.cc +++ b/gnuradio-core/src/lib/io/microtune_4937.cc @@ -1,19 +1,19 @@ /* -*- c++-*- */ /* * Copyright 2001,2003 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, @@ -99,7 +99,7 @@ microtune_4937::set_RF_freq (double target_freq, double *p_actual_freq) unsigned char buf[4]; double target_f_osc = target_freq + first_IF; - + double f_ref = 4e6 / d_reference_divider; // f_osc = f_ref * 8 * divisor @@ -129,7 +129,7 @@ microtune_4937::set_RF_freq (double target_freq, double *p_actual_freq) /*! * \returns true iff PLL is locked */ -bool +bool microtune_4937::pll_locked_p () { // FIXME diff --git a/gnuradio-core/src/lib/io/microtune_4937.h b/gnuradio-core/src/lib/io/microtune_4937.h index bc8a26c64..be8657c95 100644 --- a/gnuradio-core/src/lib/io/microtune_4937.h +++ b/gnuradio-core/src/lib/io/microtune_4937.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2001,2003 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, @@ -44,12 +44,12 @@ public: * \returns true iff sucessful. */ bool set_RF_freq (double freq, double *actual_freq); - + /*! * \returns true iff PLL is locked */ bool pll_locked_p (); - + /*! * \returns the output frequency (IF center freq) of the tuner in Hz. */ diff --git a/gnuradio-core/src/lib/io/microtune_4937_eval_board.cc b/gnuradio-core/src/lib/io/microtune_4937_eval_board.cc index f7a586075..a25b8addf 100644 --- a/gnuradio-core/src/lib/io/microtune_4937_eval_board.cc +++ b/gnuradio-core/src/lib/io/microtune_4937_eval_board.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2001,2004 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, diff --git a/gnuradio-core/src/lib/io/microtune_4937_eval_board.h b/gnuradio-core/src/lib/io/microtune_4937_eval_board.h index 09c00d116..3abd9084e 100644 --- a/gnuradio-core/src/lib/io/microtune_4937_eval_board.h +++ b/gnuradio-core/src/lib/io/microtune_4937_eval_board.h @@ -1,19 +1,19 @@ /* -*- C++ -*- */ /* * Copyright 2001,2004 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, diff --git a/gnuradio-core/src/lib/io/microtune_4937_eval_board.i b/gnuradio-core/src/lib/io/microtune_4937_eval_board.i index 1fe92c0f0..e261416f7 100644 --- a/gnuradio-core/src/lib/io/microtune_4937_eval_board.i +++ b/gnuradio-core/src/lib/io/microtune_4937_eval_board.i @@ -1,19 +1,19 @@ /* -*- C++ -*- */ /* * Copyright 2001,2004 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, diff --git a/gnuradio-core/src/lib/io/microtune_eval_board.i b/gnuradio-core/src/lib/io/microtune_eval_board.i index 3ad7eb61b..f77ef47b4 100644 --- a/gnuradio-core/src/lib/io/microtune_eval_board.i +++ b/gnuradio-core/src/lib/io/microtune_eval_board.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003 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, @@ -35,12 +35,12 @@ public: // returns actual freq or 0 if error (easier interface for SWIG) double set_RF_freq (double freq); - + /*! * \returns true iff PLL is locked */ bool pll_locked_p (); - + /*! * \returns the output frequency (IF center freq) of the tuner in Hz. */ diff --git a/gnuradio-core/src/lib/io/microtune_eval_board_defs.h b/gnuradio-core/src/lib/io/microtune_eval_board_defs.h index 5cba50bdf..61c52364f 100644 --- a/gnuradio-core/src/lib/io/microtune_eval_board_defs.h +++ b/gnuradio-core/src/lib/io/microtune_eval_board_defs.h @@ -9,19 +9,19 @@ /* * Copyright 2001 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, diff --git a/gnuradio-core/src/lib/io/microtune_xxxx.cc b/gnuradio-core/src/lib/io/microtune_xxxx.cc index f9ce44b2b..3d55f534a 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx.cc +++ b/gnuradio-core/src/lib/io/microtune_xxxx.cc @@ -1,19 +1,19 @@ /* -*- c++-*- */ /* * Copyright 2001,2003,2004 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,4 +38,4 @@ microtune_xxxx::set_RF_freq (double target_freq) return 0.0; } - + diff --git a/gnuradio-core/src/lib/io/microtune_xxxx.h b/gnuradio-core/src/lib/io/microtune_xxxx.h index 8b6ec25aa..b2646d39f 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx.h +++ b/gnuradio-core/src/lib/io/microtune_xxxx.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2001,2003,2004 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, @@ -47,7 +47,7 @@ public: * \returns true iff sucessful. */ virtual bool set_RF_freq (double freq, double *actual_freq) = 0; - + // returns actual freq or 0 if error (easier interface for SWIG) double set_RF_freq (double freq); @@ -55,7 +55,7 @@ public: * \returns true iff PLL is locked */ virtual bool pll_locked_p () = 0; - + /*! * \returns the output frequency (IF center freq) of the tuner in Hz. */ diff --git a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc index 14f2b8589..35600ff06 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc +++ b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2001,2004 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, @@ -49,7 +49,7 @@ microtune_xxxx_eval_board::~microtune_xxxx_eval_board () //! is the eval board present? -bool +bool microtune_xxxx_eval_board::board_present_p () { bool result = true; @@ -73,7 +73,7 @@ microtune_xxxx_eval_board::board_present_p () * We're using a MAX518 8-bit 5V dual dac for setting the AGC's * ---------------------------------------------------------------- */ -void +void microtune_xxxx_eval_board::write_dac (int which, int value) { unsigned char cmd[2]; @@ -82,7 +82,7 @@ microtune_xxxx_eval_board::write_dac (int which, int value) d_i2c->write (AGC_DAC_I2C_ADDR, cmd, sizeof (cmd)); } -void +void microtune_xxxx_eval_board::write_both_dacs (int value0, int value1) { unsigned char cmd[4]; @@ -111,7 +111,7 @@ microtune_xxxx_eval_board::set_RF_AGC_voltage (float volts) write_dac (0, scale_volts (volts)); } -void +void microtune_xxxx_eval_board::set_IF_AGC_voltage (float volts) { write_dac (1, scale_volts (volts)); @@ -124,7 +124,7 @@ microtune_xxxx_eval_board::set_RF_freq (double freq, double *actual_freq) { return d_tuner->set_RF_freq (freq, actual_freq); } - + double microtune_xxxx_eval_board::set_RF_freq (double freq) { diff --git a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h index 08aa438c0..7fd784ade 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h +++ b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.h @@ -1,19 +1,19 @@ /* -*- C++ -*- */ /* * Copyright 2001,2004 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, @@ -70,7 +70,7 @@ public: * \returns true iff sucessful. */ bool set_RF_freq (double freq, double *actual_freq); - + // returns actual freq or 0 if error (easier interface for SWIG) double set_RF_freq (double freq); @@ -78,7 +78,7 @@ public: * \returns true iff PLL is locked */ bool pll_locked_p (); - + /*! * \returns the output frequency (IF center freq) of the tuner in Hz. */ @@ -88,7 +88,7 @@ public: private: void write_dac (int which, int value); void write_both_dacs (int val0, int val1); - + protected: ppio_sptr d_ppio; i2c_sptr d_i2c; diff --git a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i index d6000ea08..8a8a59742 100644 --- a/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i +++ b/gnuradio-core/src/lib/io/microtune_xxxx_eval_board.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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, @@ -50,7 +50,7 @@ public: * \returns true iff PLL is locked */ bool pll_locked_p (); - + /*! * \returns the output frequency (IF center freq) of the tuner in Hz. */ diff --git a/gnuradio-core/src/lib/io/ppio.cc b/gnuradio-core/src/lib/io/ppio.cc index 9f0ed62de..a5edc539c 100644 --- a/gnuradio-core/src/lib/io/ppio.cc +++ b/gnuradio-core/src/lib/io/ppio.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003 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, diff --git a/gnuradio-core/src/lib/io/ppio.h b/gnuradio-core/src/lib/io/ppio.h index f7d14d52e..d99f7bf79 100644 --- a/gnuradio-core/src/lib/io/ppio.h +++ b/gnuradio-core/src/lib/io/ppio.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2001,2003 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, @@ -51,7 +51,7 @@ class GR_CORE_API ppio { }; /*! - * \brief Factory method. + * \brief Factory method. * * Split out from class to make life easier for SWIG */ diff --git a/gnuradio-core/src/lib/io/ppio.i b/gnuradio-core/src/lib/io/ppio.i index 8d9571e28..6b95dcf88 100644 --- a/gnuradio-core/src/lib/io/ppio.i +++ b/gnuradio-core/src/lib/io/ppio.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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, diff --git a/gnuradio-core/src/lib/io/ppio_ppdev.cc b/gnuradio-core/src/lib/io/ppio_ppdev.cc index 074de1aa1..f52845958 100644 --- a/gnuradio-core/src/lib/io/ppio_ppdev.cc +++ b/gnuradio-core/src/lib/io/ppio_ppdev.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2001,2003,2004,2008 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, @@ -94,7 +94,7 @@ ppio_ppdev::~ppio_ppdev () } -void +void ppio_ppdev::write_data (unsigned char v) { if (ioctl (d_fd, PPWDATA, &v) != 0){ @@ -115,7 +115,7 @@ ppio_ppdev::read_data () return v; } -void +void ppio_ppdev::write_control (unsigned char v) { unsigned char ctrl = v ^ CP_ACTIVE_LOW_BITS; @@ -198,7 +198,7 @@ ppio_ppdev::~ppio_ppdev () } -void +void ppio_ppdev::write_data (unsigned char v) { if (ioctl (d_fd, PPISDATA, &v) != 0){ @@ -219,7 +219,7 @@ ppio_ppdev::read_data () return v; } -void +void ppio_ppdev::write_control (unsigned char v) { unsigned char ctrl = v ^ CP_ACTIVE_LOW_BITS; @@ -274,7 +274,7 @@ ppio_ppdev::~ppio_ppdev () { } -void +void ppio_ppdev::write_data (unsigned char v) { } @@ -285,7 +285,7 @@ ppio_ppdev::read_data () return 0; } -void +void ppio_ppdev::write_control (unsigned char v) { } diff --git a/gnuradio-core/src/lib/io/ppio_ppdev.h b/gnuradio-core/src/lib/io/ppio_ppdev.h index 5d082d784..1f86d7e04 100644 --- a/gnuradio-core/src/lib/io/ppio_ppdev.h +++ b/gnuradio-core/src/lib/io/ppio_ppdev.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2001,2003 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, diff --git a/gnuradio-core/src/lib/io/sdr_1000.cc b/gnuradio-core/src/lib/io/sdr_1000.cc index df26237ef..a8c2555e0 100644 --- a/gnuradio-core/src/lib/io/sdr_1000.cc +++ b/gnuradio-core/src/lib/io/sdr_1000.cc @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003 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, @@ -49,13 +49,13 @@ sdr_1000_base::reset () write_latch (L_DDS1, 0x00, 0xff); } - + void sdr_1000_base::write_latch (int which, int value, int mask) { if (!(0 <= which && which <= 3)) return; - + d_ppio->lock (); d_shadow[which] = (d_shadow[which] & ~mask) | (value & mask); d_ppio->write_data (d_shadow[which]); diff --git a/gnuradio-core/src/lib/io/sdr_1000.h b/gnuradio-core/src/lib/io/sdr_1000.h index 6647fbba5..c00608a3a 100644 --- a/gnuradio-core/src/lib/io/sdr_1000.h +++ b/gnuradio-core/src/lib/io/sdr_1000.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2003,2004 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, @@ -40,12 +40,12 @@ enum { L_EXT = 0, L_BAND = 1, L_DDS0 = 2, L_DDS1 = 3 }; class GR_CORE_API sdr_1000_base { ppio_sptr d_ppio; int d_shadow[4]; // shadow latches - + public: sdr_1000_base (int which_pp); ~sdr_1000_base (); - + void reset (); void write_latch (int which, int value, int mask); }; diff --git a/gnuradio-core/src/lib/io/sdr_1000.i b/gnuradio-core/src/lib/io/sdr_1000.i index fbdef85e5..c9b1ef560 100644 --- a/gnuradio-core/src/lib/io/sdr_1000.i +++ b/gnuradio-core/src/lib/io/sdr_1000.i @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2004 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, -- cgit From db360e476e62d2c412d1654065d18047a25490b8 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Thu, 21 Jun 2012 22:44:16 -0400 Subject: core: fixes a very minor bug in gri_wavfile.cc and also makes a FIXME obsolete --- gnuradio-core/src/lib/io/gri_wavfile.cc | 118 ++++++-------------------------- gnuradio-core/src/lib/io/gri_wavfile.h | 27 +++----- 2 files changed, 33 insertions(+), 112 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gri_wavfile.cc b/gnuradio-core/src/lib/io/gri_wavfile.cc index e316a0825..3bc9d8fad 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.cc +++ b/gnuradio-core/src/lib/io/gri_wavfile.cc @@ -27,107 +27,30 @@ #include #include #include +#include # define VALID_COMPRESSION_TYPE 0x0001 // WAV files are always little-endian, so we need some byte switching macros -// FIXME: Use libgruel versions - +// Basically, this is the opposite of htonx() and ntohx() #ifdef WORDS_BIGENDIAN -#ifdef HAVE_BYTESWAP_H -#include -#else -#warning Using non-portable code (likely wrong other than ILP32). - -static inline short int -bswap_16 (unsigned short int x) -{ - return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)); -} - -static inline unsigned int -bswap_32 (unsigned int x) -{ - return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \ - | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)); -} -#endif // HAVE_BYTESWAP_H - -static inline uint32_t -host_to_wav(uint32_t x) -{ - return bswap_32(x); -} - -static inline uint16_t -host_to_wav(uint16_t x) -{ - return bswap_16(x); -} - -static inline int16_t -host_to_wav(int16_t x) -{ - return bswap_16(x); -} - -static inline uint32_t -wav_to_host(uint32_t x) -{ - return bswap_32(x); -} - -static inline uint16_t -wav_to_host(uint16_t x) -{ - return bswap_16(x); -} - -static inline int16_t -wav_to_host(int16_t x) -{ - return bswap_16(x); -} +static inline uint32_t host_to_wav(uint32_t x) { return bswap_32(x); } +static inline uint16_t host_to_wav(uint16_t x) { return bswap_16(x); } +static inline int16_t host_to_wav(int16_t x) { return bswap_16(x); } +static inline uint32_t wav_to_host(uint32_t x) { return bswap_32(x); } +static inline uint16_t wav_to_host(uint16_t x) { return bswap_16(x); } +static inline int16_t wav_to_host(int16_t x) { return bswap_16(x); } #else -static inline uint32_t -host_to_wav(uint32_t x) -{ - return x; -} - -static inline uint16_t -host_to_wav(uint16_t x) -{ - return x; -} - -static inline int16_t -host_to_wav(int16_t x) -{ - return x; -} - -static inline uint32_t -wav_to_host(uint32_t x) -{ - return x; -} - -static inline uint16_t -wav_to_host(uint16_t x) -{ - return x; -} - -static inline int16_t -wav_to_host(int16_t x) -{ - return x; -} +static inline uint32_t host_to_wav(uint32_t x) { return x; } +static inline uint16_t host_to_wav(uint16_t x) { return x; } +static inline int16_t host_to_wav(int16_t x) { return x; } +static inline uint32_t wav_to_host(uint32_t x) { return x; } +static inline uint16_t wav_to_host(uint16_t x) { return x; } +static inline int16_t wav_to_host(int16_t x) { return x; } #endif // WORDS_BIGENDIAN @@ -225,12 +148,15 @@ gri_wavheader_parse(FILE *fp, short int gri_wav_read_sample(FILE *fp, int bytes_per_sample) { - int16_t buf = 0; - size_t fresult; - - fresult = fread(&buf, bytes_per_sample, 1, fp); + int16_t buf_16bit; - return (short) wav_to_host(buf); + if(!fread(&buf_16bit, bytes_per_sample, 1, fp)) { + return 0; + } + if(bytes_per_sample == 1) { + return (short) buf_16bit; + } + return (short)wav_to_host(buf_16bit); } diff --git a/gnuradio-core/src/lib/io/gri_wavfile.h b/gnuradio-core/src/lib/io/gri_wavfile.h index c757be26b..16280e34a 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.h +++ b/gnuradio-core/src/lib/io/gri_wavfile.h @@ -29,20 +29,15 @@ /*! * \brief Read signal information from a given WAV file. * - * \p fp File pointer to an opened, empty file. - * \p sample_rate Stores the sample rate [S/s] - * \p nchans Number of channels - * \p bytes_per_sample Bytes per sample, can either be 1 or 2 (corresponding to - * 8 or 16 bit samples, respectively) - * \p first_sample_pos Number of the first byte containing a sample. Use this - * with fseek() to jump from the end of the file to the first sample - * when in repeat mode. - * \p samples_per_chan Number of samples per channel - * \p normalize_fac The normalization factor with which you need to divide the - * integer values of the samples to get them within [-1;1] - * \p normalize_shift The value by which the sample values need to be shifted - * after normalization (reason being, 8-bit WAV files store samples as - * unsigned char and 16-bit as signed short int) + * \param[in] fp File pointer to an opened, empty file. + * \param[out] sample_rate Stores the sample rate [S/s] + * \param[out] nchans Number of channels + * \param[out] bytes_per_sample Bytes per sample, can either be 1 or 2 (corresponding o + * 8 or 16 bit samples, respectively) + * \param[out] first_sample_pos Number of the first byte containing a sample. Use this + * with fseek() to jump from the end of the file to the + * first sample when in repeat mode. + * \param[out] samples_per_chan Number of samples per channel * \return True on a successful read, false if the file could not be read or is * not a valid WAV file. */ @@ -94,8 +89,8 @@ gri_wav_write_sample(FILE *fp, short int sample, int bytes_per_sample); * shouldn't happen), you need to fseek() to the end of the file (or * whereever). * - * \p fp File pointer to an open WAV file with a blank header - * \p byte_count Length of all samples written to the file in bytes. + * \param[in] fp File pointer to an open WAV file with a blank header + * \param[in] byte_count Length of all samples written to the file in bytes. */ bool gri_wavheader_complete(FILE *fp, unsigned int byte_count); -- cgit From 056d3006d07c11c4bfba9ac5c2f82111be55dd35 Mon Sep 17 00:00:00 2001 From: Nicholas Corgan Date: Fri, 22 Jun 2012 11:19:58 -0700 Subject: gruel: got rid of inet.h and adjusted only file that depended on it --- gnuradio-core/src/lib/io/gri_wavfile.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gri_wavfile.cc b/gnuradio-core/src/lib/io/gri_wavfile.cc index 3bc9d8fad..780bd1b98 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.cc +++ b/gnuradio-core/src/lib/io/gri_wavfile.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008 Free Software Foundation, Inc. + * Copyright 2004,2008,2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -27,7 +27,7 @@ #include #include #include -#include +#include # define VALID_COMPRESSION_TYPE 0x0001 @@ -36,12 +36,12 @@ // Basically, this is the opposite of htonx() and ntohx() #ifdef WORDS_BIGENDIAN -static inline uint32_t host_to_wav(uint32_t x) { return bswap_32(x); } -static inline uint16_t host_to_wav(uint16_t x) { return bswap_16(x); } -static inline int16_t host_to_wav(int16_t x) { return bswap_16(x); } -static inline uint32_t wav_to_host(uint32_t x) { return bswap_32(x); } -static inline uint16_t wav_to_host(uint16_t x) { return bswap_16(x); } -static inline int16_t wav_to_host(int16_t x) { return bswap_16(x); } +static inline uint32_t host_to_wav(uint32_t x) { return htonl(x); } +static inline uint16_t host_to_wav(uint16_t x) { return htons(x); } +static inline int16_t host_to_wav(int16_t x) { return htons(x); } +static inline uint32_t wav_to_host(uint32_t x) { return ntohl(x); } +static inline uint16_t wav_to_host(uint16_t x) { return ntohs(x); } +static inline int16_t wav_to_host(int16_t x) { return ntohs(x); } #else -- cgit From 75fac1e1476578cd354a2cc586af23da88ce4b12 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 28 Jun 2012 17:55:34 -0700 Subject: core: fix for gri wave byteswapping Sorry guys, I misunderstood the comments. Wave data is specifically in little endian format. Therefore we should only be swapping on big endian machines. Since systems only provide network endian macros: The following commit provides a cross platform byteswap and macros for host to/from worknet short and long. --- gnuradio-core/src/lib/io/gri_wavfile.cc | 46 +++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 17 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gri_wavfile.cc b/gnuradio-core/src/lib/io/gri_wavfile.cc index 780bd1b98..277e6b7b0 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.cc +++ b/gnuradio-core/src/lib/io/gri_wavfile.cc @@ -27,33 +27,45 @@ #include #include #include -#include +#include //BOOST_BIG_ENDIAN # define VALID_COMPRESSION_TYPE 0x0001 -// WAV files are always little-endian, so we need some byte switching macros - // Basically, this is the opposite of htonx() and ntohx() -#ifdef WORDS_BIGENDIAN +// Define host to/from worknet (little endian) short and long +#ifdef BOOST_BIG_ENDIAN + + static inline uint16_t __gri_wav_bs16(uint16_t x) + { + return (x>>8) | (x<<8); + } -static inline uint32_t host_to_wav(uint32_t x) { return htonl(x); } -static inline uint16_t host_to_wav(uint16_t x) { return htons(x); } -static inline int16_t host_to_wav(int16_t x) { return htons(x); } -static inline uint32_t wav_to_host(uint32_t x) { return ntohl(x); } -static inline uint16_t wav_to_host(uint16_t x) { return ntohs(x); } -static inline int16_t wav_to_host(int16_t x) { return ntohs(x); } + static inline uint32_t __gri_wav_bs32(uint32_t x) + { + return (uint32_t(__gri_wav_bs16(uint16_t(x&0xfffful)))<<16) | (__gri_wav_bs16(uint16_t(x>>16))); + } + + #define htowl(x) __gri_wav_bs32(x) + #define wtohl(x) __gri_wav_bs32(x) + #define htows(x) __gri_wav_bs16(x) + #define wtohs(x) __gri_wav_bs16(x) #else -static inline uint32_t host_to_wav(uint32_t x) { return x; } -static inline uint16_t host_to_wav(uint16_t x) { return x; } -static inline int16_t host_to_wav(int16_t x) { return x; } -static inline uint32_t wav_to_host(uint32_t x) { return x; } -static inline uint16_t wav_to_host(uint16_t x) { return x; } -static inline int16_t wav_to_host(int16_t x) { return x; } + #define htowl(x) uint32_t(x) + #define wtohl(x) uint32_t(x) + #define htows(x) uint16_t(x) + #define wtohs(x) uint16_t(x) -#endif // WORDS_BIGENDIAN +#endif // BOOST_BIG_ENDIAN +// WAV files are always little-endian, so we need some byte switching macros +static inline uint32_t host_to_wav(uint32_t x) { return htowl(x); } +static inline uint16_t host_to_wav(uint16_t x) { return htows(x); } +static inline int16_t host_to_wav(int16_t x) { return htows(x); } +static inline uint32_t wav_to_host(uint32_t x) { return wtohl(x); } +static inline uint16_t wav_to_host(uint16_t x) { return wtohs(x); } +static inline int16_t wav_to_host(int16_t x) { return wtohs(x); } bool gri_wavheader_parse(FILE *fp, -- cgit From 494b13ab6e5b342e03e3e3202dea9c3a85ff46e1 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Thu, 19 Jul 2012 19:15:29 -0400 Subject: core: added message source that takes in tags for controlling bursts. --- gnuradio-core/src/lib/io/CMakeLists.txt | 1 + .../src/lib/io/gr_message_burst_source.cc | 144 +++++++++++++++++++++ gnuradio-core/src/lib/io/gr_message_burst_source.h | 71 ++++++++++ gnuradio-core/src/lib/io/gr_message_burst_source.i | 38 ++++++ gnuradio-core/src/lib/io/io.i | 2 + 5 files changed, 256 insertions(+) create mode 100644 gnuradio-core/src/lib/io/gr_message_burst_source.cc create mode 100644 gnuradio-core/src/lib/io/gr_message_burst_source.h create mode 100644 gnuradio-core/src/lib/io/gr_message_burst_source.i (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/CMakeLists.txt b/gnuradio-core/src/lib/io/CMakeLists.txt index af9d7583c..3dea13396 100644 --- a/gnuradio-core/src/lib/io/CMakeLists.txt +++ b/gnuradio-core/src/lib/io/CMakeLists.txt @@ -87,6 +87,7 @@ set(gr_core_io_triple_threats gr_file_descriptor_source gr_message_sink gr_message_source + gr_message_burst_source microtune_xxxx_eval_board microtune_4702_eval_board microtune_4937_eval_board diff --git a/gnuradio-core/src/lib/io/gr_message_burst_source.cc b/gnuradio-core/src/lib/io/gr_message_burst_source.cc new file mode 100644 index 000000000..e9e2dfd4d --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_burst_source.cc @@ -0,0 +1,144 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// public constructor that returns a shared_ptr + +gr_message_burst_source_sptr +gr_make_message_burst_source(size_t itemsize, int msgq_limit) +{ + return gnuradio::get_initial_sptr(new gr_message_burst_source(itemsize, msgq_limit)); +} + +// public constructor that takes existing message queue +gr_message_burst_source_sptr +gr_make_message_burst_source(size_t itemsize, gr_msg_queue_sptr msgq) +{ + return gnuradio::get_initial_sptr(new gr_message_burst_source(itemsize, msgq)); +} + +gr_message_burst_source::gr_message_burst_source (size_t itemsize, int msgq_limit) + : gr_sync_block("message_burst_source", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(1, 1, itemsize)), + d_itemsize(itemsize), d_msgq(gr_make_msg_queue(msgq_limit)), d_msg_offset(0), d_eof(false) +{ + std::stringstream id; + id << name() << unique_id(); + d_me = pmt::pmt_string_to_symbol(id.str()); +} + +gr_message_burst_source::gr_message_burst_source (size_t itemsize, gr_msg_queue_sptr msgq) + : gr_sync_block("message_burst_source", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(1, 1, itemsize)), + d_itemsize(itemsize), d_msgq(msgq), d_msg_offset(0), d_eof(false) +{ + std::stringstream id; + id << name() << unique_id(); + d_me = pmt::pmt_string_to_symbol(id.str()); +} + +gr_message_burst_source::~gr_message_burst_source() +{ +} + +int +gr_message_burst_source::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + char *out = (char *) output_items[0]; + int nn = 0; + + uint64_t abs_sample_count = nitems_written(0); + + while (nn < noutput_items){ + if (d_msg){ + // + // Consume whatever we can from the current message + // + + int mm = std::min(noutput_items - nn, (int)((d_msg->length() - d_msg_offset) / d_itemsize)); + memcpy (out, &(d_msg->msg()[d_msg_offset]), mm * d_itemsize); + + nn += mm; + out += mm * d_itemsize; + d_msg_offset += mm * d_itemsize; + assert(d_msg_offset <= d_msg->length()); + + if (d_msg_offset == d_msg->length()){ + if (d_msg->type() == 1) // type == 1 sets EOF + d_eof = true; + d_msg.reset(); + //tag end of burst + add_item_tag(0, //stream ID + abs_sample_count+nn-1, //sample number + pmt::pmt_string_to_symbol("tx_eob"), + pmt::pmt_from_bool(1), + d_me //block src id + ); + } + } + else { + // + // No current message + // + if (d_msgq->empty_p() && nn > 0){ // no more messages in the queue, return what we've got + break; + } + + if (d_eof) + return -1; + + d_msg = d_msgq->delete_head(); // block, waiting for a message + d_msg_offset = 0; + //tag start of burst + add_item_tag(0, //stream ID + abs_sample_count+nn, //sample number + pmt::pmt_string_to_symbol("tx_sob"), + pmt::pmt_from_bool(1), + d_me //block src id + ); + + + if ((d_msg->length() % d_itemsize) != 0) + throw std::runtime_error("msg length is not a multiple of d_itemsize"); + } + } + + return nn; +} diff --git a/gnuradio-core/src/lib/io/gr_message_burst_source.h b/gnuradio-core/src/lib/io/gr_message_burst_source.h new file mode 100644 index 000000000..63e220113 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_burst_source.h @@ -0,0 +1,71 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_MESSAGE_BURST_SOURCE_H +#define INCLUDED_GR_MESSAGE_BURST_SOURCE_H + +#include +#include +#include +#include + +class gr_message_burst_source; +typedef boost::shared_ptr gr_message_burst_source_sptr; + +GR_CORE_API gr_message_burst_source_sptr gr_make_message_burst_source (size_t itemsize, int msgq_limit=0); +GR_CORE_API gr_message_burst_source_sptr gr_make_message_burst_source (size_t itemsize, gr_msg_queue_sptr msgq); + +/*! + * \brief Turn received messages into a stream and tag them for UHD to send. + * \ingroup source_blk + */ +class GR_CORE_API gr_message_burst_source : public gr_sync_block +{ + private: + size_t d_itemsize; + gr_msg_queue_sptr d_msgq; + gr_message_sptr d_msg; + unsigned d_msg_offset; + bool d_eof; + + pmt::pmt_t d_me; + + friend GR_CORE_API gr_message_burst_source_sptr + gr_make_message_burst_source(size_t itemsize, int msgq_limit); + friend GR_CORE_API gr_message_burst_source_sptr + gr_make_message_burst_source(size_t itemsize, gr_msg_queue_sptr msgq); + + protected: + gr_message_burst_source (size_t itemsize, int msgq_limit); + gr_message_burst_source (size_t itemsize, gr_msg_queue_sptr msgq); + + public: + ~gr_message_burst_source (); + + gr_msg_queue_sptr msgq() const { return d_msgq; } + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_gr_message_burst_source_H */ diff --git a/gnuradio-core/src/lib/io/gr_message_burst_source.i b/gnuradio-core/src/lib/io/gr_message_burst_source.i new file mode 100644 index 000000000..f7ad840c2 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_burst_source.i @@ -0,0 +1,38 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,message_burst_source); + +gr_message_burst_source_sptr gr_make_message_burst_source (size_t itemsize, int msgq_limit=0); +gr_message_burst_source_sptr gr_make_message_burst_source (size_t itemsize, gr_msg_queue_sptr msgq); + +class gr_message_burst_source : public gr_sync_block +{ + protected: + gr_message_burst_source (size_t itemsize, int msgq_limit); + gr_message_burst_source (size_t itemsize, gr_msg_queue_sptr msgq); + + public: + ~gr_message_burst_source (); + + gr_msg_queue_sptr msgq() const; +}; diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index eab1346f1..5cd352905 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -59,6 +60,7 @@ %include "gr_oscope_sink.i" %include "ppio.i" %include "gr_message_source.i" +%include "gr_message_burst_source.i" %include "gr_message_sink.i" %include "gr_udp_sink.i" %include "gr_udp_source.i" -- cgit From 08cf111f1d30ad08965c2892aeed5030d2cec1b2 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 14 Aug 2012 23:00:16 -0700 Subject: core: fix use of private vars in place of API accessor Conflicts: gnuradio-core/src/lib/io/gr_tagged_file_sink.cc --- gnuradio-core/src/lib/io/gr_tagged_file_sink.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc index d69892762..6d642088e 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc @@ -143,7 +143,7 @@ gr_tagged_file_sink::work (int noutput_items, std::stringstream filename; filename.setf(std::ios::fixed, std::ios::floatfield); filename.precision(8); - filename << "file" << d_n << "_" << d_timeval << ".dat"; + filename << "file" << unique_id() << "_" << d_n << "_" << d_timeval << ".dat"; d_n++; int fd; -- cgit From 65ea256f8de15b7a23c602f9775edf0636b3732c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 29 Sep 2012 20:19:16 -0700 Subject: core: udp source wait mode yields work thread --- gnuradio-core/src/lib/io/gr_udp_source.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index af41159ee..eca8e89d0 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -269,8 +269,9 @@ gr_udp_source::work (int noutput_items, else if(r == 0 ) { // timed out if( d_wait ) { // Allow boost thread interrupt, then try again - boost::this_thread::interruption_point(); - continue; + //boost::this_thread::interruption_point(); + //continue; + return 0; } else return -1; @@ -294,8 +295,9 @@ gr_udp_source::work (int noutput_items, if( d_wait ) { // Allow boost thread interrupt, then try again - boost::this_thread::interruption_point(); - continue; + //boost::this_thread::interruption_point(); + //continue; + return 0; } else return -1; -- cgit From eb4163c7bdd63783e570fb28ba87144a4c86d22f Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 21 Nov 2012 17:25:24 -0500 Subject: core: Adding a file sink block that stores metadata with file. Current working version only has a single header at the top of the file. Must update to add metadata fields when changes occur. Also adding extra_header structure to store extram, users-specified info. --- gnuradio-core/src/lib/io/CMakeLists.txt | 1 + gnuradio-core/src/lib/io/gr_file_meta_sink.cc | 125 ++++++++++++++++++++++++++ gnuradio-core/src/lib/io/gr_file_meta_sink.h | 86 ++++++++++++++++++ gnuradio-core/src/lib/io/gr_file_meta_sink.i | 71 +++++++++++++++ gnuradio-core/src/lib/io/io.i | 2 + 5 files changed, 285 insertions(+) create mode 100644 gnuradio-core/src/lib/io/gr_file_meta_sink.cc create mode 100644 gnuradio-core/src/lib/io/gr_file_meta_sink.h create mode 100644 gnuradio-core/src/lib/io/gr_file_meta_sink.i (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/CMakeLists.txt b/gnuradio-core/src/lib/io/CMakeLists.txt index 3dea13396..ddd43a4a3 100644 --- a/gnuradio-core/src/lib/io/CMakeLists.txt +++ b/gnuradio-core/src/lib/io/CMakeLists.txt @@ -81,6 +81,7 @@ endif(ENABLE_PYTHON) ######################################################################## set(gr_core_io_triple_threats gr_file_sink + gr_file_meta_sink gr_file_sink_base gr_file_source gr_file_descriptor_sink diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc new file mode 100644 index 000000000..aa34bf9b7 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc @@ -0,0 +1,125 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +gr_file_meta_sink_sptr +gr_make_file_meta_sink(size_t itemsize, const char *filename, + double samp_rate, gr_file_types type, bool complex, + const std::string &extra_dict) +{ + return gnuradio::get_initial_sptr + (new gr_file_meta_sink(itemsize, filename, + samp_rate, type, complex, + extra_dict)); +} + +gr_file_meta_sink::gr_file_meta_sink(size_t itemsize, const char *filename, + double samp_rate, gr_file_types type, bool complex, + const std::string &extra_dict) + : gr_sync_block("file_meta_sink", + gr_make_io_signature(1, 1, itemsize), + gr_make_io_signature(0, 0, 0)), + gr_file_sink_base(filename, true), + d_itemsize(itemsize) +{ + if(!open(filename)) + throw std::runtime_error("file_meta_sink: can't open file\n"); + + pmt_t timestamp = pmt_make_tuple(pmt_from_uint64(0), + pmt_from_double(0)); + + d_header = pmt_make_dict(); + d_header = pmt_dict_add(d_header, mp("sr"), mp(samp_rate)); + d_header = pmt_dict_add(d_header, mp("time"), timestamp); + d_header = pmt_dict_add(d_header, mp("type"), pmt_from_long(type)); + d_header = pmt_dict_add(d_header, mp("cplx"), complex ? PMT_T : PMT_F); + d_header = pmt_dict_add(d_header, mp("strt"), pmt_from_uint64(109)); + d_header = pmt_dict_add(d_header, mp("size"), pmt_from_uint64(0)); + // handle extra dictionary + + write_header(d_header); +} + +void +gr_file_meta_sink::write_header(pmt_t header) +{ + do_update(); + + std::string header_str = pmt_serialize_str(header); + + size_t nwritten = 0; + while(nwritten < header_str.size()) { + std::string sub = header_str.substr(nwritten); + int count = fwrite(sub.c_str(), sizeof(char), sub.size(), d_fp); + nwritten += count; + if((count == 0) && (ferror(d_fp))) { + fclose(d_fp); + throw std::runtime_error("file_meta_sink: error writing header to file\n"); + } + } +} + +gr_file_meta_sink::~gr_file_meta_sink() +{ + fseek(d_fp, 0, SEEK_SET); + + // Replace the dictionary item with the data size now that we're + // done. + uint64_t s = nitems_read(0) * d_itemsize; + d_header = pmt_dict_delete(d_header, mp("size")); + d_header = pmt_dict_add(d_header, mp("size"), pmt_from_uint64(s)); + write_header(d_header); +} + +int +gr_file_meta_sink::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + char *inbuf = (char*)input_items[0]; + int nwritten = 0; + + do_update(); // update d_fp is reqd + + if(!d_fp) + return noutput_items; // drop output on the floor + + while(nwritten < noutput_items) { + int count = fwrite(inbuf, d_itemsize, noutput_items - nwritten, d_fp); + if(count == 0) // FIXME add error handling + break; + nwritten += count; + inbuf += count * d_itemsize; + } + + if(d_unbuffered) + fflush(d_fp); + + return nwritten; +} diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.h b/gnuradio-core/src/lib/io/gr_file_meta_sink.h new file mode 100644 index 000000000..741408de1 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.h @@ -0,0 +1,86 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_FILE_META_SINK_H +#define INCLUDED_GR_FILE_META_SINK_H + +#include +#include +#include +#include + +using namespace pmt; + +enum gr_file_types { + GR_FILE_BYTE=0, + GR_FILE_CHAR=0, + GR_FILE_SHORT=1, + GR_FILE_INT, + GR_FILE_LONG, + GR_FILE_LONG_LONG, + GR_FILE_FLOAT, + GR_FILE_DOUBLE, +}; + +class gr_file_meta_sink; +typedef boost::shared_ptr gr_file_meta_sink_sptr; + +GR_CORE_API gr_file_meta_sink_sptr +gr_make_file_meta_sink(size_t itemsize, const char *filename, + double samp_rate, gr_file_types type, bool complex, + const std::string &extra_dict=""); + +/*! + * \brief Write stream to file. + * \ingroup sink_blk + */ + +class GR_CORE_API gr_file_meta_sink : public gr_sync_block, public gr_file_sink_base +{ + + friend GR_CORE_API gr_file_meta_sink_sptr + gr_make_file_meta_sink(size_t itemsize, const char *filename, + double samp_rate, gr_file_types type, bool complex, + const std::string &extra_dict); + + private: + size_t d_itemsize; + pmt_t d_header; + pmt_t d_extra_dict; + + protected: + gr_file_meta_sink(size_t itemsize, const char *filename, + double samp_rate, gr_file_types type, bool complex, + const std::string &extra_dict); + + + void write_header(pmt_t header); + + public: + ~gr_file_meta_sink(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_GR_FILE_META_SINK_H */ diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.i b/gnuradio-core/src/lib/io/gr_file_meta_sink.i new file mode 100644 index 000000000..27fb4debb --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.i @@ -0,0 +1,71 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,file_meta_sink) + +enum gr_file_types { + GR_FILE_BYTE=0, + GR_FILE_CHAR=0, + GR_FILE_SHORT, + GR_FILE_INT, + GR_FILE_LONG, + GR_FILE_LONG_LONG, + GR_FILE_FLOAT, + GR_FILE_DOUBLE, +}; + +gr_file_meta_sink_sptr +gr_make_file_meta_sink(size_t itemsize, const char *filename, + double samp_rate, gr_file_types type, bool complex, + const std::string & extra_dict=""); + +class gr_file_meta_sink : public gr_sync_block, public gr_file_sink_base +{ + protected: + gr_file_meta_sink(size_t itemsize, const char *filename, + double samp_rate, gr_file_types type, bool complex, + const std::string & extra_dict); + + public: + ~gr_file_meta_sink(); + + enum file_types { + FILE_BYTE=0, + FILE_CHAR=0, + FILE_SHORT, + FILE_INT, + FILE_LONG, + FILE_LONG_LONG, + FILE_FLOAT, + FILE_DOUBLE, + }; + + /*! + * \brief open filename and begin output to it. + */ + bool open(const char *filename); + + /*! + * \brief close current output file. + */ + void close(); +}; diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index 5cd352905..07f2e9195 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -27,6 +27,7 @@ #endif #include +#include #include #include #include @@ -49,6 +50,7 @@ %include "gr_file_sink_base.i" %include "gr_file_sink.i" +%include "gr_file_meta_sink.i" %include "gr_file_source.i" %include "gr_file_descriptor_sink.i" %include "gr_file_descriptor_source.i" -- cgit From 9dc8f8b18043e71b50b3a254cb52bf355e97e6fa Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 24 Nov 2012 19:09:02 -0500 Subject: core: Update file_meta_sink to inject headers into data stream. When a tag with updated metadata information is received, close out the previous header (by setting the segment size) and create a new header with the new data. Specifically for sample rate and time stamps. Will be useful for extra_dict when implemented. --- gnuradio-core/src/lib/io/gr_file_meta_sink.cc | 128 ++++++++++++++++++++++---- gnuradio-core/src/lib/io/gr_file_meta_sink.h | 51 ++++++++-- gnuradio-core/src/lib/io/gr_file_meta_sink.i | 6 +- 3 files changed, 160 insertions(+), 25 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc index aa34bf9b7..9d092d79f 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc @@ -28,25 +28,31 @@ #include #include +#define HEADER_SIZE 117 + gr_file_meta_sink_sptr gr_make_file_meta_sink(size_t itemsize, const char *filename, - double samp_rate, gr_file_types type, bool complex, + double samp_rate, double relative_rate, + gr_file_types type, bool complex, const std::string &extra_dict) { return gnuradio::get_initial_sptr (new gr_file_meta_sink(itemsize, filename, - samp_rate, type, complex, + samp_rate, relative_rate, + type, complex, extra_dict)); } gr_file_meta_sink::gr_file_meta_sink(size_t itemsize, const char *filename, - double samp_rate, gr_file_types type, bool complex, + double samp_rate, double relative_rate, + gr_file_types type, bool complex, const std::string &extra_dict) : gr_sync_block("file_meta_sink", gr_make_io_signature(1, 1, itemsize), gr_make_io_signature(0, 0, 0)), gr_file_sink_base(filename, true), - d_itemsize(itemsize) + d_itemsize(itemsize), d_relative_rate(relative_rate), + d_total_seg_size(0) { if(!open(filename)) throw std::runtime_error("file_meta_sink: can't open file\n"); @@ -55,11 +61,11 @@ gr_file_meta_sink::gr_file_meta_sink(size_t itemsize, const char *filename, pmt_from_double(0)); d_header = pmt_make_dict(); - d_header = pmt_dict_add(d_header, mp("sr"), mp(samp_rate)); - d_header = pmt_dict_add(d_header, mp("time"), timestamp); + d_header = pmt_dict_add(d_header, mp("rx_rate"), mp(samp_rate)); + d_header = pmt_dict_add(d_header, mp("rx_time"), timestamp); d_header = pmt_dict_add(d_header, mp("type"), pmt_from_long(type)); d_header = pmt_dict_add(d_header, mp("cplx"), complex ? PMT_T : PMT_F); - d_header = pmt_dict_add(d_header, mp("strt"), pmt_from_uint64(109)); + d_header = pmt_dict_add(d_header, mp("strt"), pmt_from_uint64(HEADER_SIZE)); d_header = pmt_dict_add(d_header, mp("size"), pmt_from_uint64(0)); // handle extra dictionary @@ -72,6 +78,8 @@ gr_file_meta_sink::write_header(pmt_t header) do_update(); std::string header_str = pmt_serialize_str(header); + if(header_str.size() != HEADER_SIZE) + throw std::runtime_error("file_meta_sink: header is wrong size.\n"); size_t nwritten = 0; while(nwritten < header_str.size()) { @@ -80,21 +88,55 @@ gr_file_meta_sink::write_header(pmt_t header) nwritten += count; if((count == 0) && (ferror(d_fp))) { fclose(d_fp); - throw std::runtime_error("file_meta_sink: error writing header to file\n"); + throw std::runtime_error("file_meta_sink: error writing header to file.\n"); } } } -gr_file_meta_sink::~gr_file_meta_sink() +bool +gr_file_meta_sink::update_header(pmt_t key, pmt_t value) { - fseek(d_fp, 0, SEEK_SET); + // Special handling caveat to transform rate from radio source into + // the rate at this sink. + if(pmt_eq(key, mp("rx_rate"))) { + double rate = pmt_to_double(value); + value = pmt_from_double(rate*d_relative_rate); + } - // Replace the dictionary item with the data size now that we're - // done. - uint64_t s = nitems_read(0) * d_itemsize; - d_header = pmt_dict_delete(d_header, mp("size")); - d_header = pmt_dict_add(d_header, mp("size"), pmt_from_uint64(s)); - write_header(d_header); + if(pmt_dict_has_key(d_header, key)) { + d_header = pmt_dict_add(d_header, key, value); + return true; + } + else { + return false; + } +} + +uint64_t +gr_file_meta_sink::get_last_header_loc() +{ + uint64_t loc = 0; + pmt_t v = pmt_dict_ref(d_header, mp("strt"), PMT_NIL); + if(!pmt_eq(v, PMT_NIL)) + loc = pmt_to_uint64(v) - HEADER_SIZE; + return loc; +} + +gr_file_meta_sink::~gr_file_meta_sink() +{ + // Replace the last header block with the final count of the number + // of items. + uint64_t loc = get_last_header_loc(); + uint64_t seg_size = nitems_read(0) * d_itemsize - d_total_seg_size; + pmt_t s = pmt_from_uint64(seg_size); + //std::cerr << "Destructor" << std::endl; + //std::cerr << " location of last header: " << loc << std::endl; + //std::cerr << " nitems_read: " << nitems_read(0)*d_itemsize << std::endl; + //std::cerr << " Segment Size: " << seg_size << std::endl; + if(update_header(mp("size"), s)) { + fseek(d_fp, loc, SEEK_SET); + write_header(d_header); + } } int @@ -110,6 +152,60 @@ gr_file_meta_sink::work(int noutput_items, if(!d_fp) return noutput_items; // drop output on the floor + uint64_t abs_N = nitems_read(0); + uint64_t end_N = abs_N + (uint64_t)(noutput_items); + std::vector all_tags; + get_tags_in_range(all_tags, 0, abs_N, end_N); + + std::vector::iterator itr; + for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { + // Special case where info is carried on the first tag, so we just + // overwrite the first header. + if(itr->offset == 0) { + if(update_header(itr->key, itr->value)) { + fseek(d_fp, 0, SEEK_SET); + write_header(d_header); + } + } + else { + // Update the last header info with the number of samples this + // block represents. + uint64_t loc = get_last_header_loc(); + uint64_t seg_size = itr->offset * d_itemsize - d_total_seg_size; + pmt_t s = pmt_from_uint64(seg_size); + //std::cerr << "Found Tag at: " << itr->offset*d_itemsize << std::endl; + //std::cerr << " last header starts at: " << loc << std::endl; + //std::cerr << " segment size is: " << seg_size << std::endl; + if(update_header(mp("size"), s)) { + fseek(d_fp, loc, SEEK_SET); + write_header(d_header); + } + + if(update_header(itr->key, itr->value)) { + // Otherwise, set current size of chunk to 0 and start of + // chunk based on current index + header size. + d_total_seg_size += seg_size; + s = pmt_from_uint64(0); + if(update_header(mp("size"), s)) { + // If we have multiple tags on the same offset, this makes + // sure we just overwrite the same header each time instead + // of creating a new header per tag. + uint64_t seg_start = loc; + if(seg_size != 0) + seg_start += HEADER_SIZE + seg_size; + pmt_t s = pmt_from_uint64(seg_start + HEADER_SIZE); + if(update_header(mp("strt"), s)) { + //std::cerr << "Adding new header" << std::endl; + //std::cerr << " new header start at: " << seg_start-HEADER_SIZE << std::endl; + //std::cerr << " new seg start at: " << seg_start << std::endl; + fseek(d_fp, seg_start, SEEK_SET); + write_header(d_header); + } + } + } + } + } + while(nwritten < noutput_items) { int count = fwrite(inbuf, d_itemsize, noutput_items - nwritten, d_fp); if(count == 0) // FIXME add error handling diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.h b/gnuradio-core/src/lib/io/gr_file_meta_sink.h index 741408de1..c0f30bdc0 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.h @@ -46,34 +46,71 @@ typedef boost::shared_ptr gr_file_meta_sink_sptr; GR_CORE_API gr_file_meta_sink_sptr gr_make_file_meta_sink(size_t itemsize, const char *filename, - double samp_rate, gr_file_types type, bool complex, + double samp_rate, double relative_rate, + gr_file_types type, bool complex, const std::string &extra_dict=""); /*! - * \brief Write stream to file. + * \brief Write stream to file with meta-data headers. * \ingroup sink_blk + * + * These files represent data as binary information in between + * meta-data headers. The headers contain information about the type + * of data and properties of the data in the next segment of + * samples. The information includes: + * + * rx_rate (double): sample rate of data. + * rx_time (uint64_t, double): time stamp of first sample in segment. + * type (gr_file_types as int32_t): data type. + * cplx (bool): Is data complex? + * strt (uint64_t): Starting byte of data in this segment. + * size (uint64_t): Size in bytes of data in this segment. + * + * Tags can be sent to the file to update the information, which will + * create a new header. Headers are found by searching from the first + * header (at position 0 in the file) and reading where the data + * segment starts plus the data segment size. Following will either be + * a new header or EOF. */ - class GR_CORE_API gr_file_meta_sink : public gr_sync_block, public gr_file_sink_base { - + /*! + * \brief Create a meta-data file sink. + * + * \param itemsize (size_t): Size of data type. + * \param filename (string): Name of file to write data to. + * \param samp_rate (double): Sample rate of data. If sample rate will be + * set by a tag, such as rx_tag from a UHD source, this is + * basically ignored. + * \param relative_rate (double): Rate chance from source of sample + * rate tag to sink. + * \param type (gr_file_types): Data type (int, float, etc.) + * \param complex (bool): If data stream is complex + * \param extra_dict (string): a serialized PMT dictionary of extra + * information. Currently not supported. + */ friend GR_CORE_API gr_file_meta_sink_sptr gr_make_file_meta_sink(size_t itemsize, const char *filename, - double samp_rate, gr_file_types type, bool complex, + double samp_rate, double relative_rate, + gr_file_types type, bool complex, const std::string &extra_dict); private: size_t d_itemsize; + double d_relative_rate; + uint64_t d_total_seg_size; pmt_t d_header; pmt_t d_extra_dict; protected: gr_file_meta_sink(size_t itemsize, const char *filename, - double samp_rate, gr_file_types type, bool complex, + double samp_rate, double relative_rate, + gr_file_types type, bool complex, const std::string &extra_dict); - void write_header(pmt_t header); + bool update_header(pmt_t key, pmt_t value); + uint64_t get_last_header_loc(); public: ~gr_file_meta_sink(); diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.i b/gnuradio-core/src/lib/io/gr_file_meta_sink.i index 27fb4debb..7d90ca304 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.i +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.i @@ -35,14 +35,16 @@ enum gr_file_types { gr_file_meta_sink_sptr gr_make_file_meta_sink(size_t itemsize, const char *filename, - double samp_rate, gr_file_types type, bool complex, + double samp_rate, double relative_rate, + gr_file_types type, bool complex, const std::string & extra_dict=""); class gr_file_meta_sink : public gr_sync_block, public gr_file_sink_base { protected: gr_file_meta_sink(size_t itemsize, const char *filename, - double samp_rate, gr_file_types type, bool complex, + double samp_rate, double relative_rate, + gr_file_types type, bool complex, const std::string & extra_dict); public: -- cgit From 88a9e1f9332d54c1743d062adfaf48aa6d3040ff Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 27 Nov 2012 11:59:26 -0800 Subject: core: adding ability to handle extra data in headers. --- gnuradio-core/src/lib/io/gr_file_meta_sink.cc | 58 +++++++++++++++++++++------ gnuradio-core/src/lib/io/gr_file_meta_sink.h | 15 +++---- gnuradio-core/src/lib/io/gr_file_meta_sink.i | 4 +- 3 files changed, 55 insertions(+), 22 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc index 9d092d79f..401d8299d 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc @@ -60,26 +60,43 @@ gr_file_meta_sink::gr_file_meta_sink(size_t itemsize, const char *filename, pmt_t timestamp = pmt_make_tuple(pmt_from_uint64(0), pmt_from_double(0)); + // handle extra dictionary + d_extra = pmt_make_dict(); + if(extra_dict.size() > 0) { + pmt_t extras = pmt_deserialize_str(extra_dict); + pmt_t keys = pmt_dict_keys(extras); + pmt_t vals = pmt_dict_values(extras); + size_t nitems = pmt_length(keys); + for(size_t i = 0; i < nitems; i++) { + d_extra = pmt_dict_add(d_extra, + pmt_nth(i, keys), + pmt_nth(i, vals)); + } + } + + d_extra_size = pmt_serialize_str(d_extra).size(); + d_header = pmt_make_dict(); d_header = pmt_dict_add(d_header, mp("rx_rate"), mp(samp_rate)); d_header = pmt_dict_add(d_header, mp("rx_time"), timestamp); d_header = pmt_dict_add(d_header, mp("type"), pmt_from_long(type)); d_header = pmt_dict_add(d_header, mp("cplx"), complex ? PMT_T : PMT_F); - d_header = pmt_dict_add(d_header, mp("strt"), pmt_from_uint64(HEADER_SIZE)); + d_header = pmt_dict_add(d_header, mp("strt"), pmt_from_uint64(HEADER_SIZE+d_extra_size)); d_header = pmt_dict_add(d_header, mp("size"), pmt_from_uint64(0)); - // handle extra dictionary - write_header(d_header); + write_header(d_header, d_extra); } void -gr_file_meta_sink::write_header(pmt_t header) +gr_file_meta_sink::write_header(pmt_t header, pmt_t extra) { do_update(); std::string header_str = pmt_serialize_str(header); - if(header_str.size() != HEADER_SIZE) - throw std::runtime_error("file_meta_sink: header is wrong size.\n"); + std::string extra_str = pmt_serialize_str(extra); + + if((header_str.size() != HEADER_SIZE) && (extra_str.size() != d_extra_size)) + throw std::runtime_error("file_meta_sink: header or extras is wrong size.\n"); size_t nwritten = 0; while(nwritten < header_str.size()) { @@ -91,6 +108,17 @@ gr_file_meta_sink::write_header(pmt_t header) throw std::runtime_error("file_meta_sink: error writing header to file.\n"); } } + + nwritten = 0; + while(nwritten < extra_str.size()) { + std::string sub = extra_str.substr(nwritten); + int count = fwrite(sub.c_str(), sizeof(char), sub.size(), d_fp); + nwritten += count; + if((count == 0) && (ferror(d_fp))) { + fclose(d_fp); + throw std::runtime_error("file_meta_sink: error writing extra to file.\n"); + } + } } bool @@ -107,6 +135,10 @@ gr_file_meta_sink::update_header(pmt_t key, pmt_t value) d_header = pmt_dict_add(d_header, key, value); return true; } + else if(pmt_dict_has_key(d_extra, key)) { + d_extra = pmt_dict_add(d_extra, key, value); + return true; + } else { return false; } @@ -118,7 +150,7 @@ gr_file_meta_sink::get_last_header_loc() uint64_t loc = 0; pmt_t v = pmt_dict_ref(d_header, mp("strt"), PMT_NIL); if(!pmt_eq(v, PMT_NIL)) - loc = pmt_to_uint64(v) - HEADER_SIZE; + loc = pmt_to_uint64(v) - (HEADER_SIZE+d_extra_size); return loc; } @@ -135,7 +167,7 @@ gr_file_meta_sink::~gr_file_meta_sink() //std::cerr << " Segment Size: " << seg_size << std::endl; if(update_header(mp("size"), s)) { fseek(d_fp, loc, SEEK_SET); - write_header(d_header); + write_header(d_header, d_extra); } } @@ -164,7 +196,7 @@ gr_file_meta_sink::work(int noutput_items, if(itr->offset == 0) { if(update_header(itr->key, itr->value)) { fseek(d_fp, 0, SEEK_SET); - write_header(d_header); + write_header(d_header, d_extra); } } else { @@ -178,7 +210,7 @@ gr_file_meta_sink::work(int noutput_items, //std::cerr << " segment size is: " << seg_size << std::endl; if(update_header(mp("size"), s)) { fseek(d_fp, loc, SEEK_SET); - write_header(d_header); + write_header(d_header, d_extra); } if(update_header(itr->key, itr->value)) { @@ -192,14 +224,14 @@ gr_file_meta_sink::work(int noutput_items, // of creating a new header per tag. uint64_t seg_start = loc; if(seg_size != 0) - seg_start += HEADER_SIZE + seg_size; - pmt_t s = pmt_from_uint64(seg_start + HEADER_SIZE); + seg_start += HEADER_SIZE + d_extra_size + seg_size + 1; + pmt_t s = pmt_from_uint64(seg_start + HEADER_SIZE + d_extra_size); if(update_header(mp("strt"), s)) { //std::cerr << "Adding new header" << std::endl; //std::cerr << " new header start at: " << seg_start-HEADER_SIZE << std::endl; //std::cerr << " new seg start at: " << seg_start << std::endl; fseek(d_fp, seg_start, SEEK_SET); - write_header(d_header); + write_header(d_header, d_extra); } } } diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.h b/gnuradio-core/src/lib/io/gr_file_meta_sink.h index c0f30bdc0..9ba4878d1 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.h @@ -46,8 +46,8 @@ typedef boost::shared_ptr gr_file_meta_sink_sptr; GR_CORE_API gr_file_meta_sink_sptr gr_make_file_meta_sink(size_t itemsize, const char *filename, - double samp_rate, double relative_rate, - gr_file_types type, bool complex, + double samp_rate=1, double relative_rate=1, + gr_file_types type=GR_FILE_FLOAT, bool complex=true, const std::string &extra_dict=""); /*! @@ -100,15 +100,16 @@ class GR_CORE_API gr_file_meta_sink : public gr_sync_block, public gr_file_sink_ double d_relative_rate; uint64_t d_total_seg_size; pmt_t d_header; - pmt_t d_extra_dict; + pmt_t d_extra; + size_t d_extra_size; protected: gr_file_meta_sink(size_t itemsize, const char *filename, - double samp_rate, double relative_rate, - gr_file_types type, bool complex, - const std::string &extra_dict); + double samp_rate=1, double relative_rate=1, + gr_file_types type=GR_FILE_FLOAT, bool complex=true, + const std::string &extra_dict=""); - void write_header(pmt_t header); + void write_header(pmt_t header, pmt_t extra); bool update_header(pmt_t key, pmt_t value); uint64_t get_last_header_loc(); diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.i b/gnuradio-core/src/lib/io/gr_file_meta_sink.i index 7d90ca304..b58a519ce 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.i +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.i @@ -35,8 +35,8 @@ enum gr_file_types { gr_file_meta_sink_sptr gr_make_file_meta_sink(size_t itemsize, const char *filename, - double samp_rate, double relative_rate, - gr_file_types type, bool complex, + double samp_rate=1, double relative_rate=1, + gr_file_types type=GR_FILE_FLOAT, bool complex=true, const std::string & extra_dict=""); class gr_file_meta_sink : public gr_sync_block, public gr_file_sink_base -- cgit From 4478cb86a5dc9fccf66c2cdd5806419b70c3837e Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Thu, 29 Nov 2012 19:46:29 -0800 Subject: Adding PDU to tagged stream and tagged stream to PDU blocks along with QA python non-stream-connected blocks still need a new thread context --- gnuradio-core/src/lib/io/CMakeLists.txt | 5 + gnuradio-core/src/lib/io/gr_message_debug.cc | 71 +++++++++++ gnuradio-core/src/lib/io/gr_message_debug.h | 59 +++++++++ gnuradio-core/src/lib/io/gr_message_debug.i | 30 +++++ gnuradio-core/src/lib/io/gr_pdu.cc | 43 +++++++ gnuradio-core/src/lib/io/gr_pdu.h | 38 ++++++ gnuradio-core/src/lib/io/gr_pdu.i | 30 +++++ .../src/lib/io/gr_pdu_to_tagged_stream.cc | 131 +++++++++++++++++++ gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.h | 63 ++++++++++ gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.i | 31 +++++ .../src/lib/io/gr_tagged_stream_to_pdu.cc | 139 +++++++++++++++++++++ gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.h | 76 +++++++++++ gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.i | 31 +++++ gnuradio-core/src/lib/io/io.i | 8 ++ 14 files changed, 755 insertions(+) create mode 100644 gnuradio-core/src/lib/io/gr_message_debug.cc create mode 100644 gnuradio-core/src/lib/io/gr_message_debug.h create mode 100644 gnuradio-core/src/lib/io/gr_message_debug.i create mode 100644 gnuradio-core/src/lib/io/gr_pdu.cc create mode 100644 gnuradio-core/src/lib/io/gr_pdu.h create mode 100644 gnuradio-core/src/lib/io/gr_pdu.i create mode 100644 gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc create mode 100644 gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.h create mode 100644 gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.i create mode 100644 gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc create mode 100644 gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.h create mode 100644 gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.i (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/CMakeLists.txt b/gnuradio-core/src/lib/io/CMakeLists.txt index 3dea13396..7041f2820 100644 --- a/gnuradio-core/src/lib/io/CMakeLists.txt +++ b/gnuradio-core/src/lib/io/CMakeLists.txt @@ -38,6 +38,7 @@ list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/microtune_xxxx.cc ${CMAKE_CURRENT_SOURCE_DIR}/ppio_ppdev.cc ${CMAKE_CURRENT_SOURCE_DIR}/gri_wavfile.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_pdu.cc ) ######################################################################## @@ -59,6 +60,7 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/microtune_xxxx.h ${CMAKE_CURRENT_SOURCE_DIR}/ppio_ppdev.h ${CMAKE_CURRENT_SOURCE_DIR}/gri_wavfile.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_pdu.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio COMPONENT "core_devel" ) @@ -85,9 +87,11 @@ set(gr_core_io_triple_threats gr_file_source gr_file_descriptor_sink gr_file_descriptor_source + gr_message_debug gr_message_sink gr_message_source gr_message_burst_source + gr_pdu_to_tagged_stream microtune_xxxx_eval_board microtune_4702_eval_board microtune_4937_eval_board @@ -98,6 +102,7 @@ set(gr_core_io_triple_threats gr_wavfile_source gr_wavfile_sink gr_tagged_file_sink + gr_tagged_stream_to_pdu ) foreach(file_tt ${gr_core_io_triple_threats}) diff --git a/gnuradio-core/src/lib/io/gr_message_debug.cc b/gnuradio-core/src/lib/io/gr_message_debug.cc new file mode 100644 index 000000000..84c11c46e --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_debug.cc @@ -0,0 +1,71 @@ +/* -*- 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, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// public constructor that returns a shared_ptr + +gr_message_debug_sptr +gr_make_message_debug () +{ + return gnuradio::get_initial_sptr(new gr_message_debug()); +} + +void gr_message_debug::print(pmt::pmt_t msg){ + std::cout << "******* DEBUG PRINT ********\n"; + pmt::pmt_print(msg); +} + + +gr_message_debug::gr_message_debug () + : gr_sync_block("message_debug", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(0, 0, 0)) +{ + message_port_register_in(pmt::mp("print")); + set_msg_handler(pmt::mp("print"), boost::bind(&gr_message_debug::print, this, _1)); +} + +gr_message_debug::~gr_message_debug() +{ +} + +int +gr_message_debug::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + return 0; // FIXME: replace with default NOP work function in gr_block +} diff --git a/gnuradio-core/src/lib/io/gr_message_debug.h b/gnuradio-core/src/lib/io/gr_message_debug.h new file mode 100644 index 000000000..37d8b7a4d --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_debug.h @@ -0,0 +1,59 @@ +/* -*- 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 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, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_MESSAGE_DEBUG_H +#define INCLUDED_GR_MESSAGE_DEBUG_H + +#include +#include +#include +#include + +class gr_message_debug; +typedef boost::shared_ptr gr_message_debug_sptr; + +GR_CORE_API gr_message_debug_sptr gr_make_message_debug (); + +/*! + * \brief Gather received items into messages and insert into msgq + * \ingroup sink_blk + */ +class GR_CORE_API gr_message_debug : public gr_sync_block +{ + private: + friend GR_CORE_API gr_message_debug_sptr + gr_make_message_debug(); + + void print(pmt::pmt_t msg); + + protected: + gr_message_debug (); + + public: + ~gr_message_debug (); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_GR_MESSAGE_DEBUG_H */ diff --git a/gnuradio-core/src/lib/io/gr_message_debug.i b/gnuradio-core/src/lib/io/gr_message_debug.i new file mode 100644 index 000000000..7bd547c91 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_message_debug.i @@ -0,0 +1,30 @@ +/* -*- 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 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, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,message_debug); + +%{ +#include +%} + +%include "gr_message_debug.h" + diff --git a/gnuradio-core/src/lib/io/gr_pdu.cc b/gnuradio-core/src/lib/io/gr_pdu.cc new file mode 100644 index 000000000..c5290b610 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_pdu.cc @@ -0,0 +1,43 @@ + +#include + +size_t gr_pdu_itemsize(gr_pdu_vector_type type){ + switch(type){ + case BYTE: + return 1; + case FLOAT: + return sizeof(float); + case COMPLEX: + return sizeof(gr_complex); + default: + throw std::runtime_error("bad type!"); + } +} + +bool gr_pdu_type_matches(gr_pdu_vector_type type, pmt::pmt_t v){ + switch(type){ + case BYTE: + return pmt::pmt_is_u8vector(v); + case FLOAT: + return pmt::pmt_is_f32vector(v); + case COMPLEX: + return pmt::pmt_is_c32vector(v); + default: + throw std::runtime_error("bad type!"); + } +} + +pmt::pmt_t gr_pdu_make_vector(gr_pdu_vector_type type, const uint8_t* buf, size_t items){ + switch(type){ + case BYTE: + return pmt::pmt_init_u8vector(items, buf); + case FLOAT: + return pmt::pmt_init_f32vector(items, (const float*)buf); + case COMPLEX: + return pmt::pmt_init_c32vector(items, (const gr_complex*)buf); + default: + throw std::runtime_error("bad type!"); + } +} + + diff --git a/gnuradio-core/src/lib/io/gr_pdu.h b/gnuradio-core/src/lib/io/gr_pdu.h new file mode 100644 index 000000000..3bea83740 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_pdu.h @@ -0,0 +1,38 @@ +/* -*- 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 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, + * Boston, MA 02110-1301, USA. + */ + +#ifndef GR_PDU_H +#define GR_PDU_H + +#include +#include + +#define pdu_port_id pmt::mp("pdus") +#define pdu_length_tag pmt::mp("pdu_length") + +enum gr_pdu_vector_type { BYTE, FLOAT, COMPLEX }; + +size_t gr_pdu_itemsize(gr_pdu_vector_type type); +bool gr_pdu_type_matches(gr_pdu_vector_type type, pmt::pmt_t v); +pmt::pmt_t gr_pdu_make_vector(gr_pdu_vector_type type, const uint8_t* buf, size_t items); + +#endif diff --git a/gnuradio-core/src/lib/io/gr_pdu.i b/gnuradio-core/src/lib/io/gr_pdu.i new file mode 100644 index 000000000..7cb3c62c7 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_pdu.i @@ -0,0 +1,30 @@ +/* -*- 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 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, + * Boston, MA 02110-1301, USA. + */ + +%{ +#include +%} + +enum gr_pdu_vector_type { BYTE, FLOAT, COMPLEX }; + + + diff --git a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc new file mode 100644 index 000000000..26c1babd6 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc @@ -0,0 +1,131 @@ +/* -*- 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, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +// public constructor that returns a shared_ptr + +gr_pdu_to_tagged_stream_sptr +gr_make_pdu_to_tagged_stream(gr_pdu_vector_type t) +{ + return gnuradio::get_initial_sptr(new gr_pdu_to_tagged_stream(t)); +} + +gr_pdu_to_tagged_stream::gr_pdu_to_tagged_stream (gr_pdu_vector_type t) + : gr_sync_block("pdu_to_tagged_stream", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(1, 1, gr_pdu_itemsize(t))), + d_vectortype(t), d_itemsize(gr_pdu_itemsize(t)) +{ + message_port_register_in(pdu_port_id); +} + +gr_pdu_to_tagged_stream::~gr_pdu_to_tagged_stream() +{ +} + +int +gr_pdu_to_tagged_stream::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + char *out = (char *) output_items[0]; + int nout = 0; + + // if we have remaining output, send it + if(d_remain.size() > 0){ + nout = std::min((size_t)d_remain.size()/d_itemsize, (size_t)noutput_items); + memcpy(out, &d_remain[0], nout*d_itemsize); + d_remain.erase( d_remain.begin(), d_remain.begin()+nout); + noutput_items -= nout; + out += nout*d_itemsize; + } + + // if we have space for at least one item output as much as we can + if(noutput_items > 0){ + + // grab a message if one exists + pmt::pmt_t msg( delete_head_nowait( pdu_port_id ) ); + if(msg.get() == NULL ){ + return nout; + } + + // make sure type is valid + if(!pmt::pmt_is_pair(msg)){ + throw std::runtime_error("received a malformed pdu message!"); + } + + printf("got a msg\n"); + pmt::pmt_print(msg); + + // grab the components of the pdu message + pmt::pmt_t meta(pmt::pmt_car(msg)); // make sure this is NIL || Dict ? + pmt::pmt_t vect(pmt::pmt_cdr(msg)); // make sure this is a vector? + + // compute offset for output tag + uint64_t offset = nitems_written(0) + nout; + + // add a tag for pdu length + add_item_tag(0, offset, pdu_length_tag, pmt::pmt_from_long( pmt::pmt_length(vect) ), pmt::mp(alias())); + + // if we recieved metadata add it as tags + if( !pmt_eq(meta, pmt::PMT_NIL) ){ + pmt::pmt_t pair(pmt::pmt_dict_keys( meta )); + while( !pmt_eq(pair, pmt::PMT_NIL) ){ + pmt::pmt_t k(pmt::pmt_cdr(pair)); + pmt::pmt_t v(pmt::pmt_dict_ref(meta, k, pmt::PMT_NIL)); + add_item_tag(0, offset, k, v, pmt::mp(alias())); + } + } + + // copy vector output + size_t ncopy = std::min((size_t)noutput_items, (size_t)pmt::pmt_length(vect)); + size_t nsave = pmt::pmt_length(vect) - ncopy; + + // copy output + size_t io(0); + nout += ncopy; + memcpy(out, pmt_uniform_vector_elements(vect,io), ncopy*d_itemsize); + + // save leftover items if needed for next work call + if(nsave > 0){ + d_remain.resize(nsave*d_itemsize, 0); + memcpy(&d_remain[0], pmt_uniform_vector_elements(vect,ncopy), nsave*d_itemsize); + } + + } + + return nout; +} diff --git a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.h b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.h new file mode 100644 index 000000000..3eb2a078b --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.h @@ -0,0 +1,63 @@ +/* -*- 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 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, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_PDU_TO_TAGGED_STREAM_H +#define INCLUDED_GR_PDU_TO_TAGGED_STREAM_H + +#include +#include +#include +#include +#include + +class gr_pdu_to_tagged_stream; +typedef boost::shared_ptr gr_pdu_to_tagged_stream_sptr; + +GR_CORE_API gr_pdu_to_tagged_stream_sptr gr_make_pdu_to_tagged_stream (gr_pdu_vector_type t); + +/*! + * \brief Turn received messages into a stream + * \ingroup source_blk + */ +class GR_CORE_API gr_pdu_to_tagged_stream : public gr_sync_block +{ + private: + gr_pdu_vector_type d_vectortype; + size_t d_itemsize; + std::vector d_remain; + + friend GR_CORE_API gr_pdu_to_tagged_stream_sptr + gr_make_pdu_to_tagged_stream(gr_pdu_vector_type t); + + protected: + gr_pdu_to_tagged_stream (gr_pdu_vector_type t); + + public: + ~gr_pdu_to_tagged_stream (); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + +}; + +#endif /* INCLUDED_GR_PDU_TO_TAGGED_SOURCE_H */ diff --git a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.i b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.i new file mode 100644 index 000000000..ddf1d8c05 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.i @@ -0,0 +1,31 @@ +/* -*- 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 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, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,pdu_to_tagged_stream); + +%{ +#include +%} + +%include + + diff --git a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc new file mode 100644 index 000000000..05ed8adc0 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc @@ -0,0 +1,139 @@ +/* -*- 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, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +// public constructor that returns a shared_ptr + +gr_tagged_stream_to_pdu_sptr +gr_make_tagged_stream_to_pdu(gr_pdu_vector_type t) +{ + return gnuradio::get_initial_sptr(new gr_tagged_stream_to_pdu(t)); +} + +gr_tagged_stream_to_pdu::gr_tagged_stream_to_pdu (gr_pdu_vector_type t) + : gr_sync_block("tagged_stream_to_pdu", + gr_make_io_signature(1, 1, gr_pdu_itemsize(t)), + gr_make_io_signature(0, 0, 0)), + d_vectortype(t), d_itemsize(gr_pdu_itemsize(t)), d_inpdu(false), + d_pdu_meta(pmt::PMT_NIL), d_pdu_vector(pmt::PMT_NIL) +{ + message_port_register_out(pdu_port_id); +} + +gr_tagged_stream_to_pdu::~gr_tagged_stream_to_pdu() +{ + printf("destructor running\n"); +} + +int +gr_tagged_stream_to_pdu::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const uint8_t *in = (const uint8_t*) input_items[0]; + uint64_t abs_N = nitems_read(0); + + // if we are not in a pdu already, start a new one + if(!d_inpdu){ + get_tags_in_range(d_tags, 0, abs_N, abs_N+1); + bool found_length_tag(false); + for(d_tags_itr = d_tags.begin(); (d_tags_itr != d_tags.end()) && (!found_length_tag); d_tags_itr++){ + if( pmt::pmt_equal( (*d_tags_itr).key, pdu_length_tag ) ){ + if( (*d_tags_itr).offset != abs_N ){ + throw std::runtime_error("expected next pdu length tag on a different item..."); + } + found_length_tag = true; + d_pdu_length = pmt::pmt_to_long( (*d_tags_itr).value ); + d_pdu_remain = d_pdu_length; + d_pdu_meta = pmt::pmt_make_dict(); + break; + } // if have length tag + } // iter over tags + if(!found_length_tag){ + throw std::runtime_error("tagged stream does not contain a pdu_length tag!"); + } + } + + size_t ncopy = std::min((size_t)noutput_items, d_pdu_remain); + + // copy any tags in this range into our meta object + get_tags_in_range(d_tags, 0, abs_N, abs_N+ncopy); + for(d_tags_itr = d_tags.begin(); d_tags_itr != d_tags.end(); d_tags_itr++){ + if( ! pmt_equal( (*d_tags_itr).key, pdu_length_tag ) ){ + d_pdu_meta = pmt_dict_add(d_pdu_meta, (*d_tags_itr).key, (*d_tags_itr).value); + } + } + + // copy samples for this vector into either a pmt or our save buffer + if(ncopy == d_pdu_remain){ // we will send this pdu + if(d_save.size() == 0){ + d_pdu_vector = gr_pdu_make_vector(d_vectortype, in, ncopy); + send_message(); + } else { + size_t oldsize = d_save.size(); + d_save.resize((oldsize + ncopy)*d_itemsize, 0); + memcpy( &d_save[oldsize*d_itemsize], in, ncopy*d_itemsize ); + d_pdu_vector = gr_pdu_make_vector(d_vectortype, &d_save[0], d_pdu_length); + send_message(); + d_save.clear(); + } + } else { + d_inpdu = true; + size_t oldsize = d_save.size(); + d_save.resize( (oldsize+ncopy)*d_itemsize ); + memcpy( &d_save[oldsize*d_itemsize], in, ncopy*d_itemsize ); + d_pdu_remain -= ncopy; + } + + return ncopy; +} + +void gr_tagged_stream_to_pdu::send_message(){ + + if(pmt::pmt_length(d_pdu_vector) != d_pdu_length){ + throw std::runtime_error("msg length not correct"); + } + + pmt::pmt_t msg = pmt::pmt_cons( d_pdu_meta, d_pdu_vector ); + message_port_pub( pdu_port_id, msg ); + + d_pdu_meta = pmt::PMT_NIL; + d_pdu_vector = pmt::PMT_NIL; + d_pdu_length = 0; + d_pdu_remain = 0; + d_inpdu = false; +} diff --git a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.h b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.h new file mode 100644 index 000000000..6a40e1c0c --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.h @@ -0,0 +1,76 @@ +/* -*- 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 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, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_TAGGED_STREAM_TO_PDU_H +#define INCLUDED_GR_TAGGED_STREAM_TO_PDU_H + +#include +#include +#include +#include +#include + +class gr_tagged_stream_to_pdu; +typedef boost::shared_ptr gr_tagged_stream_to_pdu_sptr; + +GR_CORE_API gr_tagged_stream_to_pdu_sptr gr_make_tagged_stream_to_pdu (gr_pdu_vector_type t); + +/*! + * \brief Turn received messages into a stream + * \ingroup source_blk + */ +class GR_CORE_API gr_tagged_stream_to_pdu : public gr_sync_block +{ + private: + gr_pdu_vector_type d_vectortype; + size_t d_itemsize; + + std::vector d_save; + + std::vector d_tags; + std::vector::iterator d_tags_itr; + + bool d_inpdu; + + size_t d_pdu_length; + size_t d_pdu_remain; + pmt::pmt_t d_pdu_meta; + pmt::pmt_t d_pdu_vector; + + friend GR_CORE_API gr_tagged_stream_to_pdu_sptr + gr_make_tagged_stream_to_pdu(gr_pdu_vector_type t); + + protected: + gr_tagged_stream_to_pdu (gr_pdu_vector_type t); + + public: + ~gr_tagged_stream_to_pdu (); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void send_message(); + +}; + +#endif /* INCLUDED_GR_PDU_TO_TAGGED_SOURCE_H */ diff --git a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.i b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.i new file mode 100644 index 000000000..66bd875aa --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.i @@ -0,0 +1,31 @@ +/* -*- 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 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, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,tagged_stream_to_pdu); + +%{ +#include +%} + +%include + + diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index 5cd352905..871ce1356 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -45,6 +45,10 @@ #include #include #include +#include +#include +#include +#include %} %include "gr_file_sink_base.i" @@ -67,4 +71,8 @@ %include "gr_wavfile_sink.i" %include "gr_wavfile_source.i" %include "gr_tagged_file_sink.i" +%include "gr_pdu_to_tagged_stream.i" +%include "gr_tagged_stream_to_pdu.i" +%include "gr_message_debug.i" +%include "gr_pdu.i" -- cgit From 6cc818260128df57c51a41e4e6aa459de5faf4fe Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Fri, 30 Nov 2012 22:31:43 -0800 Subject: core: gr_blocks can now have only message ports with no general_work() * msg only blocks now get thread context * added blocking msg queue delete call * added gr_message_strobe block * added grc definitions for message_debug, message_strobe, pdu_to_tagged_stream, tagged_stream_to_pdu. * allow message fan-in connections in GRC --- gnuradio-core/src/lib/io/gr_message_debug.cc | 4 +++- gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_message_debug.cc b/gnuradio-core/src/lib/io/gr_message_debug.cc index 84c11c46e..99f4a1f7b 100644 --- a/gnuradio-core/src/lib/io/gr_message_debug.cc +++ b/gnuradio-core/src/lib/io/gr_message_debug.cc @@ -44,8 +44,9 @@ gr_make_message_debug () } void gr_message_debug::print(pmt::pmt_t msg){ - std::cout << "******* DEBUG PRINT ********\n"; + std::cout << "******* MESSAGE DEBUG PRINT ********\n"; pmt::pmt_print(msg); + std::cout << "************************************\n"; } @@ -67,5 +68,6 @@ gr_message_debug::work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { + printf("gr_message_debug::work\n"); return 0; // FIXME: replace with default NOP work function in gr_block } diff --git a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc index 26c1babd6..06a1c9596 100644 --- a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc +++ b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc @@ -77,7 +77,8 @@ gr_pdu_to_tagged_stream::work(int noutput_items, if(noutput_items > 0){ // grab a message if one exists - pmt::pmt_t msg( delete_head_nowait( pdu_port_id ) ); + //pmt::pmt_t msg( delete_head_nowait( pdu_port_id ) ); + pmt::pmt_t msg( delete_head_blocking( pdu_port_id ) ); if(msg.get() == NULL ){ return nout; } @@ -87,8 +88,8 @@ gr_pdu_to_tagged_stream::work(int noutput_items, throw std::runtime_error("received a malformed pdu message!"); } - printf("got a msg\n"); - pmt::pmt_print(msg); +// printf("got a msg\n"); +// pmt::pmt_print(msg); // grab the components of the pdu message pmt::pmt_t meta(pmt::pmt_car(msg)); // make sure this is NIL || Dict ? -- cgit From 5dc1ccc01120a6f32f83f5e5fa79bc34b83f1619 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 1 Dec 2012 13:49:33 -0800 Subject: core: cleanup on pdu/msg blocks --- gnuradio-core/src/lib/io/gr_message_debug.cc | 17 +++------- gnuradio-core/src/lib/io/gr_message_debug.h | 12 +++----- gnuradio-core/src/lib/io/gr_message_debug.i | 2 +- gnuradio-core/src/lib/io/gr_pdu.cc | 36 +++++++++++++++++++--- gnuradio-core/src/lib/io/gr_pdu.h | 2 +- .../src/lib/io/gr_pdu_to_tagged_stream.cc | 2 +- gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.h | 4 +-- gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.i | 2 +- .../src/lib/io/gr_tagged_stream_to_pdu.cc | 12 +++----- gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.h | 4 +-- gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.i | 2 +- 11 files changed, 53 insertions(+), 42 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_message_debug.cc b/gnuradio-core/src/lib/io/gr_message_debug.cc index 99f4a1f7b..d98954576 100644 --- a/gnuradio-core/src/lib/io/gr_message_debug.cc +++ b/gnuradio-core/src/lib/io/gr_message_debug.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005,2010 Free Software Foundation, Inc. + * Copyright 2005,2010,2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -51,9 +51,9 @@ void gr_message_debug::print(pmt::pmt_t msg){ gr_message_debug::gr_message_debug () - : gr_sync_block("message_debug", - gr_make_io_signature(0, 0, 0), - gr_make_io_signature(0, 0, 0)) + : gr_block("message_debug", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(0, 0, 0)) { message_port_register_in(pmt::mp("print")); set_msg_handler(pmt::mp("print"), boost::bind(&gr_message_debug::print, this, _1)); @@ -62,12 +62,3 @@ gr_message_debug::gr_message_debug () gr_message_debug::~gr_message_debug() { } - -int -gr_message_debug::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - printf("gr_message_debug::work\n"); - return 0; // FIXME: replace with default NOP work function in gr_block -} diff --git a/gnuradio-core/src/lib/io/gr_message_debug.h b/gnuradio-core/src/lib/io/gr_message_debug.h index 37d8b7a4d..120694a91 100644 --- a/gnuradio-core/src/lib/io/gr_message_debug.h +++ b/gnuradio-core/src/lib/io/gr_message_debug.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2005,2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,7 +24,7 @@ #define INCLUDED_GR_MESSAGE_DEBUG_H #include -#include +#include #include #include @@ -34,10 +34,10 @@ typedef boost::shared_ptr gr_message_debug_sptr; GR_CORE_API gr_message_debug_sptr gr_make_message_debug (); /*! - * \brief Gather received items into messages and insert into msgq + * \brief Print received messages to stdout * \ingroup sink_blk */ -class GR_CORE_API gr_message_debug : public gr_sync_block +class GR_CORE_API gr_message_debug : public gr_block { private: friend GR_CORE_API gr_message_debug_sptr @@ -50,10 +50,6 @@ class GR_CORE_API gr_message_debug : public gr_sync_block public: ~gr_message_debug (); - - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); }; #endif /* INCLUDED_GR_MESSAGE_DEBUG_H */ diff --git a/gnuradio-core/src/lib/io/gr_message_debug.i b/gnuradio-core/src/lib/io/gr_message_debug.i index 7bd547c91..65d3bfc4a 100644 --- a/gnuradio-core/src/lib/io/gr_message_debug.i +++ b/gnuradio-core/src/lib/io/gr_message_debug.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/io/gr_pdu.cc b/gnuradio-core/src/lib/io/gr_pdu.cc index c5290b610..f33eed0a3 100644 --- a/gnuradio-core/src/lib/io/gr_pdu.cc +++ b/gnuradio-core/src/lib/io/gr_pdu.cc @@ -1,7 +1,33 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include -size_t gr_pdu_itemsize(gr_pdu_vector_type type){ +size_t +gr_pdu_itemsize(gr_pdu_vector_type type){ switch(type){ case BYTE: return 1; @@ -14,7 +40,8 @@ size_t gr_pdu_itemsize(gr_pdu_vector_type type){ } } -bool gr_pdu_type_matches(gr_pdu_vector_type type, pmt::pmt_t v){ +bool +gr_pdu_type_matches(gr_pdu_vector_type type, pmt::pmt_t v){ switch(type){ case BYTE: return pmt::pmt_is_u8vector(v); @@ -27,7 +54,8 @@ bool gr_pdu_type_matches(gr_pdu_vector_type type, pmt::pmt_t v){ } } -pmt::pmt_t gr_pdu_make_vector(gr_pdu_vector_type type, const uint8_t* buf, size_t items){ +pmt::pmt_t +gr_pdu_make_vector(gr_pdu_vector_type type, const uint8_t* buf, size_t items){ switch(type){ case BYTE: return pmt::pmt_init_u8vector(items, buf); @@ -39,5 +67,3 @@ pmt::pmt_t gr_pdu_make_vector(gr_pdu_vector_type type, const uint8_t* buf, size_ throw std::runtime_error("bad type!"); } } - - diff --git a/gnuradio-core/src/lib/io/gr_pdu.h b/gnuradio-core/src/lib/io/gr_pdu.h index 3bea83740..67519c89d 100644 --- a/gnuradio-core/src/lib/io/gr_pdu.h +++ b/gnuradio-core/src/lib/io/gr_pdu.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc index 06a1c9596..5c319dc39 100644 --- a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc +++ b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005,2010 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.h b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.h index 3eb2a078b..3105a3d38 100644 --- a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.h +++ b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -42,7 +42,7 @@ class GR_CORE_API gr_pdu_to_tagged_stream : public gr_sync_block { private: gr_pdu_vector_type d_vectortype; - size_t d_itemsize; + size_t d_itemsize; std::vector d_remain; friend GR_CORE_API gr_pdu_to_tagged_stream_sptr diff --git a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.i b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.i index ddf1d8c05..ec760b309 100644 --- a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.i +++ b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * diff --git a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc index 05ed8adc0..8211b7672 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005,2010 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -34,8 +34,6 @@ #include #include - - // public constructor that returns a shared_ptr gr_tagged_stream_to_pdu_sptr @@ -51,18 +49,18 @@ gr_tagged_stream_to_pdu::gr_tagged_stream_to_pdu (gr_pdu_vector_type t) d_vectortype(t), d_itemsize(gr_pdu_itemsize(t)), d_inpdu(false), d_pdu_meta(pmt::PMT_NIL), d_pdu_vector(pmt::PMT_NIL) { - message_port_register_out(pdu_port_id); + message_port_register_out(pdu_port_id); } gr_tagged_stream_to_pdu::~gr_tagged_stream_to_pdu() { - printf("destructor running\n"); + printf("destructor running\n"); } int gr_tagged_stream_to_pdu::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { const uint8_t *in = (const uint8_t*) input_items[0]; uint64_t abs_N = nitems_read(0); diff --git a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.h b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.h index 6a40e1c0c..c3fff3581 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.h +++ b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -42,7 +42,7 @@ class GR_CORE_API gr_tagged_stream_to_pdu : public gr_sync_block { private: gr_pdu_vector_type d_vectortype; - size_t d_itemsize; + size_t d_itemsize; std::vector d_save; diff --git a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.i b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.i index 66bd875aa..f12987b74 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.i +++ b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * -- cgit From 13139bb7dff0d543dfdb2cdaaa684a9fc5800cae Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 4 Dec 2012 16:54:47 -0500 Subject: core: adding a max segment size to metadata files. Automatically generates a new header after the MSS is reached. Also adds a metadata format version number (starting at 0). --- gnuradio-core/src/lib/io/gr_file_meta_sink.cc | 119 ++++++++++++++------------ gnuradio-core/src/lib/io/gr_file_meta_sink.h | 15 +++- gnuradio-core/src/lib/io/gr_file_meta_sink.i | 5 ++ 3 files changed, 84 insertions(+), 55 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc index 401d8299d..ebfeb4e4a 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc @@ -28,31 +28,32 @@ #include #include -#define HEADER_SIZE 117 - gr_file_meta_sink_sptr gr_make_file_meta_sink(size_t itemsize, const char *filename, double samp_rate, double relative_rate, gr_file_types type, bool complex, + size_t max_segment_size, const std::string &extra_dict) { return gnuradio::get_initial_sptr (new gr_file_meta_sink(itemsize, filename, samp_rate, relative_rate, type, complex, + max_segment_size, extra_dict)); } gr_file_meta_sink::gr_file_meta_sink(size_t itemsize, const char *filename, double samp_rate, double relative_rate, gr_file_types type, bool complex, + size_t max_segment_size, const std::string &extra_dict) : gr_sync_block("file_meta_sink", gr_make_io_signature(1, 1, itemsize), gr_make_io_signature(0, 0, 0)), gr_file_sink_base(filename, true), d_itemsize(itemsize), d_relative_rate(relative_rate), - d_total_seg_size(0) + d_max_seg_size(max_segment_size), d_total_seg_size(0) { if(!open(filename)) throw std::runtime_error("file_meta_sink: can't open file\n"); @@ -77,11 +78,12 @@ gr_file_meta_sink::gr_file_meta_sink(size_t itemsize, const char *filename, d_extra_size = pmt_serialize_str(d_extra).size(); d_header = pmt_make_dict(); + d_header = pmt_dict_add(d_header, mp("version"), mp(METADATA_VERSION)); d_header = pmt_dict_add(d_header, mp("rx_rate"), mp(samp_rate)); d_header = pmt_dict_add(d_header, mp("rx_time"), timestamp); d_header = pmt_dict_add(d_header, mp("type"), pmt_from_long(type)); d_header = pmt_dict_add(d_header, mp("cplx"), complex ? PMT_T : PMT_F); - d_header = pmt_dict_add(d_header, mp("strt"), pmt_from_uint64(HEADER_SIZE+d_extra_size)); + d_header = pmt_dict_add(d_header, mp("strt"), pmt_from_uint64(METADATA_HEADER_SIZE+d_extra_size)); d_header = pmt_dict_add(d_header, mp("size"), pmt_from_uint64(0)); write_header(d_header, d_extra); @@ -95,7 +97,7 @@ gr_file_meta_sink::write_header(pmt_t header, pmt_t extra) std::string header_str = pmt_serialize_str(header); std::string extra_str = pmt_serialize_str(extra); - if((header_str.size() != HEADER_SIZE) && (extra_str.size() != d_extra_size)) + if((header_str.size() != METADATA_HEADER_SIZE) && (extra_str.size() != d_extra_size)) throw std::runtime_error("file_meta_sink: header or extras is wrong size.\n"); size_t nwritten = 0; @@ -144,31 +146,63 @@ gr_file_meta_sink::update_header(pmt_t key, pmt_t value) } } +void +gr_file_meta_sink::update_last_header() +{ + // Update the last header info with the number of samples this + // block represents. + size_t seg_size = d_itemsize*d_total_seg_size; + uint64_t loc = get_last_header_loc(); + pmt_t s = pmt_from_uint64(seg_size); + //std::cerr << "Found Tag at: " << itr->offset*d_itemsize << std::endl; + //std::cerr << " last header starts at: " << loc << std::endl; + //std::cerr << " segment size is: " << seg_size << std::endl; + if(update_header(mp("size"), s)) { + fseek(d_fp, loc, SEEK_SET); + write_header(d_header, d_extra); + } +} + +void +gr_file_meta_sink::write_and_update() +{ + // New header, so set current size of chunk to 0 and start of chunk + // based on current index + header size. + uint64_t loc = get_last_header_loc(); + pmt_t s = pmt_from_uint64(0); + size_t seg_size = d_itemsize*d_total_seg_size; + if(update_header(mp("size"), s)) { + // If we have multiple tags on the same offset, this makes + // sure we just overwrite the same header each time instead + // of creating a new header per tag. + uint64_t seg_start = loc; + if(seg_size != 0) + seg_start += METADATA_HEADER_SIZE + d_extra_size + seg_size + 1; + s = pmt_from_uint64(seg_start + METADATA_HEADER_SIZE + d_extra_size); + if(update_header(mp("strt"), s)) { + //std::cerr << "Adding new header" << std::endl; + //std::cerr << " new header start at: " << seg_start-METADATA_HEADER_SIZE << std::endl; + //std::cerr << " new seg start at: " << seg_start << std::endl; + fseek(d_fp, seg_start, SEEK_SET); + write_header(d_header, d_extra); + d_total_seg_size = 0; + } + } +} + uint64_t gr_file_meta_sink::get_last_header_loc() { uint64_t loc = 0; pmt_t v = pmt_dict_ref(d_header, mp("strt"), PMT_NIL); if(!pmt_eq(v, PMT_NIL)) - loc = pmt_to_uint64(v) - (HEADER_SIZE+d_extra_size); + loc = pmt_to_uint64(v) - (METADATA_HEADER_SIZE+d_extra_size); return loc; } gr_file_meta_sink::~gr_file_meta_sink() { - // Replace the last header block with the final count of the number - // of items. - uint64_t loc = get_last_header_loc(); - uint64_t seg_size = nitems_read(0) * d_itemsize - d_total_seg_size; - pmt_t s = pmt_from_uint64(seg_size); - //std::cerr << "Destructor" << std::endl; - //std::cerr << " location of last header: " << loc << std::endl; - //std::cerr << " nitems_read: " << nitems_read(0)*d_itemsize << std::endl; - //std::cerr << " Segment Size: " << seg_size << std::endl; - if(update_header(mp("size"), s)) { - fseek(d_fp, loc, SEEK_SET); - write_header(d_header, d_extra); - } + update_last_header(); } int @@ -188,7 +222,7 @@ gr_file_meta_sink::work(int noutput_items, uint64_t end_N = abs_N + (uint64_t)(noutput_items); std::vector all_tags; get_tags_in_range(all_tags, 0, abs_N, end_N); - + std::vector::iterator itr; for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { // Special case where info is carried on the first tag, so we just @@ -200,50 +234,27 @@ gr_file_meta_sink::work(int noutput_items, } } else { - // Update the last header info with the number of samples this - // block represents. - uint64_t loc = get_last_header_loc(); - uint64_t seg_size = itr->offset * d_itemsize - d_total_seg_size; - pmt_t s = pmt_from_uint64(seg_size); - //std::cerr << "Found Tag at: " << itr->offset*d_itemsize << std::endl; - //std::cerr << " last header starts at: " << loc << std::endl; - //std::cerr << " segment size is: " << seg_size << std::endl; - if(update_header(mp("size"), s)) { - fseek(d_fp, loc, SEEK_SET); - write_header(d_header, d_extra); - } - + update_last_header(); if(update_header(itr->key, itr->value)) { - // Otherwise, set current size of chunk to 0 and start of - // chunk based on current index + header size. - d_total_seg_size += seg_size; - s = pmt_from_uint64(0); - if(update_header(mp("size"), s)) { - // If we have multiple tags on the same offset, this makes - // sure we just overwrite the same header each time instead - // of creating a new header per tag. - uint64_t seg_start = loc; - if(seg_size != 0) - seg_start += HEADER_SIZE + d_extra_size + seg_size + 1; - pmt_t s = pmt_from_uint64(seg_start + HEADER_SIZE + d_extra_size); - if(update_header(mp("strt"), s)) { - //std::cerr << "Adding new header" << std::endl; - //std::cerr << " new header start at: " << seg_start-HEADER_SIZE << std::endl; - //std::cerr << " new seg start at: " << seg_start << std::endl; - fseek(d_fp, seg_start, SEEK_SET); - write_header(d_header, d_extra); - } - } + write_and_update(); } } } while(nwritten < noutput_items) { - int count = fwrite(inbuf, d_itemsize, noutput_items - nwritten, d_fp); + size_t towrite = std::min(d_max_seg_size - d_total_seg_size, + (size_t)(noutput_items - nwritten)); + int count = fwrite(inbuf, d_itemsize, towrite, d_fp); if(count == 0) // FIXME add error handling break; nwritten += count; inbuf += count * d_itemsize; + + d_total_seg_size += count; + if(d_total_seg_size == d_max_seg_size) { + update_last_header(); + write_and_update(); + } } if(d_unbuffered) diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.h b/gnuradio-core/src/lib/io/gr_file_meta_sink.h index 9ba4878d1..f02c2c4ad 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.h @@ -30,6 +30,9 @@ using namespace pmt; +const char METADATA_VERSION = 0; +const size_t METADATA_HEADER_SIZE = 134; + enum gr_file_types { GR_FILE_BYTE=0, GR_FILE_CHAR=0, @@ -48,6 +51,7 @@ GR_CORE_API gr_file_meta_sink_sptr gr_make_file_meta_sink(size_t itemsize, const char *filename, double samp_rate=1, double relative_rate=1, gr_file_types type=GR_FILE_FLOAT, bool complex=true, + size_t max_segment_size=1000000, const std::string &extra_dict=""); /*! @@ -86,6 +90,8 @@ class GR_CORE_API gr_file_meta_sink : public gr_sync_block, public gr_file_sink_ * rate tag to sink. * \param type (gr_file_types): Data type (int, float, etc.) * \param complex (bool): If data stream is complex + * \param max_segment_size (size_t): Length of a single segment + * before the header is repeated (in items). * \param extra_dict (string): a serialized PMT dictionary of extra * information. Currently not supported. */ @@ -93,12 +99,14 @@ class GR_CORE_API gr_file_meta_sink : public gr_sync_block, public gr_file_sink_ gr_make_file_meta_sink(size_t itemsize, const char *filename, double samp_rate, double relative_rate, gr_file_types type, bool complex, + size_t max_segment_size, const std::string &extra_dict); private: size_t d_itemsize; double d_relative_rate; - uint64_t d_total_seg_size; + size_t d_max_seg_size; + size_t d_total_seg_size; pmt_t d_header; pmt_t d_extra; size_t d_extra_size; @@ -107,15 +115,20 @@ class GR_CORE_API gr_file_meta_sink : public gr_sync_block, public gr_file_sink_ gr_file_meta_sink(size_t itemsize, const char *filename, double samp_rate=1, double relative_rate=1, gr_file_types type=GR_FILE_FLOAT, bool complex=true, + size_t max_segment_size=1000000, const std::string &extra_dict=""); void write_header(pmt_t header, pmt_t extra); bool update_header(pmt_t key, pmt_t value); + void update_last_header(); + void write_and_update(); uint64_t get_last_header_loc(); public: ~gr_file_meta_sink(); + //FIXME: add setters/getters for properties. + int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.i b/gnuradio-core/src/lib/io/gr_file_meta_sink.i index b58a519ce..6cced3f38 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.i +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.i @@ -22,6 +22,9 @@ GR_SWIG_BLOCK_MAGIC(gr,file_meta_sink) +const char METADATA_VERSION = 0; +const size_t METADATA_HEADER_SIZE = 134; + enum gr_file_types { GR_FILE_BYTE=0, GR_FILE_CHAR=0, @@ -37,6 +40,7 @@ gr_file_meta_sink_sptr gr_make_file_meta_sink(size_t itemsize, const char *filename, double samp_rate=1, double relative_rate=1, gr_file_types type=GR_FILE_FLOAT, bool complex=true, + size_t max_segment_size=1000000, const std::string & extra_dict=""); class gr_file_meta_sink : public gr_sync_block, public gr_file_sink_base @@ -45,6 +49,7 @@ class gr_file_meta_sink : public gr_sync_block, public gr_file_sink_base gr_file_meta_sink(size_t itemsize, const char *filename, double samp_rate, double relative_rate, gr_file_types type, bool complex, + size_t max_segment_size, const std::string & extra_dict); public: -- cgit From 611959d2f9af4595200186acf85a64f5bf318fac Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 4 Dec 2012 18:36:35 -0500 Subject: core: updated metadata structure to use relative header info. Now the start tag info in the header is relative to the begining of the header (so, basically, the size of the header + extras). --- gnuradio-core/src/lib/io/gr_file_meta_sink.cc | 32 +++++---------------------- 1 file changed, 6 insertions(+), 26 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc index ebfeb4e4a..ff35a01fc 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc @@ -151,15 +151,13 @@ gr_file_meta_sink::update_last_header() { // Update the last header info with the number of samples this // block represents. + size_t hdrlen = METADATA_HEADER_SIZE+d_extra_size; size_t seg_size = d_itemsize*d_total_seg_size; - uint64_t loc = get_last_header_loc(); pmt_t s = pmt_from_uint64(seg_size); - //std::cerr << "Found Tag at: " << itr->offset*d_itemsize << std::endl; - //std::cerr << " last header starts at: " << loc << std::endl; - //std::cerr << " segment size is: " << seg_size << std::endl; if(update_header(mp("size"), s)) { - fseek(d_fp, loc, SEEK_SET); + fseek(d_fp, -seg_size-hdrlen, SEEK_CUR); write_header(d_header, d_extra); + fseek(d_fp, seg_size, SEEK_CUR); } } @@ -168,38 +166,19 @@ gr_file_meta_sink::write_and_update() { // New header, so set current size of chunk to 0 and start of chunk // based on current index + header size. - uint64_t loc = get_last_header_loc(); + //uint64_t loc = get_last_header_loc(); pmt_t s = pmt_from_uint64(0); - size_t seg_size = d_itemsize*d_total_seg_size; if(update_header(mp("size"), s)) { // If we have multiple tags on the same offset, this makes // sure we just overwrite the same header each time instead // of creating a new header per tag. - uint64_t seg_start = loc; - if(seg_size != 0) - seg_start += METADATA_HEADER_SIZE + d_extra_size + seg_size + 1; - s = pmt_from_uint64(seg_start + METADATA_HEADER_SIZE + d_extra_size); + s = pmt_from_uint64(METADATA_HEADER_SIZE + d_extra_size); if(update_header(mp("strt"), s)) { - //std::cerr << "Adding new header" << std::endl; - //std::cerr << " new header start at: " << seg_start-METADATA_HEADER_SIZE << std::endl; - //std::cerr << " new seg start at: " << seg_start << std::endl; - fseek(d_fp, seg_start, SEEK_SET); write_header(d_header, d_extra); - d_total_seg_size = 0; } } } -uint64_t -gr_file_meta_sink::get_last_header_loc() -{ - uint64_t loc = 0; - pmt_t v = pmt_dict_ref(d_header, mp("strt"), PMT_NIL); - if(!pmt_eq(v, PMT_NIL)) - loc = pmt_to_uint64(v) - (METADATA_HEADER_SIZE+d_extra_size); - return loc; -} - gr_file_meta_sink::~gr_file_meta_sink() { update_last_header(); @@ -254,6 +233,7 @@ gr_file_meta_sink::work(int noutput_items, if(d_total_seg_size == d_max_seg_size) { update_last_header(); write_and_update(); + d_total_seg_size = 0; } } -- cgit From 3ccdc6cd9469894dbf3ce34544b4ec21764456de Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 5 Dec 2012 12:45:30 -0500 Subject: core: Update metadata file sink to better handle tags in the right spot. --- gnuradio-core/src/lib/io/gr_file_meta_sink.cc | 46 +++++++++++++++++++++++++-- gnuradio-core/src/lib/io/gr_file_meta_sink.h | 1 - 2 files changed, 43 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc index ff35a01fc..e2b892efd 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc @@ -213,13 +213,53 @@ gr_file_meta_sink::work(int noutput_items, } } else { - update_last_header(); - if(update_header(itr->key, itr->value)) { - write_and_update(); + int item_offset = (int)(itr->offset - abs_N); + + std::cerr << "New tag found with absolute index: " << itr->offset + << " and relative index: " << item_offset << std::endl; + std::cerr << "Current segment size: " << d_total_seg_size << std::endl; + std::cerr << "Tag key: " << pmt_symbol_to_string(itr->key) << std::endl; + std::cerr << "Tag Val: "; + pmt_print(itr->value); + std::cerr << std::endl; + + // Write date to file up to the next tag location + while(nwritten < item_offset) { + size_t towrite = std::min(d_max_seg_size - d_total_seg_size, + (size_t)(item_offset - nwritten)); + int count = fwrite(inbuf, d_itemsize, towrite, d_fp); + if(count == 0) // FIXME add error handling + break; + nwritten += count; + inbuf += count * d_itemsize; + + d_total_seg_size += count; + + // Only add a new header if we are not at the position of the + // next tag + if((d_total_seg_size == d_max_seg_size) && + (nwritten < item_offset)) { + update_last_header(); + write_and_update(); + d_total_seg_size = 0; + } + } + + if(d_total_seg_size > 0) { + update_last_header(); + if(update_header(itr->key, itr->value)) { + write_and_update(); + d_total_seg_size = 0; + } + } + else { + if(update_header(itr->key, itr->value)) + update_last_header(); } } } + // Finish up the rest of the data after tags while(nwritten < noutput_items) { size_t towrite = std::min(d_max_seg_size - d_total_seg_size, (size_t)(noutput_items - nwritten)); diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.h b/gnuradio-core/src/lib/io/gr_file_meta_sink.h index f02c2c4ad..ed3a9f1db 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.h @@ -122,7 +122,6 @@ class GR_CORE_API gr_file_meta_sink : public gr_sync_block, public gr_file_sink_ bool update_header(pmt_t key, pmt_t value); void update_last_header(); void write_and_update(); - uint64_t get_last_header_loc(); public: ~gr_file_meta_sink(); -- cgit From 17c3f992bcd7b671e4e8c0a9dd13c582d256ced9 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 5 Dec 2012 13:26:50 -0500 Subject: core: Use sample and relative rate to update header based on num samples. When the max segment size is reached, we insert a new header. This updates the timestamp on that header based on the number of samples seen. --- gnuradio-core/src/lib/io/gr_file_meta_sink.cc | 44 +++++++++++++++++++-------- gnuradio-core/src/lib/io/gr_file_meta_sink.h | 2 ++ 2 files changed, 34 insertions(+), 12 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc index e2b892efd..f225e4409 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc @@ -51,8 +51,8 @@ gr_file_meta_sink::gr_file_meta_sink(size_t itemsize, const char *filename, : gr_sync_block("file_meta_sink", gr_make_io_signature(1, 1, itemsize), gr_make_io_signature(0, 0, 0)), - gr_file_sink_base(filename, true), - d_itemsize(itemsize), d_relative_rate(relative_rate), + gr_file_sink_base(filename, true), d_itemsize(itemsize), + d_samp_rate(samp_rate), d_relative_rate(relative_rate), d_max_seg_size(max_segment_size), d_total_seg_size(0) { if(!open(filename)) @@ -129,8 +129,8 @@ gr_file_meta_sink::update_header(pmt_t key, pmt_t value) // Special handling caveat to transform rate from radio source into // the rate at this sink. if(pmt_eq(key, mp("rx_rate"))) { - double rate = pmt_to_double(value); - value = pmt_from_double(rate*d_relative_rate); + d_samp_rate = pmt_to_double(value); + value = pmt_from_double(d_samp_rate*d_relative_rate); } if(pmt_dict_has_key(d_header, key)) { @@ -179,6 +179,32 @@ gr_file_meta_sink::write_and_update() } } +void +gr_file_meta_sink::update_rx_time() +{ + pmt_t rx_time = pmt_string_to_symbol("rx_time"); + pmt_t r = pmt_dict_ref(d_header, rx_time, PMT_NIL); + uint64_t secs = pmt_to_uint64(pmt_tuple_ref(r, 0)); + double fracs = pmt_to_double(pmt_tuple_ref(r, 1)); + double diff = d_total_seg_size / (d_samp_rate*d_relative_rate); + + //std::cerr << "old secs: " << secs << std::endl; + //std::cerr << "old fracs: " << fracs << std::endl; + //std::cerr << "seg size: " << d_total_seg_size << std::endl; + //std::cerr << "diff: " << diff << std::endl; + + fracs += diff; + uint64_t new_secs = static_cast(fracs); + secs += new_secs; + fracs -= new_secs; + + //std::cerr << "new secs: " << secs << std::endl; + //std::cerr << "new fracs: " << fracs << std::endl << std::endl; + + r = pmt_make_tuple(pmt_from_uint64(secs), pmt_from_double(fracs)); + d_header = pmt_dict_add(d_header, rx_time, r); +} + gr_file_meta_sink::~gr_file_meta_sink() { update_last_header(); @@ -215,14 +241,6 @@ gr_file_meta_sink::work(int noutput_items, else { int item_offset = (int)(itr->offset - abs_N); - std::cerr << "New tag found with absolute index: " << itr->offset - << " and relative index: " << item_offset << std::endl; - std::cerr << "Current segment size: " << d_total_seg_size << std::endl; - std::cerr << "Tag key: " << pmt_symbol_to_string(itr->key) << std::endl; - std::cerr << "Tag Val: "; - pmt_print(itr->value); - std::cerr << std::endl; - // Write date to file up to the next tag location while(nwritten < item_offset) { size_t towrite = std::min(d_max_seg_size - d_total_seg_size, @@ -240,6 +258,7 @@ gr_file_meta_sink::work(int noutput_items, if((d_total_seg_size == d_max_seg_size) && (nwritten < item_offset)) { update_last_header(); + update_rx_time(); write_and_update(); d_total_seg_size = 0; } @@ -272,6 +291,7 @@ gr_file_meta_sink::work(int noutput_items, d_total_seg_size += count; if(d_total_seg_size == d_max_seg_size) { update_last_header(); + update_rx_time(); write_and_update(); d_total_seg_size = 0; } diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.h b/gnuradio-core/src/lib/io/gr_file_meta_sink.h index ed3a9f1db..efe00c4e6 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.h @@ -104,6 +104,7 @@ class GR_CORE_API gr_file_meta_sink : public gr_sync_block, public gr_file_sink_ private: size_t d_itemsize; + double d_samp_rate; double d_relative_rate; size_t d_max_seg_size; size_t d_total_seg_size; @@ -122,6 +123,7 @@ class GR_CORE_API gr_file_meta_sink : public gr_sync_block, public gr_file_sink_ bool update_header(pmt_t key, pmt_t value); void update_last_header(); void write_and_update(); + void update_rx_time(); public: ~gr_file_meta_sink(); -- cgit From e8cf359e43f533fd3309389e5d62642f3080ac15 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 5 Dec 2012 14:03:03 -0500 Subject: core: update to metadata files to grow the extras dictionary when any tag is seen. --- gnuradio-core/src/lib/io/gr_file_meta_sink.cc | 59 +++++++++++++-------------- gnuradio-core/src/lib/io/gr_file_meta_sink.h | 2 +- 2 files changed, 29 insertions(+), 32 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc index f225e4409..da3be8060 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc @@ -123,7 +123,7 @@ gr_file_meta_sink::write_header(pmt_t header, pmt_t extra) } } -bool +void gr_file_meta_sink::update_header(pmt_t key, pmt_t value) { // Special handling caveat to transform rate from radio source into @@ -133,16 +133,17 @@ gr_file_meta_sink::update_header(pmt_t key, pmt_t value) value = pmt_from_double(d_samp_rate*d_relative_rate); } + // If the tag is not part of the standard header, we put it into the + // extra data, which either updates the current dictionary or adds a + // new item. if(pmt_dict_has_key(d_header, key)) { d_header = pmt_dict_add(d_header, key, value); - return true; - } - else if(pmt_dict_has_key(d_extra, key)) { - d_extra = pmt_dict_add(d_extra, key, value); - return true; } else { - return false; + d_extra = pmt_dict_add(d_extra, key, value); + d_extra_size = pmt_serialize_str(d_extra).size(); + d_header = pmt_dict_add(d_header, mp("strt"), + pmt_from_uint64(METADATA_HEADER_SIZE+d_extra_size)); } } @@ -154,11 +155,10 @@ gr_file_meta_sink::update_last_header() size_t hdrlen = METADATA_HEADER_SIZE+d_extra_size; size_t seg_size = d_itemsize*d_total_seg_size; pmt_t s = pmt_from_uint64(seg_size); - if(update_header(mp("size"), s)) { - fseek(d_fp, -seg_size-hdrlen, SEEK_CUR); - write_header(d_header, d_extra); - fseek(d_fp, seg_size, SEEK_CUR); - } + update_header(mp("size"), s); + fseek(d_fp, -seg_size-hdrlen, SEEK_CUR); + write_header(d_header, d_extra); + fseek(d_fp, seg_size, SEEK_CUR); } void @@ -168,15 +168,14 @@ gr_file_meta_sink::write_and_update() // based on current index + header size. //uint64_t loc = get_last_header_loc(); pmt_t s = pmt_from_uint64(0); - if(update_header(mp("size"), s)) { - // If we have multiple tags on the same offset, this makes - // sure we just overwrite the same header each time instead - // of creating a new header per tag. - s = pmt_from_uint64(METADATA_HEADER_SIZE + d_extra_size); - if(update_header(mp("strt"), s)) { - write_header(d_header, d_extra); - } - } + update_header(mp("size"), s); + + // If we have multiple tags on the same offset, this makes + // sure we just overwrite the same header each time instead + // of creating a new header per tag. + s = pmt_from_uint64(METADATA_HEADER_SIZE + d_extra_size); + update_header(mp("strt"), s); + write_header(d_header, d_extra); } void @@ -233,10 +232,9 @@ gr_file_meta_sink::work(int noutput_items, // Special case where info is carried on the first tag, so we just // overwrite the first header. if(itr->offset == 0) { - if(update_header(itr->key, itr->value)) { - fseek(d_fp, 0, SEEK_SET); - write_header(d_header, d_extra); - } + update_header(itr->key, itr->value); + fseek(d_fp, 0, SEEK_SET); + write_header(d_header, d_extra); } else { int item_offset = (int)(itr->offset - abs_N); @@ -266,14 +264,13 @@ gr_file_meta_sink::work(int noutput_items, if(d_total_seg_size > 0) { update_last_header(); - if(update_header(itr->key, itr->value)) { - write_and_update(); - d_total_seg_size = 0; - } + update_header(itr->key, itr->value); + write_and_update(); + d_total_seg_size = 0; } else { - if(update_header(itr->key, itr->value)) - update_last_header(); + update_header(itr->key, itr->value); + update_last_header(); } } } diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.h b/gnuradio-core/src/lib/io/gr_file_meta_sink.h index efe00c4e6..929c9634e 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.h @@ -120,7 +120,7 @@ class GR_CORE_API gr_file_meta_sink : public gr_sync_block, public gr_file_sink_ const std::string &extra_dict=""); void write_header(pmt_t header, pmt_t extra); - bool update_header(pmt_t key, pmt_t value); + void update_header(pmt_t key, pmt_t value); void update_last_header(); void write_and_update(); void update_rx_time(); -- cgit From 53be45f118e6e73d2a50fe0ba4622d6dfe96117c Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 6 Dec 2012 12:52:35 -0500 Subject: core: updated the message debug block to have a 'store' port where messages can be retrieved afterwards. Updated qa_pdu to use the new 'store' port for testing the resulting message. --- gnuradio-core/src/lib/io/gr_message_debug.cc | 39 +++++++++++++++++++--- gnuradio-core/src/lib/io/gr_message_debug.h | 49 +++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 6 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_message_debug.cc b/gnuradio-core/src/lib/io/gr_message_debug.cc index d98954576..7d28ff18e 100644 --- a/gnuradio-core/src/lib/io/gr_message_debug.cc +++ b/gnuradio-core/src/lib/io/gr_message_debug.cc @@ -43,20 +43,49 @@ gr_make_message_debug () return gnuradio::get_initial_sptr(new gr_message_debug()); } -void gr_message_debug::print(pmt::pmt_t msg){ - std::cout << "******* MESSAGE DEBUG PRINT ********\n"; - pmt::pmt_print(msg); - std::cout << "************************************\n"; +void +gr_message_debug::print(pmt::pmt_t msg) +{ + std::cout << "******* MESSAGE DEBUG PRINT ********\n"; + pmt::pmt_print(msg); + std::cout << "************************************\n"; +} + +void +gr_message_debug::store(pmt::pmt_t msg) +{ + gruel::scoped_lock guard(d_mutex); + d_messages.push_back(msg); +} + +int +gr_message_debug::num_messages() +{ + return (int)d_messages.size(); } +pmt::pmt_t +gr_message_debug::get_message(int i) +{ + gruel::scoped_lock guard(d_mutex); + + if((size_t)i >= d_messages.size()) { + throw std::runtime_error("gr_message_debug: index for message out of bounds.\n"); + } -gr_message_debug::gr_message_debug () + return d_messages[i]; +} + +gr_message_debug::gr_message_debug() : gr_block("message_debug", gr_make_io_signature(0, 0, 0), gr_make_io_signature(0, 0, 0)) { message_port_register_in(pmt::mp("print")); set_msg_handler(pmt::mp("print"), boost::bind(&gr_message_debug::print, this, _1)); + + message_port_register_in(pmt::mp("store")); + set_msg_handler(pmt::mp("store"), boost::bind(&gr_message_debug::store, this, _1)); } gr_message_debug::~gr_message_debug() diff --git a/gnuradio-core/src/lib/io/gr_message_debug.h b/gnuradio-core/src/lib/io/gr_message_debug.h index 120694a91..1ffef1b02 100644 --- a/gnuradio-core/src/lib/io/gr_message_debug.h +++ b/gnuradio-core/src/lib/io/gr_message_debug.h @@ -27,11 +27,12 @@ #include #include #include +#include class gr_message_debug; typedef boost::shared_ptr gr_message_debug_sptr; -GR_CORE_API gr_message_debug_sptr gr_make_message_debug (); +GR_CORE_API gr_message_debug_sptr gr_make_message_debug(); /*! * \brief Print received messages to stdout @@ -43,13 +44,59 @@ class GR_CORE_API gr_message_debug : public gr_block friend GR_CORE_API gr_message_debug_sptr gr_make_message_debug(); + /*! + * \brief Messages received in this port are printed to stdout. + * + * This port receives messages from the scheduler's message handling + * mechanism and prints it to stdout. This message handler function + * is only meant to be used by the scheduler to handle messages + * posted to port 'print'. + * + * \param msg A pmt message passed from the scheduler's message handling. + */ void print(pmt::pmt_t msg); + /*! + * \brief Messages received in this port are stored in a vector. + * + * This port receives messages from the scheduler's message handling + * mechanism and stores it in a vector. Messages can be retrieved + * later using the 'get_message' function. This message handler + * function is only meant to be used by the scheduler to handle + * messages posted to port 'store'. + * + * \param msg A pmt message passed from the scheduler's message handling. + */ + void store(pmt::pmt_t msg); + + gruel::mutex d_mutex; + std::vector d_messages; + protected: gr_message_debug (); public: ~gr_message_debug (); + + /*! + * \brief Reports the number of messages received by this block. + */ + int num_messages(); + + /*! + * \brief Get a message (as a PMT) from the message vector at index \p i. + * + * Messages passed to the 'store' port will be stored in a + * vector. This function retrieves those messages by index. They are + * index in order of when they were received (all messages are just + * pushed onto the back of a vector). This is mostly useful in + * debugging message passing graphs and in QA code. + * + * \param i The index in the vector for the message to retrieve. + * + * \return a message at index \p i as a pmt_t. + */ + pmt::pmt_t get_message(int i); }; #endif /* INCLUDED_GR_MESSAGE_DEBUG_H */ -- cgit From 619a167471d060e2f1b49a9aac55a23b327afa88 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 7 Dec 2012 12:11:46 -0500 Subject: core: metadata file sink can set detached header. This breaks away from subclassing gr_file_sink_base since we have to keep track of two files. --- gnuradio-core/src/lib/io/gr_file_meta_sink.cc | 280 ++++++++++++++++++++------ gnuradio-core/src/lib/io/gr_file_meta_sink.h | 41 +++- gnuradio-core/src/lib/io/gr_file_meta_sink.i | 6 +- gnuradio-core/src/lib/io/gr_file_sink_base.cc | 4 + 4 files changed, 261 insertions(+), 70 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc index da3be8060..43900bcd9 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc @@ -26,35 +26,70 @@ #include #include +#include +#include +#include +#include #include +// win32 (mingw/msvc) specific +#ifdef HAVE_IO_H +#include +#endif +#ifdef O_BINARY +#define OUR_O_BINARY O_BINARY +#else +#define OUR_O_BINARY 0 +#endif + +// should be handled via configure +#ifdef O_LARGEFILE +#define OUR_O_LARGEFILE O_LARGEFILE +#else +#define OUR_O_LARGEFILE 0 +#endif + gr_file_meta_sink_sptr gr_make_file_meta_sink(size_t itemsize, const char *filename, double samp_rate, double relative_rate, gr_file_types type, bool complex, size_t max_segment_size, - const std::string &extra_dict) + const std::string &extra_dict, + bool detached_header) { return gnuradio::get_initial_sptr (new gr_file_meta_sink(itemsize, filename, samp_rate, relative_rate, type, complex, max_segment_size, - extra_dict)); + extra_dict, + detached_header)); } gr_file_meta_sink::gr_file_meta_sink(size_t itemsize, const char *filename, double samp_rate, double relative_rate, gr_file_types type, bool complex, size_t max_segment_size, - const std::string &extra_dict) + const std::string &extra_dict, + bool detached_header) : gr_sync_block("file_meta_sink", gr_make_io_signature(1, 1, itemsize), gr_make_io_signature(0, 0, 0)), - gr_file_sink_base(filename, true), d_itemsize(itemsize), + d_itemsize(itemsize), d_samp_rate(samp_rate), d_relative_rate(relative_rate), - d_max_seg_size(max_segment_size), d_total_seg_size(0) + d_max_seg_size(max_segment_size), d_total_seg_size(0), + d_updated(false), d_unbuffered(false) { + d_fp = 0; + d_new_fp = 0; + d_hdr_fp = 0; + d_new_hdr_fp = 0; + + if(detached_header == true) + d_state = STATE_DETACHED; + else + d_state = STATE_INLINE; + if(!open(filename)) throw std::runtime_error("file_meta_sink: can't open file\n"); @@ -86,14 +121,120 @@ gr_file_meta_sink::gr_file_meta_sink(size_t itemsize, const char *filename, d_header = pmt_dict_add(d_header, mp("strt"), pmt_from_uint64(METADATA_HEADER_SIZE+d_extra_size)); d_header = pmt_dict_add(d_header, mp("size"), pmt_from_uint64(0)); - write_header(d_header, d_extra); + do_update(); + + if(d_state == STATE_DETACHED) + write_header(d_hdr_fp, d_header, d_extra); + else + write_header(d_fp, d_header, d_extra); +} + +gr_file_meta_sink::~gr_file_meta_sink() +{ + update_last_header(); + + close(); + + if(d_fp) { + fclose(d_fp); + d_fp = 0; + } + + if(d_state == STATE_DETACHED) { + if(d_hdr_fp) { + fclose(d_hdr_fp); + d_hdr_fp = 0; + } + } +} + +bool +gr_file_meta_sink::open(const char *filename) +{ + bool ret = true; + if(d_state == STATE_DETACHED) { + std::stringstream s; + s << filename << ".hdr"; + ret = _open(&d_new_hdr_fp, s.str().c_str()); + } + + ret = ret && _open(&d_new_fp, filename); + d_updated = true; + return ret; +} + +bool +gr_file_meta_sink::_open(FILE **fp, const char *filename) +{ + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function + + bool ret = true; + int fd; + + if((fd = ::open(filename, + O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY, + 0664)) < 0){ + perror(filename); + return false; + } + + if(*fp) { // if we've already got a new one open, close it + fclose(*fp); + fp = 0; + } + + if((*fp = fdopen(fd, "wb")) == NULL) { + perror(filename); + ::close(fd); // don't leak file descriptor if fdopen fails. + } + + ret = fp != 0; + + return ret; } void -gr_file_meta_sink::write_header(pmt_t header, pmt_t extra) +gr_file_meta_sink::close() { - do_update(); + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function + if(d_state == STATE_DETACHED) { + if(d_new_hdr_fp) { + fclose(d_new_hdr_fp); + d_new_hdr_fp = 0; + } + } + + if(d_new_fp) { + fclose(d_new_fp); + d_new_fp = 0; + } + d_updated = true; +} + +void +gr_file_meta_sink::do_update() +{ + if(d_updated) { + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this block + if(d_state == STATE_DETACHED) { + if(d_hdr_fp) + fclose(d_hdr_fp); + d_hdr_fp = d_new_hdr_fp; // install new file pointer + d_new_hdr_fp = 0; + } + if(d_fp) + fclose(d_fp); + d_fp = d_new_fp; // install new file pointer + d_new_fp = 0; + + d_updated = false; + } +} + +void +gr_file_meta_sink::write_header(FILE *fp, pmt_t header, pmt_t extra) +{ std::string header_str = pmt_serialize_str(header); std::string extra_str = pmt_serialize_str(extra); @@ -103,10 +244,10 @@ gr_file_meta_sink::write_header(pmt_t header, pmt_t extra) size_t nwritten = 0; while(nwritten < header_str.size()) { std::string sub = header_str.substr(nwritten); - int count = fwrite(sub.c_str(), sizeof(char), sub.size(), d_fp); + int count = fwrite(sub.c_str(), sizeof(char), sub.size(), fp); nwritten += count; - if((count == 0) && (ferror(d_fp))) { - fclose(d_fp); + if((count == 0) && (ferror(fp))) { + fclose(fp); throw std::runtime_error("file_meta_sink: error writing header to file.\n"); } } @@ -114,10 +255,10 @@ gr_file_meta_sink::write_header(pmt_t header, pmt_t extra) nwritten = 0; while(nwritten < extra_str.size()) { std::string sub = extra_str.substr(nwritten); - int count = fwrite(sub.c_str(), sizeof(char), sub.size(), d_fp); + int count = fwrite(sub.c_str(), sizeof(char), sub.size(), fp); nwritten += count; - if((count == 0) && (ferror(d_fp))) { - fclose(d_fp); + if((count == 0) && (ferror(fp))) { + fclose(fp); throw std::runtime_error("file_meta_sink: error writing extra to file.\n"); } } @@ -142,25 +283,48 @@ gr_file_meta_sink::update_header(pmt_t key, pmt_t value) else { d_extra = pmt_dict_add(d_extra, key, value); d_extra_size = pmt_serialize_str(d_extra).size(); - d_header = pmt_dict_add(d_header, mp("strt"), - pmt_from_uint64(METADATA_HEADER_SIZE+d_extra_size)); } } void gr_file_meta_sink::update_last_header() +{ + if(d_state == STATE_DETACHED) + update_last_header_detached(); + else + update_last_header_inline(); +} + +void +gr_file_meta_sink::update_last_header_inline() { // Update the last header info with the number of samples this // block represents. - size_t hdrlen = METADATA_HEADER_SIZE+d_extra_size; + + size_t hdrlen = pmt_to_uint64(pmt_dict_ref(d_header, mp("strt"), PMT_NIL)); size_t seg_size = d_itemsize*d_total_seg_size; pmt_t s = pmt_from_uint64(seg_size); update_header(mp("size"), s); + update_header(mp("strt"), pmt_from_uint64(METADATA_HEADER_SIZE+d_extra_size)); fseek(d_fp, -seg_size-hdrlen, SEEK_CUR); - write_header(d_header, d_extra); + write_header(d_fp, d_header, d_extra); fseek(d_fp, seg_size, SEEK_CUR); } +void +gr_file_meta_sink::update_last_header_detached() +{ + // Update the last header info with the number of samples this + // block represents. + size_t hdrlen = pmt_to_uint64(pmt_dict_ref(d_header, mp("strt"), PMT_NIL)); + size_t seg_size = d_itemsize*d_total_seg_size; + pmt_t s = pmt_from_uint64(seg_size); + update_header(mp("size"), s); + update_header(mp("strt"), pmt_from_uint64(METADATA_HEADER_SIZE+d_extra_size)); + fseek(d_hdr_fp, -hdrlen, SEEK_CUR); + write_header(d_hdr_fp, d_header, d_extra); +} + void gr_file_meta_sink::write_and_update() { @@ -175,7 +339,11 @@ gr_file_meta_sink::write_and_update() // of creating a new header per tag. s = pmt_from_uint64(METADATA_HEADER_SIZE + d_extra_size); update_header(mp("strt"), s); - write_header(d_header, d_extra); + + if(d_state == STATE_DETACHED) + write_header(d_hdr_fp, d_header, d_extra); + else + write_header(d_fp, d_header, d_extra); } void @@ -204,11 +372,6 @@ gr_file_meta_sink::update_rx_time() d_header = pmt_dict_add(d_header, rx_time, r); } -gr_file_meta_sink::~gr_file_meta_sink() -{ - update_last_header(); -} - int gr_file_meta_sink::work(int noutput_items, gr_vector_const_void_star &input_items, @@ -229,49 +392,40 @@ gr_file_meta_sink::work(int noutput_items, std::vector::iterator itr; for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { - // Special case where info is carried on the first tag, so we just - // overwrite the first header. - if(itr->offset == 0) { - update_header(itr->key, itr->value); - fseek(d_fp, 0, SEEK_SET); - write_header(d_header, d_extra); - } - else { - int item_offset = (int)(itr->offset - abs_N); - - // Write date to file up to the next tag location - while(nwritten < item_offset) { - size_t towrite = std::min(d_max_seg_size - d_total_seg_size, - (size_t)(item_offset - nwritten)); - int count = fwrite(inbuf, d_itemsize, towrite, d_fp); - if(count == 0) // FIXME add error handling - break; - nwritten += count; - inbuf += count * d_itemsize; - - d_total_seg_size += count; - - // Only add a new header if we are not at the position of the - // next tag - if((d_total_seg_size == d_max_seg_size) && - (nwritten < item_offset)) { - update_last_header(); - update_rx_time(); - write_and_update(); - d_total_seg_size = 0; - } - } - - if(d_total_seg_size > 0) { + int item_offset = (int)(itr->offset - abs_N); + + // Write date to file up to the next tag location + while(nwritten < item_offset) { + size_t towrite = std::min(d_max_seg_size - d_total_seg_size, + (size_t)(item_offset - nwritten)); + int count = fwrite(inbuf, d_itemsize, towrite, d_fp); + if(count == 0) // FIXME add error handling + break; + nwritten += count; + inbuf += count * d_itemsize; + + d_total_seg_size += count; + + // Only add a new header if we are not at the position of the + // next tag + if((d_total_seg_size == d_max_seg_size) && + (nwritten < item_offset)) { update_last_header(); - update_header(itr->key, itr->value); + update_rx_time(); write_and_update(); d_total_seg_size = 0; } - else { - update_header(itr->key, itr->value); - update_last_header(); - } + } + + if(d_total_seg_size > 0) { + update_last_header(); + update_header(itr->key, itr->value); + write_and_update(); + d_total_seg_size = 0; + } + else { + update_header(itr->key, itr->value); + update_last_header(); } } diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.h b/gnuradio-core/src/lib/io/gr_file_meta_sink.h index 929c9634e..c0636d66a 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.h @@ -52,7 +52,8 @@ gr_make_file_meta_sink(size_t itemsize, const char *filename, double samp_rate=1, double relative_rate=1, gr_file_types type=GR_FILE_FLOAT, bool complex=true, size_t max_segment_size=1000000, - const std::string &extra_dict=""); + const std::string &extra_dict="", + bool detached_header=false); /*! * \brief Write stream to file with meta-data headers. @@ -76,7 +77,7 @@ gr_make_file_meta_sink(size_t itemsize, const char *filename, * segment starts plus the data segment size. Following will either be * a new header or EOF. */ -class GR_CORE_API gr_file_meta_sink : public gr_sync_block, public gr_file_sink_base +class GR_CORE_API gr_file_meta_sink : public gr_sync_block { /*! * \brief Create a meta-data file sink. @@ -94,15 +95,24 @@ class GR_CORE_API gr_file_meta_sink : public gr_sync_block, public gr_file_sink_ * before the header is repeated (in items). * \param extra_dict (string): a serialized PMT dictionary of extra * information. Currently not supported. + * \param detached_header (bool): Set to true to store the header + * info in a separate file (named filename.hdr) */ friend GR_CORE_API gr_file_meta_sink_sptr gr_make_file_meta_sink(size_t itemsize, const char *filename, double samp_rate, double relative_rate, gr_file_types type, bool complex, size_t max_segment_size, - const std::string &extra_dict); + const std::string &extra_dict, + bool detached_header); private: + enum meta_state_t { + STATE_INLINE=0, + STATE_DETACHED + }; + + size_t d_itemsize; double d_samp_rate; double d_relative_rate; @@ -111,23 +121,44 @@ class GR_CORE_API gr_file_meta_sink : public gr_sync_block, public gr_file_sink_ pmt_t d_header; pmt_t d_extra; size_t d_extra_size; + bool d_updated; + bool d_unbuffered; + + boost::mutex d_mutex; + FILE *d_new_fp, *d_new_hdr_fp; + FILE *d_fp, *d_hdr_fp; + meta_state_t d_state; protected: gr_file_meta_sink(size_t itemsize, const char *filename, double samp_rate=1, double relative_rate=1, gr_file_types type=GR_FILE_FLOAT, bool complex=true, size_t max_segment_size=1000000, - const std::string &extra_dict=""); + const std::string &extra_dict="", + bool detached_header=false); - void write_header(pmt_t header, pmt_t extra); + void write_header(FILE *fp, pmt_t header, pmt_t extra); void update_header(pmt_t key, pmt_t value); void update_last_header(); + void update_last_header_inline(); + void update_last_header_detached(); void write_and_update(); void update_rx_time(); + bool _open(FILE **fp, const char *filename); + public: ~gr_file_meta_sink(); + bool open(const char *filename); + void close(); + void do_update(); + + void set_unbuffered(bool unbuffered) + { + d_unbuffered = unbuffered; + } + //FIXME: add setters/getters for properties. int work(int noutput_items, diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.i b/gnuradio-core/src/lib/io/gr_file_meta_sink.i index 6cced3f38..ed3eda0f8 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.i +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.i @@ -41,7 +41,8 @@ gr_make_file_meta_sink(size_t itemsize, const char *filename, double samp_rate=1, double relative_rate=1, gr_file_types type=GR_FILE_FLOAT, bool complex=true, size_t max_segment_size=1000000, - const std::string & extra_dict=""); + const std::string & extra_dict="", + bool detached_header=false); class gr_file_meta_sink : public gr_sync_block, public gr_file_sink_base { @@ -50,7 +51,8 @@ class gr_file_meta_sink : public gr_sync_block, public gr_file_sink_base double samp_rate, double relative_rate, gr_file_types type, bool complex, size_t max_segment_size, - const std::string & extra_dict); + const std::string & extra_dict, + bool detached_header); public: ~gr_file_meta_sink(); diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.cc b/gnuradio-core/src/lib/io/gr_file_sink_base.cc index b2dcc1be5..cb67bbb6c 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.cc @@ -79,6 +79,8 @@ gr_file_sink_base::open(const char *filename) perror (filename); return false; } + std::cerr << "OPENING NEW FILE: " << filename << std::endl; + std::cerr << "FD: " << fd << std::endl; if (d_new_fp){ // if we've already got a new one open, close it fclose(d_new_fp); @@ -90,6 +92,8 @@ gr_file_sink_base::open(const char *filename) ::close(fd); // don't leak file descriptor if fdopen fails. } + std::cerr << "D_NEW_FD: " << d_new_fp << std::endl; + d_updated = true; return d_new_fp != 0; } -- cgit From 52ca5e2765b7a4532d26502b5b76b7c85c5019d7 Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Fri, 7 Dec 2012 09:28:41 -0800 Subject: core: added gr_tuntap_pdu, gr_socket_pdu, and msg passing enhancements --- gnuradio-core/src/lib/io/CMakeLists.txt | 4 + gnuradio-core/src/lib/io/gr_message_debug.cc | 34 ++++- gnuradio-core/src/lib/io/gr_message_debug.h | 1 + gnuradio-core/src/lib/io/gr_pdu.cc | 70 +++++---- gnuradio-core/src/lib/io/gr_pdu.h | 1 + gnuradio-core/src/lib/io/gr_socket_pdu.cc | 157 +++++++++++++++++++ gnuradio-core/src/lib/io/gr_socket_pdu.h | 203 +++++++++++++++++++++++++ gnuradio-core/src/lib/io/gr_socket_pdu.i | 33 ++++ gnuradio-core/src/lib/io/gr_stream_pdu_base.cc | 117 ++++++++++++++ gnuradio-core/src/lib/io/gr_stream_pdu_base.h | 62 ++++++++ gnuradio-core/src/lib/io/gr_tuntap_pdu.cc | 143 +++++++++++++++++ gnuradio-core/src/lib/io/gr_tuntap_pdu.h | 66 ++++++++ gnuradio-core/src/lib/io/gr_tuntap_pdu.i | 30 ++++ gnuradio-core/src/lib/io/io.i | 5 + 14 files changed, 891 insertions(+), 35 deletions(-) create mode 100644 gnuradio-core/src/lib/io/gr_socket_pdu.cc create mode 100644 gnuradio-core/src/lib/io/gr_socket_pdu.h create mode 100644 gnuradio-core/src/lib/io/gr_socket_pdu.i create mode 100644 gnuradio-core/src/lib/io/gr_stream_pdu_base.cc create mode 100644 gnuradio-core/src/lib/io/gr_stream_pdu_base.h create mode 100644 gnuradio-core/src/lib/io/gr_tuntap_pdu.cc create mode 100644 gnuradio-core/src/lib/io/gr_tuntap_pdu.h create mode 100644 gnuradio-core/src/lib/io/gr_tuntap_pdu.i (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/CMakeLists.txt b/gnuradio-core/src/lib/io/CMakeLists.txt index 7041f2820..59ca06b5a 100644 --- a/gnuradio-core/src/lib/io/CMakeLists.txt +++ b/gnuradio-core/src/lib/io/CMakeLists.txt @@ -39,6 +39,7 @@ list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/ppio_ppdev.cc ${CMAKE_CURRENT_SOURCE_DIR}/gri_wavfile.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_pdu.cc + ${CMAKE_CURRENT_SOURCE_DIR}/gr_stream_pdu_base.cc ) ######################################################################## @@ -61,6 +62,7 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/ppio_ppdev.h ${CMAKE_CURRENT_SOURCE_DIR}/gri_wavfile.h ${CMAKE_CURRENT_SOURCE_DIR}/gr_pdu.h + ${CMAKE_CURRENT_SOURCE_DIR}/gr_stream_pdu_base.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio COMPONENT "core_devel" ) @@ -103,6 +105,8 @@ set(gr_core_io_triple_threats gr_wavfile_sink gr_tagged_file_sink gr_tagged_stream_to_pdu + gr_tuntap_pdu + gr_socket_pdu ) foreach(file_tt ${gr_core_io_triple_threats}) diff --git a/gnuradio-core/src/lib/io/gr_message_debug.cc b/gnuradio-core/src/lib/io/gr_message_debug.cc index 7d28ff18e..27f4c65fd 100644 --- a/gnuradio-core/src/lib/io/gr_message_debug.cc +++ b/gnuradio-core/src/lib/io/gr_message_debug.cc @@ -58,6 +58,30 @@ gr_message_debug::store(pmt::pmt_t msg) d_messages.push_back(msg); } +void +gr_message_debug::print_verbose(pmt::pmt_t msg) +{ + pmt::pmt_t meta = pmt::pmt_car(msg); + pmt::pmt_t vector = pmt::pmt_cdr(msg); + std::cout << "* MESSAGE DEBUG PRINT PDU VERBOSE *\n"; + pmt::pmt_print(meta); + size_t len = pmt::pmt_length(vector); + std::cout << "pdu_length = " << len << std::endl; + std::cout << "contents = " << std::endl; + size_t offset(0); + const uint8_t* d = (const uint8_t*) pmt_uniform_vector_elements(vector, offset); + for(size_t i=0; i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// public constructor that returns a shared_ptr +gr_socket_pdu_sptr +gr_make_socket_pdu (std::string type, std::string addr, std::string port, int MTU) +{ + return gnuradio::get_initial_sptr(new gr_socket_pdu(type,addr,port,MTU)); +} + +gr_socket_pdu::gr_socket_pdu (std::string type, std::string addr, std::string port, int MTU) + : gr_stream_pdu_base(MTU) +{ + + if( (type == "TCP_SERVER") || (type == "TCP_CLIENT")){ + boost::asio::ip::tcp::resolver resolver(_io_service); + boost::asio::ip::tcp::resolver::query query(boost::asio::ip::tcp::v4(), addr, port); + _tcp_endpoint = *resolver.resolve(query); + } + if( (type == "UDP_SERVER") || (type == "UDP_CLIENT")){ + boost::asio::ip::udp::resolver resolver(_io_service); + boost::asio::ip::udp::resolver::query query(boost::asio::ip::udp::v4(), addr, port); + if( (type == "UDP_SERVER") ){ + _udp_endpoint = *resolver.resolve(query); + } else { + _udp_endpoint_other = *resolver.resolve(query); + } + } + + // register ports + message_port_register_out(pmt::mp("pdus")); + message_port_register_in(pmt::mp("pdus")); + + // set up socketry + if (type == "TCP_SERVER"){ + _acceptor_tcp.reset(new boost::asio::ip::tcp::acceptor(_io_service, _tcp_endpoint)); + _acceptor_tcp->set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); + start_tcp_accept(); + // bind tcp server send handler + set_msg_handler(pmt::mp("pdus"), boost::bind(&gr_socket_pdu::tcp_server_send, this, _1)); + } else if(type =="TCP_CLIENT"){ + boost::system::error_code error = boost::asio::error::host_not_found; + _tcp_socket.reset(new boost::asio::ip::tcp::socket(_io_service)); + _tcp_socket->connect(_tcp_endpoint, error); + if(error){ + throw boost::system::system_error(error); + } + set_msg_handler(pmt::mp("pdus"), boost::bind(&gr_socket_pdu::tcp_client_send, this, _1)); + _tcp_socket->async_read_some( + boost::asio::buffer(rxbuf), + boost::bind(&gr_socket_pdu::handle_tcp_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); + + } else if(type =="UDP_SERVER"){ + _udp_socket.reset(new boost::asio::ip::udp::socket(_io_service, _udp_endpoint)); + _udp_socket->async_receive_from( boost::asio::buffer(rxbuf), _udp_endpoint_other, + boost::bind(&gr_socket_pdu::handle_udp_read, this, + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred)); + set_msg_handler(pmt::mp("pdus"), boost::bind(&gr_socket_pdu::udp_send, this, _1)); + } else if(type =="UDP_CLIENT"){ + _udp_socket.reset(new boost::asio::ip::udp::socket(_io_service, _udp_endpoint)); + _udp_socket->async_receive_from( boost::asio::buffer(rxbuf), _udp_endpoint_other, + boost::bind(&gr_socket_pdu::handle_udp_read, this, + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred)); + set_msg_handler(pmt::mp("pdus"), boost::bind(&gr_socket_pdu::udp_send, this, _1)); + } else { + throw std::runtime_error("unknown socket type!"); + } + + // start thread for io_service + d_thread = boost::shared_ptr(new boost::thread(boost::bind(&gr_socket_pdu::run_io_service, this))); + d_started = true; +} + +void tcp_connection::handle_read(const boost::system::error_code& error/*error*/, size_t bytes_transferred) + { + if(!error) + { + pmt::pmt_t vector = pmt::pmt_init_u8vector(bytes_transferred, (const uint8_t*)&buf[0]); + pmt::pmt_t pdu = pmt::pmt_cons( pmt::PMT_NIL, vector); + + d_block->message_port_pub( pmt::mp("pdus"), pdu ); + + socket_.async_read_some( + boost::asio::buffer(buf), + boost::bind(&tcp_connection::handle_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); + + } else { + std::cout << "error occurred\n"; + } + + } + + +void gr_socket_pdu::tcp_server_send(pmt::pmt_t msg){ + pmt::pmt_t vector = pmt::pmt_cdr(msg); + for(size_t i=0; isend(vector); + } +} + +void gr_socket_pdu::tcp_client_send(pmt::pmt_t msg){ + pmt::pmt_t vector = pmt::pmt_cdr(msg); + size_t len = pmt::pmt_length(vector); + size_t offset(0); + boost::array txbuf; + memcpy(&txbuf[0], pmt::pmt_uniform_vector_elements(vector, offset), len); + _tcp_socket->send(boost::asio::buffer(txbuf,len)); +} + +void gr_socket_pdu::udp_send(pmt::pmt_t msg){ + pmt::pmt_t vector = pmt::pmt_cdr(msg); + size_t len = pmt::pmt_length(vector); + size_t offset(0); + boost::array txbuf; + memcpy(&txbuf[0], pmt::pmt_uniform_vector_elements(vector, offset), len); + if(_udp_endpoint_other.address().to_string() != "0.0.0.0") + _udp_socket->send_to(boost::asio::buffer(txbuf,len), _udp_endpoint_other); +} diff --git a/gnuradio-core/src/lib/io/gr_socket_pdu.h b/gnuradio-core/src/lib/io/gr_socket_pdu.h new file mode 100644 index 000000000..3a96a3f97 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_socket_pdu.h @@ -0,0 +1,203 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_SOCKET_PDU_H +#define INCLUDED_GR_SOCKET_PDU_H + +#include +#include +#include +#include +#include +#include + +#include + +class gr_socket_pdu; +typedef boost::shared_ptr gr_socket_pdu_sptr; + +GR_CORE_API gr_socket_pdu_sptr gr_make_socket_pdu (std::string type, std::string addr, std::string port, int MTU=10000); + +class tcp_connection + : public boost::enable_shared_from_this +{ +public: + typedef boost::shared_ptr pointer; + gr_socket_pdu *d_block; + boost::array buf; + + static pointer create(boost::asio::io_service& io_service) + { + return pointer(new tcp_connection(io_service)); + } + + boost::asio::ip::tcp::socket& socket() + { + return socket_; + } + + void start(gr_socket_pdu* parent) + { + d_block = parent; +// message_ = "connected to gr_socket_pdu\n"; +// boost::asio::async_write(socket_, boost::asio::buffer(message_), +// boost::bind(&tcp_connection::handle_write, shared_from_this(), +// boost::asio::placeholders::error, +// boost::asio::placeholders::bytes_transferred)); + + socket_.async_read_some( + boost::asio::buffer(buf), + boost::bind(&tcp_connection::handle_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); + } + void send(pmt::pmt_t vector){ + size_t len = pmt::pmt_length(vector); + size_t offset(0); + boost::array txbuf; + memcpy(&txbuf[0], pmt::pmt_uniform_vector_elements(vector, offset), len); + boost::asio::async_write(socket_, boost::asio::buffer(txbuf, len), + boost::bind(&tcp_connection::handle_write, shared_from_this(), + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred)); + } + + ~tcp_connection(){ +// std::cout << "tcp_connection destroyed\n"; + } + +private: + tcp_connection(boost::asio::io_service& io_service) + : socket_(io_service) + { + } + + void handle_read(const boost::system::error_code& error/*error*/, size_t bytes_transferred); + + void handle_write(const boost::system::error_code& /*error*/, + size_t /*bytes_transferred*/) + { + } + + boost::asio::ip::tcp::socket socket_; + std::string message_; +}; + + +/*! + * \brief Gather received items into messages and insert into msgq + * \ingroup sink_blk + */ +class GR_CORE_API gr_socket_pdu : public gr_stream_pdu_base +{ + private: + friend GR_CORE_API gr_socket_pdu_sptr + gr_make_socket_pdu(std::string type, std::string addr, std::string port, int MTU); + + boost::asio::io_service _io_service; + + boost::array rxbuf; + + // tcp specific + boost::asio::ip::tcp::endpoint _tcp_endpoint; + + // specific to tcp server + boost::shared_ptr _acceptor_tcp; + std::vector d_tcp_connections; + void tcp_server_send(pmt::pmt_t msg); + void tcp_client_send(pmt::pmt_t msg); + void udp_send(pmt::pmt_t msg); + + // specific to tcp client + boost::shared_ptr _tcp_socket; + + // specific to udp client/server + boost::asio::ip::udp::endpoint _udp_endpoint; + boost::asio::ip::udp::endpoint _udp_endpoint_other; + boost::shared_ptr _udp_socket; + + void handle_receive(const boost::system::error_code& error, std::size_t ){ + } + + void start_tcp_accept(){ + tcp_connection::pointer new_connection = + tcp_connection::create(_acceptor_tcp->get_io_service()); + + _acceptor_tcp->async_accept(new_connection->socket(), + boost::bind(&gr_socket_pdu::handle_tcp_accept, this, new_connection, + boost::asio::placeholders::error)); + } + + void handle_tcp_accept(tcp_connection::pointer new_connection, const boost::system::error_code& error){ + if (!error) + { + new_connection->start(this); + d_tcp_connections.push_back(new_connection); + start_tcp_accept(); + } else { + std::cout << error << std::endl; + } + } + + void run_io_service(){ + _io_service.run(); + } + + void handle_udp_read(const boost::system::error_code& error/*error*/, size_t bytes_transferred){ + if(!error){ + pmt::pmt_t vector = pmt::pmt_init_u8vector(bytes_transferred, (const uint8_t*)&rxbuf[0]); + pmt::pmt_t pdu = pmt::pmt_cons( pmt::PMT_NIL, vector); + + message_port_pub( pmt::mp("pdus"), pdu ); + + _udp_socket->async_receive_from( boost::asio::buffer(rxbuf), _udp_endpoint_other, + boost::bind(&gr_socket_pdu::handle_udp_read, this, + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred)); + } else { + throw boost::system::system_error(error); +// std::cout << "error occurred\n"; + } + } + void handle_tcp_read(const boost::system::error_code& error/*error*/, size_t bytes_transferred){ + if(!error) + { + pmt::pmt_t vector = pmt::pmt_init_u8vector(bytes_transferred, (const uint8_t*)&rxbuf[0]); + pmt::pmt_t pdu = pmt::pmt_cons( pmt::PMT_NIL, vector); + + message_port_pub( pmt::mp("pdus"), pdu ); + + _tcp_socket->async_read_some( + boost::asio::buffer(rxbuf), + boost::bind(&gr_socket_pdu::handle_tcp_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); + + } else { + //std::cout << "error occurred\n"; + throw boost::system::system_error(error); + } + } + + protected: + gr_socket_pdu (std::string type, std::string addr, std::string port, int MTU=10000); + public: + ~gr_socket_pdu () {} +}; + +#endif /* INCLUDED_GR_TUNTAP_PDU_H */ diff --git a/gnuradio-core/src/lib/io/gr_socket_pdu.i b/gnuradio-core/src/lib/io/gr_socket_pdu.i new file mode 100644 index 000000000..3e20b63e2 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_socket_pdu.i @@ -0,0 +1,33 @@ +/* -*- 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 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, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,socket_pdu); + +%ignore tcp_connection; + +%{ +#include +%} + +%include "gr_stream_pdu_base.h" +%include "gr_socket_pdu.h" + diff --git a/gnuradio-core/src/lib/io/gr_stream_pdu_base.cc b/gnuradio-core/src/lib/io/gr_stream_pdu_base.cc new file mode 100644 index 000000000..cff7296cb --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_stream_pdu_base.cc @@ -0,0 +1,117 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const long timeout_us = 100*1000; //100ms + +gr_stream_pdu_base::gr_stream_pdu_base (int MTU) + : gr_sync_block("stream_pdu_base", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(0, 0, 0)), + d_finished(false), d_started(false), d_fd(-1) +{ + // reserve space for rx buffer + d_rxbuf.resize(MTU,0); +} + +gr_stream_pdu_base::~gr_stream_pdu_base() +{ + stop_rxthread(); +} + +void gr_stream_pdu_base::stop_rxthread(){ + d_finished = true; + if(d_started){ + d_thread->interrupt(); + d_thread->join(); + } + } + +void gr_stream_pdu_base::start_rxthread(pmt::pmt_t _rxport){ + rxport = _rxport; + d_thread = boost::shared_ptr(new boost::thread(boost::bind(&gr_stream_pdu_base::run, this))); + d_started = true; + } + +void gr_stream_pdu_base::run(){ + while(!d_finished) { + if(not wait_ready()){ continue; } + const int result = read( d_fd, &d_rxbuf[0], d_rxbuf.size() ); + if(result <= 0){ throw std::runtime_error("gr_stream_pdu_base, bad socket read!"); } + pmt::pmt_t vector = pmt::pmt_init_u8vector(result, &d_rxbuf[0]); + pmt::pmt_t pdu = pmt::pmt_cons( pmt::PMT_NIL, vector); + message_port_pub(rxport, pdu); + } +} + +void gr_stream_pdu_base::send(pmt::pmt_t msg){ + pmt::pmt_t vector = pmt::pmt_cdr(msg); + size_t offset(0); + size_t itemsize(gr_pdu_itemsize(type_from_pmt(vector))); + int len( pmt::pmt_length(vector)*itemsize ); + + const int rv = write(d_fd, pmt::pmt_uniform_vector_elements(vector, offset), len); + if(rv != len){ + std::cerr << boost::format("WARNING: gr_stream_pdu_base::send(pdu) write failed! (d_fd=%d, len=%d, rv=%d)") + % d_fd % len % rv << std::endl; + } +} + +int +gr_stream_pdu_base::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + throw std::runtime_error("should not be called.\n"); + return 0; +} + +bool gr_stream_pdu_base::wait_ready(){ + //setup timeval for timeout + timeval tv; + tv.tv_sec = 0; + tv.tv_usec = timeout_us; + + //setup rset for timeout + fd_set rset; + FD_ZERO(&rset); + FD_SET(d_fd, &rset); + + //call select with timeout on receive socket + return ::select(d_fd+1, &rset, NULL, NULL, &tv) > 0; +} diff --git a/gnuradio-core/src/lib/io/gr_stream_pdu_base.h b/gnuradio-core/src/lib/io/gr_stream_pdu_base.h new file mode 100644 index 000000000..dc5dc5c2e --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_stream_pdu_base.h @@ -0,0 +1,62 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_STREAM_PDU_BASE_H +#define INCLUDED_GR_STREAM_PDU_BASE_H + +#include +#include +#include +#include + +#include + + +/*! + * \brief Gather received items into messages and insert into msgq + * \ingroup sink_blk + */ +class GR_CORE_API gr_stream_pdu_base : public gr_sync_block +{ + public: + boost::shared_ptr d_thread; + bool d_finished; + bool d_started; + std::vector d_rxbuf; + void run(); + int d_fd; + gr_stream_pdu_base (int MTU=10000); + ~gr_stream_pdu_base (); + void send(pmt::pmt_t msg); + bool wait_ready(); + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + void start_rxthread(pmt::pmt_t _rxport); + void stop_rxthread(); + private: + pmt::pmt_t rxport; +}; + +typedef boost::shared_ptr gr_stream_pdu_base_sptr; + +#endif /* INCLUDED_GR_TUNTAP_PDU_H */ diff --git a/gnuradio-core/src/lib/io/gr_tuntap_pdu.cc b/gnuradio-core/src/lib/io/gr_tuntap_pdu.cc new file mode 100644 index 000000000..44de1a5f7 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_tuntap_pdu.cc @@ -0,0 +1,143 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if (defined(linux) || defined(__linux) || defined(__linux__)) + +#include +#include +#include +#include + +#include +#include + + +// public constructor that returns a shared_ptr + +gr_tuntap_pdu_sptr +gr_make_tuntap_pdu (std::string dev, int MTU) +{ + return gnuradio::get_initial_sptr(new gr_tuntap_pdu(dev, MTU)); +} + +gr_tuntap_pdu::gr_tuntap_pdu (std::string dev, int MTU) + : gr_stream_pdu_base(MTU) +{ + + // make the tuntap + char dev_cstr[1024]; + memset(dev_cstr, 0x00, 1024); + strncpy(dev_cstr, dev.c_str(), std::min(sizeof(dev_cstr), dev.size())); + d_fd = tun_alloc(dev_cstr); + if(d_fd <= 0){ + throw std::runtime_error("TunTap make: tun_alloc failed (are you running as root?)"); + } + + std::cout << boost::format( + "Allocated virtual ethernet interface: %s\n" + "You must now use ifconfig to set its IP address. E.g.,\n" + " $ sudo ifconfig %s 192.168.200.1\n" + "Be sure to use a different address in the same subnet for each machine.\n" + ) % dev % dev << std::endl; + + // set up output message port + message_port_register_out(pmt::mp("pdus")); + start_rxthread(pmt::mp("pdus")); + + // set up input message port + message_port_register_in(pmt::mp("pdus")); + set_msg_handler(pmt::mp("pdus"), boost::bind(&gr_tuntap_pdu::send, this, _1)); +} + + +int gr_tuntap_pdu::tun_alloc(char *dev, int flags) { + struct ifreq ifr; + int fd, err; + const char *clonedev = "/dev/net/tun"; + + /* Arguments taken by the function: + * + * char *dev: the name of an interface (or '\0'). MUST have enough + * space to hold the interface name if '\0' is passed + * int flags: interface flags (eg, IFF_TUN etc.) + */ + + /* open the clone device */ + if( (fd = open(clonedev, O_RDWR)) < 0 ) { + return fd; + } + + /* preparation of the struct ifr, of type "struct ifreq" */ + memset(&ifr, 0, sizeof(ifr)); + + ifr.ifr_flags = flags; /* IFF_TUN or IFF_TAP, plus maybe IFF_NO_PI */ + + if (*dev) { + /* if a device name was specified, put it in the structure; otherwise, + * the kernel will try to allocate the "next" device of the + * specified type */ + strncpy(ifr.ifr_name, dev, IFNAMSIZ); + } + + /* try to create the device */ + if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ) { + close(fd); + return err; + } + + /* if the operation was successful, write back the name of the + * interface to the variable "dev", so the caller can know + * it. Note that the caller MUST reserve space in *dev (see calling + * code below) */ + strcpy(dev, ifr.ifr_name); + + /* this is the special file descriptor that the caller will use to talk + * with the virtual interface */ + return fd; +} + +#else //if not linux + +boost::shared_ptr gr_make_tuntap_pdu (std::string dev, int MTU){ + boost::shared_ptr rv; + throw std::runtime_error("tuntap only implemented on linux"); + return rv; +} + +#endif diff --git a/gnuradio-core/src/lib/io/gr_tuntap_pdu.h b/gnuradio-core/src/lib/io/gr_tuntap_pdu.h new file mode 100644 index 000000000..0e8071c30 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_tuntap_pdu.h @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_TUNTAP_PDU_H +#define INCLUDED_GR_TUNTAP_PDU_H + +#include +#include +#include +#include +#include + +#if (defined(linux) || defined(__linux) || defined(__linux__)) + +#include + +class gr_tuntap_pdu; +typedef boost::shared_ptr gr_tuntap_pdu_sptr; + +GR_CORE_API gr_tuntap_pdu_sptr gr_make_tuntap_pdu (std::string dev, int MTU=10000); + +/*! + * \brief Gather received items into messages and insert into msgq + * \ingroup sink_blk + */ +class GR_CORE_API gr_tuntap_pdu : public gr_stream_pdu_base +{ + private: + friend GR_CORE_API gr_tuntap_pdu_sptr + gr_make_tuntap_pdu(std::string dev, int MTU); + int tun_alloc(char* dev, int flags = IFF_TAP | IFF_NO_PI); + std::string d_dev; + protected: + gr_tuntap_pdu (std::string dev, int MTU=10000); + + public: + ~gr_tuntap_pdu () {} + +}; + +#else // if not linux + +GR_CORE_API boost::shared_ptr gr_make_tuntap_pdu (std::string dev, int MTU=0); + +#endif + +#endif /* INCLUDED_GR_TUNTAP_PDU_H */ diff --git a/gnuradio-core/src/lib/io/gr_tuntap_pdu.i b/gnuradio-core/src/lib/io/gr_tuntap_pdu.i new file mode 100644 index 000000000..589bbc385 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_tuntap_pdu.i @@ -0,0 +1,30 @@ +/* -*- 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 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, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,tuntap_pdu); + +%{ +#include +%} + +%include "gr_tuntap_pdu.h" + diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index 871ce1356..e2de4eb97 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -49,6 +49,8 @@ #include #include #include +#include +#include %} %include "gr_file_sink_base.i" @@ -75,4 +77,7 @@ %include "gr_tagged_stream_to_pdu.i" %include "gr_message_debug.i" %include "gr_pdu.i" +%include "gr_tuntap_pdu.i" +%include "gr_socket_pdu.i" + -- cgit From 9dc29eb8b72fd28f8759cec79debe693cb66ee4e Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 11 Dec 2012 19:31:51 -0500 Subject: core: better error handling on file source/sink. This addresses ticket #448. --- gnuradio-core/src/lib/io/gr_file_sink.cc | 27 +++++++++++++++++---------- gnuradio-core/src/lib/io/gr_file_sink_base.cc | 2 +- gnuradio-core/src/lib/io/gr_file_source.cc | 5 +++-- 3 files changed, 21 insertions(+), 13 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_sink.cc b/gnuradio-core/src/lib/io/gr_file_sink.cc index 5d147fcfe..10c8360cb 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink.cc @@ -42,8 +42,6 @@ gr_file_sink::gr_file_sink(size_t itemsize, const char *filename) gr_file_sink_base(filename, true), d_itemsize(itemsize) { - if (!open(filename)) - throw std::runtime_error ("can't open file"); } gr_file_sink::~gr_file_sink () @@ -55,23 +53,32 @@ gr_file_sink::work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - char *inbuf = (char *) input_items[0]; + char *inbuf = (char*)input_items[0]; int nwritten = 0; do_update(); // update d_fp is reqd - if (!d_fp) + if(!d_fp) return noutput_items; // drop output on the floor - while (nwritten < noutput_items){ - int count = fwrite (inbuf, d_itemsize, noutput_items - nwritten, d_fp); - if (count == 0) // FIXME add error handling - break; + while(nwritten < noutput_items) { + int count = fwrite(inbuf, d_itemsize, noutput_items - nwritten, d_fp); + if(count == 0) { + if(ferror(d_fp)) { + std::stringstream s; + s << "file_sink write failed with error " << fileno(d_fp) << std::endl; + throw std::runtime_error(s.str()); + } + else { // is EOF + break; + } + } nwritten += count; inbuf += count * d_itemsize; } - if (d_unbuffered) - fflush (d_fp); + + if(d_unbuffered) + fflush (d_fp); return nwritten; } diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.cc b/gnuradio-core/src/lib/io/gr_file_sink_base.cc index b2dcc1be5..2dd896ae7 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.cc @@ -122,5 +122,5 @@ gr_file_sink_base::do_update() void gr_file_sink_base::set_unbuffered(bool unbuffered) { - d_unbuffered = unbuffered; + d_unbuffered = unbuffered; } diff --git a/gnuradio-core/src/lib/io/gr_file_source.cc b/gnuradio-core/src/lib/io/gr_file_source.cc index 3f06a8244..96333fa24 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_source.cc @@ -111,8 +111,9 @@ gr_file_source::work (int noutput_items, break; if (fseek ((FILE *) d_fp, 0, SEEK_SET) == -1) { - fprintf(stderr, "[%s] fseek failed\n", __FILE__); - exit(-1); + std::stringstream s; + s << "[" << __FILE__ << "]" << " fseek failed" << std::endl; + throw std::runtime_error(s.str()); } } -- cgit From ee53cca50e3f39ddc1d44669c3ea9f0d73d32022 Mon Sep 17 00:00:00 2001 From: Brett L. Trotter Date: Tue, 11 Dec 2012 21:53:08 -0500 Subject: core: Patch to file source to allow opening of new files while running. Addresses issues #352. --- gnuradio-core/src/lib/io/gr_file_source.cc | 96 ++++++++++++++++++++++++------ gnuradio-core/src/lib/io/gr_file_source.h | 64 ++++++++++++++++---- gnuradio-core/src/lib/io/gr_file_source.i | 2 + 3 files changed, 130 insertions(+), 32 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_source.cc b/gnuradio-core/src/lib/io/gr_file_source.cc index 96333fa24..09f3986cd 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_source.cc @@ -49,24 +49,14 @@ #define OUR_O_LARGEFILE 0 #endif -gr_file_source::gr_file_source (size_t itemsize, const char *filename, bool repeat) - : gr_sync_block ("file_source", - gr_make_io_signature (0, 0, 0), - gr_make_io_signature (1, 1, itemsize)), - d_itemsize (itemsize), d_fp (0), d_repeat (repeat) +gr_file_source::gr_file_source(size_t itemsize, const char *filename, bool repeat) + : gr_sync_block("file_source", + gr_make_io_signature (0, 0, 0), + gr_make_io_signature (1, 1, itemsize)), + d_itemsize(itemsize), d_fp(0), d_new_fp (0), d_repeat(repeat), + d_updated(false) { - // we use "open" to use to the O_LARGEFILE flag - - int fd; - if ((fd = open (filename, O_RDONLY | OUR_O_LARGEFILE | OUR_O_BINARY)) < 0){ - perror (filename); - throw std::runtime_error ("can't open file"); - } - - if ((d_fp = fdopen (fd, "rb")) == NULL){ - perror (filename); - throw std::runtime_error ("can't open file"); - } + open(filename, repeat); } // public constructor that returns a shared_ptr @@ -79,7 +69,11 @@ gr_make_file_source (size_t itemsize, const char *filename, bool repeat) gr_file_source::~gr_file_source () { - fclose ((FILE *) d_fp); + close(); + if(d_fp) { + fclose(d_fp); + d_fp = 0; + } } int @@ -91,6 +85,11 @@ gr_file_source::work (int noutput_items, int i; int size = noutput_items; + do_update(); // update d_fp is reqd + if(d_fp == NULL) + throw std::runtime_error("work with file not open"); + + boost::mutex::scoped_lock lock(fp_mutex); // hold for the rest of this function while (size) { i = fread(o, d_itemsize, size, (FILE *) d_fp); @@ -129,5 +128,64 @@ gr_file_source::work (int noutput_items, bool gr_file_source::seek (long seek_point, int whence) { - return fseek ((FILE *) d_fp, seek_point * d_itemsize, whence) == 0; + // obtain exclusive access for duration of this function + boost::mutex::scoped_lock lock(fp_mutex); + return fseek((FILE *) d_fp, seek_point * d_itemsize, whence) == 0; +} + +void +gr_file_source::open(const char *filename, bool repeat) +{ + // obtain exclusive access for duration of this function + boost::mutex::scoped_lock lock(fp_mutex); + + int fd; + + // we use "open" to use to the O_LARGEFILE flag + if((fd = ::open(filename, O_RDONLY | OUR_O_LARGEFILE | OUR_O_BINARY)) < 0) { + perror(filename); + throw std::runtime_error("can't open file"); + } + + if(d_new_fp) { + fclose(d_new_fp); + d_new_fp = 0; + } + + if((d_new_fp = fdopen (fd, "rb")) == NULL) { + perror(filename); + ::close(fd); // don't leak file descriptor if fdopen fails + throw std::runtime_error("can't open file"); + } + + d_updated = true; + d_repeat = repeat; +} + +void +gr_file_source::close() +{ + // obtain exclusive access for duration of this function + boost::mutex::scoped_lock lock(fp_mutex); + + if(d_new_fp != NULL) { + fclose(d_new_fp); + d_new_fp = NULL; + } + d_updated = true; +} + +void +gr_file_source::do_update() +{ + if(d_updated) { + boost::mutex::scoped_lock lock(fp_mutex); // hold while in scope + + if(d_fp) + fclose(d_fp); + + d_fp = d_new_fp; // install new file pointer + d_new_fp = 0; + d_updated = false; + } } diff --git a/gnuradio-core/src/lib/io/gr_file_source.h b/gnuradio-core/src/lib/io/gr_file_source.h index 1cc44a3b1..0478fba04 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.h +++ b/gnuradio-core/src/lib/io/gr_file_source.h @@ -25,6 +25,7 @@ #include #include +#include class gr_file_source; typedef boost::shared_ptr gr_file_source_sptr; @@ -39,31 +40,68 @@ gr_make_file_source (size_t itemsize, const char *filename, bool repeat = false) class GR_CORE_API gr_file_source : public gr_sync_block { - friend GR_CORE_API gr_file_source_sptr gr_make_file_source (size_t itemsize, - const char *filename, - bool repeat); private: - size_t d_itemsize; - void *d_fp; - bool d_repeat; + size_t d_itemsize; + FILE *d_fp; + FILE *d_new_fp; + bool d_repeat; + bool d_updated; protected: - gr_file_source (size_t itemsize, const char *filename, bool repeat); + gr_file_source(size_t itemsize, const char *filename, bool repeat); + + void do_update(); + + boost::mutex fp_mutex; public: - ~gr_file_source (); + /*! + * \brief Create a file source. + * + * Opens \p filename as a source of items into a flowgraph. The data + * is expected to be in binary format, item after item. The \p + * itemsize of the block determines the conversion from bits to + * items. + * + * If \p repeat is turned on, the file will repeat the file after + * it's reached the end. + * + * \param itemsize the size of each item in the file, in bytes + * \param filename name of the file to source from + * \param repeat repeat file from start + */ + friend GR_CORE_API gr_file_source_sptr + gr_make_file_source(size_t itemsize, + const char *filename, + bool repeat); + + ~gr_file_source(); - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); /*! - * \brief seek file to \p seek_point relative to \p whence + * \brief Seek file to \p seek_point relative to \p whence * * \param seek_point sample offset in file * \param whence one of SEEK_SET, SEEK_CUR, SEEK_END (man fseek) */ - bool seek (long seek_point, int whence); + bool seek(long seek_point, int whence); + + /*! + * \brief Opens a new file. + * + * \param filename name of the file to source from + * \param repeat repeat file from start + */ + void open(const char *filename, bool repeat); + + /*! + * \brief Close the file handle. + */ + void close(); + }; #endif /* INCLUDED_GR_FILE_SOURCE_H */ diff --git a/gnuradio-core/src/lib/io/gr_file_source.i b/gnuradio-core/src/lib/io/gr_file_source.i index 9bf44691d..e71cef0d1 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.i +++ b/gnuradio-core/src/lib/io/gr_file_source.i @@ -40,4 +40,6 @@ class gr_file_source : public gr_sync_block ~gr_file_source (); bool seek (long seek_point, int whence); + void open (const char *filename, bool repeat); + void close(); }; -- cgit From f62d61c12e158255925da6af0ec430e122ef6ca2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 12 Dec 2012 16:00:42 -0500 Subject: core: these two don't need to include if_tun.h, which causes problems on other platforms. --- gnuradio-core/src/lib/io/gr_socket_pdu.h | 2 -- gnuradio-core/src/lib/io/gr_stream_pdu_base.h | 3 --- 2 files changed, 5 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_socket_pdu.h b/gnuradio-core/src/lib/io/gr_socket_pdu.h index 3a96a3f97..f554febdc 100644 --- a/gnuradio-core/src/lib/io/gr_socket_pdu.h +++ b/gnuradio-core/src/lib/io/gr_socket_pdu.h @@ -30,8 +30,6 @@ #include #include -#include - class gr_socket_pdu; typedef boost::shared_ptr gr_socket_pdu_sptr; diff --git a/gnuradio-core/src/lib/io/gr_stream_pdu_base.h b/gnuradio-core/src/lib/io/gr_stream_pdu_base.h index dc5dc5c2e..35bacf523 100644 --- a/gnuradio-core/src/lib/io/gr_stream_pdu_base.h +++ b/gnuradio-core/src/lib/io/gr_stream_pdu_base.h @@ -28,9 +28,6 @@ #include #include -#include - - /*! * \brief Gather received items into messages and insert into msgq * \ingroup sink_blk -- cgit From 6e1b2888b3001c1c80fd78a714f5e5b98b1fe81d Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 12 Dec 2012 16:09:08 -0500 Subject: core: added a stub class for gr_tuntap_pdu to compile on OSX (tested) and Windows (untested). --- gnuradio-core/src/lib/io/gr_tuntap_pdu.cc | 15 +++++++++++++-- gnuradio-core/src/lib/io/gr_tuntap_pdu.h | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_tuntap_pdu.cc b/gnuradio-core/src/lib/io/gr_tuntap_pdu.cc index 44de1a5f7..d369310a6 100644 --- a/gnuradio-core/src/lib/io/gr_tuntap_pdu.cc +++ b/gnuradio-core/src/lib/io/gr_tuntap_pdu.cc @@ -134,8 +134,19 @@ int gr_tuntap_pdu::tun_alloc(char *dev, int flags) { #else //if not linux -boost::shared_ptr gr_make_tuntap_pdu (std::string dev, int MTU){ - boost::shared_ptr rv; +// Just a stub class and factory function for swig. +class gr_tuntap_pdu +{ +private: + gr_tuntap_pdu() {}; +public: + ~gr_tuntap_pdu() {}; +}; + +gr_block_sptr +gr_make_tuntap_pdu(std::string dev, int MTU) +{ + gr_block_sptr rv; throw std::runtime_error("tuntap only implemented on linux"); return rv; } diff --git a/gnuradio-core/src/lib/io/gr_tuntap_pdu.h b/gnuradio-core/src/lib/io/gr_tuntap_pdu.h index 0e8071c30..384d57703 100644 --- a/gnuradio-core/src/lib/io/gr_tuntap_pdu.h +++ b/gnuradio-core/src/lib/io/gr_tuntap_pdu.h @@ -59,7 +59,7 @@ class GR_CORE_API gr_tuntap_pdu : public gr_stream_pdu_base #else // if not linux -GR_CORE_API boost::shared_ptr gr_make_tuntap_pdu (std::string dev, int MTU=0); +GR_CORE_API gr_block_sptr gr_make_tuntap_pdu (std::string dev, int MTU=0); #endif -- cgit From aeb7bbfdcb7cdab610de4b2576ecf7a3a92f8d50 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 12 Dec 2012 16:17:04 -0500 Subject: core: put the stub class in the wrong file. --- gnuradio-core/src/lib/io/gr_tuntap_pdu.cc | 9 --------- gnuradio-core/src/lib/io/gr_tuntap_pdu.h | 8 ++++++++ 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_tuntap_pdu.cc b/gnuradio-core/src/lib/io/gr_tuntap_pdu.cc index d369310a6..8dd4b18a1 100644 --- a/gnuradio-core/src/lib/io/gr_tuntap_pdu.cc +++ b/gnuradio-core/src/lib/io/gr_tuntap_pdu.cc @@ -134,15 +134,6 @@ int gr_tuntap_pdu::tun_alloc(char *dev, int flags) { #else //if not linux -// Just a stub class and factory function for swig. -class gr_tuntap_pdu -{ -private: - gr_tuntap_pdu() {}; -public: - ~gr_tuntap_pdu() {}; -}; - gr_block_sptr gr_make_tuntap_pdu(std::string dev, int MTU) { diff --git a/gnuradio-core/src/lib/io/gr_tuntap_pdu.h b/gnuradio-core/src/lib/io/gr_tuntap_pdu.h index 384d57703..18c83f42b 100644 --- a/gnuradio-core/src/lib/io/gr_tuntap_pdu.h +++ b/gnuradio-core/src/lib/io/gr_tuntap_pdu.h @@ -59,6 +59,14 @@ class GR_CORE_API gr_tuntap_pdu : public gr_stream_pdu_base #else // if not linux +class gr_tuntap_pdu +{ +private: + gr_tuntap_pdu() {}; +public: + ~gr_tuntap_pdu() {}; +}; + GR_CORE_API gr_block_sptr gr_make_tuntap_pdu (std::string dev, int MTU=0); #endif -- cgit From 6530bfb32eedbe0c72e090a1d1065c8325e12fe8 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 13 Dec 2012 11:58:06 -0500 Subject: core: cleaning up file meta sink. --- gnuradio-core/src/lib/io/gr_file_meta_sink.h | 2 +- gnuradio-core/src/lib/io/gr_file_meta_sink.i | 21 ++------------------- 2 files changed, 3 insertions(+), 20 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.h b/gnuradio-core/src/lib/io/gr_file_meta_sink.h index c0636d66a..e5374af2b 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.h @@ -25,8 +25,8 @@ #include #include -#include #include +#include using namespace pmt; diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.i b/gnuradio-core/src/lib/io/gr_file_meta_sink.i index ed3eda0f8..9513b090f 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.i +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.i @@ -44,7 +44,7 @@ gr_make_file_meta_sink(size_t itemsize, const char *filename, const std::string & extra_dict="", bool detached_header=false); -class gr_file_meta_sink : public gr_sync_block, public gr_file_sink_base +class gr_file_meta_sink : public gr_sync_block { protected: gr_file_meta_sink(size_t itemsize, const char *filename, @@ -57,24 +57,7 @@ class gr_file_meta_sink : public gr_sync_block, public gr_file_sink_base public: ~gr_file_meta_sink(); - enum file_types { - FILE_BYTE=0, - FILE_CHAR=0, - FILE_SHORT, - FILE_INT, - FILE_LONG, - FILE_LONG_LONG, - FILE_FLOAT, - FILE_DOUBLE, - }; - - /*! - * \brief open filename and begin output to it. - */ bool open(const char *filename); - - /*! - * \brief close current output file. - */ void close(); + void set_unbuffered(bool unbuffered); }; -- cgit From 758fff58405ba7e351f80cc780177fe78494d78f Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 13 Dec 2012 11:58:25 -0500 Subject: core: adding a file meta source block. Right now, reads headers to get the item size and segment size. Streams data segments as correct data type out of streaming port 0. Does nothing else with meta data. --- gnuradio-core/src/lib/io/CMakeLists.txt | 1 + gnuradio-core/src/lib/io/gr_file_meta_source.cc | 384 ++++++++++++++++++++++++ gnuradio-core/src/lib/io/gr_file_meta_source.h | 117 ++++++++ gnuradio-core/src/lib/io/gr_file_meta_source.i | 44 +++ gnuradio-core/src/lib/io/io.i | 2 + 5 files changed, 548 insertions(+) create mode 100644 gnuradio-core/src/lib/io/gr_file_meta_source.cc create mode 100644 gnuradio-core/src/lib/io/gr_file_meta_source.h create mode 100644 gnuradio-core/src/lib/io/gr_file_meta_source.i (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/CMakeLists.txt b/gnuradio-core/src/lib/io/CMakeLists.txt index c5b85d304..1cbcd2daf 100644 --- a/gnuradio-core/src/lib/io/CMakeLists.txt +++ b/gnuradio-core/src/lib/io/CMakeLists.txt @@ -88,6 +88,7 @@ set(gr_core_io_triple_threats gr_file_meta_sink gr_file_sink_base gr_file_source + gr_file_meta_source gr_file_descriptor_sink gr_file_descriptor_source gr_message_debug diff --git a/gnuradio-core/src/lib/io/gr_file_meta_source.cc b/gnuradio-core/src/lib/io/gr_file_meta_source.cc new file mode 100644 index 000000000..b0850593b --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_meta_source.cc @@ -0,0 +1,384 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include + +// win32 (mingw/msvc) specific +#ifdef HAVE_IO_H +#include +#endif +#ifdef O_BINARY +#define OUR_O_BINARY O_BINARY +#else +#define OUR_O_BINARY 0 +#endif + +// should be handled via configure +#ifdef O_LARGEFILE +#define OUR_O_LARGEFILE O_LARGEFILE +#else +#define OUR_O_LARGEFILE 0 +#endif + +gr_file_meta_source_sptr +gr_make_file_meta_source(const char *filename, + bool repeat, + bool detached_header, + const char *hdr_filename) +{ + return gnuradio::get_initial_sptr + (new gr_file_meta_source(filename, + repeat, + detached_header, + hdr_filename)); +} + +gr_file_meta_source::gr_file_meta_source(const char *filename, + bool repeat, + bool detached_header, + const char *hdr_filename) + : gr_sync_block("file_meta_source", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(1, 1, 1)), + d_itemsize(0), d_samp_rate(0), + d_seg_size(0), + d_updated(false), d_repeat(repeat) +{ + d_fp = 0; + d_new_fp = 0; + d_hdr_fp = 0; + d_new_hdr_fp = 0; + + if(detached_header == true) + d_state = STATE_DETACHED; + else + d_state = STATE_INLINE; + + if(!open(filename)) + throw std::runtime_error("file_meta_source: can't open file\n"); + + do_update(); + + pmt_t hdr = PMT_NIL, extras = PMT_NIL; + if(read_header(hdr, extras)) + parse_header(hdr); + else + throw std::runtime_error("file_meta_source: could not read header.\n"); + + // Set output signature based on itemsize info in header + set_output_signature(gr_make_io_signature(1, 1, d_itemsize)); + + // Convert from bytes to items + d_seg_size /= d_itemsize; +} + +gr_file_meta_source::~gr_file_meta_source() +{ + close(); + + if(d_fp) { + fclose(d_fp); + d_fp = 0; + } + + if(d_state == STATE_DETACHED) { + if(d_hdr_fp) { + fclose(d_hdr_fp); + d_hdr_fp = 0; + } + } +} + +bool +gr_file_meta_source::read_header(pmt_t &hdr, pmt_t &extras) +{ + size_t ret; + size_t size = 0; + std::string str; + char *hdr_buffer = new char[METADATA_HEADER_SIZE]; + while(size < METADATA_HEADER_SIZE) { + ret = fread(&hdr_buffer[size], sizeof(char), METADATA_HEADER_SIZE-size, d_fp); + if(ret == 0) { + delete [] hdr_buffer; + if(feof(d_fp)) + return false; + else { + std::stringstream s; + s << "file_meta_source: error occurred extracting header: " + << strerror(errno) << std::endl; + throw std::runtime_error(s.str()); + } + } + size += ret; + } + + // Convert to string or the char array gets confused by the \0 + str.insert(0, hdr_buffer, METADATA_HEADER_SIZE); + hdr = pmt_deserialize_str(str); + delete [] hdr_buffer; + + uint64_t seg_start, extra_len; + pmt_t r, dump; + if(pmt_dict_has_key(hdr, pmt_string_to_symbol("strt"))) { + r = pmt_dict_ref(hdr, pmt_string_to_symbol("strt"), dump); + seg_start = pmt_to_uint64(r); + extra_len = seg_start - METADATA_HEADER_SIZE; + } + + if(extra_len > 0) { + size = 0; + hdr_buffer = new char[extra_len]; + while(size < extra_len) { + ret = fread(&hdr_buffer[size], sizeof(char), extra_len-size, d_fp); + if(ret == 0) { + delete [] hdr_buffer; + if(feof(d_fp)) + return false; + else { + std::stringstream s; + s << "file_meta_source: error occurred extracting extras: " + << strerror(errno) << std::endl; + throw std::runtime_error(s.str()); + } + } + size += ret; + } + + str.clear(); + str.insert(0, hdr_buffer, extra_len); + extras = pmt_deserialize_str(str); + delete [] hdr_buffer; + } + + return true; +} + +void +gr_file_meta_source::parse_header(pmt_t hdr) +{ + // GET SAMPLE RATE + if(pmt_dict_has_key(hdr, pmt_string_to_symbol("rx_rate"))) { + d_samp_rate = pmt_to_double(pmt_dict_ref(hdr, pmt_string_to_symbol("rx_rate"), PMT_NIL)); + } + else { + throw std::runtime_error("file_meta_source: Could not extract sample rate.\n"); + } + + // GET TIME STAMP + if(pmt_dict_has_key(hdr, pmt_string_to_symbol("rx_time"))) { + d_time_stamp = pmt_dict_ref(hdr, pmt_string_to_symbol("rx_time"), PMT_NIL); + } + else { + throw std::runtime_error("file_meta_source: Could not extract time stamp.\n"); + } + + // GET DATA TYPE + if(pmt_dict_has_key(hdr, pmt_string_to_symbol("type"))) { + int t = pmt_to_long(pmt_dict_ref(hdr, pmt_string_to_symbol("type"), PMT_NIL)); + switch(t) { + case(GR_FILE_CHAR): d_itemsize = sizeof(char); break; + case(GR_FILE_SHORT): d_itemsize = sizeof(short); break; + case(GR_FILE_INT): d_itemsize = sizeof(int); break; + case(GR_FILE_LONG): d_itemsize = sizeof(long int); break; + case(GR_FILE_LONG_LONG): d_itemsize = sizeof(long long int); break; + case(GR_FILE_FLOAT): d_itemsize = sizeof(float); break; + case(GR_FILE_DOUBLE): d_itemsize = sizeof(double); break; + default: + throw std::runtime_error("file_meta_source: Could not determine data type size.\n"); + } + } + else { + throw std::runtime_error("file_meta_source: Could not extract data type.\n"); + } + + // GET COMPLEX INDICATOR + if(pmt_dict_has_key(hdr, pmt_string_to_symbol("cplx"))) { + bool cplx = pmt_to_bool(pmt_dict_ref(hdr, pmt_string_to_symbol("cplx"), PMT_NIL)); + if(cplx) + d_itemsize *= 2; + } + else { + throw std::runtime_error("file_meta_source: Could not extract complex indicator.\n"); + } + + // GET FIRST SEGMENT SIZE + if(pmt_dict_has_key(hdr, pmt_string_to_symbol("size"))) { + d_seg_size = pmt_to_uint64(pmt_dict_ref(hdr, pmt_string_to_symbol("size"), PMT_NIL)); + } + else { + throw std::runtime_error("file_meta_source: Could not extract segment size.\n"); + } +} + +bool +gr_file_meta_source::open(const char *filename) +{ + bool ret = true; + if(d_state == STATE_DETACHED) { + std::stringstream s; + s << filename << ".hdr"; + ret = _open(&d_new_hdr_fp, s.str().c_str()); + } + + ret = ret && _open(&d_new_fp, filename); + d_updated = true; + return ret; +} + +bool +gr_file_meta_source::_open(FILE **fp, const char *filename) +{ + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function + + bool ret = true; + int fd; + + if((fd = ::open(filename, + O_RDONLY|OUR_O_LARGEFILE|OUR_O_BINARY)) < 0) { + perror(filename); + return false; + } + + if(*fp) { // if we've already got a new one open, close it + fclose(*fp); + fp = 0; + } + + if((*fp = fdopen(fd, "rb")) == NULL) { + perror(filename); + ::close(fd); // don't leak file descriptor if fdopen fails. + } + + ret = fp != 0; + + return ret; +} + +void +gr_file_meta_source::close() +{ + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function + if(d_state == STATE_DETACHED) { + if(d_new_hdr_fp) { + fclose(d_new_hdr_fp); + d_new_hdr_fp = 0; + } + } + + if(d_new_fp) { + fclose(d_new_fp); + d_new_fp = 0; + } + d_updated = true; +} + +void +gr_file_meta_source::do_update() +{ + if(d_updated) { + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this block + if(d_state == STATE_DETACHED) { + if(d_hdr_fp) + fclose(d_hdr_fp); + d_hdr_fp = d_new_hdr_fp; // install new file pointer + d_new_hdr_fp = 0; + } + + if(d_fp) + fclose(d_fp); + d_fp = d_new_fp; // install new file pointer + d_new_fp = 0; + + d_updated = false; + } +} + +int +gr_file_meta_source::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + // We've reached the end of a segment; parse the next header and get + // the new tags to send and set the next segment size. + if((d_seg_size == 0) && (!feof(d_fp))) { + pmt_t hdr=PMT_NIL, extras=PMT_NIL; + if(read_header(hdr, extras)) + parse_header(hdr); + else + return -1; + } + + char *out = (char*)output_items[0]; + int i; + int seg_size = std::min(noutput_items, (int)d_seg_size); + int size = seg_size; + + do_update(); // update d_fp is reqd + if(d_fp == NULL) + throw std::runtime_error("work with file not open"); + + gruel::scoped_lock lock(d_mutex); // hold for the rest of this function + while(size) { + i = fread(out, d_itemsize, size, d_fp); + + size -= i; + d_seg_size -= i; + out += i * d_itemsize; + + if(size == 0) // done + break; + + if(i > 0) // short read, try again + continue; + + // We got a zero from fread. This is either EOF or error. In + // any event, if we're in repeat mode, seek back to the beginning + // of the file and try again, else break + + if(!d_repeat) + break; + + if(fseek(d_fp, 0, SEEK_SET) == -1) { + std::stringstream s; + s << "[" << __FILE__ << "]" << " fseek failed" << std::endl; + throw std::runtime_error(s.str()); + } + } + + if(size > 0) { // EOF or error + if(size == seg_size) // we didn't read anything; say we're done + return -1; + return seg_size - size; // else return partial result + } + + return seg_size; +} diff --git a/gnuradio-core/src/lib/io/gr_file_meta_source.h b/gnuradio-core/src/lib/io/gr_file_meta_source.h new file mode 100644 index 000000000..819f4ece2 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_meta_source.h @@ -0,0 +1,117 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_FILE_META_SOURCE_H +#define INCLUDED_GR_FILE_META_SOURCE_H + +#include +#include +#include +#include +#include + +#include + +class gr_file_meta_source; +typedef boost::shared_ptr gr_file_meta_source_sptr; + +GR_CORE_API gr_file_meta_source_sptr +gr_make_file_meta_source(const char *filename, + bool repeat=false, + bool detached_header=false, + const char *hdr_filename=""); + +/*! + * \brief Reads stream from file with meta-data headers. Headers are + * parsed into tags. + * \ingroup source_blk + * + * The information in the metadata headers includes: + * + * rx_rate (double): sample rate of data. + * rx_time (uint64_t, double): time stamp of first sample in segment. + * type (gr_file_types as int32_t): data type. + * cplx (bool): Is data complex? + * strt (uint64_t): Starting byte of data in this segment. + * size (uint64_t): Size in bytes of data in this segment. + * + * Any item inside of the extra header dictionary is ready out and + * made into a stream tag. + */ +class GR_CORE_API gr_file_meta_source : public gr_sync_block +{ + /*! + * \brief Create a meta-data file source. + * + * \param filename (string): Name of file to write data to. + * \param repeate (bool): Repeats file when EOF is found. + * \param detached_header (bool): Set to true if header + * info is stored in a separate file (usually named filename.hdr) + * \param hdr_filename (string): Name of detached header file if used. + */ + friend GR_CORE_API gr_file_meta_source_sptr + gr_make_file_meta_source(const char *filename, + bool repeat, + bool detached_header, + const char *hdr_filename); + + private: + enum meta_state_t { + STATE_INLINE=0, + STATE_DETACHED + }; + + size_t d_itemsize; + double d_samp_rate; + pmt_t d_time_stamp; + size_t d_seg_size; + bool d_updated; + bool d_repeat; + + gruel::mutex d_mutex; + FILE *d_new_fp, *d_new_hdr_fp; + FILE *d_fp, *d_hdr_fp; + meta_state_t d_state; + + protected: + gr_file_meta_source(const char *filename, + bool repeat=false, + bool detached_header=false, + const char *hdr_filename=""); + + bool _open(FILE **fp, const char *filename); + bool read_header(pmt_t &hdr, pmt_t &extras); + void parse_header(pmt_t hdr); + + public: + ~gr_file_meta_source(); + + bool open(const char *filename); + void close(); + void do_update(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_GR_FILE_META_SOURCE_H */ diff --git a/gnuradio-core/src/lib/io/gr_file_meta_source.i b/gnuradio-core/src/lib/io/gr_file_meta_source.i new file mode 100644 index 000000000..6cf089da1 --- /dev/null +++ b/gnuradio-core/src/lib/io/gr_file_meta_source.i @@ -0,0 +1,44 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,file_meta_source) + +gr_file_meta_source_sptr +gr_make_file_meta_source(const char *filename, + bool repeat=false, + bool detached_header=false, + const char *hdr_filename=""); + +class gr_file_meta_source : public gr_sync_block +{ + protected: + gr_file_meta_source(const char *filename, + bool repeat, + bool detached_header, + const char *hdr_filename); + + public: + ~gr_file_meta_source(); + + bool open(const char *filename); + void close(); +}; diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index 055f28847..5885214d8 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +59,7 @@ %include "gr_file_sink.i" %include "gr_file_meta_sink.i" %include "gr_file_source.i" +%include "gr_file_meta_source.i" %include "gr_file_descriptor_sink.i" %include "gr_file_descriptor_source.i" %include "gr_histo_sink.i" -- cgit From 01837095fe61ccb560e0db8ea7646bd068821d6c Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 13 Dec 2012 13:45:16 -0500 Subject: core: forgot to remove these outputs. --- gnuradio-core/src/lib/io/gr_file_sink_base.cc | 5 ----- 1 file changed, 5 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.cc b/gnuradio-core/src/lib/io/gr_file_sink_base.cc index 4eecf928e..d0aca418e 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.cc @@ -79,9 +79,6 @@ gr_file_sink_base::open(const char *filename) perror (filename); return false; } - std::cerr << "OPENING NEW FILE: " << filename << std::endl; - std::cerr << "FD: " << fd << std::endl; - if (d_new_fp){ // if we've already got a new one open, close it fclose(d_new_fp); d_new_fp = 0; @@ -92,8 +89,6 @@ gr_file_sink_base::open(const char *filename) ::close(fd); // don't leak file descriptor if fdopen fails. } - std::cerr << "D_NEW_FD: " << d_new_fp << std::endl; - d_updated = true; return d_new_fp != 0; } -- cgit From 68159be8e0114e347b942e33d0b116c9f77127ac Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 13 Dec 2012 13:51:55 -0500 Subject: core: updated meta data file sink to extract header metadata as tags and add them to the tag stream. --- gnuradio-core/src/lib/io/gr_file_meta_source.cc | 53 +++++++++++++++++++------ gnuradio-core/src/lib/io/gr_file_meta_source.h | 6 ++- 2 files changed, 45 insertions(+), 14 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_meta_source.cc b/gnuradio-core/src/lib/io/gr_file_meta_source.cc index b0850593b..10f08e79d 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_source.cc @@ -90,15 +90,12 @@ gr_file_meta_source::gr_file_meta_source(const char *filename, pmt_t hdr = PMT_NIL, extras = PMT_NIL; if(read_header(hdr, extras)) - parse_header(hdr); + parse_header(hdr, 0, d_tags); else throw std::runtime_error("file_meta_source: could not read header.\n"); // Set output signature based on itemsize info in header set_output_signature(gr_make_io_signature(1, 1, d_itemsize)); - - // Convert from bytes to items - d_seg_size /= d_itemsize; } gr_file_meta_source::~gr_file_meta_source() @@ -183,19 +180,39 @@ gr_file_meta_source::read_header(pmt_t &hdr, pmt_t &extras) } void -gr_file_meta_source::parse_header(pmt_t hdr) +gr_file_meta_source::parse_header(pmt_t hdr, uint64_t offset, + std::vector &tags) { + pmt_t r, key; + // GET SAMPLE RATE - if(pmt_dict_has_key(hdr, pmt_string_to_symbol("rx_rate"))) { - d_samp_rate = pmt_to_double(pmt_dict_ref(hdr, pmt_string_to_symbol("rx_rate"), PMT_NIL)); + key = pmt_string_to_symbol("rx_rate"); + if(pmt_dict_has_key(hdr, key)) { + r = pmt_dict_ref(hdr, key, PMT_NIL); + d_samp_rate = pmt_to_double(r); + + gr_tag_t t; + t.offset = offset; + t.key = key; + t.value = r; + t.srcid = alias_pmt(); + tags.push_back(t); } else { throw std::runtime_error("file_meta_source: Could not extract sample rate.\n"); } // GET TIME STAMP - if(pmt_dict_has_key(hdr, pmt_string_to_symbol("rx_time"))) { - d_time_stamp = pmt_dict_ref(hdr, pmt_string_to_symbol("rx_time"), PMT_NIL); + key = pmt_string_to_symbol("rx_time"); + if(pmt_dict_has_key(hdr, key)) { + d_time_stamp = pmt_dict_ref(hdr, key, PMT_NIL); + + gr_tag_t t; + t.offset = offset; + t.key = key; + t.value = d_time_stamp; + t.srcid = alias_pmt(); + tags.push_back(t); } else { throw std::runtime_error("file_meta_source: Could not extract time stamp.\n"); @@ -230,9 +247,12 @@ gr_file_meta_source::parse_header(pmt_t hdr) throw std::runtime_error("file_meta_source: Could not extract complex indicator.\n"); } - // GET FIRST SEGMENT SIZE + // GET SEGMENT SIZE if(pmt_dict_has_key(hdr, pmt_string_to_symbol("size"))) { d_seg_size = pmt_to_uint64(pmt_dict_ref(hdr, pmt_string_to_symbol("size"), PMT_NIL)); + + // Convert from bytes to items + d_seg_size /= d_itemsize; } else { throw std::runtime_error("file_meta_source: Could not extract segment size.\n"); @@ -329,12 +349,13 @@ gr_file_meta_source::work(int noutput_items, { // We've reached the end of a segment; parse the next header and get // the new tags to send and set the next segment size. - if((d_seg_size == 0) && (!feof(d_fp))) { + if(d_seg_size == 0) { pmt_t hdr=PMT_NIL, extras=PMT_NIL; if(read_header(hdr, extras)) - parse_header(hdr); - else + parse_header(hdr, nitems_written(0), d_tags); + else { return -1; + } } char *out = (char*)output_items[0]; @@ -346,6 +367,12 @@ gr_file_meta_source::work(int noutput_items, if(d_fp == NULL) throw std::runtime_error("work with file not open"); + // Push all tags onto the stream and remove them from the vector + while(!d_tags.empty()) { + add_item_tag(0, d_tags.back()); + d_tags.pop_back(); + } + gruel::scoped_lock lock(d_mutex); // hold for the rest of this function while(size) { i = fread(out, d_itemsize, size, d_fp); diff --git a/gnuradio-core/src/lib/io/gr_file_meta_source.h b/gnuradio-core/src/lib/io/gr_file_meta_source.h index 819f4ece2..de0bedf72 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_source.h +++ b/gnuradio-core/src/lib/io/gr_file_meta_source.h @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -92,6 +93,8 @@ class GR_CORE_API gr_file_meta_source : public gr_sync_block FILE *d_fp, *d_hdr_fp; meta_state_t d_state; + std::vector d_tags; + protected: gr_file_meta_source(const char *filename, bool repeat=false, @@ -100,7 +103,8 @@ class GR_CORE_API gr_file_meta_source : public gr_sync_block bool _open(FILE **fp, const char *filename); bool read_header(pmt_t &hdr, pmt_t &extras); - void parse_header(pmt_t hdr); + void parse_header(pmt_t hdr, uint64_t offset, + std::vector &tags); public: ~gr_file_meta_source(); -- cgit From 5e39e6c17b6af181f4cd9110e3a17a2d287318d1 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 13 Dec 2012 14:23:11 -0500 Subject: core: metadata file source parses extras header and converts data to tags. --- gnuradio-core/src/lib/io/gr_file_meta_source.cc | 29 +++++++++++++++++++++++-- gnuradio-core/src/lib/io/gr_file_meta_source.h | 2 ++ 2 files changed, 29 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_meta_source.cc b/gnuradio-core/src/lib/io/gr_file_meta_source.cc index 10f08e79d..02955e7b9 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_source.cc @@ -89,8 +89,10 @@ gr_file_meta_source::gr_file_meta_source(const char *filename, do_update(); pmt_t hdr = PMT_NIL, extras = PMT_NIL; - if(read_header(hdr, extras)) + if(read_header(hdr, extras)) { parse_header(hdr, 0, d_tags); + parse_extras(extras, 0, d_tags); + } else throw std::runtime_error("file_meta_source: could not read header.\n"); @@ -259,6 +261,27 @@ gr_file_meta_source::parse_header(pmt_t hdr, uint64_t offset, } } +void +gr_file_meta_source::parse_extras(pmt_t extras, uint64_t offset, + std::vector &tags) +{ + pmt_t item, key, val; + + size_t nitems = pmt_length(extras); + for(size_t i = 0; i < nitems; i++) { + item = pmt_nth(i, extras); + key = pmt_car(item); + val = pmt_cdr(item); + + gr_tag_t t; + t.offset = offset; + t.key = key; + t.value = val; + t.srcid = alias_pmt(); + tags.push_back(t); + } +} + bool gr_file_meta_source::open(const char *filename) { @@ -351,8 +374,10 @@ gr_file_meta_source::work(int noutput_items, // the new tags to send and set the next segment size. if(d_seg_size == 0) { pmt_t hdr=PMT_NIL, extras=PMT_NIL; - if(read_header(hdr, extras)) + if(read_header(hdr, extras)) { parse_header(hdr, nitems_written(0), d_tags); + parse_extras(extras, nitems_written(0), d_tags); + } else { return -1; } diff --git a/gnuradio-core/src/lib/io/gr_file_meta_source.h b/gnuradio-core/src/lib/io/gr_file_meta_source.h index de0bedf72..46665e415 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_source.h +++ b/gnuradio-core/src/lib/io/gr_file_meta_source.h @@ -105,6 +105,8 @@ class GR_CORE_API gr_file_meta_source : public gr_sync_block bool read_header(pmt_t &hdr, pmt_t &extras); void parse_header(pmt_t hdr, uint64_t offset, std::vector &tags); + void parse_extras(pmt_t extras, uint64_t offset, + std::vector &tags); public: ~gr_file_meta_source(); -- cgit From e760dbff49cfc9fcbf55a7d472158d448c9bb3de Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 13 Dec 2012 18:09:07 -0500 Subject: core: updates metadata parser: don't assume value is a float. Also fixes an error in Doxygen markup. --- gnuradio-core/src/lib/io/gr_file_meta_source.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_meta_source.h b/gnuradio-core/src/lib/io/gr_file_meta_source.h index 46665e415..cb34e11d9 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_source.h +++ b/gnuradio-core/src/lib/io/gr_file_meta_source.h @@ -64,7 +64,7 @@ class GR_CORE_API gr_file_meta_source : public gr_sync_block * \brief Create a meta-data file source. * * \param filename (string): Name of file to write data to. - * \param repeate (bool): Repeats file when EOF is found. + * \param repeat (bool): Repeats file when EOF is found. * \param detached_header (bool): Set to true if header * info is stored in a separate file (usually named filename.hdr) * \param hdr_filename (string): Name of detached header file if used. -- cgit From d12b7b7511c9751af973d1f3cd8fc8020000f4ac Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 14 Dec 2012 10:28:05 -0500 Subject: core: updated file metadata source to support detached header files. --- gnuradio-core/src/lib/io/gr_file_meta_source.cc | 42 ++++++++++++++++--------- gnuradio-core/src/lib/io/gr_file_meta_source.h | 17 +++++----- gnuradio-core/src/lib/io/gr_file_meta_source.i | 11 ++++--- 3 files changed, 43 insertions(+), 27 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_meta_source.cc b/gnuradio-core/src/lib/io/gr_file_meta_source.cc index 02955e7b9..669c5d477 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_source.cc @@ -50,10 +50,10 @@ #endif gr_file_meta_source_sptr -gr_make_file_meta_source(const char *filename, +gr_make_file_meta_source(const std::string &filename, bool repeat, bool detached_header, - const char *hdr_filename) + const std::string &hdr_filename) { return gnuradio::get_initial_sptr (new gr_file_meta_source(filename, @@ -62,10 +62,10 @@ gr_make_file_meta_source(const char *filename, hdr_filename)); } -gr_file_meta_source::gr_file_meta_source(const char *filename, +gr_file_meta_source::gr_file_meta_source(const std::string &filename, bool repeat, bool detached_header, - const char *hdr_filename) + const std::string &hdr_filename) : gr_sync_block("file_meta_source", gr_make_io_signature(0, 0, 0), gr_make_io_signature(1, 1, 1)), @@ -78,12 +78,13 @@ gr_file_meta_source::gr_file_meta_source(const char *filename, d_hdr_fp = 0; d_new_hdr_fp = 0; - if(detached_header == true) + if(detached_header == true) { d_state = STATE_DETACHED; + } else d_state = STATE_INLINE; - if(!open(filename)) + if(!open(filename, hdr_filename)) throw std::runtime_error("file_meta_source: can't open file\n"); do_update(); @@ -120,15 +121,22 @@ gr_file_meta_source::~gr_file_meta_source() bool gr_file_meta_source::read_header(pmt_t &hdr, pmt_t &extras) { + // Select which file handle to read from. + FILE *fp; + if(d_state == STATE_DETACHED) + fp = d_hdr_fp; + else + fp = d_fp; + size_t ret; size_t size = 0; std::string str; char *hdr_buffer = new char[METADATA_HEADER_SIZE]; while(size < METADATA_HEADER_SIZE) { - ret = fread(&hdr_buffer[size], sizeof(char), METADATA_HEADER_SIZE-size, d_fp); + ret = fread(&hdr_buffer[size], sizeof(char), METADATA_HEADER_SIZE-size, fp); if(ret == 0) { delete [] hdr_buffer; - if(feof(d_fp)) + if(feof(fp)) return false; else { std::stringstream s; @@ -157,10 +165,10 @@ gr_file_meta_source::read_header(pmt_t &hdr, pmt_t &extras) size = 0; hdr_buffer = new char[extra_len]; while(size < extra_len) { - ret = fread(&hdr_buffer[size], sizeof(char), extra_len-size, d_fp); + ret = fread(&hdr_buffer[size], sizeof(char), extra_len-size, fp); if(ret == 0) { delete [] hdr_buffer; - if(feof(d_fp)) + if(feof(fp)) return false; else { std::stringstream s; @@ -283,16 +291,20 @@ gr_file_meta_source::parse_extras(pmt_t extras, uint64_t offset, } bool -gr_file_meta_source::open(const char *filename) +gr_file_meta_source::open(const std::string &filename, + const std::string &hdr_filename) { bool ret = true; if(d_state == STATE_DETACHED) { - std::stringstream s; - s << filename << ".hdr"; - ret = _open(&d_new_hdr_fp, s.str().c_str()); + std::string s; + if(hdr_filename == "") + s = filename + ".hdr"; + else + s = hdr_filename; + ret = _open(&d_new_hdr_fp, s.c_str()); } - ret = ret && _open(&d_new_fp, filename); + ret = ret && _open(&d_new_fp, filename.c_str()); d_updated = true; return ret; } diff --git a/gnuradio-core/src/lib/io/gr_file_meta_source.h b/gnuradio-core/src/lib/io/gr_file_meta_source.h index cb34e11d9..95e466936 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_source.h +++ b/gnuradio-core/src/lib/io/gr_file_meta_source.h @@ -36,10 +36,10 @@ class gr_file_meta_source; typedef boost::shared_ptr gr_file_meta_source_sptr; GR_CORE_API gr_file_meta_source_sptr -gr_make_file_meta_source(const char *filename, +gr_make_file_meta_source(const std::string &filename, bool repeat=false, bool detached_header=false, - const char *hdr_filename=""); + const std::string &hdr_filename=""); /*! * \brief Reads stream from file with meta-data headers. Headers are @@ -68,12 +68,14 @@ class GR_CORE_API gr_file_meta_source : public gr_sync_block * \param detached_header (bool): Set to true if header * info is stored in a separate file (usually named filename.hdr) * \param hdr_filename (string): Name of detached header file if used. + * Defaults to 'filename.hdr' if detached_header is true but this + * field is an empty string. */ friend GR_CORE_API gr_file_meta_source_sptr - gr_make_file_meta_source(const char *filename, + gr_make_file_meta_source(const std::string &filename, bool repeat, bool detached_header, - const char *hdr_filename); + const std::string &hdr_filename); private: enum meta_state_t { @@ -96,10 +98,10 @@ class GR_CORE_API gr_file_meta_source : public gr_sync_block std::vector d_tags; protected: - gr_file_meta_source(const char *filename, + gr_file_meta_source(const std::string &filename, bool repeat=false, bool detached_header=false, - const char *hdr_filename=""); + const std::string &hdr_filename=""); bool _open(FILE **fp, const char *filename); bool read_header(pmt_t &hdr, pmt_t &extras); @@ -111,7 +113,8 @@ class GR_CORE_API gr_file_meta_source : public gr_sync_block public: ~gr_file_meta_source(); - bool open(const char *filename); + bool open(const std::string &filename, + const std::string &hdr_filename=""); void close(); void do_update(); diff --git a/gnuradio-core/src/lib/io/gr_file_meta_source.i b/gnuradio-core/src/lib/io/gr_file_meta_source.i index 6cf089da1..cb1281036 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_source.i +++ b/gnuradio-core/src/lib/io/gr_file_meta_source.i @@ -23,22 +23,23 @@ GR_SWIG_BLOCK_MAGIC(gr,file_meta_source) gr_file_meta_source_sptr -gr_make_file_meta_source(const char *filename, +gr_make_file_meta_source(const std::string &filename, bool repeat=false, bool detached_header=false, - const char *hdr_filename=""); + const std::string &hdr_filename=""); class gr_file_meta_source : public gr_sync_block { protected: - gr_file_meta_source(const char *filename, + gr_file_meta_source(const std::string &filename, bool repeat, bool detached_header, - const char *hdr_filename); + const std::string &hdr_filename); public: ~gr_file_meta_source(); - bool open(const char *filename); + bool open(const std::string &filename, + const std::string &hdr_filename=""); void close(); }; -- cgit From 8f7271cfe496346f34a6e7352ec0f597b79341a4 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 14 Dec 2012 10:35:31 -0500 Subject: core: use std::string in file metadata sink (easier to work with; matches source). --- gnuradio-core/src/lib/io/gr_file_meta_sink.cc | 13 ++++++------- gnuradio-core/src/lib/io/gr_file_meta_sink.h | 8 ++++---- gnuradio-core/src/lib/io/gr_file_meta_sink.i | 6 +++--- 3 files changed, 13 insertions(+), 14 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc index 43900bcd9..2b722bc61 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc @@ -50,7 +50,7 @@ #endif gr_file_meta_sink_sptr -gr_make_file_meta_sink(size_t itemsize, const char *filename, +gr_make_file_meta_sink(size_t itemsize, const std::string &filename, double samp_rate, double relative_rate, gr_file_types type, bool complex, size_t max_segment_size, @@ -66,7 +66,7 @@ gr_make_file_meta_sink(size_t itemsize, const char *filename, detached_header)); } -gr_file_meta_sink::gr_file_meta_sink(size_t itemsize, const char *filename, +gr_file_meta_sink::gr_file_meta_sink(size_t itemsize, const std::string &filename, double samp_rate, double relative_rate, gr_file_types type, bool complex, size_t max_segment_size, @@ -149,16 +149,15 @@ gr_file_meta_sink::~gr_file_meta_sink() } bool -gr_file_meta_sink::open(const char *filename) +gr_file_meta_sink::open(const std::string &filename) { bool ret = true; if(d_state == STATE_DETACHED) { - std::stringstream s; - s << filename << ".hdr"; - ret = _open(&d_new_hdr_fp, s.str().c_str()); + std::string s = filename + ".hdr"; + ret = _open(&d_new_hdr_fp, s.c_str()); } - ret = ret && _open(&d_new_fp, filename); + ret = ret && _open(&d_new_fp, filename.c_str()); d_updated = true; return ret; } diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.h b/gnuradio-core/src/lib/io/gr_file_meta_sink.h index e5374af2b..c0219ac25 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.h @@ -48,7 +48,7 @@ class gr_file_meta_sink; typedef boost::shared_ptr gr_file_meta_sink_sptr; GR_CORE_API gr_file_meta_sink_sptr -gr_make_file_meta_sink(size_t itemsize, const char *filename, +gr_make_file_meta_sink(size_t itemsize, const std::string &filename, double samp_rate=1, double relative_rate=1, gr_file_types type=GR_FILE_FLOAT, bool complex=true, size_t max_segment_size=1000000, @@ -99,7 +99,7 @@ class GR_CORE_API gr_file_meta_sink : public gr_sync_block * info in a separate file (named filename.hdr) */ friend GR_CORE_API gr_file_meta_sink_sptr - gr_make_file_meta_sink(size_t itemsize, const char *filename, + gr_make_file_meta_sink(size_t itemsize, const std::string &filename, double samp_rate, double relative_rate, gr_file_types type, bool complex, size_t max_segment_size, @@ -130,7 +130,7 @@ class GR_CORE_API gr_file_meta_sink : public gr_sync_block meta_state_t d_state; protected: - gr_file_meta_sink(size_t itemsize, const char *filename, + gr_file_meta_sink(size_t itemsize, const std::string &filename, double samp_rate=1, double relative_rate=1, gr_file_types type=GR_FILE_FLOAT, bool complex=true, size_t max_segment_size=1000000, @@ -150,7 +150,7 @@ class GR_CORE_API gr_file_meta_sink : public gr_sync_block public: ~gr_file_meta_sink(); - bool open(const char *filename); + bool open(const std::string &filename); void close(); void do_update(); diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.i b/gnuradio-core/src/lib/io/gr_file_meta_sink.i index 9513b090f..743e89730 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.i +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.i @@ -37,7 +37,7 @@ enum gr_file_types { }; gr_file_meta_sink_sptr -gr_make_file_meta_sink(size_t itemsize, const char *filename, +gr_make_file_meta_sink(size_t itemsize, const std::string &filename, double samp_rate=1, double relative_rate=1, gr_file_types type=GR_FILE_FLOAT, bool complex=true, size_t max_segment_size=1000000, @@ -47,7 +47,7 @@ gr_make_file_meta_sink(size_t itemsize, const char *filename, class gr_file_meta_sink : public gr_sync_block { protected: - gr_file_meta_sink(size_t itemsize, const char *filename, + gr_file_meta_sink(size_t itemsize, const std::string &filename, double samp_rate, double relative_rate, gr_file_types type, bool complex, size_t max_segment_size, @@ -57,7 +57,7 @@ class gr_file_meta_sink : public gr_sync_block public: ~gr_file_meta_sink(); - bool open(const char *filename); + bool open(const std::string &filename); void close(); void set_unbuffered(bool unbuffered); }; -- cgit From 057c4c67e785f36138a289ed1f5400cf8f8d55b5 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 14 Dec 2012 11:32:55 -0500 Subject: core: When the file meta sink is closed by user, make sure the last header is properly updated. --- gnuradio-core/src/lib/io/gr_file_meta_sink.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc index 2b722bc61..9cec5bc28 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc @@ -131,8 +131,6 @@ gr_file_meta_sink::gr_file_meta_sink(size_t itemsize, const std::string &filenam gr_file_meta_sink::~gr_file_meta_sink() { - update_last_header(); - close(); if(d_fp) { @@ -196,6 +194,8 @@ void gr_file_meta_sink::close() { gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function + update_last_header(); + if(d_state == STATE_DETACHED) { if(d_new_hdr_fp) { fclose(d_new_hdr_fp); -- cgit From 75b01cc4f55c38dfe5bb329c23df591e43cf4c66 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 14 Dec 2012 12:05:00 -0500 Subject: core: Added detached header test to file metadata QA. Also adds a flush when updating the headers. --- gnuradio-core/src/lib/io/gr_file_meta_sink.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc index 9cec5bc28..b016dd1d3 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc @@ -261,6 +261,8 @@ gr_file_meta_sink::write_header(FILE *fp, pmt_t header, pmt_t extra) throw std::runtime_error("file_meta_sink: error writing extra to file.\n"); } } + + fflush(fp); } void -- cgit From 3910c6da3c62232e6593e5fcfe53f5ece933a294 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 14 Dec 2012 13:57:29 -0500 Subject: core: adding itemsize key to metadata header to allow for vectorized items. This also simplifies some code in the source since we're told exactly what the items size is and don't have to infer. Also adds an example using vector items. --- gnuradio-core/src/lib/io/gr_file_meta_sink.cc | 9 ++++--- gnuradio-core/src/lib/io/gr_file_meta_sink.h | 2 +- gnuradio-core/src/lib/io/gr_file_meta_sink.i | 2 +- gnuradio-core/src/lib/io/gr_file_meta_source.cc | 33 +++++-------------------- 4 files changed, 13 insertions(+), 33 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc index b016dd1d3..ab0acbdb4 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc @@ -116,10 +116,11 @@ gr_file_meta_sink::gr_file_meta_sink(size_t itemsize, const std::string &filenam d_header = pmt_dict_add(d_header, mp("version"), mp(METADATA_VERSION)); d_header = pmt_dict_add(d_header, mp("rx_rate"), mp(samp_rate)); d_header = pmt_dict_add(d_header, mp("rx_time"), timestamp); + d_header = pmt_dict_add(d_header, mp("size"), pmt_from_long(d_itemsize)); d_header = pmt_dict_add(d_header, mp("type"), pmt_from_long(type)); d_header = pmt_dict_add(d_header, mp("cplx"), complex ? PMT_T : PMT_F); d_header = pmt_dict_add(d_header, mp("strt"), pmt_from_uint64(METADATA_HEADER_SIZE+d_extra_size)); - d_header = pmt_dict_add(d_header, mp("size"), pmt_from_uint64(0)); + d_header = pmt_dict_add(d_header, mp("bytes"), pmt_from_uint64(0)); do_update(); @@ -305,7 +306,7 @@ gr_file_meta_sink::update_last_header_inline() size_t hdrlen = pmt_to_uint64(pmt_dict_ref(d_header, mp("strt"), PMT_NIL)); size_t seg_size = d_itemsize*d_total_seg_size; pmt_t s = pmt_from_uint64(seg_size); - update_header(mp("size"), s); + update_header(mp("bytes"), s); update_header(mp("strt"), pmt_from_uint64(METADATA_HEADER_SIZE+d_extra_size)); fseek(d_fp, -seg_size-hdrlen, SEEK_CUR); write_header(d_fp, d_header, d_extra); @@ -320,7 +321,7 @@ gr_file_meta_sink::update_last_header_detached() size_t hdrlen = pmt_to_uint64(pmt_dict_ref(d_header, mp("strt"), PMT_NIL)); size_t seg_size = d_itemsize*d_total_seg_size; pmt_t s = pmt_from_uint64(seg_size); - update_header(mp("size"), s); + update_header(mp("bytes"), s); update_header(mp("strt"), pmt_from_uint64(METADATA_HEADER_SIZE+d_extra_size)); fseek(d_hdr_fp, -hdrlen, SEEK_CUR); write_header(d_hdr_fp, d_header, d_extra); @@ -333,7 +334,7 @@ gr_file_meta_sink::write_and_update() // based on current index + header size. //uint64_t loc = get_last_header_loc(); pmt_t s = pmt_from_uint64(0); - update_header(mp("size"), s); + update_header(mp("bytes"), s); // If we have multiple tags on the same offset, this makes // sure we just overwrite the same header each time instead diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.h b/gnuradio-core/src/lib/io/gr_file_meta_sink.h index c0219ac25..9b67cc4c8 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.h @@ -31,7 +31,7 @@ using namespace pmt; const char METADATA_VERSION = 0; -const size_t METADATA_HEADER_SIZE = 134; +const size_t METADATA_HEADER_SIZE = 149; enum gr_file_types { GR_FILE_BYTE=0, diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.i b/gnuradio-core/src/lib/io/gr_file_meta_sink.i index 743e89730..6fa34913b 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.i +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.i @@ -23,7 +23,7 @@ GR_SWIG_BLOCK_MAGIC(gr,file_meta_sink) const char METADATA_VERSION = 0; -const size_t METADATA_HEADER_SIZE = 134; +const size_t METADATA_HEADER_SIZE = 149; enum gr_file_types { GR_FILE_BYTE=0, diff --git a/gnuradio-core/src/lib/io/gr_file_meta_source.cc b/gnuradio-core/src/lib/io/gr_file_meta_source.cc index 669c5d477..d940e5edc 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_source.cc @@ -228,38 +228,17 @@ gr_file_meta_source::parse_header(pmt_t hdr, uint64_t offset, throw std::runtime_error("file_meta_source: Could not extract time stamp.\n"); } - // GET DATA TYPE - if(pmt_dict_has_key(hdr, pmt_string_to_symbol("type"))) { - int t = pmt_to_long(pmt_dict_ref(hdr, pmt_string_to_symbol("type"), PMT_NIL)); - switch(t) { - case(GR_FILE_CHAR): d_itemsize = sizeof(char); break; - case(GR_FILE_SHORT): d_itemsize = sizeof(short); break; - case(GR_FILE_INT): d_itemsize = sizeof(int); break; - case(GR_FILE_LONG): d_itemsize = sizeof(long int); break; - case(GR_FILE_LONG_LONG): d_itemsize = sizeof(long long int); break; - case(GR_FILE_FLOAT): d_itemsize = sizeof(float); break; - case(GR_FILE_DOUBLE): d_itemsize = sizeof(double); break; - default: - throw std::runtime_error("file_meta_source: Could not determine data type size.\n"); - } - } - else { - throw std::runtime_error("file_meta_source: Could not extract data type.\n"); - } - - // GET COMPLEX INDICATOR - if(pmt_dict_has_key(hdr, pmt_string_to_symbol("cplx"))) { - bool cplx = pmt_to_bool(pmt_dict_ref(hdr, pmt_string_to_symbol("cplx"), PMT_NIL)); - if(cplx) - d_itemsize *= 2; + // GET ITEM SIZE OF DATA + if(pmt_dict_has_key(hdr, pmt_string_to_symbol("size"))) { + d_itemsize = pmt_to_long(pmt_dict_ref(hdr, pmt_string_to_symbol("size"), PMT_NIL)); } else { - throw std::runtime_error("file_meta_source: Could not extract complex indicator.\n"); + throw std::runtime_error("file_meta_source: Could not extract item size.\n"); } // GET SEGMENT SIZE - if(pmt_dict_has_key(hdr, pmt_string_to_symbol("size"))) { - d_seg_size = pmt_to_uint64(pmt_dict_ref(hdr, pmt_string_to_symbol("size"), PMT_NIL)); + if(pmt_dict_has_key(hdr, pmt_string_to_symbol("bytes"))) { + d_seg_size = pmt_to_uint64(pmt_dict_ref(hdr, pmt_string_to_symbol("bytes"), PMT_NIL)); // Convert from bytes to items d_seg_size /= d_itemsize; -- cgit From 461ece56b36a44b2405282630157739c7f9a26ba Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 14 Dec 2012 16:10:30 -0500 Subject: blocks: moving file metadata sink/source to gr-blocks. --- gnuradio-core/src/lib/io/CMakeLists.txt | 2 - gnuradio-core/src/lib/io/gr_file_meta_sink.cc | 457 ------------------------ gnuradio-core/src/lib/io/gr_file_meta_sink.h | 169 --------- gnuradio-core/src/lib/io/gr_file_meta_sink.i | 63 ---- gnuradio-core/src/lib/io/gr_file_meta_source.cc | 427 ---------------------- gnuradio-core/src/lib/io/gr_file_meta_source.h | 126 ------- gnuradio-core/src/lib/io/gr_file_meta_source.i | 45 --- gnuradio-core/src/lib/io/io.i | 4 - 8 files changed, 1293 deletions(-) delete mode 100644 gnuradio-core/src/lib/io/gr_file_meta_sink.cc delete mode 100644 gnuradio-core/src/lib/io/gr_file_meta_sink.h delete mode 100644 gnuradio-core/src/lib/io/gr_file_meta_sink.i delete mode 100644 gnuradio-core/src/lib/io/gr_file_meta_source.cc delete mode 100644 gnuradio-core/src/lib/io/gr_file_meta_source.h delete mode 100644 gnuradio-core/src/lib/io/gr_file_meta_source.i (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/CMakeLists.txt b/gnuradio-core/src/lib/io/CMakeLists.txt index 1cbcd2daf..59ca06b5a 100644 --- a/gnuradio-core/src/lib/io/CMakeLists.txt +++ b/gnuradio-core/src/lib/io/CMakeLists.txt @@ -85,10 +85,8 @@ endif(ENABLE_PYTHON) ######################################################################## set(gr_core_io_triple_threats gr_file_sink - gr_file_meta_sink gr_file_sink_base gr_file_source - gr_file_meta_source gr_file_descriptor_sink gr_file_descriptor_source gr_message_debug diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc deleted file mode 100644 index ab0acbdb4..000000000 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc +++ /dev/null @@ -1,457 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2012 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, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include - -// win32 (mingw/msvc) specific -#ifdef HAVE_IO_H -#include -#endif -#ifdef O_BINARY -#define OUR_O_BINARY O_BINARY -#else -#define OUR_O_BINARY 0 -#endif - -// should be handled via configure -#ifdef O_LARGEFILE -#define OUR_O_LARGEFILE O_LARGEFILE -#else -#define OUR_O_LARGEFILE 0 -#endif - -gr_file_meta_sink_sptr -gr_make_file_meta_sink(size_t itemsize, const std::string &filename, - double samp_rate, double relative_rate, - gr_file_types type, bool complex, - size_t max_segment_size, - const std::string &extra_dict, - bool detached_header) -{ - return gnuradio::get_initial_sptr - (new gr_file_meta_sink(itemsize, filename, - samp_rate, relative_rate, - type, complex, - max_segment_size, - extra_dict, - detached_header)); -} - -gr_file_meta_sink::gr_file_meta_sink(size_t itemsize, const std::string &filename, - double samp_rate, double relative_rate, - gr_file_types type, bool complex, - size_t max_segment_size, - const std::string &extra_dict, - bool detached_header) - : gr_sync_block("file_meta_sink", - gr_make_io_signature(1, 1, itemsize), - gr_make_io_signature(0, 0, 0)), - d_itemsize(itemsize), - d_samp_rate(samp_rate), d_relative_rate(relative_rate), - d_max_seg_size(max_segment_size), d_total_seg_size(0), - d_updated(false), d_unbuffered(false) -{ - d_fp = 0; - d_new_fp = 0; - d_hdr_fp = 0; - d_new_hdr_fp = 0; - - if(detached_header == true) - d_state = STATE_DETACHED; - else - d_state = STATE_INLINE; - - if(!open(filename)) - throw std::runtime_error("file_meta_sink: can't open file\n"); - - pmt_t timestamp = pmt_make_tuple(pmt_from_uint64(0), - pmt_from_double(0)); - - // handle extra dictionary - d_extra = pmt_make_dict(); - if(extra_dict.size() > 0) { - pmt_t extras = pmt_deserialize_str(extra_dict); - pmt_t keys = pmt_dict_keys(extras); - pmt_t vals = pmt_dict_values(extras); - size_t nitems = pmt_length(keys); - for(size_t i = 0; i < nitems; i++) { - d_extra = pmt_dict_add(d_extra, - pmt_nth(i, keys), - pmt_nth(i, vals)); - } - } - - d_extra_size = pmt_serialize_str(d_extra).size(); - - d_header = pmt_make_dict(); - d_header = pmt_dict_add(d_header, mp("version"), mp(METADATA_VERSION)); - d_header = pmt_dict_add(d_header, mp("rx_rate"), mp(samp_rate)); - d_header = pmt_dict_add(d_header, mp("rx_time"), timestamp); - d_header = pmt_dict_add(d_header, mp("size"), pmt_from_long(d_itemsize)); - d_header = pmt_dict_add(d_header, mp("type"), pmt_from_long(type)); - d_header = pmt_dict_add(d_header, mp("cplx"), complex ? PMT_T : PMT_F); - d_header = pmt_dict_add(d_header, mp("strt"), pmt_from_uint64(METADATA_HEADER_SIZE+d_extra_size)); - d_header = pmt_dict_add(d_header, mp("bytes"), pmt_from_uint64(0)); - - do_update(); - - if(d_state == STATE_DETACHED) - write_header(d_hdr_fp, d_header, d_extra); - else - write_header(d_fp, d_header, d_extra); -} - -gr_file_meta_sink::~gr_file_meta_sink() -{ - close(); - - if(d_fp) { - fclose(d_fp); - d_fp = 0; - } - - if(d_state == STATE_DETACHED) { - if(d_hdr_fp) { - fclose(d_hdr_fp); - d_hdr_fp = 0; - } - } -} - -bool -gr_file_meta_sink::open(const std::string &filename) -{ - bool ret = true; - if(d_state == STATE_DETACHED) { - std::string s = filename + ".hdr"; - ret = _open(&d_new_hdr_fp, s.c_str()); - } - - ret = ret && _open(&d_new_fp, filename.c_str()); - d_updated = true; - return ret; -} - -bool -gr_file_meta_sink::_open(FILE **fp, const char *filename) -{ - gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function - - bool ret = true; - int fd; - - if((fd = ::open(filename, - O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY, - 0664)) < 0){ - perror(filename); - return false; - } - - if(*fp) { // if we've already got a new one open, close it - fclose(*fp); - fp = 0; - } - - if((*fp = fdopen(fd, "wb")) == NULL) { - perror(filename); - ::close(fd); // don't leak file descriptor if fdopen fails. - } - - ret = fp != 0; - - return ret; -} - -void -gr_file_meta_sink::close() -{ - gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function - update_last_header(); - - if(d_state == STATE_DETACHED) { - if(d_new_hdr_fp) { - fclose(d_new_hdr_fp); - d_new_hdr_fp = 0; - } - } - - if(d_new_fp) { - fclose(d_new_fp); - d_new_fp = 0; - } - d_updated = true; -} - -void -gr_file_meta_sink::do_update() -{ - if(d_updated) { - gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this block - if(d_state == STATE_DETACHED) { - if(d_hdr_fp) - fclose(d_hdr_fp); - d_hdr_fp = d_new_hdr_fp; // install new file pointer - d_new_hdr_fp = 0; - } - - if(d_fp) - fclose(d_fp); - d_fp = d_new_fp; // install new file pointer - d_new_fp = 0; - - d_updated = false; - } -} - -void -gr_file_meta_sink::write_header(FILE *fp, pmt_t header, pmt_t extra) -{ - std::string header_str = pmt_serialize_str(header); - std::string extra_str = pmt_serialize_str(extra); - - if((header_str.size() != METADATA_HEADER_SIZE) && (extra_str.size() != d_extra_size)) - throw std::runtime_error("file_meta_sink: header or extras is wrong size.\n"); - - size_t nwritten = 0; - while(nwritten < header_str.size()) { - std::string sub = header_str.substr(nwritten); - int count = fwrite(sub.c_str(), sizeof(char), sub.size(), fp); - nwritten += count; - if((count == 0) && (ferror(fp))) { - fclose(fp); - throw std::runtime_error("file_meta_sink: error writing header to file.\n"); - } - } - - nwritten = 0; - while(nwritten < extra_str.size()) { - std::string sub = extra_str.substr(nwritten); - int count = fwrite(sub.c_str(), sizeof(char), sub.size(), fp); - nwritten += count; - if((count == 0) && (ferror(fp))) { - fclose(fp); - throw std::runtime_error("file_meta_sink: error writing extra to file.\n"); - } - } - - fflush(fp); -} - -void -gr_file_meta_sink::update_header(pmt_t key, pmt_t value) -{ - // Special handling caveat to transform rate from radio source into - // the rate at this sink. - if(pmt_eq(key, mp("rx_rate"))) { - d_samp_rate = pmt_to_double(value); - value = pmt_from_double(d_samp_rate*d_relative_rate); - } - - // If the tag is not part of the standard header, we put it into the - // extra data, which either updates the current dictionary or adds a - // new item. - if(pmt_dict_has_key(d_header, key)) { - d_header = pmt_dict_add(d_header, key, value); - } - else { - d_extra = pmt_dict_add(d_extra, key, value); - d_extra_size = pmt_serialize_str(d_extra).size(); - } -} - -void -gr_file_meta_sink::update_last_header() -{ - if(d_state == STATE_DETACHED) - update_last_header_detached(); - else - update_last_header_inline(); -} - -void -gr_file_meta_sink::update_last_header_inline() -{ - // Update the last header info with the number of samples this - // block represents. - - size_t hdrlen = pmt_to_uint64(pmt_dict_ref(d_header, mp("strt"), PMT_NIL)); - size_t seg_size = d_itemsize*d_total_seg_size; - pmt_t s = pmt_from_uint64(seg_size); - update_header(mp("bytes"), s); - update_header(mp("strt"), pmt_from_uint64(METADATA_HEADER_SIZE+d_extra_size)); - fseek(d_fp, -seg_size-hdrlen, SEEK_CUR); - write_header(d_fp, d_header, d_extra); - fseek(d_fp, seg_size, SEEK_CUR); -} - -void -gr_file_meta_sink::update_last_header_detached() -{ - // Update the last header info with the number of samples this - // block represents. - size_t hdrlen = pmt_to_uint64(pmt_dict_ref(d_header, mp("strt"), PMT_NIL)); - size_t seg_size = d_itemsize*d_total_seg_size; - pmt_t s = pmt_from_uint64(seg_size); - update_header(mp("bytes"), s); - update_header(mp("strt"), pmt_from_uint64(METADATA_HEADER_SIZE+d_extra_size)); - fseek(d_hdr_fp, -hdrlen, SEEK_CUR); - write_header(d_hdr_fp, d_header, d_extra); -} - -void -gr_file_meta_sink::write_and_update() -{ - // New header, so set current size of chunk to 0 and start of chunk - // based on current index + header size. - //uint64_t loc = get_last_header_loc(); - pmt_t s = pmt_from_uint64(0); - update_header(mp("bytes"), s); - - // If we have multiple tags on the same offset, this makes - // sure we just overwrite the same header each time instead - // of creating a new header per tag. - s = pmt_from_uint64(METADATA_HEADER_SIZE + d_extra_size); - update_header(mp("strt"), s); - - if(d_state == STATE_DETACHED) - write_header(d_hdr_fp, d_header, d_extra); - else - write_header(d_fp, d_header, d_extra); -} - -void -gr_file_meta_sink::update_rx_time() -{ - pmt_t rx_time = pmt_string_to_symbol("rx_time"); - pmt_t r = pmt_dict_ref(d_header, rx_time, PMT_NIL); - uint64_t secs = pmt_to_uint64(pmt_tuple_ref(r, 0)); - double fracs = pmt_to_double(pmt_tuple_ref(r, 1)); - double diff = d_total_seg_size / (d_samp_rate*d_relative_rate); - - //std::cerr << "old secs: " << secs << std::endl; - //std::cerr << "old fracs: " << fracs << std::endl; - //std::cerr << "seg size: " << d_total_seg_size << std::endl; - //std::cerr << "diff: " << diff << std::endl; - - fracs += diff; - uint64_t new_secs = static_cast(fracs); - secs += new_secs; - fracs -= new_secs; - - //std::cerr << "new secs: " << secs << std::endl; - //std::cerr << "new fracs: " << fracs << std::endl << std::endl; - - r = pmt_make_tuple(pmt_from_uint64(secs), pmt_from_double(fracs)); - d_header = pmt_dict_add(d_header, rx_time, r); -} - -int -gr_file_meta_sink::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - char *inbuf = (char*)input_items[0]; - int nwritten = 0; - - do_update(); // update d_fp is reqd - - if(!d_fp) - return noutput_items; // drop output on the floor - - uint64_t abs_N = nitems_read(0); - uint64_t end_N = abs_N + (uint64_t)(noutput_items); - std::vector all_tags; - get_tags_in_range(all_tags, 0, abs_N, end_N); - - std::vector::iterator itr; - for(itr = all_tags.begin(); itr != all_tags.end(); itr++) { - int item_offset = (int)(itr->offset - abs_N); - - // Write date to file up to the next tag location - while(nwritten < item_offset) { - size_t towrite = std::min(d_max_seg_size - d_total_seg_size, - (size_t)(item_offset - nwritten)); - int count = fwrite(inbuf, d_itemsize, towrite, d_fp); - if(count == 0) // FIXME add error handling - break; - nwritten += count; - inbuf += count * d_itemsize; - - d_total_seg_size += count; - - // Only add a new header if we are not at the position of the - // next tag - if((d_total_seg_size == d_max_seg_size) && - (nwritten < item_offset)) { - update_last_header(); - update_rx_time(); - write_and_update(); - d_total_seg_size = 0; - } - } - - if(d_total_seg_size > 0) { - update_last_header(); - update_header(itr->key, itr->value); - write_and_update(); - d_total_seg_size = 0; - } - else { - update_header(itr->key, itr->value); - update_last_header(); - } - } - - // Finish up the rest of the data after tags - while(nwritten < noutput_items) { - size_t towrite = std::min(d_max_seg_size - d_total_seg_size, - (size_t)(noutput_items - nwritten)); - int count = fwrite(inbuf, d_itemsize, towrite, d_fp); - if(count == 0) // FIXME add error handling - break; - nwritten += count; - inbuf += count * d_itemsize; - - d_total_seg_size += count; - if(d_total_seg_size == d_max_seg_size) { - update_last_header(); - update_rx_time(); - write_and_update(); - d_total_seg_size = 0; - } - } - - if(d_unbuffered) - fflush(d_fp); - - return nwritten; -} diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.h b/gnuradio-core/src/lib/io/gr_file_meta_sink.h deleted file mode 100644 index 9b67cc4c8..000000000 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.h +++ /dev/null @@ -1,169 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2012 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, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GR_FILE_META_SINK_H -#define INCLUDED_GR_FILE_META_SINK_H - -#include -#include -#include -#include - -using namespace pmt; - -const char METADATA_VERSION = 0; -const size_t METADATA_HEADER_SIZE = 149; - -enum gr_file_types { - GR_FILE_BYTE=0, - GR_FILE_CHAR=0, - GR_FILE_SHORT=1, - GR_FILE_INT, - GR_FILE_LONG, - GR_FILE_LONG_LONG, - GR_FILE_FLOAT, - GR_FILE_DOUBLE, -}; - -class gr_file_meta_sink; -typedef boost::shared_ptr gr_file_meta_sink_sptr; - -GR_CORE_API gr_file_meta_sink_sptr -gr_make_file_meta_sink(size_t itemsize, const std::string &filename, - double samp_rate=1, double relative_rate=1, - gr_file_types type=GR_FILE_FLOAT, bool complex=true, - size_t max_segment_size=1000000, - const std::string &extra_dict="", - bool detached_header=false); - -/*! - * \brief Write stream to file with meta-data headers. - * \ingroup sink_blk - * - * These files represent data as binary information in between - * meta-data headers. The headers contain information about the type - * of data and properties of the data in the next segment of - * samples. The information includes: - * - * rx_rate (double): sample rate of data. - * rx_time (uint64_t, double): time stamp of first sample in segment. - * type (gr_file_types as int32_t): data type. - * cplx (bool): Is data complex? - * strt (uint64_t): Starting byte of data in this segment. - * size (uint64_t): Size in bytes of data in this segment. - * - * Tags can be sent to the file to update the information, which will - * create a new header. Headers are found by searching from the first - * header (at position 0 in the file) and reading where the data - * segment starts plus the data segment size. Following will either be - * a new header or EOF. - */ -class GR_CORE_API gr_file_meta_sink : public gr_sync_block -{ - /*! - * \brief Create a meta-data file sink. - * - * \param itemsize (size_t): Size of data type. - * \param filename (string): Name of file to write data to. - * \param samp_rate (double): Sample rate of data. If sample rate will be - * set by a tag, such as rx_tag from a UHD source, this is - * basically ignored. - * \param relative_rate (double): Rate chance from source of sample - * rate tag to sink. - * \param type (gr_file_types): Data type (int, float, etc.) - * \param complex (bool): If data stream is complex - * \param max_segment_size (size_t): Length of a single segment - * before the header is repeated (in items). - * \param extra_dict (string): a serialized PMT dictionary of extra - * information. Currently not supported. - * \param detached_header (bool): Set to true to store the header - * info in a separate file (named filename.hdr) - */ - friend GR_CORE_API gr_file_meta_sink_sptr - gr_make_file_meta_sink(size_t itemsize, const std::string &filename, - double samp_rate, double relative_rate, - gr_file_types type, bool complex, - size_t max_segment_size, - const std::string &extra_dict, - bool detached_header); - - private: - enum meta_state_t { - STATE_INLINE=0, - STATE_DETACHED - }; - - - size_t d_itemsize; - double d_samp_rate; - double d_relative_rate; - size_t d_max_seg_size; - size_t d_total_seg_size; - pmt_t d_header; - pmt_t d_extra; - size_t d_extra_size; - bool d_updated; - bool d_unbuffered; - - boost::mutex d_mutex; - FILE *d_new_fp, *d_new_hdr_fp; - FILE *d_fp, *d_hdr_fp; - meta_state_t d_state; - - protected: - gr_file_meta_sink(size_t itemsize, const std::string &filename, - double samp_rate=1, double relative_rate=1, - gr_file_types type=GR_FILE_FLOAT, bool complex=true, - size_t max_segment_size=1000000, - const std::string &extra_dict="", - bool detached_header=false); - - void write_header(FILE *fp, pmt_t header, pmt_t extra); - void update_header(pmt_t key, pmt_t value); - void update_last_header(); - void update_last_header_inline(); - void update_last_header_detached(); - void write_and_update(); - void update_rx_time(); - - bool _open(FILE **fp, const char *filename); - - public: - ~gr_file_meta_sink(); - - bool open(const std::string &filename); - void close(); - void do_update(); - - void set_unbuffered(bool unbuffered) - { - d_unbuffered = unbuffered; - } - - //FIXME: add setters/getters for properties. - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); -}; - -#endif /* INCLUDED_GR_FILE_META_SINK_H */ diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.i b/gnuradio-core/src/lib/io/gr_file_meta_sink.i deleted file mode 100644 index 6fa34913b..000000000 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.i +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2012 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, - * Boston, MA 02110-1301, USA. - */ - -GR_SWIG_BLOCK_MAGIC(gr,file_meta_sink) - -const char METADATA_VERSION = 0; -const size_t METADATA_HEADER_SIZE = 149; - -enum gr_file_types { - GR_FILE_BYTE=0, - GR_FILE_CHAR=0, - GR_FILE_SHORT, - GR_FILE_INT, - GR_FILE_LONG, - GR_FILE_LONG_LONG, - GR_FILE_FLOAT, - GR_FILE_DOUBLE, -}; - -gr_file_meta_sink_sptr -gr_make_file_meta_sink(size_t itemsize, const std::string &filename, - double samp_rate=1, double relative_rate=1, - gr_file_types type=GR_FILE_FLOAT, bool complex=true, - size_t max_segment_size=1000000, - const std::string & extra_dict="", - bool detached_header=false); - -class gr_file_meta_sink : public gr_sync_block -{ - protected: - gr_file_meta_sink(size_t itemsize, const std::string &filename, - double samp_rate, double relative_rate, - gr_file_types type, bool complex, - size_t max_segment_size, - const std::string & extra_dict, - bool detached_header); - - public: - ~gr_file_meta_sink(); - - bool open(const std::string &filename); - void close(); - void set_unbuffered(bool unbuffered); -}; diff --git a/gnuradio-core/src/lib/io/gr_file_meta_source.cc b/gnuradio-core/src/lib/io/gr_file_meta_source.cc deleted file mode 100644 index d940e5edc..000000000 --- a/gnuradio-core/src/lib/io/gr_file_meta_source.cc +++ /dev/null @@ -1,427 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2012 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, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include - -// win32 (mingw/msvc) specific -#ifdef HAVE_IO_H -#include -#endif -#ifdef O_BINARY -#define OUR_O_BINARY O_BINARY -#else -#define OUR_O_BINARY 0 -#endif - -// should be handled via configure -#ifdef O_LARGEFILE -#define OUR_O_LARGEFILE O_LARGEFILE -#else -#define OUR_O_LARGEFILE 0 -#endif - -gr_file_meta_source_sptr -gr_make_file_meta_source(const std::string &filename, - bool repeat, - bool detached_header, - const std::string &hdr_filename) -{ - return gnuradio::get_initial_sptr - (new gr_file_meta_source(filename, - repeat, - detached_header, - hdr_filename)); -} - -gr_file_meta_source::gr_file_meta_source(const std::string &filename, - bool repeat, - bool detached_header, - const std::string &hdr_filename) - : gr_sync_block("file_meta_source", - gr_make_io_signature(0, 0, 0), - gr_make_io_signature(1, 1, 1)), - d_itemsize(0), d_samp_rate(0), - d_seg_size(0), - d_updated(false), d_repeat(repeat) -{ - d_fp = 0; - d_new_fp = 0; - d_hdr_fp = 0; - d_new_hdr_fp = 0; - - if(detached_header == true) { - d_state = STATE_DETACHED; - } - else - d_state = STATE_INLINE; - - if(!open(filename, hdr_filename)) - throw std::runtime_error("file_meta_source: can't open file\n"); - - do_update(); - - pmt_t hdr = PMT_NIL, extras = PMT_NIL; - if(read_header(hdr, extras)) { - parse_header(hdr, 0, d_tags); - parse_extras(extras, 0, d_tags); - } - else - throw std::runtime_error("file_meta_source: could not read header.\n"); - - // Set output signature based on itemsize info in header - set_output_signature(gr_make_io_signature(1, 1, d_itemsize)); -} - -gr_file_meta_source::~gr_file_meta_source() -{ - close(); - - if(d_fp) { - fclose(d_fp); - d_fp = 0; - } - - if(d_state == STATE_DETACHED) { - if(d_hdr_fp) { - fclose(d_hdr_fp); - d_hdr_fp = 0; - } - } -} - -bool -gr_file_meta_source::read_header(pmt_t &hdr, pmt_t &extras) -{ - // Select which file handle to read from. - FILE *fp; - if(d_state == STATE_DETACHED) - fp = d_hdr_fp; - else - fp = d_fp; - - size_t ret; - size_t size = 0; - std::string str; - char *hdr_buffer = new char[METADATA_HEADER_SIZE]; - while(size < METADATA_HEADER_SIZE) { - ret = fread(&hdr_buffer[size], sizeof(char), METADATA_HEADER_SIZE-size, fp); - if(ret == 0) { - delete [] hdr_buffer; - if(feof(fp)) - return false; - else { - std::stringstream s; - s << "file_meta_source: error occurred extracting header: " - << strerror(errno) << std::endl; - throw std::runtime_error(s.str()); - } - } - size += ret; - } - - // Convert to string or the char array gets confused by the \0 - str.insert(0, hdr_buffer, METADATA_HEADER_SIZE); - hdr = pmt_deserialize_str(str); - delete [] hdr_buffer; - - uint64_t seg_start, extra_len; - pmt_t r, dump; - if(pmt_dict_has_key(hdr, pmt_string_to_symbol("strt"))) { - r = pmt_dict_ref(hdr, pmt_string_to_symbol("strt"), dump); - seg_start = pmt_to_uint64(r); - extra_len = seg_start - METADATA_HEADER_SIZE; - } - - if(extra_len > 0) { - size = 0; - hdr_buffer = new char[extra_len]; - while(size < extra_len) { - ret = fread(&hdr_buffer[size], sizeof(char), extra_len-size, fp); - if(ret == 0) { - delete [] hdr_buffer; - if(feof(fp)) - return false; - else { - std::stringstream s; - s << "file_meta_source: error occurred extracting extras: " - << strerror(errno) << std::endl; - throw std::runtime_error(s.str()); - } - } - size += ret; - } - - str.clear(); - str.insert(0, hdr_buffer, extra_len); - extras = pmt_deserialize_str(str); - delete [] hdr_buffer; - } - - return true; -} - -void -gr_file_meta_source::parse_header(pmt_t hdr, uint64_t offset, - std::vector &tags) -{ - pmt_t r, key; - - // GET SAMPLE RATE - key = pmt_string_to_symbol("rx_rate"); - if(pmt_dict_has_key(hdr, key)) { - r = pmt_dict_ref(hdr, key, PMT_NIL); - d_samp_rate = pmt_to_double(r); - - gr_tag_t t; - t.offset = offset; - t.key = key; - t.value = r; - t.srcid = alias_pmt(); - tags.push_back(t); - } - else { - throw std::runtime_error("file_meta_source: Could not extract sample rate.\n"); - } - - // GET TIME STAMP - key = pmt_string_to_symbol("rx_time"); - if(pmt_dict_has_key(hdr, key)) { - d_time_stamp = pmt_dict_ref(hdr, key, PMT_NIL); - - gr_tag_t t; - t.offset = offset; - t.key = key; - t.value = d_time_stamp; - t.srcid = alias_pmt(); - tags.push_back(t); - } - else { - throw std::runtime_error("file_meta_source: Could not extract time stamp.\n"); - } - - // GET ITEM SIZE OF DATA - if(pmt_dict_has_key(hdr, pmt_string_to_symbol("size"))) { - d_itemsize = pmt_to_long(pmt_dict_ref(hdr, pmt_string_to_symbol("size"), PMT_NIL)); - } - else { - throw std::runtime_error("file_meta_source: Could not extract item size.\n"); - } - - // GET SEGMENT SIZE - if(pmt_dict_has_key(hdr, pmt_string_to_symbol("bytes"))) { - d_seg_size = pmt_to_uint64(pmt_dict_ref(hdr, pmt_string_to_symbol("bytes"), PMT_NIL)); - - // Convert from bytes to items - d_seg_size /= d_itemsize; - } - else { - throw std::runtime_error("file_meta_source: Could not extract segment size.\n"); - } -} - -void -gr_file_meta_source::parse_extras(pmt_t extras, uint64_t offset, - std::vector &tags) -{ - pmt_t item, key, val; - - size_t nitems = pmt_length(extras); - for(size_t i = 0; i < nitems; i++) { - item = pmt_nth(i, extras); - key = pmt_car(item); - val = pmt_cdr(item); - - gr_tag_t t; - t.offset = offset; - t.key = key; - t.value = val; - t.srcid = alias_pmt(); - tags.push_back(t); - } -} - -bool -gr_file_meta_source::open(const std::string &filename, - const std::string &hdr_filename) -{ - bool ret = true; - if(d_state == STATE_DETACHED) { - std::string s; - if(hdr_filename == "") - s = filename + ".hdr"; - else - s = hdr_filename; - ret = _open(&d_new_hdr_fp, s.c_str()); - } - - ret = ret && _open(&d_new_fp, filename.c_str()); - d_updated = true; - return ret; -} - -bool -gr_file_meta_source::_open(FILE **fp, const char *filename) -{ - gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function - - bool ret = true; - int fd; - - if((fd = ::open(filename, - O_RDONLY|OUR_O_LARGEFILE|OUR_O_BINARY)) < 0) { - perror(filename); - return false; - } - - if(*fp) { // if we've already got a new one open, close it - fclose(*fp); - fp = 0; - } - - if((*fp = fdopen(fd, "rb")) == NULL) { - perror(filename); - ::close(fd); // don't leak file descriptor if fdopen fails. - } - - ret = fp != 0; - - return ret; -} - -void -gr_file_meta_source::close() -{ - gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function - if(d_state == STATE_DETACHED) { - if(d_new_hdr_fp) { - fclose(d_new_hdr_fp); - d_new_hdr_fp = 0; - } - } - - if(d_new_fp) { - fclose(d_new_fp); - d_new_fp = 0; - } - d_updated = true; -} - -void -gr_file_meta_source::do_update() -{ - if(d_updated) { - gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this block - if(d_state == STATE_DETACHED) { - if(d_hdr_fp) - fclose(d_hdr_fp); - d_hdr_fp = d_new_hdr_fp; // install new file pointer - d_new_hdr_fp = 0; - } - - if(d_fp) - fclose(d_fp); - d_fp = d_new_fp; // install new file pointer - d_new_fp = 0; - - d_updated = false; - } -} - -int -gr_file_meta_source::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - // We've reached the end of a segment; parse the next header and get - // the new tags to send and set the next segment size. - if(d_seg_size == 0) { - pmt_t hdr=PMT_NIL, extras=PMT_NIL; - if(read_header(hdr, extras)) { - parse_header(hdr, nitems_written(0), d_tags); - parse_extras(extras, nitems_written(0), d_tags); - } - else { - return -1; - } - } - - char *out = (char*)output_items[0]; - int i; - int seg_size = std::min(noutput_items, (int)d_seg_size); - int size = seg_size; - - do_update(); // update d_fp is reqd - if(d_fp == NULL) - throw std::runtime_error("work with file not open"); - - // Push all tags onto the stream and remove them from the vector - while(!d_tags.empty()) { - add_item_tag(0, d_tags.back()); - d_tags.pop_back(); - } - - gruel::scoped_lock lock(d_mutex); // hold for the rest of this function - while(size) { - i = fread(out, d_itemsize, size, d_fp); - - size -= i; - d_seg_size -= i; - out += i * d_itemsize; - - if(size == 0) // done - break; - - if(i > 0) // short read, try again - continue; - - // We got a zero from fread. This is either EOF or error. In - // any event, if we're in repeat mode, seek back to the beginning - // of the file and try again, else break - - if(!d_repeat) - break; - - if(fseek(d_fp, 0, SEEK_SET) == -1) { - std::stringstream s; - s << "[" << __FILE__ << "]" << " fseek failed" << std::endl; - throw std::runtime_error(s.str()); - } - } - - if(size > 0) { // EOF or error - if(size == seg_size) // we didn't read anything; say we're done - return -1; - return seg_size - size; // else return partial result - } - - return seg_size; -} diff --git a/gnuradio-core/src/lib/io/gr_file_meta_source.h b/gnuradio-core/src/lib/io/gr_file_meta_source.h deleted file mode 100644 index 95e466936..000000000 --- a/gnuradio-core/src/lib/io/gr_file_meta_source.h +++ /dev/null @@ -1,126 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2012 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, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_GR_FILE_META_SOURCE_H -#define INCLUDED_GR_FILE_META_SOURCE_H - -#include -#include -#include -#include -#include -#include - -#include - -class gr_file_meta_source; -typedef boost::shared_ptr gr_file_meta_source_sptr; - -GR_CORE_API gr_file_meta_source_sptr -gr_make_file_meta_source(const std::string &filename, - bool repeat=false, - bool detached_header=false, - const std::string &hdr_filename=""); - -/*! - * \brief Reads stream from file with meta-data headers. Headers are - * parsed into tags. - * \ingroup source_blk - * - * The information in the metadata headers includes: - * - * rx_rate (double): sample rate of data. - * rx_time (uint64_t, double): time stamp of first sample in segment. - * type (gr_file_types as int32_t): data type. - * cplx (bool): Is data complex? - * strt (uint64_t): Starting byte of data in this segment. - * size (uint64_t): Size in bytes of data in this segment. - * - * Any item inside of the extra header dictionary is ready out and - * made into a stream tag. - */ -class GR_CORE_API gr_file_meta_source : public gr_sync_block -{ - /*! - * \brief Create a meta-data file source. - * - * \param filename (string): Name of file to write data to. - * \param repeat (bool): Repeats file when EOF is found. - * \param detached_header (bool): Set to true if header - * info is stored in a separate file (usually named filename.hdr) - * \param hdr_filename (string): Name of detached header file if used. - * Defaults to 'filename.hdr' if detached_header is true but this - * field is an empty string. - */ - friend GR_CORE_API gr_file_meta_source_sptr - gr_make_file_meta_source(const std::string &filename, - bool repeat, - bool detached_header, - const std::string &hdr_filename); - - private: - enum meta_state_t { - STATE_INLINE=0, - STATE_DETACHED - }; - - size_t d_itemsize; - double d_samp_rate; - pmt_t d_time_stamp; - size_t d_seg_size; - bool d_updated; - bool d_repeat; - - gruel::mutex d_mutex; - FILE *d_new_fp, *d_new_hdr_fp; - FILE *d_fp, *d_hdr_fp; - meta_state_t d_state; - - std::vector d_tags; - - protected: - gr_file_meta_source(const std::string &filename, - bool repeat=false, - bool detached_header=false, - const std::string &hdr_filename=""); - - bool _open(FILE **fp, const char *filename); - bool read_header(pmt_t &hdr, pmt_t &extras); - void parse_header(pmt_t hdr, uint64_t offset, - std::vector &tags); - void parse_extras(pmt_t extras, uint64_t offset, - std::vector &tags); - - public: - ~gr_file_meta_source(); - - bool open(const std::string &filename, - const std::string &hdr_filename=""); - void close(); - void do_update(); - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); -}; - -#endif /* INCLUDED_GR_FILE_META_SOURCE_H */ diff --git a/gnuradio-core/src/lib/io/gr_file_meta_source.i b/gnuradio-core/src/lib/io/gr_file_meta_source.i deleted file mode 100644 index cb1281036..000000000 --- a/gnuradio-core/src/lib/io/gr_file_meta_source.i +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2012 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, - * Boston, MA 02110-1301, USA. - */ - -GR_SWIG_BLOCK_MAGIC(gr,file_meta_source) - -gr_file_meta_source_sptr -gr_make_file_meta_source(const std::string &filename, - bool repeat=false, - bool detached_header=false, - const std::string &hdr_filename=""); - -class gr_file_meta_source : public gr_sync_block -{ - protected: - gr_file_meta_source(const std::string &filename, - bool repeat, - bool detached_header, - const std::string &hdr_filename); - - public: - ~gr_file_meta_source(); - - bool open(const std::string &filename, - const std::string &hdr_filename=""); - void close(); -}; diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index 5885214d8..e2de4eb97 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -27,9 +27,7 @@ #endif #include -#include #include -#include #include #include #include @@ -57,9 +55,7 @@ %include "gr_file_sink_base.i" %include "gr_file_sink.i" -%include "gr_file_meta_sink.i" %include "gr_file_source.i" -%include "gr_file_meta_source.i" %include "gr_file_descriptor_sink.i" %include "gr_file_descriptor_source.i" %include "gr_histo_sink.i" -- cgit From 1bb31c97fb2b764f8133c844102558c0db046b05 Mon Sep 17 00:00:00 2001 From: Nicholas Corgan Date: Thu, 20 Dec 2012 19:20:11 -0800 Subject: core: fixed pdu MSVC compatibility issues --- gnuradio-core/src/lib/io/gr_pdu.cc | 24 ++++++++++++------------ gnuradio-core/src/lib/io/gr_pdu.h | 2 +- gnuradio-core/src/lib/io/gr_pdu.i | 2 +- gnuradio-core/src/lib/io/gr_socket_pdu.h | 1 + gnuradio-core/src/lib/io/gr_stream_pdu_base.cc | 6 ++++++ 5 files changed, 21 insertions(+), 14 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_pdu.cc b/gnuradio-core/src/lib/io/gr_pdu.cc index b2757c307..302fd7b9b 100644 --- a/gnuradio-core/src/lib/io/gr_pdu.cc +++ b/gnuradio-core/src/lib/io/gr_pdu.cc @@ -29,11 +29,11 @@ size_t gr_pdu_itemsize(gr_pdu_vector_type type){ switch(type){ - case BYTE: + case pdu_byte: return 1; - case FLOAT: + case pdu_float: return sizeof(float); - case COMPLEX: + case pdu_complex: return sizeof(gr_complex); default: throw std::runtime_error("bad type!"); @@ -43,11 +43,11 @@ gr_pdu_itemsize(gr_pdu_vector_type type){ bool gr_pdu_type_matches(gr_pdu_vector_type type, pmt::pmt_t v){ switch(type){ - case BYTE: + case pdu_byte: return pmt::pmt_is_u8vector(v); - case FLOAT: + case pdu_float: return pmt::pmt_is_f32vector(v); - case COMPLEX: + case pdu_complex: return pmt::pmt_is_c32vector(v); default: throw std::runtime_error("bad type!"); @@ -57,11 +57,11 @@ gr_pdu_type_matches(gr_pdu_vector_type type, pmt::pmt_t v){ pmt::pmt_t gr_pdu_make_vector(gr_pdu_vector_type type, const uint8_t* buf, size_t items){ switch(type){ - case BYTE: + case pdu_byte: return pmt::pmt_init_u8vector(items, buf); - case FLOAT: + case pdu_float: return pmt::pmt_init_f32vector(items, (const float*)buf); - case COMPLEX: + case pdu_complex: return pmt::pmt_init_c32vector(items, (const gr_complex*)buf); default: throw std::runtime_error("bad type!"); @@ -70,10 +70,10 @@ gr_pdu_make_vector(gr_pdu_vector_type type, const uint8_t* buf, size_t items){ gr_pdu_vector_type type_from_pmt(pmt::pmt_t vector){ if(pmt_is_u8vector(vector)) - return BYTE; + return pdu_byte; if(pmt_is_f32vector(vector)) - return FLOAT; + return pdu_float; if(pmt_is_c32vector(vector)) - return COMPLEX; + return pdu_complex; throw std::runtime_error("bad type!"); } diff --git a/gnuradio-core/src/lib/io/gr_pdu.h b/gnuradio-core/src/lib/io/gr_pdu.h index 5ed9cdded..a5ae87db7 100644 --- a/gnuradio-core/src/lib/io/gr_pdu.h +++ b/gnuradio-core/src/lib/io/gr_pdu.h @@ -29,7 +29,7 @@ #define pdu_port_id pmt::mp("pdus") #define pdu_length_tag pmt::mp("pdu_length") -enum gr_pdu_vector_type { BYTE, FLOAT, COMPLEX }; +enum gr_pdu_vector_type { pdu_byte, pdu_float, pdu_complex }; size_t gr_pdu_itemsize(gr_pdu_vector_type type); bool gr_pdu_type_matches(gr_pdu_vector_type type, pmt::pmt_t v); diff --git a/gnuradio-core/src/lib/io/gr_pdu.i b/gnuradio-core/src/lib/io/gr_pdu.i index 7cb3c62c7..ada3a63a7 100644 --- a/gnuradio-core/src/lib/io/gr_pdu.i +++ b/gnuradio-core/src/lib/io/gr_pdu.i @@ -24,7 +24,7 @@ #include %} -enum gr_pdu_vector_type { BYTE, FLOAT, COMPLEX }; +enum gr_pdu_vector_type { pdu_byte, pdu_float, pdu_complex }; diff --git a/gnuradio-core/src/lib/io/gr_socket_pdu.h b/gnuradio-core/src/lib/io/gr_socket_pdu.h index f554febdc..e30a4cc6c 100644 --- a/gnuradio-core/src/lib/io/gr_socket_pdu.h +++ b/gnuradio-core/src/lib/io/gr_socket_pdu.h @@ -28,6 +28,7 @@ #include #include #include +#include #include class gr_socket_pdu; diff --git a/gnuradio-core/src/lib/io/gr_stream_pdu_base.cc b/gnuradio-core/src/lib/io/gr_stream_pdu_base.cc index cff7296cb..7250c33e5 100644 --- a/gnuradio-core/src/lib/io/gr_stream_pdu_base.cc +++ b/gnuradio-core/src/lib/io/gr_stream_pdu_base.cc @@ -24,6 +24,7 @@ #include "config.h" #endif +#include #include #include #include @@ -35,8 +36,13 @@ #include #include #include +#include #include +#ifdef HAVE_IO_H +#include +#endif + static const long timeout_us = 100*1000; //100ms gr_stream_pdu_base::gr_stream_pdu_base (int MTU) -- cgit From 241cacef600c0cc5eaaa560959958ad2784970cb Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 14 Jan 2013 17:40:40 -0600 Subject: core: gr_socket_pdu missing iostream --- gnuradio-core/src/lib/io/gr_socket_pdu.h | 1 + 1 file changed, 1 insertion(+) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_socket_pdu.h b/gnuradio-core/src/lib/io/gr_socket_pdu.h index e30a4cc6c..2fedb317d 100644 --- a/gnuradio-core/src/lib/io/gr_socket_pdu.h +++ b/gnuradio-core/src/lib/io/gr_socket_pdu.h @@ -30,6 +30,7 @@ #include #include #include +#include class gr_socket_pdu; typedef boost::shared_ptr gr_socket_pdu_sptr; -- cgit From f3f3b8842d011639f6b70329eaaa72dd3047da41 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Wed, 23 Jan 2013 09:49:30 -0800 Subject: blocks: fix use of bare boost::mutex::scoped_lock gr_file_source gr::blocks::file_source --- gnuradio-core/src/lib/io/gr_file_source.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_file_source.cc b/gnuradio-core/src/lib/io/gr_file_source.cc index 09f3986cd..f3def0721 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_source.cc @@ -89,7 +89,7 @@ gr_file_source::work (int noutput_items, if(d_fp == NULL) throw std::runtime_error("work with file not open"); - boost::mutex::scoped_lock lock(fp_mutex); // hold for the rest of this function + gruel::scoped_lock lock(fp_mutex); // hold for the rest of this function while (size) { i = fread(o, d_itemsize, size, (FILE *) d_fp); @@ -129,7 +129,7 @@ bool gr_file_source::seek (long seek_point, int whence) { // obtain exclusive access for duration of this function - boost::mutex::scoped_lock lock(fp_mutex); + gruel::scoped_lock lock(fp_mutex); return fseek((FILE *) d_fp, seek_point * d_itemsize, whence) == 0; } @@ -137,7 +137,7 @@ void gr_file_source::open(const char *filename, bool repeat) { // obtain exclusive access for duration of this function - boost::mutex::scoped_lock lock(fp_mutex); + gruel::scoped_lock lock(fp_mutex); int fd; @@ -166,7 +166,7 @@ void gr_file_source::close() { // obtain exclusive access for duration of this function - boost::mutex::scoped_lock lock(fp_mutex); + gruel::scoped_lock lock(fp_mutex); if(d_new_fp != NULL) { fclose(d_new_fp); @@ -179,7 +179,7 @@ void gr_file_source::do_update() { if(d_updated) { - boost::mutex::scoped_lock lock(fp_mutex); // hold while in scope + gruel::scoped_lock lock(fp_mutex); // hold while in scope if(d_fp) fclose(d_fp); -- cgit From e9044d16e8a075234abfda2db5db243e2bdee026 Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Wed, 13 Feb 2013 11:29:57 -0500 Subject: core: cleaning warnings --- gnuradio-core/src/lib/io/gr_message_debug.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/io') diff --git a/gnuradio-core/src/lib/io/gr_message_debug.cc b/gnuradio-core/src/lib/io/gr_message_debug.cc index 27f4c65fd..1327c31ba 100644 --- a/gnuradio-core/src/lib/io/gr_message_debug.cc +++ b/gnuradio-core/src/lib/io/gr_message_debug.cc @@ -71,7 +71,7 @@ gr_message_debug::print_verbose(pmt::pmt_t msg) size_t offset(0); const uint8_t* d = (const uint8_t*) pmt_uniform_vector_elements(vector, offset); for(size_t i=0; i #include #include #include -- cgit