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