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)