From 49bb0961268c48d189d6ed45f09787d533613d11 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Sun, 21 Jul 2024 13:32:11 +0200 Subject: [PATCH] [Sat planner] First version of sat planner added --- application/controllers/Satellite.php | 99 ++ application/views/interface_assets/header.php | 4 +- application/views/satellite/pass.php | 649 ++++++++++ application/views/satellite/passtable.php | 47 + assets/js/sections/satpasses.js | 23 + predict/Predict.php | 877 ++++++++++++++ predict/Predict/DeepArg.php | 35 + predict/Predict/DeepStatic.php | 83 ++ predict/Predict/Exception.php | 5 + predict/Predict/Geodetic.php | 13 + predict/Predict/Math.php | 196 +++ predict/Predict/ObsSet.php | 12 + predict/Predict/Pass.php | 27 + predict/Predict/PassDetail.php | 38 + predict/Predict/QTH.php | 20 + predict/Predict/SGPObs.php | 156 +++ predict/Predict/SGPSDP.php | 1061 +++++++++++++++++ predict/Predict/SGSDPStatic.php | 39 + predict/Predict/Sat.php | 324 +++++ predict/Predict/Solar.php | 115 ++ predict/Predict/TLE.php | 232 ++++ predict/Predict/Time.php | 222 ++++ predict/Predict/Vector.php | 13 + predict/README.md | 35 + predict/composer.json | 19 + predict/generatePackage.php | 63 + predict/package.xml | 182 +++ 27 files changed, 4588 insertions(+), 1 deletion(-) create mode 100644 application/views/satellite/pass.php create mode 100644 application/views/satellite/passtable.php create mode 100644 assets/js/sections/satpasses.js create mode 100644 predict/Predict.php create mode 100644 predict/Predict/DeepArg.php create mode 100644 predict/Predict/DeepStatic.php create mode 100644 predict/Predict/Exception.php create mode 100644 predict/Predict/Geodetic.php create mode 100644 predict/Predict/Math.php create mode 100644 predict/Predict/ObsSet.php create mode 100644 predict/Predict/Pass.php create mode 100644 predict/Predict/PassDetail.php create mode 100644 predict/Predict/QTH.php create mode 100644 predict/Predict/SGPObs.php create mode 100644 predict/Predict/SGPSDP.php create mode 100644 predict/Predict/SGSDPStatic.php create mode 100644 predict/Predict/Sat.php create mode 100644 predict/Predict/Solar.php create mode 100644 predict/Predict/TLE.php create mode 100644 predict/Predict/Time.php create mode 100644 predict/Predict/Vector.php create mode 100644 predict/README.md create mode 100644 predict/composer.json create mode 100644 predict/generatePackage.php create mode 100644 predict/package.xml diff --git a/application/controllers/Satellite.php b/application/controllers/Satellite.php index 9679c1ce8..7ebfe720f 100644 --- a/application/controllers/Satellite.php +++ b/application/controllers/Satellite.php @@ -173,4 +173,103 @@ class Satellite extends CI_Controller { echo json_encode($satellite_data, JSON_FORCE_OBJECT); } + public function pass() { + $this->load->model('satellite_model'); + $this->load->model('stations'); + $active_station_id = $this->stations->find_active(); + $pageData['activegrid'] = $this->stations->gridsquare_from_station($active_station_id); + + $pageData['satellites'] = $this->satellite_model->get_all_satellites_with_tle(); + + $footerData = []; + $footerData['scripts'] = [ + 'assets/js/sections/satpasses.js?' . filemtime(realpath(__DIR__ . "/../../assets/js/sections/satpasses.js")), + ]; + + // Render Page + $pageData['page_title'] = "Satellite pass"; + $this->load->view('interface_assets/header', $pageData); + $this->load->view('satellite/pass'); + $this->load->view('interface_assets/footer', $footerData); + } + + public function searchpasses() { + try { + $result = $this->get_tle_for_predict(); + $this->calcpass($result); + } + catch (Exception $e) { + header("Content-type: application/json"); + echo json_encode(['ok' => 'Error', 'message' => $e->getMessage() . $e->getCode()]); + } + } + + public function get_tle_for_predict() { + $sat = $this->security->xss_clean($this->input->post('sat')); + $this->load->model('satellite_model'); + return $this->satellite_model->get_tle($sat); + } + + function calcpass($sat_tle) { + require_once realpath(__DIR__ . "/../../predict/Predict.php"); + require_once realpath(__DIR__ . "/../../predict/Predict/Sat.php"); + require_once realpath(__DIR__ . "/../../predict/Predict/QTH.php"); + require_once realpath(__DIR__ . "/../../predict/Predict/Time.php"); + require_once realpath(__DIR__ . "/../../predict/Predict/TLE.php"); + + // Track execution time of this script + $start = microtime(true); + + // The observer or groundstation is called QTH in ham radio terms + $predict = new Predict(); + $qth = new Predict_QTH(); + $qth->alt = $this->security->xss_clean($this->input->post('altitude')); // Altitude in meters + + $strQRA = $this->security->xss_clean($this->input->post('yourgrid')); + + if ((strlen($strQRA) % 2 == 0) && (strlen($strQRA) <= 10)) { // Check if QRA is EVEN (the % 2 does that) and smaller/equal 8 + $strQRA = strtoupper($strQRA); + if (strlen($strQRA) == 4) $strQRA .= "LL"; // Only 4 Chars? Fill with center "LL" as only A-R allowed + if (strlen($strQRA) == 6) $strQRA .= "55"; // Only 6 Chars? Fill with center "55" + if (strlen($strQRA) == 8) $strQRA .= "LL"; // Only 8 Chars? Fill with center "LL" as only A-R allowed + + if (!preg_match('/^[A-R]{2}[0-9]{2}[A-X]{2}[0-9]{2}[A-X]{2}$/', $strQRA)) { + return false; + } + } + + if(!$this->load->is_loaded('Qra')) { + $this->load->library('Qra'); + } + $homecoordinates = $this->qra->qra2latlong($this->security->xss_clean($this->input->post('yourgrid'))); + + $qth->lat = $homecoordinates[0]; + $qth->lon = $homecoordinates[1]; + + $temp = preg_split('/\n/', $sat_tle->tle); + + $tle = new Predict_TLE($sat_tle->satellite, $temp[0], $temp[1]); // Instantiate it + $sat = new Predict_Sat($tle); // Load up the satellite data + + $now = Predict_Time::get_current_daynum(); // get the current time as Julian Date (daynum) + + // You can modify some preferences in Predict(), the defaults are below + // + $predict->minEle = $this->security->xss_clean($this->input->post('minelevation')); // Minimum elevation for a pass + // $predict->timeRes = 10; // Pass details: time resolution in seconds + // $predict->numEntries = 20; // Pass details: number of entries per pass + // $predict->threshold = -6; // Twilight threshold (sun must be at this lat or lower) + + // Get the passes and filter visible only, takes about 4 seconds for 10 days + $results = $predict->get_passes($sat, $qth, $now, 10); + $filtered = $predict->filterVisiblePasses($results); + + $zone = $this->security->xss_clean($this->input->post('timezone')); + $format = 'm-d-Y H:i:s'; // Time format from PHP's date() function + + $data['filtered'] = $filtered; + $data['zone'] = $zone; + $data['format'] = $format; + $this->load->view('satellite/passtable', $data); + } } diff --git a/application/views/interface_assets/header.php b/application/views/interface_assets/header.php index faafb4446..c2ee0d12f 100644 --- a/application/views/interface_assets/header.php +++ b/application/views/interface_assets/header.php @@ -271,6 +271,8 @@
= __("Satellite Flightpath"); ?> + = __("Satellite Pass"); ?> + = __("Backup"); ?> = __("Update Country Files"); ?> @@ -404,7 +406,7 @@ if (!($this->config->item('disable_oqrs') ?? false)) { $oqrs_requests = $this->oqrs_model->oqrs_requests($location_list); ?> -