GNU Radio's SATNOGS Package
ax25_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, 2020 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_AX25_DECODER_H
22 #define INCLUDED_SATNOGS_AX25_DECODER_H
23 
24 #include <satnogs/api.h>
25 #include <satnogs/decoder.h>
26 #include <gnuradio/digital/lfsr.h>
27 
28 #include <deque>
29 
30 namespace gr {
31 namespace satnogs {
32 
33 /*!
34  * \brief AX.25 decoder that supports the legacy hardware radios.
35  *
36  * This block takes as input a quadrature demodulated bit stream.
37  * Each byte should contains only one bit of information at the LSB.
38  *
39  * The block will try to find an AX.25 frame. If the frame pass the
40  * CRC check then a blob PMT message is produced at the message output
41  * indicated with name 'out'. Otherwise if the frame did not pass the
42  * CRC check or the size was invalid, a blob PMT message is generated at
43  * the output port with the name 'fail'. This will help to recover at least
44  * some bytes from a corrupted message.
45  *
46  * The block also supports destination callsign check. Only frames with
47  * the right destination Callsign will be accepted. This feature can be
48  * disabled using the promisc parameter.
49  *
50  * \ingroup satnogs
51  *
52  */
54 public:
55 
56  /**
57  * The decoder take as input a quadrature demodulated bit stream.
58  * Each byte should contains only one bit of information at the LSB.
59  *
60  * The decoder will try to find an AX.25 frame. If the frame pass the
61  * CRC check then at the metadata the CRC_VALID option will be set to true,
62  * otherwise to false. CRC invalid frames are meaningful because only one
63  * bit of error can cause the entire frame to fail. This will help to recover
64  * at least some bytes from a corrupted message.
65  *
66  * The decoder also supports destination callsign check. Only frames with
67  * the right destination Callsign will be accepted. This feature can be
68  * disabled using the promisc parameter.
69  * @param addr the Callsign of the receiver
70  * @param ssid the SSID of the receiver
71  * @param promisc if set to yes, the Callsign check is disabled
72  * @param descramble if set to yes, the data will be descrambled prior
73  * decoding using the G3RUH self-synchronizing descrambler.
74  * @param max_frame_len the maximum allowed frame length
75  * @param error_correction set to true to enable the 1-bit error correction
76  *
77  * @return a shared pointer of the decoder instance
78  */
79  static decoder::decoder_sptr
80  make(const std::string &addr, uint8_t ssid, bool promisc = false,
81  bool descramble = true, bool crc_check = true,
82  size_t max_frame_len = 512,
83  bool error_correction = false);
84 
85  /**
86  * The decoder take as input a quadrature demodulated bit stream.
87  * Each byte should contains only one bit of information at the LSB.
88  *
89  * The decoder will try to find an AX.25 frame. If the frame pass the
90  * CRC check then at the metadata the CRC_VALID option will be set to true,
91  * otherwise to false. CRC invalid frames are meaningful because only one
92  * bit of error can cause the entire frame to fail. This will help to recover
93  * at least some bytes from a corrupted message.
94  *
95  * The decoder also supports destination callsign check. Only frames with
96  * the right destination Callsign will be accepted. This feature can be
97  * disabled using the promisc parameter.
98  * @param addr the Callsign of the receiver
99  * @param ssid the SSID of the receiver
100  * @param promisc if set to yes, the Callsign check is disabled
101  * @param descramble if set to yes, the data will be descrambled prior
102  * decoding using the G3RUH self-synchronizing descrambler.
103  * @param crc_check bypass the CRC check of the frame
104  * @param max_frame_len the maximum allowed frame length
105  * @param error_correction set to true to enable the 1-bit error correction
106  */
107  ax25_decoder(const std::string &addr, uint8_t ssid, bool promisc = false,
108  bool descramble = true, bool crc_check = true,
109  size_t max_frame_len = 512,
110  bool error_correction = false);
111 
112  ~ax25_decoder();
113 
115  decode(const void *in, int len);
116 
117  void
118  reset();
119 private:
120 
121  typedef enum {
122  NO_SYNC, IN_SYNC, DECODING
123  } decoding_state_t;
124 
125  /**
126  * If this flag is set, the decoder operates in promiscuous mode and
127  * forwards all successfully decoded frames
128  */
129  const bool d_promisc;
130  const bool d_descramble;
131  const bool d_crc_check;
132  const size_t d_max_frame_len;
133  const bool d_error_correction;
134  decoding_state_t d_state;
135  uint8_t d_shift_reg;
136  uint8_t d_dec_b;
137  uint8_t d_prev_bit_nrzi;
138  size_t d_received_bytes;
139  size_t d_decoded_bits;
140  digital::lfsr d_lfsr;
141  uint8_t *d_frame_buffer;
142  std::deque<uint8_t> d_bitstream;
143  size_t d_start_idx;
144  uint64_t d_frame_start;
145  uint64_t d_sample_cnt;
146 
147  void
148  reset_state();
149  void
150  enter_sync_state();
151  void
152  enter_decoding_state();
153  bool
154  enter_frame_end(decoder_status_t &status);
155 
156  bool
157  _decode(decoder_status_t &status);
158 
159  inline void
160  decode_1b(uint8_t in);
161  bool
162  is_frame_valid();
163  bool
164  error_correction();
165 };
166 
167 } // namespace satnogs
168 } // namespace gr
169 
170 #endif /* INCLUDED_SATNOGS_AX25_DECODER_H */
171 
AX.25 decoder that supports the legacy hardware radios.
Definition: ax25_decoder.h:53
Abstract class that provided the API for the c decoders.
Definition: decoder.h:69
Definition: amsat_duv_decoder.h:29
class decoder_status decoder_status_t
Definition: decoder.h:55
#define SATNOGS_API
Definition: api.h:30