3 * Copyright 2009 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
27 #include <noaa_hrpt_deframer.h>
28 #include <gr_io_signature.h>
29 #include <noaa_hrpt.h>
36 noaa_hrpt_deframer_sptr
37 noaa_make_hrpt_deframer()
39 return gnuradio::get_initial_sptr(new noaa_hrpt_deframer());
42 noaa_hrpt_deframer::noaa_hrpt_deframer()
43 : gr_block("noaa_hrpt_deframer",
44 gr_make_io_signature(1, 1, sizeof(char)),
45 gr_make_io_signature(1, 1, sizeof(short)))
47 set_output_multiple(6); // room for writing full sync when received
54 noaa_hrpt_deframer::enter_idle()
60 noaa_hrpt_deframer::enter_synced()
63 d_bit_count = HRPT_BITS_PER_WORD;
64 d_word_count = HRPT_MINOR_FRAME_WORDS-HRPT_SYNC_WORDS;
69 noaa_hrpt_deframer::general_work(int noutput_items,
70 gr_vector_int &ninput_items,
71 gr_vector_const_void_star &input_items,
72 gr_vector_void_star &output_items)
74 int ninputs = ninput_items[0];
75 const char *in = (const char *)input_items[0];
76 unsigned short *out = (unsigned short *)output_items[0];
79 while (i < ninputs && j < noutput_items) {
81 char diff = bit^d_last_bit;
84 // Wait for transition if not synced, otherwise, alternate bits
85 if (d_mid_bit && (diff | (d_state == ST_SYNCED))) {
88 d_shifter = (d_shifter << 1) | bit; // MSB transmitted first
90 if ((d_shifter & 0x0FFFFFFFFFFFFFFFLL) == HRPT_MINOR_FRAME_SYNC) {
91 out[j++] = HRPT_SYNC1;
92 out[j++] = HRPT_SYNC2;
93 out[j++] = HRPT_SYNC3;
94 out[j++] = HRPT_SYNC4;
95 out[j++] = HRPT_SYNC5;
96 out[j++] = HRPT_SYNC6;
102 d_word = (d_word << 1) | bit; // MSB transmitted first
103 if (--d_bit_count == 0) {
106 d_bit_count = HRPT_BITS_PER_WORD;
107 if (--d_word_count == 0) {
114 throw std::runtime_error("noaa_hrpt_deframer: bad state\n");