Add LRPT decoder

Currently it performs only convolutional decoding
This commit is contained in:
Manolis Surligas 2018-08-02 16:17:12 +03:00
parent dcadfe9ab1
commit 854becb15d
8 changed files with 229 additions and 209 deletions

View File

@ -36,6 +36,7 @@ list(APPEND enabled_blocks
satnogs_fox_telem_mm.xml satnogs_fox_telem_mm.xml
satnogs_frame_file_sink.xml satnogs_frame_file_sink.xml
satnogs_iq_sink.xml satnogs_iq_sink.xml
satnogs_lrpt_decoder.xml
satnogs_lrpt_sync.xml satnogs_lrpt_sync.xml
satnogs_morse_decoder.xml satnogs_morse_decoder.xml
satnogs_multi_format_msg_sink.xml satnogs_multi_format_msg_sink.xml

View File

@ -0,0 +1,17 @@
<?xml version="1.0"?>
<block>
<name>LRPT Frame Decoder</name>
<key>satnogs_lrpt_decoder</key>
<import>import satnogs</import>
<make>satnogs.lrpt_decoder()</make>
<sink>
<name>cadu</name>
<type>message</type>
</sink>
<source>
<name>frame</name>
<type>message</type>
</source>
</block>

View File

@ -21,10 +21,4 @@
<name>cadu</name> <name>cadu</name>
<type>message</type> <type>message</type>
</source> </source>
<source>
<name>reset</name>
<type>message</type>
</source>
</block> </block>

View File

@ -2,7 +2,7 @@
/* /*
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
* *
* Copyright (C) 2016, Libre Space Foundation <http://librespacefoundation.org/> * Copyright (C) 2016,2018 Libre Space Foundation <http://librespacefoundation.org/>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,28 +21,30 @@
#ifndef INCLUDE_SATNOGS_UTILS_H_ #ifndef INCLUDE_SATNOGS_UTILS_H_
#define INCLUDE_SATNOGS_UTILS_H_ #define INCLUDE_SATNOGS_UTILS_H_
#include <cstdint>
#include <cmath>
namespace gr namespace gr
{ {
namespace satnogs namespace satnogs
{ {
/**
/**
* Computes the Mean Absolute Percentage Error * Computes the Mean Absolute Percentage Error
* @param ref the reference value * @param ref the reference value
* @param estimation the estimated value * @param estimation the estimated value
* @return the mean absolute percentage error * @return the mean absolute percentage error
*/ */
static inline double static inline double
mape (double ref, double estimation) mape (double ref, double estimation)
{ {
return std::abs (ref - estimation) / ref; return std::abs (ref - estimation) / ref;
} }
/** /**
* Lookup table for the CCITT CRC16 * Lookup table for the CCITT CRC16
*/ */
static const uint16_t crc16_ccitt_table_reverse[256] = static const uint16_t crc16_ccitt_table_reverse[256] =
{ 0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, 0x8C48, { 0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, 0x8C48,
0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7, 0x1081, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7, 0x1081,
0x0108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E, 0x9CC9, 0x0108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E, 0x9CC9,
@ -76,7 +78,7 @@ namespace gr
0xE606, 0xD49D, 0xC514, 0xB1AB, 0xA022, 0x92B9, 0x8330, 0x7BC7, 0xE606, 0xD49D, 0xC514, 0xB1AB, 0xA022, 0x92B9, 0x8330, 0x7BC7,
0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78 }; 0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78 };
static const uint16_t crc16_ccitt_table[256] = static const uint16_t crc16_ccitt_table[256] =
{ 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108,
0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, 0x1231, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, 0x1231,
0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, 0x9339, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, 0x9339,
@ -110,43 +112,43 @@ namespace gr
0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, 0x6E17, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, 0x6E17,
0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 }; 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 };
static inline uint16_t static inline uint16_t
update_crc16_ccitt_reversed(uint16_t crc, const uint8_t *data, size_t len) update_crc16_ccitt_reversed (uint16_t crc, const uint8_t *data, size_t len)
{ {
register size_t i; register size_t i;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
crc = (crc >> 8) ^ crc16_ccitt_table_reverse[(crc ^ data[i]) & 0xff]; crc = (crc >> 8) ^ crc16_ccitt_table_reverse[(crc ^ data[i]) & 0xff];
} }
return crc; return crc;
} }
static inline uint16_t static inline uint16_t
crc16_ccitt_reversed(const uint8_t *data, size_t len) crc16_ccitt_reversed (const uint8_t *data, size_t len)
{ {
return update_crc16_ccitt_reversed(0xFFFF, data, len) ^ 0xFFFF; return update_crc16_ccitt_reversed (0xFFFF, data, len) ^ 0xFFFF;
} }
static uint16_t static uint16_t
update_crc16_ccitt (uint16_t crc, const uint8_t *buf, size_t len) update_crc16_ccitt (uint16_t crc, const uint8_t *buf, size_t len)
{ {
while (len-- != 0) { while (len-- != 0) {
crc = crc16_ccitt_table[((crc >> 8) ^ *buf++) & 0xff] ^ (crc << 8); crc = crc16_ccitt_table[((crc >> 8) ^ *buf++) & 0xff] ^ (crc << 8);
} }
return crc; return crc;
} }
static inline uint16_t static inline uint16_t
crc16_ccitt(const uint8_t *data, size_t len) crc16_ccitt (const uint8_t *data, size_t len)
{ {
return update_crc16_ccitt(0x0000, data, len); return update_crc16_ccitt (0x0000, data, len);
} }
/** /**
* Counts the number of active bits in x * Counts the number of active bits in x
*/ */
static inline unsigned int static inline unsigned int
bit_count (unsigned int x) bit_count (unsigned int x)
{ {
/* /*
* Some more magic from * Some more magic from
* http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel * http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
@ -154,9 +156,9 @@ namespace gr
x = x - ((x >> 1) & 0x55555555); x = x - ((x >> 1) & 0x55555555);
x = (x & 0x33333333) + ((x >> 2) & 0x33333333); x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
return (((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24; return (((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
} }
static const uint8_t _bytes_reversed[256] = static const uint8_t _bytes_reversed[256] =
{ 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, { 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0,
0x30, 0xB0, 0x70, 0xF0, 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0x30, 0xB0, 0x70, 0xF0, 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68,
0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, 0x04, 0x84, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, 0x04, 0x84,
@ -182,26 +184,35 @@ namespace gr
0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF,
0x7F, 0xFF }; 0x7F, 0xFF };
/** /**
* Reverse the bits of the byte b. * Reverse the bits of the byte b.
* @param b the byte to be mirrored. * @param b the byte to be mirrored.
*/ */
static inline uint8_t static inline uint8_t
reverse_byte (uint8_t b) reverse_byte (uint8_t b)
{ {
return _bytes_reversed[b]; return _bytes_reversed[b];
} }
static inline uint32_t static inline uint32_t
reverse_uint32_bytes (uint32_t i) reverse_uint32_bytes (uint32_t i)
{ {
return (_bytes_reversed[i & 0xff] << 24) return (_bytes_reversed[i & 0xff] << 24)
| (_bytes_reversed[(i >> 8) & 0xff] << 16) | (_bytes_reversed[(i >> 8) & 0xff] << 16)
| (_bytes_reversed[(i >> 16) & 0xff] << 8) | (_bytes_reversed[(i >> 16) & 0xff] << 8)
| (_bytes_reversed[(i >> 24) & 0xff]); | (_bytes_reversed[(i >> 24) & 0xff]);
} }
} // namespace satnogs static inline uint64_t
reverse_uint64_bytes (uint64_t x)
{
x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32;
x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16;
x = (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8;
return x;
}
} // namespace satnogs
} // namespace gr } // namespace gr

