summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnathan Corgan <johnathan@corganlabs.com>2013-02-28 11:02:21 -0800
committerJohnathan Corgan <johnathan@corganlabs.com>2013-02-28 11:02:21 -0800
commit33c7198b12eaae233e5e0e0a2bc266f2efb018b1 (patch)
tree184eff568243b976bb41501175d090d88213b0a3
parent51c02f87a08efa4e679630771ec7dd0605e4986a (diff)
blocks: added gr::blocks::pdu namespace for PDU functions
-rw-r--r--gr-blocks/include/blocks/CMakeLists.txt1
-rw-r--r--gr-blocks/include/blocks/pdu.h48
-rw-r--r--gr-blocks/lib/CMakeLists.txt1
-rw-r--r--gr-blocks/lib/pdu.cc92
-rw-r--r--gr-blocks/lib/stream_pdu_base.cc6
-rw-r--r--gr-blocks/lib/tuntap_pdu_impl.cc2
6 files changed, 146 insertions, 4 deletions
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index cea725d360..05672ecf90 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -127,6 +127,7 @@ install(FILES
nlog10_ff.h
pack_k_bits_bb.h
patterned_interleaver.h
+ pdu.h
peak_detector2_fb.h
regenerate_bb.h
repeat.h
diff --git a/gr-blocks/include/blocks/pdu.h b/gr-blocks/include/blocks/pdu.h
new file mode 100644
index 0000000000..de0999c574
--- /dev/null
+++ b/gr-blocks/include/blocks/pdu.h
@@ -0,0 +1,48 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2013 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_BLOCKS_PDU_H
+#define INCLUDED_BLOCKS_PDU_H
+
+#include <blocks/api.h>
+#include <gr_complex.h>
+#include <gruel/pmt.h>
+
+#define PDU_PORT_ID pmt::mp("pdus")
+#define PDU_LENGTH_TAG pmt::mp("pdu_length")
+
+namespace gr {
+ namespace blocks {
+ namespace pdu {
+
+ enum vector_type { byte_t, float_t, complex_t };
+
+ BLOCKS_API size_t itemsize(vector_type type);
+ BLOCKS_API bool type_matches(vector_type type, pmt::pmt_t v);
+ BLOCKS_API pmt::pmt_t make_vector(vector_type type, const uint8_t* buf, size_t items);
+ BLOCKS_API vector_type type_from_pmt(pmt::pmt_t vector);
+
+ } /* namespace pdu */
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_PDU_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 17068f472d..87f41ff289 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -166,6 +166,7 @@ list(APPEND gr_blocks_sources
nlog10_ff_impl.cc
pack_k_bits_bb_impl.cc
patterned_interleaver_impl.cc
+ pdu.cc
peak_detector2_fb_impl.cc
regenerate_bb_impl.cc
repeat_impl.cc
diff --git a/gr-blocks/lib/pdu.cc b/gr-blocks/lib/pdu.cc
new file mode 100644
index 0000000000..41a2d88c3a
--- /dev/null
+++ b/gr-blocks/lib/pdu.cc
@@ -0,0 +1,92 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2013 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <blocks/pdu.h>
+
+namespace gr {
+ namespace blocks {
+ namespace pdu {
+
+ size_t
+ itemsize(vector_type type)
+ {
+ switch(type) {
+ case byte_t:
+ return sizeof(char);
+ case float_t:
+ return sizeof(float);
+ case complex_t:
+ return sizeof(gr_complex);
+ default:
+ throw std::runtime_error("bad PDU type");
+ }
+ }
+
+ bool
+ type_matches(vector_type type, pmt::pmt_t v)
+ {
+ switch(type) {
+ case byte_t:
+ return pmt::pmt_is_u8vector(v);
+ case float_t:
+ return pmt::pmt_is_f32vector(v);
+ case complex_t:
+ return pmt::pmt_is_c32vector(v);
+ default:
+ throw std::runtime_error("bad PDU type");
+ }
+ }
+
+ pmt::pmt_t
+ make_vector(vector_type type, const uint8_t *buf, size_t items)
+ {
+ switch(type) {
+ case byte_t:
+ return pmt::pmt_init_u8vector(items, buf);
+ case float_t:
+ return pmt::pmt_init_f32vector(items, (const float *)buf);
+ case complex_t:
+ return pmt::pmt_init_c32vector(items, (const gr_complex *)buf);
+ default:
+ throw std::runtime_error("bad PDU type");
+ }
+ }
+
+ vector_type
+ type_from_pmt(pmt::pmt_t vector)
+ {
+ if(pmt_is_u8vector(vector))
+ return byte_t;
+ if(pmt_is_f32vector(vector))
+ return float_t;
+ if(pmt_is_c32vector(vector))
+ return complex_t;
+ throw std::runtime_error("bad PDU type");
+ }
+
+ } /* namespace pdu */
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/stream_pdu_base.cc b/gr-blocks/lib/stream_pdu_base.cc
index 3378067f85..cc56b4ee65 100644
--- a/gr-blocks/lib/stream_pdu_base.cc
+++ b/gr-blocks/lib/stream_pdu_base.cc
@@ -28,7 +28,7 @@
#include <io.h>
#endif
-#include <gr_pdu.h>
+#include <blocks/pdu.h>
#include <gr_basic_block.h>
#include "stream_pdu_base.h"
#include <boost/format.hpp>
@@ -112,12 +112,12 @@ namespace gr {
{
pmt::pmt_t vector = pmt::pmt_cdr(msg);
size_t offset(0);
- size_t itemsize(::gr_pdu_itemsize(type_from_pmt(vector)));
+ size_t itemsize(pdu::itemsize(pdu::type_from_pmt(vector)));
int len(pmt::pmt_length(vector)*itemsize);
const int rv = write(d_fd, pmt::pmt_uniform_vector_elements(vector, offset), len);
if (rv != len) {
- std::cerr << boost::format("WARNING: gr_stream_pdu_base::send(pdu) write failed! (d_fd=%d, len=%d, rv=%d)")
+ std::cerr << boost::format("WARNING: stream_pdu_base::send(pdu) write failed! (d_fd=%d, len=%d, rv=%d)")
% d_fd % len % rv << std::endl;
}
}
diff --git a/gr-blocks/lib/tuntap_pdu_impl.cc b/gr-blocks/lib/tuntap_pdu_impl.cc
index 1970a92b69..8de817738f 100644
--- a/gr-blocks/lib/tuntap_pdu_impl.cc
+++ b/gr-blocks/lib/tuntap_pdu_impl.cc
@@ -26,7 +26,7 @@
#include "tuntap_pdu_impl.h"
#include <gr_io_signature.h>
-#include <gr_pdu.h>
+#include <blocks/pdu.h>
#include <boost/format.hpp>
#include <sys/types.h>