GNU Radio 3.6.5.1 C++ API
check_lfsr_32k_s_impl.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004,2013 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 
23 #ifndef INCLUDED_GR_CHECK_LFSR_32K_S_IMPL_H
24 #define INCLUDED_GR_CHECK_LFSR_32K_S_IMPL_H
25 
27 #include <blocks/lfsr_32k.h>
28 
29 namespace gr {
30  namespace blocks {
31 
33  {
34  private:
35  enum state {
36  SEARCHING, // searching for synchronization
37  MATCH0,
38  MATCH1,
39  MATCH2,
40  LOCKED // is locked
41  };
42 
43  state d_state;
44  unsigned int d_history; // bitmask of decisions
45 
46  long d_ntotal; // total number of shorts
47  long d_nright; // # of correct shorts
48  long d_runlength; // # of correct shorts in a row
49 
50  static const int BUFSIZE = 2048 - 1; // ensure pattern isn't packet aligned
51  int d_index;
52  unsigned short d_buffer[BUFSIZE];
53 
54  void enter_SEARCHING();
55  void enter_MATCH0();
56  void enter_MATCH1();
57  void enter_MATCH2();
58  void enter_LOCKED();
59 
60  void right()
61  {
62  d_history = (d_history << 1) | 0x1;
63  d_nright++;
64  d_runlength++;
65  }
66 
67  void wrong()
68  {
69  d_history = (d_history << 1) | 0x0;
70  d_runlength = 0;
71  }
72 
73  bool right_three_times() { return (d_history & 0x7) == 0x7; }
74  bool wrong_three_times() { return (d_history & 0x7) == 0x0; }
75 
76  void log_error(unsigned short expected, unsigned short actual);
77 
78  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  long ntotal() const { return d_ntotal; }
87  long nright() const { return d_nright; }
88  long runlength() const { return d_runlength; }
89  };
90 
91  } /* namespace blocks */
92 } /* namespace gr */
93 
94 #endif /* INCLUDED_GR_CHECK_LFSR_32K_S_IMPL_H */