satdump/src-core/core/module.h

105 lines
3.5 KiB
C
Raw Normal View History

2021-02-14 12:05:44 +01:00
#pragma once
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <memory>
2021-02-18 00:37:12 +01:00
#include <atomic>
2021-02-19 00:03:52 +01:00
#include "imgui/imgui_flags.h"
2021-03-11 19:28:50 +01:00
#include "dll_export.h"
2021-10-22 15:26:17 +02:00
#include "common/dsp/complex.h"
#include "common/dsp/buffer.h"
2021-07-21 00:54:48 +02:00
#include "nlohmann/json.hpp"
#include "plugin.h"
2021-02-14 12:05:44 +01:00
2021-07-13 15:52:15 +02:00
// Utils
2023-08-05 15:31:52 -04:00
#define WRITE_IMAGE(image, path) \
{ \
std::string newPath = path; \
image.append_ext(&newPath); \
image.save_img(std::string(newPath).c_str()); \
d_output_files.push_back(newPath); \
}
#define UITO_C_STR(input) "%s", std::to_string(input).c_str()
2021-02-15 19:52:38 +01:00
2021-07-13 15:52:15 +02:00
// Colors
#define IMCOLOR_NOSYNC ImColor::HSV(0 / 360.0, 1, 1, 1.0)
#define IMCOLOR_SYNCING ImColor::HSV(39.0 / 360.0, 0.93, 1, 1.0)
#define IMCOLOR_SYNCED ImColor::HSV(113.0 / 360.0, 1, 1, 1.0)
2021-11-23 11:54:24 +01:00
#define REGISTER_MODULE(module) modules_registry.emplace(module::getID(), module::getInstance)
#define REGISTER_MODULE_EXTERNAL(registry, module) registry.emplace(module::getID(), module::getInstance)
2021-02-20 00:36:44 +01:00
enum ModuleDataType
{
2021-03-22 22:26:21 +01:00
DATA_STREAM, // Generic data, for which a circular buffer will be used
DATA_DSP_STREAM, // DSP Data using the specialized buffer and complex floats
2021-03-22 22:26:21 +01:00
DATA_FILE, // Just generic data from a file
2021-02-20 00:36:44 +01:00
};
2021-02-14 12:05:44 +01:00
class ProcessingModule
{
protected:
const std::string d_input_file;
const std::string d_output_file_hint;
std::vector<std::string> d_output_files;
nlohmann::json d_parameters;
2021-02-20 00:36:44 +01:00
ModuleDataType input_data_type, output_data_type;
2021-02-14 12:05:44 +01:00
bool streamingInput; // Used to know if we should treat the input as a stream or file
2021-02-14 12:05:44 +01:00
public:
ProcessingModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters);
2021-02-20 00:36:44 +01:00
virtual std::vector<ModuleDataType> getInputTypes() { return {DATA_FILE}; }
virtual std::vector<ModuleDataType> getOutputTypes() { return {DATA_FILE}; }
void setInputType(ModuleDataType type);
void setOutputType(ModuleDataType type);
2021-05-22 16:36:09 +02:00
ModuleDataType getInputType();
ModuleDataType getOutputType();
2021-03-22 22:26:21 +01:00
virtual void init();
2021-05-22 16:36:09 +02:00
virtual void stop();
2021-02-14 12:05:44 +01:00
virtual void process() = 0;
2021-03-31 18:15:26 +02:00
virtual void drawUI(bool window) = 0;
2021-02-14 12:05:44 +01:00
std::vector<std::string> getOutputs();
2021-02-20 00:36:44 +01:00
public:
std::shared_ptr<dsp::RingBuffer<uint8_t>> input_fifo;
std::shared_ptr<dsp::RingBuffer<uint8_t>> output_fifo;
2021-10-22 15:26:17 +02:00
std::shared_ptr<dsp::stream<complex_t>> input_stream;
std::shared_ptr<dsp::stream<complex_t>> output_stream;
2021-02-22 18:23:31 +01:00
std::atomic<bool> input_active;
2021-02-20 00:36:44 +01:00
2021-07-21 00:54:48 +02:00
public:
nlohmann::json module_stats;
2021-02-14 12:05:44 +01:00
public:
static std::string getID();
2021-07-21 00:54:48 +02:00
virtual std::string getIDM() = 0;
2021-02-14 12:05:44 +01:00
static std::vector<std::string> getParameters();
static std::shared_ptr<ProcessingModule> getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters);
2021-02-14 12:05:44 +01:00
};
SATDUMP_DLL extern std::map<std::string, std::function<std::shared_ptr<ProcessingModule>(std::string, std::string, nlohmann::json)>> modules_registry;
2021-02-14 12:05:44 +01:00
2021-11-23 11:54:24 +01:00
// Event where modules are registered, so plugins can load theirs
struct RegisterModulesEvent
{
std::map<std::string, std::function<std::shared_ptr<ProcessingModule>(std::string, std::string, nlohmann::json)>> &modules_registry;
};
void registerModules();
SATDUMP_DLL extern float ui_scale; // UI Scaling factor, for DPI scaling
2022-02-25 20:25:38 +01:00
SATDUMP_DLL extern int demod_constellation_size; // Demodulator constellation size
// Status stuff
enum instrument_status_t
{
DECODING,
PROCESSING,
SAVING,
DONE,
};
2022-02-25 20:50:27 +01:00
void drawStatus(instrument_status_t status);