summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gr-blocks/include/gnuradio/blocks/file_meta_sink.h19
-rw-r--r--gr-blocks/lib/file_meta_sink_impl.cc60
-rw-r--r--gr-blocks/lib/file_meta_sink_impl.h14
-rw-r--r--gr-blocks/python/blocks/qa_file_metadata.py6
4 files changed, 51 insertions, 48 deletions
diff --git a/gr-blocks/include/gnuradio/blocks/file_meta_sink.h b/gr-blocks/include/gnuradio/blocks/file_meta_sink.h
index 0d68132f0d..36d44b545a 100644
--- a/gr-blocks/include/gnuradio/blocks/file_meta_sink.h
+++ b/gr-blocks/include/gnuradio/blocks/file_meta_sink.h
@@ -87,17 +87,20 @@ namespace gr {
* \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 extra_dict: a PMT dictionary of extra
+ * information.
* \param detached_header (bool): Set to true to store the header
* info in a separate file (named filename.hdr)
*/
- static sptr make(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);
+ static sptr make(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,
+ pmt::pmt_t extra_dict=pmt::make_dict(),
+ bool detached_header=false);
virtual bool open(const std::string &filename) = 0;
virtual void close() = 0;
diff --git a/gr-blocks/lib/file_meta_sink_impl.cc b/gr-blocks/lib/file_meta_sink_impl.cc
index b6d858489d..fed28c7352 100644
--- a/gr-blocks/lib/file_meta_sink_impl.cc
+++ b/gr-blocks/lib/file_meta_sink_impl.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2012 Free Software Foundation, Inc.
+ * Copyright 2012,2018 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -56,12 +56,15 @@ namespace gr {
file_meta_sink::sptr
- file_meta_sink::make(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)
+ file_meta_sink::make(size_t itemsize,
+ const std::string &filename,
+ double samp_rate,
+ double relative_rate,
+ gr_file_types type,
+ bool complex,
+ size_t max_segment_size,
+ pmt::pmt_t extra_dict,
+ bool detached_header)
{
return gnuradio::get_initial_sptr
(new file_meta_sink_impl(itemsize, filename,
@@ -73,19 +76,19 @@ namespace gr {
}
file_meta_sink_impl::file_meta_sink_impl(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)
+ const std::string &filename,
+ double samp_rate, double relative_rate,
+ gr_file_types type, bool complex,
+ size_t max_segment_size,
+ pmt::pmt_t extra_dict,
+ bool detached_header)
: sync_block("file_meta_sink",
- io_signature::make(1, 1, itemsize),
- io_signature::make(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)
+ io_signature::make(1, 1, itemsize),
+ io_signature::make(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;
@@ -105,16 +108,13 @@ namespace gr {
// handle extra dictionary
d_extra = pmt::make_dict();
- if(extra_dict.size() > 0) {
- pmt::pmt_t extras = pmt::deserialize_str(extra_dict);
- pmt::pmt_t keys = pmt::dict_keys(extras);
- pmt::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));
- }
+ pmt::pmt_t keys = pmt::dict_keys(extra_dict);
+ pmt::pmt_t vals = pmt::dict_values(extra_dict);
+ 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();
@@ -248,7 +248,7 @@ namespace gr {
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");
+ throw std::runtime_error("file_meta_sink: header or extra_dict is wrong size.\n");
size_t nwritten = 0;
while(nwritten < header_str.size()) {
diff --git a/gr-blocks/lib/file_meta_sink_impl.h b/gr-blocks/lib/file_meta_sink_impl.h
index 5e678729b2..b274b3e8ed 100644
--- a/gr-blocks/lib/file_meta_sink_impl.h
+++ b/gr-blocks/lib/file_meta_sink_impl.h
@@ -66,12 +66,14 @@ namespace gr {
bool _open(FILE **fp, const char *filename);
public:
- file_meta_sink_impl(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);
+ file_meta_sink_impl(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,
+ pmt::pmt_t extra_dict=pmt::make_dict(),
+ bool detached_header=false);
~file_meta_sink_impl();
bool open(const std::string &filename);
diff --git a/gr-blocks/python/blocks/qa_file_metadata.py b/gr-blocks/python/blocks/qa_file_metadata.py
index 16c1a8916f..cdc0b94520 100644
--- a/gr-blocks/python/blocks/qa_file_metadata.py
+++ b/gr-blocks/python/blocks/qa_file_metadata.py
@@ -55,14 +55,13 @@ class test_file_metadata(gr_unittest.TestCase):
val = pmt.from_double(samp_rate)
extras = pmt.make_dict()
extras = pmt.dict_add(extras, key, val)
- extras_str = pmt.serialize_str(extras)
data = sig_source_c(samp_rate, 1000, 1, N)
src = blocks.vector_source_c(data)
fsnk = blocks.file_meta_sink(gr.sizeof_gr_complex, outfile,
samp_rate, 1,
blocks.GR_FILE_FLOAT, True,
- 1000000, extras_str, detached)
+ 1000000, extras, detached)
fsnk.set_unbuffered(True)
self.tb.connect(src, fsnk)
@@ -135,14 +134,13 @@ class test_file_metadata(gr_unittest.TestCase):
val = pmt.from_double(samp_rate)
extras = pmt.make_dict()
extras = pmt.dict_add(extras, key, val)
- extras_str = pmt.serialize_str(extras)
data = sig_source_c(samp_rate, 1000, 1, N)
src = blocks.vector_source_c(data)
fsnk = blocks.file_meta_sink(gr.sizeof_gr_complex, outfile,
samp_rate, 1,
blocks.GR_FILE_FLOAT, True,
- 1000000, extras_str, detached)
+ 1000000, extras, detached)
fsnk.set_unbuffered(True)
self.tb.connect(src, fsnk)