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
31
32
33namespace gr {
34namespace satnogs {
35
36/*!
37 * \brief A IEEE 802.15.4 like decoder
38 *
39 * The IEEE 802.15.4 uses the well known preamble + sync word synchronization
40 * scheme. Many popular on Cubesats ICs like the Texas Instruments CC1xxx family
41 * or the AXxxxx of On Semiconductors follow this scheme. This decoder
42 * class provides a generic way to decode signals following this framing
43 * scheme.
44 *
45 */
47{
48public:
49 /**
50 *
51 * @param preamble the preamble should be a repeated word. Note that due to AGC
52 * settling, the receiver may not receive the whole preamble. If the preamble
53 * is indeed a repeated pattern, a portion of it can be given as parameter.
54 * The block should be able to deal with this. However, a quite small subset
55 * may lead to a larger number of false alarms
56 *
57 * @param preamble_threshold the maximum number of bits that are
58 * allowed to be wrong at the preamble
59 *
60 * @param sync the synchronization work following the preamble
61 *
62 * @param sync_threshold the maximum number of bits that are
63 * allowed to be wrong at the synchronization word
64 *
65 * @param crc the CRC scheme to use
66 *
67 *
68 * @param var_len if set to true, variable length decoding is used. Otherwise,
69 * the \p max_len parameter indicates the fixed frame size
70 *
71 * @param max_len the maximum allowed decode-able frame length
72 *
73 * @param rs if set, the decoder will perform RS(255,223) decoding prior the
74 * descrambling and the CRC
75 *
76 * @return shared pointer of the decoder
77 */
78 using sptr = std::shared_ptr<ieee802_15_4_variant_decoder>;
79 static sptr make(const std::vector<uint8_t>& preamble,
80 size_t preamble_threshold,
81 const std::vector<uint8_t>& sync,
82 size_t sync_threshold,
83 size_t max_len = 1024);
84
85 ieee802_15_4_variant_decoder(const std::vector<uint8_t>& preamble,
86 size_t preamble_threshold,
87 const std::vector<uint8_t>& sync,
88 size_t sync_threshold,
89 size_t max_len = 1024);
90
91
92 static sptr make(const std::vector<uint8_t>& preamble,
93 size_t preamble_threshold,
94 uint8_t length_field_bytes,
95 const std::vector<uint8_t>& sync,
96 size_t sync_threshold);
97
98 ieee802_15_4_variant_decoder(const std::vector<uint8_t>& preamble,
99 size_t preamble_threshold,
100 uint8_t length_field_bytes,
101 const std::vector<uint8_t>& sync,
102 size_t sync_threshold);
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 const bool d_var_len;
131 size_t d_len;
132 size_t d_length_field_len;
133 decoding_state_t d_state;
134 size_t d_cnt;
135 uint64_t d_frame_start_idx;
136 uint8_t* d_pdu;
137 size_t d_max_frame_len;
138
139
140 decoder_status_t decode_var_len(const void* in, int len);
141
142 decoder_status_t decode_const_len(const void* in, int len);
143
144 int search_preamble(const uint8_t* in, int len);
145
146 int search_sync(const uint8_t* in, int len);
147
148 int decode_frame_len(const uint8_t* in);
149
150 void decode_payload(decoder_status_t& status, const uint8_t* in, int len);
151};
152
153} // namespace satnogs
154} // namespace gr
155
156#endif /* INCLUDED_SATNOGS_IEEE802_15_4_VARIANT_DECODER_H */
#define SATNOGS_API
Definition api.h:19
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:47
std::shared_ptr< ieee802_15_4_variant_decoder > sptr
Definition ieee802_15_4_variant_decoder.h:78
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, size_t max_len=1024)
static sptr make(const std::vector< uint8_t > &preamble, size_t preamble_threshold, const std::vector< uint8_t > &sync, size_t sync_threshold, size_t max_len=1024)
decoder_status_t decode(const void *in, int len)
ieee802_15_4_variant_decoder(const std::vector< uint8_t > &preamble, size_t preamble_threshold, uint8_t length_field_bytes, const std::vector< uint8_t > &sync, size_t sync_threshold)
static sptr make(const std::vector< uint8_t > &preamble, size_t preamble_threshold, uint8_t length_field_bytes, const std::vector< uint8_t > &sync, size_t sync_threshold)
Implements a bit shift register.
Definition shift_reg.h:36
class decoder_status decoder_status_t
Definition decoder.h:56
Definition amsat_duv_decoder.h:29