Commit a344bc49 authored by Manolis Surligas's avatar Manolis Surligas

Start the LRPT sync block

parent f7e67d0a
......@@ -29,6 +29,14 @@ list(APPEND debug_blocks
list(APPEND enabled_blocks
satnogs_block_tree.xml
satnogs_ax25_decoder_bm.xml
satnogs_ax25_encoder_mb.xml
satnogs_ccsds_rs_decoder_mm.xml
satnogs_decoder_8b10b.xml
satnogs_fox_telem_mm.xml
satnogs_frame_file_sink.xml
satnogs_iq_sink.xml
satnogs_lrpt_sync.xml
satnogs_morse_decoder.xml
satnogs_multi_format_msg_sink.xml
satnogs_ogg_encoder.xml
......@@ -38,13 +46,10 @@ list(APPEND enabled_blocks
satnogs_doppler_correction_cc.xml
satnogs_udp_msg_sink.xml
satnogs_coarse_doppler_correction_cc.xml
satnogs_ax25_encoder_mb.xml
satnogs_ax25_decoder_bm.xml
satnogs_waterfall_sink.xml
satnogs_quad_demod_filter_ff.xml
satnogs_ogg_source.xml
satnogs_noaa_apt_sink.xml
satnogs_frame_file_sink.xml
satnogs_iq_sink.xml
)
if(${INCLUDE_DEBUG_BLOCKS})
......@@ -52,8 +57,5 @@ if(${INCLUDE_DEBUG_BLOCKS})
endif()
install(FILES
${enabled_blocks}
satnogs_quad_demod_filter_ff.xml
satnogs_decoder_8b10b.xml
satnogs_ccsds_rs_decoder_mm.xml
satnogs_fox_telem_mm.xml DESTINATION share/gnuradio/grc/blocks
DESTINATION share/gnuradio/grc/blocks
)
......@@ -21,10 +21,11 @@
<block>satnogs_cw_matched_filter_ff</block>
<block>satnogs_morse_decoder</block>
<block>satnogs_multi_format_msg_sink</block>
<block>satnogs_lrpt_sync</block>
<block>satnogs_iq_sink</block>
<block>satnogs_ogg_encoder</block>
<block>satnogs_ogg_source</block>
<block>satnogs_cw_to_symbol</block>
<block>satnogs_sine_matched_filter_ff</block>
<block>satnogs_udp_msg_source</block>
<block>satnogs_tcp_rigctl_msg_source</block>
<block>satnogs_doppler_correction_cc</block>
......
......@@ -2,7 +2,6 @@
<block>
<name>IQ Sink</name>
<key>satnogs_iq_sink</key>
<category>[SatNOGS]</category>
<import>import satnogs</import>
<make>satnogs.iq_sink($scale, $filename, $append, $status)</make>
<callback>open($file)</callback>
......
<?xml version="1.0"?>
<block>
<name>LRPT Frame Sync</name>
<key>satnogs_lrpt_sync</key>
<import>import satnogs</import>
<make>satnogs.lrpt_sync($thresh)</make>
<param>
<name>Threshold</name>
<key>thresh</key>
<value>2</value>
<type>int</type>
</param>
<sink>
<name>in</name>
<type>complex</type>
</sink>
</block>
\ No newline at end of file
......@@ -70,5 +70,6 @@ install(FILES
quad_demod_filter_ff.h
decoder_8b10b.h
ccsds_rs_decoder_mm.h
fox_telem_mm.h DESTINATION include/satnogs
fox_telem_mm.h
lrpt_sync.h DESTINATION include/satnogs
)
\ No newline at end of file
This diff is collapsed.
......@@ -69,7 +69,8 @@ list(APPEND satnogs_sources
quad_demod_filter_ff_impl.cc
decoder_8b10b_impl.cc
ccsds_rs_decoder_mm_impl.cc
fox_telem_mm_impl.cc)
fox_telem_mm_impl.cc
lrpt_sync_impl.cc)
if(${INCLUDE_DEBUG_BLOCKS})
list(APPEND satnogs_sources ${satnogs_debug_sources})
......@@ -88,6 +89,8 @@ add_dependencies(gnuradio-satnogs fec)
target_link_libraries(gnuradio-satnogs
${Boost_LIBRARIES}
${GNURADIO_ALL_LIBRARIES}
gnuradio-blocks
gnuradio-digital
${CMAKE_THREAD_LIBS_INIT}
${NOVA_LIBRARIES}
${VOLK_LIBRARIES}
......
/* -*- 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_sync_impl.h"
#include <satnogs/log.h>
#include <volk/volk.h>
#include <gnuradio/blocks/count_bits.h>
namespace gr
{
namespace satnogs
{
lrpt_sync::sptr
lrpt_sync::make (size_t threshold)
{
return gnuradio::get_initial_sptr (new lrpt_sync_impl (threshold));
}
/*
* The private constructor
*/
lrpt_sync_impl::lrpt_sync_impl (size_t threshold) :
gr::sync_block ("lrpt_sync",
gr::io_signature::make (1, 1, sizeof(gr_complex)),
gr::io_signature::make (0, 0, 0)),
d_thresh(threshold),
d_asm_coded(0xd49c24ff2686b),
d_asm_coded_len(52),
d_asm_coded_mask((1ULL << d_asm_coded_len) - 1),
/*
* We process the data in a multiple of 2 frames and a UW
* sync word
*/
d_window((72 + 8)/2),
d_frame_sync(false),
d_rotate(1, 0),
d_qpsk(digital::constellation_qpsk::make()),
d_shift_reg0(0x0),
d_shift_reg1(0x0),
d_shift_reg2(0x0),
d_shift_reg3(0x0)
{
set_output_multiple(d_window);
const int alignment_multiple = volk_get_alignment () / sizeof(gr_complex);
set_alignment (std::max (1, alignment_multiple));
d_rotate_pi2 = (gr_complex *)volk_malloc(d_window, volk_get_alignment ());
if(!d_rotate_pi2) {
throw std::runtime_error("lrpt_sync: Could not allocate memory");
}
d_rotate_2pi2 = (gr_complex *)volk_malloc(d_window, volk_get_alignment ());
if(!d_rotate_2pi2) {
volk_free(d_rotate_pi2);
throw std::runtime_error("lrpt_sync: Could not allocate memory");
}
d_rotate_3pi2 = (gr_complex *)volk_malloc(d_window, volk_get_alignment ());
if(!d_rotate_3pi2) {
volk_free(d_rotate_pi2);
volk_free(d_rotate_2pi2);
throw std::runtime_error("lrpt_sync: Could not allocate memory");
}
}
/*
* Our virtual destructor.
*/
lrpt_sync_impl::~lrpt_sync_impl ()
{
volk_free (d_rotate_pi2);
volk_free (d_rotate_2pi2);
volk_free (d_rotate_3pi2);
}
bool
lrpt_sync_impl::found_sync(uint64_t reg)
{
return blocks::count_bits64 ((reg ^ d_asm_coded) & d_asm_coded_mask)
<= d_thresh;
}
int
lrpt_sync_impl::work_no_sync(const gr_complex *in, int noutput_items)
{
uint32_t bits;
int multiple = noutput_items / d_window;
for(int i = 0; i < multiple; i++) {
volk_32fc_s32fc_multiply_32fc(d_rotate_pi2, in + i * d_window,
gr_complex(0, 1), d_window);
volk_32fc_s32fc_multiply_32fc(d_rotate_2pi2, in + i * d_window,
gr_complex(-1, 0), d_window);
volk_32fc_s32fc_multiply_32fc(d_rotate_3pi2, in + i * d_window,
gr_complex(0, -1), d_window);
/*
* Search for the sync pattern, rotating the QPSK constellation on
* all possible positions
*/
for(int j = 0; j < d_window; j++) {
bits = d_qpsk->decision_maker(in + i * d_window + j);
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;
return i * d_window + j;
}
bits = d_qpsk->decision_maker(d_rotate_pi2 + j);
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;
return i * d_window + j;
}
bits = d_qpsk->decision_maker(d_rotate_2pi2 + j);
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;
return i * d_window + j;
}
bits = d_qpsk->decision_maker(d_rotate_3pi2 + j);
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;
return i * d_window + j;
}
}
}
return noutput_items;
}
int
lrpt_sync_impl::work_sync(const gr_complex *in, int noutput_items)
{
return noutput_items;
}
int
lrpt_sync_impl::work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const gr_complex *in = (const gr_complex *) input_items[0];
uint32_t bits;
if(!d_frame_sync) {
return work_no_sync(in, noutput_items);
}
return work_sync(in, noutput_items);
}
} /* namespace satnogs */
} /* namespace gr */
This diff is collapsed.
......@@ -35,6 +35,7 @@
#include "satnogs/decoder_8b10b.h"
#include "satnogs/ccsds_rs_decoder_mm.h"
#include "satnogs/fox_telem_mm.h"
#include "satnogs/lrpt_sync.h"
%}
......@@ -113,3 +114,6 @@ GR_SWIG_BLOCK_MAGIC2(satnogs, ccsds_rs_decoder_mm);
%include "satnogs/fox_telem_mm.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, fox_telem_mm);
%include "satnogs/lrpt_sync.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, lrpt_sync);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment