Add convolutional deinterleaver
This commit is contained in:
parent
62fb14e3d1
commit
dcadfe9ab1
|
@ -16,5 +16,15 @@
|
|||
<name>in</name>
|
||||
<type>complex</type>
|
||||
</sink>
|
||||
|
||||
<source>
|
||||
<name>cadu</name>
|
||||
<type>message</type>
|
||||
</source>
|
||||
|
||||
<source>
|
||||
<name>reset</name>
|
||||
<type>message</type>
|
||||
</source>
|
||||
|
||||
</block>
|
|
@ -32,6 +32,7 @@ list(APPEND HEADER_FILES
|
|||
api.h
|
||||
ax25.h
|
||||
config.h
|
||||
convolutional_deinterleaver.h
|
||||
log.h
|
||||
morse_tree.h
|
||||
morse.h
|
||||
|
@ -71,5 +72,6 @@ install(FILES
|
|||
decoder_8b10b.h
|
||||
ccsds_rs_decoder_mm.h
|
||||
fox_telem_mm.h
|
||||
lrpt_sync.h DESTINATION include/satnogs
|
||||
lrpt_sync.h
|
||||
lrpt_decoder.h DESTINATION include/satnogs
|
||||
)
|
|
@ -0,0 +1,63 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
||||
*
|
||||
* Copyright (C) 2018, Libre Space Foundation <http://librespacefoundation.org/>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_SATNOGS_CONVOLUTIONAL_DEINTERLEAVER_H
|
||||
#define INCLUDED_SATNOGS_CONVOLUTIONAL_DEINTERLEAVER_H
|
||||
|
||||
#include <satnogs/api.h>
|
||||
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
namespace gr
|
||||
{
|
||||
namespace satnogs
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief <+description+>
|
||||
*
|
||||
*/
|
||||
class SATNOGS_API convolutional_deinterleaver
|
||||
{
|
||||
public:
|
||||
convolutional_deinterleaver (size_t branches, size_t M);
|
||||
~convolutional_deinterleaver ();
|
||||
|
||||
uint8_t
|
||||
decode_bit(uint8_t b);
|
||||
|
||||
uint8_t
|
||||
decode_byte(uint8_t b);
|
||||
|
||||
void
|
||||
reset();
|
||||
|
||||
private:
|
||||
const size_t d_nbranches;
|
||||
const size_t d_M;
|
||||
size_t d_idx;
|
||||
std::vector<std::deque<uint8_t>> d_branches;
|
||||
};
|
||||
|
||||
} // namespace satnogs
|
||||
} // namespace gr
|
||||
|
||||
#endif /* INCLUDED_SATNOGS_CONVOLUTIONAL_DEINTERLEAVER_H */
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
||||
*
|
||||
* Copyright (C) 2018, Libre Space Foundation <http://librespacefoundation.org/>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_SATNOGS_LRPT_DECODER_H
|
||||
#define INCLUDED_SATNOGS_LRPT_DECODER_H
|
||||
|
||||
#include <satnogs/api.h>
|
||||
#include <gnuradio/block.h>
|
||||
|
||||
namespace gr
|
||||
{
|
||||
namespace satnogs
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief <+description of block+>
|
||||
* \ingroup satnogs
|
||||
*
|
||||
*/
|
||||
class SATNOGS_API lrpt_decoder : virtual public gr::block
|
||||
{
|
||||
public:
|
||||
typedef boost::shared_ptr<lrpt_decoder> sptr;
|
||||
|
||||
/*!
|
||||
* \brief Return a shared_ptr to a new instance of satnogs::lrpt_decoder.
|
||||
*
|
||||
* To avoid accidental use of raw pointers, satnogs::lrpt_decoder's
|
||||
* constructor is in a private implementation
|
||||
* class. satnogs::lrpt_decoder::make is the public interface for
|
||||
* creating new instances.
|
||||
*/
|
||||
static sptr
|
||||
make ();
|
||||
};
|
||||
|
||||
} // namespace satnogs
|
||||
} // namespace gr
|
||||
|
||||
#endif /* INCLUDED_SATNOGS_LRPT_DECODER_H */
|
||||
|
|
@ -70,7 +70,9 @@ list(APPEND satnogs_sources
|
|||
decoder_8b10b_impl.cc
|
||||
ccsds_rs_decoder_mm_impl.cc
|
||||
fox_telem_mm_impl.cc
|
||||
lrpt_sync_impl.cc)
|
||||
lrpt_sync_impl.cc
|
||||
convolutional_deinterleaver.cc
|
||||
lrpt_decoder_impl.cc)
|
||||
|
||||
if(${INCLUDE_DEBUG_BLOCKS})
|
||||
list(APPEND satnogs_sources ${satnogs_debug_sources})
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
||||
*
|
||||
* Copyright (C) 2018, Libre Space Foundation <http://librespacefoundation.org/>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gnuradio/io_signature.h>
|
||||
#include <satnogs/convolutional_deinterleaver.h>
|
||||
|
||||
namespace gr
|
||||
{
|
||||
namespace satnogs
|
||||
{
|
||||
|
||||
convolutional_deinterleaver::convolutional_deinterleaver (size_t branches,
|
||||
size_t M) :
|
||||
d_nbranches (branches),
|
||||
d_M (M),
|
||||
d_idx(0)
|
||||
{
|
||||
for(size_t i = 0; i < d_nbranches; i++) {
|
||||
d_branches.push_back(std::deque<uint8_t>((d_nbranches - 1 - i) * M, 0));
|
||||
}
|
||||
}
|
||||
|
||||
convolutional_deinterleaver::~convolutional_deinterleaver ()
|
||||
{
|
||||
}
|
||||
|
||||
uint8_t
|
||||
convolutional_deinterleaver::decode_bit (uint8_t b)
|
||||
{
|
||||
uint8_t ret;
|
||||
d_branches[d_idx].push_back(b);
|
||||
ret = d_branches[d_idx].front();
|
||||
d_branches[d_idx].pop_front();
|
||||
d_idx = (d_idx + 1) % d_nbranches;
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
convolutional_deinterleaver::decode_byte (uint8_t b)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
ret = decode_bit(b >> 7) << 7;
|
||||
ret |= decode_bit((b >> 6) & 0x1) << 6;
|
||||
ret |= decode_bit((b >> 5) & 0x1) << 5;
|
||||
ret |= decode_bit((b >> 4) & 0x1) << 4;
|
||||
ret |= decode_bit((b >> 3) & 0x1) << 3;
|
||||
ret |= decode_bit((b >> 2) & 0x1) << 2;
|
||||
ret |= decode_bit((b >> 1) & 0x1) << 1;
|
||||
ret |= decode_bit(b & 0x1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
convolutional_deinterleaver::reset ()
|
||||
{
|
||||
d_branches.clear();
|
||||
for(size_t i = 0; i < d_nbranches; i++) {
|
||||
d_branches.push_back(std::deque<uint8_t>((d_nbranches - 1 - i) * d_M, 0));
|
||||
}
|
||||
d_idx = 0;
|
||||
}
|
||||
|
||||
} /* namespace satnogs */
|
||||
} /* namespace gr */
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
||||
*
|
||||
* Copyright (C) 2018, Libre Space Foundation <http://librespacefoundation.org/>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gnuradio/io_signature.h>
|
||||
#include "lrpt_decoder_impl.h"
|
||||
#include <satnogs/log.h>
|
||||
#include <fec.h>
|
||||
|
||||
namespace gr
|
||||
{
|
||||
namespace satnogs
|
||||
{
|
||||
|
||||
lrpt_decoder::sptr
|
||||
lrpt_decoder::make ()
|
||||
{
|
||||
return gnuradio::get_initial_sptr (new lrpt_decoder_impl ());
|
||||
}
|
||||
|
||||
/*
|
||||
* The private constructor
|
||||
*/
|
||||
lrpt_decoder_impl::lrpt_decoder_impl()
|
||||
: gr::block("lrpt_decoder",
|
||||
gr::io_signature::make(0, 0, 0),
|
||||
gr::io_signature::make(0, 0, 0)),
|
||||
d_cadu_len(1020),
|
||||
d_coded_cadu_len(1020 * 2),
|
||||
d_conv_deinterl(36, 2048)
|
||||
{
|
||||
|
||||
message_port_register_in(pmt::mp("cadu"));
|
||||
message_port_register_in(pmt::mp("reset"));
|
||||
|
||||
set_msg_handler (
|
||||
pmt::mp ("cadu"),
|
||||
boost::bind (&lrpt_decoder_impl::decode, this, _1));
|
||||
|
||||
set_msg_handler (
|
||||
pmt::mp ("reset"),
|
||||
boost::bind (&lrpt_decoder_impl::reset, this, _1));
|
||||
|
||||
d_vt = create_viterbi27(d_cadu_len * 8);
|
||||
if(!d_vt) {
|
||||
throw std::runtime_error("lrpt_decoder: Failed to init Viterbi decoder");
|
||||
}
|
||||
int polys[2] = {0x79, 0x5b};
|
||||
set_viterbi27_polynomial(polys);
|
||||
|
||||
d_cadu = new uint8_t[d_cadu_len];
|
||||
d_coded_cadu_deinterl = new uint8_t[d_coded_cadu_len];
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Our virtual destructor.
|
||||
*/
|
||||
lrpt_decoder_impl::~lrpt_decoder_impl ()
|
||||
{
|
||||
|
||||
delete [] d_cadu;
|
||||
delete [] d_coded_cadu_deinterl;
|
||||
}
|
||||
|
||||
void
|
||||
lrpt_decoder_impl::decode (pmt::pmt_t m)
|
||||
{
|
||||
const uint8_t *coded_cadu = (const uint8_t *)pmt::blob_data(m);
|
||||
if(pmt::blob_length(m) != d_coded_cadu_len) {
|
||||
LOG_ERROR("Wrong CADU size");
|
||||
return;
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < d_coded_cadu_len; i++) {
|
||||
d_coded_cadu_deinterl[i] = d_conv_deinterl.decode_byte(coded_cadu[i]);
|
||||
}
|
||||
init_viterbi27(d_vt, 0);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
lrpt_decoder_impl::reset (pmt::pmt_t m)
|
||||
{
|
||||
if(pmt::to_bool(m)) {
|
||||
d_conv_deinterl.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} /* namespace satnogs */
|
||||
} /* namespace gr */
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
||||
*
|
||||
* Copyright (C) 2018, Libre Space Foundation <http://librespacefoundation.org/>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_SATNOGS_LRPT_DECODER_IMPL_H
|
||||
#define INCLUDED_SATNOGS_LRPT_DECODER_IMPL_H
|
||||
|
||||
#include <satnogs/lrpt_decoder.h>
|
||||
#include <satnogs/convolutional_deinterleaver.h>
|
||||
|
||||
namespace gr
|
||||
{
|
||||
namespace satnogs
|
||||
{
|
||||
|
||||
class lrpt_decoder_impl : public lrpt_decoder
|
||||
{
|
||||
|
||||
public:
|
||||
lrpt_decoder_impl ();
|
||||
~lrpt_decoder_impl ();
|
||||
|
||||
private:
|
||||
const size_t d_cadu_len;
|
||||
const size_t d_coded_cadu_len;
|
||||
convolutional_deinterleaver d_conv_deinterl;
|
||||
uint8_t *d_coded_cadu_deinterl;
|
||||
uint8_t *d_cadu;
|
||||
void *d_vt;
|
||||
|
||||
void
|
||||
decode(pmt::pmt_t m);
|
||||
|
||||
void
|
||||
reset(pmt::pmt_t m);
|
||||
};
|
||||
|
||||
} // namespace satnogs
|
||||
} // namespace gr
|
||||
|
||||
#endif /* INCLUDED_SATNOGS_LRPT_DECODER_IMPL_H */
|
||||
|
|
@ -57,11 +57,12 @@ lrpt_sync_impl::lrpt_sync_impl (size_t threshold) :
|
|||
*/
|
||||
d_window((72 + 8)/2),
|
||||
/* Each CADU has the 4 byte ASM and a VCDU of 1020 bytes*/
|
||||
d_coded_cadu_len((4 + 1020) * 2),
|
||||
d_coded_cadu_len(1020 * 2),
|
||||
d_frame_sync(false),
|
||||
d_received(0),
|
||||
d_rotate(1, 0),
|
||||
d_qpsk(digital::constellation_qpsk::make()),
|
||||
d_conv_deinter(36, 2048),
|
||||
d_shift_reg0(0x0),
|
||||
d_shift_reg1(0x0),
|
||||
d_shift_reg2(0x0),
|
||||
|
@ -96,9 +97,10 @@ lrpt_sync_impl::lrpt_sync_impl (size_t threshold) :
|
|||
throw std::runtime_error("lrpt_sync: Could not allocate memory");
|
||||
}
|
||||
|
||||
d_coded_cadu = new uint8_t[(4 + 1020) * 2];
|
||||
/* Copy the coded ASM in front */
|
||||
memcpy(d_coded_cadu, &d_asm_coded, sizeof(uint64_t));
|
||||
d_coded_cadu = new uint8_t[d_coded_cadu_len];
|
||||
|
||||
message_port_register_out(pmt::mp("cadu"));
|
||||
message_port_register_out(pmt::mp("reset"));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -139,38 +141,42 @@ lrpt_sync_impl::work_no_sync(const gr_complex *in, int noutput_items)
|
|||
*/
|
||||
for(int j = 0; j < d_window; j++) {
|
||||
bits = d_qpsk->decision_maker(in + i * d_window + j);
|
||||
//bits = (d_conv_deinter.decode_bit(bits >> 1) << 1) | d_conv_deinter.decode_bit(bits & 0x1);
|
||||
d_shift_reg0 = (d_shift_reg0 << 2) | bits;
|
||||
if(found_sync(d_shift_reg0)) {
|
||||
d_rotate = gr_complex(1.0, 0);
|
||||
d_frame_sync = true;
|
||||
d_received = sizeof(uint64_t);
|
||||
LOG_ERROR("SYNC");
|
||||
return i * d_window + j;
|
||||
}
|
||||
|
||||
bits = d_qpsk->decision_maker(d_rotate_pi2 + j);
|
||||
//bits = (d_conv_deinter.decode_bit(bits >> 1) << 1) | d_conv_deinter.decode_bit(bits & 0x1);
|
||||
d_shift_reg1 = (d_shift_reg1 << 2) | bits;
|
||||
if(found_sync(d_shift_reg1)) {
|
||||
d_rotate = gr_complex(0.0, 1.0);
|
||||
d_frame_sync = true;
|
||||
d_received = sizeof(uint64_t);
|
||||
LOG_ERROR("SYNC");
|
||||
return i * d_window + j;
|
||||
}
|
||||
|
||||
bits = d_qpsk->decision_maker(d_rotate_2pi2 + j);
|
||||
//bits = (d_conv_deinter.decode_bit(bits >> 1) << 1) | d_conv_deinter.decode_bit(bits & 0x1);
|
||||
d_shift_reg2 = (d_shift_reg2 << 2) | bits;
|
||||
if(found_sync(d_shift_reg2)) {
|
||||
d_rotate = gr_complex(-1.0, 0);
|
||||
d_frame_sync = true;
|
||||
d_received = sizeof(uint64_t);
|
||||
LOG_ERROR("SYNC");
|
||||
return i * d_window + j;
|
||||
}
|
||||
|
||||
bits = d_qpsk->decision_maker(d_rotate_3pi2 + j);
|
||||
//bits = (d_conv_deinter.decode_bit(bits >> 1) << 1) | d_conv_deinter.decode_bit(bits & 0x1);
|
||||
d_shift_reg3 = (d_shift_reg3 << 2) | bits;
|
||||
if(found_sync(d_shift_reg3)) {
|
||||
d_rotate = gr_complex(0.0, -1.0);
|
||||
d_frame_sync = true;
|
||||
d_received = sizeof(uint64_t);
|
||||
LOG_ERROR("SYNC");
|
||||
return i * d_window + j;
|
||||
}
|
||||
}
|
||||
|
@ -202,6 +208,8 @@ lrpt_sync_impl::work_sync(const gr_complex *in, int noutput_items)
|
|||
LOG_ERROR("frame");
|
||||
d_received = 0;
|
||||
d_frame_sync = false;
|
||||
message_port_pub (pmt::mp ("cadu"),
|
||||
pmt::make_blob (d_coded_cadu, d_coded_cadu_len));
|
||||
return i * d_window + j + 4;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#define INCLUDED_SATNOGS_LRPT_SYNC_IMPL_H
|
||||
|
||||
#include <satnogs/lrpt_sync.h>
|
||||
#include <satnogs/convolutional_deinterleaver.h>
|
||||
#include <gnuradio/digital/constellation.h>
|
||||
|
||||
namespace gr
|
||||
|
@ -51,6 +52,7 @@ private:
|
|||
size_t d_received;
|
||||
gr_complex d_rotate;
|
||||
digital::constellation_qpsk::sptr d_qpsk;
|
||||
convolutional_deinterleaver d_conv_deinter;
|
||||
uint64_t d_shift_reg0;
|
||||
uint64_t d_shift_reg1;
|
||||
uint64_t d_shift_reg2;
|
||||
|
|
Loading…
Reference in New Issue