SatDump 2.0.0-alpha-520736c72
Loading...
Searching...
No Matches
file_source.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 FileSourceBlock : public Block
13 {
14 public:
15 std::string p_file = "/tmp/afile";
16 int p_buffer_size = 8192;
17
18 private:
19 int d_buffer_size;
20
21 std::atomic<bool> d_eof;
22
23 std::ifstream file_reader;
24
25 bool work();
26
27 public:
28 // TODOREWORK
29 std::atomic<uint64_t> d_filesize;
30 std::atomic<uint64_t> d_progress;
31
32 public:
33 FileSourceBlock();
34 ~FileSourceBlock();
35
36 void init()
37 {
38 d_buffer_size = p_buffer_size;
39
40 file_reader = std::ifstream(p_file, std::ios::binary);
41
42 d_filesize = getFilesize(p_file);
43 d_progress = 0;
44 d_eof = false;
45 }
46
47 nlohmann::ordered_json get_cfg_list()
48 {
49 nlohmann::ordered_json p;
50 add_param_simple(p, "file", "string");
51 p["file"]["disable"] = is_work_running();
52 add_param_simple(p, "buffer_size", "int");
53 p["buffer_size"]["disable"] = is_work_running();
54 return p;
55 }
56
57 nlohmann::json get_cfg(std::string key)
58 {
59 if (key == "file")
60 return p_file;
61 else if (key == "buffer_size")
62 return p_buffer_size;
63 else
64 throw satdump_exception(key);
65 }
66
67 cfg_res_t set_cfg(std::string key, nlohmann::json v)
68 {
69 if (key == "file")
70 p_file = v;
71 else if (key == "buffer_size")
72 p_buffer_size = v;
73 else
74 throw satdump_exception(key);
75 return RES_OK;
76 }
77 };
78 } // namespace ndsp
79} // 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_source.h:36
nlohmann::json get_cfg(std::string key)
Get parameters of the block as JSON.
Definition file_source.h:57
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:67
nlohmann::ordered_json get_cfg_list()
Get parameters LIST of the block's parameters. This does not contain actual values,...
Definition file_source.h:47