summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/lib
diff options
context:
space:
mode:
authorJacob Gilbert <jacob.gilbert@protonmail.com>2021-03-13 18:10:44 -0800
committermormj <34754695+mormj@users.noreply.github.com>2021-03-18 16:35:41 -0400
commita8a9913136a64da903f190493bdc117b5349625e (patch)
treecb14b39daa613397e324efd063f688c91e9b3bfa /gnuradio-runtime/lib
parentbd1e4d470c83470f1a54c2c4c85c8e475c070bfa (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/lib')
-rw-r--r--gnuradio-runtime/lib/CMakeLists.txt1
-rw-r--r--gnuradio-runtime/lib/pdu.cc119
2 files changed, 120 insertions, 0 deletions
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 */