View File

@ -25,7 +25,9 @@
#include <gnuradio/io_signature.h> #include <gnuradio/io_signature.h>
#include "lrpt_decoder_impl.h" #include "lrpt_decoder_impl.h"
#include <satnogs/log.h> #include <satnogs/log.h>
#include <fec.h> extern "C" {
#include <fec.h>
}
namespace gr namespace gr
{ {
@ -45,22 +47,18 @@ lrpt_decoder_impl::lrpt_decoder_impl()
: gr::block("lrpt_decoder", : gr::block("lrpt_decoder",
gr::io_signature::make(0, 0, 0), gr::io_signature::make(0, 0, 0),
gr::io_signature::make(0, 0, 0)), gr::io_signature::make(0, 0, 0)),
d_cadu_len(1020), d_cadu_len(1020 + 4),
d_coded_cadu_len(1020 * 2), d_coded_cadu_len(1020 * 2 + 4*2),
d_conv_deinterl(36, 2048) d_conv_deinterl(36, 2048)
{ {
message_port_register_in(pmt::mp("cadu")); message_port_register_in(pmt::mp("cadu"));
message_port_register_in(pmt::mp("reset")); message_port_register_out(pmt::mp("frame"));
set_msg_handler ( set_msg_handler (
pmt::mp ("cadu"), pmt::mp ("cadu"),
boost::bind (&lrpt_decoder_impl::decode, this, _1)); 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); d_vt = create_viterbi27(d_cadu_len * 8);
if(!d_vt) { if(!d_vt) {
throw std::runtime_error("lrpt_decoder: Failed to init Viterbi decoder"); throw std::runtime_error("lrpt_decoder: Failed to init Viterbi decoder");
@ -69,7 +67,7 @@ lrpt_decoder_impl::lrpt_decoder_impl()
set_viterbi27_polynomial(polys); set_viterbi27_polynomial(polys);
d_cadu = new uint8_t[d_cadu_len]; d_cadu = new uint8_t[d_cadu_len];
d_coded_cadu_deinterl = new uint8_t[d_coded_cadu_len]; d_coded_cadu_syms = new uint8_t[d_coded_cadu_len * 8];
} }
@ -80,7 +78,7 @@ lrpt_decoder_impl::~lrpt_decoder_impl ()
{ {
delete [] d_cadu; delete [] d_cadu;
delete [] d_coded_cadu_deinterl; delete [] d_coded_cadu_syms;
} }
void void
@ -92,20 +90,23 @@ lrpt_decoder_impl::decode (pmt::pmt_t m)
return; 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); init_viterbi27(d_vt, 0);
for(size_t i = 0; i < d_coded_cadu_len; i++) {
d_coded_cadu_syms[i * 8] = ~(255 + (coded_cadu[i] >> 7));
d_coded_cadu_syms[i * 8 + 1] = ~(255 + (coded_cadu[i] >> 6) & 0x1);
d_coded_cadu_syms[i * 8 + 2] = ~(255 + (coded_cadu[i] >> 5) & 0x1);
d_coded_cadu_syms[i * 8 + 3] = ~(255 + (coded_cadu[i] >> 4) & 0x1);
d_coded_cadu_syms[i * 8 + 4] = ~(255 + (coded_cadu[i] >> 3) & 0x1);
d_coded_cadu_syms[i * 8 + 5] = ~(255 + (coded_cadu[i] >> 2) & 0x1);
d_coded_cadu_syms[i * 8 + 6] = ~(255 + (coded_cadu[i] >> 1) & 0x1);
d_coded_cadu_syms[i * 8 + 7] = ~(255 + (coded_cadu[i] & 0x1));
}
update_viterbi27_blk(d_vt, d_coded_cadu_syms, d_cadu_len * 8);
chainback_viterbi27(d_vt, d_cadu, d_cadu_len * 8, 0);
message_port_pub(pmt::mp("frame"), pmt::make_blob(d_cadu, d_cadu_len));
} }
void
lrpt_decoder_impl::reset (pmt::pmt_t m)
{
if(pmt::to_bool(m)) {
d_conv_deinterl.reset();
}
}
} /* namespace satnogs */ } /* namespace satnogs */

