summaryrefslogtreecommitdiffstats
path: root/blocks/src/lib/op25_decoder_ff.h
blob: 43b6d622783d61536922cee92730db5162b0ee32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* -*- C++ -*- */

/*
 * Copyright 2008-2011 Steve Glass
 * 
 * This file is part of OP25.
 * 
 * OP25 is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 * 
 * OP25 is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with OP25; see the file COPYING.  If not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Boston, MA
 * 02110-1301, USA.
 */

#ifndef INCLUDED_OP25_DECODER_FF_H
#define INCLUDED_OP25_DECODER_FF_H

#include <boost/scoped_ptr.hpp>
#include <data_unit.h>
#include <data_unit_handler.h>
#include <gr_block.h>
#include <gr_msg_queue.h>
#include <imbe_decoder.h>

typedef boost::shared_ptr<class op25_decoder_ff> op25_decoder_ff_sptr;

op25_decoder_ff_sptr op25_make_decoder_ff();

/**
 * op25_decoder_ff is a GNU Radio block for decoding APCO P25
 * signals. This class expects its input to be a stream of dibit
 * symbols from the demodulator and produces a mono audio
 * stream.
 */
class op25_decoder_ff : public gr_block
{
public:

   /**
    * op25_decoder_ff (virtual) destructor.
    */
   virtual ~op25_decoder_ff();

   /**
    * Estimate nof_input_items_reqd for a given nof_output_items.
    */
   virtual void forecast(int nof_output_items, gr_vector_int &nof_input_items_reqd);

   /**
    * Process symbols into frames.
    */
   virtual int general_work(int nof_output_items, gr_vector_int& nof_input_items, gr_vector_const_void_star& input_items, gr_vector_void_star& output_items);
   /**
    * Return a pointer to a string identifying the destination of
    * the received frames.
    *
    * \return A pointer to a NUL-terminated character string.
    */
   const char *destination() const;

   /**
    * Accessor for the msgq attribute. Returns a pointer to the msgq
    * if it exists.
    *
    * \return A (possibly NULL) gr_msg_queue_sptr pointing to the message queue.
    */
   gr_msg_queue_sptr get_msgq() const;

   /**
    * Accessor for the msgq attribute. Sets the msgq to point to the
    * provided message queue object.
    *
    * \return A (possibly NULL) gr_msg_queue_sptr pointing to the message queue.
    */
   void set_msgq(gr_msg_queue_sptr msgq);

private:

   /**
    * Expose class to public ctor. Create a new instance of
    * op25_decoder_ff and wrap it in a shared_ptr. This is effectively
    * the public constructor.
    */
   friend op25_decoder_ff_sptr op25_make_decoder_ff();

   /**
    * op25_decoder_ff protected constructor.
    */
   op25_decoder_ff();

   /**
    * Tests whether d_frame_header correlates with the APCO P25 frame
    * sync sequence. This method must only be called when the frame
    * header is larger than 48 bits in length (the minimum size for
    * the FS).
    *
    * \return true if the frame header correlates; otherwise false.
    */
   bool correlated();

   /**
    * Tests whether d_frame_header identifies a known data unit and if
    * so sets d_data_unit to point to an appropriate instance and
    * returns a pointer to it. This method must only be called when
    * the frame header is larger than 114 bits in length (the minimum
    * size for a frame containing a NID).
    *
    * \return A data_unit_sptr pointing to an appropriate data_unit
    * instance or NULL if the frame header is unrecognized.
    */
   data_unit_sptr identified();

   /**
    * Handle a received symbol.
    *
    * \param d The symbol to process.
    */
   void receive_symbol(dibit d);

private:

   /**
    * When d_state == READING the current data unit, otherwise null.
    */
   data_unit_sptr d_data_unit;

   /**
    * The head of a chain of data_unit_handler instances.
    */
   data_unit_handler_sptr d_data_unit_handler;

   /**
    * A bit_queue used to correlate the FS.
    */
   bit_queue d_frame_hdr;

   /**
    * The IMBE decoder to use.
    */
   imbe_decoder_sptr d_imbe;

   /**
    * Valid states for the decoder state model.
    */
   enum { SYNCHRONIZING, IDENTIFYING, READING } d_state;

   /**
    * The p25cai (TUN/TAP) data unit handler.
    */
   class p25cai_du_handler *d_p25cai_du_handler;

   /**
    * The snapshot data unit handler.
    */
   class snapshot_du_handler *d_snapshot_du_handler;

};

#endif /* INCLUDED_OP25_DECODER_FF_H */