SatDump 2.0.0-alpha-520736c72
Loading...
Searching...
No Matches
psk_demod.h
1#pragma once
2
3#include "common/dsp/complex.h"
4#include "dsp/agc/agc.h"
5#include "dsp/block.h"
6#include "dsp/clock_recovery/clock_recovery_mm.h"
7#include "dsp/filter/rrc.h"
8#include "dsp/pll/costas.h"
9#include "logger.h"
10#include "nlohmann/json.hpp"
11#include "utils/string.h"
12#include <string>
13
14namespace satdump
15{
16 namespace ndsp
17 {
18 class PSKDemodHierBlock : public Block
19 {
20 private:
22 AGCBlock<complex_t> agc_blk;
24 CostasBlock pll_blk;
25
26 private:
27 bool running = false;
28
29 std::string constellation = "bpsk";
30 double samplerate = 6e6;
31 double symbolrate = 2e6;
32 bool advanced_mode = false;
33
34 public:
35 PSKDemodHierBlock();
36 ~PSKDemodHierBlock();
37
38 std::vector<BlockIO> get_inputs() { return rrc_blk.get_inputs(); }
39 std::vector<BlockIO> get_outputs() { return pll_blk.get_outputs(); }
40 void set_input(BlockIO f, int i) { rrc_blk.set_input(f, i); }
41 BlockIO get_output(int i, int nbuf) { return pll_blk.get_output(i, nbuf); }
42
43 void init()
44 {
45 /*if (running)
46 {
47 pll_blk.stop(true, true);
48 rec_blk.stop(true, true);
49 agc_blk.stop(true, true);
50 }
51
52 if (constellation == "oqpsk")
53 {
54 logger->error("TODOREWORK!");
55 }
56 else
57 {
58 agc_blk.link(&rrc_blk, 0, 0, 4);
59 rec_blk.link(&agc_blk, 0, 0, 4);
60 pll_blk.link(&rec_blk, 0, 0, 4);
61 }
62
63 if (running)
64 {
65 agc_blk.start();
66 rec_blk.start();
67 pll_blk.start();
68 }*/
69 }
70
71 void start()
72 {
73 init();
74
75 rrc_blk.start();
76 agc_blk.start();
77 rec_blk.start();
78 pll_blk.start();
79
80 running = true;
81 }
82
83 void stop(bool stop_snow, bool force)
84 {
85 rrc_blk.stop(stop_snow);
86 agc_blk.stop(stop_snow);
87 rec_blk.stop(stop_snow);
88 pll_blk.stop(stop_snow);
89
90 running = false;
91 }
92
93 nlohmann::ordered_json get_cfg_list()
94 {
95 nlohmann::ordered_json v;
96
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");
101
102 if (advanced_mode)
103 {
104 auto rrc_list = rrc_blk.get_cfg_list();
105 for (auto &i : rrc_list.items())
106 {
107 if (i.value().contains("name"))
108 i.value()["name"] = "RRC " + i.value()["name"].get<std::string>();
109 v["rrc_" + i.key()] = i.value();
110 }
111 auto agc_list = agc_blk.get_cfg_list();
112 for (auto &i : agc_list.items())
113 {
114 if (i.value().contains("name"))
115 i.value()["name"] = "AGC " + i.value()["name"].get<std::string>();
116 v["agc_" + i.key()] = i.value();
117 }
118 auto rec_list = rec_blk.get_cfg_list();
119 for (auto &i : rec_list.items())
120 {
121 if (i.value().contains("name"))
122 i.value()["name"] = "Rec " + i.value()["name"].get<std::string>();
123 v["rec_" + i.key()] = i.value();
124 }
125 auto pll_list = pll_blk.get_cfg_list();
126 for (auto &i : pll_list.items())
127 {
128 if (i.value().contains("name"))
129 i.value()["name"] = "PLL " + i.value()["name"].get<std::string>();
130 v["pll_" + i.key()] = i.value();
131 }
132 }
133
134 return v;
135 }
136
137 nlohmann::json get_cfg(std::string key)
138 {
139 if (key == "constellation")
140 return constellation;
141 else if (key == "samplerate")
142 return samplerate;
143 else if (key == "symbolrate")
144 return symbolrate;
145 else if (key == "advanced")
146 return advanced_mode;
147 else if (key.find("rrc_") == 0)
148 {
149 replaceAllStr(key, "rrc_", "");
150 return rrc_blk.get_cfg(key);
151 }
152 else if (key.find("agc_") == 0)
153 {
154 replaceAllStr(key, "agc_", "");
155 return agc_blk.get_cfg(key);
156 }
157 else if (key.find("rec_") == 0)
158 {
159 replaceAllStr(key, "rec_", "");
160 return rec_blk.get_cfg(key);
161 }
162 else if (key.find("pll_") == 0)
163 {
164 replaceAllStr(key, "pll_", "");
165 return pll_blk.get_cfg(key);
166 }
167 else
168 {
169 return nlohmann::ordered_json();
170 }
171 }
172
173 cfg_res_t set_cfg(std::string key, nlohmann::json v)
174 {
175 if (key == "constellation" && (v == "bpsk" || v == "qpsk"))
176 {
177 constellation = v;
178
179 init();
180
181 if (v == "bpsk")
182 return pll_blk.set_cfg("order", 2);
183 else
184 return pll_blk.set_cfg("order", 4);
185 }
186 else if (key == "samplerate" || key == "symbolrate")
187 {
188 if (key == "samplerate")
189 samplerate = v;
190 if (key == "symbolrate")
191 symbolrate = v;
192
193 cfg_res_t res = RES_OK;
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);
197 return res;
198 }
199 else if (key == "advanced")
200 {
201 advanced_mode = v;
202 return RES_LISTUPD;
203 }
204 else if (key.find("rrc_") == 0)
205 {
206 replaceAllStr(key, "rrc_", "");
207 return rrc_blk.set_cfg(key, v);
208 }
209 else if (key.find("agc_") == 0)
210 {
211 replaceAllStr(key, "agc_", "");
212 return agc_blk.set_cfg(key, v);
213 }
214 else if (key.find("rec_") == 0)
215 {
216 replaceAllStr(key, "rec_", "");
217 return rec_blk.set_cfg(key, v);
218 }
219 else if (key.find("pll_") == 0)
220 {
221 replaceAllStr(key, "pll_", "");
222 return pll_blk.set_cfg(key, v);
223 }
224 else
225 {
226 return RES_ERR;
227 }
228 }
229
230 bool work() { return false; }
231 };
232 } // namespace ndsp
233} // namespace satdump
Definition agc.h:11
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 costas.h:11
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
Definition rrc.h:13
A collection of string-related utility functions.
Block IO helper class.
Definition block.h:44