From 401e8f5248e416d00e019a43c51f38f8ff177371 Mon Sep 17 00:00:00 2001 From: George Vardakis Date: Sun, 9 Apr 2017 19:25:37 +0300 Subject: [PATCH] Add documentation and synchronization option --- grc/CMakeLists.txt | 2 +- grc/satnogs_noaa_apt_sink.xml | 67 +++++++++++++++++++ include/satnogs/CMakeLists.txt | 2 +- .../{noaa_apt_sync.h => noaa_apt_sink.h} | 54 ++++++++++----- lib/CMakeLists.txt | 2 +- ...apt_sync_impl.cc => noaa_apt_sink_impl.cc} | 65 +++++++----------- ...a_apt_sync_impl.h => noaa_apt_sink_impl.h} | 35 +++++----- swig/satnogs_swig.i | 6 +- 8 files changed, 153 insertions(+), 80 deletions(-) create mode 100644 grc/satnogs_noaa_apt_sink.xml rename include/satnogs/{noaa_apt_sync.h => noaa_apt_sink.h} (95%) rename lib/{noaa_apt_sync_impl.cc => noaa_apt_sink_impl.cc} (96%) rename lib/{noaa_apt_sync_impl.h => noaa_apt_sink_impl.h} (98%) diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index b7d02c7..78435cb 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -50,5 +50,5 @@ endif() install(FILES ${enabled_blocks} satnogs_ogg_source.xml - satnogs_noaa_apt_sync.xml DESTINATION share/gnuradio/grc/blocks + satnogs_noaa_apt_sink.xml DESTINATION share/gnuradio/grc/blocks ) diff --git a/grc/satnogs_noaa_apt_sink.xml b/grc/satnogs_noaa_apt_sink.xml new file mode 100644 index 0000000..aeac50f --- /dev/null +++ b/grc/satnogs_noaa_apt_sink.xml @@ -0,0 +1,67 @@ + + + NOAA APT Sink + satnogs_noaa_apt_sink + [satnogs] + import satnogs + satnogs.noaa_apt_sink($*filename,$*filename_png, $width, $height, $split, $sync) + + Output Data Filename + filename + + file_save + + + Output PNG Filename + filename_png + + file_save + + + PNG width + width + 2080 + int + + + PNG height + height + 1500 + int + + + Split Images + split + False + bool + part + + + + + Synchronize + sync + False + bool + part + + + + + in + float + + + diff --git a/include/satnogs/CMakeLists.txt b/include/satnogs/CMakeLists.txt index d4232de..98debec 100644 --- a/include/satnogs/CMakeLists.txt +++ b/include/satnogs/CMakeLists.txt @@ -64,5 +64,5 @@ endif() install(FILES ${HEADER_FILES} ogg_source.h - noaa_apt_sync.h DESTINATION include/satnogs + noaa_apt_sink.h DESTINATION include/satnogs ) \ No newline at end of file diff --git a/include/satnogs/noaa_apt_sync.h b/include/satnogs/noaa_apt_sink.h similarity index 95% rename from include/satnogs/noaa_apt_sync.h rename to include/satnogs/noaa_apt_sink.h index 4fc2718..164976c 100644 --- a/include/satnogs/noaa_apt_sync.h +++ b/include/satnogs/noaa_apt_sink.h @@ -675,39 +675,61 @@ * . */ - -#ifndef INCLUDED_SATNOGS_NOAA_APT_SYNC_H -#define INCLUDED_SATNOGS_NOAA_APT_SYNC_H +#ifndef INCLUDED_SATNOGS_NOAA_APT_SINK_H +#define INCLUDED_SATNOGS_NOAA_APT_SINK_H #include #include -namespace gr { - namespace satnogs { +namespace gr +{ + namespace satnogs + { /*! - * \brief <+description of block+> + * Sink block for NOAA satellites * \ingroup satnogs * */ - class SATNOGS_API noaa_apt_sync : virtual public gr::sync_block + class SATNOGS_API noaa_apt_sink : virtual public gr::sync_block { - public: - typedef boost::shared_ptr sptr; + public: + typedef boost::shared_ptr sptr; /*! - * \brief Return a shared_ptr to a new instance of satnogs::noaa_apt_sync. + * Accepts a stream of floats in the range [0,1] which + * correspond to one sample per symbol (pixel) and + * outputs a file containing the grayscale pixels of + * the resulting image in the form of one byte per pixel. + * The PNG image is also produced by this block. The user can + * choose between deriving a single PNG file for each + * width x length pixels or two PNG files corresponding to + * each one of the two different spectrum images contained + * in a NOAA APT transmission. Further, this block performs + * normalization on the input float values based on the max + * and min values observed in the stream. Adding to that, + * the user has the option to synchronize to the first of the + * two training sequences used by the NOAA APT protocol so that + * the two images are displayed one next to the other. + * + * + * @param filename the filename of the byte output file + * @param filename_png the base filename of the output PNG file(s) + * @param width the width of the image in the APT transmission + * @param height the height of the image in the APT transmission + * @param split user option for splitting the two images contained + * in a NOAA APT transmission + * @param sync user option for synchronizing to the first of the + * two training sequences * - * To avoid accidental use of raw pointers, satnogs::noaa_apt_sync's - * constructor is in a private implementation - * class. satnogs::noaa_apt_sync::make is the public interface for - * creating new instances. */ - static sptr make( const char *filename, const char *filename_png, size_t width, size_t height, bool split); + static sptr + make (const char *filename, const char *filename_png, size_t width, + size_t height, bool split, bool sync); }; } // namespace satnogs } // namespace gr -#endif /* INCLUDED_SATNOGS_NOAA_APT_SYNC_H */ +#endif /* INCLUDED_SATNOGS_NOAA_APT_SINK_H */ diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 03ec25a..24a10a8 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -62,7 +62,7 @@ list(APPEND satnogs_sources qb50_deframer_impl.cc waterfall_sink_impl.cc ogg_source_impl.cc - noaa_apt_sync_impl.cc) + noaa_apt_sink_impl.cc) if(${INCLUDE_DEBUG_BLOCKS}) list(APPEND satnogs_sources ${satnogs_debug_sources}) diff --git a/lib/noaa_apt_sync_impl.cc b/lib/noaa_apt_sink_impl.cc similarity index 96% rename from lib/noaa_apt_sync_impl.cc rename to lib/noaa_apt_sink_impl.cc index 6e86c23..e983206 100644 --- a/lib/noaa_apt_sync_impl.cc +++ b/lib/noaa_apt_sink_impl.cc @@ -680,7 +680,7 @@ #endif #include -#include "noaa_apt_sync_impl.h" +#include "noaa_apt_sink_impl.h" #define PNG_DEBUG 3 #include @@ -692,28 +692,29 @@ namespace gr namespace satnogs { - noaa_apt_sync::sptr - noaa_apt_sync::make (const char *filename, const char *filename_png, - size_t width, size_t height, bool split) + noaa_apt_sink::sptr + noaa_apt_sink::make (const char *filename, const char *filename_png, + size_t width, size_t height, bool split, bool sync) { return gnuradio::get_initial_sptr ( - new noaa_apt_sync_impl (filename, filename_png, width, height, split)); + new noaa_apt_sink_impl (filename, filename_png, width, height, split, sync)); } /* * The private constructor */ - noaa_apt_sync_impl::noaa_apt_sync_impl (const char *filename, + noaa_apt_sink_impl::noaa_apt_sink_impl (const char *filename, const char *filename_png, size_t width, size_t height, - bool split) : - gr::sync_block ("noaa_apt_sync", + bool split, + bool sync) : + gr::sync_block ("noaa_apt_sink", gr::io_signature::make (1, 1, sizeof(float)), gr::io_signature::make (0, 0, 0)), d_sync_word (0x0ccccccc), d_constructed_word (0), d_slicer_threshold (0.5), - d_sync_found (false), + d_sync_found (sync), d_max_value (-1), d_min_value (100), d_filename (filename), @@ -729,16 +730,18 @@ namespace gr d_out = fopen (filename, "wb"); } - noaa_apt_sync_impl::~noaa_apt_sync_impl () + noaa_apt_sink_impl::~noaa_apt_sink_impl () { fclose (d_out); produce_image (); } void - noaa_apt_sync_impl::produce_image () + noaa_apt_sink_impl::produce_image () { std::ifstream file (d_filename, std::ios::binary | std::ios::ate); std::streamsize size = file.tellg (); + if (size == 0) + return; file.seekg (0, std::ios::beg); std::vector buffer (size); png_structp png_ptr; @@ -749,9 +752,9 @@ namespace gr png_bytep * row_pointers_left; png_bytep * row_pointers_right; size_t num_pictures = 0; - int height = size / d_width; - int picture_modulo = 0; - int row_modulo = 0; + size_t height = size / d_width; + size_t picture_modulo = 0; + size_t row_modulo = 0; if (height > d_height) { num_pictures = height / d_height; if (height % d_height > 0) { @@ -766,7 +769,7 @@ namespace gr row_modulo = size % d_width; } if (file.read (buffer.data (), size)) { - for (int image = 0; image < num_pictures; image++) { + for (size_t image = 0; image < num_pictures; image++) { if (d_split == false) { FILE *fp; std::string fn; @@ -803,12 +806,7 @@ namespace gr if (!info_ptr) printf ("[write_png_file] png_create_info_struct failed"); - if (setjmp(png_jmpbuf(png_ptr))) - printf ("[write_png_file] Error during init_io"); - png_init_io (png_ptr, fp); - if (setjmp(png_jmpbuf(png_ptr))) - printf ("[write_png_file] Error during writing header"); png_set_IHDR (png_ptr, info_ptr, d_width, height, 8, PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE, @@ -816,11 +814,8 @@ namespace gr PNG_FILTER_TYPE_BASE); png_write_info (png_ptr, info_ptr); - - if (setjmp(png_jmpbuf(png_ptr))) - printf ("[write_png_file] Error during writing bytes"); row_pointers = (png_bytep*) malloc (sizeof(png_bytep) * height); - for (int y = 0; y < height; y++) { + for (size_t y = 0; y < height; y++) { row_pointers[y] = (png_byte*) malloc ( png_get_rowbytes (png_ptr, info_ptr)); if ((image == num_pictures - 1) && (y == height - 1) @@ -840,8 +835,6 @@ namespace gr } } png_write_image (png_ptr, row_pointers); - if (setjmp(png_jmpbuf(png_ptr))) - printf ("[write_png_file] Error during end of write"); png_write_end (png_ptr, NULL); fclose (fp); } @@ -901,19 +894,13 @@ namespace gr info_ptr_left = png_create_info_struct (png_ptr_left); info_ptr_right = png_create_info_struct (png_ptr_right); - if ((!info_ptr_left) && (!info_ptr_right) && (!info_ptr)) + if ((!info_ptr_left) && (!info_ptr_right)) printf ("[write_png_file] png_create_info_struct failed"); - - if (setjmp( - png_jmpbuf(png_ptr_left)) && (setjmp(png_jmpbuf(png_ptr_right)))) printf ("[write_png_file] Error during init_io"); png_init_io (png_ptr_left, fp_left); png_init_io (png_ptr_right, fp_right); - if (setjmp( - png_jmpbuf(png_ptr_left)) && (setjmp(png_jmpbuf(png_ptr_right)))) - printf ("[write_png_file] Error during writing header"); png_set_IHDR (png_ptr_left, info_ptr_left, d_width / 2, height, 8, PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE, @@ -927,15 +914,11 @@ namespace gr png_write_info (png_ptr_left, info_ptr_left); png_write_info (png_ptr_right, info_ptr_right); - - if (setjmp(png_jmpbuf(png_ptr_left)) - && (setjmp(png_jmpbuf(png_ptr_right)))) - printf ("[write_png_file] Error during writing bytes"); row_pointers_left = (png_bytep*) malloc ( sizeof(png_bytep) * height); row_pointers_right = (png_bytep*) malloc ( sizeof(png_bytep) * height); - for (int y = 0; y < height; y++) { + for (size_t y = 0; y < height; y++) { row_pointers_left[y] = (png_byte*) malloc ( (d_width / 2) * sizeof(png_byte)); row_pointers_right[y] = (png_byte*) malloc ( @@ -967,9 +950,6 @@ namespace gr } png_write_image (png_ptr_left, row_pointers_left); png_write_image (png_ptr_right, row_pointers_right); - if (setjmp( - png_jmpbuf(png_ptr_left)) && setjmp(png_jmpbuf(png_ptr_right))) - printf ("[write_png_file] Error during end of write"); png_write_end (png_ptr_left, NULL); png_write_end (png_ptr_right, NULL); fclose (fp_left); @@ -979,7 +959,7 @@ namespace gr } } int - noaa_apt_sync_impl::work (int noutput_items, + noaa_apt_sink_impl::work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { @@ -987,6 +967,7 @@ namespace gr uint8_t b = 0; float sample; long int r; + for (int i = 0; i < noutput_items; i++) { if (d_sync_found) { if (d_sample_counter < d_norm_window) { diff --git a/lib/noaa_apt_sync_impl.h b/lib/noaa_apt_sink_impl.h similarity index 98% rename from lib/noaa_apt_sync_impl.h rename to lib/noaa_apt_sink_impl.h index 8005530..d869a9d 100644 --- a/lib/noaa_apt_sync_impl.h +++ b/lib/noaa_apt_sink_impl.h @@ -675,17 +675,19 @@ * . */ -#ifndef INCLUDED_SATNOGS_NOAA_APT_SYNC_IMPL_H -#define INCLUDED_SATNOGS_NOAA_APT_SYNC_IMPL_H +#ifndef INCLUDED_SATNOGS_NOAA_APT_SINK_IMPL_H +#define INCLUDED_SATNOGS_NOAA_APT_SINK_IMPL_H -#include +#include -namespace gr { - namespace satnogs { +namespace gr +{ + namespace satnogs + { - class noaa_apt_sync_impl : public noaa_apt_sync + class noaa_apt_sink_impl : public noaa_apt_sink { - private: + private: uint32_t d_sync_word; uint32_t d_constructed_word; float d_slicer_threshold; @@ -703,20 +705,21 @@ namespace gr { size_t d_height; bool d_split; - public: - noaa_apt_sync_impl( const char *filename, const char *filename_png, size_t width, size_t height, bool split); - ~noaa_apt_sync_impl(); - void produce_image(); - + public: + noaa_apt_sink_impl (const char *filename, const char *filename_png, + size_t width, size_t height, bool split, bool sync); + ~noaa_apt_sink_impl (); + void + produce_image (); // Where all the action really happens - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + 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_NOAA_APT_SYNC_IMPL_H */ +#endif /* INCLUDED_SATNOGS_NOAA_APT_SINK_IMPL_H */ diff --git a/swig/satnogs_swig.i b/swig/satnogs_swig.i index 7a14d9b..42583b4 100644 --- a/swig/satnogs_swig.i +++ b/swig/satnogs_swig.i @@ -33,7 +33,7 @@ #include "satnogs/waterfall_sink.h" #include "satnogs/ogg_encoder.h" #include "satnogs/ogg_source.h" -#include "satnogs/noaa_apt_sync.h" +#include "satnogs/noaa_apt_sink.h" %} @@ -104,5 +104,5 @@ GR_SWIG_BLOCK_MAGIC2(satnogs, waterfall_sink); GR_SWIG_BLOCK_MAGIC2(satnogs, ogg_encoder); %include "satnogs/ogg_source.h" GR_SWIG_BLOCK_MAGIC2(satnogs, ogg_source); -%include "satnogs/noaa_apt_sync.h" -GR_SWIG_BLOCK_MAGIC2(satnogs, noaa_apt_sync); +%include "satnogs/noaa_apt_sink.h" +GR_SWIG_BLOCK_MAGIC2(satnogs, noaa_apt_sink);