SatDump 2.0.0-alpha-76a915210
Loading...
Searching...
No Matches
splitter.h
1#pragma once
2
3#include "common/dsp/complex.h"
4#include "dsp/block.h"
5#include <mutex>
6#include <string>
7
8namespace satdump
9{
10 namespace ndsp
11 {
12 template <typename T>
13 class SplitterBlock : public Block
14 {
15 public:
16 int p_noutputs = 0;
17 std::mutex vfos_mtx;
18
19 public:
20 struct IOInfo
21 {
22 std::string id;
23 bool forward_terminator;
24 };
25
26 private:
27 bool work();
28
29 public:
30 SplitterBlock();
31 ~SplitterBlock();
32
33 void init() {}
34
35 nlohmann::ordered_json get_cfg_list()
36 {
37 nlohmann::ordered_json p;
38 add_param_simple(p, "noutputs", "int");
39 p["noutputs"]["disable"] = is_work_running();
40 return p;
41 }
42
43 nlohmann::json get_cfg(std::string key)
44 {
45 if (key == "noutputs")
46 return p_noutputs;
47 throw satdump_exception(key);
48 }
49
50 cfg_res_t set_cfg(std::string key, nlohmann::json v)
51 {
52 std::lock_guard<std::mutex> lock_mtx(vfos_mtx);
53
54 if (key == "noutputs")
55 {
56 int no = p_noutputs;
57 p_noutputs = v;
58
59 if (p_noutputs < 0)
60 p_noutputs = 0;
61
62 if (no != p_noutputs)
63 {
64 Block::outputs.clear();
65 for (int i = 0; i < p_noutputs; i++)
66 {
67 BlockIO o = {{"out" + std::to_string(i + 1), std::is_same_v<T, complex_t> ? DSP_SAMPLE_TYPE_CF32 : DSP_SAMPLE_TYPE_F32}};
68 o.blkdata = std::make_shared<IOInfo>(IOInfo{std::to_string(i + 1), true});
69 o.fifo = std::make_shared<DSPStream>(4); // TODOREWORK
70 Block::outputs.push_back(o);
71 }
72 }
73 return RES_IOUPD;
74 }
75 else
76 throw satdump_exception(key);
77 return RES_OK;
78 }
79
80 public:
81 BlockIO &add_output(std::string id, bool forward_terminator = true)
82 {
83 std::lock_guard<std::mutex> lock_mtx(vfos_mtx);
84
85 BlockIO o = {{id, std::is_same_v<T, complex_t> ? DSP_SAMPLE_TYPE_CF32 : DSP_SAMPLE_TYPE_F32}};
86 o.blkdata = std::make_shared<IOInfo>(IOInfo{id, forward_terminator});
87 o.fifo = std::make_shared<DSPStream>(4); // TODOREWORK
88 Block::outputs.push_back(o);
89 return outputs[outputs.size() - 1];
90 }
91
92 void del_output(std::string id, bool send_terminator) // TODOREWORk maybe a terminator_type_none, _propag, etc? Also maybe a handleTerminator doing it?
93 {
94 std::lock_guard<std::mutex> lock_mtx(vfos_mtx);
95
96 for (int i = 0; i < outputs.size(); i++)
97 if (((IOInfo *)outputs[i].blkdata.get())->id == id)
98 {
99 if (send_terminator)
100 (outputs.begin() + i)->fifo->wait_enqueue((outputs.begin() + i)->fifo->newBufferTerminator());
101 outputs.erase(outputs.begin() + i);
102 }
103 }
104 };
105 } // namespace ndsp
106} // 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
void init()
Applies current parameters to the block. This is called automatically once in start(),...
Definition splitter.h:33
nlohmann::ordered_json get_cfg_list()
Get parameters LIST of the block's parameters. This does not contain actual values,...
Definition splitter.h:35
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 splitter.h:50
nlohmann::json get_cfg(std::string key)
Get parameters of the block as JSON.
Definition splitter.h:43
Block IO helper class.
Definition block.h:42
Definition splitter.h:21