3 * Copyright 2004 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 <gr_check_lfsr_32k_s.h>
28 #include <gr_io_signature.h>
32 gr_check_lfsr_32k_s_sptr
33 gr_make_check_lfsr_32k_s ()
35 return gr_check_lfsr_32k_s_sptr (new gr_check_lfsr_32k_s ());
38 gr_check_lfsr_32k_s::gr_check_lfsr_32k_s ()
39 : gr_sync_block ("gr_check_lfsr_32k",
40 gr_make_io_signature (1, 1, sizeof (short)),
41 gr_make_io_signature (0, 0, 0)),
42 d_state(SEARCHING), d_history (0), d_ntotal (0), d_nright (0),
43 d_runlength (0), d_index(0)
47 for (int i = 0; i < BUFSIZE; i++)
48 d_buffer[i] = lfsr.next_short ();
54 gr_check_lfsr_32k_s::work (int noutput_items,
55 gr_vector_const_void_star &input_items,
56 gr_vector_void_star &output_items)
58 unsigned short *in = (unsigned short *) input_items[0];
60 for (int i = 0; i < noutput_items; i++){
61 unsigned short x = in[i];
62 unsigned short expected;
86 expected = d_buffer[d_index];
87 d_index = d_index + 1;
88 if (d_index >= BUFSIZE)
95 log_error (expected, x);
96 if (wrong_three_times ())
108 return noutput_items;
112 gr_check_lfsr_32k_s::enter_SEARCHING ()
115 wrong (); // reset history
120 d_index = 0; // reset LFSR to beginning
123 fprintf (stdout, "gr_check_lfsr_32k: enter_SEARCHING at offset %8ld (0x%08lx)\n",
130 gr_check_lfsr_32k_s::enter_MATCH0 ()
136 gr_check_lfsr_32k_s::enter_MATCH1 ()
142 gr_check_lfsr_32k_s::enter_MATCH2 ()
148 gr_check_lfsr_32k_s::enter_LOCKED ()
151 right (); // setup history
155 d_index = 3; // already matched first 3 items
158 fprintf (stdout, "gr_check_lfsr_32k: enter_LOCKED at offset %8ld (0x%08lx)\n",
163 gr_check_lfsr_32k_s::log_error (unsigned short expected, unsigned short actual)
167 "gr_check_lfsr_32k: expected %5d (0x%04x) got %5d (0x%04x) offset %8ld (0x%08lx)\n",
168 expected, expected, actual, actual, d_ntotal, d_ntotal);