SatDump 2.0.0-alpha-520736c72
Loading...
Searching...
No Matches
module_svissr_image_decoder.h
Go to the documentation of this file.
1#pragma once
2
7
9#include "pipeline/modules/base/filestream_to_filestream.h"
10#include <thread>
11
12namespace fengyun_svissr
13{
14 enum SVISSRSubCommunicationBlockType
15 {
16 Simplified_mapping,
17 Orbit_and_attitude,
18 MANAM,
19 Calibration_1,
20 Calibration_2,
21 Spare
22 };
23
25 {
26 int start_offset;
27 int end_offset;
28 };
29
30 // Abstracts the stupid idiot subcommunication groups away
31 typedef std::vector<uint8_t> Group;
32 typedef std::vector<uint8_t> MinorFrame;
33
34 class SVISSRImageDecoderModule : public satdump::pipeline::base::FileStreamToFileStreamModule
35 {
36 struct SVISSRSubcommunicationBlock
37 {
38 std::string name;
39 int start_offset;
40 int end_offset;
41 };
42
43 protected:
44 // Settings
45 std::string sat_name;
46
47 // Read buffer
48 uint8_t *frame;
49
50 // Utils values
51 bool backwardScan;
52 bool writingImage = false;
53 int valid_lines;
54 float approx_progess;
55 bool apply_correction;
56 int global_counter;
57 bool counter_locked = false;
58
60 {
61 int scid;
62
63 image::Image image1; /* VIS Visible 500-900 nm */
64 image::Image image2; /* IR4 Medium wave 3.5-4.0 μm */
65 image::Image image3; /* IR3 Water vapour 6.5-7.0 μm */
66 image::Image image4; /* IR1 Long wave IR 10.3-11.3 μm */
67 image::Image image5; /* IR2 Split window 11.5-12.5 μm */
68
69 std::string directory;
70 };
71
72 // Image readers
73 SVISSRReader vissrImageReader;
74
75 // Saving is multithreaded
76 std::mutex images_queue_mtx;
77 std::vector<std::shared_ptr<SVISSRBuffer>> images_queue;
78 std::thread images_queue_thread;
79
80 bool images_thread_should_run;
81 void image_saving_thread_f()
82 {
83 while (images_thread_should_run || images_queue.size() > 0)
84 {
85 images_queue_mtx.lock();
86 bool has_images = images_queue.size() > 0;
87 images_queue_mtx.unlock();
88
89 if (has_images)
90 {
91 images_queue_mtx.lock();
92 auto img = images_queue[0];
93 images_queue.erase(images_queue.begin());
94 images_queue_mtx.unlock();
95 writeImages(*img);
96 continue;
97 }
98
99 std::this_thread::sleep_for(std::chrono::seconds(1));
100 }
101 }
102
103 std::string getSvissrFilename(std::tm *timeReadable, std::string channel);
104 void writeImages(SVISSRBuffer &buffer);
105
106 // Stats
107 std::vector<int> scid_stats;
108
109 // Subcommunication block handling
110 void save_subcom_frame();
111 std::vector<MinorFrame> subcommunication_frames; /* 25 2097 byte groups forming a full subcommunication frame */
112 MinorFrame current_subcom_frame; /* A full subcommunication frame */
113 std::vector<Group> group_retransmissions; /* Retransmissions of a given group */
114
115 // UI Stuff
116 float corr_history_ca[200];
117 unsigned int textureID = 0;
118 uint32_t *textureBuffer;
119
120 public:
121 SVISSRImageDecoderModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters);
122 ~SVISSRImageDecoderModule();
123 void process();
124 void drawUI(bool window);
125
126 nlohmann::json getModuleStats();
127
128 public:
129 static std::string getID();
130 virtual std::string getIDM() { return getID(); };
131 static nlohmann::json getParams() { return {}; } // TODOREWORK
132 static std::shared_ptr<ProcessingModule> getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters);
133 };
134} // namespace fengyun_svissr
void save_subcom_frame()
Builds the 25 received groups of a minor frame, saves it. Aborts if we didn't get 25 groups.
Definition module_svissr_image_decoder.cpp:140
void writeImages(SVISSRBuffer &buffer)
Processes the received products.
Definition module_svissr_image_decoder.cpp:174
Definition svissr_reader.h:15
Definition image.h:17
Definition module_svissr_image_decoder.h:60
Definition module_svissr_image_decoder.h:25
Contains functions to read image data from SVISSR frames.