GNU Radio's SATNOGS Package
noaa_apt_sink_impl.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
4  *
5  * Copyright (C) 2017,2018 Libre Space Foundation <http://librespacefoundation.org/>
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef INCLUDED_SATNOGS_NOAA_APT_SINK_IMPL_H
22 #define INCLUDED_SATNOGS_NOAA_APT_SINK_IMPL_H
23 
24 #include <satnogs/noaa_apt_sink.h>
25 #define PNG_DEBUG 3
26 #include <png++/png.hpp>
27 #include <chrono>
28 
29 
30 
31 namespace gr {
32 namespace satnogs {
34 
36 private:
37  // Factor exponential smoothing average,
38  // which is used for sync pattern detection
39  const float f_average_alpha;
40  static const bool synca_seq[];
41  static const bool syncb_seq[];
42 
43  std::string d_filename_png;
44  size_t d_width;
45  size_t d_height;
46  bool d_synchronize_opt;
47  bool d_flip;
48  size_t d_history_length;
49  bool d_has_sync;
50  bool d_image_received;
51 
52  png::image<png::gray_pixel> d_full_image;
53  png::image<png::gray_pixel> d_left_image;
54  png::image<png::gray_pixel> d_right_image;
55  std::string d_full_filename;
56  std::string d_left_filename;
57  std::string d_right_filename;
58 
59  size_t d_current_x;
60  size_t d_current_y;
61  size_t d_num_images;
62 
63  float f_max_level;
64  float f_min_level;
65  float f_average;
66 
67 public:
68  noaa_apt_sink_impl(const char *filename_png, size_t width, size_t height,
69  bool sync, bool flip);
71 
72  // Where all the action really happens
73  int
74  work(int noutput_items, gr_vector_const_void_star &input_items,
75  gr_vector_void_star &output_items);
76 
77  bool
78  stop();
79 private:
80 
81  /*
82  * Checks if the history portion of the input contains a sync marker.
83  * Matches the 40 samples before pos against the patterns.
84  */
86  is_marker(size_t pos, const float *samples);
87 
88  // Sets the pixel indicated by coordinates in the images (both full and split)
89  void
90  set_pixel(size_t x, size_t y, float sample);
91 
92  /*
93  * Updates d_current_x to new_x,
94  * while using historical samples to fill any resulting gaps in the images.
95  */
96  void
97  skip_to(size_t new_x, size_t pos, const float *samples);
98 
99  // Writes a single image to disk, also takes care of flipping
100  void
101  write_image(png::image<png::gray_pixel> image, std::string filename);
102 };
103 
104 } // namespace satnogs
105 } // namespace gr
106 
107 #endif /* INCLUDED_SATNOGS_NOAA_APT_SINK_IMPL_H */
Definition: noaa_apt_sink_impl.h:35
Definition: amsat_duv_decoder.h:29
noaa_apt_sync_marker
Definition: noaa_apt_sink_impl.h:33
Definition: noaa_apt_sink.h:35