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