diff options
author | Tom Rondeau | 2011-07-17 17:25:57 -0400 |
---|---|---|
committer | Tom Rondeau | 2011-07-17 17:25:57 -0400 |
commit | f7b9a0c6922c86cd54c1300ab45209d8e2db13df (patch) | |
tree | 5ede528cd302e85bc40edcad876525659f4e1ed2 /gnuradio-core/src | |
parent | caa4af889f54a696d3a533c77c5016df82f2987c (diff) | |
parent | 04409d2ba42ac5b372a7b6bb7e9c8de5722d76d7 (diff) | |
download | gnuradio-f7b9a0c6922c86cd54c1300ab45209d8e2db13df.tar.gz gnuradio-f7b9a0c6922c86cd54c1300ab45209d8e2db13df.tar.bz2 gnuradio-f7b9a0c6922c86cd54c1300ab45209d8e2db13df.zip |
Merge branch '8psk' into next
Conflicts:
gr-msdd6000/src/Makefile.swig.gen
Diffstat (limited to 'gnuradio-core/src')
20 files changed, 877 insertions, 88 deletions
diff --git a/gnuradio-core/src/lib/filter/Makefile.am b/gnuradio-core/src/lib/filter/Makefile.am index 0314079a2..d8f634c38 100644 --- a/gnuradio-core/src/lib/filter/Makefile.am +++ b/gnuradio-core/src/lib/filter/Makefile.am @@ -188,6 +188,7 @@ EXTRA_DIST += \ # work around automake deficiency libfilter_la_common_SOURCES = \ $(GENERATED_CC) \ + gr_adaptive_fir_ccc.cc \ gr_adaptive_fir_ccf.cc \ gr_cma_equalizer_cc.cc \ gri_fft_filter_fff_generic.cc \ @@ -272,6 +273,7 @@ grinclude_HEADERS = \ ccomplex_dotprod_x86.h \ float_dotprod_generic.h \ float_dotprod_x86.h \ + gr_adaptive_fir_ccc.h \ gr_adaptive_fir_ccf.h \ gr_altivec.h \ gr_cma_equalizer_cc.h \ @@ -357,6 +359,7 @@ noinst_HEADERS = \ swiginclude_HEADERS = \ filter.i \ filter_generated.i \ + gr_adaptive_fir_ccc.i \ gr_adaptive_fir_ccf.i \ gr_cma_equalizer_cc.i \ gr_fft_filter_ccc.i \ diff --git a/gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.cc b/gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.cc new file mode 100644 index 000000000..884caf29c --- /dev/null +++ b/gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.cc @@ -0,0 +1,88 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 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_adaptive_fir_ccc.h> +#include <gr_io_signature.h> + +gr_adaptive_fir_ccc::gr_adaptive_fir_ccc(const char *name, int decimation, + const std::vector<gr_complex> &taps) + : gr_sync_decimator (name, + gr_make_io_signature (1, 1, sizeof(gr_complex)), + gr_make_io_signature (1, 1, sizeof(gr_complex)), + decimation), + d_taps(taps), d_updated(false) +{ + set_history(d_taps.size()); +} + +void +gr_adaptive_fir_ccc::set_taps(const std::vector<gr_complex> &taps) +{ + d_new_taps = taps; + d_updated = true; +} + +gr_complex +gr_adaptive_fir_ccc::filter(gr_complex *x) +{ + // Generic dot product of d_taps[] and in[] + gr_complex acc(0.0, 0.0); + int l = d_taps.size(); + for (int k = 0; k < l; k++) + acc += d_taps[l-k-1] * x[k]; + return acc; +} + +int +gr_adaptive_fir_ccc::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + gr_complex *in = (gr_complex *)input_items[0]; + gr_complex *out = (gr_complex *)output_items[0]; + + if (d_updated) { + d_taps = d_new_taps; + set_history(d_taps.size()); + d_updated = false; + return 0; // history requirements may have changed. + } + + int j = 0, k, l = d_taps.size(); + for (int i = 0; i < noutput_items; i++) { + out[i] = filter(&in[j]); + + // Adjust taps + d_error = error(out[i]); + for (k = 0; k < l; k++) { + update_tap(d_taps[l-k-1], in[j+k]); + } + + j += decimation(); + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.h b/gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.h new file mode 100644 index 000000000..8678255b7 --- /dev/null +++ b/gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.h @@ -0,0 +1,61 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 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_ADAPTIVE_FIR_CCC_H +#define INCLUDED_GR_ADAPTIVE_FIR_CCC_H + +#include <gr_sync_decimator.h> + +/*! + * \brief Adaptive FIR filter with gr_complex input, gr_complex output and float taps + * \ingroup filter_blk + */ +class gr_adaptive_fir_ccc : public gr_sync_decimator +{ +private: + std::vector<gr_complex> d_new_taps; + bool d_updated; + +protected: + gr_complex d_error; + std::vector<gr_complex> d_taps; + + // Override to calculate error signal per output + virtual gr_complex error(const gr_complex &out) = 0; + + // Override to calculate new weight from old, corresponding input + virtual void update_tap(gr_complex &tap, const gr_complex &in) = 0; + + gr_complex filter(gr_complex *x); + + gr_adaptive_fir_ccc(const char *name, int decimation, + const std::vector<gr_complex> &taps); + +public: + void set_taps(const std::vector<gr_complex> &taps); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif diff --git a/gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.i b/gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.i new file mode 100644 index 000000000..7e9a3fac3 --- /dev/null +++ b/gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.i @@ -0,0 +1,31 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 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. + */ + +class gr_adaptive_fir_ccc : public gr_sync_decimator +{ +protected: + gr_adaptive_fir_ccc(char *name, int decimation, + const std::vector<gr_complex> &taps); + +public: + void set_taps(const std::vector<gr_complex> &taps); +}; diff --git a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc index 937899c0d..a52d1d901 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc +++ b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc @@ -37,12 +37,14 @@ gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (double sps, float gain, const std::vector<float> &taps, unsigned int filter_size, float init_phase, - float max_rate_deviation) + float max_rate_deviation, + int osps) { return gnuradio::get_initial_sptr(new gr_pfb_clock_sync_ccf (sps, gain, taps, - filter_size, - init_phase, - max_rate_deviation)); + filter_size, + init_phase, + max_rate_deviation, + osps)); } static int ios[] = {sizeof(gr_complex), sizeof(float), sizeof(float), sizeof(float)}; @@ -51,12 +53,14 @@ gr_pfb_clock_sync_ccf::gr_pfb_clock_sync_ccf (double sps, float gain, const std::vector<float> &taps, unsigned int filter_size, float init_phase, - float max_rate_deviation) + float max_rate_deviation, + int osps) : gr_block ("pfb_clock_sync_ccf", gr_make_io_signature (1, 1, sizeof(gr_complex)), gr_make_io_signaturev (1, 4, iosig)), d_updated (false), d_nfilters(filter_size), - d_max_dev(max_rate_deviation) + d_max_dev(max_rate_deviation), + d_osps(osps) { d_nfilters = filter_size; d_sps = floor(sps); @@ -239,13 +243,13 @@ gr_pfb_clock_sync_ccf::general_work (int noutput_items, } // We need this many to process one output - int nrequired = ninput_items[0] - d_taps_per_filter; + int nrequired = ninput_items[0] - d_taps_per_filter - d_osps; int i = 0, count = 0; float error, error_r, error_i; // produce output as long as we can and there are enough input samples - while((i < noutput_items) && (count < nrequired)) { + while((i < noutput_items-d_osps) && (count < nrequired)) { d_filtnum = (int)floor(d_k); // Keep the current filter number in [0, d_nfilters] @@ -262,7 +266,10 @@ gr_pfb_clock_sync_ccf::general_work (int noutput_items, count -= 1; } - out[i] = d_filters[d_filtnum]->filter(&in[count]); + for(int k = 0; k < d_osps; k++) { + out[i+k] = d_filters[d_filtnum]->filter(&in[count+k]); + } + gr_complex diff = d_diff_filters[d_filtnum]->filter(&in[count]); error_r = out[i].real() * diff.real(); error_i = out[i].imag() * diff.imag(); @@ -275,14 +282,17 @@ gr_pfb_clock_sync_ccf::general_work (int noutput_items, // Keep our rate within a good range d_rate_f = gr_branchless_clip(d_rate_f, d_max_dev); - i++; - count += (int)floor(d_sps); - if(output_items.size() == 4) { - err[i] = error; - outrate[i] = d_rate_f; - outk[i] = d_k; + // FIXME: don't really know what to do about d_osps>1 + for(int k = 0; k < d_osps; k++) { + err[i] = error; + outrate[i] = d_rate_f; + outk[i] = d_k; + } } + + i+=d_osps; + count += (int)floor(d_sps); } consume_each(count); diff --git a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h index 684ac85ce..d4357e3d8 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h +++ b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h @@ -32,7 +32,8 @@ gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (double sps, float gain, const std::vector<float> &taps, unsigned int filter_size=32, float init_phase=0, - float max_rate_deviation=1.5); + float max_rate_deviation=1.5, + int osps=1); class gr_fir_ccf; @@ -47,7 +48,7 @@ class gr_fir_ccf; * derivative of the filtered signal, which in turn maximizes the SNR and * minimizes ISI. * - * This approach works by setting up two filterbanks; one filterbanke contains the + * This approach works by setting up two filterbanks; one filterbank contains the * signal's pulse shaping matched filter (such as a root raised cosine filter), * where each branch of the filterbank contains a different phase of the filter. * The second filterbank contains the derivatives of the filters in the first @@ -85,7 +86,7 @@ class gr_fir_ccf; * equal to (gain^2)/4. * * The clock sync block needs to know the number of samples per symbol (sps), because it - * only returns a single point representing the sample. The sps can be any positive real + * only returns a single point representing the symbol. The sps can be any positive real * number and does not need to be an integer. The filter taps must also be specified. The * taps are generated by first conceiving of the prototype filter that would be the signal's * matched filter. Then interpolate this by the number of filters in the filterbank. These @@ -128,7 +129,8 @@ class gr_pfb_clock_sync_ccf : public gr_block const std::vector<float> &taps, unsigned int filter_size, float init_phase, - float max_rate_deviation); + float max_rate_deviation, + int osps); bool d_updated; double d_sps; @@ -147,6 +149,7 @@ class gr_pfb_clock_sync_ccf : public gr_block float d_max_dev; int d_filtnum; int d_taps_per_filter; + int d_osps; /*! * Build the polyphase filterbank timing synchronizer. @@ -155,7 +158,8 @@ class gr_pfb_clock_sync_ccf : public gr_block const std::vector<float> &taps, unsigned int filter_size, float init_phase, - float max_rate_deviation); + float max_rate_deviation, + int osps); void create_diff_taps(const std::vector<float> &newtaps, std::vector<float> &difftaps); diff --git a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i index 197984287..343ed0912 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i +++ b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i @@ -26,7 +26,8 @@ gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (double sps, float gain, const std::vector<float> &taps, unsigned int filter_size=32, float init_phase=0, - float max_rate_deviation=1.5); + float max_rate_deviation=1.5, + int osps=1); class gr_pfb_clock_sync_ccf : public gr_block { @@ -35,7 +36,8 @@ class gr_pfb_clock_sync_ccf : public gr_block const std::vector<float> &taps, unsigned int filter_size, float init_phase, - float max_rate_deviation); + float max_rate_deviation, + int osps); public: ~gr_pfb_clock_sync_ccf (); diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am index 2a7a4b025..defbbbb0c 100644 --- a/gnuradio-core/src/lib/general/Makefile.am +++ b/gnuradio-core/src/lib/general/Makefile.am @@ -263,8 +263,8 @@ grinclude_HEADERS = \ gr_map_bb.h \ gr_math.h \ gr_misc.h \ - gr_mpsk_receiver_cc.h \ gr_nco.h \ + gr_mpsk_receiver_cc.h \ gr_nlog10_ff.h \ gr_nop.h \ gr_null_sink.h \ diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index e8a18ab19..5a5534129 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -98,6 +98,7 @@ #include <gr_ofdm_cyclic_prefixer.h> #include <gr_ofdm_mapper_bcv.h> #include <gr_ofdm_frame_sink.h> + //#include <gr_ofdm_frame_sink2.h> #include <gr_ofdm_insert_preamble.h> #include <gr_ofdm_sampler.h> #include <gr_regenerate_bb.h> @@ -224,6 +225,7 @@ %include "gr_ofdm_cyclic_prefixer.i" %include "gr_ofdm_mapper_bcv.i" %include "gr_ofdm_frame_sink.i" + //%include "gr_ofdm_frame_sink2.i" %include "gr_ofdm_insert_preamble.i" %include "gr_ofdm_sampler.i" %include "gr_regenerate_bb.i" diff --git a/gnuradio-core/src/lib/general/gr_costas_loop_cc.cc b/gnuradio-core/src/lib/general/gr_costas_loop_cc.cc index f3bfd0951..b77b19745 100644 --- a/gnuradio-core/src/lib/general/gr_costas_loop_cc.cc +++ b/gnuradio-core/src/lib/general/gr_costas_loop_cc.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2010 Free Software Foundation, Inc. + * Copyright 2006,2010,2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -64,12 +64,30 @@ gr_costas_loop_cc::gr_costas_loop_cc (float alpha, float beta, d_phase_detector = &gr_costas_loop_cc::phase_detector_4; break; + case 8: + d_phase_detector = &gr_costas_loop_cc::phase_detector_8; + break; + default: - throw std::invalid_argument("order must be 2 or 4"); + throw std::invalid_argument("order must be 2, 4, or 8"); break; } } +float +gr_costas_loop_cc::phase_detector_8(gr_complex sample) const +{ + float K = sqrt(2.0) - 1; + + if(abs(sample.real()) >= abs(sample.imag())) { + return ((sample.real()>0 ? 1.0 : -1.0) * sample.imag() - + (sample.imag()>0 ? 1.0 : -1.0) * sample.real() * K); + } + else { + return ((sample.real()>0 ? 1.0 : -1.0) * sample.imag() * K - + (sample.imag()>0 ? 1.0 : -1.0) * sample.real()); + } +} float gr_costas_loop_cc::phase_detector_4(gr_complex sample) const diff --git a/gnuradio-core/src/lib/general/gr_costas_loop_cc.h b/gnuradio-core/src/lib/general/gr_costas_loop_cc.h index 3b4aab86c..181880f1c 100644 --- a/gnuradio-core/src/lib/general/gr_costas_loop_cc.h +++ b/gnuradio-core/src/lib/general/gr_costas_loop_cc.h @@ -89,6 +89,12 @@ class gr_costas_loop_cc : public gr_sync_block int order ) throw (std::invalid_argument); + /*! \brief the phase detector circuit for 8th-order PSK loops + * \param sample complex sample + * \return the phase error + */ + float phase_detector_8(gr_complex sample) const; // for 8PSK + /*! \brief the phase detector circuit for fourth-order loops * \param sample complex sample * \return the phase error diff --git a/gnuradio-core/src/lib/general/gr_ofdm_frame_sink2.cc b/gnuradio-core/src/lib/general/gr_ofdm_frame_sink2.cc new file mode 100644 index 000000000..40574b4e9 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_ofdm_frame_sink2.cc @@ -0,0 +1,374 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2008,2010,2011 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_ofdm_frame_sink2.h> +#include <gr_io_signature.h> +#include <gr_expj.h> +#include <gr_math.h> +#include <math.h> +#include <cstdio> +#include <stdexcept> +#include <iostream> +#include <string.h> +#include <gr_constellation.h> + +#define VERBOSE 0 + +inline void +gr_ofdm_frame_sink2::enter_search() +{ + if (VERBOSE) + fprintf(stderr, "@ enter_search\n"); + + d_state = STATE_SYNC_SEARCH; + +} + +inline void +gr_ofdm_frame_sink2::enter_have_sync() +{ + if (VERBOSE) + fprintf(stderr, "@ enter_have_sync\n"); + + d_state = STATE_HAVE_SYNC; + + // clear state of demapper + d_byte_offset = 0; + d_partial_byte = 0; + + d_header = 0; + d_headerbytelen_cnt = 0; + + // Resetting PLL + d_freq = 0.0; + d_phase = 0.0; + fill(d_dfe.begin(), d_dfe.end(), gr_complex(1.0,0.0)); +} + +inline void +gr_ofdm_frame_sink2::enter_have_header() +{ + d_state = STATE_HAVE_HEADER; + + // header consists of two 16-bit shorts in network byte order + // payload length is lower 12 bits + // whitener offset is upper 4 bits + d_packetlen = (d_header >> 16) & 0x0fff; + d_packet_whitener_offset = (d_header >> 28) & 0x000f; + d_packetlen_cnt = 0; + + if (VERBOSE) + fprintf(stderr, "@ enter_have_header (payload_len = %d) (offset = %d)\n", + d_packetlen, d_packet_whitener_offset); +} + + +unsigned int gr_ofdm_frame_sink2::demapper(const gr_complex *in, + unsigned char *out) +{ + unsigned int i=0, bytes_produced=0; + gr_complex carrier; + + carrier=gr_expj(d_phase); + + gr_complex accum_error = 0.0; + //while(i < d_occupied_carriers) { + while(i < d_subcarrier_map.size()) { + if(d_nresid > 0) { + d_partial_byte |= d_resid; + d_byte_offset += d_nresid; + d_nresid = 0; + d_resid = 0; + } + + //while((d_byte_offset < 8) && (i < d_occupied_carriers)) { + while((d_byte_offset < 8) && (i < d_subcarrier_map.size())) { + //gr_complex sigrot = in[i]*carrier*d_dfe[i]; + gr_complex sigrot = in[d_subcarrier_map[i]]*carrier*d_dfe[i]; + + if(d_derotated_output != NULL){ + d_derotated_output[i] = sigrot; + } + + unsigned char bits = d_constell->decision_maker(&sigrot); + + gr_complex closest_sym = d_constell->points()[bits]; + + accum_error += sigrot * conj(closest_sym); + + // FIX THE FOLLOWING STATEMENT + if (norm(sigrot)> 0.001) d_dfe[i] += d_eq_gain*(closest_sym/sigrot-d_dfe[i]); + + i++; + + if((8 - d_byte_offset) >= d_nbits) { + d_partial_byte |= bits << (d_byte_offset); + d_byte_offset += d_nbits; + } + else { + d_nresid = d_nbits-(8-d_byte_offset); + int mask = ((1<<(8-d_byte_offset))-1); + d_partial_byte |= (bits & mask) << d_byte_offset; + d_resid = bits >> (8-d_byte_offset); + d_byte_offset += (d_nbits - d_nresid); + } + //printf("demod symbol: %.4f + j%.4f bits: %x partial_byte: %x byte_offset: %d resid: %x nresid: %d\n", + // in[i-1].real(), in[i-1].imag(), bits, d_partial_byte, d_byte_offset, d_resid, d_nresid); + } + + if(d_byte_offset == 8) { + //printf("demod byte: %x \n\n", d_partial_byte); + out[bytes_produced++] = d_partial_byte; + d_byte_offset = 0; + d_partial_byte = 0; + } + } + //std::cerr << "accum_error " << accum_error << std::endl; + + float angle = arg(accum_error); + + d_freq = d_freq - d_freq_gain*angle; + d_phase = d_phase + d_freq - d_phase_gain*angle; + if (d_phase >= 2*M_PI) d_phase -= 2*M_PI; + if (d_phase <0) d_phase += 2*M_PI; + + //if(VERBOSE) + // std::cerr << angle << "\t" << d_freq << "\t" << d_phase << "\t" << std::endl; + + return bytes_produced; +} + + +gr_ofdm_frame_sink2_sptr +gr_make_ofdm_frame_sink2(gr_constellation_sptr constell, + gr_msg_queue_sptr target_queue, unsigned int occupied_carriers, + float phase_gain, float freq_gain) +{ + return gnuradio::get_initial_sptr(new gr_ofdm_frame_sink2(constell, + target_queue, occupied_carriers, + phase_gain, freq_gain)); +} + + +gr_ofdm_frame_sink2::gr_ofdm_frame_sink2(gr_constellation_sptr constell, + gr_msg_queue_sptr target_queue, unsigned int occupied_carriers, + float phase_gain, float freq_gain) + : gr_sync_block ("ofdm_frame_sink2", + gr_make_io_signature2 (2, 2, sizeof(gr_complex)*occupied_carriers, sizeof(char)), + gr_make_io_signature (1, 1, sizeof(gr_complex)*occupied_carriers)), + d_constell(constell), + d_target_queue(target_queue), d_occupied_carriers(occupied_carriers), + d_byte_offset(0), d_partial_byte(0), + d_resid(0), d_nresid(0),d_phase(0),d_freq(0),d_phase_gain(phase_gain),d_freq_gain(freq_gain), + d_eq_gain(0.05) +{ + if (d_constell->dimensionality() != 1) + throw std::runtime_error ("This receiver only works with constellations of dimension 1."); + + std::string carriers = "FE7F"; + + // A bit hacky to fill out carriers to occupied_carriers length + int diff = (d_occupied_carriers - 4*carriers.length()); + while(diff > 7) { + carriers.insert(0, "f"); + carriers.insert(carriers.length(), "f"); + diff -= 8; + } + + // if there's extras left to be processed + // divide remaining to put on either side of current map + // all of this is done to stick with the concept of a carrier map string that + // can be later passed by the user, even though it'd be cleaner to just do this + // on the carrier map itself + int diff_left=0; + int diff_right=0; + + // dictionary to convert from integers to ascii hex representation + char abc[16] = {'0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + if(diff > 0) { + char c[2] = {0,0}; + + diff_left = (int)ceil((float)diff/2.0f); // number of carriers to put on the left side + c[0] = abc[(1 << diff_left) - 1]; // convert to bits and move to ASCI integer + carriers.insert(0, c); + + diff_right = diff - diff_left; // number of carriers to put on the right side + c[0] = abc[0xF^((1 << diff_right) - 1)]; // convert to bits and move to ASCI integer + carriers.insert(carriers.length(), c); + } + + // It seemed like such a good idea at the time... + // because we are only dealing with the occupied_carriers + // at this point, the diff_left in the following compensates + // for any offset from the 0th carrier introduced + unsigned int i,j,k; + for(i = 0; i < (d_occupied_carriers/4)+diff_left; i++) { + char c = carriers[i]; + for(j = 0; j < 4; j++) { + k = (strtol(&c, NULL, 16) >> (3-j)) & 0x1; + if(k) { + d_subcarrier_map.push_back(4*i + j - diff_left); + } + } + } + + // make sure we stay in the limit currently imposed by the occupied_carriers + if(d_subcarrier_map.size() > d_occupied_carriers) { + throw std::invalid_argument("gr_ofdm_mapper_bcv: subcarriers allocated exceeds size of occupied carriers"); + } + + d_bytes_out = new unsigned char[d_occupied_carriers]; + d_dfe.resize(occupied_carriers); + fill(d_dfe.begin(), d_dfe.end(), gr_complex(1.0,0.0)); + + d_nbits = d_constell->bits_per_symbol(); + + enter_search(); +} + +gr_ofdm_frame_sink2::~gr_ofdm_frame_sink2 () +{ + delete [] d_bytes_out; +} + + +int +gr_ofdm_frame_sink2::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const gr_complex *in = (const gr_complex *) input_items[0]; + const char *sig = (const char *) input_items[1]; + unsigned int j = 0; + unsigned int bytes=0; + + // If the output is connected, send it the derotated symbols + if(output_items.size() >= 1) + d_derotated_output = (gr_complex *)output_items[0]; + else + d_derotated_output = NULL; + + if (VERBOSE) + fprintf(stderr,">>> Entering state machine\n"); + + switch(d_state) { + + case STATE_SYNC_SEARCH: // Look for flag indicating beginning of pkt + if (VERBOSE) + fprintf(stderr,"SYNC Search, noutput=%d\n", noutput_items); + + if (sig[0]) { // Found it, set up for header decode + enter_have_sync(); + } + break; + + case STATE_HAVE_SYNC: + // only demod after getting the preamble signal; otherwise, the + // equalizer taps will screw with the PLL performance + bytes = demapper(&in[0], d_bytes_out); + + if (VERBOSE) { + if(sig[0]) + printf("ERROR -- Found SYNC in HAVE_SYNC\n"); + fprintf(stderr,"Header Search bitcnt=%d, header=0x%08x\n", + d_headerbytelen_cnt, d_header); + } + + j = 0; + while(j < bytes) { + d_header = (d_header << 8) | (d_bytes_out[j] & 0xFF); + j++; + + if (++d_headerbytelen_cnt == HEADERBYTELEN) { + + if (VERBOSE) + fprintf(stderr, "got header: 0x%08x\n", d_header); + + // we have a full header, check to see if it has been received properly + if (header_ok()){ + enter_have_header(); + + if (VERBOSE) + printf("\nPacket Length: %d\n", d_packetlen); + + while((j < bytes) && (d_packetlen_cnt < d_packetlen)) { + d_packet[d_packetlen_cnt++] = d_bytes_out[j++]; + } + + if(d_packetlen_cnt == d_packetlen) { + gr_message_sptr msg = + gr_make_message(0, d_packet_whitener_offset, 0, d_packetlen); + memcpy(msg->msg(), d_packet, d_packetlen_cnt); + d_target_queue->insert_tail(msg); // send it + msg.reset(); // free it up + + enter_search(); + } + } + else { + enter_search(); // bad header + } + } + } + break; + + case STATE_HAVE_HEADER: + bytes = demapper(&in[0], d_bytes_out); + + if (VERBOSE) { + if(sig[0]) + printf("ERROR -- Found SYNC in HAVE_HEADER at %d, length of %d\n", d_packetlen_cnt, d_packetlen); + fprintf(stderr,"Packet Build\n"); + } + + j = 0; + while(j < bytes) { + d_packet[d_packetlen_cnt++] = d_bytes_out[j++]; + + if (d_packetlen_cnt == d_packetlen){ // packet is filled + // build a message + // NOTE: passing header field as arg1 is not scalable + gr_message_sptr msg = + gr_make_message(0, d_packet_whitener_offset, 0, d_packetlen_cnt); + memcpy(msg->msg(), d_packet, d_packetlen_cnt); + + d_target_queue->insert_tail(msg); // send it + msg.reset(); // free it up + + enter_search(); + break; + } + } + break; + + default: + assert(0); + + } // switch + + return 1; +} diff --git a/gnuradio-core/src/lib/general/gr_ofdm_frame_sink2.h b/gnuradio-core/src/lib/general/gr_ofdm_frame_sink2.h new file mode 100644 index 000000000..de8c6a37e --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_ofdm_frame_sink2.h @@ -0,0 +1,120 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2011 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_OFDM_FRAME_SINK2_H +#define INCLUDED_GR_OFDM_FRAME_SINK2_H + +#include <gr_sync_block.h> +#include <gr_msg_queue.h> +#include <gr_constellation.h> + +class gr_ofdm_frame_sink2; +typedef boost::shared_ptr<gr_ofdm_frame_sink2> gr_ofdm_frame_sink2_sptr; + +gr_ofdm_frame_sink2_sptr +gr_make_ofdm_frame_sink2 (gr_constellation_sptr constell, + gr_msg_queue_sptr target_queue, unsigned int occupied_tones, + float phase_gain=0.25, float freq_gain=0.25*0.25/4.0); + +/*! + * \brief Takes an OFDM symbol in, demaps it into bits of 0's and 1's, packs + * them into packets, and sends to to a message queue sink. + * \ingroup sink_blk + * \ingroup ofdm_blk + * + * NOTE: The mod input parameter simply chooses a pre-defined demapper/slicer. Eventually, + * we want to be able to pass in a reference to an object to do the demapping and slicing + * for a given modulation type. + */ +class gr_ofdm_frame_sink2 : public gr_sync_block +{ + friend gr_ofdm_frame_sink2_sptr + gr_make_ofdm_frame_sink2 (gr_constellation_sptr constell, + gr_msg_queue_sptr target_queue, unsigned int occupied_tones, + float phase_gain, float freq_gain); + + private: + enum state_t {STATE_SYNC_SEARCH, STATE_HAVE_SYNC, STATE_HAVE_HEADER}; + + static const int MAX_PKT_LEN = 4096; + static const int HEADERBYTELEN = 4; + + gr_msg_queue_sptr d_target_queue; // where to send the packet when received + state_t d_state; + unsigned int d_header; // header bits + int d_headerbytelen_cnt; // how many so far + + unsigned char *d_bytes_out; // hold the current bytes produced by the demapper + + unsigned int d_occupied_carriers; + unsigned int d_byte_offset; + unsigned int d_partial_byte; + + unsigned char d_packet[MAX_PKT_LEN]; // assembled payload + int d_packetlen; // length of packet + int d_packet_whitener_offset; // offset into whitener string to use + int d_packetlen_cnt; // how many so far + + gr_complex * d_derotated_output; // Pointer to output stream to send deroated symbols out + + gr_constellation_sptr d_constell; + std::vector<gr_complex> d_dfe; + unsigned int d_nbits; + + unsigned char d_resid; + unsigned int d_nresid; + float d_phase; + float d_freq; + float d_phase_gain; + float d_freq_gain; + float d_eq_gain; + + std::vector<int> d_subcarrier_map; + + protected: + gr_ofdm_frame_sink2(gr_constellation_sptr constell, + gr_msg_queue_sptr target_queue, unsigned int occupied_tones, + float phase_gain, float freq_gain); + + void enter_search(); + void enter_have_sync(); + void enter_have_header(); + + bool header_ok() + { + // confirm that two copies of header info are identical + return ((d_header >> 16) ^ (d_header & 0xffff)) == 0; + } + + unsigned char slicer(const gr_complex x); + unsigned int demapper(const gr_complex *in, + unsigned char *out); + + public: + ~gr_ofdm_frame_sink2(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_GR_OFDM_FRAME_SINK2_H */ diff --git a/gnuradio-core/src/lib/general/gr_ofdm_frame_sink2.i b/gnuradio-core/src/lib/general/gr_ofdm_frame_sink2.i new file mode 100644 index 000000000..8fa320089 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_ofdm_frame_sink2.i @@ -0,0 +1,39 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2011 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,ofdm_frame_sink2); + +gr_ofdm_frame_sink2_sptr +gr_make_ofdm_frame_sink2(gr_constellation_sptr constell, + gr_msg_queue_sptr target_queue, unsigned int occupied_tones, + float phase_gain=0.25, float freq_gain=0.25*0.25/4); + +class gr_ofdm_frame_sink2 : public gr_sync_block +{ + protected: + gr_ofdm_frame_sink2(gr_constellation_sptr constell, + gr_msg_queue_sptr target_queue, unsigned int occupied_tones, + float phase_gain, float freq_gain); + + public: + ~gr_ofdm_frame_sink2(); +}; diff --git a/gnuradio-core/src/lib/swig/Makefile.am b/gnuradio-core/src/lib/swig/Makefile.am index f8e7640ae..d304a2123 100644 --- a/gnuradio-core/src/lib/swig/Makefile.am +++ b/gnuradio-core/src/lib/swig/Makefile.am @@ -45,7 +45,7 @@ TOP_SWIG_IFILES = \ swiginclude_HEADERS = \ gnuradio.i \ gr_swig_block_magic.i \ - gr_shared_ptr.i + gr_shared_ptr.i # SWIG headers that get installed in ${prefix}/include/gnuradio/swig/... nobase_swiginclude_HEADERS = \ diff --git a/gnuradio-core/src/lib/swig/Makefile.swig.gen b/gnuradio-core/src/lib/swig/Makefile.swig.gen index 0c3247565..cede68817 100644 --- a/gnuradio-core/src/lib/swig/Makefile.swig.gen +++ b/gnuradio-core/src/lib/swig/Makefile.swig.gen @@ -105,7 +105,7 @@ _gnuradio_core_runtime_la_CXXFLAGS = \ $(gnuradio_core_runtime_la_swig_cxxflags) python/gnuradio_core_runtime.cc: gnuradio_core_runtime.py -gnuradio_core_runtime.py: gnuradio_core_runtime.i +gnuradio_core_runtime.py: gnuradio_core_runtime.i # Include the python dependencies for this file -include python/gnuradio_core_runtime.d @@ -250,7 +250,7 @@ _gnuradio_core_general_la_CXXFLAGS = \ $(gnuradio_core_general_la_swig_cxxflags) python/gnuradio_core_general.cc: gnuradio_core_general.py -gnuradio_core_general.py: gnuradio_core_general.i +gnuradio_core_general.py: gnuradio_core_general.i # Include the python dependencies for this file -include python/gnuradio_core_general.d @@ -395,7 +395,7 @@ _gnuradio_core_gengen_la_CXXFLAGS = \ $(gnuradio_core_gengen_la_swig_cxxflags) python/gnuradio_core_gengen.cc: gnuradio_core_gengen.py -gnuradio_core_gengen.py: gnuradio_core_gengen.i +gnuradio_core_gengen.py: gnuradio_core_gengen.i # Include the python dependencies for this file -include python/gnuradio_core_gengen.d @@ -540,7 +540,7 @@ _gnuradio_core_filter_la_CXXFLAGS = \ $(gnuradio_core_filter_la_swig_cxxflags) python/gnuradio_core_filter.cc: gnuradio_core_filter.py -gnuradio_core_filter.py: gnuradio_core_filter.i +gnuradio_core_filter.py: gnuradio_core_filter.i # Include the python dependencies for this file -include python/gnuradio_core_filter.d @@ -685,7 +685,7 @@ _gnuradio_core_io_la_CXXFLAGS = \ $(gnuradio_core_io_la_swig_cxxflags) python/gnuradio_core_io.cc: gnuradio_core_io.py -gnuradio_core_io.py: gnuradio_core_io.i +gnuradio_core_io.py: gnuradio_core_io.i # Include the python dependencies for this file -include python/gnuradio_core_io.d @@ -830,7 +830,7 @@ _gnuradio_core_hier_la_CXXFLAGS = \ $(gnuradio_core_hier_la_swig_cxxflags) python/gnuradio_core_hier.cc: gnuradio_core_hier.py -gnuradio_core_hier.py: gnuradio_core_hier.i +gnuradio_core_hier.py: gnuradio_core_hier.i # Include the python dependencies for this file -include python/gnuradio_core_hier.d diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/ofdm.py b/gnuradio-core/src/python/gnuradio/blks2impl/ofdm.py index 2663f7cf8..3b1cd12ac 100644 --- a/gnuradio-core/src/python/gnuradio/blks2impl/ofdm.py +++ b/gnuradio-core/src/python/gnuradio/blks2impl/ofdm.py @@ -21,12 +21,26 @@ # import math -from gnuradio import gr, ofdm_packet_utils +from gnuradio import gr, ofdm_packet_utils, modulation_utils2 import gnuradio.gr.gr_threading as _threading import psk, qam from gnuradio.blks2impl.ofdm_receiver import ofdm_receiver +def _add_common_options(normal, expert): + """ + Adds OFDM-specific options to the Options Parser that are common + both to the modulator and demodulator. + """ + mods_list = ", ".join(modulation_utils2.type_1_constellations().keys()) + normal.add_option("-m", "--modulation", type="string", default="psk", + help="set modulation type (" + mods_list + ") [default=%default]") + expert.add_option("", "--fft-length", type="intx", default=512, + help="set the number of FFT bins [default=%default]") + expert.add_option("", "--occupied-tones", type="intx", default=200, + help="set the number of occupied FFT bins [default=%default]") + expert.add_option("", "--cp-length", type="intx", default=128, + help="set the number of bits in the cyclic prefix [default=%default]") # ///////////////////////////////////////////////////////////////////////////// # mod/demod with packets as i/o @@ -61,6 +75,8 @@ class ofdm_mod(gr.hier_block2): self._fft_length = options.fft_length self._occupied_tones = options.occupied_tones self._cp_length = options.cp_length + + arity = options.constellation_points win = [] #[1 for i in range(self._fft_length)] @@ -82,19 +98,9 @@ class ofdm_mod(gr.hier_block2): symbol_length = options.fft_length + options.cp_length - mods = {"bpsk": 2, "qpsk": 4, "8psk": 8, "qam8": 8, "qam16": 16, "qam64": 64, "qam256": 256} - arity = mods[self._modulation] - - rot = 1 - if self._modulation == "qpsk": - rot = (0.707+0.707j) - - if(self._modulation.find("psk") >= 0): - rotated_const = map(lambda pt: pt * rot, psk.gray_constellation[arity]) - elif(self._modulation.find("qam") >= 0): - rotated_const = map(lambda pt: pt * rot, qam.constellation[arity]) - #print rotated_const - self._pkt_input = gr.ofdm_mapper_bcv(rotated_const, msgq_limit, + const = modulation_utils2.type_1_constellations()[self._modulation](arity).points() + + self._pkt_input = gr.ofdm_mapper_bcv(const, msgq_limit, options.occupied_tones, options.fft_length) self.preambles = gr.ofdm_insert_preamble(self._fft_length, padded_preambles) @@ -140,14 +146,10 @@ class ofdm_mod(gr.hier_block2): """ Adds OFDM-specific options to the Options Parser """ - normal.add_option("-m", "--modulation", type="string", default="bpsk", - help="set modulation type (bpsk, qpsk, 8psk, qam{16,64}) [default=%default]") - expert.add_option("", "--fft-length", type="intx", default=512, - help="set the number of FFT bins [default=%default]") - expert.add_option("", "--occupied-tones", type="intx", default=200, - help="set the number of occupied FFT bins [default=%default]") - expert.add_option("", "--cp-length", type="intx", default=128, - help="set the number of bits in the cyclic prefix [default=%default]") + _add_common_options(normal, expert) + for mod in modulation_utils2.type_1_mods().values(): + mod.add_options(expert) + # Make a static method to call before instantiation add_options = staticmethod(add_options) @@ -196,6 +198,9 @@ class ofdm_demod(gr.hier_block2): self._cp_length = options.cp_length self._snr = options.snr + arity = options.constellation_points + print("con points is %s" % options.constellation_points) + # Use freq domain to get doubled-up known symbol for correlation in time domain zeros_on_left = int(math.ceil((self._fft_length - self._occupied_tones)/2.0)) ksfreq = known_symbols_4512_3[0:self._occupied_tones] @@ -211,22 +216,11 @@ class ofdm_demod(gr.hier_block2): self._occupied_tones, self._snr, preambles, options.log) - mods = {"bpsk": 2, "qpsk": 4, "8psk": 8, "qam8": 8, "qam16": 16, "qam64": 64, "qam256": 256} - arity = mods[self._modulation] - - rot = 1 - if self._modulation == "qpsk": - rot = (0.707+0.707j) - - if(self._modulation.find("psk") >= 0): - rotated_const = map(lambda pt: pt * rot, psk.gray_constellation[arity]) - elif(self._modulation.find("qam") >= 0): - rotated_const = map(lambda pt: pt * rot, qam.constellation[arity]) - #print rotated_const + constell = modulation_utils2.type_1_constellations()[self._modulation](arity) phgain = 0.25 frgain = phgain*phgain / 4.0 - self.ofdm_demod = gr.ofdm_frame_sink(rotated_const, range(arity), + self.ofdm_demod = gr.ofdm_frame_sink2(constell.base(), self._rcvd_pktq, self._occupied_tones, phgain, frgain) @@ -253,14 +247,9 @@ class ofdm_demod(gr.hier_block2): """ Adds OFDM-specific options to the Options Parser """ - normal.add_option("-m", "--modulation", type="string", default="bpsk", - help="set modulation type (bpsk or qpsk) [default=%default]") - expert.add_option("", "--fft-length", type="intx", default=512, - help="set the number of FFT bins [default=%default]") - expert.add_option("", "--occupied-tones", type="intx", default=200, - help="set the number of occupied FFT bins [default=%default]") - expert.add_option("", "--cp-length", type="intx", default=128, - help="set the number of bits in the cyclic prefix [default=%default]") + _add_common_options(normal, expert) + for mod in modulation_utils2.type_1_mods().values(): + mod.add_options(expert) # Make a static method to call before instantiation add_options = staticmethod(add_options) diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/pkt.py b/gnuradio-core/src/python/gnuradio/blks2impl/pkt.py index 908437ef2..aa720d1a5 100644 --- a/gnuradio-core/src/python/gnuradio/blks2impl/pkt.py +++ b/gnuradio-core/src/python/gnuradio/blks2impl/pkt.py @@ -34,7 +34,8 @@ class mod_pkts(gr.hier_block2): Send packets by calling send_pkt """ - def __init__(self, modulator, access_code=None, msgq_limit=2, pad_for_usrp=True, use_whitener_offset=False): + def __init__(self, modulator, access_code=None, msgq_limit=2, pad_for_usrp=True, use_whitener_offset=False, + modulate=True): """ Hierarchical block for sending packets @@ -49,13 +50,18 @@ class mod_pkts(gr.hier_block2): @type msgq_limit: int @param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples @param use_whitener_offset: If true, start of whitener XOR string is incremented each packet + @param modulate: If false, no modulation will be performed. See gmsk_mod for remaining parameters """ + if modulate: + output_size = gr.sizeof_gr_complex + else: + output_size = gr.sizeof_char gr.hier_block2.__init__(self, "mod_pkts", gr.io_signature(0, 0, 0), # Input signature - gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature + gr.io_signature(1, 1, output_size)) # Output signature self._modulator = modulator self._pad_for_usrp = pad_for_usrp @@ -70,7 +76,10 @@ class mod_pkts(gr.hier_block2): # accepts messages from the outside world self._pkt_input = gr.message_source(gr.sizeof_char, msgq_limit) - self.connect(self._pkt_input, self._modulator, self) + if modulate: + self.connect(self._pkt_input, self._modulator, self) + else: + self.connect(self._pkt_input, self) def send_pkt(self, payload='', eof=False): """ @@ -106,13 +115,15 @@ class demod_pkts(gr.hier_block2): app via the callback. """ - def __init__(self, demodulator, access_code=None, callback=None, threshold=-1): + def __init__(self, demodulator, access_code=None, callback=None, threshold=-1, demodulate=True): """ Hierarchical block for demodulating and deframing packets. The input is the complex modulated signal at baseband. Demodulated packets are sent to the handler. + If demodulator is None it is assumed the input is already demodulated. + @param demodulator: instance of demodulator class (gr_block or hier_block2) @type demodulator: complex baseband in @param access_code: AKA sync vector @@ -123,9 +134,14 @@ class demod_pkts(gr.hier_block2): @type threshold: int """ + if demodulator is not None: + input_size = gr.sizeof_gr_complex + else: + input_size = gr.sizeof_char + gr.hier_block2.__init__(self, "demod_pkts", - gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature - gr.io_signature(0, 0, 0)) # Output signature + gr.io_signature(1, 1, input_size), # Input signature + gr.io_signature(0, 0, 0)) # Output signature self._demodulator = demodulator if access_code is None: @@ -141,9 +157,13 @@ class demod_pkts(gr.hier_block2): self.correlator = gr.correlate_access_code_bb(access_code, threshold) self.framer_sink = gr.framer_sink_1(self._rcvd_pktq) - self.connect(self, self._demodulator, self.correlator, self.framer_sink) + if self._demodulator is not None: + self.connect(self, self._demodulator, self.correlator, self.framer_sink) + else: + self.connect(self, self.correlator, self.framer_sink) - self._watcher = _queue_watcher_thread(self._rcvd_pktq, callback) + if callback is not None: + self._watcher = _queue_watcher_thread(self._rcvd_pktq, callback) class _queue_watcher_thread(_threading.Thread): diff --git a/gnuradio-core/src/python/gnuradio/gr_xmlrunner.py b/gnuradio-core/src/python/gnuradio/gr_xmlrunner.py index ded77f5f3..c3dc5cf13 100644 --- a/gnuradio-core/src/python/gnuradio/gr_xmlrunner.py +++ b/gnuradio-core/src/python/gnuradio/gr_xmlrunner.py @@ -6,8 +6,6 @@ XML Test Runner for PyUnit # the Public Domain. With contributions by Paolo Borelli and others. # Added to GNU Radio Oct. 3, 2010 -from __future__ import with_statement - __version__ = "0.1" import os.path @@ -185,7 +183,9 @@ class XMLTestRunner(object): result = _XMLTestResult(classname) start_time = time.time() - with _fake_std_streams(): + fss = _fake_std_streams() + fss.__enter__() + try: test(result) try: out_s = sys.stdout.getvalue() @@ -195,6 +195,8 @@ class XMLTestRunner(object): err_s = sys.stderr.getvalue() except AttributeError: err_s = "" + finally: + fss.__exit__(None, None, None) time_taken = time.time() - start_time result.print_report(stream, time_taken, out_s, err_s) @@ -218,8 +220,8 @@ class _fake_std_streams(object): def __enter__(self): self._orig_stdout = sys.stdout self._orig_stderr = sys.stderr - sys.stdout = StringIO() - sys.stderr = StringIO() + #sys.stdout = StringIO() + #sys.stderr = StringIO() def __exit__(self, exc_type, exc_val, exc_tb): sys.stdout = self._orig_stdout diff --git a/gnuradio-core/src/python/gnuradio/modulation_utils2.py b/gnuradio-core/src/python/gnuradio/modulation_utils2.py index c5dba3e79..f30055f4a 100644 --- a/gnuradio-core/src/python/gnuradio/modulation_utils2.py +++ b/gnuradio-core/src/python/gnuradio/modulation_utils2.py @@ -47,6 +47,15 @@ def type_1_demods(): def add_type_1_demod(name, demod_class): _type_1_demodulators[name] = demod_class +# Also record the constellation making functions of the modulations +_type_1_constellations = {} + +def type_1_constellations(): + return _type_1_constellations + +def add_type_1_constellation(name, constellation): + _type_1_constellations[name] = constellation + def extract_kwargs_from_options(function, excluded_args, options): """ @@ -79,3 +88,14 @@ def extract_kwargs_from_options(function, excluded_args, options): if getattr(options, kw) is not None: d[kw] = getattr(options, kw) return d + +def extract_kwargs_from_options_for_class(cls, options): + """ + Given command line options, create dictionary suitable for passing to __init__ + """ + d = extract_kwargs_from_options( + cls.__init__, ('self',), options) + for base in cls.__bases__: + if hasattr(base, 'extract_kwargs_from_options'): + d.update(base.extract_kwargs_from_options(options)) + return d |