3#include "common/dsp/complex.h"
4#include "dsp/agc/agc.h"
6#include "dsp/clock_recovery/clock_recovery_mm.h"
7#include "dsp/filter/rrc.h"
8#include "dsp/pll/costas.h"
10#include "nlohmann/json.hpp"
18 class PSKDemodHierBlock :
public Block
29 std::string constellation =
"bpsk";
30 double samplerate = 6e6;
31 double symbolrate = 2e6;
32 bool advanced_mode =
false;
38 std::vector<BlockIO>
get_inputs() {
return rrc_blk.get_inputs(); }
39 std::vector<BlockIO>
get_outputs() {
return pll_blk.get_outputs(); }
83 void stop(
bool stop_snow,
bool force)
85 rrc_blk.stop(stop_snow);
86 agc_blk.stop(stop_snow);
87 rec_blk.stop(stop_snow);
88 pll_blk.stop(stop_snow);
95 nlohmann::ordered_json v;
97 add_param_list(v,
"constellation",
"string", {
"bpsk",
"qpsk"});
98 add_param_simple(v,
"samplerate",
"float");
99 add_param_simple(v,
"symbolrate",
"float");
100 add_param_simple(v,
"advanced",
"bool");
104 auto rrc_list = rrc_blk.get_cfg_list();
105 for (
auto &i : rrc_list.items())
107 if (i.value().contains(
"name"))
108 i.value()[
"name"] =
"RRC " + i.value()[
"name"].get<std::string>();
109 v[
"rrc_" + i.key()] = i.value();
111 auto agc_list = agc_blk.get_cfg_list();
112 for (
auto &i : agc_list.items())
114 if (i.value().contains(
"name"))
115 i.value()[
"name"] =
"AGC " + i.value()[
"name"].get<std::string>();
116 v[
"agc_" + i.key()] = i.value();
118 auto rec_list = rec_blk.get_cfg_list();
119 for (
auto &i : rec_list.items())
121 if (i.value().contains(
"name"))
122 i.value()[
"name"] =
"Rec " + i.value()[
"name"].get<std::string>();
123 v[
"rec_" + i.key()] = i.value();
125 auto pll_list = pll_blk.get_cfg_list();
126 for (
auto &i : pll_list.items())
128 if (i.value().contains(
"name"))
129 i.value()[
"name"] =
"PLL " + i.value()[
"name"].get<std::string>();
130 v[
"pll_" + i.key()] = i.value();
139 if (key ==
"constellation")
140 return constellation;
141 else if (key ==
"samplerate")
143 else if (key ==
"symbolrate")
145 else if (key ==
"advanced")
146 return advanced_mode;
147 else if (key.find(
"rrc_") == 0)
149 replaceAllStr(key,
"rrc_",
"");
150 return rrc_blk.get_cfg(key);
152 else if (key.find(
"agc_") == 0)
154 replaceAllStr(key,
"agc_",
"");
155 return agc_blk.get_cfg(key);
157 else if (key.find(
"rec_") == 0)
159 replaceAllStr(key,
"rec_",
"");
160 return rec_blk.get_cfg(key);
162 else if (key.find(
"pll_") == 0)
164 replaceAllStr(key,
"pll_",
"");
165 return pll_blk.get_cfg(key);
169 return nlohmann::ordered_json();
175 if (key ==
"constellation" && (v ==
"bpsk" || v ==
"qpsk"))
182 return pll_blk.set_cfg(
"order", 2);
184 return pll_blk.set_cfg(
"order", 4);
186 else if (key ==
"samplerate" || key ==
"symbolrate")
188 if (key ==
"samplerate")
190 if (key ==
"symbolrate")
194 res = std::max(rrc_blk.set_cfg(
"samplerate", samplerate), res);
195 res = std::max(rrc_blk.set_cfg(
"symbolrate", symbolrate), res);
196 res = std::max(rec_blk.set_cfg(
"omega", samplerate / symbolrate), res);
199 else if (key ==
"advanced")
204 else if (key.find(
"rrc_") == 0)
206 replaceAllStr(key,
"rrc_",
"");
207 return rrc_blk.set_cfg(key, v);
209 else if (key.find(
"agc_") == 0)
211 replaceAllStr(key,
"agc_",
"");
212 return agc_blk.set_cfg(key, v);
214 else if (key.find(
"rec_") == 0)
216 replaceAllStr(key,
"rec_",
"");
217 return rec_blk.set_cfg(key, v);
219 else if (key.find(
"pll_") == 0)
221 replaceAllStr(key,
"pll_",
"");
222 return pll_blk.set_cfg(key, v);
cfg_res_t
set_cfg status.
Definition block.h:241
Block(std::string id, std::vector< BlockIO > in={}, std::vector< BlockIO > out={})
Generic constructor, to be overloaded.
Definition block.h:208
Definition clock_recovery_mm.h:13
bool work()
The actual looping work function meant to handle all the DSP (well, in most blocks)
Definition psk_demod.h:230
void init()
Applies current parameters to the block. This is called automatically once in start(),...
Definition psk_demod.h:43
nlohmann::json get_cfg(std::string key)
Get parameters of the block as JSON.
Definition psk_demod.h:137
std::vector< BlockIO > get_inputs()
Get the block's input configurations and streams. You should not modify them.
Definition psk_demod.h:38
nlohmann::ordered_json get_cfg_list()
Get parameters LIST of the block's parameters. This does not contain actual values,...
Definition psk_demod.h:93
BlockIO get_output(int i, int nbuf)
Get one of the block's outputs, creating the fifo it if nbuf != 0.
Definition psk_demod.h:41
std::vector< BlockIO > get_outputs()
Get the block's output configurations and streams. You should not modify them.
Definition psk_demod.h:39
void start()
Starts this block's internal thread and loop.
Definition psk_demod.h:71
void set_input(BlockIO f, int i)
Link an input to an output stream of some sort. This also checks the type of the BlockIO to ensure (s...
Definition psk_demod.h:40
void stop(bool stop_snow, bool force)
Stops the block, or rather tells the internal loop it should exit & joins the thread to wait....
Definition psk_demod.h:83
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 psk_demod.h:173
A collection of string-related utility functions.
Block IO helper class.
Definition block.h:44