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