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 <gnuradio/digital/lfsr.h>
27
28#include <deque>
29
30namespace gr {
31namespace 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{
55public:
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 using sptr = std::shared_ptr<ax25_decoder>;
80
81 static sptr make(const std::string& addr,
82 uint8_t ssid,
83 bool promisc = false,
84 bool descramble = true,
85 bool crc_check = true,
86 size_t max_frame_len = 512,
87 bool error_correction = false);
88
89 /**
90 * The decoder take as input a quadrature demodulated bit stream.
91 * Each byte should contains only one bit of information at the LSB.
92 *
93 * The decoder will try to find an AX.25 frame. If the frame pass the
94 * CRC check then at the metadata the CRC_VALID option will be set to true,
95 * otherwise to false. CRC invalid frames are meaningful because only one
96 * bit of error can cause the entire frame to fail. This will help to recover
97 * at least some bytes from a corrupted message.
98 *
99 * The decoder also supports destination callsign check. Only frames with
100 * the right destination Callsign will be accepted. This feature can be
101 * disabled using the promisc parameter.
102 * @param addr the Callsign of the receiver
103 * @param ssid the SSID of the receiver
104 * @param promisc if set to yes, the Callsign check is disabled
105 * @param descramble if set to yes, the data will be descrambled prior
106 * decoding using the G3RUH self-synchronizing descrambler.
107 * @param crc_check bypass the CRC check of the frame
108 * @param max_frame_len the maximum allowed frame length
109 * @param error_correction set to true to enable the 1-bit error correction
110 */
111 ax25_decoder(const std::string& addr,
112 uint8_t ssid,
113 bool promisc = false,
114 bool descramble = true,
115 bool crc_check = true,
116 size_t max_frame_len = 512,
117 bool error_correction = false);
118
120
121 decoder_status_t decode(const void* in, int len);
122
123 void reset();
124
125private:
126 typedef enum { NO_SYNC, IN_SYNC, DECODING } decoding_state_t;
127
128 /**
129 * If this flag is set, the decoder operates in promiscuous mode and
130 * forwards all successfully decoded frames
131 */
132 const bool d_promisc;
133 const bool d_descramble;
134 const bool d_crc_check;
135 const size_t d_max_frame_len;
136 const bool d_error_correction;
137 decoding_state_t d_state;
138 uint8_t d_shift_reg;
139 uint8_t d_dec_b;
140 uint8_t d_prev_bit_nrzi;
141 size_t d_received_bytes;
142 size_t d_decoded_bits;
143 digital::lfsr d_lfsr;
144 uint8_t* d_frame_buffer;
145 std::deque<uint8_t> d_bitstream;
146 size_t d_start_idx;
147 uint64_t d_frame_start;
148 uint64_t d_sample_cnt;
149
150 void reset_state();
151 void enter_sync_state();
152 void enter_decoding_state();
153 bool enter_frame_end(decoder_status_t& status);
154
155 bool _decode(decoder_status_t& status);
156
157 inline void decode_1b(uint8_t in);
158 bool is_frame_valid();
159 bool error_correction();
160};
161
162} // namespace satnogs
163} // namespace gr
164
165#endif /* INCLUDED_SATNOGS_AX25_DECODER_H */
#define SATNOGS_API
Definition: api.h:19
AX.25 decoder that supports the legacy hardware radios.
Definition: ax25_decoder.h:54
ax25_decoder(const std::string &addr, uint8_t ssid, bool promisc=false, bool descramble=true, bool crc_check=true, size_t max_frame_len=512, bool error_correction=false)
decoder_status_t decode(const void *in, int len)
std::shared_ptr< ax25_decoder > sptr
Definition: ax25_decoder.h:79
static sptr make(const std::string &addr, uint8_t ssid, bool promisc=false, bool descramble=true, bool crc_check=true, size_t max_frame_len=512, bool error_correction=false)
Abstract class that provided the API for the c decoders.
Definition: decoder.h:71
class decoder_status decoder_status_t
Definition: decoder.h:56
Definition: amsat_duv_decoder.h:29