forked from slimit75/xACARS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposUpdateLoop.py
60 lines (49 loc) · 1.44 KB
/
posUpdateLoop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# ----------------------------------------- #
# posUpdateLoop.pyw #
# Speed_Limit75 #
# #
# This file runs a loop to refresh data in #
# the input folder every 5 seconds, #
# regardless if it can connect to FSUIPC or #
# XPUIPC. #
# ----------------------------------------- #
# Import libarys
import time
import threading
import track
import json
import web
import config
import os
import tkinter as tk
from tkinter import messagebox
# Set variables
stop = False
pirepID = ""
# Define functions
def loop():
global pirepID
while True:
track.beginTrack()
lat, lon, hdg, vs, alt, gs = track.posUpdate()
try:
exportdata = {"lat": lat,"lon": lon,"heading": hdg,"altitude": alt,"vs": vs,"gs": gs}
exportdata = {"positions": [exportdata]}
exportdata = json.dumps(exportdata)
web.post(config.website + '/api/pireps/' + pirepID + '/acars/position', exportdata)
except Exception as e:
tk.messagebox.showerror("xACARS Error - Update Loop", e)
time.sleep(5)
if stop == True:
break
def startLoop(x):
global thread
global pirepID
pirepID = x
thread = threading.Thread(target=loop)
thread.start()
def stopLoop():
global thread
global stop
stop = True
track.endTrack()