satdump/src-interface/recorder/tracking/tracking_widget.cpp

132 lines
4.5 KiB
C++
Raw Normal View History

2023-07-17 23:11:13 +02:00
#include "tracking_widget.h"
#include "common/tracking/tle.h"
#include "imgui/imgui.h"
2023-09-06 22:28:55 -04:00
#include "logger.h"
2023-07-17 23:11:13 +02:00
#include "core/module.h"
#include "core/config.h"
2023-07-18 12:27:58 +02:00
#include "main_ui.h"
2023-07-17 23:11:13 +02:00
2023-07-20 19:31:46 +02:00
#include "rotcl_handler.h"
2023-07-17 23:11:13 +02:00
namespace satdump
{
TrackingWidget::TrackingWidget()
{
try
{
qth_lon = config::main_cfg["satdump_general"]["qth_lon"]["value"].get<double>();
qth_lat = config::main_cfg["satdump_general"]["qth_lat"]["value"].get<double>();
qth_alt = config::main_cfg["satdump_general"]["qth_alt"]["value"].get<double>();
}
catch (std::exception &e)
{
logger->error("Could not get QTH lon/lat! %s", e.what());
}
logger->trace("Using QTH %f %f Alt %f", qth_lon, qth_lat, qth_alt);
2023-07-18 18:12:04 +02:00
if (general_tle_registry.size() > 0)
2023-07-18 16:59:32 +02:00
has_tle = true;
2023-07-17 23:11:13 +02:00
for (auto &tle : general_tle_registry)
satoptions.push_back(tle.name);
2023-07-17 23:11:13 +02:00
observer_station = predict_create_observer("Main", qth_lat * DEG_TO_RAD, qth_lon * DEG_TO_RAD, qth_alt);
2023-07-18 21:31:13 +02:00
// Updates on registry updates
eventBus->register_handler<TLEsUpdatedEvent>([this](TLEsUpdatedEvent)
{
tle_update_mutex.lock();
if (general_tle_registry.size() > 0)
has_tle = true;
satoptions.clear();
2023-07-18 21:31:13 +02:00
for (auto &tle : general_tle_registry)
satoptions.push_back(tle.name);
2023-07-18 21:31:13 +02:00
tle_update_mutex.unlock(); });
2023-07-20 01:02:57 +02:00
rotator_handler = std::make_shared<RotctlHandler>();
2023-07-27 20:24:55 +02:00
// Restore settings
loadConfig();
// Start threads
2023-07-20 01:02:57 +02:00
backend_thread = std::thread(&TrackingWidget::backend_run, this);
2023-07-22 21:23:38 +02:00
rotatorth_thread = std::thread(&TrackingWidget::rotatorth_run, this);
// Attempt to apply provided CLI settings
2023-11-09 12:04:09 +01:00
if (satdump::config::main_cfg.contains("cli"))
{
2023-11-09 12:04:09 +01:00
auto &cli_settings = satdump::config::main_cfg["cli"];
2023-11-09 12:04:09 +01:00
if (cli_settings.contains("engage_autotrack") && cli_settings["engage_autotrack"].get<bool>())
{
2023-11-09 12:04:09 +01:00
upcoming_satellite_passes_mtx.lock();
autotrack_engaged = true;
updateAutotrackPasses();
if (upcoming_satellite_passes_sel.size() > 0)
{
for (int i = 0; i < (int)general_tle_registry.size(); i++)
if (general_tle_registry[i].norad == upcoming_satellite_passes_sel[0].norad)
current_satellite = i;
horizons_mode = false;
backend_needs_update = true;
autotrack_pass_has_started = false;
}
else
{
autotrack_engaged = false;
}
upcoming_satellite_passes_mtx.unlock();
}
}
2023-07-17 23:11:13 +02:00
}
TrackingWidget::~TrackingWidget()
{
predict_destroy_observer(observer_station);
2023-07-20 01:02:57 +02:00
backend_should_run = false;
if (backend_thread.joinable())
backend_thread.join();
2023-07-22 21:23:38 +02:00
rotatorth_should_run = false;
if (rotatorth_thread.joinable())
rotatorth_thread.join();
2023-07-17 23:11:13 +02:00
}
void TrackingWidget::render()
{
2023-07-18 16:59:32 +02:00
if (!has_tle)
return;
2023-07-25 21:56:47 +02:00
renderPolarPlot();
2023-08-02 23:32:14 +02:00
ImGui::Separator();
2023-07-25 21:56:47 +02:00
renderSelectionMenu();
2023-07-17 23:11:13 +02:00
ImGui::Spacing();
if (ImGui::CollapsingHeader("Object Information"))
2023-08-02 23:32:14 +02:00
renderObjectStatus();
if (ImGui::CollapsingHeader("Rotator Configuration"))
2023-08-02 23:32:14 +02:00
renderRotatorStatus();
2023-07-20 16:36:16 +02:00
ImGui::Spacing();
2023-08-02 23:32:14 +02:00
ImGui::Separator();
2023-07-20 15:55:38 +02:00
ImGui::Spacing();
2023-08-02 23:32:14 +02:00
if (ImGui::Button("Schedule and Config"))
config_window_was_asked = show_window_config = true;
2023-07-20 15:55:38 +02:00
2023-07-25 21:56:47 +02:00
renderConfigWindow();
2023-07-17 23:11:13 +02:00
}
double TrackingWidget::getTime()
{
auto time = std::chrono::system_clock::now();
auto since_epoch = time.time_since_epoch();
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(since_epoch);
return millis.count() / 1e3;
}
}