View File

@ -40,15 +40,12 @@ private:
const size_t d_cadu_len; const size_t d_cadu_len;
const size_t d_coded_cadu_len; const size_t d_coded_cadu_len;
convolutional_deinterleaver d_conv_deinterl; convolutional_deinterleaver d_conv_deinterl;
uint8_t *d_coded_cadu_deinterl; uint8_t *d_coded_cadu_syms;
uint8_t *d_cadu; uint8_t *d_cadu;
void *d_vt; void *d_vt;
void void
decode(pmt::pmt_t m); decode(pmt::pmt_t m);
void
reset(pmt::pmt_t m);
}; };
} // namespace satnogs } // namespace satnogs

View File

@ -25,6 +25,7 @@
#include <gnuradio/io_signature.h> #include <gnuradio/io_signature.h>
#include "lrpt_sync_impl.h" #include "lrpt_sync_impl.h"
#include <satnogs/log.h> #include <satnogs/log.h>
#include <satnogs/utils.h>
#include <volk/volk.h> #include <volk/volk.h>
#include <gnuradio/blocks/count_bits.h> #include <gnuradio/blocks/count_bits.h>
@ -57,7 +58,7 @@ lrpt_sync_impl::lrpt_sync_impl (size_t threshold) :
*/ */
d_window((72 + 8)/2), d_window((72 + 8)/2),
/* Each CADU has the 4 byte ASM and a VCDU of 1020 bytes*/ /* Each CADU has the 4 byte ASM and a VCDU of 1020 bytes*/
d_coded_cadu_len(1020 * 2), d_coded_cadu_len(1020 * 2 + 4*2),
d_frame_sync(false), d_frame_sync(false),
d_received(0), d_received(0),
d_rotate(1, 0), d_rotate(1, 0),
@ -97,10 +98,12 @@ lrpt_sync_impl::lrpt_sync_impl (size_t threshold) :
throw std::runtime_error("lrpt_sync: Could not allocate memory"); throw std::runtime_error("lrpt_sync: Could not allocate memory");
} }
uint64_t asm_coded = reverse_uint64_bytes(d_asm_coded);
d_coded_cadu = new uint8_t[d_coded_cadu_len]; d_coded_cadu = new uint8_t[d_coded_cadu_len];
memcpy(d_coded_cadu, &asm_coded, sizeof(uint64_t));
d_received = sizeof(uint64_t);
message_port_register_out(pmt::mp("cadu")); message_port_register_out(pmt::mp("cadu"));
message_port_register_out(pmt::mp("reset"));
} }
/* /*
@ -146,7 +149,6 @@ lrpt_sync_impl::work_no_sync(const gr_complex *in, int noutput_items)
if(found_sync(d_shift_reg0)) { if(found_sync(d_shift_reg0)) {
d_rotate = gr_complex(1.0, 0); d_rotate = gr_complex(1.0, 0);
d_frame_sync = true; d_frame_sync = true;
LOG_ERROR("SYNC");
return i * d_window + j; return i * d_window + j;
} }
@ -156,7 +158,6 @@ lrpt_sync_impl::work_no_sync(const gr_complex *in, int noutput_items)
if(found_sync(d_shift_reg1)) { if(found_sync(d_shift_reg1)) {
d_rotate = gr_complex(0.0, 1.0); d_rotate = gr_complex(0.0, 1.0);
d_frame_sync = true; d_frame_sync = true;
LOG_ERROR("SYNC");
return i * d_window + j; return i * d_window + j;
} }
@ -166,7 +167,6 @@ lrpt_sync_impl::work_no_sync(const gr_complex *in, int noutput_items)
if(found_sync(d_shift_reg2)) { if(found_sync(d_shift_reg2)) {
d_rotate = gr_complex(-1.0, 0); d_rotate = gr_complex(-1.0, 0);
d_frame_sync = true; d_frame_sync = true;
LOG_ERROR("SYNC");
return i * d_window + j; return i * d_window + j;
} }
@ -176,7 +176,6 @@ lrpt_sync_impl::work_no_sync(const gr_complex *in, int noutput_items)
if(found_sync(d_shift_reg3)) { if(found_sync(d_shift_reg3)) {
d_rotate = gr_complex(0.0, -1.0); d_rotate = gr_complex(0.0, -1.0);
d_frame_sync = true; d_frame_sync = true;
LOG_ERROR("SYNC");
return i * d_window + j; return i * d_window + j;
} }
} }
@ -192,11 +191,7 @@ lrpt_sync_impl::work_sync(const gr_complex *in, int noutput_items)
for(int i = 0; i < multiple; i++) { for(int i = 0; i < multiple; i++) {
volk_32fc_s32fc_multiply_32fc(d_corrected, in + i * d_window, volk_32fc_s32fc_multiply_32fc(d_corrected, in + i * d_window,
d_rotate, d_window); d_rotate, d_window);
/* for(int j = 0; j < d_window; j += 4) {
* Skip UW, for now
* NOTE: UW is unencoded
*/
for(int j = 0; j < d_window - 4; j += 4) {
b = 0; b = 0;
b = d_qpsk->decision_maker(d_corrected + j) << 6; b = d_qpsk->decision_maker(d_corrected + j) << 6;
b |= d_qpsk->decision_maker(d_corrected + j + 1) << 4; b |= d_qpsk->decision_maker(d_corrected + j + 1) << 4;
@ -206,7 +201,7 @@ lrpt_sync_impl::work_sync(const gr_complex *in, int noutput_items)
d_coded_cadu[d_received++] = b; d_coded_cadu[d_received++] = b;
if(d_received == d_coded_cadu_len) { if(d_received == d_coded_cadu_len) {
LOG_ERROR("frame"); LOG_ERROR("frame");
d_received = 0; d_received = sizeof(uint64_t);
d_frame_sync = false; d_frame_sync = false;
message_port_pub (pmt::mp ("cadu"), message_port_pub (pmt::mp ("cadu"),
pmt::make_blob (d_coded_cadu, d_coded_cadu_len)); pmt::make_blob (d_coded_cadu, d_coded_cadu_len));

View File

@ -35,6 +35,7 @@
#include "satnogs/decoder_8b10b.h" #include "satnogs/decoder_8b10b.h"
#include "satnogs/ccsds_rs_decoder_mm.h" #include "satnogs/ccsds_rs_decoder_mm.h"
#include "satnogs/fox_telem_mm.h" #include "satnogs/fox_telem_mm.h"
#include "satnogs/lrpt_decoder.h"
#include "satnogs/lrpt_sync.h" #include "satnogs/lrpt_sync.h"
%} %}
@ -117,3 +118,6 @@ GR_SWIG_BLOCK_MAGIC2(satnogs, fox_telem_mm);
%include "satnogs/lrpt_sync.h" %include "satnogs/lrpt_sync.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, lrpt_sync); GR_SWIG_BLOCK_MAGIC2(satnogs, lrpt_sync);
%include "satnogs/lrpt_decoder.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, lrpt_decoder);