2024-01-21 17:12:11 +01:00
|
|
|
#include "autotrack.h"
|
|
|
|
|
#include "common/utils.h"
|
2025-05-31 20:26:47 +02:00
|
|
|
#include "logger.h"
|
2025-05-26 19:21:10 +01:00
|
|
|
#include "utils/time.h"
|
2024-01-21 17:12:11 +01:00
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
void AutoTrackApp::add_vfo_live(std::string id, std::string name, double freq, satdump::pipeline::Pipeline vpipeline, nlohmann::json vpipeline_params)
|
2024-01-21 17:12:11 +01:00
|
|
|
{
|
|
|
|
|
vfos_mtx.lock();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
VFOInfo wipInfo;
|
|
|
|
|
wipInfo.id = id;
|
|
|
|
|
wipInfo.name = name;
|
|
|
|
|
wipInfo.freq = freq;
|
2024-07-21 14:58:03 -04:00
|
|
|
wipInfo.selected_pipeline = vpipeline;
|
2024-01-21 17:12:11 +01:00
|
|
|
wipInfo.pipeline_params = vpipeline_params;
|
|
|
|
|
wipInfo.lpool = std::make_shared<ctpl::thread_pool>(8);
|
|
|
|
|
|
|
|
|
|
vpipeline_params["samplerate"] = get_samplerate();
|
2024-05-15 17:53:20 +02:00
|
|
|
vpipeline_params["baseband_format"] = "cf32";
|
2024-01-21 17:12:11 +01:00
|
|
|
vpipeline_params["buffer_size"] = dsp::STREAM_BUFFER_SIZE; // This is required, as we WILL go over the (usually) default 8192 size
|
|
|
|
|
vpipeline_params["start_timestamp"] = (double)time(0); // Some pipelines need this
|
|
|
|
|
|
2025-06-11 17:38:30 +02:00
|
|
|
std::string output_dir = prepareAutomatedPipelineFolder(time(0), freq, vpipeline.id, d_output_folder);
|
2024-01-21 17:12:11 +01:00
|
|
|
|
|
|
|
|
wipInfo.output_dir = output_dir;
|
|
|
|
|
|
2025-05-31 20:26:47 +02:00
|
|
|
wipInfo.live_pipeline = std::make_shared<satdump::pipeline::LivePipeline>(vpipeline, vpipeline_params, output_dir);
|
2024-01-21 17:12:11 +01:00
|
|
|
splitter->add_vfo(id, get_samplerate(), frequency_hz - freq);
|
|
|
|
|
wipInfo.live_pipeline->start(splitter->get_vfo_output(id), *wipInfo.lpool.get());
|
|
|
|
|
splitter->set_vfo_enabled(id, true);
|
|
|
|
|
|
|
|
|
|
if (fft)
|
|
|
|
|
fft_plot->vfo_freqs.push_back({name, freq});
|
|
|
|
|
|
|
|
|
|
vfo_list.push_back(wipInfo);
|
|
|
|
|
}
|
|
|
|
|
catch (std::exception &e)
|
|
|
|
|
{
|
|
|
|
|
logger->error("Error adding VFO : %s", e.what());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vfos_mtx.unlock();
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-21 22:58:56 +01:00
|
|
|
void AutoTrackApp::add_vfo_reco(std::string id, std::string name, double freq, dsp::BasebandType type, int decimation)
|
|
|
|
|
{
|
|
|
|
|
vfos_mtx.lock();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
VFOInfo wipInfo;
|
|
|
|
|
wipInfo.id = id;
|
|
|
|
|
wipInfo.name = name;
|
|
|
|
|
wipInfo.freq = freq;
|
|
|
|
|
|
|
|
|
|
splitter->add_vfo(id, get_samplerate(), frequency_hz - freq);
|
|
|
|
|
|
|
|
|
|
if (decimation > 1)
|
|
|
|
|
wipInfo.decim_ptr = std::make_shared<dsp::SmartResamplerBlock<complex_t>>(splitter->get_vfo_output(id), 1, decimation);
|
|
|
|
|
wipInfo.file_sink = std::make_shared<dsp::FileSinkBlock>(decimation > 1 ? wipInfo.decim_ptr->output_stream : splitter->get_vfo_output(id));
|
|
|
|
|
wipInfo.file_sink->set_output_sample_type(type);
|
|
|
|
|
|
|
|
|
|
if (decimation > 1)
|
|
|
|
|
wipInfo.decim_ptr->start();
|
|
|
|
|
wipInfo.file_sink->start();
|
|
|
|
|
|
2025-05-26 19:21:10 +01:00
|
|
|
wipInfo.file_sink->start_recording(d_output_folder + "/" + prepareBasebandFileName(satdump::getTime(), get_samplerate() / decimation, freq), get_samplerate() / decimation);
|
2024-01-21 22:58:56 +01:00
|
|
|
|
|
|
|
|
splitter->set_vfo_enabled(id, true);
|
|
|
|
|
|
|
|
|
|
if (fft)
|
|
|
|
|
fft_plot->vfo_freqs.push_back({name, freq});
|
|
|
|
|
|
|
|
|
|
vfo_list.push_back(wipInfo);
|
|
|
|
|
}
|
|
|
|
|
catch (std::exception &e)
|
|
|
|
|
{
|
|
|
|
|
logger->error("Error adding VFO : %s", e.what());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vfos_mtx.unlock();
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-21 17:12:11 +01:00
|
|
|
void AutoTrackApp::del_vfo(std::string id)
|
|
|
|
|
{
|
|
|
|
|
vfos_mtx.lock();
|
2025-05-31 20:26:47 +02:00
|
|
|
auto it = std::find_if(vfo_list.begin(), vfo_list.end(), [&id](VFOInfo &c) { return c.id == id; });
|
2024-01-21 17:12:11 +01:00
|
|
|
if (it != vfo_list.end())
|
|
|
|
|
{
|
|
|
|
|
if (fft)
|
|
|
|
|
{
|
|
|
|
|
std::string name = it->name;
|
2025-05-31 20:26:47 +02:00
|
|
|
auto it2 = std::find_if(fft_plot->vfo_freqs.begin(), fft_plot->vfo_freqs.end(), [&name](auto &c) { return c.first == name; });
|
2024-01-21 17:12:11 +01:00
|
|
|
if (it2 != fft_plot->vfo_freqs.end())
|
|
|
|
|
fft_plot->vfo_freqs.erase(it2);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-21 22:58:56 +01:00
|
|
|
if (it->file_sink)
|
|
|
|
|
it->file_sink->stop_recording();
|
|
|
|
|
|
2024-01-21 17:12:11 +01:00
|
|
|
splitter->set_vfo_enabled(it->id, false);
|
2024-01-21 22:58:56 +01:00
|
|
|
|
2025-06-11 17:38:30 +02:00
|
|
|
if (it->selected_pipeline.id != "")
|
2024-01-21 22:58:56 +01:00
|
|
|
it->live_pipeline->stop();
|
|
|
|
|
|
|
|
|
|
if (it->file_sink)
|
|
|
|
|
{
|
|
|
|
|
it->file_sink->stop();
|
|
|
|
|
if (it->decim_ptr)
|
|
|
|
|
it->decim_ptr->stop();
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-21 17:12:11 +01:00
|
|
|
splitter->del_vfo(it->id);
|
|
|
|
|
|
2025-06-11 17:38:30 +02:00
|
|
|
if (it->selected_pipeline.id != "")
|
2024-01-21 17:12:11 +01:00
|
|
|
{
|
2025-05-31 20:26:47 +02:00
|
|
|
if (d_settings.contains("finish_processing") && d_settings["finish_processing"].get<bool>() && it->live_pipeline->getOutputFile().size() > 0)
|
2024-01-21 17:12:11 +01:00
|
|
|
{
|
2025-05-31 20:26:47 +02:00
|
|
|
std::string input_file = it->live_pipeline->getOutputFile();
|
|
|
|
|
satdump::pipeline::Pipeline selected_pipeline_ = it->selected_pipeline;
|
2024-01-21 22:58:56 +01:00
|
|
|
std::string pipeline_output_dir_ = it->output_dir;
|
|
|
|
|
nlohmann::json pipeline_params_ = it->pipeline_params;
|
2024-07-21 14:58:03 -04:00
|
|
|
auto fun = [selected_pipeline_, pipeline_output_dir_, input_file, pipeline_params_](int)
|
2024-01-21 22:58:56 +01:00
|
|
|
{
|
2025-05-31 20:26:47 +02:00
|
|
|
satdump::pipeline::Pipeline pipeline = selected_pipeline_;
|
|
|
|
|
int start_level = pipeline.live_cfg.normal_live[pipeline.live_cfg.normal_live.size() - 1];
|
|
|
|
|
std::string input_level = pipeline.steps[start_level].level;
|
2024-01-21 22:58:56 +01:00
|
|
|
pipeline.run(input_file, pipeline_output_dir_, pipeline_params_, input_level);
|
|
|
|
|
};
|
|
|
|
|
main_thread_pool.push(fun);
|
|
|
|
|
}
|
2024-01-21 17:12:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vfo_list.erase(it);
|
|
|
|
|
}
|
|
|
|
|
if (vfo_list.size() == 0)
|
|
|
|
|
if (fft)
|
|
|
|
|
fft_plot->vfo_freqs.clear();
|
|
|
|
|
vfos_mtx.unlock();
|
|
|
|
|
}
|