From 7acc0696afaece1aa8346df982219a121b3943d6 Mon Sep 17 00:00:00 2001 From: LongHairedHacker Date: Sat, 30 Mar 2019 18:03:40 +0100 Subject: [PATCH] Added module Added sync detection to module --- grc/CMakeLists.txt | 1 + grc/satnogs.tree.yml | 2 +- grc/satnogs_sstv_pd120_sink.block.yml | 23 +++++ include/satnogs/CMakeLists.txt | 3 +- include/satnogs/sstv_pd120_sink.h | 56 ++++++++++++ lib/CMakeLists.txt | 2 +- lib/sstv_pd120_sink_impl.cc | 123 ++++++++++++++++++++++++++ lib/sstv_pd120_sink_impl.h | 55 ++++++++++++ swig/satnogs_swig0.i | 4 + 9 files changed, 266 insertions(+), 3 deletions(-) create mode 100644 grc/satnogs_sstv_pd120_sink.block.yml create mode 100644 include/satnogs/sstv_pd120_sink.h create mode 100644 lib/sstv_pd120_sink_impl.cc create mode 100644 lib/sstv_pd120_sink_impl.h diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index d51f901..07cf0fc 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -51,6 +51,7 @@ list(APPEND enabled_blocks satnogs_waterfall_sink.block.yml satnogs_whitening_ccsds.block.yml satnogs_whitening.block.yml + satnogs_sstv_pd120_sink.block.yml satnogs.tree.yml ) diff --git a/grc/satnogs.tree.yml b/grc/satnogs.tree.yml index 308d0f4..a5fb192 100644 --- a/grc/satnogs.tree.yml +++ b/grc/satnogs.tree.yml @@ -27,6 +27,7 @@ - satnogs_waterfall_sink - satnogs_whitening_ccsds - satnogs_whitening + - satnogs_sstv_pd120_sink - Debug: - satnogs_cw_encoder - satnogs_cw_to_symbol @@ -34,4 +35,3 @@ - satnogs_debug_msg_source - satnogs_morse_debug_source - satnogs_multi_format_msg_sink - diff --git a/grc/satnogs_sstv_pd120_sink.block.yml b/grc/satnogs_sstv_pd120_sink.block.yml new file mode 100644 index 0000000..7901c40 --- /dev/null +++ b/grc/satnogs_sstv_pd120_sink.block.yml @@ -0,0 +1,23 @@ +id: satnogs_sstv_pd120_sink +label: SSTV PD120 sink + +parameters: +- id: filename_png + label: Output PNG Filename + dtype: file_save + +- id: split + label: Flip Image + dtype: bool + default: False + +inputs: +- label: in + domain: stream + dtype: float + +templates: + imports: import satnogs + make: satnogs.sstv_pd120_sink(${filename_png}, ${split}) + +file_format: 1 diff --git a/include/satnogs/CMakeLists.txt b/include/satnogs/CMakeLists.txt index 465bc09..cc18b22 100644 --- a/include/satnogs/CMakeLists.txt +++ b/include/satnogs/CMakeLists.txt @@ -24,7 +24,7 @@ add_subdirectory(libfec) list(APPEND DEBUG_HEADER_FILES - cw_encoder.h + cw_encoder.h debug_msg_source_raw.h debug_msg_source.h morse_debug_source.h @@ -73,6 +73,7 @@ list(APPEND HEADER_FILES utils.h waterfall_sink.h whitening.h + sstv_pd120_sink.h ) if(${INCLUDE_DEBUG_BLOCKS}) diff --git a/include/satnogs/sstv_pd120_sink.h b/include/satnogs/sstv_pd120_sink.h new file mode 100644 index 0000000..f1a47e4 --- /dev/null +++ b/include/satnogs/sstv_pd120_sink.h @@ -0,0 +1,56 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2017, Libre Space Foundation + * + * 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 . + */ + + + +#ifndef INCLUDED_SATNOGS_SSTV_PD120_SINK_H +#define INCLUDED_SATNOGS_SSTV_PD120_SINK_H + +#include +#include + +namespace gr { + namespace satnogs { + + /*! + * \brief <+description of block+> + * \ingroup satnogs + * + */ + class SATNOGS_API sstv_pd120_sink : virtual public gr::sync_block + { + public: + typedef boost::shared_ptr sptr; + + /*! + * \brief Return a shared_ptr to a new instance of satnogs::sstv_pd120_sink. + * + * To avoid accidental use of raw pointers, satnogs::sstv_pd120_sink's + * constructor is in a private implementation + * class. satnogs::sstv_pd120_sink::make is the public interface for + * creating new instances. + */ + static sptr make(const char *filename_png, bool split); + }; + + } // namespace satnogs +} // namespace gr + +#endif /* INCLUDED_SATNOGS_SSTV_PD120_SINK_H */ diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index d3b5698..e83e11a 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -65,6 +65,7 @@ list(APPEND satnogs_sources udp_msg_source_impl.cc waterfall_sink_impl.cc whitening.cc + sstv_pd120_sink_impl.cc ) if(${INCLUDE_DEBUG_BLOCKS}) @@ -147,4 +148,3 @@ foreach(qa_file ${test_satnogs_sources}) ${CMAKE_CURRENT_SOURCE_DIR}/${qa_file} ) endforeach(qa_file) - diff --git a/lib/sstv_pd120_sink_impl.cc b/lib/sstv_pd120_sink_impl.cc new file mode 100644 index 0000000..8750ae5 --- /dev/null +++ b/lib/sstv_pd120_sink_impl.cc @@ -0,0 +1,123 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2018, Libre Space Foundation + * + * 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 . + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "sstv_pd120_sink_impl.h" + +namespace gr { + namespace satnogs { + + const size_t image_width = 640; + const size_t sync_length = 105; + const size_t sync_thresh = 100; + const size_t porch_length = 10; + const size_t line_length = sync_length + porch_length + 4 * image_width; + + const float max_dev = 600; + const float center = 1750; + const float min_freq = 1200; + const float max_freq = 2300; + + const float color_low = 1500; + const float color_high = max_freq; + + + sstv_pd120_sink::sptr + sstv_pd120_sink::make(const char *filename_png, bool split) + { + return gnuradio::get_initial_sptr + (new sstv_pd120_sink_impl(filename_png, split)); + } + + /* + * The private constructor + */ + sstv_pd120_sink_impl::sstv_pd120_sink_impl(const char *filename_png, bool split) + : gr::sync_block("sstv_pd120_sink", + gr::io_signature::make (1, 1, sizeof(float)), + gr::io_signature::make (0, 0, 0)), + d_filename_png (filename_png), + d_split (split), + d_has_sync(false) + { + set_history(sync_length); + d_line = new float[line_length]; + } + + /* + * Our virtual destructor. + */ + sstv_pd120_sink_impl::~sstv_pd120_sink_impl() + { + delete[] d_line; + } + + float + sstv_pd120_sink_impl::to_frequency(float sample) { + float freq = center + sample * max_dev; + freq = std::max(min_freq, freq); + freq = std::min(max_freq, freq); + return freq; + } + + bool + sstv_pd120_sink_impl::is_sync(size_t pos, const float *samples) { + size_t count = 0; + for(size_t i = 0; i < sync_length; i++) { + float sample = to_frequency(samples[pos - (sync_length - 1) + i]); + if(sample < color_low) { + count += 1; + } + } + + bool res = count > sync_length && !d_has_sync; + d_has_sync = count > sync_length; + + std::cout << "Count: " << count << " " << d_has_sync << std::endl; + + return res; + } + + int + sstv_pd120_sink_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const float *in = (const float *) input_items[0]; + + std::cout << "foo" << std::endl; + for (size_t i = sync_length - 1; + i < noutput_items + sync_length - 1; i++) { + + if(is_sync(i, in)) { + std::cout << "Sync: " << i << std::endl; + } + } + + // Tell runtime system how many output items we produced. + return noutput_items; + } + + } /* namespace satnogs */ +} /* namespace gr */ diff --git a/lib/sstv_pd120_sink_impl.h b/lib/sstv_pd120_sink_impl.h new file mode 100644 index 0000000..b831563 --- /dev/null +++ b/lib/sstv_pd120_sink_impl.h @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2018, Libre Space Foundation + * + * 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 . + */ + + +#ifndef INCLUDED_SATNOGS_SSTV_PD120_SINK_IMPL_H +#define INCLUDED_SATNOGS_SSTV_PD120_SINK_IMPL_H + +#include + +namespace gr { + namespace satnogs { + + class sstv_pd120_sink_impl : public sstv_pd120_sink + { + private: + std::string d_filename_png; + bool d_split; + bool d_has_sync; + + float *d_line; + + float to_frequency(float sample); + bool is_sync(size_t pos, const float *samples); + + public: + sstv_pd120_sink_impl(const char *filename_png, bool split); + ~sstv_pd120_sink_impl(); + + // Where all the action really happens + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } // namespace satnogs +} // namespace gr + +#endif /* INCLUDED_SATNOGS_SSTV_PD120_SINK_IMPL_H */ diff --git a/swig/satnogs_swig0.i b/swig/satnogs_swig0.i index 044230d..67bf853 100644 --- a/swig/satnogs_swig0.i +++ b/swig/satnogs_swig0.i @@ -34,6 +34,7 @@ #include "satnogs/ogg_encoder.h" #include "satnogs/ogg_source.h" #include "satnogs/noaa_apt_sink.h" +#include "satnogs/sstv_pd120_sink.h" #include "satnogs/frame_file_sink.h" #include "satnogs/iq_sink.h" #include "satnogs/json_converter.h" @@ -99,6 +100,9 @@ GR_SWIG_BLOCK_MAGIC2(satnogs, ogg_source); %include "satnogs/noaa_apt_sink.h" GR_SWIG_BLOCK_MAGIC2(satnogs, noaa_apt_sink); +%include "satnogs/sstv_pd120_sink.h" +GR_SWIG_BLOCK_MAGIC2(satnogs, sstv_pd120_sink); + %include "satnogs/frame_file_sink.h" GR_SWIG_BLOCK_MAGIC2(satnogs, frame_file_sink);