-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgps.py
More file actions
executable file
·76 lines (55 loc) · 1.56 KB
/
gps.py
File metadata and controls
executable file
·76 lines (55 loc) · 1.56 KB
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
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/python2
import serial
import sys
import re
import datetime
import pynmea2
class NEO6MGPS:
def __init__(self, serialport, baudratespeed):
self.gpsdevice = serial.Serial(port=serialport, baudrate=baudratespeed, timeout=5)
self.init()
def init(self):
if self.isOpen():
return True
return False
def open(self):
self.gpsdevice.open()
def isOpen(self):
return self.gpsdevice.isOpen()
def readBuffer(self):
try:
data = self.gpsdevice.read(1)
n = self.gpsdevice.inWaiting()
if n:
data = data + self.gpsdevice.read(n)
return data
except Exception, e:
print "Big time read error, what happened: ", e
sys.exit(1)
device = NEO6MGPS("/dev/ttyAMA0", 9600)
newdata = ""
line = ""
gpsdata = ""
while device.isOpen():
if newdata:
line = newdata
newdata = ""
line = line + device.readBuffer()
print line
if re.search("\r\n", line):
data, newdata = line.split("\r\n")
#print "----" + str(datetime.datetime.now()) + "----"
#print data
try:
pNMEA = pynmea2.parse(data)
if isinstance(pNMEA, pynmea2.types.talker.GGA):
print "\r\nLAT:" + pNMEA.lat + pNMEA.lat_dir
print "LONG:" + pNMEA.lon + pNMEA.lon_dir
print "SAT:" + str(pNMEA.num_sats)
print "GPS Sig:" + str(pNMEA.gps_qual)
else:
print ""
except Exception,e:
print e
pass
line = ""