GNU Radio 3.6.5.1 C++ API
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  *
37  * This sink is typically used to test the USRP "Counting Mode" or "Counting mode 32 bit".
38  */
40 {
42 
43  enum state {
44  SEARCHING, // searching for synchronization
45  LOCKED // is locked
46  };
47 
48  state d_state;
49  unsigned int d_history; // bitmask of decisions
50  unsigned short d_current_count;
51  unsigned int d_current_count_32bit;
52 
53  long d_total_errors;
54  long d_total_shorts;
55  bool d_do_32bit;
56 
57  gr_check_counting_s (bool do_32bit);
58 
59  void enter_SEARCHING ();
60  void enter_LOCKED ();
61 
62  void right (){
63  d_history = (d_history << 1) | 0x1;
64  }
65 
66  void wrong (){
67  d_history = (d_history << 1) | 0x0;
68  d_total_errors++;
69  }
70 
71  bool right_three_times () { return (d_history & 0x7) == 0x7; }
72  bool wrong_three_times () { return (d_history & 0x7) == 0x0; }
73 
74  void log_error (unsigned short expected, unsigned short actual);
75  void log_error_32bit (unsigned int expected, unsigned int actual);
76 
77  int check_32bit (int noutput_items, unsigned short * in);
78  int check_16bit (int noutput_items, unsigned short * in);
79 
80  public:
81 
82  int work (int noutput_items,
83  gr_vector_const_void_star &input_items,
84  gr_vector_void_star &output_items);
85 };
86 
87 
88 #endif /* INCLUDED_GR_CHECK_COUNTING_S_H */