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  * @return shared pointer of the decoder
74  */
75  static decoder::decoder_sptr
76  make(const std::vector<uint8_t> &preamble,
77  size_t preamble_threshold,
78  const std::vector<uint8_t> &sync,
79  size_t sync_threshold,
81  whitening::whitening_sptr descrambler, bool var_len = true,
82  size_t max_len = 1024);
83 
84  ieee802_15_4_variant_decoder(const std::vector<uint8_t> &preamble,
85  size_t preamble_threshold,
86  const std::vector<uint8_t> &sync,
87  size_t sync_threshold,
88  crc::crc_t crc,
89  whitening::whitening_sptr descrambler,
90  bool var_len = true,
91  size_t max_len = 1024);
93 
95  decode(const void *in, int len);
96 
97  void
98  reset();
99 
100  size_t
101  input_multiple() const;
102 
103 private:
104  /**
105  * Decoding FSM states
106  */
107  typedef enum {
108  SEARCHING, //!< when searching for the start of the preamble
109  SEARCHING_SYNC, //!< We have preamble, search for sync
110  DECODING_GENERIC_FRAME_LEN, //!< Decoding the frame length
111  DECODING_PAYLOAD //!< Decoding the payload
112  } decoding_state_t;
113 
114  shift_reg d_preamble;
115  shift_reg d_preamble_shift_reg;
116  const size_t d_preamble_len;
117  const size_t d_preamble_thrsh;
118  shift_reg d_sync;
119  shift_reg d_sync_shift_reg;
120  const size_t d_sync_len;
121  const size_t d_sync_thrsh;
122  crc::crc_t d_crc;
123  whitening::whitening_sptr d_descrambler;
124  const bool d_var_len;
125  size_t d_len;
126  size_t d_length_field_len;
127  decoding_state_t d_state;
128  size_t d_cnt;
129  uint64_t d_frame_start_idx;
130  uint8_t *d_pdu;
131 
133  decode_var_len(const void *in, int len);
134 
136  decode_const_len(const void *in, int len);
137 
138  int
139  search_preamble(const uint8_t *in, int len);
140 
141  int
142  search_sync(const uint8_t *in, int len);
143 
144  int
145  decode_frame_len(const uint8_t *in);
146 
147  void
148  decode_payload(decoder_status_t &status, const uint8_t *in, int len);
149 
150  bool
151  check_crc();
152 
153 };
154 
155 } // namespace satnogs
156 } // namespace gr
157 
158 #endif /* INCLUDED_SATNOGS_IEEE802_15_4_VARIANT_DECODER_H */
159 
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