Skip to content

Commit

Permalink
Merge pull request #292 from anarkiwi/description
Browse files Browse the repository at this point in the history
add optional sigmf description.
  • Loading branch information
anarkiwi authored Jul 10, 2024
2 parents b181a0d + f3924d1 commit 315b210
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 72 deletions.
7 changes: 5 additions & 2 deletions grc/iqtlabs_write_freq_samples.block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ 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
make: >
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 <gnuradio/iqtlabs/write_freq_samples.h>']
Expand All @@ -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:
Expand Down Expand Up @@ -78,6 +79,8 @@ parameters:
dtype: bool
- id: rotate
dtype: bool
- id: description
dtype: string

inputs:
- label: input
Expand Down
3 changes: 2 additions & 1 deletion include/gnuradio/iqtlabs/write_freq_samples.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lib/base_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<sigmf::core::GlobalT>().datatype = datatype;
record.global.access<sigmf::core::GlobalT>().sample_rate = sample_rate;
record.global.access<sigmf::core::GlobalT>().version = "1.0.0";
if (description.size()) {
record.global.access<sigmf::core::GlobalT>().description = description;
}
auto capture =
sigmf::Capture<sigmf::core::DescrT, sigmf::capture_details::DescrT>();
capture.get<sigmf::core::DescrT>().sample_start = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/base_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<tag_t> &all_tags,
std::vector<tag_t> &rx_freq_tags,
std::vector<TIME_T> &rx_times);
Expand Down
19 changes: 10 additions & 9 deletions lib/write_freq_samples_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,19 @@ 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<write_freq_samples_impl>(
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(
const std::string &tag, COUNT_T itemsize, const std::string &datatype,
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),
Expand All @@ -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);
Expand Down Expand Up @@ -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<boost::mutex> guard(queue_lock_);
COUNT_T annotations = 0;
while (!inference_q_.empty()) {
Expand Down
5 changes: 3 additions & 2 deletions lib/write_freq_samples_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
68 changes: 22 additions & 46 deletions python/iqtlabs/bindings/write_freq_samples_python.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <pybind11/complex.h>
Expand All @@ -27,47 +29,21 @@ namespace py = pybind11;
// pydoc.h is automatically generated in the build directory
#include <write_freq_samples_pydoc.h>

void bind_write_freq_samples(py::module& m)
{

using write_freq_samples = ::gr::iqtlabs::write_freq_samples;


py::class_<write_freq_samples, gr::block, gr::basic_block,
std::shared_ptr<write_freq_samples>>(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_<write_freq_samples, gr::block, gr::basic_block,
std::shared_ptr<write_freq_samples>>(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))

;
}








2 changes: 2 additions & 0 deletions python/iqtlabs/qa_write_freq_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"]
Expand Down
1 change: 1 addition & 0 deletions test_flow_graphs/smoke_test_write_freq_samples.grc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ blocks:
sigmf: '1'
zstd: '1'
rotate: '1'
description: '""'
states:
bus_sink: false
bus_source: false
Expand Down

0 comments on commit 315b210

Please sign in to comment.