diff options
27 files changed, 0 insertions, 1683 deletions
diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index b844cf302c..12e0bf0346 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -164,7 +164,6 @@ set(gr_core_general_triple_threats gr_null_source gr_pa_2x2_phase_combiner gr_prefs - gr_random_pdu gr_remez gr_skiphead gr_test diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index ff4c95631b..04d524ee5c 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -38,7 +38,6 @@ //#include <gr_endianness.h> #include <gr_endian_swap.h> #include <gr_firdes.h> -#include <gr_random_pdu.h> #include <gr_fake_channel_coder_pp.h> #include <gr_vco_f.h> #include <gr_pa_2x2_phase_combiner.h> @@ -76,7 +75,6 @@ //%include "gr_endianness.i" %include "gr_endian_swap.i" %include "gr_firdes.i" -%include "gr_random_pdu.i" %include "gr_fake_channel_coder_pp.i" %include "gr_vco_f.i" %include "gr_pa_2x2_phase_combiner.i" diff --git a/gnuradio-core/src/lib/general/gr_random_pdu.cc b/gnuradio-core/src/lib/general/gr_random_pdu.cc deleted file mode 100644 index 746f8944a2..0000000000 --- a/gnuradio-core/src/lib/general/gr_random_pdu.cc +++ /dev/null @@ -1,85 +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_random_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 <vector> - -// public constructor that returns a shared_ptr - -gr_random_pdu_sptr -gr_make_random_pdu (int items_min, int items_max) -{ - return gnuradio::get_initial_sptr(new gr_random_pdu(items_min, items_max)); -} - -gr_random_pdu::gr_random_pdu (int items_min, int items_max) - : gr_block("random_pdu", - gr_make_io_signature(0, 0, 0), - gr_make_io_signature(0, 0, 0)), - urange(items_min, items_max), - brange(0, 255), - rvar(rng, urange), - bvar(rng, brange) -{ - message_port_register_out(pmt::mp("pdus")); - message_port_register_in(pmt::mp("generate")); - set_msg_handler(pmt::mp("generate"), boost::bind(&gr_random_pdu::generate_pdu, this, _1)); -} - -bool gr_random_pdu::start(){ - output_random(); - return true; -} - -void gr_random_pdu::output_random(){ - - // pick a random vector length - int len = rvar(); - - // fill it with random bytes - std::vector<unsigned char> vec; - for(int i=0; i<len; i++){ - vec.push_back((unsigned char) bvar()); - } - - // send the vector - pmt::pmt_t vecpmt( pmt::make_blob( &vec[0], len ) ); - pmt::pmt_t pdu( pmt::cons( pmt::PMT_NIL, vecpmt ) ); - - message_port_pub( pmt::mp("pdus"), pdu ); - - std::cout << "sending new random vector of length " << len << "\n"; -} - diff --git a/gnuradio-core/src/lib/general/gr_random_pdu.h b/gnuradio-core/src/lib/general/gr_random_pdu.h deleted file mode 100644 index e6457d21b6..0000000000 --- a/gnuradio-core/src/lib/general/gr_random_pdu.h +++ /dev/null @@ -1,64 +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_RANDOM_PDU_H -#define INCLUDED_GR_RANDOM_PDU_H - -#include <gr_core_api.h> -#include <gr_block.h> -#include <gr_message.h> -#include <gr_msg_queue.h> - -#include <boost/random.hpp> -#include <boost/generator_iterator.hpp> - -class gr_random_pdu; -typedef boost::shared_ptr<gr_random_pdu> gr_random_pdu_sptr; - -GR_CORE_API gr_random_pdu_sptr gr_make_random_pdu (int mintime, int maxtime); - -/*! - * \brief Send message at defined interval - * \ingroup msg_blk - */ -class GR_CORE_API gr_random_pdu : public gr_block -{ - private: - friend GR_CORE_API gr_random_pdu_sptr - gr_make_random_pdu(int mintime, int maxtime); - - void output_random(); - - boost::mt19937 rng; - boost::uniform_int<> urange; - boost::uniform_int<> brange; - boost::variate_generator< boost::mt19937, boost::uniform_int<> > rvar; // pdu length - boost::variate_generator< boost::mt19937, boost::uniform_int<> > bvar; // pdu contents - - public: - gr_random_pdu (int, int); - bool start(); - void generate_pdu(pmt::pmt_t msg){ output_random(); } - void generate_pdu(){ output_random(); } -}; - -#endif /* INCLUDED_GR_RANDOM_PDU_H */ diff --git a/gnuradio-core/src/lib/general/gr_random_pdu.i b/gnuradio-core/src/lib/general/gr_random_pdu.i deleted file mode 100644 index 045a330605..0000000000 --- a/gnuradio-core/src/lib/general/gr_random_pdu.i +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2005 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. - */ - -GR_SWIG_BLOCK_MAGIC(gr,random_pdu); - -%{ -#include <gr_random_pdu.h> -%} - -%include "gr_random_pdu.h" - diff --git a/gnuradio-core/src/lib/io/CMakeLists.txt b/gnuradio-core/src/lib/io/CMakeLists.txt index 23c019d63b..7368283dab 100644 --- a/gnuradio-core/src/lib/io/CMakeLists.txt +++ b/gnuradio-core/src/lib/io/CMakeLists.txt @@ -38,8 +38,6 @@ list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/microtune_xxxx.cc ${CMAKE_CURRENT_SOURCE_DIR}/ppio_ppdev.cc ${CMAKE_CURRENT_SOURCE_DIR}/gri_wavfile.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_pdu.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gr_stream_pdu_base.cc ) ######################################################################## @@ -61,8 +59,6 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/microtune_xxxx.h ${CMAKE_CURRENT_SOURCE_DIR}/ppio_ppdev.h ${CMAKE_CURRENT_SOURCE_DIR}/gri_wavfile.h - ${CMAKE_CURRENT_SOURCE_DIR}/gr_pdu.h - ${CMAKE_CURRENT_SOURCE_DIR}/gr_stream_pdu_base.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio COMPONENT "core_devel" ) @@ -93,7 +89,6 @@ set(gr_core_io_triple_threats gr_message_sink gr_message_source gr_message_burst_source - gr_pdu_to_tagged_stream microtune_xxxx_eval_board microtune_4702_eval_board microtune_4937_eval_board @@ -104,8 +99,6 @@ set(gr_core_io_triple_threats gr_wavfile_source gr_wavfile_sink gr_tagged_file_sink - gr_tagged_stream_to_pdu - gr_socket_pdu ) foreach(file_tt ${gr_core_io_triple_threats}) diff --git a/gnuradio-core/src/lib/io/gr_pdu.cc b/gnuradio-core/src/lib/io/gr_pdu.cc deleted file mode 100644 index fe5d9f690f..0000000000 --- a/gnuradio-core/src/lib/io/gr_pdu.cc +++ /dev/null @@ -1,79 +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_pdu.h> - -size_t -gr_pdu_itemsize(gr_pdu_vector_type type){ - switch(type){ - case pdu_byte: - return 1; - case pdu_float: - return sizeof(float); - case pdu_complex: - return sizeof(gr_complex); - default: - throw std::runtime_error("bad type!"); - } -} - -bool -gr_pdu_type_matches(gr_pdu_vector_type type, pmt::pmt_t v){ - switch(type){ - case pdu_byte: - return pmt::is_u8vector(v); - case pdu_float: - return pmt::is_f32vector(v); - case pdu_complex: - return pmt::is_c32vector(v); - default: - throw std::runtime_error("bad type!"); - } -} - -pmt::pmt_t -gr_pdu_make_vector(gr_pdu_vector_type type, const uint8_t* buf, size_t items){ - switch(type){ - case pdu_byte: - return pmt::init_u8vector(items, buf); - case pdu_float: - return pmt::init_f32vector(items, (const float*)buf); - case pdu_complex: - return pmt::init_c32vector(items, (const gr_complex*)buf); - default: - throw std::runtime_error("bad type!"); - } -} - -gr_pdu_vector_type type_from_pmt(pmt::pmt_t vector){ - if(is_u8vector(vector)) - return pdu_byte; - if(is_f32vector(vector)) - return pdu_float; - if(is_c32vector(vector)) - return pdu_complex; - throw std::runtime_error("bad type!"); -} diff --git a/gnuradio-core/src/lib/io/gr_pdu.h b/gnuradio-core/src/lib/io/gr_pdu.h deleted file mode 100644 index 53058ccb6c..0000000000 --- a/gnuradio-core/src/lib/io/gr_pdu.h +++ /dev/null @@ -1,40 +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 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") - -enum gr_pdu_vector_type { pdu_byte, pdu_float, pdu_complex }; - -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.i b/gnuradio-core/src/lib/io/gr_pdu.i deleted file mode 100644 index ada3a63a73..0000000000 --- a/gnuradio-core/src/lib/io/gr_pdu.i +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- c++ -*- */
-/*
- * Copyright 2005 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.
- */
-
-%{
-#include <gr_pdu.h>
-%}
-
-enum gr_pdu_vector_type { pdu_byte, pdu_float, pdu_complex };
-
-
-
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 deleted file mode 100644 index 79011d8536..0000000000 --- a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc +++ /dev/null @@ -1,132 +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_pdu_to_tagged_stream.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> - - -// public constructor that returns a shared_ptr - -gr_pdu_to_tagged_stream_sptr -gr_make_pdu_to_tagged_stream(gr_pdu_vector_type t) -{ - return gnuradio::get_initial_sptr(new gr_pdu_to_tagged_stream(t)); -} - -gr_pdu_to_tagged_stream::gr_pdu_to_tagged_stream (gr_pdu_vector_type t) - : gr_sync_block("pdu_to_tagged_stream", - gr_make_io_signature(0, 0, 0), - 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); -} - -gr_pdu_to_tagged_stream::~gr_pdu_to_tagged_stream() -{ -} - -int -gr_pdu_to_tagged_stream::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - char *out = (char *) output_items[0]; - int nout = 0; - - // if we have remaining output, send it - if(d_remain.size() > 0){ - nout = std::min((size_t)d_remain.size()/d_itemsize, (size_t)noutput_items); - memcpy(out, &d_remain[0], nout*d_itemsize); - d_remain.erase( d_remain.begin(), d_remain.begin()+nout); - noutput_items -= nout; - out += nout*d_itemsize; - } - - // if we have space for at least one item output as much as we can - 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 ) ); - if(msg.get() == NULL ){ - return nout; - } - - // make sure type is valid - if(!pmt::is_pair(msg)){ - throw std::runtime_error("received a malformed pdu message!"); - } - -// printf("got a msg\n"); -// pmt::print(msg); - - // grab the components of the pdu message - pmt::pmt_t meta(pmt::car(msg)); // make sure this is NIL || Dict ? - pmt::pmt_t vect(pmt::cdr(msg)); // make sure this is a vector? - - // compute offset for output tag - 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())); - - // if we recieved metadata add it as tags - if( !eq(meta, pmt::PMT_NIL) ){ - pmt::pmt_t pair(pmt::dict_keys( meta )); - while( !eq(pair, pmt::PMT_NIL) ){ - pmt::pmt_t k(pmt::cdr(pair)); - pmt::pmt_t v(pmt::dict_ref(meta, k, pmt::PMT_NIL)); - add_item_tag(0, offset, k, v, pmt::mp(alias())); - } - } - - // copy vector output - size_t ncopy = std::min((size_t)noutput_items, (size_t)pmt::length(vect)); - size_t nsave = pmt::length(vect) - ncopy; - - // copy output - size_t io(0); - nout += ncopy; - memcpy(out, uniform_vector_elements(vect,io), ncopy*d_itemsize); - - // save leftover items if needed for next work call - if(nsave > 0){ - d_remain.resize(nsave*d_itemsize, 0); - memcpy(&d_remain[0], uniform_vector_elements(vect,ncopy), nsave*d_itemsize); - } - - } - - return nout; -} diff --git a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.h b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.h deleted file mode 100644 index 3105a3d386..0000000000 --- a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.h +++ /dev/null @@ -1,63 +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_PDU_TO_TAGGED_STREAM_H -#define INCLUDED_GR_PDU_TO_TAGGED_STREAM_H - -#include <gr_core_api.h> -#include <gr_sync_block.h> -#include <gr_message.h> -#include <gr_msg_queue.h> -#include <gr_pdu.h> - -class gr_pdu_to_tagged_stream; -typedef boost::shared_ptr<gr_pdu_to_tagged_stream> gr_pdu_to_tagged_stream_sptr; - -GR_CORE_API gr_pdu_to_tagged_stream_sptr gr_make_pdu_to_tagged_stream (gr_pdu_vector_type t); - -/*! - * \brief Turn received messages into a stream - * \ingroup source_blk - */ -class GR_CORE_API gr_pdu_to_tagged_stream : public gr_sync_block -{ - private: - gr_pdu_vector_type d_vectortype; - size_t d_itemsize; - std::vector<uint8_t> d_remain; - - friend GR_CORE_API gr_pdu_to_tagged_stream_sptr - gr_make_pdu_to_tagged_stream(gr_pdu_vector_type t); - - protected: - gr_pdu_to_tagged_stream (gr_pdu_vector_type t); - - public: - ~gr_pdu_to_tagged_stream (); - - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - -}; - -#endif /* INCLUDED_GR_PDU_TO_TAGGED_SOURCE_H */ diff --git a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.i b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.i deleted file mode 100644 index ec760b309a..0000000000 --- a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.i +++ /dev/null @@ -1,31 +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. - */ - -GR_SWIG_BLOCK_MAGIC(gr,pdu_to_tagged_stream); - -%{ -#include <gr_pdu_to_tagged_stream.h> -%} - -%include <gr_pdu_to_tagged_stream.h> - - diff --git a/gnuradio-core/src/lib/io/gr_socket_pdu.cc b/gnuradio-core/src/lib/io/gr_socket_pdu.cc deleted file mode 100644 index 366ca507bc..0000000000 --- a/gnuradio-core/src/lib/io/gr_socket_pdu.cc +++ /dev/null @@ -1,157 +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_socket_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> - -// public constructor that returns a shared_ptr -gr_socket_pdu_sptr -gr_make_socket_pdu (std::string type, std::string addr, std::string port, int MTU) -{ - return gnuradio::get_initial_sptr(new gr_socket_pdu(type,addr,port,MTU)); -} - -gr_socket_pdu::gr_socket_pdu (std::string type, std::string addr, std::string port, int MTU) - : gr_stream_pdu_base(MTU) -{ - - if( (type == "TCP_SERVER") || (type == "TCP_CLIENT")){ - boost::asio::ip::tcp::resolver resolver(_io_service); - boost::asio::ip::tcp::resolver::query query(boost::asio::ip::tcp::v4(), addr, port); - _tcp_endpoint = *resolver.resolve(query); - } - if( (type == "UDP_SERVER") || (type == "UDP_CLIENT")){ - boost::asio::ip::udp::resolver resolver(_io_service); - boost::asio::ip::udp::resolver::query query(boost::asio::ip::udp::v4(), addr, port); - if( (type == "UDP_SERVER") ){ - _udp_endpoint = *resolver.resolve(query); - } else { - _udp_endpoint_other = *resolver.resolve(query); - } - } - - // register ports - message_port_register_out(pmt::mp("pdus")); - message_port_register_in(pmt::mp("pdus")); - - // set up socketry - if (type == "TCP_SERVER"){ - _acceptor_tcp.reset(new boost::asio::ip::tcp::acceptor(_io_service, _tcp_endpoint)); - _acceptor_tcp->set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); - start_tcp_accept(); - // bind tcp server send handler - set_msg_handler(pmt::mp("pdus"), boost::bind(&gr_socket_pdu::tcp_server_send, this, _1)); - } else if(type =="TCP_CLIENT"){ - boost::system::error_code error = boost::asio::error::host_not_found; - _tcp_socket.reset(new boost::asio::ip::tcp::socket(_io_service)); - _tcp_socket->connect(_tcp_endpoint, error); - if(error){ - throw boost::system::system_error(error); - } - set_msg_handler(pmt::mp("pdus"), boost::bind(&gr_socket_pdu::tcp_client_send, this, _1)); - _tcp_socket->async_read_some( - boost::asio::buffer(rxbuf), - boost::bind(&gr_socket_pdu::handle_tcp_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); - - } else if(type =="UDP_SERVER"){ - _udp_socket.reset(new boost::asio::ip::udp::socket(_io_service, _udp_endpoint)); - _udp_socket->async_receive_from( boost::asio::buffer(rxbuf), _udp_endpoint_other, - boost::bind(&gr_socket_pdu::handle_udp_read, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); - set_msg_handler(pmt::mp("pdus"), boost::bind(&gr_socket_pdu::udp_send, this, _1)); - } else if(type =="UDP_CLIENT"){ - _udp_socket.reset(new boost::asio::ip::udp::socket(_io_service, _udp_endpoint)); - _udp_socket->async_receive_from( boost::asio::buffer(rxbuf), _udp_endpoint_other, - boost::bind(&gr_socket_pdu::handle_udp_read, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); - set_msg_handler(pmt::mp("pdus"), boost::bind(&gr_socket_pdu::udp_send, this, _1)); - } else { - throw std::runtime_error("unknown socket type!"); - } - - // start thread for io_service - d_thread = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&gr_socket_pdu::run_io_service, this))); - d_started = true; -} - -void tcp_connection::handle_read(const boost::system::error_code& error/*error*/, size_t bytes_transferred) - { - if(!error) - { - pmt::pmt_t vector = pmt::init_u8vector(bytes_transferred, (const uint8_t*)&buf[0]); - pmt::pmt_t pdu = pmt::cons( pmt::PMT_NIL, vector); - - d_block->message_port_pub( pmt::mp("pdus"), pdu ); - - socket_.async_read_some( - boost::asio::buffer(buf), - boost::bind(&tcp_connection::handle_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); - - } else { - std::cout << "error occurred\n"; - } - - } - - -void gr_socket_pdu::tcp_server_send(pmt::pmt_t msg){ - pmt::pmt_t vector = pmt::cdr(msg); - for(size_t i=0; i<d_tcp_connections.size(); i++){ - d_tcp_connections[i]->send(vector); - } -} - -void gr_socket_pdu::tcp_client_send(pmt::pmt_t msg){ - pmt::pmt_t vector = pmt::cdr(msg); - size_t len = pmt::length(vector); - size_t offset(0); - boost::array<char, 10000> txbuf; - memcpy(&txbuf[0], pmt::uniform_vector_elements(vector, offset), len); - _tcp_socket->send(boost::asio::buffer(txbuf,len)); -} - -void gr_socket_pdu::udp_send(pmt::pmt_t msg){ - pmt::pmt_t vector = pmt::cdr(msg); - size_t len = pmt::length(vector); - size_t offset(0); - boost::array<char, 10000> txbuf; - memcpy(&txbuf[0], pmt::uniform_vector_elements(vector, offset), len); - if(_udp_endpoint_other.address().to_string() != "0.0.0.0") - _udp_socket->send_to(boost::asio::buffer(txbuf,len), _udp_endpoint_other); -} diff --git a/gnuradio-core/src/lib/io/gr_socket_pdu.h b/gnuradio-core/src/lib/io/gr_socket_pdu.h deleted file mode 100644 index 0940e3eb83..0000000000 --- a/gnuradio-core/src/lib/io/gr_socket_pdu.h +++ /dev/null @@ -1,203 +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_SOCKET_PDU_H -#define INCLUDED_GR_SOCKET_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> -#include <boost/array.hpp> -#include <boost/asio.hpp> -#include <iostream> - -class gr_socket_pdu; -typedef boost::shared_ptr<gr_socket_pdu> gr_socket_pdu_sptr; - -GR_CORE_API gr_socket_pdu_sptr gr_make_socket_pdu (std::string type, std::string addr, std::string port, int MTU=10000); - -class tcp_connection - : public boost::enable_shared_from_this<tcp_connection> -{ -public: - typedef boost::shared_ptr<tcp_connection> pointer; - gr_socket_pdu *d_block; - boost::array<char, 10000> buf; - - static pointer create(boost::asio::io_service& io_service) - { - return pointer(new tcp_connection(io_service)); - } - - boost::asio::ip::tcp::socket& socket() - { - return socket_; - } - - void start(gr_socket_pdu* parent) - { - d_block = parent; -// message_ = "connected to gr_socket_pdu\n"; -// boost::asio::async_write(socket_, boost::asio::buffer(message_), -// boost::bind(&tcp_connection::handle_write, shared_from_this(), -// boost::asio::placeholders::error, -// boost::asio::placeholders::bytes_transferred)); - - socket_.async_read_some( - boost::asio::buffer(buf), - boost::bind(&tcp_connection::handle_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); - } - void send(pmt::pmt_t vector){ - size_t len = pmt::length(vector); - size_t offset(0); - boost::array<char, 10000> txbuf; - memcpy(&txbuf[0], pmt::uniform_vector_elements(vector, offset), len); - boost::asio::async_write(socket_, boost::asio::buffer(txbuf, len), - boost::bind(&tcp_connection::handle_write, shared_from_this(), - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); - } - - ~tcp_connection(){ -// std::cout << "tcp_connection destroyed\n"; - } - -private: - tcp_connection(boost::asio::io_service& io_service) - : socket_(io_service) - { - } - - void handle_read(const boost::system::error_code& error/*error*/, size_t bytes_transferred); - - void handle_write(const boost::system::error_code& /*error*/, - size_t /*bytes_transferred*/) - { - } - - boost::asio::ip::tcp::socket socket_; - std::string message_; -}; - - -/*! - * \brief Gather received items into messages and insert into msgq - * \ingroup sink_blk - */ -class GR_CORE_API gr_socket_pdu : public gr_stream_pdu_base -{ - private: - friend GR_CORE_API gr_socket_pdu_sptr - gr_make_socket_pdu(std::string type, std::string addr, std::string port, int MTU); - - boost::asio::io_service _io_service; - - boost::array<char, 10000> rxbuf; - - // tcp specific - boost::asio::ip::tcp::endpoint _tcp_endpoint; - - // specific to tcp server - boost::shared_ptr<boost::asio::ip::tcp::acceptor> _acceptor_tcp; - std::vector<tcp_connection::pointer> d_tcp_connections; - void tcp_server_send(pmt::pmt_t msg); - void tcp_client_send(pmt::pmt_t msg); - void udp_send(pmt::pmt_t msg); - - // specific to tcp client - boost::shared_ptr<boost::asio::ip::tcp::socket> _tcp_socket; - - // specific to udp client/server - boost::asio::ip::udp::endpoint _udp_endpoint; - boost::asio::ip::udp::endpoint _udp_endpoint_other; - boost::shared_ptr<boost::asio::ip::udp::socket> _udp_socket; - - void handle_receive(const boost::system::error_code& error, std::size_t ){ - } - - void start_tcp_accept(){ - tcp_connection::pointer new_connection = - tcp_connection::create(_acceptor_tcp->get_io_service()); - - _acceptor_tcp->async_accept(new_connection->socket(), - boost::bind(&gr_socket_pdu::handle_tcp_accept, this, new_connection, - boost::asio::placeholders::error)); - } - - void handle_tcp_accept(tcp_connection::pointer new_connection, const boost::system::error_code& error){ - if (!error) - { - new_connection->start(this); - d_tcp_connections.push_back(new_connection); - start_tcp_accept(); - } else { - std::cout << error << std::endl; - } - } - - void run_io_service(){ - _io_service.run(); - } - - void handle_udp_read(const boost::system::error_code& error/*error*/, size_t bytes_transferred){ - if(!error){ - pmt::pmt_t vector = pmt::init_u8vector(bytes_transferred, (const uint8_t*)&rxbuf[0]); - pmt::pmt_t pdu = pmt::cons( pmt::PMT_NIL, vector); - - message_port_pub( pmt::mp("pdus"), pdu ); - - _udp_socket->async_receive_from( boost::asio::buffer(rxbuf), _udp_endpoint_other, - boost::bind(&gr_socket_pdu::handle_udp_read, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred)); - } else { - throw boost::system::system_error(error); -// std::cout << "error occurred\n"; - } - } - void handle_tcp_read(const boost::system::error_code& error/*error*/, size_t bytes_transferred){ - if(!error) - { - pmt::pmt_t vector = pmt::init_u8vector(bytes_transferred, (const uint8_t*)&rxbuf[0]); - pmt::pmt_t pdu = pmt::cons( pmt::PMT_NIL, vector); - - message_port_pub( pmt::mp("pdus"), pdu ); - - _tcp_socket->async_read_some( - boost::asio::buffer(rxbuf), - boost::bind(&gr_socket_pdu::handle_tcp_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); - - } else { - //std::cout << "error occurred\n"; - throw boost::system::system_error(error); - } - } - - protected: - gr_socket_pdu (std::string type, std::string addr, std::string port, int MTU=10000); - public: - ~gr_socket_pdu () {} -}; - -#endif /* INCLUDED_GR_TUNTAP_PDU_H */ diff --git a/gnuradio-core/src/lib/io/gr_socket_pdu.i b/gnuradio-core/src/lib/io/gr_socket_pdu.i deleted file mode 100644 index 3e20b63e20..0000000000 --- a/gnuradio-core/src/lib/io/gr_socket_pdu.i +++ /dev/null @@ -1,33 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2005 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. - */ - -GR_SWIG_BLOCK_MAGIC(gr,socket_pdu); - -%ignore tcp_connection; - -%{ -#include <gr_socket_pdu.h> -%} - -%include "gr_stream_pdu_base.h" -%include "gr_socket_pdu.h" - diff --git a/gnuradio-core/src/lib/io/gr_stream_pdu_base.cc b/gnuradio-core/src/lib/io/gr_stream_pdu_base.cc deleted file mode 100644 index 0a0038ea25..0000000000 --- a/gnuradio-core/src/lib/io/gr_stream_pdu_base.cc +++ /dev/null @@ -1,123 +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 <ciso646> -#include <gr_stream_pdu_base.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/asio.hpp> -#include <boost/format.hpp> - -#ifdef HAVE_IO_H -#include <io.h> -#endif - -static const long timeout_us = 100*1000; //100ms - -gr_stream_pdu_base::gr_stream_pdu_base (int MTU) - : gr_sync_block("stream_pdu_base", - gr_make_io_signature(0, 0, 0), - gr_make_io_signature(0, 0, 0)), - d_finished(false), d_started(false), d_fd(-1) -{ - // reserve space for rx buffer - d_rxbuf.resize(MTU,0); -} - -gr_stream_pdu_base::~gr_stream_pdu_base() -{ - stop_rxthread(); -} - -void gr_stream_pdu_base::stop_rxthread(){ - d_finished = true; - if(d_started){ - d_thread->interrupt(); - d_thread->join(); - } - } - -void gr_stream_pdu_base::start_rxthread(pmt::pmt_t _rxport){ - rxport = _rxport; - d_thread = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&gr_stream_pdu_base::run, this))); - d_started = true; - } - -void gr_stream_pdu_base::run(){ - while(!d_finished) { - if(not wait_ready()){ continue; } - const int result = read( d_fd, &d_rxbuf[0], d_rxbuf.size() ); - if(result <= 0){ throw std::runtime_error("gr_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); - message_port_pub(rxport, pdu); - } -} - -void gr_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; - } -} - -int -gr_stream_pdu_base::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - throw std::runtime_error("should not be called.\n"); - return 0; -} - -bool gr_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; -} diff --git a/gnuradio-core/src/lib/io/gr_stream_pdu_base.h b/gnuradio-core/src/lib/io/gr_stream_pdu_base.h deleted file mode 100644 index 35bacf523f..0000000000 --- a/gnuradio-core/src/lib/io/gr_stream_pdu_base.h +++ /dev/null @@ -1,59 +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_STREAM_PDU_BASE_H -#define INCLUDED_GR_STREAM_PDU_BASE_H - -#include <gr_core_api.h> -#include <gr_sync_block.h> -#include <gr_message.h> -#include <gr_msg_queue.h> - -/*! - * \brief Gather received items into messages and insert into msgq - * \ingroup sink_blk - */ -class GR_CORE_API gr_stream_pdu_base : public gr_sync_block -{ - public: - boost::shared_ptr<boost::thread> d_thread; - bool d_finished; - bool d_started; - std::vector<uint8_t> d_rxbuf; - void run(); - int d_fd; - gr_stream_pdu_base (int MTU=10000); - ~gr_stream_pdu_base (); - void send(pmt::pmt_t msg); - bool wait_ready(); - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - void start_rxthread(pmt::pmt_t _rxport); - void stop_rxthread(); - private: - pmt::pmt_t rxport; -}; - -typedef boost::shared_ptr<gr_stream_pdu_base> gr_stream_pdu_base_sptr; - -#endif /* INCLUDED_GR_TUNTAP_PDU_H */ 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 deleted file mode 100644 index 7daac6db26..0000000000 --- a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc +++ /dev/null @@ -1,137 +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_tagged_stream_to_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> - -// public constructor that returns a shared_ptr - -gr_tagged_stream_to_pdu_sptr -gr_make_tagged_stream_to_pdu(gr_pdu_vector_type t) -{ - return gnuradio::get_initial_sptr(new gr_tagged_stream_to_pdu(t)); -} - -gr_tagged_stream_to_pdu::gr_tagged_stream_to_pdu (gr_pdu_vector_type t) - : gr_sync_block("tagged_stream_to_pdu", - gr_make_io_signature(1, 1, gr_pdu_itemsize(t)), - gr_make_io_signature(0, 0, 0)), - 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); -} - -gr_tagged_stream_to_pdu::~gr_tagged_stream_to_pdu() -{ - printf("destructor running\n"); -} - -int -gr_tagged_stream_to_pdu::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - const uint8_t *in = (const uint8_t*) input_items[0]; - uint64_t abs_N = nitems_read(0); - - // if we are not in a pdu already, start a new one - if(!d_inpdu){ - 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( (*d_tags_itr).offset != abs_N ){ - throw std::runtime_error("expected next pdu length tag on a different item..."); - } - found_length_tag = true; - d_pdu_length = pmt::to_long( (*d_tags_itr).value ); - d_pdu_remain = d_pdu_length; - d_pdu_meta = pmt::make_dict(); - break; - } // if have length tag - } // iter over tags - if(!found_length_tag){ - throw std::runtime_error("tagged stream does not contain a pdu_length tag!"); - } - } - - size_t ncopy = std::min((size_t)noutput_items, d_pdu_remain); - - // 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 ) ){ - d_pdu_meta = dict_add(d_pdu_meta, (*d_tags_itr).key, (*d_tags_itr).value); - } - } - - // copy samples for this vector into either a pmt or our save buffer - if(ncopy == d_pdu_remain){ // we will send this pdu - if(d_save.size() == 0){ - d_pdu_vector = gr_pdu_make_vector(d_vectortype, in, ncopy); - send_message(); - } else { - size_t oldsize = d_save.size(); - d_save.resize((oldsize + ncopy)*d_itemsize, 0); - memcpy( &d_save[oldsize*d_itemsize], in, ncopy*d_itemsize ); - d_pdu_vector = gr_pdu_make_vector(d_vectortype, &d_save[0], d_pdu_length); - send_message(); - d_save.clear(); - } - } else { - d_inpdu = true; - size_t oldsize = d_save.size(); - d_save.resize( (oldsize+ncopy)*d_itemsize ); - memcpy( &d_save[oldsize*d_itemsize], in, ncopy*d_itemsize ); - d_pdu_remain -= ncopy; - } - - return ncopy; -} - -void gr_tagged_stream_to_pdu::send_message(){ - - if(pmt::length(d_pdu_vector) != d_pdu_length){ - throw std::runtime_error("msg length not correct"); - } - - pmt::pmt_t msg = pmt::cons( d_pdu_meta, d_pdu_vector ); - message_port_pub( PDU_PORT_ID, msg ); - - d_pdu_meta = pmt::PMT_NIL; - d_pdu_vector = pmt::PMT_NIL; - d_pdu_length = 0; - d_pdu_remain = 0; - d_inpdu = false; -} diff --git a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.h b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.h deleted file mode 100644 index c3fff35815..0000000000 --- a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.h +++ /dev/null @@ -1,76 +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_TAGGED_STREAM_TO_PDU_H -#define INCLUDED_GR_TAGGED_STREAM_TO_PDU_H - -#include <gr_core_api.h> -#include <gr_sync_block.h> -#include <gr_message.h> -#include <gr_msg_queue.h> -#include <gr_pdu.h> - -class gr_tagged_stream_to_pdu; -typedef boost::shared_ptr<gr_tagged_stream_to_pdu> gr_tagged_stream_to_pdu_sptr; - -GR_CORE_API gr_tagged_stream_to_pdu_sptr gr_make_tagged_stream_to_pdu (gr_pdu_vector_type t); - -/*! - * \brief Turn received messages into a stream - * \ingroup source_blk - */ -class GR_CORE_API gr_tagged_stream_to_pdu : public gr_sync_block -{ - private: - gr_pdu_vector_type d_vectortype; - size_t d_itemsize; - - std::vector<uint8_t> d_save; - - std::vector<gr_tag_t> d_tags; - std::vector<gr_tag_t>::iterator d_tags_itr; - - bool d_inpdu; - - size_t d_pdu_length; - size_t d_pdu_remain; - pmt::pmt_t d_pdu_meta; - pmt::pmt_t d_pdu_vector; - - friend GR_CORE_API gr_tagged_stream_to_pdu_sptr - gr_make_tagged_stream_to_pdu(gr_pdu_vector_type t); - - protected: - gr_tagged_stream_to_pdu (gr_pdu_vector_type t); - - public: - ~gr_tagged_stream_to_pdu (); - - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - - void send_message(); - -}; - -#endif /* INCLUDED_GR_PDU_TO_TAGGED_SOURCE_H */ diff --git a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.i b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.i deleted file mode 100644 index f12987b74c..0000000000 --- a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.i +++ /dev/null @@ -1,31 +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. - */ - -GR_SWIG_BLOCK_MAGIC(gr,tagged_stream_to_pdu); - -%{ -#include <gr_tagged_stream_to_pdu.h> -%} - -%include <gr_tagged_stream_to_pdu.h> - - diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index 33cc906e92..01a174903d 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -45,11 +45,7 @@ #include <gr_wavfile_sink.h> #include <gr_wavfile_source.h> #include <gr_tagged_file_sink.h> -#include <gr_pdu_to_tagged_stream.h> -#include <gr_tagged_stream_to_pdu.h> #include <gr_message_debug.h> -#include <gr_pdu.h> -#include <gr_socket_pdu.h> %} %include "gr_file_sink_base.i" @@ -72,10 +68,6 @@ %include "gr_wavfile_sink.i" %include "gr_wavfile_source.i" %include "gr_tagged_file_sink.i" -%include "gr_pdu_to_tagged_stream.i" -%include "gr_tagged_stream_to_pdu.i" %include "gr_message_debug.i" -%include "gr_pdu.i" -%include "gr_socket_pdu.i" diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_pdu.py b/gnuradio-core/src/python/gnuradio/gr/qa_pdu.py deleted file mode 100755 index 00aacdfb11..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_pdu.py +++ /dev/null @@ -1,111 +0,0 @@ -#!/usr/bin/env python -# -# 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. -# - -from gnuradio import gr, gr_unittest -import pmt -import time - -class test_pdu(gr_unittest.TestCase): - - def setUp(self): - self.tb = gr.top_block() - - def tearDown(self): - self.tb = None - - def test_000(self): - # Just run some data through and make sure it doesn't puke. - src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) - - src = gr.pdu_to_tagged_stream(gr.pdu_byte) - snk3 = gr.tagged_stream_to_pdu(gr.pdu_byte) - snk2 = gr.vector_sink_b() - snk = gr.tag_debug(1, "test") - - dbg = gr.message_debug() - - # Test that the right number of ports exist. - pi = dbg.message_ports_in() - po = dbg.message_ports_out() - - self.assertEqual(pmt.length(pi), 3) - self.assertEqual(pmt.length(po), 0) - - pi = snk3.message_ports_in() - po = snk3.message_ports_out() - self.assertEqual(pmt.length(pi), 0) - self.assertEqual(pmt.length(po), 1) - - #print "Message Debug input ports: " - #pmt.print(pi) - #print "Message Debug output ports: " - #pmt.print(po) - - #print "Stream to PDU input ports: " - #pmt.print(pi) - #print "Stream to PDU output ports: " - #pmt.print(po) - time.sleep(0.1) - - self.tb.connect(src, snk) - self.tb.connect(src, snk2) - self.tb.connect(src, snk3) - - self.tb.msg_connect(snk3, "pdus", dbg, "store") - self.tb.start() - - # make our reference and message pmts - port = pmt.intern("pdus") - msg = pmt.cons( pmt.PMT_NIL, pmt.make_u8vector(16, 0xFF) ) - - #print "printing port & msg" - #print(port) - #print(msg) - - # post the message - src.to_basic_block()._post( port, msg ) - - while(dbg.num_messages() < 1): - time.sleep(0.5) - self.tb.stop() - self.tb.wait() - - # Get the vector of data from the vector sink - result_data = snk2.data() - - # Get the vector of data from the message sink - # Convert the message PMT as a pair into its vector - result_msg = dbg.get_message(0) - msg_vec = pmt.cdr(result_msg) - print(msg_vec) - - # Convert the PMT vector into a Python list - msg_data = [] - for i in xrange(16): - msg_data.append(pmt.u8vector_ref(msg_vec, i)) - - actual_data = 16*[0xFF,] - self.assertEqual(actual_data, list(result_data)) - self.assertEqual(actual_data, msg_data) - -if __name__ == '__main__': - gr_unittest.run(test_pdu, "test_pdu.xml") diff --git a/grc/blocks/block_tree.xml b/grc/blocks/block_tree.xml index 4567a65781..968e528680 100644 --- a/grc/blocks/block_tree.xml +++ b/grc/blocks/block_tree.xml @@ -37,10 +37,6 @@ <name>Message Tools</name> <block>gr_message_debug</block> <block>gr_message_strobe</block> - <block>gr_pdu_to_tagged_stream</block> - <block>gr_tagged_stream_to_pdu</block> - <block>gr_socket_pdu</block> - <block>gr_random_pdu</block> </cat> <cat> <name>Operators</name> diff --git a/grc/blocks/gr_pdu_to_tagged_stream.xml b/grc/blocks/gr_pdu_to_tagged_stream.xml deleted file mode 100644 index 6d2fea97e7..0000000000 --- a/grc/blocks/gr_pdu_to_tagged_stream.xml +++ /dev/null @@ -1,40 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -## PDU Message to Tagged Stream -################################################### - --> -<block> - <name>PDU to Tagged Stream</name> - <key>gr_pdu_to_tagged_stream</key> - <import>from gnuradio import gr</import> - <make>gr.pdu_to_tagged_stream($type.tv)</make> - <param> - <name>Item Type</name> - <key>type</key> - <type>enum</type> - <option> - <name>Byte</name> - <key>byte</key> - <opt>tv:gr.pdu_byte</opt> - </option> - <option> - <name>Complex</name> - <key>complex</key> - <opt>tv:gr.pdu_complex</opt> - </option> - <option> - <name>Float</name> - <key>float</key> - <opt>tv:gr.pdu_float</opt> - </option> - </param> - <sink> - <name>pdus</name> - <type>message</type> - </sink> - <source> - <name>out</name> - <type>$type</type> - </source> -</block> diff --git a/grc/blocks/gr_random_pdu.xml b/grc/blocks/gr_random_pdu.xml deleted file mode 100644 index ed5a79a924..0000000000 --- a/grc/blocks/gr_random_pdu.xml +++ /dev/null @@ -1,35 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -## Random PDU -################################################### - --> -<block> - <name>Random PDU Generator</name> - <key>gr_random_pdu</key> - <import>from gnuradio import gr</import> - <import>from gruel import pmt</import> - <make>gr.random_pdu($minsize, $maxsize)</make> - <param> - <name>Min Bytes</name> - <key>minsize</key> - <value>50</value> - <type>int</type> - </param> - <param> - <name>Max Bytes</name> - <key>maxsize</key> - <value>2000</value> - <type>int</type> - </param> - <sink> - <name>generate</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_socket_pdu.xml b/grc/blocks/gr_socket_pdu.xml deleted file mode 100644 index a175c36991..0000000000 --- a/grc/blocks/gr_socket_pdu.xml +++ /dev/null @@ -1,62 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -## Socket PDU Message source/sink -################################################### - --> -<block> - <name>Socket PDU</name> - <key>gr_socket_pdu</key> - <import>from gnuradio import gr</import> - <make>gr.socket_pdu($type, $host, $port, $mtu)</make> - <param> - <name>Type</name> - <key>type</key> - <value>TCP_SERVER</value> - <type>enum</type> - <option> - <name>TCP Server</name> - <key>"TCP_SERVER"</key> - </option> - <option> - <name>TCP Client</name> - <key>"TCP_CLIENT"</key> - </option> - <option> - <name>UDP Server</name> - <key>"UDP_SERVER"</key> - </option> - <option> - <name>UDP Client</name> - <key>"UDP_CLIENT"</key> - </option> - </param> - <param> - <name>Host</name> - <key>host</key> - <value></value> - <type>string</type> - </param> - <param> - <name>Port</name> - <key>port</key> - <value>52001</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_tagged_stream_to_pdu.xml b/grc/blocks/gr_tagged_stream_to_pdu.xml deleted file mode 100644 index e2f754c9eb..0000000000 --- a/grc/blocks/gr_tagged_stream_to_pdu.xml +++ /dev/null @@ -1,40 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -## Tagged Stream to PDU Message -################################################### - --> -<block> - <name>Tagged Stream to PDU</name> - <key>gr_tagged_stream_to_pdu</key> - <import>from gnuradio import gr</import> - <make>gr.tagged_stream_to_pdu($type.tv)</make> - <param> - <name>Item Type</name> - <key>type</key> - <type>enum</type> - <option> - <name>Byte</name> - <key>byte</key> - <opt>tv:gr.pdu_byte</opt> - </option> - <option> - <name>Complex</name> - <key>complex</key> - <opt>tv:gr.pdu_complex</opt> - </option> - <option> - <name>Float</name> - <key>float</key> - <opt>tv:gr.pdu_float</opt> - </option> - </param> - <sink> - <name>in</name> - <type>$type</type> - </sink> - <source> - <name>pdus</name> - <type>message</type> - </source> -</block> |