diff --git a/station/__pycache__/config.cpython-311.pyc b/station/__pycache__/config.cpython-311.pyc index b9c79a7..0ecb19d 100644 Binary files a/station/__pycache__/config.cpython-311.pyc and b/station/__pycache__/config.cpython-311.pyc differ diff --git a/station/__pycache__/puller.cpython-311.pyc b/station/__pycache__/puller.cpython-311.pyc index 0d36b15..b4091ea 100644 Binary files a/station/__pycache__/puller.cpython-311.pyc and b/station/__pycache__/puller.cpython-311.pyc differ diff --git a/station/artefacts/.gitkeep b/station/artefacts/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/station/config.py b/station/config.py index dacd5f2..cae5a3f 100644 --- a/station/config.py +++ b/station/config.py @@ -1,10 +1,4 @@ -masterUrl = "http://10.0.3.41:8000" -pullInterval = 10 # in sec -apiKey = "7b105947-65d6-40ba-bb4c-50b95a3ec1c8" - -# do not edit -station = { - "lat": 0, - "lon": 0, - "alt": 0 #KM -} \ No newline at end of file +masterUrl = "http://10.0.0.8" +pullInterval = 120 # in sec +apiKey = "672bccda-6eb3-4cae-bcbf-ed398e9d3dd9" +planInterval = 1200 # in sec \ No newline at end of file diff --git a/station/main.py b/station/main.py index cf20c69..831b21f 100644 --- a/station/main.py +++ b/station/main.py @@ -4,16 +4,24 @@ import time from datetime import datetime, timedelta from recorder import recorder +import sys +import traceback +import planner + def onRecorded(info): pass +i = 0 while True: try: - puller.pull() + if (i % config.pullInterval) == 0: + puller.pull() + jobsDeltas = [] for job in puller.watingJobs: - print(f"Job {job['target']['name']} starts at {job['start']}") + jobsDeltas.append((job["start"] - datetime.utcnow()).total_seconds()) + if job["start"] <= datetime.utcnow() + timedelta(seconds=60): if job["end"] <= datetime.utcnow(): puller.setFail(job["id"]) @@ -22,15 +30,21 @@ while True: # start record puller.setRecording(job["id"]) - curRecorder = recorder(job) + curRecorder = recorder(job, puller.location) curRecorder.start() puller.watingJobs.remove(job) + + if (i % 10) == 0 and len(jobsDeltas): + print(f"Next job in {min(jobsDeltas)}s") + + # ask for planeble satellites + if (i % config.planInterval) == 0: + planner.planAll(puller.location) + + i += 1 - except: - print("[ERROR] main script fail restarting") + except Exception as inst: + print(f"[ERROR] main script fail restarting - error {inst}") - - - - time.sleep(config.pullInterval) \ No newline at end of file + time.sleep(1) \ No newline at end of file diff --git a/station/planner.py b/station/planner.py new file mode 100644 index 0000000..9a9caef --- /dev/null +++ b/station/planner.py @@ -0,0 +1,50 @@ +from pyorbital.orbital import Orbital +from datetime import datetime, timedelta +import time + +import puller + +def plan(lat, lon, alt, tle, transmitter, receiver, name, delta = timedelta(seconds=1800), predictH = 24, horizon = 0): + #prevent plan same obsevation + last = datetime.utcnow() + + for ob in puller.watingJobs: + last = max(ob["start"], last) + + orb = Orbital(name, line1=tle["line1"], line2=tle["line2"]) + + passes = orb.get_next_passes( + datetime.utcnow() + delta, + predictH, + lon, + lat, + alt, + tol = 0.001, + horizon = horizon + ) + + for ob in passes: + start = ob[0] + end = ob[1] + + if start < last: + print(f"[INFO] alredy planed {name} at {start}") + continue + + print(f"[INFO] planed {name} at {start}") + + puller.plan(transmitter, receiver, start, end) + +def planAll(location): + planeble = puller.getPlaneble() + + for transmitter in planeble: + plan( + location["lat"], + location["lon"], + location["alt"], + transmitter["locator"]["tle"], + transmitter["transmitter"], + transmitter["receiver"], + transmitter["name"] + ) \ No newline at end of file diff --git a/station/puller.py b/station/puller.py index 846d6da..85d4b0f 100644 --- a/station/puller.py +++ b/station/puller.py @@ -8,6 +8,7 @@ import os import pathlib watingJobs = [] +location = {} def getNewJobs(): response = urlopen(config.masterUrl + "/api/observation/record?key=" + config.apiKey) @@ -19,10 +20,23 @@ def getInfo(): data_json = json.loads(response.read()) return data_json +def getPlaneble(): + response = urlopen(config.masterUrl + "/api/station/autoPlanable?key=" + config.apiKey) + data_json = json.loads(response.read()) + return data_json + def apiSend(url, data, files=None): r = requests.post(url=config.masterUrl + url, data=data, files=files) return r.text +def plan(transmitter, receiver, start, end): + apiSend("/api/observation/plan", { + "transmitter": transmitter, + "receiver": receiver, + "start": start.strftime("%Y-%m-%dT%H:%M:%S"), + "end": end .strftime("%Y-%m-%dT%H:%M:%S") + }) + def setFail(observation): apiSend("/api/observation/fail", {"id": observation}) @@ -71,12 +85,12 @@ def parseNewJobs(jobs): watingJobs.append(job) def parseInfo(info): - if "gps" in info: - config.lat = info["gps"]["lat"] - config.lon = info["gps"]["lon"] - config.alt = info["gps"]["alt"] / 1000 + if "gps" in info["locator"]: + location["lat"] = info["locator"]["gps"]["lat"] + location["lon"] = info["locator"]["gps"]["lon"] + location["alt"] = info["locator"]["gps"]["alt"] / 1000 - print(f"[INFO] loaded locator from YAGS server LAT: {config.lat}, LON: {config.lon}, ALT: {config.alt}") + #print(f"[INFO] loaded locator from YAGS server LAT: {position["lat"]}, LON: {position["lon"]}, ALT: {position["alt"]}") def pull(): #get station info diff --git a/station/records/.gitkeep b/station/records/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/web/API/cron.php b/web/API/crons.php similarity index 77% rename from web/API/cron.php rename to web/API/crons.php index f3ec5e0..a2b1dfa 100644 --- a/web/API/cron.php +++ b/web/API/crons.php @@ -7,7 +7,7 @@ function tle($params) { // get all targets - $targets = new \wsos\database\core\table(\DAL\targets::class); + $targets = new \wsos\database\core\table(\DAL\target::class); $updated = []; foreach ($targets->getAll()->values as $target) { @@ -23,9 +23,9 @@ $newTle = file_get_contents("https://celestrak.org/NORAD/elements/gp.php?CATNR={$norad}&FORMAT=tle"); $newTle = explode("\n", $newTle); - if (count($newTle) == 3) { //tle loaded - $locator["tle"]["line1"] = $newTle[1]; - $locator["tle"]["line2"] = $newTle[2]; + if (count($newTle) >= 3) { //tle loaded + $locator["tle"]["line1"] = str_replace("\r", "", $newTle[1]); + $locator["tle"]["line2"] = str_replace("\r", "", $newTle[2]); $updated[] = ["name" => $target->name->get(), "norad" => $norad]; diff --git a/web/API/main.php b/web/API/main.php index 8d4ce5c..b463cf0 100644 --- a/web/API/main.php +++ b/web/API/main.php @@ -13,7 +13,7 @@ //register API functions include_once(__DIR__ . "/observations.php"); include_once(__DIR__ . "/stations.php"); - include_once(__DIR__ . "/cron.php"); + include_once(__DIR__ . "/crons.php"); //init API $api->serve($router->getArgs()); \ No newline at end of file