diff --git a/grc/iqtlabs_write_freq_samples.block.yml b/grc/iqtlabs_write_freq_samples.block.yml index be2dcda5..a566a82a 100644 --- a/grc/iqtlabs_write_freq_samples.block.yml +++ b/grc/iqtlabs_write_freq_samples.block.yml @@ -24,6 +24,7 @@ documentation: |- sigmf: if True, write a sigmf file. zstd: if True, use zstd comporession. rotate: If True, rotate file on tag. + description: If set, what text description to include in sigmf file. templates: imports: from gnuradio import iqtlabs @@ -31,7 +32,7 @@ templates: iqtlabs.write_freq_samples(${tag}, ${type.size}, "${type.datatype}", ${vlen}, ${sdir}, ${prefix}, ${write_step_samples}, ${skip_tune_step_samples}, ${samp_rate}, ${rotate_secs}, ${gain}, - ${sigmf}, ${zstd}, ${rotate}) + ${sigmf}, ${zstd}, ${rotate}, ${description}) cpp_templates: includes: ['#include '] @@ -40,7 +41,7 @@ cpp_templates: this->${id} = gr::iqtlabs::write_freq_samples::make(${tag}, ${type.size}, "${type.datatype}", ${vlen}, ${sdir}, ${prefix}, ${write_step_samples}, ${skip_tune_step_samples}, ${samp_rate}, ${rotate_secs}, ${gain}, - ${sigmf}, ${zstd}, ${rotate}); + ${sigmf}, ${zstd}, ${rotate}, ${description}); link: ['libgnuradio-iqtlabs.so'] parameters: @@ -78,6 +79,8 @@ parameters: dtype: bool - id: rotate dtype: bool + - id: description + dtype: string inputs: - label: input diff --git a/include/gnuradio/iqtlabs/write_freq_samples.h b/include/gnuradio/iqtlabs/write_freq_samples.h index 1f41654e..cab9ca7a 100644 --- a/include/gnuradio/iqtlabs/write_freq_samples.h +++ b/include/gnuradio/iqtlabs/write_freq_samples.h @@ -220,7 +220,8 @@ class IQTLABS_API write_freq_samples : virtual public gr::block { const std::string &sdir, const std::string &prefix, uint64_t write_step_samples, uint64_t skip_tune_step_samples, uint64_t samp_rate, uint64_t rotate_secs, double gain, - bool sigmf, bool zstd, bool rotate); + bool sigmf, bool zstd, bool rotate, + const std::string &description); }; } // namespace iqtlabs diff --git a/lib/base_impl.cc b/lib/base_impl.cc index 953062dc..1785cd9c 100644 --- a/lib/base_impl.cc +++ b/lib/base_impl.cc @@ -264,11 +264,15 @@ std::string base_impl::secs_dir(const std::string &dir, COUNT_T rotate_secs) { sigmf_record_t base_impl::create_sigmf(const std::string &source_file, double timestamp, const std::string &datatype, - double sample_rate, double gain) { + double sample_rate, double gain, + const std::string &description) { sigmf_record_t record; record.global.access().datatype = datatype; record.global.access().sample_rate = sample_rate; record.global.access().version = "1.0.0"; + if (description.size()) { + record.global.access().description = description; + } auto capture = sigmf::Capture(); capture.get().sample_start = 0; diff --git a/lib/base_impl.h b/lib/base_impl.h index fcb7e847..9532485e 100644 --- a/lib/base_impl.h +++ b/lib/base_impl.h @@ -276,7 +276,7 @@ class base_impl { std::string secs_dir(const std::string &dir, COUNT_T rotate_secs); sigmf_record_t create_sigmf(const std::string &source_file, double timestamp, const std::string &datatype, double sample_rate, - double gain); + double gain, const std::string &description); void get_tags(const pmt::pmt_t want_tag, const std::vector &all_tags, std::vector &rx_freq_tags, std::vector &rx_times); diff --git a/lib/write_freq_samples_impl.cc b/lib/write_freq_samples_impl.cc index d044f158..a7734a28 100644 --- a/lib/write_freq_samples_impl.cc +++ b/lib/write_freq_samples_impl.cc @@ -218,11 +218,11 @@ write_freq_samples::sptr write_freq_samples::make( COUNT_T vlen, const std::string &sdir, const std::string &prefix, COUNT_T write_step_samples, COUNT_T skip_tune_step_samples, COUNT_T samp_rate, COUNT_T rotate_secs, double gain, bool sigmf, bool zstd, - bool rotate) { + bool rotate, const std::string &description) { return gnuradio::make_block_sptr( tag, itemsize, datatype, vlen, sdir, prefix, write_step_samples, - skip_tune_step_samples, samp_rate, rotate_secs, gain, sigmf, zstd, - rotate); + skip_tune_step_samples, samp_rate, rotate_secs, gain, sigmf, zstd, rotate, + description); } write_freq_samples_impl::write_freq_samples_impl( @@ -230,7 +230,7 @@ write_freq_samples_impl::write_freq_samples_impl( COUNT_T vlen, const std::string &sdir, const std::string &prefix, COUNT_T write_step_samples, COUNT_T skip_tune_step_samples, COUNT_T samp_rate, COUNT_T rotate_secs, double gain, bool sigmf, bool zstd, - bool rotate) + bool rotate, const std::string &description) : gr::block("write_freq_samples", gr::io_signature::make(1 /* min inputs */, 1 /* max inputs */, vlen * itemsize), @@ -240,9 +240,9 @@ write_freq_samples_impl::write_freq_samples_impl( skip_tune_step_samples_(skip_tune_step_samples), samp_rate_(samp_rate), sample_clock_(0), open_sample_clock_(0), rotate_secs_(rotate_secs), write_step_samples_count_(0), skip_tune_step_samples_count_(0), - sdir_(sdir), prefix_(prefix), datatype_(datatype), gain_(gain), - sigmf_(sigmf), zstd_(zstd), rotate_(rotate), last_rx_freq_(0), - last_rx_time_(0) { + sdir_(sdir), prefix_(prefix), datatype_(datatype), + description_(description), gain_(gain), sigmf_(sigmf), zstd_(zstd), + rotate_(rotate), last_rx_freq_(0), last_rx_time_(0) { outbuf_p.reset(new boost::iostreams::filtering_ostream()); open_(1); message_port_register_in(INFERENCE_KEY); @@ -335,8 +335,9 @@ void write_freq_samples_impl::close_() { final_samples_path += ".zst"; } if (sigmf_) { - sigmf_record_t record = create_sigmf(final_samples_path, open_time_, - datatype_, samp_rate_, gain_); + sigmf_record_t record = + create_sigmf(final_samples_path, open_time_, datatype_, samp_rate_, + gain_, description_); boost::lock_guard guard(queue_lock_); COUNT_T annotations = 0; while (!inference_q_.empty()) { diff --git a/lib/write_freq_samples_impl.h b/lib/write_freq_samples_impl.h index f4a15d00..5228ace4 100644 --- a/lib/write_freq_samples_impl.h +++ b/lib/write_freq_samples_impl.h @@ -245,7 +245,7 @@ class write_freq_samples_impl : public write_freq_samples, base_impl { COUNT_T itemsize_, vlen_, write_step_samples_, skip_tune_step_samples_, samp_rate_, sample_clock_, open_sample_clock_, rotate_secs_, write_step_samples_count_, skip_tune_step_samples_count_; - std::string sdir_, prefix_, datatype_; + std::string sdir_, prefix_, datatype_, description_; double gain_; bool sigmf_, zstd_, rotate_; FREQ_T last_rx_freq_; @@ -265,7 +265,8 @@ class write_freq_samples_impl : public write_freq_samples, base_impl { COUNT_T write_step_samples, COUNT_T skip_tune_step_samples, COUNT_T samp_rate, COUNT_T rotate_secs, double gain, bool sigmf, - bool zstd, bool rotate); + bool zstd, bool rotate, + const std::string &description); ~write_freq_samples_impl(); int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, diff --git a/python/iqtlabs/bindings/docstrings/write_freq_samples_pydoc_template.h b/python/iqtlabs/bindings/docstrings/write_freq_samples_pydoc_template.h index 76e91b7e..8a4d607f 100644 --- a/python/iqtlabs/bindings/docstrings/write_freq_samples_pydoc_template.h +++ b/python/iqtlabs/bindings/docstrings/write_freq_samples_pydoc_template.h @@ -7,21 +7,16 @@ * */ #include "pydoc_macros.h" -#define D(...) DOC(gr,iqtlabs, __VA_ARGS__ ) +#define D(...) DOC(gr, iqtlabs, __VA_ARGS__) /* This file contains placeholders for docstrings for the Python bindings. Do not edit! These were automatically extracted during the binding process and will be overwritten during the build process */ +static const char *__doc_gr_iqtlabs_write_freq_samples = R"doc()doc"; - - static const char *__doc_gr_iqtlabs_write_freq_samples = R"doc()doc"; +static const char *__doc_gr_iqtlabs_write_freq_samples_write_freq_samples = + R"doc()doc"; - - static const char *__doc_gr_iqtlabs_write_freq_samples_write_freq_samples = R"doc()doc"; - - - static const char *__doc_gr_iqtlabs_write_freq_samples_make = R"doc()doc"; - - +static const char *__doc_gr_iqtlabs_write_freq_samples_make = R"doc()doc"; diff --git a/python/iqtlabs/bindings/write_freq_samples_python.cc b/python/iqtlabs/bindings/write_freq_samples_python.cc index 638030a4..4276a287 100644 --- a/python/iqtlabs/bindings/write_freq_samples_python.cc +++ b/python/iqtlabs/bindings/write_freq_samples_python.cc @@ -8,13 +8,15 @@ */ /***********************************************************************************/ -/* This file is automatically generated using bindtool and can be manually edited */ -/* The following lines can be configured to regenerate this file during cmake */ -/* If manual edits are made, the following tags should be modified accordingly. */ -/* BINDTOOL_GEN_AUTOMATIC(0) */ -/* BINDTOOL_USE_PYGCCXML(0) */ -/* BINDTOOL_HEADER_FILE(write_freq_samples.h) */ -/* BINDTOOL_HEADER_FILE_HASH(68fae4e2419a2f9963bc7cdeeb287190) */ +/* This file is automatically generated using bindtool and can be manually + * edited */ +/* The following lines can be configured to regenerate this file during cmake */ +/* If manual edits are made, the following tags should be modified accordingly. + */ +/* BINDTOOL_GEN_AUTOMATIC(0) */ +/* BINDTOOL_USE_PYGCCXML(0) */ +/* BINDTOOL_HEADER_FILE(write_freq_samples.h) */ +/* BINDTOOL_HEADER_FILE_HASH(517a8e777f21ba1ff4cc9278a8ec5737) */ /***********************************************************************************/ #include @@ -27,47 +29,21 @@ namespace py = pybind11; // pydoc.h is automatically generated in the build directory #include -void bind_write_freq_samples(py::module& m) -{ - - using write_freq_samples = ::gr::iqtlabs::write_freq_samples; - - - py::class_>(m, "write_freq_samples", D(write_freq_samples)) - - .def(py::init(&write_freq_samples::make), - py::arg("tag"), - py::arg("itemsize"), - py::arg("datatype"), - py::arg("vlen"), - py::arg("sdir"), - py::arg("prefix"), - py::arg("write_step_samples"), - py::arg("skip_tune_step_samples"), - py::arg("samp_rate"), - py::arg("rotate_secs"), - py::arg("gain"), - py::arg("sigmf"), - py::arg("zstd"), - py::arg("rotate"), - D(write_freq_samples,make) - ) - - - - - ; +void bind_write_freq_samples(py::module &m) { + using write_freq_samples = ::gr::iqtlabs::write_freq_samples; + py::class_>(m, "write_freq_samples", + D(write_freq_samples)) + .def(py::init(&write_freq_samples::make), py::arg("tag"), + py::arg("itemsize"), py::arg("datatype"), py::arg("vlen"), + py::arg("sdir"), py::arg("prefix"), py::arg("write_step_samples"), + py::arg("skip_tune_step_samples"), py::arg("samp_rate"), + py::arg("rotate_secs"), py::arg("gain"), py::arg("sigmf"), + py::arg("zstd"), py::arg("rotate"), py::arg("description"), + D(write_freq_samples, make)) + ; } - - - - - - - - diff --git a/python/iqtlabs/qa_write_freq_samples.py b/python/iqtlabs/qa_write_freq_samples.py index e22753a5..e9e313cc 100755 --- a/python/iqtlabs/qa_write_freq_samples.py +++ b/python/iqtlabs/qa_write_freq_samples.py @@ -264,6 +264,7 @@ def run_flowgraph( sigmf=True, zstd=True, rotate=rotate, + description="a description", ) blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex, samp_rate, True) blocks_stream_to_vector_0 = blocks.stream_to_vector( @@ -317,6 +318,7 @@ def write_freq_samples(self, rotate): total_annotations += len(annotations) self.assertEqual(samp_rate, sigmf_global["core:sample_rate"], sigmf) self.assertEqual("1.0.0", sigmf_global["core:version"], sigmf) + self.assertEqual("a description", sigmf_global["core:description"], sigmf) self.assertTrue(sigmf_global["core:datatype"]) global_sigmf_capture = sigmf["captures"][0] source_file = global_sigmf_capture["capture_details:source_file"] diff --git a/test_flow_graphs/smoke_test_write_freq_samples.grc b/test_flow_graphs/smoke_test_write_freq_samples.grc index 225c8f44..3dfb4125 100644 --- a/test_flow_graphs/smoke_test_write_freq_samples.grc +++ b/test_flow_graphs/smoke_test_write_freq_samples.grc @@ -82,6 +82,7 @@ blocks: sigmf: '1' zstd: '1' rotate: '1' + description: '""' states: bus_sink: false bus_source: false