-
Notifications
You must be signed in to change notification settings - Fork 0
/
Location Detection.py
65 lines (55 loc) · 1.64 KB
/
Location Detection.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
61
62
63
64
65
import threading
import pynmea2
import os
class Message:
def __init__(self):
self.msg =''
# Gps Receiver thread funcion, check gps value for infinte times
def getgpsdata(serial, dmesg):
print("getgpsdata")
while True:
data = serial.readline()
if data.find('GGA') > 0:
dmesg.msg = pynmea2.parse(data)
# API to call start the GPS Receiver
def start_gps_receiver(serial, dmesg):
t2 = threading.Thread(target=getgpsdata, args=(serial, dmesg))
t2.start()
print("GPS Receiver started")
# API to fix the GPS Revceiver
def ready_gps_receiver(msg):
print("Please wait fixing GPS .....")
dmesg = msg.msg
while(dmesg.gps_qual != 1):
pass
print("GPS Fix available")
# API to get latitude from the GPS Receiver
def get_latitude(msg):
print("Getting Latitude")
dmesg = msg.msg
print("Latitude:", dmesg.latitude)
# API to get longitude from the GPS Receiver
def get_longitude(msg):
print("Getting Longitude")
dmesg = msg.msg
print("Longitude:", dmesg.longitude)
# API to get Number of Satellites from the GPS Receiver
def get_num_satellite(msg):
print("Getting Number of satellite")
dmesg = msg.msg
print("No of satellites:", dmesg.num_sats)
# API to get Altitude of Antenna from the GPS Receiver
def get_altitude(msg):
print("Getting altitude of Antenna")
dmesg = msg.msg
print("Altitude (M):", dmesg.altitude)
# API to check the status of GPS Fix
def get_gps_fix(msg):
dmesg = msg.msg
print("GPS Fix stats:", dmesg.gps_qual)
# API to Exit
def function_exit(msg):
print("Exiting ......")
print("stopping the thread")
exit()
return 1