From ce9a41e69f5e3b9e0280d22fa778d167c3982db7 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Tue, 8 Sep 2009 21:08:29 -0700 Subject: [PATCH] Added HRPT deframer block --- gr-noaa/grc/Makefile.am | 1 + gr-noaa/grc/noaa_hrpt_deframer.xml | 12 + gr-noaa/grc/usrp_rx_hrpt.grc | 367 +++++++++++++++-------------- gr-noaa/grc/usrp_rx_hrpt.py | 16 +- gr-noaa/lib/Makefile.am | 2 + gr-noaa/lib/noaa_hrpt_deframer.cc | 102 ++++++++ gr-noaa/lib/noaa_hrpt_deframer.h | 52 ++++ gr-noaa/swig/Makefile.am | 1 + gr-noaa/swig/noaa_hrpt_deframer.i | 32 +++ gr-noaa/swig/noaa_swig.i | 2 + 10 files changed, 406 insertions(+), 181 deletions(-) create mode 100644 gr-noaa/grc/noaa_hrpt_deframer.xml create mode 100644 gr-noaa/lib/noaa_hrpt_deframer.cc create mode 100644 gr-noaa/lib/noaa_hrpt_deframer.h create mode 100644 gr-noaa/swig/noaa_hrpt_deframer.i diff --git a/gr-noaa/grc/Makefile.am b/gr-noaa/grc/Makefile.am index e56bd354..4e4c0bae 100644 --- a/gr-noaa/grc/Makefile.am +++ b/gr-noaa/grc/Makefile.am @@ -28,6 +28,7 @@ dist_bin_SCRIPTS = \ usrp_rx_lrit.py dist_grcblocks_DATA = \ + noaa_hrpt_deframer.xml \ noaa_hrpt_pll_cf.xml \ noaa_hrpt_sync_fb.xml diff --git a/gr-noaa/grc/noaa_hrpt_deframer.xml b/gr-noaa/grc/noaa_hrpt_deframer.xml new file mode 100644 index 00000000..bc68f71d --- /dev/null +++ b/gr-noaa/grc/noaa_hrpt_deframer.xml @@ -0,0 +1,12 @@ + + + HRPT Deframer + noaa_hrpt_deframer + NOAA + from gnuradio import noaa + noaa.hrpt_deframer() + + in + byte + + diff --git a/gr-noaa/grc/usrp_rx_hrpt.grc b/gr-noaa/grc/usrp_rx_hrpt.grc index 25b13353..71584674 100644 --- a/gr-noaa/grc/usrp_rx_hrpt.grc +++ b/gr-noaa/grc/usrp_rx_hrpt.grc @@ -1,6 +1,6 @@ - Tue Sep 8 14:57:48 2009 + Tue Sep 8 21:03:12 2009 options @@ -377,41 +377,6 @@ 0 - - gr_file_source - - id - src - - - _enabled - True - - - file - poes-d16.dat - - - type - complex - - - repeat - False - - - vlen - 1 - - - _coordinate - (34, 423) - - - _rotation - 0 - - gr_agc_xx @@ -540,41 +505,6 @@ 0 - - noaa_hrpt_sync_fb - - id - noaa_hrpt_sync_fb_0 - - - _enabled - True - - - alpha - 0.001 - - - beta - 0.001**2/4.0 - - - sps - sps - - - max_offset - max_sync_offset - - - _coordinate - (856, 494) - - - _rotation - 0 - - virtual_sink @@ -618,10 +548,10 @@ - gr_add_const_vxx + wxgui_scopesink2 id - gr_add_const_vxx_0 + wxgui_scopesink2_0_0_0_0 _enabled @@ -632,66 +562,103 @@ float - const - 48.0 + title + Post-SYNC - vlen + samp_rate + sym_rate + + + v_scale + 0.5 + + + t_scale + 20.0/sym_rate + + + ac_couple + False + + + xy_mode + False + + + num_inputs 1 + + grid_pos + 1, 0, 1, 1 + + + notebook + displays, 1 + _coordinate - (692, 919) + (452, 990) _rotation - 0 + 180 - gr_float_to_char + wxgui_scopesink2 id - gr_float_to_char_0 + wxgui_scopesink2_0 _enabled True - _coordinate - (848, 923) + type + complex - _rotation - 0 + title + RX Waveform - - - gr_file_sink - id - gr_file_sink_0 + samp_rate + sample_rate - _enabled - True + v_scale + 0 - file - bits.dat + t_scale + 20.0/sample_rate - type - byte + ac_couple + False - vlen + xy_mode + False + + + num_inputs 1 + + grid_pos + 1, 0, 1, 1 + + + notebook + displays, 0 + _coordinate - (1020, 919) + (433, 570) _rotation @@ -702,7 +669,7 @@ wxgui_scopesink2 id - wxgui_scopesink2_0_0_0_0 + wxgui_scopesink2_0_0 _enabled @@ -714,11 +681,11 @@ title - Post-SYNC + Post-PLL samp_rate - sym_rate + sample_rate v_scale @@ -726,7 +693,7 @@ t_scale - 20.0/sym_rate + 20.0/sample_rate ac_couple @@ -742,7 +709,7 @@ grid_pos - 1, 0, 1, 1 + 0, 0, 1, 1 notebook @@ -750,7 +717,7 @@ _coordinate - (452, 990) + (618, 335) _rotation @@ -758,78 +725,88 @@ - wxgui_fftsink2 + noaa_hrpt_sync_fb id - rx_fftsink + noaa_hrpt_sync_fb_0 _enabled True - type - complex + alpha + 0.001 - title - RX Spectrum + beta + 0.001**2/4.0 - samp_rate - sample_rate + sps + sps - baseband_freq - 1698e6 + max_offset + max_sync_offset - y_per_div - 5 + _coordinate + (856, 494) - y_divs - 8 + _rotation + 0 + + + noaa_hrpt_deframer - ref_level - 20 + id + noaa_hrpt_deframer_0 - ref_scale - 2.0 + _enabled + True - fft_size - 1024 + _coordinate + (1110, 631) - fft_rate - 30 + _rotation + 0 + + + gr_file_source - peak_hold - False + id + src - average + _enabled True - avg_alpha - 0.1 + file + poes-d16.dat - grid_pos - 0, 0, 1, 1 + type + complex - notebook - displays, 0 + repeat + True + + + vlen + 1 _coordinate - (434, 269) + (34, 423) _rotation @@ -837,58 +814,80 @@ - wxgui_scopesink2 + gr_add_const_vxx id - wxgui_scopesink2_0 + gr_add_const_vxx_0 _enabled - True + False type - complex + float - title - RX Waveform + const + 48.0 - samp_rate - sample_rate + vlen + 1 - v_scale + _coordinate + (692, 919) + + + _rotation 0 + + + gr_float_to_char - t_scale - 20.0/sample_rate + id + gr_float_to_char_0 - ac_couple + _enabled False - xy_mode + _coordinate + (848, 923) + + + _rotation + 0 + + + + gr_file_sink + + id + gr_file_sink_0 + + + _enabled False - num_inputs - 1 + file + bits.dat - grid_pos - 1, 0, 1, 1 + type + byte - notebook - displays, 0 + vlen + 1 _coordinate - (433, 570) + (1020, 919) _rotation @@ -896,10 +895,10 @@ - wxgui_scopesink2 + wxgui_fftsink2 id - wxgui_scopesink2_0_0 + rx_fftsink _enabled @@ -907,35 +906,55 @@ type - float + complex title - Post-PLL + RX Spectrum samp_rate sample_rate - v_scale - 0.5 + baseband_freq + 1698e6 - t_scale - 20.0/sample_rate + y_per_div + 5 - ac_couple - False + y_divs + 8 - xy_mode + ref_level + -5 + + + ref_scale + 2.0 + + + fft_size + 1024 + + + fft_rate + 30 + + + peak_hold False - num_inputs - 1 + average + True + + + avg_alpha + 0.1 grid_pos @@ -943,15 +962,15 @@ notebook - displays, 1 + displays, 0 _coordinate - (618, 335) + (434, 269) _rotation - 180 + 0 @@ -1032,4 +1051,10 @@ 0 0 + + noaa_hrpt_sync_fb_0 + noaa_hrpt_deframer_0 + 0 + 0 + diff --git a/gr-noaa/grc/usrp_rx_hrpt.py b/gr-noaa/grc/usrp_rx_hrpt.py index 10e2f31c..40cc517f 100755 --- a/gr-noaa/grc/usrp_rx_hrpt.py +++ b/gr-noaa/grc/usrp_rx_hrpt.py @@ -2,7 +2,7 @@ ################################################## # Gnuradio Python Flow Graph # Title: USRP HRPT Receiver -# Generated: Tue Sep 8 14:58:57 2009 +# Generated: Tue Sep 8 21:03:12 2009 ################################################## from gnuradio import eng_notation @@ -98,10 +98,8 @@ class usrp_rx_hrpt(grc_wxgui.top_block_gui): # Blocks ################################################## self.agr = gr.agc_cc(1e-6, 1.0, 1.0, 1.0) - self.gr_add_const_vxx_0 = gr.add_const_vff((48.0, )) self.gr_char_to_float_0 = gr.char_to_float() - self.gr_file_sink_0 = gr.file_sink(gr.sizeof_char*1, "bits.dat") - self.gr_float_to_char_0 = gr.float_to_char() + self.noaa_hrpt_deframer_0 = noaa.hrpt_deframer() self.noaa_hrpt_pll_cf_0 = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset) self.noaa_hrpt_sync_fb_0 = noaa.hrpt_sync_fb(0.001, 0.001**2/4.0, sps, max_sync_offset) self.rx_fftsink = fftsink2.fft_sink_c( @@ -109,7 +107,7 @@ class usrp_rx_hrpt(grc_wxgui.top_block_gui): baseband_freq=1698e6, y_per_div=5, y_divs=8, - ref_level=20, + ref_level=-5, ref_scale=2.0, sample_rate=sample_rate, fft_size=1024, @@ -120,7 +118,7 @@ class usrp_rx_hrpt(grc_wxgui.top_block_gui): peak_hold=False, ) self.displays.GetPage(0).GridAdd(self.rx_fftsink.win, 0, 0, 1, 1) - self.src = gr.file_source(gr.sizeof_gr_complex*1, "poes-d16.dat", False) + self.src = gr.file_source(gr.sizeof_gr_complex*1, "poes-d16.dat", True) self.throttle = gr.throttle(gr.sizeof_gr_complex*1, sample_rate) self.wxgui_scopesink2_0 = scopesink2.scope_sink_c( self.displays.GetPage(0).GetWin(), @@ -168,9 +166,7 @@ class usrp_rx_hrpt(grc_wxgui.top_block_gui): self.connect((self.noaa_hrpt_sync_fb_0, 0), (self.gr_char_to_float_0, 0)) self.connect((self.noaa_hrpt_pll_cf_0, 0), (self.noaa_hrpt_sync_fb_0, 0)) self.connect((self.gr_char_to_float_0, 0), (self.wxgui_scopesink2_0_0_0_0, 0)) - self.connect((self.gr_char_to_float_0, 0), (self.gr_add_const_vxx_0, 0)) - self.connect((self.gr_add_const_vxx_0, 0), (self.gr_float_to_char_0, 0)) - self.connect((self.gr_float_to_char_0, 0), (self.gr_file_sink_0, 0)) + self.connect((self.noaa_hrpt_sync_fb_0, 0), (self.noaa_hrpt_deframer_0, 0)) def set_decim(self, decim): self.decim = decim @@ -185,9 +181,9 @@ class usrp_rx_hrpt(grc_wxgui.top_block_gui): self.sample_rate = sample_rate self.set_sps(self.sample_rate/self.sym_rate) self.set_max_carrier_offset(2*math.pi*100e3/self.sample_rate) - self.rx_fftsink.set_sample_rate(self.sample_rate) self.wxgui_scopesink2_0.set_sample_rate(self.sample_rate) self.wxgui_scopesink2_0_0.set_sample_rate(self.sample_rate) + self.rx_fftsink.set_sample_rate(self.sample_rate) def set_sps(self, sps): self.sps = sps diff --git a/gr-noaa/lib/Makefile.am b/gr-noaa/lib/Makefile.am index 1b758871..578c98ad 100644 --- a/gr-noaa/lib/Makefile.am +++ b/gr-noaa/lib/Makefile.am @@ -29,6 +29,7 @@ lib_LTLIBRARIES = \ libgnuradio-noaa.la libgnuradio_noaa_la_SOURCES = \ + noaa_hrpt_deframer.cc \ noaa_hrpt_pll_cf.cc \ noaa_hrpt_sync_fb.cc @@ -38,5 +39,6 @@ libgnuradio_noaa_la_LIBADD = \ libgnuradio_noaa_la_LDFLAGS = $(NO_UNDEFINED) -version-info 0:0:0 grinclude_HEADERS = \ + noaa_hrpt_deframer.h \ noaa_hrpt_pll_cf.h \ noaa_hrpt_sync_fb.h diff --git a/gr-noaa/lib/noaa_hrpt_deframer.cc b/gr-noaa/lib/noaa_hrpt_deframer.cc new file mode 100644 index 00000000..71712277 --- /dev/null +++ b/gr-noaa/lib/noaa_hrpt_deframer.cc @@ -0,0 +1,102 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 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 +#include + +#define ST_IDLE 0 +#define ST_SYNCED 1 + +#define HRPT_MINOR_FRAME_SYNC 0x0A116FD719D83C95LL +#define HRPT_BITS_PER_MINOR_FRAME 11090*10 +#define HRPT_SYNC_LENGTH 6*10 + +static int frames_seen = 0; + +noaa_hrpt_deframer_sptr +noaa_make_hrpt_deframer() +{ + return gnuradio::get_initial_sptr(new noaa_hrpt_deframer()); +} + +noaa_hrpt_deframer::noaa_hrpt_deframer() + : gr_sync_block("noaa_hrpt_deframer", + gr_make_io_signature(1, 1, sizeof(char)), + gr_make_io_signature(0, 0, 0)) +{ + enter_idle(); +} + +void +noaa_hrpt_deframer::enter_idle() +{ + d_state = ST_IDLE; +} + +void +noaa_hrpt_deframer::enter_synced() +{ + d_state = ST_SYNCED; + d_count = HRPT_BITS_PER_MINOR_FRAME-HRPT_SYNC_LENGTH; +} + +int +noaa_hrpt_deframer::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const char *in = (const char *)input_items[0]; + + int i = 0; + while (i < noutput_items) { + char bit = in[i++]; + if (d_state != ST_SYNCED) + fprintf(stderr, "."); + + switch (d_state) { + case ST_IDLE: + d_shifter = (d_shifter << 1) | bit; // MSB transmitted first + + if ((d_shifter & 0x0FFFFFFFFFFFFFFF) == HRPT_MINOR_FRAME_SYNC) { + fprintf(stderr, "\nSYNC #%i...", frames_seen++); + enter_synced(); + } + break; + + case ST_SYNCED: + if (--d_count == 0) { + fprintf(stderr, "done."); + enter_idle(); + } + break; + + default: + throw std::runtime_error("noaa_hrpt_deframer: bad state\n"); + } + } + + return i; +} diff --git a/gr-noaa/lib/noaa_hrpt_deframer.h b/gr-noaa/lib/noaa_hrpt_deframer.h new file mode 100644 index 00000000..bc91bc89 --- /dev/null +++ b/gr-noaa/lib/noaa_hrpt_deframer.h @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 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_NOAA_HRPT_DEFRAMER_H +#define INCLUDED_NOAA_HRPT_DEFRAMER_H + +#include + +class noaa_hrpt_deframer; +typedef boost::shared_ptr noaa_hrpt_deframer_sptr; + +noaa_hrpt_deframer_sptr +noaa_make_hrpt_deframer(); + +class noaa_hrpt_deframer : public gr_sync_block +{ + friend noaa_hrpt_deframer_sptr noaa_make_hrpt_deframer(); + noaa_hrpt_deframer(); + + unsigned int d_state; + unsigned int d_count; + unsigned long long d_shifter; // 60 bit sync word + + void enter_idle(); + void enter_synced(); + +public: + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_NOAA_HRPT_DEFRAMER_H */ diff --git a/gr-noaa/swig/Makefile.am b/gr-noaa/swig/Makefile.am index e1584227..98311eb7 100644 --- a/gr-noaa/swig/Makefile.am +++ b/gr-noaa/swig/Makefile.am @@ -53,6 +53,7 @@ noaa_swig_python = \ # additional SWIG files to be installed noaa_swig_swiginclude_headers = \ noaa_swig.i \ + noaa_hrpt_deframer.i \ noaa_hrpt_pll_cf.i \ noaa_hrpt_sync_fb.i diff --git a/gr-noaa/swig/noaa_hrpt_deframer.i b/gr-noaa/swig/noaa_hrpt_deframer.i new file mode 100644 index 00000000..73106d72 --- /dev/null +++ b/gr-noaa/swig/noaa_hrpt_deframer.i @@ -0,0 +1,32 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 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(noaa,hrpt_deframer) + +noaa_hrpt_deframer_sptr +noaa_make_hrpt_deframer(); + +class noaa_hrpt_deframer : public gr_sync_block +{ +private: + noaa_hrpt_deframer(); +}; diff --git a/gr-noaa/swig/noaa_swig.i b/gr-noaa/swig/noaa_swig.i index 8223eedb..44f2e472 100644 --- a/gr-noaa/swig/noaa_swig.i +++ b/gr-noaa/swig/noaa_swig.i @@ -23,9 +23,11 @@ %include "gnuradio.i" %{ +#include #include #include %} +%include "noaa_hrpt_deframer.i" %include "noaa_hrpt_pll_cf.i" %include "noaa_hrpt_sync_fb.i" -- 2.47.2