GNU Radio's SATNOGS Package
scrambler.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) 2022, 2024 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 SCRAMBLER_H
22#define SCRAMBLER_H
23
24#include <gnuradio/digital/lfsr.h>
25#include <gnuradio/fec/encoder.h>
29#include <string>
30
31namespace gr {
32namespace satnogs {
33namespace code {
34
35class SATNOGS_API scrambler : virtual public fec::generic_encoder
36{
37public:
38 static int base_unique_id;
39
40 int unique_id();
41
42 using sptr = fec::generic_encoder::sptr;
43
44 static sptr make(uint32_t mask,
45 uint32_t seed,
46 uint32_t order,
47 bool msb = false,
48 bool self_sync = false);
49
50 static sptr make_ccsds(bool msb = false);
51
52 static sptr make_g3ruh(bool msb = false);
53
54 static sptr make_none();
55
56 scrambler(uint32_t mask,
57 uint32_t seed,
58 uint32_t order,
59 bool msb = false,
60 bool self_sync = false);
61
63
64 void reset();
65
66 void scramble(uint8_t* out, const uint8_t* in, size_t len);
67 void descramble(uint8_t* out, const uint8_t* in, size_t len);
68
69 void scramble_one_bit_per_byte(uint8_t* out, const uint8_t* in, size_t bits_num);
70 void descramble_one_bit_per_byte(uint8_t* out, const uint8_t* in, size_t bits_num);
71 double rate() override;
72
73 /*!
74 * Returns the input size in items that the encoder object uses
75 * to encode a full frame. Often, this number is the number of
76 * bits per frame if the input format is unpacked. If the block
77 * expects packed bytes, then this value should be the number of
78 * bytes (number of bits / 8) per input frame.
79 *
80 * The child class MUST implement this function.
81 */
82 int get_input_size() override;
83
84 /*!
85 * Returns the output size in items that the encoder object
86 * produces after encoding a full frame. Often, this number is
87 * the number of bits in the outputted frame if the input format
88 * is unpacked. If the block produces packed bytes, then this
89 * value should be the number of bytes (number of bits / 8) per
90 * frame produced. This value is generally something like
91 * R*get_input_size() for a 1/R rate code.
92 *
93 * The child class MUST implement this function.
94 */
95 int get_output_size() override;
96
97 /*!
98 * Set up a conversion type required to setup the data properly
99 * for this encoder. The encoder itself will not implement the
100 * conversion and expects an external wrapper (e.g.,
101 * fec.extended_encoder) to read this value and "do the right
102 * thing" to format the data.
103 *
104 * The default behavior is 'none', which means no conversion is
105 * required. Whatever the get_input_item_size() value returns,
106 * the input is expected to conform directly to this. Generally,
107 * this means unpacked bytes.
108 *
109 * If 'pack', the block expects the inputs to be packed
110 * bytes. The wrapper should implement a
111 * gr::blocks::pack_k_bits_bb(8) block for this.
112 *
113 * The child class MAY implement this function. If not
114 * reimplemented, it returns "none".
115 */
116 const char* get_input_conversion() override;
117
118 /*!
119 * Set up a conversion type required to understand the output
120 * style of this encoder. Generally an encoder will produce
121 * unpacked bytes with a bit set in the LSB.
122 *
123 * The default behavior is 'none', which means no conversion is
124 * required and the encoder produces unpacked bytes.
125 *
126 * If 'packed_bits', the block produces packed bits and the
127 * wrapper should unpack these (using, for instance,
128 * gr::block::unpack_k_bits_bb(8)).
129 *
130 * The child class MAY implement this function. If not
131 * reimplemented, it returns "none".
132 */
133 const char* get_output_conversion() override;
134
135 /*!
136 * Updates the size of the frame to encode.
137 *
138 * The child class MUST implement this function and interpret
139 * how the \p frame_size information affects the block's
140 * behavior. It should also provide bounds checks.
141 */
142 bool set_frame_size(unsigned int frame_size) override;
143
144 void generic_work(fec_input_buffer_type inbuffer, void* outbuffer) override;
145
146private:
147 const bool d_msb;
148 const bool d_self_sync;
149 digital::lfsr d_lfsr;
150 int d_id;
151 size_t m_frame_len;
152};
153
154
155} // namespace code
156} // namespace satnogs
157} // namespace gr
158
159#endif // SCRAMBLER_H
#define SATNOGS_API
Definition api.h:19
Definition scrambler.h:36
void generic_work(fec_input_buffer_type inbuffer, void *outbuffer) override
static sptr make(uint32_t mask, uint32_t seed, uint32_t order, bool msb=false, bool self_sync=false)
scrambler(uint32_t mask, uint32_t seed, uint32_t order, bool msb=false, bool self_sync=false)
void descramble_one_bit_per_byte(uint8_t *out, const uint8_t *in, size_t bits_num)
void scramble(uint8_t *out, const uint8_t *in, size_t len)
static sptr make_g3ruh(bool msb=false)
const char * get_input_conversion() override
int get_output_size() override
void scramble_one_bit_per_byte(uint8_t *out, const uint8_t *in, size_t bits_num)
fec::generic_encoder::sptr sptr
Definition scrambler.h:42
static sptr make_ccsds(bool msb=false)
void descramble(uint8_t *out, const uint8_t *in, size_t len)
const char * get_output_conversion() override
static int base_unique_id
Definition scrambler.h:38
bool set_frame_size(unsigned int frame_size) override
std::conditional< config::gnuradio_version_num(config::gnuradio_major, config::gnuradio_minor, config::gnuradio_patch, config::gnuradio_tweak) >=config::gnuradio_version_num(3, 10, 11, 0), const void *, void * >::type fec_input_buffer_type
Definition code.h:35
Definition amsat_duv_decoder.h:29