Add documentation and synchronization option

This commit is contained in:
George Vardakis 2017-04-09 19:25:37 +03:00
parent 3b30b6b78e
commit 401e8f5248
8 changed files with 153 additions and 80 deletions

View File

@ -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
)

View File

@ -0,0 +1,67 @@
<?xml version="1.0"?>
<block>
<name>NOAA APT Sink</name>
<key>satnogs_noaa_apt_sink</key>
<category>[satnogs]</category>
<import>import satnogs</import>
<make>satnogs.noaa_apt_sink($*filename,$*filename_png, $width, $height, $split, $sync)</make>
<param>
<name>Output Data Filename</name>
<key>filename</key>
<value></value>
<type>file_save</type>
</param>
<param>
<name>Output PNG Filename</name>
<key>filename_png</key>
<value></value>
<type>file_save</type>
</param>
<param>
<name>PNG width</name>
<key>width</key>
<value>2080</value>
<type>int</type>
</param>
<param>
<name>PNG height</name>
<key>height</key>
<value>1500</value>
<type>int</type>
</param>
<param>
<name>Split Images</name>
<key>split</key>
<value>False</value>
<type>bool</type>
<hide>part</hide>
<option>
<name>Yes</name>
<key>True</key>
</option>
<option>
<name>No</name>
<key>False</key>
</option>
</param>
<param>
<name>Synchronize</name>
<key>sync</key>
<value>False</value>
<type>bool</type>
<hide>part</hide>
<option>
<name>Yes</name>
<key>False</key>
</option>
<option>
<name>No</name>
<key>True</key>
</option>
</param>
<sink>
<name>in</name>
<type>float</type>
</sink>
</block>

View File

@ -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
)

View File

@ -675,39 +675,61 @@
* <http://www.gnu.org/philosophy/why-not-lgpl.html>.
*/
#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 <satnogs/api.h>
#include <gnuradio/sync_block.h>
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<noaa_apt_sync> sptr;
public:
typedef boost::shared_ptr<noaa_apt_sink> 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 */

View File

@ -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})

View File

@ -680,7 +680,7 @@
#endif
#include <gnuradio/io_signature.h>
#include "noaa_apt_sync_impl.h"
#include "noaa_apt_sink_impl.h"
#define PNG_DEBUG 3
#include <png.h>
@ -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<char> 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) {

View File

@ -675,17 +675,19 @@
* <http://www.gnu.org/philosophy/why-not-lgpl.html>.
*/
#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 <satnogs/noaa_apt_sync.h>
#include <satnogs/noaa_apt_sink.h>
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 */

View File

@ -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);