SatDump 2.0.0-alpha-520736c72
Loading...
Searching...
No Matches
file_sink.h
1#pragma once
2
3#include "common/utils.h"
4#include "dsp/block.h"
5#include <fstream>
6
7namespace satdump
8{
9 namespace ndsp
10 {
11 template <typename T>
12 class FileSinkBlock : public Block
13 {
14 public:
15 std::string p_file = "/tmp/afile";
16
17 private:
18 std::ofstream file_writer;
19
20 bool work();
21
22 public:
23 FileSinkBlock();
24 ~FileSinkBlock();
25
26 void init() { file_writer = std::ofstream(p_file, std::ios::binary); }
27
28 nlohmann::ordered_json get_cfg_list()
29 {
30 nlohmann::ordered_json p;
31 add_param_simple(p, "file", "string");
32 p["file"]["disable"] = is_work_running();
33 return p;
34 }
35
36 nlohmann::json get_cfg(std::string key)
37 {
38 if (key == "file")
39 return p_file;
40 else
41 throw satdump_exception(key);
42 }
43
44 cfg_res_t set_cfg(std::string key, nlohmann::json v)
45 {
46 if (key == "file")
47 p_file = v;
48 else
49 throw satdump_exception(key);
50 return RES_OK;
51 }
52 };
53 } // namespace ndsp
54} // 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
void init()
Applies current parameters to the block. This is called automatically once in start(),...
Definition file_sink.h:26
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_sink.h:44
nlohmann::ordered_json get_cfg_list()
Get parameters LIST of the block's parameters. This does not contain actual values,...
Definition file_sink.h:28
nlohmann::json get_cfg(std::string key)
Get parameters of the block as JSON.
Definition file_sink.h:36