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 *
47 * \ingroup satnogs
48 *
49 */
51{
52public:
53 /**
54 * The decoder take as input a quadrature demodulated bit stream.
55 * Each byte should contains only one bit of information at the LSB.
56 *
57 * The decoder will try to find an AX.25 frame. If the frame pass the
58 * CRC check then at the metadata the CRC_VALID option will be set to true,
59 * otherwise to false. CRC invalid frames are meaningful because only one
60 * bit of error can cause the entire frame to fail. This will help to recover
61 * at least some bytes from a corrupted message.
62 *
63 * @param addr the Callsign of the receiver
64 * @param ssid the SSID of the receiver
65 * @param descramble if set to yes, the data will be descrambled prior
66 * decoding using the G3RUH self-synchronizing descrambler.
67 * @param max_frame_len the maximum allowed frame length
68 * @param error_correction set to true to enable the 1-bit error correction
69 *
70 * @return a shared pointer of the decoder instance
71 */
72 using sptr = std::shared_ptr<ax25_decoder>;
73
74 static sptr make(const std::string& addr,
75 uint8_t ssid,
76 bool descramble = true,
77 bool crc_check = true,
78 size_t max_frame_len = 512,
79 bool error_correction = false);
80
81 /**
82 * The decoder take as input a quadrature demodulated bit stream.
83 * Each byte should contains only one bit of information at the LSB.
84 *
85 * The decoder will try to find an AX.25 frame. If the frame pass the
86 * CRC check then at the metadata the CRC_VALID option will be set to true,
87 * otherwise to false. CRC invalid frames are meaningful because only one
88 * bit of error can cause the entire frame to fail. This will help to recover
89 * at least some bytes from a corrupted message.
90 *
91 * @param addr the Callsign of the receiver
92 * @param ssid the SSID of the receiver
93 * @param descramble if set to yes, the data will be descrambled prior
94 * decoding using the G3RUH self-synchronizing descrambler.
95 * @param crc_check bypass the CRC check of the frame
96 * @param max_frame_len the maximum allowed frame length
97 * @param error_correction set to true to enable the 1-bit error correction
98 */
99 ax25_decoder(const std::string& addr,
100 uint8_t ssid,
101 bool descramble = true,
102 bool crc_check = true,
103 size_t max_frame_len = 512,
104 bool error_correction = false);
105
107
108 decoder_status_t decode(const void* in, int len);
109
110 void reset();
111
112private:
113 typedef enum { NO_SYNC, IN_SYNC, DECODING } decoding_state_t;
114
115
116 const bool d_descramble;
117 const bool d_crc_check;
118 const size_t d_max_frame_len;
119 const bool d_error_correction;
120 decoding_state_t d_state;
121 uint8_t d_shift_reg;
122 uint8_t d_dec_b;
123 uint8_t d_prev_bit_nrzi;
124 size_t d_received_bytes;
125 size_t d_decoded_bits;
126 digital::lfsr d_lfsr;
127 uint8_t* d_frame_buffer;
128 std::deque<uint8_t> d_bitstream;
129 size_t d_start_idx;
130 uint64_t d_frame_start;
131 uint64_t d_sample_cnt;
132
133 void reset_state();
134 void enter_sync_state();
135 void enter_decoding_state();
136 bool enter_frame_end(decoder_status_t& status);
137
138 bool _decode(decoder_status_t& status);
139
140 inline void decode_1b(uint8_t in);
141 bool is_frame_valid();
142 bool error_correction();
143};
144
145} // namespace satnogs
146} // namespace gr
147
148#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:51
decoder_status_t decode(const void *in, int len)
std::shared_ptr< ax25_decoder > sptr
Definition ax25_decoder.h:72
static sptr make(const std::string &addr, uint8_t ssid, bool descramble=true, bool crc_check=true, size_t max_frame_len=512, bool error_correction=false)
ax25_decoder(const std::string &addr, uint8_t ssid, 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