summaryrefslogtreecommitdiff
path: root/gnuradio-core
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-core')
-rw-r--r--gnuradio-core/src/lib/general/gr_head.cc1
-rw-r--r--gnuradio-core/src/lib/general/gr_skiphead.cc25
-rw-r--r--gnuradio-core/src/lib/general/gr_skiphead.h20
-rw-r--r--gnuradio-core/src/lib/general/gr_skiphead.i13
-rw-r--r--gnuradio-core/src/lib/general/gri_fft.cc6
-rw-r--r--gnuradio-core/src/lib/general/gri_fft.h14
-rw-r--r--gnuradio-core/src/lib/io/CMakeLists.txt1
-rw-r--r--gnuradio-core/src/lib/io/gr_message_burst_source.cc144
-rw-r--r--gnuradio-core/src/lib/io/gr_message_burst_source.h71
-rw-r--r--gnuradio-core/src/lib/io/gr_message_burst_source.i38
-rw-r--r--gnuradio-core/src/lib/io/gr_tagged_file_sink.cc23
-rw-r--r--gnuradio-core/src/lib/io/io.i2
12 files changed, 344 insertions, 14 deletions
diff --git a/gnuradio-core/src/lib/general/gr_head.cc b/gnuradio-core/src/lib/general/gr_head.cc
index cb07c84ddc..1726888113 100644
--- a/gnuradio-core/src/lib/general/gr_head.cc
+++ b/gnuradio-core/src/lib/general/gr_head.cc
@@ -26,6 +26,7 @@
#include <gr_head.h>
#include <gr_io_signature.h>
#include <string.h>
+#include <iostream>
gr_head::gr_head (size_t sizeof_stream_item, unsigned long long nitems)
: gr_sync_block ("head",
diff --git a/gnuradio-core/src/lib/general/gr_skiphead.cc b/gnuradio-core/src/lib/general/gr_skiphead.cc
index c887376e45..e9dad8fab8 100644
--- a/gnuradio-core/src/lib/general/gr_skiphead.cc
+++ b/gnuradio-core/src/lib/general/gr_skiphead.cc
@@ -41,6 +41,31 @@ gr_make_skiphead (size_t itemsize, uint64_t nitems_to_skip)
return gnuradio::get_initial_sptr(new gr_skiphead (itemsize, nitems_to_skip));
}
+void
+gr_skiphead::set_nitems_to_skip(uint64_t nitems_to_skip)
+{
+ d_nitems_to_skip = nitems_to_skip;
+ reset();
+}
+
+uint64_t
+gr_skiphead::nitems_to_skip() const
+{
+ return d_nitems_to_skip;
+}
+
+uint64_t
+gr_skiphead::nitems_skiped() const
+{
+ return d_nitems;
+}
+
+void
+gr_skiphead::reset()
+{
+ d_nitems = 0;
+}
+
int
gr_skiphead::general_work(int noutput_items,
gr_vector_int &ninput_items_ignored,
diff --git a/gnuradio-core/src/lib/general/gr_skiphead.h b/gnuradio-core/src/lib/general/gr_skiphead.h
index 899b40f27a..710530ff4c 100644
--- a/gnuradio-core/src/lib/general/gr_skiphead.h
+++ b/gnuradio-core/src/lib/general/gr_skiphead.h
@@ -51,6 +51,26 @@ class GR_CORE_API gr_skiphead : public gr_block
public:
+ /*!
+ * \brief Sets number of items to skip; resets current skip count to 0.
+ */
+ void set_nitems_to_skip(uint64_t nitems_to_skip);
+
+ /*!
+ * \brief Gets the number of items to skip.
+ */
+ uint64_t nitems_to_skip() const;
+
+ /*!
+ * \brief Gets the number of items already skipped.
+ */
+ uint64_t nitems_skiped() const;
+
+ /*!
+ * \brief Resets number of items skipped to 0.
+ */
+ void reset();
+
int general_work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
diff --git a/gnuradio-core/src/lib/general/gr_skiphead.i b/gnuradio-core/src/lib/general/gr_skiphead.i
index 3246db9702..8ab23a77a6 100644
--- a/gnuradio-core/src/lib/general/gr_skiphead.i
+++ b/gnuradio-core/src/lib/general/gr_skiphead.i
@@ -22,9 +22,14 @@
GR_SWIG_BLOCK_MAGIC(gr,skiphead);
-gr_skiphead_sptr gr_make_skiphead (size_t itemsize, uint64_t nitems_to_skip);
+gr_skiphead_sptr gr_make_skiphead(size_t itemsize,
+ uint64_t nitems_to_skip);
-class gr_skiphead : public gr_block {
- friend gr_skiphead_sptr gr_make_skiphead (size_t itemsize, uint64_t nitems_to_skip);
- gr_skiphead (size_t itemsize, uint64_t nitems_to_skip);
+class gr_skiphead : public gr_block
+{
+public:
+ void set_nitems_to_skip(uint64_t nitems_to_skip);
+ uint64_t nitems_to_skip() const;
+ uint64_t nitems_skiped() const;
+ void reset();
};
diff --git a/gnuradio-core/src/lib/general/gri_fft.cc b/gnuradio-core/src/lib/general/gri_fft.cc
index 68e7e69519..78446ad39b 100644
--- a/gnuradio-core/src/lib/general/gri_fft.cc
+++ b/gnuradio-core/src/lib/general/gri_fft.cc
@@ -59,6 +59,12 @@ gri_fft_malloc_float(int size)
return (float*)fftwf_malloc(sizeof(float)*size);
}
+double *
+gri_fft_malloc_double(int size)
+{
+ return (double*)fftwf_malloc(sizeof(double)*size);
+}
+
void
gri_fft_free(void *b)
{
diff --git a/gnuradio-core/src/lib/general/gri_fft.h b/gnuradio-core/src/lib/general/gri_fft.h
index 65e9d046e2..c6fbd4f43f 100644
--- a/gnuradio-core/src/lib/general/gri_fft.h
+++ b/gnuradio-core/src/lib/general/gri_fft.h
@@ -30,17 +30,21 @@
#include <gr_complex.h>
#include <boost/thread.hpp>
-/*! \brief Helper function for allocating complex fft buffers
+/*! \brief Helper function for allocating complex* buffers
*/
-gr_complex* gri_fft_malloc_complex(int size);
+GR_CORE_API gr_complex* gri_fft_malloc_complex(int size);
-/*! \brief Helper function for allocating float fft buffers
+/*! \brief Helper function for allocating float* buffers
*/
-float* gri_fft_malloc_float(int size);
+GR_CORE_API float* gri_fft_malloc_float(int size);
+
+/*! \brief Helper function for allocating double* buffers
+ */
+GR_CORE_API double* gri_fft_malloc_double(int size);
/*! \brief Helper function for freeing fft buffers
*/
-void gri_fft_free(void *b);
+GR_CORE_API void gri_fft_free(void *b);
/*!
diff --git a/gnuradio-core/src/lib/io/CMakeLists.txt b/gnuradio-core/src/lib/io/CMakeLists.txt
index af9d7583c3..3dea13396c 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 0000000000..e9e2dfd4dc
--- /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 <gr_message_burst_source.h>
+#include <gr_io_signature.h>
+#include <cstdio>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdexcept>
+#include <string.h>
+#include <gr_tags.h>
+
+// 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 0000000000..63e2201139
--- /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 <gr_core_api.h>
+#include <gr_sync_block.h>
+#include <gr_message.h>
+#include <gr_msg_queue.h>
+
+class gr_message_burst_source;
+typedef boost::shared_ptr<gr_message_burst_source> 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 0000000000..f7ad840c22
--- /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/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc
index d698927629..c0da23b4f7 100644
--- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc
+++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc
@@ -82,7 +82,7 @@ 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::key_time
+ pmt::pmt_t tkey = pmt::pmt_string_to_symbol("rx_time"); // use gr_tags::key_time
std::vector<gr_tag_t> all_tags;
get_tags_in_range(all_tags, 0, start_N, end_N);
@@ -91,6 +91,20 @@ gr_tagged_file_sink::work (int noutput_items,
std::vector<gr_tag_t>::iterator vitr = all_tags.begin();
+ // Look for a time tag and initialize d_timeval.
+ std::vector<gr_tag_t> time_tags_outer;
+ get_tags_in_range(time_tags_outer, 0, start_N, end_N, tkey);
+ if (time_tags_outer.size() > 0) {
+ const gr_tag_t tag = time_tags_outer[0];
+ uint64_t offset = tag.offset;
+ pmt::pmt_t time = tag.value;
+ uint64_t tsecs = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(time, 0));
+ double tfrac = pmt::pmt_to_double(pmt::pmt_tuple_ref(time, 1));
+ double delta = (double)offset / d_sample_rate;
+ d_timeval = (double)tsecs + tfrac + delta;
+ d_last_N = offset;
+ }
+
int idx = 0, idx_stop = 0;
while(idx < noutput_items) {
if(d_state == NOT_IN_BURST) {
@@ -108,8 +122,7 @@ gr_tagged_file_sink::work (int noutput_items,
// to new time based on sample rate of this block.
std::vector<gr_tag_t> 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"));
+ get_tags_in_range(time_tags, 0, d_last_N, N, tkey);
if(time_tags.size() > 0) {
const gr_tag_t tag = time_tags[time_tags.size()-1];
@@ -117,7 +130,7 @@ gr_tagged_file_sink::work (int noutput_items,
// Get time based on last time tag from USRP
pmt::pmt_t time = tag.value;
- int tsecs = pmt::pmt_to_long(pmt::pmt_tuple_ref(time, 0));
+ uint64_t tsecs = pmt::pmt_to_uint64(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
@@ -143,7 +156,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" << d_unique_id << "_" << d_n << "_" << d_timeval << ".dat";
d_n++;
int fd;
diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i
index eab1346f18..5cd352905d 100644
--- a/gnuradio-core/src/lib/io/io.i
+++ b/gnuradio-core/src/lib/io/io.i
@@ -38,6 +38,7 @@
#include <gr_oscope_sink_f.h>
#include <ppio.h>
#include <gr_message_source.h>
+#include <gr_message_burst_source.h>
#include <gr_message_sink.h>
#include <gr_udp_sink.h>
#include <gr_udp_source.h>
@@ -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"