diff options
author | Jacob Gilbert <jacob.gilbert@protonmail.com> | 2021-03-13 18:10:44 -0800 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-03-18 16:35:41 -0400 |
commit | a8a9913136a64da903f190493bdc117b5349625e (patch) | |
tree | cb14b39daa613397e324efd063f688c91e9b3bfa /gnuradio-runtime | |
parent | bd1e4d470c83470f1a54c2c4c85c8e475c070bfa (diff) |
gr-pdu: move pdu blocks to gr::pdu
Moving the following from gr::blocks into gr-pdu:
- pdu_filter block
- pdu_remove block
- pdu_set block
- pdu_to_tagged_stream block
- random_pdu block
- tagged_stream_to_pdu block
Moving the following from gr::blocks into gr-network:
- socket_pdu block
- stream_pdu_base (noblock)
- tcp_connection (noblock)
- tuntap_pdu block
Moving the following from gr::blocks into gr:
- pdu (noblock, general PDU functions)
Signed-off-by: Jacob Gilbert <jacob.gilbert@protonmail.com>
Diffstat (limited to 'gnuradio-runtime')
9 files changed, 317 insertions, 1 deletions
diff --git a/gnuradio-runtime/include/gnuradio/CMakeLists.txt b/gnuradio-runtime/include/gnuradio/CMakeLists.txt index 4789a71bbe..9f38af335a 100644 --- a/gnuradio-runtime/include/gnuradio/CMakeLists.txt +++ b/gnuradio-runtime/include/gnuradio/CMakeLists.txt @@ -40,6 +40,7 @@ install(FILES msg_handler.h msg_queue.h nco.h + pdu.h prefs.h pycallback_object.h random.h diff --git a/gnuradio-runtime/include/gnuradio/pdu.h b/gnuradio-runtime/include/gnuradio/pdu.h new file mode 100644 index 0000000000..f6957e5487 --- /dev/null +++ b/gnuradio-runtime/include/gnuradio/pdu.h @@ -0,0 +1,46 @@ +/* -*- c++ -*- */ +/* + * Copyright 2013,2021 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + + +#ifndef INCLUDED_GR_PDU_H +#define INCLUDED_GR_PDU_H + +#include <gnuradio/api.h> +#include <pmt/pmt.h> + +namespace gr { +namespace msgport_names { +// static const PMT interned string getters for standard port names +GR_RUNTIME_API const pmt::pmt_t bpdu(); +GR_RUNTIME_API const pmt::pmt_t cpdu(); +GR_RUNTIME_API const pmt::pmt_t dict(); +GR_RUNTIME_API const pmt::pmt_t fpdu(); +GR_RUNTIME_API const pmt::pmt_t msg(); +GR_RUNTIME_API const pmt::pmt_t pdu(); +GR_RUNTIME_API const pmt::pmt_t pdus(); // compatibility, use of pdu() preferred +GR_RUNTIME_API const pmt::pmt_t vec(); +} /* namespace ports */ + +namespace types { +enum vector_type { byte_t, float_t, complex_t }; +} /* namespace types */ + +namespace pdu { +// pdu functions +GR_RUNTIME_API size_t itemsize(types::vector_type type); +GR_RUNTIME_API bool type_matches(types::vector_type type, pmt::pmt_t v); +GR_RUNTIME_API pmt::pmt_t +make_pdu_vector(types::vector_type type, const uint8_t* buf, size_t items); +GR_RUNTIME_API types::vector_type type_from_pmt(pmt::pmt_t vector); + +} // namespace pdu +} // namespace gr + +#endif /* INCLUDED_GR_PDU_H */ diff --git a/gnuradio-runtime/lib/CMakeLists.txt b/gnuradio-runtime/lib/CMakeLists.txt index 4cddb26fe0..9a6cd4488f 100644 --- a/gnuradio-runtime/lib/CMakeLists.txt +++ b/gnuradio-runtime/lib/CMakeLists.txt @@ -72,6 +72,7 @@ add_library(gnuradio-runtime msg_handler.cc msg_queue.cc pagesize.cc + pdu.cc prefs.cc realtime.cc realtime_impl.cc diff --git a/gnuradio-runtime/lib/pdu.cc b/gnuradio-runtime/lib/pdu.cc new file mode 100644 index 0000000000..e01092de20 --- /dev/null +++ b/gnuradio-runtime/lib/pdu.cc @@ -0,0 +1,119 @@ +/* -*- c++ -*- */ +/* + * Copyright 2013,2021 Free Software Foundation, Inc. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gnuradio/gr_complex.h> +#include <gnuradio/pdu.h> +#include <pmt/pmt.h> + +namespace gr { +namespace msgport_names { + +const pmt::pmt_t bpdu() +{ + static const pmt::pmt_t val = pmt::mp("bpdu"); + return val; +} +const pmt::pmt_t cpdu() +{ + static const pmt::pmt_t val = pmt::mp("cpdu"); + return val; +} +const pmt::pmt_t dict() +{ + static const pmt::pmt_t val = pmt::mp("dict"); + return val; +} +const pmt::pmt_t fpdu() +{ + static const pmt::pmt_t val = pmt::mp("fpdu"); + return val; +} +const pmt::pmt_t msg() +{ + static const pmt::pmt_t val = pmt::mp("msg"); + return val; +} +const pmt::pmt_t pdu() +{ + static const pmt::pmt_t val = pmt::mp("pdu"); + return val; +} +const pmt::pmt_t pdus() +{ + static const pmt::pmt_t val = pmt::mp("pdus"); + return val; +} +const pmt::pmt_t vec() +{ + static const pmt::pmt_t val = pmt::mp("vec"); + return val; +} + +} /* namespace ports */ + +namespace pdu { + +size_t itemsize(types::vector_type type) +{ + switch (type) { + case types::byte_t: + return sizeof(char); + case types::float_t: + return sizeof(float); + case types::complex_t: + return sizeof(gr_complex); + default: + throw std::runtime_error("bad PDU type"); + } +} + +bool type_matches(types::vector_type type, pmt::pmt_t v) +{ + switch (type) { + case types::byte_t: + return pmt::is_u8vector(v); + case types::float_t: + return pmt::is_f32vector(v); + case types::complex_t: + return pmt::is_c32vector(v); + default: + throw std::runtime_error("bad PDU type"); + } +} + +pmt::pmt_t make_pdu_vector(types::vector_type type, const uint8_t* buf, size_t items) +{ + switch (type) { + case types::byte_t: + return pmt::init_u8vector(items, buf); + case types::float_t: + return pmt::init_f32vector(items, (const float*)buf); + case types::complex_t: + return pmt::init_c32vector(items, (const gr_complex*)buf); + default: + throw std::runtime_error("bad PDU type"); + } +} + +types::vector_type type_from_pmt(pmt::pmt_t vector) +{ + if (pmt::is_u8vector(vector)) + return types::byte_t; + if (pmt::is_f32vector(vector)) + return types::float_t; + if (pmt::is_c32vector(vector)) + return types::complex_t; + throw std::runtime_error("bad PDU type"); +} + +} /* namespace pdu */ +} /* namespace gr */ diff --git a/gnuradio-runtime/python/gnuradio/__init__.py b/gnuradio-runtime/python/gnuradio/__init__.py index 2326c3ab89..45bc91bf4d 100644 --- a/gnuradio-runtime/python/gnuradio/__init__.py +++ b/gnuradio-runtime/python/gnuradio/__init__.py @@ -57,4 +57,5 @@ if path.endswith(path_ending): __path__.append(os.path.join(build_path, 'gr-utils')) __path__.append(os.path.join(build_path, 'gr-uhd', 'python')) __path__.append(os.path.join(build_path, 'gr-pdu', 'python')) + __path__.append(os.path.join(build_path, 'gr-network', 'python')) __path__.append(os.path.join(build_path, 'gr-zeromq', 'python')) diff --git a/gnuradio-runtime/python/gnuradio/gr/bindings/CMakeLists.txt b/gnuradio-runtime/python/gnuradio/gr/bindings/CMakeLists.txt index 17b1a30590..ef8f1f10dd 100644 --- a/gnuradio-runtime/python/gnuradio/gr/bindings/CMakeLists.txt +++ b/gnuradio-runtime/python/gnuradio/gr/bindings/CMakeLists.txt @@ -42,6 +42,7 @@ messages/msg_queue_python.cc msg_handler_python.cc msg_queue_python.cc nco_python.cc + pdu_python.cc prefs_python.cc # pycallback_object_python.cc random_python.cc @@ -81,7 +82,7 @@ messages/msg_queue_python.cc # xoroshiro128p_python.cc python_bindings.cc) -GR_PYBIND_MAKE_CHECK_HASH(gr +GR_PYBIND_MAKE_CHECK_HASH(gr ../../../.. gr::gr "${gr_python_files}") diff --git a/gnuradio-runtime/python/gnuradio/gr/bindings/docstrings/pdu_pydoc_template.h b/gnuradio-runtime/python/gnuradio/gr/bindings/docstrings/pdu_pydoc_template.h new file mode 100644 index 0000000000..8ba6b5ddd0 --- /dev/null +++ b/gnuradio-runtime/python/gnuradio/gr/bindings/docstrings/pdu_pydoc_template.h @@ -0,0 +1,51 @@ +/* + * Copyright 2021 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ +#include "pydoc_macros.h" +#define D(...) DOC(gr, __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_msgport_names_bpdu = R"doc()doc"; + + +static const char* __doc_gr_msgport_names_cpdu = R"doc()doc"; + + +static const char* __doc_gr_msgport_names_dict = R"doc()doc"; + + +static const char* __doc_gr_msgport_names_fpdu = R"doc()doc"; + + +static const char* __doc_gr_msgport_names_msg = R"doc()doc"; + + +static const char* __doc_gr_msgport_names_pdu = R"doc()doc"; + + +static const char* __doc_gr_msgport_names_pdus = R"doc()doc"; + + +static const char* __doc_gr_msgport_names_vec = R"doc()doc"; + + +static const char* __doc_gr_pdu_itemsize = R"doc()doc"; + + +static const char* __doc_gr_pdu_type_matches = R"doc()doc"; + + +static const char* __doc_gr_pdu_make_pdu_vector = R"doc()doc"; + + +static const char* __doc_gr_pdu_type_from_pmt = R"doc()doc"; diff --git a/gnuradio-runtime/python/gnuradio/gr/bindings/pdu_python.cc b/gnuradio-runtime/python/gnuradio/gr/bindings/pdu_python.cc new file mode 100644 index 0000000000..98df9acd8c --- /dev/null +++ b/gnuradio-runtime/python/gnuradio/gr/bindings/pdu_python.cc @@ -0,0 +1,94 @@ +/* + * Copyright 2021 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +/***********************************************************************************/ +/* 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(pdu.h) */ +/* BINDTOOL_HEADER_FILE_HASH(2b56328d8782d0a1816df04928cd83c5) */ +/***********************************************************************************/ + +#include <pybind11/complex.h> +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> + +namespace py = pybind11; + +#include <gnuradio/pdu.h> +// pydoc.h is automatically generated in the build directory +#include <pdu_pydoc.h> + +void bind_pdu(py::module& m) +{ + + py::module m_types = m.def_submodule("types"); + + py::enum_<::gr::types::vector_type>(m_types, "vector_type") + .value("byte_t", ::gr::types::byte_t) // 0 + .value("float_t", ::gr::types::float_t) // 1 + .value("complex_t", ::gr::types::complex_t) // 2 + .export_values(); + + py::implicitly_convertible<int, ::gr::types::vector_type>(); + + + py::module m_msgport_names = m.def_submodule("msgport_names"); + + m_msgport_names.def("bpdu", &::gr::msgport_names::bpdu, D(msgport_names, bpdu)); + + + m_msgport_names.def("cpdu", &::gr::msgport_names::cpdu, D(msgport_names, cpdu)); + + + m_msgport_names.def("dict", &::gr::msgport_names::dict, D(msgport_names, dict)); + + + m_msgport_names.def("fpdu", &::gr::msgport_names::fpdu, D(msgport_names, fpdu)); + + + m_msgport_names.def("msg", &::gr::msgport_names::msg, D(msgport_names, msg)); + + + m_msgport_names.def("pdu", &::gr::msgport_names::pdu, D(msgport_names, pdu)); + + + m_msgport_names.def("pdus", &::gr::msgport_names::pdus, D(msgport_names, pdus)); + + + m_msgport_names.def("vec", &::gr::msgport_names::vec, D(msgport_names, vec)); + + + py::module m_pdu = m.def_submodule("pdu"); + + m_pdu.def("itemsize", &::gr::pdu::itemsize, py::arg("type"), D(pdu, itemsize)); + + + m_pdu.def("type_matches", + &::gr::pdu::type_matches, + py::arg("type"), + py::arg("v"), + D(pdu, type_matches)); + + + m_pdu.def("make_pdu_vector", + &::gr::pdu::make_pdu_vector, + py::arg("type"), + py::arg("buf"), + py::arg("items"), + D(pdu, make_pdu_vector)); + + + m_pdu.def("type_from_pmt", + &::gr::pdu::type_from_pmt, + py::arg("vector"), + D(pdu, type_from_pmt)); +} diff --git a/gnuradio-runtime/python/gnuradio/gr/bindings/python_bindings.cc b/gnuradio-runtime/python/gnuradio/gr/bindings/python_bindings.cc index 8307fa8790..c180116c80 100644 --- a/gnuradio-runtime/python/gnuradio/gr/bindings/python_bindings.cc +++ b/gnuradio-runtime/python/gnuradio/gr/bindings/python_bindings.cc @@ -52,6 +52,7 @@ void bind_msg_queue(py::module&); void bind_msg_handler(py::module&); void bind_msg_queue(py::module&); void bind_nco(py::module&); +void bind_pdu(py::module&); void bind_prefs(py::module&); // void bind_pycallback_object(py::module&); void bind_random(py::module&); @@ -152,6 +153,7 @@ PYBIND11_MODULE(gr_python, m) bind_nco(m); + bind_pdu(m); bind_prefs(m); // // bind_pycallback_object(m); bind_random(m); |