diff options
20 files changed, 148 insertions, 77 deletions
diff --git a/docs/doxygen/other/main_page.dox b/docs/doxygen/other/main_page.dox index deb6f8ebf8..3ad9e68021 100644 --- a/docs/doxygen/other/main_page.dox +++ b/docs/doxygen/other/main_page.dox @@ -45,6 +45,7 @@ More details on GNU Radio concepts: \li \ref page_metadata \li \ref volk_guide \li \ref page_pfb +\li \ref page_tagged_stream_blocks \section flowgraph Operating a Flowgraph diff --git a/gnuradio-runtime/include/gr_logger.h b/gnuradio-runtime/include/gr_logger.h index 5898d0bfad..c6b4b15dad 100644 --- a/gnuradio-runtime/include/gr_logger.h +++ b/gnuradio-runtime/include/gr_logger.h @@ -39,9 +39,7 @@ #include <gr_runtime_api.h> #include <assert.h> #include <iostream> -#include <time.h> -#include <boost/filesystem.hpp> -#include <boost/thread.hpp> +#include <boost/format.hpp> #ifdef ENABLE_GR_LOG diff --git a/gnuradio-runtime/include/gr_tagged_stream_block.h b/gnuradio-runtime/include/gr_tagged_stream_block.h index 797845f8e2..67b144fb66 100644 --- a/gnuradio-runtime/include/gr_tagged_stream_block.h +++ b/gnuradio-runtime/include/gr_tagged_stream_block.h @@ -35,8 +35,8 @@ class GR_RUNTIME_API gr_tagged_stream_block : public gr_block { private: - pmt::pmt_t d_length_tag_key; //! This is the key for the tag that stores the PDU length - gr_vector_int d_n_input_items_reqd; //! How many input items do I need to process the next PDU? + pmt::pmt_t d_length_tag_key; //!< This is the key for the tag that stores the PDU length + gr_vector_int d_n_input_items_reqd; //!< How many input items do I need to process the next PDU? protected: std::string d_length_tag_key_str; @@ -46,7 +46,8 @@ class GR_RUNTIME_API gr_tagged_stream_block : public gr_block gr_io_signature_sptr output_signature, const std::string &length_tag_key); - /* \brief Parse all tags on the first sample of a PDU, return the number of items per input + /*! + * \brief Parse all tags on the first sample of a PDU, return the number of items per input * and prune the length tags. * * In most cases, you don't need to override this, unless the number of items read @@ -66,7 +67,8 @@ class GR_RUNTIME_API gr_tagged_stream_block : public gr_block gr_vector_int &n_input_items_reqd ); - /* \brief Calculate the number of output items. + /*! + * \brief Calculate the number of output items. * * This is basically the inverse function to forecast(): Given a number of input * items, it returns the maximum number of output items. @@ -77,7 +79,8 @@ class GR_RUNTIME_API gr_tagged_stream_block : public gr_block */ virtual int calculate_output_stream_length(const gr_vector_int &ninput_items); - /* \brief Set the new length tags on the output stream + /*! + * \brief Set the new length tags on the output stream * * Default behaviour: Set a tag with key \p length_tag_key and * the number of produced items on every output port. @@ -91,11 +94,12 @@ class GR_RUNTIME_API gr_tagged_stream_block : public gr_block public: - /* \brief Don't override this. + /*! \brief Don't override this. */ void /* final */ forecast (int noutput_items, gr_vector_int &ninput_items_required); - /* - Reads the number of input items from the tags using parse_length_tags() + /*! + * - Reads the number of input items from the tags using parse_length_tags() * - Checks there's enough data on the input and output buffers * - If not, inform the scheduler and do nothing * - Calls work() with the exact number of items per PDU diff --git a/gnuradio-runtime/lib/gr_tagged_stream_block.cc b/gnuradio-runtime/lib/gr_tagged_stream_block.cc index 32b6a09033..a60515f481 100644 --- a/gnuradio-runtime/lib/gr_tagged_stream_block.cc +++ b/gnuradio-runtime/lib/gr_tagged_stream_block.cc @@ -24,6 +24,7 @@ #include "config.h" #endif +#include <boost/format.hpp> #include <gr_tagged_stream_block.h> gr_tagged_stream_block::gr_tagged_stream_block (const std::string &name, @@ -111,7 +112,8 @@ gr_tagged_stream_block::general_work (int noutput_items, } for (unsigned i = 0; i < input_items.size(); i++) { if (d_n_input_items_reqd[i] == -1) { - throw std::runtime_error("Missing length tag."); + GR_LOG_FATAL(d_logger, boost::format("Missing a required length tag on port %1% at item #%2%") % i % nitems_read(i)); + throw std::runtime_error("Missing length tag."); } if (d_n_input_items_reqd[i] > ninput_items[i]) { return 0; diff --git a/gr-blocks/include/blocks/tagged_stream_mux.h b/gr-blocks/include/blocks/tagged_stream_mux.h index 23e8a94403..d271cf890f 100644 --- a/gr-blocks/include/blocks/tagged_stream_mux.h +++ b/gr-blocks/include/blocks/tagged_stream_mux.h @@ -31,12 +31,11 @@ namespace gr { /*! * \brief Combines tagged streams. * - * \description * Takes N streams as input. Each stream is tagged with packet lengths. * Packets are output sequentially from each input stream. * * The output signal has a new length tag, which is the sum of all - * individual length tags. + * individual length tags. The old length tags are discarded. * * All other tags are propagated as expected, i.e. they stay associated * with the same input item. @@ -48,7 +47,8 @@ namespace gr { public: typedef boost::shared_ptr<tagged_stream_mux> sptr; - /* \param itemsize Items size (number of bytes per item) + /*! + * \param itemsize Items size (number of bytes per item) * \param lengthtagname Length tag key */ static sptr make(size_t itemsize, const std::string &lengthtagname); diff --git a/gr-digital/include/digital/ofdm_frame_equalizer_vcvc.h b/gr-digital/include/digital/ofdm_frame_equalizer_vcvc.h index 68e8b7ad9f..de74d325ad 100644 --- a/gr-digital/include/digital/ofdm_frame_equalizer_vcvc.h +++ b/gr-digital/include/digital/ofdm_frame_equalizer_vcvc.h @@ -42,7 +42,7 @@ namespace gr { public: typedef boost::shared_ptr<ofdm_frame_equalizer_vcvc> sptr; - /* + /*! * \param equalizer The equalizer object that will do the actual work * \param len_tag_key Length tag key * \param propagate_channel_state If true, the channel state after the last symbol diff --git a/gr-digital/include/digital/packet_header_default.h b/gr-digital/include/digital/packet_header_default.h index a4158e728c..d69a0f30a6 100644 --- a/gr-digital/include/digital/packet_header_default.h +++ b/gr-digital/include/digital/packet_header_default.h @@ -30,9 +30,19 @@ namespace gr { namespace digital { /*! - * \brief <+description of block+> + * \brief Default header formatter for digital packet transmission. * \ingroup digital * + * For bursty/packetized digital transmission, packets are usually prepended + * with a packet header, containing the number of bytes etc. + * This class is not a block, but a tool to create these packet header. + * + * This is a default packet header (see header_formatter()) for a description + * on the header format). To create other header, derive packet header creator + * classes from this function. + * + * gr::digital::packet_headergenerator_bb uses header generators derived from + * this class to create packet headers from data streams. */ class DIGITAL_API packet_header_default : public boost::enable_shared_from_this<gr::digital::packet_header_default> { @@ -53,7 +63,8 @@ namespace gr { long header_len() { return d_header_len; }; pmt::pmt_t len_tag_key() { return d_len_tag_key; }; - /* \brief Encodes the header information in the given tags into bits and places them into \p out + /*! + * \brief Encodes the header information in the given tags into bits and places them into \p out * * Uses the following header format: * Bits 0-11: The packet length (what was stored in the tag with key \p len_tag_key) @@ -70,7 +81,8 @@ namespace gr { const std::vector<gr_tag_t> &tags=std::vector<gr_tag_t>() ); - /* \brief Inverse function to header_formatter(). + /*! + * \brief Inverse function to header_formatter(). * * Reads the bit stream in \in and writes a corresponding tag into \p tags. * diff --git a/gr-digital/include/digital/packet_header_ofdm.h b/gr-digital/include/digital/packet_header_ofdm.h index 6c3453ed1d..9f70900b49 100644 --- a/gr-digital/include/digital/packet_header_ofdm.h +++ b/gr-digital/include/digital/packet_header_ofdm.h @@ -48,7 +48,8 @@ namespace gr { int bits_per_sym=1); ~packet_header_ofdm(); - /* \brief Inverse function to header_formatter(). + /*! + * \brief Inverse function to header_formatter(). * * Does the same as packet_header_default::header_parser(), but * adds another tag that stores the number of OFDM symbols in the @@ -72,8 +73,8 @@ namespace gr { protected: pmt::pmt_t d_frame_len_tag_key; - const std::vector<std::vector<int> > d_occupied_carriers; //! Which carriers/symbols carry data - int d_syms_per_set; //! Helper variable: Total number of elements in d_occupied_carriers + const std::vector<std::vector<int> > d_occupied_carriers; //!< Which carriers/symbols carry data + int d_syms_per_set; //!< Helper variable: Total number of elements in d_occupied_carriers }; } // namespace digital diff --git a/gr-digital/include/digital/packet_headergenerator_bb.h b/gr-digital/include/digital/packet_headergenerator_bb.h index 8d92bf84ed..cec860fd55 100644 --- a/gr-digital/include/digital/packet_headergenerator_bb.h +++ b/gr-digital/include/digital/packet_headergenerator_bb.h @@ -33,18 +33,33 @@ namespace gr { * \brief Generates a header for a tagged, streamed packet. * \ingroup digital * - * Input: A tagged stream. The first element must have a tag with the key - * specified in len_tag_key, which hold the exact number of elements - * in the PDU. - * Output: An tagged stream of length header_len. The output is determined - * by a header formatter. + * Input: A tagged stream. This is consumed entirely, it is not appended + * to the output stream. + * Output: An tagged stream containing the header. The details on the header + * are set in a header formatter object (of type packet_header_default + * or a subclass thereof). If only a number of bits is specified, a + * default header is generated (see packet_header_default). */ class DIGITAL_API packet_headergenerator_bb : virtual public gr_tagged_stream_block { public: typedef boost::shared_ptr<packet_headergenerator_bb> sptr; - static sptr make(const packet_header_default::sptr &header_formatter); + /* \param header_formatter A header formatter object. + * \param len_tag_key Length tag key. Note that for header generation, + * it is irrelevant which tag names are set in the + * formatter object, only this value is relevant! + */ + static sptr make( + const packet_header_default::sptr &header_formatter, + const std::string &len_tag_key="packet_len" + ); + + /* \param header_len If this value is given, a packet_header_default + * object is used to generate the header. This is + * the number of bits per header. + * \param len_tag_key Length tag key. + */ static sptr make( long header_len, const std::string &len_tag_key = "packet_len"); diff --git a/gr-digital/include/digital/packet_headerparser_b.h b/gr-digital/include/digital/packet_headerparser_b.h index a3db069cbd..2dc6a80717 100644 --- a/gr-digital/include/digital/packet_headerparser_b.h +++ b/gr-digital/include/digital/packet_headerparser_b.h @@ -35,7 +35,11 @@ namespace gr { * * In a sense, this is the inverse block to packet_headergenerator_bb. * The difference is, the parsed header is not output as a stream, - * but as a message. + * but as a PMT dictionary, which is published to message port with + * the id "header_data". + * The dictionary consists of the tags created by the header formatter + * object. You should be able to use the exact same formatter object + * as used on the Tx side in the packet_headergenerator_bb. * * If only a header length is given, this block uses the default header * format. diff --git a/gr-digital/lib/header_payload_demux_impl.h b/gr-digital/lib/header_payload_demux_impl.h index ceab9a8629..dc8cc7883a 100644 --- a/gr-digital/lib/header_payload_demux_impl.h +++ b/gr-digital/lib/header_payload_demux_impl.h @@ -30,17 +30,17 @@ namespace gr { class header_payload_demux_impl : public header_payload_demux { private: - int d_header_len; //! Number of bytes per header - int d_items_per_symbol; //! Bytes per symbol - int d_gi; //! Bytes per guard interval - pmt::pmt_t d_len_tag_key; //! Key of length tag - pmt::pmt_t d_trigger_tag_key; //! Key of trigger tag (if used) - bool d_output_symbols; //! If true, output is symbols, not items - size_t d_itemsize; //! Bytes per item - bool d_uses_trigger_tag; //! If a trigger tag is used - int d_ninput_items_reqd; //! Helper for forecast() - int d_state; //! Current read state - int d_remaining_symbols; //! When in payload or header state, the number of symbols still to transmit + int d_header_len; //!< Number of bytes per header + int d_items_per_symbol; //!< Bytes per symbol + int d_gi; //!< Bytes per guard interval + pmt::pmt_t d_len_tag_key; //!< Key of length tag + pmt::pmt_t d_trigger_tag_key; //!< Key of trigger tag (if used) + bool d_output_symbols; //!< If true, output is symbols, not items + size_t d_itemsize; //!< Bytes per item + bool d_uses_trigger_tag; //!< If a trigger tag is used + int d_ninput_items_reqd; //!< Helper for forecast() + int d_state; //!< Current read state + int d_remaining_symbols; //!< When in payload or header state, the number of symbols still to transmit // Helpers to make the state machine more readable diff --git a/gr-digital/lib/ofdm_frame_equalizer_vcvc_impl.h b/gr-digital/lib/ofdm_frame_equalizer_vcvc_impl.h index 803874713f..f86451e839 100644 --- a/gr-digital/lib/ofdm_frame_equalizer_vcvc_impl.h +++ b/gr-digital/lib/ofdm_frame_equalizer_vcvc_impl.h @@ -36,7 +36,7 @@ namespace gr { std::vector<gr_complex> d_channel_state; protected: - // This aren't really necessary, so let's override them with nuthin' + // These aren't really necessary, so let's override them with nuthin' void remove_length_tags(const std::vector<std::vector<gr_tag_t> > &tags) {}; void update_length_tags(int n_produced, int n_ports) {}; diff --git a/gr-digital/lib/ofdm_serializer_vcc_impl.h b/gr-digital/lib/ofdm_serializer_vcc_impl.h index ef2f1c83b1..4f750eac71 100644 --- a/gr-digital/lib/ofdm_serializer_vcc_impl.h +++ b/gr-digital/lib/ofdm_serializer_vcc_impl.h @@ -30,16 +30,17 @@ namespace gr { class ofdm_serializer_vcc_impl : public ofdm_serializer_vcc { private: - int d_fft_len; //! FFT length - std::vector<std::vector<int> > d_occupied_carriers; //! Which carriers/symbols carry data - pmt::pmt_t d_packet_len_tag_key; //! Key of the length tag - pmt::pmt_t d_out_len_tag_key; //! Key of the length tag - const int d_symbols_skipped; //! Start position in d_occupied_carriers - int d_curr_set; //! Current position in d_occupied_carriers + int d_fft_len; //!< FFT length + std::vector<std::vector<int> > d_occupied_carriers; //!< Which carriers/symbols carry data + pmt::pmt_t d_packet_len_tag_key; //!< Key of the length tag + pmt::pmt_t d_out_len_tag_key; //!< Key of the length tag + const int d_symbols_skipped; //!< Start position in d_occupied_carriers + int d_curr_set; //!< Current position in d_occupied_carriers int d_symbols_per_set; protected: - /* Calculate the number of scalar complex symbols given a number of + /*! + * Calculate the number of scalar complex symbols given a number of * OFDM symbols. */ int calculate_output_stream_length(const gr_vector_int &ninput_items); diff --git a/gr-digital/lib/packet_headergenerator_bb_impl.cc b/gr-digital/lib/packet_headergenerator_bb_impl.cc index bcfaf6b63d..3232858148 100644 --- a/gr-digital/lib/packet_headergenerator_bb_impl.cc +++ b/gr-digital/lib/packet_headergenerator_bb_impl.cc @@ -23,6 +23,7 @@ #include "config.h" #endif +#include <boost/format.hpp> #include <gr_io_signature.h> #include "packet_headergenerator_bb_impl.h" @@ -30,9 +31,12 @@ namespace gr { namespace digital { packet_headergenerator_bb::sptr - packet_headergenerator_bb::make(const packet_header_default::sptr &header_formatter) + packet_headergenerator_bb::make( + const packet_header_default::sptr &header_formatter, + const std::string &len_tag_key + ) { - return gnuradio::get_initial_sptr (new packet_headergenerator_bb_impl(header_formatter)); + return gnuradio::get_initial_sptr (new packet_headergenerator_bb_impl(header_formatter, len_tag_key)); } @@ -45,25 +49,23 @@ namespace gr { const packet_header_default::sptr header_formatter( new packet_header_default(header_len, len_tag_key) ); - return gnuradio::get_initial_sptr (new packet_headergenerator_bb_impl(header_formatter)); + return gnuradio::get_initial_sptr (new packet_headergenerator_bb_impl(header_formatter, len_tag_key)); } packet_headergenerator_bb_impl::packet_headergenerator_bb_impl( - const gr::digital::packet_header_default::sptr &header_formatter + const gr::digital::packet_header_default::sptr &header_formatter, + const std::string &len_tag_key ) : gr_tagged_stream_block("packet_headergenerator_bb_impl", gr_make_io_signature(1, 1, sizeof (char)), gr_make_io_signature(1, 1, sizeof (char)), - pmt::symbol_to_string(header_formatter->len_tag_key())), - d_formatter(header_formatter), - d_input_size(1), - d_header_len(header_formatter->header_len()), - d_len_tag_value(pmt::from_long(d_header_len)) + len_tag_key), + d_formatter(header_formatter) { - set_output_multiple(d_header_len); + set_output_multiple(d_formatter->header_len()); // This is the worst case rate, because we don't know the true value, of course - set_relative_rate(d_header_len); + set_relative_rate(d_formatter->header_len()); set_tag_propagation_policy(TPP_DONT); } @@ -79,10 +81,11 @@ namespace gr { { unsigned char *out = (unsigned char *) output_items[0]; if (!d_formatter->header_formatter(ninput_items[0], out)) { + GR_LOG_FATAL(d_logger, boost::format("header_formatter() returned false (this shouldn't happen). Offending header started at %1%") % nitems_read(0)); throw std::runtime_error("header formatter returned false."); } - return d_header_len; + return d_formatter->header_len(); } } /* namespace digital */ diff --git a/gr-digital/lib/packet_headergenerator_bb_impl.h b/gr-digital/lib/packet_headergenerator_bb_impl.h index 7d2494cf8b..ce60fdf76c 100644 --- a/gr-digital/lib/packet_headergenerator_bb_impl.h +++ b/gr-digital/lib/packet_headergenerator_bb_impl.h @@ -31,16 +31,16 @@ namespace gr { { private: gr::digital::packet_header_default::sptr d_formatter; - int d_input_size; - int d_header_len; - pmt::pmt_t d_len_tag_value; public: - packet_headergenerator_bb_impl(const packet_header_default::sptr &header_formatter); + packet_headergenerator_bb_impl( + const packet_header_default::sptr &header_formatter, + const std::string &len_tag_key + ); ~packet_headergenerator_bb_impl(); void remove_length_tags(const std::vector<std::vector<gr_tag_t> > &tags) {}; - int calculate_output_stream_length(const gr_vector_int &ninput_items) { return d_header_len; }; + int calculate_output_stream_length(const gr_vector_int &ninput_items) { return d_formatter->header_len(); }; int work(int noutput_items, gr_vector_int &ninput_items, diff --git a/gr-digital/lib/packet_headerparser_b_impl.cc b/gr-digital/lib/packet_headerparser_b_impl.cc index 825cfa3d86..60e1fdef0b 100644 --- a/gr-digital/lib/packet_headerparser_b_impl.cc +++ b/gr-digital/lib/packet_headerparser_b_impl.cc @@ -23,6 +23,7 @@ #include "config.h" #endif +#include <boost/format.hpp> #include <gr_io_signature.h> #include "packet_headerparser_b_impl.h" @@ -73,6 +74,7 @@ namespace gr { std::vector<gr_tag_t> tags; if (!d_header_formatter->header_parser(in, tags)) { + GR_LOG_INFO(d_logger, boost::format("Detected an invalid packet at item %1%") % nitems_read(0)); message_port_pub(msg_port_id, pmt::PMT_F); } else { pmt::pmt_t dict(pmt::make_dict()); diff --git a/gr-digital/python/ofdm_txrx.py b/gr-digital/python/ofdm_txrx.py index 190354e262..37c4086cc3 100644 --- a/gr-digital/python/ofdm_txrx.py +++ b/gr-digital/python/ofdm_txrx.py @@ -128,10 +128,10 @@ class ofdm_tx(gr.hier_block2): self.sync_words.append(self.sync_word2) crc = digital.crc32_bb(False, self.frame_length_tag_key) formatter_object = digital.packet_header_ofdm( - occupied_carriers, 1, self.frame_length_tag_key, self.frame_length_tag_key, "", - bps_header + occupied_carriers=occupied_carriers, n_syms=1, + bits_per_sym=self.bps_header ) - header_gen = digital.packet_headergenerator_bb(formatter_object.base()) + header_gen = digital.packet_headergenerator_bb(formatter_object.base(), self.frame_length_tag_key) header_payload_mux = blocks.tagged_stream_mux(gr.sizeof_gr_complex*1, self.frame_length_tag_key) self.connect(self, crc, header_gen, header_mod, (header_payload_mux, 0)) payload_constellation = _get_constellation(bps_payload) diff --git a/gr-digital/python/qa_ofdm_txrx.py b/gr-digital/python/qa_ofdm_txrx.py index 963fca850c..15c5b90fe9 100755 --- a/gr-digital/python/qa_ofdm_txrx.py +++ b/gr-digital/python/qa_ofdm_txrx.py @@ -21,9 +21,12 @@ # import numpy +import random from gnuradio import gr, gr_unittest import digital_swig as digital import blocks_swig as blocks +from ofdm_txrx import ofdm_tx, ofdm_rx +from utils import tagged_streams class test_ofdm_txrx (gr_unittest.TestCase): diff --git a/gr-digital/python/qa_packet_headergenerator_bb.py b/gr-digital/python/qa_packet_headergenerator_bb.py index 43659c604d..0f42c33a51 100755 --- a/gr-digital/python/qa_packet_headergenerator_bb.py +++ b/gr-digital/python/qa_packet_headergenerator_bb.py @@ -110,7 +110,7 @@ class qa_packet_headergenerator_bb (gr_unittest.TestCase): tag3.value = pmt.from_long(4) src = blocks.vector_source_b(data, False, 1, (tag1, tag2, tag3)) formatter_object = digital.packet_header_default(12, tagname) - header = digital.packet_headergenerator_bb(formatter_object.formatter()) + header = digital.packet_headergenerator_bb(formatter_object.formatter(), tagname) sink = blocks.vector_sink_b() self.tb.connect(src, header, sink) self.tb.run() @@ -142,7 +142,7 @@ class qa_packet_headergenerator_bb (gr_unittest.TestCase): formatter_object = digital.packet_header_ofdm(occupied_carriers, 1, tagname) self.assertEqual(formatter_object.header_len(), 6) self.assertEqual(pmt.symbol_to_string(formatter_object.len_tag_key()), tagname) - header = digital.packet_headergenerator_bb(formatter_object.formatter()) + header = digital.packet_headergenerator_bb(formatter_object.formatter(), tagname) sink = blocks.vector_sink_b() self.tb.connect(src, header, sink) self.tb.run() diff --git a/gr-uhd/examples/python/usrp_spectrum_sense.py b/gr-uhd/examples/python/usrp_spectrum_sense.py index 39e85ab18a..fe97e21cbd 100755 --- a/gr-uhd/examples/python/usrp_spectrum_sense.py +++ b/gr-uhd/examples/python/usrp_spectrum_sense.py @@ -107,7 +107,10 @@ class my_top_block(gr.top_block): help="time to delay (in seconds) after changing frequency [default=%default]") parser.add_option("", "--dwell-delay", type="eng_float", default=10e-3, metavar="SECS", - help="time to dwell (in seconds) at a given frequncy [default=%default]") + help="time to dwell (in seconds) at a given frequency [default=%default]") + parser.add_option("", "--channel-bandwidth", type="eng_float", + default=12.5e3, metavar="Hz", + help="channel bandwidth of fft bins in Hz [default=%default]") parser.add_option("-F", "--fft-size", type="int", default=256, help="specify number of FFT bins [default=%default]") parser.add_option("", "--real-time", action="store_true", default=False, @@ -125,8 +128,9 @@ class my_top_block(gr.top_block): # swap them self.min_freq, self.max_freq = self.max_freq, self.min_freq - self.fft_size = options.fft_size - + self.fft_size = options.fft_size + self.channel_bandwidth = options.channel_bandwidth + if not options.real_time: realtime = False else: @@ -150,14 +154,14 @@ class my_top_block(gr.top_block): if(options.antenna): self.u.set_antenna(options.antenna, 0) - usrp_rate = options.samp_rate + self.usrp_rate = usrp_rate = options.samp_rate self.u.set_samp_rate(usrp_rate) dev_rate = self.u.get_samp_rate() - s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) + s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = filter.window.blackmanharris(self.fft_size) - ffter = fft.fft_vcc(self.fft_size, True, mywindow) + ffter = fft.fft_vcc(self.fft_size, True, mywindow, True) power = 0 for tap in mywindow: power += tap*tap @@ -197,7 +201,7 @@ class my_top_block(gr.top_block): options.gain = float(g.start()+g.stop())/2.0 self.set_gain(options.gain) - print "gain =", options.gain + print "gain =", options.gain def set_next_freq(self): target_freq = self.next_freq @@ -231,6 +235,20 @@ class my_top_block(gr.top_block): def main_loop(tb): + + def nearest_freq(freq, channel_bandwidth): + freq = round(freq / channel_bandwidth, 0) * channel_bandwidth + return freq + + def bin_freq(i_bin, center_freq): + hz_per_bin = tb.usrp_rate / tb.fft_size + freq = center_freq - (tb.usrp_rate / 2) + (hz_per_bin * i_bin) + freq = nearest_freq(freq, tb.channel_bandwidth) + return freq + + bin_start = int(tb.fft_size * ((1 - 0.75) / 2)) + bin_stop = int(tb.fft_size - bin_start) + while 1: # Get the next message sent from the C++ code (blocking call). @@ -238,7 +256,7 @@ def main_loop(tb): m = parse_msg(tb.msgq.delete_head()) # Print center freq so we know that something is happening... - print m.center_freq + #print "m.center_freq:", m.center_freq # FIXME do something useful with the data... @@ -248,6 +266,13 @@ def main_loop(tb): # m.raw_data is a string that contains the binary floats. # You could write this as binary to a file. + for i_bin in range(bin_start, bin_stop): + + # create signal object to find matching signals + freq = int(bin_freq(i_bin, m.center_freq)) + power = float(m.data[i_bin]) + + print freq, power if __name__ == '__main__': t = ThreadClass() |