GNU Radio's SATNOGS Package
ieee802_15_4_variant_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-2023, 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 * SPDX-License-Identifier: GNU General Public License v3.0 or later
21 */
22
23
24#ifndef INCLUDED_SATNOGS_IEEE802_15_4_VARIANT_DECODER_H
25#define INCLUDED_SATNOGS_IEEE802_15_4_VARIANT_DECODER_H
26
32
33
34namespace gr {
35namespace satnogs {
36
37/*!
38 * \brief A IEEE 802.15.4 like decoder
39 *
40 * The IEEE 802.15.4 uses the well known preamble + sync word synchronization
41 * scheme. Many popular on Cubesats ICs like the Texas Instruments CC1xxx family
42 * or the AXxxxx of On Semiconductors follow this scheme. This decoder
43 * class provides a generic way to decode signals following this framing
44 * scheme.
45 *
46 */
48{
49public:
50 /**
51 *
52 * @param preamble the preamble should be a repeated word. Note that due to AGC
53 * settling, the receiver may not receive the whole preamble. If the preamble
54 * is indeed a repeated pattern, a portion of it can be given as parameter.
55 * The block should be able to deal with this. However, a quite small subset
56 * may lead to a larger number of false alarms
57 *
58 * @param preamble_threshold the maximum number of bits that are
59 * allowed to be wrong at the preamble
60 *
61 * @param sync the synchronization work following the preamble
62 *
63 * @param sync_threshold the maximum number of bits that are
64 * allowed to be wrong at the synchronization word
65 *
66 * @param crc the CRC scheme to use
67 *
68 * @param descrambler if set, data will be first descrambled by this descrambling
69 * method
70 *
71 * @param var_len if set to true, variable length decoding is used. Otherwise,
72 * the \p max_len parameter indicates the fixed frame size
73 *
74 * @param max_len the maximum allowed decode-able frame length
75 *
76 * @param rs if set, the decoder will perform RS(255,223) decoding prior the
77 * descrambling and the CRC
78 *
79 * @return shared pointer of the decoder
80 */
81 using sptr = std::shared_ptr<ieee802_15_4_variant_decoder>;
82 static sptr make(const std::vector<uint8_t>& preamble,
83 size_t preamble_threshold,
84 const std::vector<uint8_t>& sync,
85 size_t sync_threshold,
87 whitening::sptr descrambler,
88 bool var_len = true,
89 size_t max_len = 1024,
90 bool drop_invalid = true,
91 bool rs = false);
92
93 ieee802_15_4_variant_decoder(const std::vector<uint8_t>& preamble,
94 size_t preamble_threshold,
95 const std::vector<uint8_t>& sync,
96 size_t sync_threshold,
98 whitening::sptr descrambler,
99 bool var_len = true,
100 size_t max_len = 1024,
101 bool drop_invalid = true,
102 bool rs = false);
104
105 decoder_status_t decode(const void* in, int len);
106
107 void reset();
108
109 size_t input_multiple() const;
110
111private:
112 /**
113 * Decoding FSM states
114 */
115 typedef enum {
116 SEARCHING, //!< when searching for the start of the preamble
117 SEARCHING_SYNC, //!< We have preamble, search for sync
118 DECODING_GENERIC_FRAME_LEN, //!< Decoding the frame length
119 DECODING_PAYLOAD //!< Decoding the payload
120 } decoding_state_t;
121
122 shift_reg d_preamble;
123 shift_reg d_preamble_shift_reg;
124 const size_t d_preamble_len;
125 const size_t d_preamble_thrsh;
126 shift_reg d_sync;
127 shift_reg d_sync_shift_reg;
128 const size_t d_sync_len;
129 const size_t d_sync_thrsh;
130 crc::type d_crc;
131 whitening::sptr d_descrambler;
132 const bool d_var_len;
133 const bool d_drop_invalid;
134 const bool d_rs;
135 size_t d_len;
136 size_t d_length_field_len;
137 decoding_state_t d_state;
138 size_t d_cnt;
139 uint64_t d_frame_start_idx;
140 uint8_t* d_pdu;
141
142 decoder_status_t decode_var_len(const void* in, int len);
143
144 decoder_status_t decode_const_len(const void* in, int len);
145
146 int search_preamble(const uint8_t* in, int len);
147
148 int search_sync(const uint8_t* in, int len);
149
150 int decode_frame_len(const uint8_t* in);
151
152 void decode_payload(decoder_status_t& status, const uint8_t* in, int len);
153
154 bool check_crc();
155};
156
157} // namespace satnogs
158} // namespace gr
159
160#endif /* INCLUDED_SATNOGS_IEEE802_15_4_VARIANT_DECODER_H */
#define SATNOGS_API
Definition: api.h:19
Definition: crc.h:44
type
Predefined CRC types.
Definition: crc.h:51
Abstract class that provided the API for the c decoders.
Definition: decoder.h:71
A IEEE 802.15.4 like decoder.
Definition: ieee802_15_4_variant_decoder.h:48
static sptr make(const std::vector< uint8_t > &preamble, size_t preamble_threshold, const std::vector< uint8_t > &sync, size_t sync_threshold, crc::type crc, whitening::sptr descrambler, bool var_len=true, size_t max_len=1024, bool drop_invalid=true, bool rs=false)
ieee802_15_4_variant_decoder(const std::vector< uint8_t > &preamble, size_t preamble_threshold, const std::vector< uint8_t > &sync, size_t sync_threshold, crc::type crc, whitening::sptr descrambler, bool var_len=true, size_t max_len=1024, bool drop_invalid=true, bool rs=false)
std::shared_ptr< ieee802_15_4_variant_decoder > sptr
Definition: ieee802_15_4_variant_decoder.h:81
decoder_status_t decode(const void *in, int len)
Implements a bit shift register.
Definition: shift_reg.h:36
std::shared_ptr< whitening > sptr
Definition: whitening.h:42
class decoder_status decoder_status_t
Definition: decoder.h:56
Definition: amsat_duv_decoder.h:29
Definition: rs-common.h:7