gr-satnogs/lib/noaa_apt_sink_impl.h

113 lines
3.2 KiB
C
Raw Normal View History

2017-04-08 20:50:18 +02:00
/* -*- c++ -*- */
2017-07-19 15:57:00 +02:00
/*
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
*
* Copyright (C) 2017, 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/>.
2017-04-08 20:50:18 +02:00
*/
#ifndef INCLUDED_SATNOGS_NOAA_APT_SINK_IMPL_H
#define INCLUDED_SATNOGS_NOAA_APT_SINK_IMPL_H
2017-04-08 20:50:18 +02:00
#include <satnogs/noaa_apt_sink.h>
2017-04-10 14:01:02 +02:00
#define PNG_DEBUG 3
2018-01-02 19:00:53 +01:00
#include <png++/png.hpp>
#include <chrono>
2017-04-08 20:50:18 +02:00
2018-01-02 19:00:53 +01:00
namespace gr
{
namespace satnogs
{
2018-01-02 22:42:51 +01:00
enum class noaa_apt_sync_marker {SYNC_A, SYNC_B, NONE};
2017-04-08 20:50:18 +02:00
class noaa_apt_sink_impl : public noaa_apt_sink
2017-04-08 20:50:18 +02:00
{
private:
2018-01-02 19:00:53 +01:00
std::string d_filename_png;
2017-04-08 20:50:18 +02:00
size_t d_width;
size_t d_height;
2017-04-09 16:20:02 +02:00
bool d_split;
2017-04-10 14:01:02 +02:00
bool d_synchronize_opt;
2017-04-10 17:03:00 +02:00
bool d_flip;
2018-01-02 19:00:53 +01:00
size_t d_history_length;
bool d_has_sync;
2018-01-02 19:00:53 +01:00
png::image<png::gray_pixel> d_full_image;
png::image<png::gray_pixel> d_left_image;
png::image<png::gray_pixel> d_right_image;
std::string d_full_filename;
std::string d_left_filename;
std::string d_right_filename;
size_t d_current_x;
size_t d_current_y;
2018-01-02 22:42:51 +01:00
size_t d_num_images;
2018-01-02 19:00:53 +01:00
float f_max_level;
float f_min_level;
2018-01-02 22:42:51 +01:00
float f_average;
2017-04-10 17:03:00 +02:00
public:
2017-07-19 15:57:00 +02:00
noaa_apt_sink_impl (const char *filename_png, size_t width, size_t height,
bool split, bool sync, bool flip);
~noaa_apt_sink_impl ();
2017-04-08 20:50:18 +02:00
// Where all the action really happens
int
work (int noutput_items, gr_vector_const_void_star &input_items,
2017-07-19 15:57:00 +02:00
gr_vector_void_star &output_items);
2018-01-02 19:00:53 +01:00
bool
stop ();
2018-01-02 19:00:53 +01:00
private:
2018-01-03 00:34:32 +01:00
// Generate empty images and filenames to save them to
2018-01-02 19:00:53 +01:00
void
init_images ();
2018-01-03 00:34:32 +01:00
/*
* Check if the history portion of the input contains a sync marker.
* Matches the 40 samples before pos against the patterns.
*/
2018-01-02 22:42:51 +01:00
noaa_apt_sync_marker
is_marker (size_t pos, const float *samples);
2018-01-03 00:34:32 +01:00
// Set the pixel indicated by coordinates in the images (both full and split)
2018-01-02 19:00:53 +01:00
void
2018-01-02 22:42:51 +01:00
set_pixel (size_t x, size_t y, float sample);
2018-01-02 19:00:53 +01:00
2018-01-03 00:34:32 +01:00
/*
* Updates d_current_x to new_x,
* while using historical samples to fill any resulting gaps in the images.
*/
2018-01-02 19:00:53 +01:00
void
2018-01-02 22:42:51 +01:00
skip_to (size_t new_x, size_t pos, const float *samples);
2018-01-02 19:00:53 +01:00
2018-01-03 00:34:32 +01:00
// Write the images to disk
2018-01-02 19:00:53 +01:00
void
write_images ();
2018-01-03 00:34:32 +01:00
// Write a single image to disk, also takes care of flipping
2018-01-02 19:00:53 +01:00
void
write_image (png::image<png::gray_pixel> image, std::string filename);
2017-04-08 20:50:18 +02:00
};
} // namespace satnogs
} // namespace gr
#endif /* INCLUDED_SATNOGS_NOAA_APT_SINK_IMPL_H */