From b6d443279b32e731f747eb92ea97249d38874352 Mon Sep 17 00:00:00 2001 From: fly Date: Sun, 3 May 2020 23:25:10 +1000 Subject: [PATCH] Right? Signed-off-by: fly --- config.py | 13 +++++++++---- fg.py | 26 +++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/config.py b/config.py index 6e7f2ca..79fd032 100644 --- a/config.py +++ b/config.py @@ -21,6 +21,7 @@ class config: def __init__(self): self.host = "localhost" self.port = 1711 + self.localPort = 1712 if os.name == 'nt': # If on windows # TODO give windows path pass @@ -34,10 +35,11 @@ class config: print("Usage: aloftWxr.py [OPTIONS]") print("Fetch live weather from NOAA servers and loads it into FlightGear") print("OPTIONS") - print(" -h, --help Shows this help and exit") - print(" -f, --host FlightGear host. Default 'localhost'") - print(" -p, --port FLightGear port. Default 1711") - print(" -t, --tmp Directory for temporary files") + print(" -h, --help Shows this help and exit") + print(" -f, --host FlightGear host. Default 'localhost'") + print(" -p, --port FLightGear port. Default 1711") + print(" -P, --localPort aloftWxr port. Default 1712") + print(" -t, --tmp Directory for temporary files") sys.exit(0) elif sys.argv[i] == "-f" or sys.argv[i] == "--host": i += 1 @@ -45,6 +47,9 @@ class config: elif sys.argv[i] == "-p" or sys.argv[i] == "--port": i += 1 self.port = sys.argv[i] + elif sys.argv[i] == "-P" or sys.argv[i] == "--localPort": + i += 1 + self.locaPort = sys.argv[i] elif sys.argv[i] == "-t" or sys.argv[i] == "--tmp": i += 1 self.tmpPath = sys.argv[i] diff --git a/fg.py b/fg.py index 287811f..6991d1b 100644 --- a/fg.py +++ b/fg.py @@ -14,7 +14,27 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +import socket + +class aircraftPos: + def __init__(self, lat, lon, alt): + self.lat = lat + self.lon = lon + self.alt = alt + class connection: - def sendData(wp): - # TODO - pass + def __init__(self, conf): + try: + self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + self.sock.bind('0.0.0.0', conf.localPort) + except: + print("ERROR: Unable to open socket") + def sendData(self, wp): + wpt = '{:f},{:f}'.format(wp.lat, wp.lon) + for w in wp: + wpt += ',{:f},{:f}'.format(w.direction, w.speed) + self.sock.sendto(wpt.encode(), (conf.host, conf.port)) + def receiveData(self): + msg, addr = self.sock.recvfrom(1024); + lat, lon, alt = msg.split(,) + return aircraftPos(lat, lon, alt)