2023-07-17 23:11:13 +02:00
|
|
|
#include "tracking_widget.h"
|
2025-06-08 18:06:12 +02:00
|
|
|
#include "common/imgui_utils.h"
|
|
|
|
|
#include "common/tracking/rotator/rotcl_handler.h"
|
|
|
|
|
#include "core/config.h"
|
|
|
|
|
#include "core/style.h"
|
2023-07-17 23:11:13 +02:00
|
|
|
#include "imgui/imgui.h"
|
2023-09-06 22:28:55 -04:00
|
|
|
#include "logger.h"
|
2023-07-18 12:27:58 +02:00
|
|
|
#include "main_ui.h"
|
2025-05-26 19:21:10 +01:00
|
|
|
#include "utils/time.h"
|
2023-07-20 19:31:46 +02:00
|
|
|
|
2023-07-17 23:11:13 +02:00
|
|
|
namespace satdump
|
|
|
|
|
{
|
|
|
|
|
TrackingWidget::TrackingWidget()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2025-06-08 18:06:12 +02:00
|
|
|
qth_lon = satdump_cfg.getValueFromSatDumpGeneral<double>("qth_lon");
|
|
|
|
|
qth_lat = satdump_cfg.getValueFromSatDumpGeneral<double>("qth_lat");
|
|
|
|
|
qth_alt = satdump_cfg.getValueFromSatDumpGeneral<double>("qth_alt");
|
2023-07-17 23:11:13 +02:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
2024-08-29 19:27:27 +02:00
|
|
|
rotator_options = rotator::getRotatorHandlerOptions();
|
|
|
|
|
for (auto &st : rotator_options)
|
|
|
|
|
rotator_options_str += st.name + '\0';
|
|
|
|
|
|
|
|
|
|
rotator_handler = rotator_options[selected_rotator_handler].construct();
|
2023-12-02 19:51:09 +01:00
|
|
|
|
|
|
|
|
if (rotator_handler)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-01-14 17:16:33 +01:00
|
|
|
nlohmann::json cfg = db->get_user_json("recorder_tracking");
|
|
|
|
|
rotator_handler->set_settings(cfg["rotator_config"][rotator_handler->get_id()]);
|
2023-12-02 19:51:09 +01:00
|
|
|
}
|
2024-03-12 23:15:18 -04:00
|
|
|
catch (std::exception &)
|
2023-12-02 19:51:09 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-23 00:50:32 +02:00
|
|
|
|
2023-12-10 19:53:50 +01:00
|
|
|
// Init Obj Tracker
|
2023-12-10 13:03:59 +01:00
|
|
|
object_tracker.setQTH(qth_lon, qth_lat, qth_alt);
|
|
|
|
|
object_tracker.setRotator(rotator_handler);
|
2026-01-14 17:16:33 +01:00
|
|
|
object_tracker.setObject(object_tracker.TRACKING_SATELLITE, 57166); // Phoenix replaced King for default sat
|
2025-06-08 18:06:12 +02:00
|
|
|
object_tracker.rotator_target_pos_updated_callback = [this](double az, double el) { sat_finder.setTarget(az, el); };
|
2024-04-14 14:10:42 +02:00
|
|
|
|
|
|
|
|
// Init Sat finder
|
|
|
|
|
sat_finder.setQTH(qth_lon, qth_lat, qth_alt);
|
2023-11-08 15:09:07 +01:00
|
|
|
|
2023-12-10 19:53:50 +01:00
|
|
|
// Init scheduler
|
2024-01-22 23:03:51 +01:00
|
|
|
auto_scheduler.eng_callback = [this](AutoTrackCfg, SatellitePass, TrackedObject obj)
|
2023-12-10 19:53:50 +01:00
|
|
|
{
|
|
|
|
|
object_tracker.setObject(object_tracker.TRACKING_SATELLITE, obj.norad);
|
|
|
|
|
saveConfig();
|
|
|
|
|
};
|
2024-01-17 14:55:30 +01:00
|
|
|
auto_scheduler.aos_callback = [this](AutoTrackCfg autotrack_cfg, SatellitePass pass, TrackedObject obj)
|
2023-12-10 19:53:50 +01:00
|
|
|
{
|
2024-01-17 14:55:30 +01:00
|
|
|
this->aos_callback(autotrack_cfg, pass, obj);
|
2023-12-10 19:53:50 +01:00
|
|
|
object_tracker.setObject(object_tracker.TRACKING_SATELLITE, obj.norad);
|
|
|
|
|
};
|
2025-06-08 18:06:12 +02:00
|
|
|
auto_scheduler.los_callback = [this](AutoTrackCfg autotrack_cfg, SatellitePass pass, TrackedObject obj) { this->los_callback(autotrack_cfg, pass, obj); };
|
2023-12-10 19:53:50 +01:00
|
|
|
|
|
|
|
|
auto_scheduler.setQTH(qth_lon, qth_lat, qth_alt);
|
|
|
|
|
|
|
|
|
|
// Restore config
|
|
|
|
|
loadConfig();
|
|
|
|
|
|
|
|
|
|
// Start scheduler
|
|
|
|
|
auto_scheduler.start();
|
|
|
|
|
|
2023-11-08 15:09:07 +01:00
|
|
|
// Attempt to apply provided CLI settings
|
2025-06-08 16:57:37 +02:00
|
|
|
if (satdump::satdump_cfg.main_cfg.contains("cli"))
|
2023-11-08 15:09:07 +01:00
|
|
|
{
|
2025-06-08 16:57:37 +02:00
|
|
|
auto &cli_settings = satdump::satdump_cfg.main_cfg["cli"];
|
2023-11-08 15:09:07 +01:00
|
|
|
|
2023-11-09 12:04:09 +01:00
|
|
|
if (cli_settings.contains("engage_autotrack") && cli_settings["engage_autotrack"].get<bool>())
|
2023-11-08 15:09:07 +01:00
|
|
|
{
|
2023-12-10 19:53:50 +01:00
|
|
|
auto_scheduler.setEngaged(true, getTime());
|
2023-11-08 15:09:07 +01:00
|
|
|
}
|
|
|
|
|
}
|
2023-07-17 23:11:13 +02:00
|
|
|
}
|
|
|
|
|
|
2025-06-08 18:06:12 +02:00
|
|
|
TrackingWidget::~TrackingWidget() { saveConfig(); }
|
2023-07-17 23:11:13 +02:00
|
|
|
|
|
|
|
|
void TrackingWidget::render()
|
|
|
|
|
{
|
2024-01-19 15:54:21 -05:00
|
|
|
object_tracker.renderPolarPlot();
|
2023-07-18 16:59:32 +02:00
|
|
|
|
2023-08-02 23:32:14 +02:00
|
|
|
ImGui::Separator();
|
2023-12-10 13:03:59 +01:00
|
|
|
|
|
|
|
|
object_tracker.renderSelectionMenu();
|
|
|
|
|
|
2023-07-17 23:11:13 +02:00
|
|
|
ImGui::Spacing();
|
2023-12-10 13:03:59 +01:00
|
|
|
|
2023-08-05 17:12:01 +02:00
|
|
|
if (ImGui::CollapsingHeader("Object Information"))
|
2023-12-10 13:03:59 +01:00
|
|
|
object_tracker.renderObjectStatus();
|
|
|
|
|
|
2023-08-05 17:12:01 +02:00
|
|
|
if (ImGui::CollapsingHeader("Rotator Configuration"))
|
2023-12-10 13:03:59 +01:00
|
|
|
{
|
|
|
|
|
object_tracker.renderRotatorStatus();
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
|
|
if (rotator_handler->is_connected())
|
|
|
|
|
style::beginDisabled();
|
2024-07-29 11:40:19 -04:00
|
|
|
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
|
2024-08-29 19:27:27 +02:00
|
|
|
if (ImGui::Combo("Type##rotatortype", &selected_rotator_handler, rotator_options_str.c_str()))
|
2023-12-10 13:03:59 +01:00
|
|
|
{
|
2024-08-29 19:27:27 +02:00
|
|
|
rotator_handler = rotator_options[selected_rotator_handler].construct();
|
|
|
|
|
object_tracker.setRotator(rotator_handler);
|
2023-12-10 13:03:59 +01:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-01-14 17:16:33 +01:00
|
|
|
nlohmann::json cfg = db->get_user_json("recorder_tracking");
|
|
|
|
|
rotator_handler->set_settings(cfg["rotator_config"][rotator_handler->get_id()]);
|
2023-12-10 13:03:59 +01:00
|
|
|
}
|
2024-03-12 23:15:18 -04:00
|
|
|
catch (std::exception &)
|
2023-12-10 13:03:59 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (rotator_handler->is_connected())
|
|
|
|
|
style::endDisabled();
|
|
|
|
|
|
|
|
|
|
rotator_handler->render();
|
|
|
|
|
}
|
|
|
|
|
|
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-12-10 13:03:59 +01:00
|
|
|
|
2024-03-12 23:15:18 -04:00
|
|
|
float width_available = ImGui::GetContentRegionAvail().x;
|
|
|
|
|
std::string is_engaged = auto_scheduler.getEngaged() ? "YES" : "NO";
|
|
|
|
|
float centered_pos = width_available / 2.0f - ImGui::CalcTextSize(std::string("Autotrack Engaged: " + is_engaged).c_str()).x / 2.0f;
|
2024-08-10 14:57:35 +02:00
|
|
|
if (centered_pos > 0)
|
2024-03-12 23:15:18 -04:00
|
|
|
ImGui::SetCursorPosX(centered_pos);
|
|
|
|
|
ImGui::TextUnformatted("Autotrack Engaged:");
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::TextColored(auto_scheduler.getEngaged() ? style::theme.green : style::theme.red, "%s", is_engaged.c_str());
|
|
|
|
|
if (ImGui::Button("Schedule and Config", ImVec2(width_available, 0.0f)))
|
2023-08-05 17:12:01 +02:00
|
|
|
config_window_was_asked = show_window_config = true;
|
2024-04-14 14:10:42 +02:00
|
|
|
if (ImGui::Button("Satellite finder", ImVec2(width_available, 0.0f)))
|
|
|
|
|
show_satellite_finder_window = satellite_finder_was_asked = true;
|
2024-03-12 23:15:18 -04:00
|
|
|
ImGui::Spacing();
|
2023-12-10 13:03:59 +01:00
|
|
|
renderConfig();
|
2024-04-14 14:10:42 +02:00
|
|
|
renderSatfinder();
|
2023-07-17 23:11:13 +02:00
|
|
|
}
|
|
|
|
|
|
2023-12-10 13:03:59 +01:00
|
|
|
void TrackingWidget::renderConfig()
|
2023-07-17 23:11:13 +02:00
|
|
|
{
|
2023-12-10 13:03:59 +01:00
|
|
|
if (show_window_config)
|
|
|
|
|
{
|
2024-07-21 15:46:18 -04:00
|
|
|
ImGui::SetNextWindowSizeConstraints(ImVec2(800 * ui_scale, 300 * ui_scale), ImVec2(INFINITY, INFINITY));
|
2023-12-10 13:03:59 +01:00
|
|
|
ImGui::Begin("Tracking Configuration", &show_window_config);
|
2024-07-21 15:46:18 -04:00
|
|
|
ImGui::SetWindowSize(ImVec2(800 * ui_scale, 550 * ui_scale), ImGuiCond_FirstUseEver);
|
2023-12-10 13:03:59 +01:00
|
|
|
|
|
|
|
|
if (ImGui::BeginTabBar("##trackingtabbar"))
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::BeginTabItem("Scheduling"))
|
|
|
|
|
{
|
2023-12-10 19:53:50 +01:00
|
|
|
ImGui::BeginChild("##trackingbarschedule", ImVec2(0, 0), false, ImGuiWindowFlags_NoResize);
|
2024-01-19 15:54:21 -05:00
|
|
|
auto_scheduler.renderAutotrackConfig(getTime());
|
2023-12-10 19:53:50 +01:00
|
|
|
ImGui::EndChild();
|
2023-12-10 13:03:59 +01:00
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::BeginTabItem("Rotator Config"))
|
|
|
|
|
{
|
2023-12-10 19:53:50 +01:00
|
|
|
object_tracker.renderRotatorConfig();
|
2023-12-10 13:03:59 +01:00
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
2024-10-06 10:03:15 -04:00
|
|
|
if (ImGui::BeginTabItem("Export/Import"))
|
2024-09-30 14:42:56 -04:00
|
|
|
{
|
2024-10-06 14:08:04 -04:00
|
|
|
ImGui::BeginChild("##trackingimportexport", ImVec2(0, 0), false, ImGuiWindowFlags_NoResize);
|
2024-10-06 10:03:15 -04:00
|
|
|
if (config_import_export.draw_export())
|
|
|
|
|
config_import_export.do_export(auto_scheduler, object_tracker, rotator_handler);
|
2024-10-06 14:08:04 -04:00
|
|
|
ImGui::Spacing();
|
|
|
|
|
bool disable_import = auto_scheduler.getEngaged();
|
|
|
|
|
if (disable_import)
|
|
|
|
|
style::beginDisabled();
|
2024-10-06 10:03:15 -04:00
|
|
|
if (config_import_export.draw_import())
|
|
|
|
|
config_import_export.do_import(auto_scheduler, object_tracker, rotator_handler);
|
2024-10-06 14:08:04 -04:00
|
|
|
if (disable_import)
|
|
|
|
|
style::endDisabled();
|
|
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
2024-09-30 14:42:56 -04:00
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
2023-12-10 13:03:59 +01:00
|
|
|
ImGui::EndTabBar();
|
|
|
|
|
}
|
2023-07-17 23:11:13 +02:00
|
|
|
|
2023-12-10 13:03:59 +01:00
|
|
|
if (config_window_was_asked)
|
|
|
|
|
ImGuiUtils_BringCurrentWindowToFront();
|
|
|
|
|
config_window_was_asked = false;
|
|
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-14 14:10:42 +02:00
|
|
|
|
2025-06-08 18:06:12 +02:00
|
|
|
void TrackingWidget::renderSatfinder()
|
|
|
|
|
{
|
|
|
|
|
if (show_satellite_finder_window)
|
|
|
|
|
{
|
2024-04-14 14:10:42 +02:00
|
|
|
ImGui::Begin("Satellite finder", &show_satellite_finder_window);
|
|
|
|
|
ImGui::SetWindowSize(ImVec2(800, 550), ImGuiCond_FirstUseEver);
|
|
|
|
|
if (satellite_finder_was_asked)
|
|
|
|
|
ImGuiUtils_BringCurrentWindowToFront();
|
|
|
|
|
satellite_finder_was_asked = false;
|
|
|
|
|
|
|
|
|
|
sat_finder.render();
|
|
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-08 18:06:12 +02:00
|
|
|
} // namespace satdump
|