diff options
41 files changed, 769 insertions, 541 deletions
diff --git a/docs/sphinx/source/gr/converter_blk.rst b/docs/sphinx/source/gr/converter_blk.rst index 81d159ece0..be643d2cb1 100644 --- a/docs/sphinx/source/gr/converter_blk.rst +++ b/docs/sphinx/source/gr/converter_blk.rst @@ -8,4 +8,3 @@ gnuradio.gr: Type Conversions .. autooldblock:: gnuradio.gr.complex_to_mag .. autooldblock:: gnuradio.gr.complex_to_mag_squared .. autooldblock:: gnuradio.gr.complex_to_arg -.. autooldblock:: gnuradio.gr.unpack_k_bits_bb diff --git a/docs/sphinx/source/gr/index.rst b/docs/sphinx/source/gr/index.rst index 9c4f34f93c..9cba4089fd 100644 --- a/docs/sphinx/source/gr/index.rst +++ b/docs/sphinx/source/gr/index.rst @@ -132,7 +132,6 @@ Type Conversions gnuradio.gr.complex_to_mag gnuradio.gr.complex_to_mag_squared gnuradio.gr.complex_to_arg - gnuradio.gr.unpack_k_bits_bb Signal Level Control (AGC) ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index d38d478e7d..b844cf302c 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -170,8 +170,6 @@ set(gr_core_general_triple_threats gr_test gr_vco_f gr_vector_map - gr_unpack_k_bits_bb - gr_pack_k_bits_bb gr_annotator_alltoall gr_annotator_1to1 gr_annotator_raw diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index 1769c1e832..ff4c95631b 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -47,8 +47,6 @@ #include <gr_constants.h> #include <gr_test_types.h> #include <gr_test.h> -#include <gr_unpack_k_bits_bb.h> -#include <gr_pack_k_bits_bb.h> #include <gr_feval.h> #include <gr_bin_statistics_f.h> #include <gr_copy.h> @@ -87,8 +85,6 @@ %include "gr_constants.i" %include "gr_test_types.h" %include "gr_test.i" -%include "gr_unpack_k_bits_bb.i" -%include "gr_pack_k_bits_bb.i" %include "gr_feval.i" %include "gr_bin_statistics_f.i" %include "gr_copy.i" diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc deleted file mode 100644 index 0ea0c9e388..0000000000 --- a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2012 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. - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gr_pack_k_bits_bb.h> -#include <gr_io_signature.h> -#include <stdexcept> -#include <iostream> - -gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb(unsigned k) -{ - return gnuradio::get_initial_sptr(new gr_pack_k_bits_bb(k)); -} - - -gr_pack_k_bits_bb::gr_pack_k_bits_bb (unsigned k) - : gr_sync_decimator("pack_k_bits_bb", - gr_make_io_signature (1, 1, sizeof(unsigned char)), - gr_make_io_signature (1, 1, sizeof(unsigned char)), - k), - d_k (k) -{ - if (d_k == 0) - throw std::out_of_range("interpolation must be > 0"); -} - -gr_pack_k_bits_bb::~gr_pack_k_bits_bb() -{ -} - -int -gr_pack_k_bits_bb::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - const unsigned char *in = (const unsigned char *)input_items[0]; - unsigned char *out = (unsigned char *)output_items[0]; - - for(int i = 0; i < noutput_items; i++) { - out[i] = 0x00; - for(unsigned int j = 0; j < d_k; j++) { - out[i] |= (0x01 & in[i*d_k+j])<<(d_k-j-1); - } - } - - return noutput_items; -} diff --git a/gnuradio-core/src/lib/general/gr_unpack_k_bits_bb.cc b/gnuradio-core/src/lib/general/gr_unpack_k_bits_bb.cc deleted file mode 100644 index 00b88e9724..0000000000 --- a/gnuradio-core/src/lib/general/gr_unpack_k_bits_bb.cc +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2005,2010 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. - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gr_unpack_k_bits_bb.h> -#include <gr_io_signature.h> -#include <stdexcept> -#include <iostream> - -gr_unpack_k_bits_bb_sptr gr_make_unpack_k_bits_bb (unsigned k) -{ - return gnuradio::get_initial_sptr(new gr_unpack_k_bits_bb (k)); -} - - -gr_unpack_k_bits_bb::gr_unpack_k_bits_bb (unsigned k) - : gr_sync_interpolator ("unpack_k_bits_bb", - gr_make_io_signature (1, 1, sizeof (unsigned char)), - gr_make_io_signature (1, 1, sizeof (unsigned char)), - k), - d_k (k) -{ - if (d_k == 0) - throw std::out_of_range ("interpolation must be > 0"); -} - -gr_unpack_k_bits_bb::~gr_unpack_k_bits_bb () -{ -} - -int -gr_unpack_k_bits_bb::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - const unsigned char *in = (const unsigned char *) input_items[0]; - unsigned char *out = (unsigned char *) output_items[0]; - - int n = 0; - for (unsigned int i = 0; i < noutput_items/d_k; i++){ - unsigned int t = in[i]; - for (int j = d_k - 1; j >= 0; j--) - out[n++] = (t >> j) & 0x01; - } - - assert(n == noutput_items); - return noutput_items; -} diff --git a/gnuradio-core/src/lib/io/CMakeLists.txt b/gnuradio-core/src/lib/io/CMakeLists.txt index 59ca06b5a2..23c019d63b 100644 --- a/gnuradio-core/src/lib/io/CMakeLists.txt +++ b/gnuradio-core/src/lib/io/CMakeLists.txt @@ -105,7 +105,6 @@ set(gr_core_io_triple_threats gr_wavfile_sink gr_tagged_file_sink gr_tagged_stream_to_pdu - gr_tuntap_pdu gr_socket_pdu ) diff --git a/gnuradio-core/src/lib/io/gr_pdu.h b/gnuradio-core/src/lib/io/gr_pdu.h index a5ae87db7f..53058ccb6c 100644 --- a/gnuradio-core/src/lib/io/gr_pdu.h +++ b/gnuradio-core/src/lib/io/gr_pdu.h @@ -23,17 +23,18 @@ #ifndef GR_PDU_H #define GR_PDU_H +#include <gr_core_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") +#define PDU_PORT_ID pmt::mp("pdus") +#define PDU_LENGTH_TAG pmt::mp("pdu_length") enum gr_pdu_vector_type { pdu_byte, pdu_float, pdu_complex }; -size_t gr_pdu_itemsize(gr_pdu_vector_type type); -bool gr_pdu_type_matches(gr_pdu_vector_type type, pmt::pmt_t v); -pmt::pmt_t gr_pdu_make_vector(gr_pdu_vector_type type, const uint8_t* buf, size_t items); -gr_pdu_vector_type type_from_pmt(pmt::pmt_t vector); +GR_CORE_API size_t gr_pdu_itemsize(gr_pdu_vector_type type); +GR_CORE_API bool gr_pdu_type_matches(gr_pdu_vector_type type, pmt::pmt_t v); +GR_CORE_API pmt::pmt_t gr_pdu_make_vector(gr_pdu_vector_type type, const uint8_t* buf, size_t items); +GR_CORE_API gr_pdu_vector_type type_from_pmt(pmt::pmt_t vector); #endif diff --git a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc index 9354a1366d..79011d8536 100644 --- a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc +++ b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc @@ -49,7 +49,7 @@ gr_pdu_to_tagged_stream::gr_pdu_to_tagged_stream (gr_pdu_vector_type t) gr_make_io_signature(1, 1, gr_pdu_itemsize(t))), d_vectortype(t), d_itemsize(gr_pdu_itemsize(t)) { - message_port_register_in(pdu_port_id); + message_port_register_in(PDU_PORT_ID); } gr_pdu_to_tagged_stream::~gr_pdu_to_tagged_stream() @@ -77,8 +77,8 @@ gr_pdu_to_tagged_stream::work(int noutput_items, if(noutput_items > 0){ // grab a message if one exists - //pmt::pmt_t msg( delete_head_nowait( pdu_port_id ) ); - pmt::pmt_t msg( delete_head_blocking( pdu_port_id ) ); + //pmt::pmt_t msg( delete_head_nowait( PDU_PORT_ID ) ); + pmt::pmt_t msg( delete_head_blocking( PDU_PORT_ID ) ); if(msg.get() == NULL ){ return nout; } @@ -99,7 +99,7 @@ gr_pdu_to_tagged_stream::work(int noutput_items, uint64_t offset = nitems_written(0) + nout; // add a tag for pdu length - add_item_tag(0, offset, pdu_length_tag, pmt::from_long( pmt::length(vect) ), pmt::mp(alias())); + add_item_tag(0, offset, PDU_LENGTH_TAG, pmt::from_long( pmt::length(vect) ), pmt::mp(alias())); // if we recieved metadata add it as tags if( !eq(meta, pmt::PMT_NIL) ){ diff --git a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc index 3493f6a389..7daac6db26 100644 --- a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc +++ b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc @@ -49,7 +49,7 @@ gr_tagged_stream_to_pdu::gr_tagged_stream_to_pdu (gr_pdu_vector_type t) d_vectortype(t), d_itemsize(gr_pdu_itemsize(t)), d_inpdu(false), d_pdu_meta(pmt::PMT_NIL), d_pdu_vector(pmt::PMT_NIL) { - message_port_register_out(pdu_port_id); + message_port_register_out(PDU_PORT_ID); } gr_tagged_stream_to_pdu::~gr_tagged_stream_to_pdu() @@ -70,7 +70,7 @@ gr_tagged_stream_to_pdu::work(int noutput_items, get_tags_in_range(d_tags, 0, abs_N, abs_N+1); bool found_length_tag(false); for(d_tags_itr = d_tags.begin(); (d_tags_itr != d_tags.end()) && (!found_length_tag); d_tags_itr++){ - if( pmt::equal( (*d_tags_itr).key, pdu_length_tag ) ){ + if( pmt::equal( (*d_tags_itr).key, PDU_LENGTH_TAG ) ){ if( (*d_tags_itr).offset != abs_N ){ throw std::runtime_error("expected next pdu length tag on a different item..."); } @@ -91,7 +91,7 @@ gr_tagged_stream_to_pdu::work(int noutput_items, // copy any tags in this range into our meta object get_tags_in_range(d_tags, 0, abs_N, abs_N+ncopy); for(d_tags_itr = d_tags.begin(); d_tags_itr != d_tags.end(); d_tags_itr++){ - if( ! equal( (*d_tags_itr).key, pdu_length_tag ) ){ + if( ! equal( (*d_tags_itr).key, PDU_LENGTH_TAG ) ){ d_pdu_meta = dict_add(d_pdu_meta, (*d_tags_itr).key, (*d_tags_itr).value); } } @@ -127,7 +127,7 @@ void gr_tagged_stream_to_pdu::send_message(){ } pmt::pmt_t msg = pmt::cons( d_pdu_meta, d_pdu_vector ); - message_port_pub( pdu_port_id, msg ); + message_port_pub( PDU_PORT_ID, msg ); d_pdu_meta = pmt::PMT_NIL; d_pdu_vector = pmt::PMT_NIL; diff --git a/gnuradio-core/src/lib/io/gr_tuntap_pdu.cc b/gnuradio-core/src/lib/io/gr_tuntap_pdu.cc deleted file mode 100644 index 8dd4b18a10..0000000000 --- a/gnuradio-core/src/lib/io/gr_tuntap_pdu.cc +++ /dev/null @@ -1,145 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2012 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 <gr_tuntap_pdu.h> -#include <gr_io_signature.h> -#include <cstdio> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <stdexcept> -#include <string.h> -#include <iostream> -#include <gr_pdu.h> -#include <boost/format.hpp> - -#if (defined(linux) || defined(__linux) || defined(__linux__)) - -#include <sys/ioctl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - -#include <arpa/inet.h> -#include <linux/if.h> - - -// public constructor that returns a shared_ptr - -gr_tuntap_pdu_sptr -gr_make_tuntap_pdu (std::string dev, int MTU) -{ - return gnuradio::get_initial_sptr(new gr_tuntap_pdu(dev, MTU)); -} - -gr_tuntap_pdu::gr_tuntap_pdu (std::string dev, int MTU) - : gr_stream_pdu_base(MTU) -{ - - // make the tuntap - char dev_cstr[1024]; - memset(dev_cstr, 0x00, 1024); - strncpy(dev_cstr, dev.c_str(), std::min(sizeof(dev_cstr), dev.size())); - d_fd = tun_alloc(dev_cstr); - if(d_fd <= 0){ - throw std::runtime_error("TunTap make: tun_alloc failed (are you running as root?)"); - } - - std::cout << boost::format( - "Allocated virtual ethernet interface: %s\n" - "You must now use ifconfig to set its IP address. E.g.,\n" - " $ sudo ifconfig %s 192.168.200.1\n" - "Be sure to use a different address in the same subnet for each machine.\n" - ) % dev % dev << std::endl; - - // set up output message port - message_port_register_out(pmt::mp("pdus")); - start_rxthread(pmt::mp("pdus")); - - // set up input message port - message_port_register_in(pmt::mp("pdus")); - set_msg_handler(pmt::mp("pdus"), boost::bind(&gr_tuntap_pdu::send, this, _1)); -} - - -int gr_tuntap_pdu::tun_alloc(char *dev, int flags) { - struct ifreq ifr; - int fd, err; - const char *clonedev = "/dev/net/tun"; - - /* Arguments taken by the function: - * - * char *dev: the name of an interface (or '\0'). MUST have enough - * space to hold the interface name if '\0' is passed - * int flags: interface flags (eg, IFF_TUN etc.) - */ - - /* open the clone device */ - if( (fd = open(clonedev, O_RDWR)) < 0 ) { - return fd; - } - - /* preparation of the struct ifr, of type "struct ifreq" */ - memset(&ifr, 0, sizeof(ifr)); - - ifr.ifr_flags = flags; /* IFF_TUN or IFF_TAP, plus maybe IFF_NO_PI */ - - if (*dev) { - /* if a device name was specified, put it in the structure; otherwise, - * the kernel will try to allocate the "next" device of the - * specified type */ - strncpy(ifr.ifr_name, dev, IFNAMSIZ); - } - - /* try to create the device */ - if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ) { - close(fd); - return err; - } - - /* if the operation was successful, write back the name of the - * interface to the variable "dev", so the caller can know - * it. Note that the caller MUST reserve space in *dev (see calling - * code below) */ - strcpy(dev, ifr.ifr_name); - - /* this is the special file descriptor that the caller will use to talk - * with the virtual interface */ - return fd; -} - -#else //if not linux - -gr_block_sptr -gr_make_tuntap_pdu(std::string dev, int MTU) -{ - gr_block_sptr rv; - throw std::runtime_error("tuntap only implemented on linux"); - return rv; -} - -#endif diff --git a/gnuradio-core/src/lib/io/gr_tuntap_pdu.h b/gnuradio-core/src/lib/io/gr_tuntap_pdu.h deleted file mode 100644 index 18c83f42b2..0000000000 --- a/gnuradio-core/src/lib/io/gr_tuntap_pdu.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2012 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_GR_TUNTAP_PDU_H -#define INCLUDED_GR_TUNTAP_PDU_H - -#include <gr_core_api.h> -#include <gr_sync_block.h> -#include <gr_message.h> -#include <gr_msg_queue.h> -#include <gr_stream_pdu_base.h> - -#if (defined(linux) || defined(__linux) || defined(__linux__)) - -#include <linux/if_tun.h> - -class gr_tuntap_pdu; -typedef boost::shared_ptr<gr_tuntap_pdu> gr_tuntap_pdu_sptr; - -GR_CORE_API gr_tuntap_pdu_sptr gr_make_tuntap_pdu (std::string dev, int MTU=10000); - -/*! - * \brief Gather received items into messages and insert into msgq - * \ingroup sink_blk - */ -class GR_CORE_API gr_tuntap_pdu : public gr_stream_pdu_base -{ - private: - friend GR_CORE_API gr_tuntap_pdu_sptr - gr_make_tuntap_pdu(std::string dev, int MTU); - int tun_alloc(char* dev, int flags = IFF_TAP | IFF_NO_PI); - std::string d_dev; - protected: - gr_tuntap_pdu (std::string dev, int MTU=10000); - - public: - ~gr_tuntap_pdu () {} - -}; - -#else // if not linux - -class gr_tuntap_pdu -{ -private: - gr_tuntap_pdu() {}; -public: - ~gr_tuntap_pdu() {}; -}; - -GR_CORE_API gr_block_sptr gr_make_tuntap_pdu (std::string dev, int MTU=0); - -#endif - -#endif /* INCLUDED_GR_TUNTAP_PDU_H */ diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index e2de4eb976..33cc906e92 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -49,7 +49,6 @@ #include <gr_tagged_stream_to_pdu.h> #include <gr_message_debug.h> #include <gr_pdu.h> -#include <gr_tuntap_pdu.h> #include <gr_socket_pdu.h> %} @@ -77,7 +76,6 @@ %include "gr_tagged_stream_to_pdu.i" %include "gr_message_debug.i" %include "gr_pdu.i" -%include "gr_tuntap_pdu.i" %include "gr_socket_pdu.i" diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml index 7f5a13abb7..95918ec30d 100644 --- a/gr-blocks/grc/blocks_block_tree.xml +++ b/gr-blocks/grc/blocks_block_tree.xml @@ -85,8 +85,6 @@ <cat> <name>Stream Operations (New) </name> <block>blocks_delay</block> - <block>blocks_packed_to_unpacked_xx</block> - <block>blocks_unpacked_to_packed_xx</block> <block>blocks_deinterleave</block> <block>blocks_interleave</block> <block>blocks_keep_m_in_n</block> @@ -106,7 +104,18 @@ <block>blocks_threshold_ff</block> </cat> <cat> + <name>Misc Conversions (New) </name> + <block>blocks_packed_to_unpacked_xx</block> + <block>blocks_unpacked_to_packed_xx</block> + <block>blocks_pack_k_bits_bb</block> + <block>blocks_unpack_k_bits_bb</block> + </cat> + <cat> <name>Misc (New) </name> <block>blocks_throttle</block> </cat> + <cat> + <name>Networking</name> + <block>blocks_tuntap_pdu</block> + </cat> </cat> diff --git a/grc/blocks/gr_pack_k_bits_bb.xml b/gr-blocks/grc/blocks_pack_k_bits_bb.xml index 34e64a5d96..5400eb4af9 100644 --- a/grc/blocks/gr_pack_k_bits_bb.xml +++ b/gr-blocks/grc/blocks_pack_k_bits_bb.xml @@ -6,9 +6,9 @@ --> <block> <name>Pack K Bits</name> - <key>gr_pack_k_bits_bb</key> - <import>from gnuradio import gr</import> - <make>gr.pack_k_bits_bb($k)</make> + <key>blocks_pack_k_bits_bb</key> + <import>from gnuradio import blocks</import> + <make>blocks.pack_k_bits_bb($k)</make> <param> <name>K</name> <key>k</key> diff --git a/gr-blocks/grc/blocks_tuntap_pdu.xml b/gr-blocks/grc/blocks_tuntap_pdu.xml new file mode 100644 index 0000000000..d9a63d4a7f --- /dev/null +++ b/gr-blocks/grc/blocks_tuntap_pdu.xml @@ -0,0 +1,34 @@ +<?xml version="1.0"?> +<!-- +################################################### +## TUNTAP PDU async message source/sink +################################################### + --> +<block> + <name>TUNTAP PDU</name> + <key>blocks_tuntap_pdu</key> + <import>from gnuradio import blocks</import> + <make>blocks.tuntap_pdu($ifn, $mtu)</make> + <param> + <name>Interface Name</name> + <key>ifn</key> + <value>tun0</value> + <type>string</type> + </param> + <param> + <name>MTU</name> + <key>mtu</key> + <value>10000</value> + <type>int</type> + </param> + <sink> + <name>pdus</name> + <type>message</type> + <optional>1</optional> + </sink> + <source> + <name>pdus</name> + <type>message</type> + <optional>1</optional> + </source> +</block> diff --git a/grc/blocks/gr_unpack_k_bits_bb.xml b/gr-blocks/grc/blocks_unpack_k_bits_bb.xml index 9917644ab5..90d7493af0 100644 --- a/grc/blocks/gr_unpack_k_bits_bb.xml +++ b/gr-blocks/grc/blocks_unpack_k_bits_bb.xml @@ -6,9 +6,9 @@ --> <block> <name>Unpack K Bits</name> - <key>gr_unpack_k_bits_bb</key> - <import>from gnuradio import gr</import> - <make>gr.unpack_k_bits_bb($k)</make> + <key>blocks_unpack_k_bits_bb</key> + <import>from gnuradio import blocks</import> + <make>blocks.unpack_k_bits_bb($k)</make> <param> <name>K</name> <key>k</key> diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt index d3c08f6e6d..48e399d065 100644 --- a/gr-blocks/include/blocks/CMakeLists.txt +++ b/gr-blocks/include/blocks/CMakeLists.txt @@ -125,6 +125,7 @@ install(FILES multiply_const_cc.h multiply_const_ff.h nlog10_ff.h + pack_k_bits_bb.h patterned_interleaver.h peak_detector2_fb.h regenerate_bb.h @@ -142,7 +143,9 @@ install(FILES threshold_ff.h throttle.h transcendental.h + tuntap_pdu.h uchar_to_float.h + unpack_k_bits_bb.h vector_to_stream.h vector_to_streams.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h b/gr-blocks/include/blocks/pack_k_bits_bb.h index 8e1508c78b..5bf71c9c3e 100644 --- a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h +++ b/gr-blocks/include/blocks/pack_k_bits_bb.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2012 Free Software Foundation, Inc. + * Copyright 2012-2013 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,34 +23,31 @@ #ifndef INCLUDED_GR_PACK_K_BITS_BB_H #define INCLUDED_GR_PACK_K_BITS_BB_H -#include <gr_core_api.h> +#include <blocks/api.h> #include <gr_sync_decimator.h> -class gr_pack_k_bits_bb; -typedef boost::shared_ptr<gr_pack_k_bits_bb> gr_pack_k_bits_bb_sptr; -GR_CORE_API gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb (unsigned k); - -class gr_pack_k_bits_bb; - -/*! - * \brief Converts a stream of bytes with 1 bit in the LSB to a byte with k relevent bits. - * \ingroup converter_blk - */ -class GR_CORE_API gr_pack_k_bits_bb : public gr_sync_decimator -{ - private: - friend GR_CORE_API gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb (unsigned k); - - gr_pack_k_bits_bb (unsigned k); - - unsigned d_k; // number of relevent bits to pack from k input bytes - - public: - ~gr_pack_k_bits_bb (); - - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); -}; - -#endif +namespace gr { + namespace blocks { + + /*! + * \brief Converts a stream of bytes with 1 bit in the LSB to a + * byte with k relevent bits. + * \ingroup converter_blk + */ + class BLOCKS_API pack_k_bits_bb : virtual public gr_sync_decimator + { + public: + // gr::blocks::pack_k_bits_bb::sptr + typedef boost::shared_ptr<pack_k_bits_bb> sptr; + + /*! + * \brief Make a pack_k_bits block. + * \param k number of bits to be packed. + */ + static sptr make(unsigned k); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_PACK_K_BITS_BB_H */ diff --git a/gr-blocks/include/blocks/tuntap_pdu.h b/gr-blocks/include/blocks/tuntap_pdu.h new file mode 100644 index 0000000000..70abb0bd5b --- /dev/null +++ b/gr-blocks/include/blocks/tuntap_pdu.h @@ -0,0 +1,53 @@ +/* -*- 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_TUNTAP_PDU_H +#define INCLUDED_BLOCKS_TUNTAP_PDU_H + +#include <blocks/api.h> +#include <gr_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Creates TUNTAP interface and translates traffic to PDUs + * \ingroup net_blk + */ + class BLOCKS_API tuntap_pdu : virtual public gr_block + { + public: + // gr::blocks::tuntap_pdu::sptr + typedef boost::shared_ptr<tuntap_pdu> sptr; + + /*! + * \brief Construct a TUNTAP PDU interface + * \param dev Device name to create + * \param MTU Maximum Transmission Unit size + */ + static sptr make(std::string dev, int MTU=10000); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_BLOCKS_TUNTAP_PDU_H */ diff --git a/gnuradio-core/src/lib/general/gr_unpack_k_bits_bb.h b/gr-blocks/include/blocks/unpack_k_bits_bb.h index c3ea28d3fa..b716ded1d3 100644 --- a/gnuradio-core/src/lib/general/gr_unpack_k_bits_bb.h +++ b/gr-blocks/include/blocks/unpack_k_bits_bb.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2013 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,34 +23,30 @@ #ifndef INCLUDED_GR_UNPACK_K_BITS_BB_H #define INCLUDED_GR_UNPACK_K_BITS_BB_H -#include <gr_core_api.h> +#include <blocks/api.h> #include <gr_sync_interpolator.h> -class gr_unpack_k_bits_bb; -typedef boost::shared_ptr<gr_unpack_k_bits_bb> gr_unpack_k_bits_bb_sptr; -GR_CORE_API gr_unpack_k_bits_bb_sptr gr_make_unpack_k_bits_bb (unsigned k); - -class gr_unpack_k_bits_bb; - -/*! - * \brief Converts a byte with k relevent bits to k output bytes with 1 bit in the LSB. - * \ingroup converter_blk - */ -class GR_CORE_API gr_unpack_k_bits_bb : public gr_sync_interpolator -{ - private: - friend GR_CORE_API gr_unpack_k_bits_bb_sptr gr_make_unpack_k_bits_bb (unsigned k); - - gr_unpack_k_bits_bb (unsigned k); - - unsigned d_k; // number of relevent bits to unpack into k output bytes - - public: - ~gr_unpack_k_bits_bb (); - - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); -}; - -#endif +namespace gr { + namespace blocks { + + /*! + * \brief Converts a byte with k relevent bits to k output bytes with 1 bit in the LSB. + * \ingroup converter_blk + */ + class BLOCKS_API unpack_k_bits_bb : virtual public gr_sync_interpolator + { + public: + // gr::blocks::unpack_k_bits_bb::sptr + typedef boost::shared_ptr<unpack_k_bits_bb> sptr; + + /*! + * \brief Make an unpack_k_bits block. + * \param k number of bits to unpack. + */ + static sptr make(unsigned k); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_UNPACK_K_BITS_BB_H */ diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index 20e3ae4aa6..28158ab593 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -164,6 +164,7 @@ list(APPEND gr_blocks_sources multiply_const_cc_impl.cc multiply_const_ff_impl.cc nlog10_ff_impl.cc + pack_k_bits_bb_impl.cc patterned_interleaver_impl.cc peak_detector2_fb_impl.cc regenerate_bb_impl.cc @@ -173,6 +174,7 @@ list(APPEND gr_blocks_sources short_to_char_impl.cc short_to_float_impl.cc stream_mux_impl.cc + stream_pdu_base.cc stream_to_streams_impl.cc stream_to_vector_impl.cc streams_to_stream_impl.cc @@ -181,8 +183,10 @@ list(APPEND gr_blocks_sources threshold_ff_impl.cc throttle_impl.cc transcendental_impl.cc + tuntap_pdu_impl.cc uchar_array_to_float.cc uchar_to_float_impl.cc + unpack_k_bits_bb_impl.cc vector_to_stream_impl.cc vector_to_streams_impl.cc ) diff --git a/gr-blocks/lib/ConfigChecks.cmake b/gr-blocks/lib/ConfigChecks.cmake index 72d6d1d8ab..7f60aed403 100644 --- a/gr-blocks/lib/ConfigChecks.cmake +++ b/gr-blocks/lib/ConfigChecks.cmake @@ -56,7 +56,7 @@ CHECK_INCLUDE_FILE_CXX(windows.h HAVE_WINDOWS_H) IF(HAVE_WINDOWS_H) ADD_DEFINITIONS(-DHAVE_WINDOWS_H -DUSING_WINSOCK) MESSAGE(STATUS "Adding windows libs to gr blocks libs...") - LIST(APPEND gnuradio_core_libs WS2_32.lib WSock32.lib) + LIST(APPEND blocks_libs WS2_32.lib WSock32.lib) ENDIF(HAVE_WINDOWS_H) ######################################################################## diff --git a/gr-blocks/lib/pack_k_bits_bb_impl.cc b/gr-blocks/lib/pack_k_bits_bb_impl.cc new file mode 100644 index 0000000000..2a7fcc04cb --- /dev/null +++ b/gr-blocks/lib/pack_k_bits_bb_impl.cc @@ -0,0 +1,76 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012-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. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include "pack_k_bits_bb_impl.h" +#include <gr_io_signature.h> +#include <stdexcept> +#include <iostream> + +namespace gr { + namespace blocks { + + pack_k_bits_bb::sptr + pack_k_bits_bb::make(unsigned k) + { + return gnuradio::get_initial_sptr + (new pack_k_bits_bb_impl(k)); + } + + pack_k_bits_bb_impl::pack_k_bits_bb_impl(unsigned k) + : gr_sync_decimator("pack_k_bits_bb", + gr_make_io_signature(1, 1, sizeof(unsigned char)), + gr_make_io_signature(1, 1, sizeof(unsigned char)), + k), + d_k(k) + { + if(d_k == 0) + throw std::out_of_range("interpolation must be > 0"); + } + + pack_k_bits_bb_impl::~pack_k_bits_bb_impl() + { + } + + int + pack_k_bits_bb_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const unsigned char *in = (const unsigned char *)input_items[0]; + unsigned char *out = (unsigned char *)output_items[0]; + + for(int i = 0; i < noutput_items; i++) { + out[i] = 0x00; + for(unsigned int j = 0; j < d_k; j++) { + out[i] |= (0x01 & in[i*d_k+j])<<(d_k-j-1); + } + } + + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.i b/gr-blocks/lib/pack_k_bits_bb_impl.h index 6ae2095ec7..668d438a46 100644 --- a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.i +++ b/gr-blocks/lib/pack_k_bits_bb_impl.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2012 Free Software Foundation, Inc. + * Copyright 2012-2013 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -20,15 +20,29 @@ * Boston, MA 02110-1301, USA. */ -GR_SWIG_BLOCK_MAGIC(gr,pack_k_bits_bb) +#ifndef INCLUDED_GR_PACK_K_BITS_BB_IMPL_H +#define INCLUDED_GR_PACK_K_BITS_BB_IMPL_H -gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb (int k) throw(std::exception); +#include <blocks/pack_k_bits_bb.h> -class gr_pack_k_bits_bb : public gr_sync_decimator -{ - private: - gr_pack_k_bits_bb (int k); +namespace gr { + namespace blocks { - public: - ~gr_pack_k_bits_bb (); -}; + class pack_k_bits_bb_impl : public pack_k_bits_bb + { + private: + unsigned d_k; // number of relevent bits to pack from k input bytes + + public: + pack_k_bits_bb_impl(unsigned k); + ~pack_k_bits_bb_impl(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_PACK_K_BITS_BB_IMPL_H */ diff --git a/gr-blocks/lib/stream_pdu_base.cc b/gr-blocks/lib/stream_pdu_base.cc new file mode 100644 index 0000000000..14e76149a0 --- /dev/null +++ b/gr-blocks/lib/stream_pdu_base.cc @@ -0,0 +1,126 @@ +/* -*- 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 + +#ifdef HAVE_IO_H +#include <io.h> +#endif + +#include <gr_pdu.h> +#include <gr_basic_block.h> +#include "stream_pdu_base.h" +#include <boost/format.hpp> + +static const long timeout_us = 100*1000; //100ms + +namespace gr { + namespace blocks { + + stream_pdu_base::stream_pdu_base(int MTU) + : d_fd(-1), + d_started(false), + d_finished(false) + { + // reserve space for rx buffer + d_rxbuf.resize(MTU,0); + } + + stream_pdu_base::~stream_pdu_base() + { + stop_rxthread(); + } + + void + stream_pdu_base::start_rxthread(gr_basic_block *blk, pmt::pmt_t port) + { + d_blk = blk; + d_port = port; + d_thread = gruel::thread(boost::bind(&stream_pdu_base::run, this)); + d_started = true; + } + + void + stream_pdu_base::stop_rxthread() + { + d_finished = true; + + if (d_started) { + d_thread.interrupt(); + d_thread.join(); + } + } + + void + stream_pdu_base::run() + { + while(!d_finished) { + if (!wait_ready()) + continue; + + const int result = read(d_fd, &d_rxbuf[0], d_rxbuf.size()); + if (result <= 0) + throw std::runtime_error("stream_pdu_base, bad socket read!"); + + pmt::pmt_t vector = pmt::init_u8vector(result, &d_rxbuf[0]); + pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector); + + d_blk->message_port_pub(d_port, pdu); + } + } + + bool + stream_pdu_base::wait_ready() + { + //setup timeval for timeout + timeval tv; + tv.tv_sec = 0; + tv.tv_usec = timeout_us; + + //setup rset for timeout + fd_set rset; + FD_ZERO(&rset); + FD_SET(d_fd, &rset); + + //call select with timeout on receive socket + return ::select(d_fd+1, &rset, NULL, NULL, &tv) > 0; + } + + void + stream_pdu_base::send(pmt::pmt_t msg) + { + pmt::pmt_t vector = pmt::cdr(msg); + size_t offset(0); + size_t itemsize(::gr_pdu_itemsize(type_from_pmt(vector))); + int len(pmt::length(vector)*itemsize); + + const int rv = write(d_fd, 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)") + % d_fd % len % rv << std::endl; + } + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/stream_pdu_base.h b/gr-blocks/lib/stream_pdu_base.h new file mode 100644 index 0000000000..66eaaf0c04 --- /dev/null +++ b/gr-blocks/lib/stream_pdu_base.h @@ -0,0 +1,60 @@ +/* -*- 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_STREAM_PDU_BASE_H +#define INCLUDED_STREAM_PDU_BASE_H + +#include <gruel/thread.h> +#include <gruel/pmt.h> + +class gr_basic_block; + +namespace gr { + namespace blocks { + + class stream_pdu_base + { + public: + stream_pdu_base(int MTU=10000); + ~stream_pdu_base(); + + protected: + int d_fd; + bool d_started; + bool d_finished; + std::vector<uint8_t> d_rxbuf; + gruel::thread d_thread; + + pmt::pmt_t d_port; + gr_basic_block *d_blk; + + void run(); + void send(pmt::pmt_t msg); + bool wait_ready(); + void start_rxthread(gr_basic_block *blk, pmt::pmt_t rxport); + void stop_rxthread(); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_STREAM_PDU_BASE_H */ diff --git a/gr-blocks/lib/tuntap_pdu_impl.cc b/gr-blocks/lib/tuntap_pdu_impl.cc new file mode 100644 index 0000000000..1970a92b69 --- /dev/null +++ b/gr-blocks/lib/tuntap_pdu_impl.cc @@ -0,0 +1,139 @@ +/* -*- 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 "tuntap_pdu_impl.h" +#include <gr_io_signature.h> +#include <gr_pdu.h> +#include <boost/format.hpp> + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#if (defined(linux) || defined(__linux) || defined(__linux__)) +#include <sys/ioctl.h> +#include <arpa/inet.h> +#include <linux/if.h> +#endif + +namespace gr { + namespace blocks { + + tuntap_pdu::sptr + tuntap_pdu::make(std::string dev, int MTU) + { +#if (defined(linux) || defined(__linux) || defined(__linux__)) + return gnuradio::get_initial_sptr(new tuntap_pdu_impl(dev, MTU)); +#else + throw std::runtime_error("tuntap_pdu not implemented on this platform"); +#endif + } + +#if (defined(linux) || defined(__linux) || defined(__linux__)) + tuntap_pdu_impl::tuntap_pdu_impl(std::string dev, int MTU) + : gr_block("tuntap_pdu", + gr_make_io_signature (0, 0, 0), + gr_make_io_signature (0, 0, 0)), + stream_pdu_base(MTU), + d_dev(dev) + { + // make the tuntap + char dev_cstr[1024]; + memset(dev_cstr, 0x00, 1024); + strncpy(dev_cstr, dev.c_str(), std::min(sizeof(dev_cstr), dev.size())); + + d_fd = tun_alloc(dev_cstr); + if (d_fd <= 0) + throw std::runtime_error("gr::tuntap_pdu::make: tun_alloc failed (are you running as root?)"); + + std::cout << boost::format( + "Allocated virtual ethernet interface: %s\n" + "You must now use ifconfig to set its IP address. E.g.,\n" + " $ sudo ifconfig %s 192.168.200.1\n" + "Be sure to use a different address in the same subnet for each machine.\n" + ) % dev % dev << std::endl; + + // set up output message port + message_port_register_out(PDU_PORT_ID); + start_rxthread(this, PDU_PORT_ID); + + // set up input message port + message_port_register_in(PDU_PORT_ID); + set_msg_handler(PDU_PORT_ID, boost::bind(&tuntap_pdu_impl::send, this, _1)); + } + + int + tuntap_pdu_impl::tun_alloc(char *dev, int flags) + { + struct ifreq ifr; + int fd, err; + const char *clonedev = "/dev/net/tun"; + + /* Arguments taken by the function: + * + * char *dev: the name of an interface (or '\0'). MUST have enough + * space to hold the interface name if '\0' is passed + * int flags: interface flags (eg, IFF_TUN etc.) + */ + + /* open the clone device */ + if ((fd = open(clonedev, O_RDWR)) < 0) + return fd; + + /* preparation of the struct ifr, of type "struct ifreq" */ + memset(&ifr, 0, sizeof(ifr)); + + ifr.ifr_flags = flags; /* IFF_TUN or IFF_TAP, plus maybe IFF_NO_PI */ + + /* if a device name was specified, put it in the structure; otherwise, + * the kernel will try to allocate the "next" device of the + * specified type + */ + if (*dev) + strncpy(ifr.ifr_name, dev, IFNAMSIZ); + + /* try to create the device */ + if ((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0) { + close(fd); + return err; + } + + /* if the operation was successful, write back the name of the + * interface to the variable "dev", so the caller can know + * it. Note that the caller MUST reserve space in *dev (see calling + * code below) + */ + strcpy(dev, ifr.ifr_name); + + /* this is the special file descriptor that the caller will use to talk + * with the virtual interface + */ + return fd; + } +#endif + + } /* namespace blocks */ +}/* namespace gr */ diff --git a/gnuradio-core/src/lib/io/gr_tuntap_pdu.i b/gr-blocks/lib/tuntap_pdu_impl.h index 589bbc3853..396d9d51c8 100644 --- a/gnuradio-core/src/lib/io/gr_tuntap_pdu.i +++ b/gr-blocks/lib/tuntap_pdu_impl.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2013 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -20,11 +20,32 @@ * Boston, MA 02110-1301, USA. */ -GR_SWIG_BLOCK_MAGIC(gr,tuntap_pdu); +#ifndef INCLUDED_BLOCKS_TUNTAP_PDU_IMPL_H +#define INCLUDED_BLOCKS_TUNTAP_PDU_IMPL_H -%{ -#include <gr_tuntap_pdu.h> -%} +#include <blocks/tuntap_pdu.h> +#include "stream_pdu_base.h" -%include "gr_tuntap_pdu.h" +#if (defined(linux) || defined(__linux) || defined(__linux__)) +#include <linux/if_tun.h> +#endif +namespace gr { + namespace blocks { + + class tuntap_pdu_impl : public tuntap_pdu, public stream_pdu_base + { +#if (defined(linux) || defined(__linux) || defined(__linux__)) + private: + std::string d_dev; + int tun_alloc(char *dev, int flags = IFF_TAP | IFF_NO_PI); + + public: + tuntap_pdu_impl(std::string dev, int MTU); +#endif + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_BLOCKS_TUNTAP_PDU_IMPL_H */ diff --git a/gr-blocks/lib/unpack_k_bits_bb_impl.cc b/gr-blocks/lib/unpack_k_bits_bb_impl.cc new file mode 100644 index 0000000000..367100be84 --- /dev/null +++ b/gr-blocks/lib/unpack_k_bits_bb_impl.cc @@ -0,0 +1,77 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2010,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. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include "unpack_k_bits_bb_impl.h" +#include <gr_io_signature.h> +#include <stdexcept> +#include <iostream> + +namespace gr { + namespace blocks { + + unpack_k_bits_bb::sptr + unpack_k_bits_bb::make(unsigned k) + { + return gnuradio::get_initial_sptr + (new unpack_k_bits_bb_impl(k)); + } + + unpack_k_bits_bb_impl::unpack_k_bits_bb_impl(unsigned k) + : gr_sync_interpolator("unpack_k_bits_bb", + gr_make_io_signature(1, 1, sizeof(unsigned char)), + gr_make_io_signature(1, 1, sizeof(unsigned char)), + k), + d_k(k) + { + if(d_k == 0) + throw std::out_of_range("interpolation must be > 0"); + } + + unpack_k_bits_bb_impl::~unpack_k_bits_bb_impl() + { + } + + int + unpack_k_bits_bb_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const unsigned char *in = (const unsigned char *)input_items[0]; + unsigned char *out = (unsigned char *)output_items[0]; + + int n = 0; + for(unsigned int i = 0; i < noutput_items/d_k; i++) { + unsigned int t = in[i]; + for(int j = d_k - 1; j >= 0; j--) + out[n++] = (t >> j) & 0x01; + } + + assert(n == noutput_items); + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gnuradio-core/src/lib/general/gr_unpack_k_bits_bb.i b/gr-blocks/lib/unpack_k_bits_bb_impl.h index de0f4b33e7..c72d16ebf8 100644 --- a/gnuradio-core/src/lib/general/gr_unpack_k_bits_bb.i +++ b/gr-blocks/lib/unpack_k_bits_bb_impl.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2013 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -20,15 +20,29 @@ * Boston, MA 02110-1301, USA. */ -GR_SWIG_BLOCK_MAGIC(gr,unpack_k_bits_bb) +#ifndef INCLUDED_GR_UNPACK_K_BITS_BB_IMPL_H +#define INCLUDED_GR_UNPACK_K_BITS_BB_IMPL_H -gr_unpack_k_bits_bb_sptr gr_make_unpack_k_bits_bb (int k) throw(std::exception); +#include <blocks/unpack_k_bits_bb.h> -class gr_unpack_k_bits_bb : public gr_sync_interpolator -{ - private: - gr_unpack_k_bits_bb (int k); +namespace gr { + namespace blocks { - public: - ~gr_unpack_k_bits_bb (); -}; + class unpack_k_bits_bb_impl : public unpack_k_bits_bb + { + private: + unsigned d_k; // number of relevent bits to unpack into k output bytes + + public: + unpack_k_bits_bb_impl(unsigned k); + ~unpack_k_bits_bb_impl(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_UNPACK_K_BITS_BB_IMPL_H */ diff --git a/gr-blocks/python/qa_file_metadata.py b/gr-blocks/python/qa_file_metadata.py index 69974d6dad..c2319a800e 100644 --- a/gr-blocks/python/qa_file_metadata.py +++ b/gr-blocks/python/qa_file_metadata.py @@ -35,6 +35,7 @@ def sig_source_c(samp_rate, freq, amp, N): class test_file_metadata(gr_unittest.TestCase): def setUp(self): + os.environ['GR_CONF_CONTROLPORT_ON'] = 'False' self.tb = gr.top_block() def tearDown(self): diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_pack_k_bits.py b/gr-blocks/python/qa_pack_k_bits.py index 25fc5e9fcc..cd55d2f200 100755 --- a/gnuradio-core/src/python/gnuradio/gr/qa_pack_k_bits.py +++ b/gr-blocks/python/qa_pack_k_bits.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2006,2010 Free Software Foundation, Inc. +# Copyright 2006,2010,2013 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -21,12 +21,13 @@ # from gnuradio import gr, gr_unittest +import blocks_swig as blocks import random class test_pack(gr_unittest.TestCase): def setUp(self): - self.tb = gr.top_block () + self.tb = gr.top_block() def tearDown(self): self.tb = None @@ -35,7 +36,7 @@ class test_pack(gr_unittest.TestCase): src_data = (1,0,1,1,0,1,1,0) expected_results = (1,0,1,1,0,1,1,0) src = gr.vector_source_b(src_data,False) - op = gr.pack_k_bits_bb(1) + op = blocks.pack_k_bits_bb(1) dst = gr.vector_sink_b() self.tb.connect(src, op, dst) self.tb.run() @@ -45,7 +46,7 @@ class test_pack(gr_unittest.TestCase): src_data = (1,0,1,1,0,0,0,1) expected_results = ( 2, 3, 0, 1) src = gr.vector_source_b(src_data,False) - op = gr.pack_k_bits_bb(2) + op = blocks.pack_k_bits_bb(2) dst = gr.vector_sink_b() self.tb.connect(src, op, dst) self.tb.run() @@ -55,8 +56,8 @@ class test_pack(gr_unittest.TestCase): def test_003(self): src_data = expected_results = map(lambda x: random.randint(0,3), range(10)); src = gr.vector_source_b( src_data ); - pack = gr.pack_k_bits_bb(2); - unpack = gr.unpack_k_bits_bb(2); + pack = blocks.pack_k_bits_bb(2); + unpack = blocks.unpack_k_bits_bb(2); snk = gr.vector_sink_b(); self.tb.connect(src,unpack,pack,snk); self.tb.run() diff --git a/gr-blocks/python/qa_stream_mux.py b/gr-blocks/python/qa_stream_mux.py index f21a9bbbc9..657bd3d63f 100755 --- a/gr-blocks/python/qa_stream_mux.py +++ b/gr-blocks/python/qa_stream_mux.py @@ -22,10 +22,12 @@ from gnuradio import gr, gr_unittest import blocks_swig +import os class test_stream_mux (gr_unittest.TestCase): def setUp (self): + os.environ['GR_CONF_CONTROLPORT_ON'] = 'False' self.tb = gr.top_block () def tearDown (self): diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_unpack_k_bits.py b/gr-blocks/python/qa_unpack_k_bits.py index bb4e7733d4..e038d5a03a 100755 --- a/gnuradio-core/src/python/gnuradio/gr/qa_unpack_k_bits.py +++ b/gr-blocks/python/qa_unpack_k_bits.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2006,2010 Free Software Foundation, Inc. +# Copyright 2006,2010,2013 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -21,6 +21,7 @@ # from gnuradio import gr, gr_unittest +import blocks_swig as blocks import random class test_unpack(gr_unittest.TestCase): @@ -35,7 +36,7 @@ class test_unpack(gr_unittest.TestCase): src_data = (1,0,1,1,0,1,1,0) expected_results = (1,0,1,1,0,1,1,0) src = gr.vector_source_b(src_data,False) - op = gr.unpack_k_bits_bb(1) + op = blocks.unpack_k_bits_bb(1) dst = gr.vector_sink_b() self.tb.connect(src, op, dst) self.tb.run() @@ -45,13 +46,12 @@ class test_unpack(gr_unittest.TestCase): src_data = ( 2, 3, 0, 1) expected_results = (1,0,1,1,0,0,0,1) src = gr.vector_source_b(src_data,False) - op = gr.unpack_k_bits_bb(2) + op = blocks.unpack_k_bits_bb(2) dst = gr.vector_sink_b() self.tb.connect(src, op, dst) self.tb.run() self.assertEqual(expected_results, dst.data()) - if __name__ == '__main__': gr_unittest.run(test_unpack, "test_unpack.xml") diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i index db8af34368..bd57da5348 100644 --- a/gr-blocks/swig/blocks_swig.i +++ b/gr-blocks/swig/blocks_swig.i @@ -99,6 +99,7 @@ #include "blocks/not_ss.h" #include "blocks/not_ii.h" #include "blocks/patterned_interleaver.h" +#include "blocks/pack_k_bits_bb.h" #include "blocks/packed_to_unpacked_bb.h" #include "blocks/packed_to_unpacked_ss.h" #include "blocks/packed_to_unpacked_ii.h" @@ -125,7 +126,9 @@ #include "blocks/threshold_ff.h" #include "blocks/throttle.h" #include "blocks/transcendental.h" +#include "blocks/tuntap_pdu.h" #include "blocks/uchar_to_float.h" +#include "blocks/unpack_k_bits_bb.h" #include "blocks/unpacked_to_packed_bb.h" #include "blocks/unpacked_to_packed_ss.h" #include "blocks/unpacked_to_packed_ii.h" @@ -204,14 +207,15 @@ %include "blocks/not_bb.h" %include "blocks/not_ss.h" %include "blocks/not_ii.h" -%include "blocks/patterned_interleaver.h" +%include "blocks/or_bb.h" +%include "blocks/or_ss.h" +%include "blocks/or_ii.h" +%include "blocks/pack_k_bits_bb.h" %include "blocks/packed_to_unpacked_bb.h" %include "blocks/packed_to_unpacked_ss.h" %include "blocks/packed_to_unpacked_ii.h" +%include "blocks/patterned_interleaver.h" %include "blocks/peak_detector2_fb.h" -%include "blocks/or_bb.h" -%include "blocks/or_ss.h" -%include "blocks/or_ii.h" %include "blocks/regenerate_bb.h" %include "blocks/repeat.h" %include "blocks/rms_cf.h" @@ -231,7 +235,9 @@ %include "blocks/threshold_ff.h" %include "blocks/throttle.h" %include "blocks/transcendental.h" +%include "blocks/tuntap_pdu.h" %include "blocks/uchar_to_float.h" +%include "blocks/unpack_k_bits_bb.h" %include "blocks/unpacked_to_packed_bb.h" %include "blocks/unpacked_to_packed_ss.h" %include "blocks/unpacked_to_packed_ii.h" @@ -310,6 +316,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, not_bb); GR_SWIG_BLOCK_MAGIC2(blocks, not_ss); GR_SWIG_BLOCK_MAGIC2(blocks, not_ii); GR_SWIG_BLOCK_MAGIC2(blocks, patterned_interleaver); +GR_SWIG_BLOCK_MAGIC2(blocks, pack_k_bits_bb); GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_bb); GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_ss); GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_ii); @@ -336,7 +343,9 @@ GR_SWIG_BLOCK_MAGIC2(blocks, sub_cc); GR_SWIG_BLOCK_MAGIC2(blocks, threshold_ff); GR_SWIG_BLOCK_MAGIC2(blocks, throttle); GR_SWIG_BLOCK_MAGIC2(blocks, transcendental); +GR_SWIG_BLOCK_MAGIC2(blocks, tuntap_pdu); GR_SWIG_BLOCK_MAGIC2(blocks, uchar_to_float); +GR_SWIG_BLOCK_MAGIC2(blocks, unpack_k_bits_bb); GR_SWIG_BLOCK_MAGIC2(blocks, unpacked_to_packed_bb); GR_SWIG_BLOCK_MAGIC2(blocks, unpacked_to_packed_ss); GR_SWIG_BLOCK_MAGIC2(blocks, unpacked_to_packed_ii); diff --git a/gr-digital/examples/berawgn.py b/gr-digital/examples/berawgn.py index b20b17fd39..6f9679d555 100755 --- a/gr-digital/examples/berawgn.py +++ b/gr-digital/examples/berawgn.py @@ -77,7 +77,7 @@ class BitErrors(gr.hier_block2): intdump_decim = int(N_BITS) self.connect(self, comp, - gr.unpack_k_bits_bb(bits_per_byte), + blocks.unpack_k_bits_bb(bits_per_byte), blocks.uchar_to_float(), blocks.integrate_ff(intdump_decim), blocks.multiply_const_ff(1.0/N_BITS), diff --git a/gr-digital/python/generic_mod_demod.py b/gr-digital/python/generic_mod_demod.py index a5d1d9eb37..bc00646ccc 100644 --- a/gr-digital/python/generic_mod_demod.py +++ b/gr-digital/python/generic_mod_demod.py @@ -303,7 +303,7 @@ class generic_demod(gr.hier_block2): mod_codes.invert_code(self._constellation.pre_diff_code())) # unpack the k bit vector into a stream of bits - self.unpack = gr.unpack_k_bits_bb(self.bits_per_symbol()) + self.unpack = blocks.unpack_k_bits_bb(self.bits_per_symbol()) if verbose: self._print_verbage() @@ -312,14 +312,14 @@ class generic_demod(gr.hier_block2): self._setup_logging() # Connect and Initialize base class - blocks = [self, self.agc, self.freq_recov, - self.time_recov, self.receiver] + self._blocks = [self, self.agc, self.freq_recov, + self.time_recov, self.receiver] if differential: - blocks.append(self.diffdec) + self._blocks.append(self.diffdec) if self.pre_diff_code: - blocks.append(self.symbol_mapper) - blocks += [self.unpack, self] - self.connect(*blocks) + self._blocks.append(self.symbol_mapper) + self._blocks += [self.unpack, self] + self.connect(*self._blocks) def samples_per_symbol(self): return self._samples_per_symbol diff --git a/gr-digital/python/qa_constellation.py b/gr-digital/python/qa_constellation.py index 12dbca232f..37112f70a3 100755 --- a/gr-digital/python/qa_constellation.py +++ b/gr-digital/python/qa_constellation.py @@ -206,7 +206,7 @@ class mod_demod(gr.hier_block2): self.blocks.append(digital.map_bb( mod_codes.invert_code(self.constellation.pre_diff_code()))) # unpack the k bit vector into a stream of bits - self.blocks.append(gr.unpack_k_bits_bb( + self.blocks.append(blocks.unpack_k_bits_bb( self.constellation.bits_per_symbol())) # connect to block output check_index = len(self.blocks) diff --git a/grc/blocks/block_tree.xml b/grc/blocks/block_tree.xml index a78184dff1..4567a65781 100644 --- a/grc/blocks/block_tree.xml +++ b/grc/blocks/block_tree.xml @@ -39,7 +39,6 @@ <block>gr_message_strobe</block> <block>gr_pdu_to_tagged_stream</block> <block>gr_tagged_stream_to_pdu</block> - <block>gr_tuntap_pdu</block> <block>gr_socket_pdu</block> <block>gr_random_pdu</block> </cat> @@ -69,11 +68,6 @@ <block>gr_burst_tagger</block> </cat> <cat> - <name>Misc Conversions</name> - <block>gr_unpack_k_bits_bb</block> - <block>gr_pack_k_bits_bb</block> - </cat> - <cat> <name>Synchronizers</name> <block>gr_mpsk_sync_cc</block> diff --git a/grc/blocks/gr_tuntap_pdu.xml b/grc/blocks/gr_tuntap_pdu.xml deleted file mode 100644 index f169345afa..0000000000 --- a/grc/blocks/gr_tuntap_pdu.xml +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -## Tuntap PDU Message source/sink -################################################### - --> -<block> - <name>TunTap PDU</name> - <key>gr_tuntap_pdu</key> - <import>from gnuradio import gr</import> - <make>gr.tuntap_pdu($ifn, $mtu)</make> - <param> - <name>Interface Name</name> - <key>ifn</key> - <value>tun0</value> - <type>string</type> - </param> - <param> - <name>MTU</name> - <key>mtu</key> - <value>10000</value> - <type>int</type> - </param> - <sink> - <name>pdus</name> - <type>message</type> - <optional>1</optional> - </sink> - <source> - <name>pdus</name> - <type>message</type> - <optional>1</optional> - </source> -</block> |