SatDump 2.0.0-alpha-520736c72
Loading...
Searching...
No Matches
iq_sink.h
1#pragma once
2
3#include "common/dsp/block.h"
4#include "common/dsp/complex.h"
5#include "dsp/block.h"
6#include "iq_types.h"
7#include <cstdint>
8#include <cstdio>
9
10namespace satdump
11{
12 namespace ndsp
13 {
14 class IQSinkBlock : public Block
15 {
16 public:
17 size_t total_written_raw;
18 size_t total_written_bytes_compressed;
19
20 private:
21 int buffer_size = 1024 * 1024; // TODOREWORK
22 std::string filepath;
23 IQType format;
24 bool autogen = false;
25 double samplerate = 1e6;
26 double frequency = 100e6;
27 double timestamp = 0;
28
29 FILE *file_stream = nullptr;
30 void *buffer_convert = nullptr;
31
32 bool work();
33
34 public:
35 void start();
36 void stop(bool stop_now = false, bool force=false);
37
38 public:
39 IQSinkBlock();
40 ~IQSinkBlock();
41
42 void init() {}
43
44 nlohmann::ordered_json get_cfg_list()
45 {
46 nlohmann::ordered_json p;
47 add_param_simple(p, "file", "string");
48 p["file"]["disable"] = is_work_running();
49 add_param_simple(p, "type", "string");
50 p["type"]["disable"] = is_work_running();
51 add_param_simple(p, "buffer_size", "int");
52 p["buffer_size"]["disable"] = is_work_running();
53 add_param_simple(p, "autogen", "bool");
54 p["autogen"]["disable"] = is_work_running();
55 add_param_simple(p, "samplerate", "float");
56 p["samplerate"]["disable"] = is_work_running();
57 add_param_simple(p, "frequency", "float");
58 p["frequency"]["disable"] = is_work_running();
59 add_param_simple(p, "timestamp", "float");
60 p["timestamp"]["disable"] = is_work_running();
61 return p;
62 }
63
64 nlohmann::json get_cfg(std::string key)
65 {
66 if (key == "buffer_size")
67 return buffer_size;
68 else if (key == "file")
69 return filepath;
70 else if (key == "type")
71 return format;
72 else if (key == "autogen")
73 return autogen;
74 else if (key == "samplerate")
75 return samplerate;
76 else if (key == "frequency")
77 return frequency;
78 else if (key == "timestamp")
79 return timestamp;
80 else
81 throw satdump_exception(key);
82 }
83
84 cfg_res_t set_cfg(std::string key, nlohmann::json v)
85 {
86 if (key == "buffer_size")
87 buffer_size = v;
88 else if (key == "file")
89 filepath = v;
90 else if (key == "type")
91 format = v.get<std::string>();
92 else if (key == "samplerate")
93 samplerate = v;
94 else if (key == "autogen")
95 autogen = v;
96 else if (key == "frequency")
97 frequency = v;
98 else if (key == "timestamp")
99 timestamp = v;
100 else
101 throw satdump_exception(key);
102 return RES_OK;
103 }
104
105 public:
106 static std::string prepareBasebandFileName(double timeValue_precise, uint64_t samplerate, uint64_t frequency);
107 };
108 } // namespace ndsp
109} // namespace satdump
cfg_res_t
set_cfg status.
Definition block.h:241
virtual bool work()=0
The actual looping work function meant to handle all the DSP (well, in most blocks)
Block(std::string id, std::vector< BlockIO > in={}, std::vector< BlockIO > out={})
Generic constructor, to be overloaded.
Definition block.h:208
nlohmann::json get_cfg(std::string key)
Get parameters of the block as JSON.
Definition iq_sink.h:64
cfg_res_t set_cfg(std::string key, nlohmann::json v)
Set parameters of the block from JSON, including potentially IO configurations for blocks that may ha...
Definition iq_sink.h:84
void start()
Starts this block's internal thread and loop.
Definition iq_sink.cpp:20
void stop(bool stop_now=false, bool force=false)
Stops the block, or rather tells the internal loop it should exit & joins the thread to wait....
Definition iq_sink.cpp:46
nlohmann::ordered_json get_cfg_list()
Get parameters LIST of the block's parameters. This does not contain actual values,...
Definition iq_sink.h:44
void init()
Applies current parameters to the block. This is called automatically once in start(),...
Definition iq_sink.h:42
Definition iq_types.h:26