From 03ace46bb752efe140b3757e9994fbddd6066c7c Mon Sep 17 00:00:00 2001 From: Aang23 Date: Fri, 21 Jul 2023 15:46:28 +0200 Subject: [PATCH] More tracking work, pull all Horizons objects --- src-interface/recorder/tracking_widget.cpp | 55 +++++++++++++++--- src-interface/recorder/tracking_widget.h | 9 ++- .../recorder/tracking_widget_backend.cpp | 57 ++++++++++++++++++- 3 files changed, 109 insertions(+), 12 deletions(-) diff --git a/src-interface/recorder/tracking_widget.cpp b/src-interface/recorder/tracking_widget.cpp index 2bc2d96cc..923d813d8 100644 --- a/src-interface/recorder/tracking_widget.cpp +++ b/src-interface/recorder/tracking_widget.cpp @@ -28,13 +28,10 @@ namespace satdump has_tle = true; for (auto &tle : general_tle_registry) - satoptionstr += tle.name + '\0'; + satoptions.push_back(tle.name); observer_station = predict_create_observer("Main", qth_lat * DEG_TO_RAD, qth_lon * DEG_TO_RAD, qth_alt); - for (auto &hid : horizons_ids) - horizonsoptionstr += hid + '\0'; - // Updates on registry updates eventBus->register_handler([this](TLEsUpdatedEvent) { @@ -43,9 +40,9 @@ namespace satdump if (general_tle_registry.size() > 0) has_tle = true; - satoptionstr = ""; + satoptions.clear(); for (auto &tle : general_tle_registry) - satoptionstr += tle.name + '\0'; + satoptions.push_back(tle.name); tle_update_mutex.unlock(); }); @@ -176,9 +173,49 @@ namespace satdump ImGui::SetNextItemWidth(ImGui::GetWindowContentRegionWidth()); if (horizons_mode) - update_global = update_global || ImGui::Combo("###horizonsselectcombo", ¤t_horizons, horizonsoptionstr.c_str()); + { + if (ImGui::BeginCombo("###horizonsselectcombo", horizonsoptions[current_horizons].second.c_str())) + { + ImGui::InputTextWithHint("##horizonssatellitetracking", u8"\uf422 Search", &horizonssearchstr); + for (int i = 0; i < horizonsoptions.size(); i++) + { + bool show = true; + if (horizonssearchstr.size() != 0) + show = isStringPresent(horizonsoptions[i].second, horizonssearchstr); + if (show) + { + if (ImGui::Selectable(horizonsoptions[i].second.c_str(), i == current_horizons)) + { + current_horizons = i; + update_global = true; + } + } + } + ImGui::EndCombo(); + } + } else - update_global = update_global || ImGui::Combo("###satelliteselectcombo", ¤t_satellite, satoptionstr.c_str()); + { + if (ImGui::BeginCombo("###satelliteselectcombo", satoptions[current_satellite].c_str())) + { + ImGui::InputTextWithHint("##searchsatellitetracking", u8"\uf422 Search", &satsearchstr); + for (int i = 0; i < satoptions.size(); i++) + { + bool show = true; + if (satsearchstr.size() != 0) + show = isStringPresent(satoptions[i], satsearchstr); + if (show) + { + if (ImGui::Selectable(satoptions[i].c_str(), i == current_satellite)) + { + current_satellite = i; + update_global = true; + } + } + } + ImGui::EndCombo(); + } + } if (ImGui::BeginTable("##trackingradiotable", 2, NULL)) { @@ -192,6 +229,8 @@ namespace satdump ImGui::TableSetColumnIndex(1); if (ImGui::RadioButton("Horizons", horizons_mode)) { + if (horizonsoptions.size() == 1) + horizonsoptions = pullHorizonsList(); horizons_mode = true; update_global = true; } diff --git a/src-interface/recorder/tracking_widget.h b/src-interface/recorder/tracking_widget.h index e09412416..09f5c1f30 100644 --- a/src-interface/recorder/tracking_widget.h +++ b/src-interface/recorder/tracking_widget.h @@ -27,8 +27,9 @@ namespace satdump predict_observer_t *observer_station; predict_observation observation_pos; - std::string satoptionstr; + std::vector satoptions; int current_satellite = 0; + std::string satsearchstr; double getTime(); @@ -40,10 +41,12 @@ namespace satdump float az, el; }; - std::vector horizons_ids = {"STEREO-A", "STEREO-B", "JUICE", "JWST", "SOHO", "Sun", "CH-3", "New Horizons"}; - std::string horizonsoptionstr; + std::vector> horizonsoptions = {{-234, "STEREO-A"}}; int current_horizons = 0; std::vector horizons_data; + std::string horizonssearchstr; + + std::vector> pullHorizonsList(); void loadHorizons(); diff --git a/src-interface/recorder/tracking_widget_backend.cpp b/src-interface/recorder/tracking_widget_backend.cpp index 9d931b9b6..a762401a7 100644 --- a/src-interface/recorder/tracking_widget_backend.cpp +++ b/src-interface/recorder/tracking_widget_backend.cpp @@ -187,7 +187,11 @@ namespace satdump else { if (predict_is_geosynchronous(satellite_object)) + { + next_aos_time = 0; + next_los_time = std::numeric_limits::max(); return; + } upcoming_passes_mtx.lock(); @@ -237,7 +241,7 @@ namespace satdump std::string cmd = (std::string) "https://ssd.jpl.nasa.gov/api/horizons.api?format=text" + "&OBJ_DATA=NO" + "&MAKE_EPHEM=YES" + - "&COMMAND=" + horizons_ids[current_horizons] + + "&COMMAND=" + std::to_string(horizonsoptions[current_horizons].first) + "&CAL_FORMAT=JD" + "&EPHEM_TYPE=OBSERVER" + "&CENTER='coord@399'" + @@ -308,6 +312,56 @@ namespace satdump logger->trace("Done pulling Horizons data..."); } + std::vector> TrackingWidget::pullHorizonsList() + { + std::vector> vv; + + logger->trace("Pulling object list from Horizons..."); + + std::string url = "https://ssd.jpl.nasa.gov/api/horizons.api?format=text&COMMAND='*'"; + std::string req_result; + perform_http_request(url, req_result); + + std::istringstream req_results(req_result); + std::string line; + + bool got_start = false; + while (getline(req_results, line)) + { + if (line.find(" ------- ---------------------------------- ----------- ------------------- ") != std::string::npos) + { + got_start = true; + continue; + } + + if (!got_start) + continue; + + try + { + std::string numid = line.substr(0, 9); + std::string name = line.substr(11, 35); + std::string desig = line.substr(45, 13); + std::string iauo = line.substr(59, 21); + + int id = std::stoi(numid); + + bool is_valid = false; + for (auto &c : name) + if (c != ' ') + is_valid = true; + + if (is_valid && name.find("simulation") == std::string::npos) + vv.push_back({id, name}); + } + catch (std::exception &e) + { + } + } + + return vv; + } + void TrackingWidget::updateRotator() { // logger->info("Rot update!"); @@ -338,4 +392,5 @@ namespace satdump logger->error("Error setting rotator position %f %f!", current_req_rotator_az, current_req_rotator_el); } } + }