Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
fly 2020-05-03 23:25:10 +10:00
parent a5c1e72cac
commit b6d443279b
2 changed files with 32 additions and 7 deletions

View file

@ -21,6 +21,7 @@ class config:
def __init__(self): def __init__(self):
self.host = "localhost" self.host = "localhost"
self.port = 1711 self.port = 1711
self.localPort = 1712
if os.name == 'nt': # If on windows if os.name == 'nt': # If on windows
# TODO give windows path # TODO give windows path
pass pass
@ -34,10 +35,11 @@ class config:
print("Usage: aloftWxr.py [OPTIONS]") print("Usage: aloftWxr.py [OPTIONS]")
print("Fetch live weather from NOAA servers and loads it into FlightGear") print("Fetch live weather from NOAA servers and loads it into FlightGear")
print("OPTIONS") print("OPTIONS")
print(" -h, --help Shows this help and exit") print(" -h, --help Shows this help and exit")
print(" -f, --host FlightGear host. Default 'localhost'") print(" -f, --host FlightGear host. Default 'localhost'")
print(" -p, --port FLightGear port. Default 1711") print(" -p, --port FLightGear port. Default 1711")
print(" -t, --tmp Directory for temporary files") print(" -P, --localPort aloftWxr port. Default 1712")
print(" -t, --tmp Directory for temporary files")
sys.exit(0) sys.exit(0)
elif sys.argv[i] == "-f" or sys.argv[i] == "--host": elif sys.argv[i] == "-f" or sys.argv[i] == "--host":
i += 1 i += 1
@ -45,6 +47,9 @@ class config:
elif sys.argv[i] == "-p" or sys.argv[i] == "--port": elif sys.argv[i] == "-p" or sys.argv[i] == "--port":
i += 1 i += 1
self.port = sys.argv[i] 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": elif sys.argv[i] == "-t" or sys.argv[i] == "--tmp":
i += 1 i += 1
self.tmpPath = sys.argv[i] self.tmpPath = sys.argv[i]

26
fg.py
View file

@ -14,7 +14,27 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # 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: class connection:
def sendData(wp): def __init__(self, conf):
# TODO try:
pass 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)