GNU Radio's SATNOGS Package
decoder.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
4  *
5  * Copyright (C) 2019, Libre Space Foundation <http://libre.space>
6  *
7  * This program 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 of the License, or
10  * (at your option) any later version.
11  *
12  * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef INCLUDED_SATNOGS_DECODER_H
22 #define INCLUDED_SATNOGS_DECODER_H
23 
24 #include <satnogs/api.h>
25 #include <cstdint>
26 #include <cstdlib>
27 #include <pmt/pmt.h>
28 
29 namespace gr {
30 namespace satnogs {
31 
32 /**
33  * The status of the decoder
34  *
35  * This class contains all the necessary information that the
36  * \ref decoder::decode() method returns and used by the frame_decoder()
37  * to properly inform the GNU Radio scheduler and/or propagate decoded frames
38  */
40 public:
41  int consumed; /**< The number of input items consumed */
42  bool
43  decode_success; /**< Indicated if there was a successful decoding */
44  pmt::pmt_t
45  data; /**< a dictionary with the PDU with of decoded data and the corresponding metadata for the decoded frame */
46 
48  consumed(0),
49  decode_success(false),
50  data(pmt::make_dict())
51  {
52  }
53 };
54 
56 
57 
58 /**
59  * \brief Abstract class that provided the API for the c decoders
60  *
61  * This is an abstract class providing the API for the SatNOGS decoders.
62  *
63  * The gr-satnogs module tries to provide a unified decoding framework,
64  * for various satellites.
65  * Specialization is performed by passing to the generic decoding block the
66  * appropriate decoder class that implements this abstract class API.
67  *
68  */
70 public:
71  typedef boost::shared_ptr<decoder> decoder_sptr;
72 
73  static int base_unique_id;
74 
75  int
76  unique_id() const;
77 
78  decoder(int input_item_size, size_t max_frame_len = 8192);
79  virtual ~decoder();
80 
81  /**
82  * Decodes a buffer of input items contained in the in buffer.
83  * This method is called continuously by the frame_decoder.
84  * Based on the returned status data, the frame_decoder() instructs
85  * properly the GNU Radio scheduler and/or propagates decoded data.
86  *
87  * As the number of input items may not enough to decode a frame, each decoder
88  * should keep internal state, so decoding can be accomplished after an
89  * arbitrary number of calls to this method
90  *
91  * @param in the input items
92  *
93  * @param nitems the number of input items contained in the in buffer
94  *
95  * @return the status of the decoder after the call of this method. For
96  * more information refer to decoder_status()
97  */
98  virtual decoder_status_t
99  decode(const void *in, int nitems) = 0;
100 
101 
102  /**
103  * Resets the internal state of the decoder to the initial defaults
104  *
105  */
106  virtual void
107  reset() = 0;
108 
109  virtual size_t
110  input_multiple() const;
111 
112  size_t
113  max_frame_len() const;
114 
115  int
116  sizeof_input_item() const;
117 
118 protected:
119  void
120  incr_nitems_read(size_t nitems);
121 
122  uint64_t
123  nitems_read() const;
124 
125 private:
126  const int d_sizeof_in;
127  const size_t d_max_frame_len;
128  const int d_id;
129  uint64_t d_nitems_read;
130 };
131 
132 } // namespace satnogs
133 } // namespace gr
134 
135 #endif /* INCLUDED_SATNOGS_DECODER_H */
136 
Definition: decoder.h:39
bool decode_success
Definition: decoder.h:43
decoder_status()
Definition: decoder.h:47
Abstract class that provided the API for the c decoders.
Definition: decoder.h:69
pmt::pmt_t data
Definition: decoder.h:45
Definition: amsat_duv_decoder.h:29
int consumed
Definition: decoder.h:41
class decoder_status decoder_status_t
Definition: decoder.h:55
static int base_unique_id
Definition: decoder.h:73
#define SATNOGS_API
Definition: api.h:30