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
|
|
|
|
*
|
2018-01-05 15:42:51 +01:00
|
|
|
* Copyright (C) 2017,2018 Libre Space Foundation <http://librespacefoundation.org/>
|
2017-07-19 15:57:00 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
2017-04-09 18:25:37 +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
|
|
|
|
2017-04-09 18:25:37 +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>
|
2017-08-07 13:28:40 +02:00
|
|
|
#include <chrono>
|
2017-04-08 20:50:18 +02:00
|
|
|
|
2018-01-02 19:00:53 +01:00
|
|
|
|
|
|
|
|
2017-04-09 18:25:37 +02: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
|
|
|
|
2017-04-09 18:25:37 +02:00
|
|
|
class noaa_apt_sink_impl : public noaa_apt_sink
|
2017-04-08 20:50:18 +02:00
|
|
|
{
|
2017-04-09 18:25:37 +02:00
|
|
|
private:
|
2018-01-05 13:37:55 +01:00
|
|
|
// Factor exponential smoothing average,
|
|
|
|
// which is used for sync pattern detection
|
|
|
|
const float f_average_alpha;
|
2018-01-04 16:23:41 +01:00
|
|
|
static const bool synca_seq[];
|
|
|
|
static const bool syncb_seq[];
|
|
|
|
|
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-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;
|
2018-01-04 15:42:36 +01:00
|
|
|
bool d_has_sync;
|
2018-02-02 15:21:39 +01:00
|
|
|
bool d_image_received;
|
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
|
|
|
|
2017-04-09 18:25:37 +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,
|
2018-02-02 15:21:39 +01:00
|
|
|
bool sync, bool flip);
|
2017-04-09 18:25:37 +02:00
|
|
|
~noaa_apt_sink_impl ();
|
2017-04-08 20:50:18 +02:00
|
|
|
|
|
|
|
// Where all the action really happens
|
2017-04-09 18:25:37 +02:00
|
|
|
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
|
|
|
|
2018-02-02 17:44:32 +01:00
|
|
|
bool
|
|
|
|
stop();
|
2018-01-02 19:00:53 +01:00
|
|
|
private:
|
|
|
|
|
2018-01-03 00:34:32 +01:00
|
|
|
/*
|
2018-01-04 16:06:54 +01:00
|
|
|
* Checks if the history portion of the input contains a sync marker.
|
2018-01-03 00:34:32 +01:00
|
|
|
* 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-04 16:06:54 +01:00
|
|
|
// Sets 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-04 16:06:54 +01:00
|
|
|
// Writes 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
|
|
|
|
|
2017-04-09 18:25:37 +02:00
|
|
|
#endif /* INCLUDED_SATNOGS_NOAA_APT_SINK_IMPL_H */
|