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(const std::string &name, const std::string &version,
79  int input_item_size, size_t max_frame_len = 8192);
80  virtual ~decoder();
81 
82  /**
83  * Decodes a buffer of input items contained in the in buffer.
84  * This method is called continuously by the frame_decoder.
85  * Based on the returned status data, the frame_decoder() instructs
86  * properly the GNU Radio scheduler and/or propagates decoded data.
87  *
88  * As the number of input items may not enough to decode a frame, each decoder
89  * should keep internal state, so decoding can be accomplished after an
90  * arbitrary number of calls to this method
91  *
92  * @param in the input items
93  *
94  * @param nitems the number of input items contained in the in buffer
95  *
96  * @return the status of the decoder after the call of this method. For
97  * more information refer to decoder_status()
98  */
99  virtual decoder_status_t
100  decode(const void *in, int nitems) = 0;
101 
102 
103  /**
104  * Resets the internal state of the decoder to the initial defaults
105  *
106  */
107  virtual void
108  reset() = 0;
109 
110  virtual size_t
111  input_multiple() const;
112 
113  size_t
114  max_frame_len() const;
115 
116  int
117  sizeof_input_item() const;
118 
119  std::string
120  name() const;
121 
122  std::string
123  version() const;
124 
125 protected:
126  void
127  incr_nitems_read(size_t nitems);
128 
129  uint64_t
130  nitems_read() const;
131 
132 private:
133  const std::string d_name;
134  const std::string d_version;
135  const int d_sizeof_in;
136  const size_t d_max_frame_len;
137  const int d_id;
138  uint64_t d_nitems_read;
139 };
140 
141 } // namespace satnogs
142 } // namespace gr
143 
144 #endif /* INCLUDED_SATNOGS_DECODER_H */
145 
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