gr-baz Package
gr_check_counting_s.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
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)
10  * any later version.
11  *
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.
16  *
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.
21  */
22 #ifndef INCLUDED_GR_CHECK_COUNTING_S_H
23 #define INCLUDED_GR_CHECK_COUNTING_S_H
24 
25 #include <gr_core_api.h>
26 #include <gr_sync_block.h>
27 
30 
32 
33 /*!
34  * \brief sink that checks if its input stream consists of a counting sequence.
35  * \param do_32bit expect an interleaved 32 bit counter in stead of 16 bit counter (default false)
36  * \ingroup sink_blk
37  *
38  * This sink is typically used to test the USRP "Counting Mode" or "Counting mode 32 bit".
39  */
41 {
43 
44  enum state {
45  SEARCHING, // searching for synchronization
46  LOCKED // is locked
47  };
48 
49  state d_state;
50  unsigned int d_history; // bitmask of decisions
51  unsigned short d_current_count;
52  unsigned int d_current_count_32bit;
53 
54  long d_total_errors;
55  long d_total_shorts;
56  bool d_do_32bit;
57 
58  gr_check_counting_s (bool do_32bit);
59 
60  void enter_SEARCHING ();
61  void enter_LOCKED ();
62 
63  void right (){
64  d_history = (d_history << 1) | 0x1;
65  }
66 
67  void wrong (){
68  d_history = (d_history << 1) | 0x0;
69  d_total_errors++;
70  }
71 
72  bool right_three_times () { return (d_history & 0x7) == 0x7; }
73  bool wrong_three_times () { return (d_history & 0x7) == 0x0; }
74 
75  void log_error (unsigned short expected, unsigned short actual);
76  void log_error_32bit (unsigned int expected, unsigned int actual);
77 
78  int check_32bit (int noutput_items, unsigned short * in);
79  int check_16bit (int noutput_items, unsigned short * in);
80 
81  public:
82 
83  int work (int noutput_items,
84  gr_vector_const_void_star &input_items,
85  gr_vector_void_star &output_items);
86 };
87 
88 
89 #endif /* INCLUDED_GR_CHECK_COUNTING_S_H */