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 2, 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_counting_s.h>
28 #include <gr_io_signature.h>
32 gr_check_counting_s_sptr
33 gr_make_check_counting_s (bool do_32bit)
35 return gr_check_counting_s_sptr (new gr_check_counting_s (do_32bit));
38 gr_check_counting_s::gr_check_counting_s (bool do_32bit)
39 : gr_sync_block ("gr_check_counting",
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_current_count (0), d_current_count_32bit(0),
43 d_total_errors (0), d_total_shorts (0),
50 gr_check_counting_s::work (int noutput_items,
51 gr_vector_const_void_star &input_items,
52 gr_vector_void_star &output_items)
54 unsigned short *in = (unsigned short *) input_items[0];
56 return check_32bit(noutput_items,in);
58 return check_16bit(noutput_items,in);
62 gr_check_counting_s::check_16bit (int noutput_items,
65 for (int i = 0; i < noutput_items; i++){
66 unsigned short x = in[i];
71 if (x == d_current_count){
73 log_error (d_current_count, x);
74 d_current_count = d_current_count + 1;
75 if (right_three_times ())
80 log_error (d_current_count, x);
81 d_current_count = x + 1;
86 if (x == d_current_count){
88 d_current_count = d_current_count + 1;
92 log_error (d_current_count, x);
93 d_current_count = d_current_count + 1;
94 if (wrong_three_times ())
106 return noutput_items;
110 gr_check_counting_s::check_32bit (int noutput_items,
114 for (int i = 0; i < noutput_items-1; i+=2){
115 unsigned int x_high16bits = in[i];
116 unsigned int x_low16bits = in[i+1];
117 unsigned int x = x_high16bits<<16 | x_low16bits;
122 if (x == d_current_count_32bit){
124 log_error_32bit (d_current_count_32bit, x);
125 d_current_count_32bit = d_current_count_32bit + 1;
126 if (right_three_times ())
131 log_error_32bit (d_current_count_32bit, x);
132 d_current_count_32bit = x + 1;
137 if (x == d_current_count_32bit){
139 d_current_count_32bit = d_current_count_32bit + 1;
143 log_error_32bit (d_current_count_32bit, x);
144 d_current_count_32bit = d_current_count_32bit + 1;
145 if (wrong_three_times ())
157 return noutput_items;
161 gr_check_counting_s::enter_SEARCHING ()
164 fprintf (stdout, "gr_check_counting: enter_SEARCHING at offset %8ld (0x%08lx)\n",
165 d_total_shorts, d_total_shorts);
169 gr_check_counting_s::enter_LOCKED ()
172 fprintf (stdout, "gr_check_counting: enter_LOCKED at offset %8ld (0x%08lx)\n",
173 d_total_shorts, d_total_shorts);
177 gr_check_counting_s::log_error (unsigned short expected, unsigned short actual)
180 "gr_check_counting: expected %5d (0x%04x) got %5d (0x%04x) offset %8ld (0x%08lx)\n",
181 expected, expected, actual, actual, d_total_shorts, d_total_shorts);
185 gr_check_counting_s::log_error_32bit (unsigned int expected, unsigned int actual)
188 "gr_check_counting: expected %10d (0x%08x) got %10d (0x%08x) offset %8ld (0x%08lx)\n",
189 expected, expected, actual, actual, d_total_shorts, d_total_shorts);