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>
42 #define HRPT_MINOR_FRAME_SYNC 0x0A116FD719D83C95LL
44 static int frames_seen = 0;
46 noaa_hrpt_deframer_sptr
47 noaa_make_hrpt_deframer()
49 return gnuradio::get_initial_sptr(new noaa_hrpt_deframer());
52 noaa_hrpt_deframer::noaa_hrpt_deframer()
53 : gr_block("noaa_hrpt_deframer",
54 gr_make_io_signature(1, 1, sizeof(char)),
55 gr_make_io_signature(1, 1, sizeof(short)))
57 set_output_multiple(6); // room for writing full sync when received
62 noaa_hrpt_deframer::enter_idle()
68 noaa_hrpt_deframer::enter_synced()
71 d_bit_count = HRPT_BITS_PER_WORD;
72 d_word_count = HRPT_MINOR_FRAME_WORDS-HRPT_SYNC_WORDS;
77 noaa_hrpt_deframer::general_work(int noutput_items,
78 gr_vector_int &ninput_items,
79 gr_vector_const_void_star &input_items,
80 gr_vector_void_star &output_items)
82 int ninputs = ninput_items[0];
83 const char *in = (const char *)input_items[0];
84 unsigned short *out = (unsigned short *)output_items[0];
87 while (i < ninputs && j < noutput_items) {
92 d_shifter = (d_shifter << 1) | bit; // MSB transmitted first
94 if ((d_shifter & 0x0FFFFFFFFFFFFFFFLL) == HRPT_MINOR_FRAME_SYNC) {
95 fprintf(stderr, "SYNC #%i", frames_seen++);
107 d_word = (d_word << 1) | bit; // MSB transmitted first
108 if (--d_bit_count == 0) {
111 d_bit_count = HRPT_BITS_PER_WORD;
112 if (--d_word_count == 0) {
113 fprintf(stderr, "...done\n");
120 throw std::runtime_error("noaa_hrpt_deframer: bad state\n");