SatDump 2.0.0-alpha-76a915210
Loading...
Searching...
No Matches
file_source.h
1#pragma once
2
3#include "common/dsp/io/baseband_interface.h"
4#include "dsp/block.h"
5
6namespace satdump
7{
8 namespace ndsp
9 {
10 class FileSourceBlock : public Block
11 {
12 public:
13 std::string p_file = "/tmp/afile";
14 dsp::BasebandType p_type = dsp::CF_32;
15 int p_buffer_size = 8192;
16 bool p_iq_swap = false;
17
18 private:
19 dsp::BasebandType d_type;
20
21 int d_buffer_size;
22 bool d_iq_swap;
23 std::atomic<bool> d_eof;
24
25 dsp::BasebandReader baseband_reader;
26
27 bool work();
28
29 public:
30 // TODOREWORK
31 std::atomic<uint64_t> d_filesize;
32 std::atomic<uint64_t> d_progress;
33
34 public:
35 FileSourceBlock();
36 ~FileSourceBlock();
37
38 void init()
39 {
40 d_type = p_type;
41 d_buffer_size = p_buffer_size;
42 d_iq_swap = p_iq_swap;
43
44 baseband_reader.set_file(p_file, p_type);
45
46 d_filesize = baseband_reader.filesize;
47 d_progress = 0;
48 d_eof = false;
49 }
50
51 nlohmann::ordered_json get_cfg_list()
52 {
53 nlohmann::ordered_json p;
54 add_param_simple(p, "file", "string");
55 p["file"]["disable"] = is_work_running();
56 add_param_simple(p, "type", "string");
57 p["type"]["disable"] = is_work_running();
58 add_param_simple(p, "buffer_size", "int");
59 p["buffer_size"]["disable"] = is_work_running();
60 add_param_simple(p, "iq_swap", "bool");
61 p["iq_swap"]["disable"] = is_work_running();
62 return p;
63 }
64
65 nlohmann::json get_cfg(std::string key)
66 {
67 if (key == "file")
68 return p_file;
69 else if (key == "type")
70 return (std::string)p_type;
71 else if (key == "buffer_size")
72 return p_buffer_size;
73 else if (key == "iq_swap")
74 return p_iq_swap;
75 else
76 throw satdump_exception(key);
77 }
78
79 cfg_res_t set_cfg(std::string key, nlohmann::json v)
80 {
81 if (key == "file")
82 p_file = v;
83 else if (key == "type")
84 p_type = v.get<std::string>();
85 else if (key == "buffer_size")
86 p_buffer_size = v;
87 else if (key == "iq_swap")
88 p_iq_swap = v;
89 else
90 throw satdump_exception(key);
91 return RES_OK;
92 }
93 };
94 } // namespace ndsp
95} // namespace satdump
cfg_res_t
set_cfg status.
Definition block.h:227
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:206
nlohmann::json get_cfg(std::string key)
Get parameters of the block as JSON.
Definition file_source.h:65
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 file_source.h:79
void init()
Applies current parameters to the block. This is called automatically once in start(),...
Definition file_source.h:38
nlohmann::ordered_json get_cfg_list()
Get parameters LIST of the block's parameters. This does not contain actual values,...
Definition file_source.h:51