Fix idle, add newlines to dummy GPS data
This commit is contained in:
+19
-16
@@ -7,18 +7,18 @@ import serial
|
||||
import time
|
||||
import os
|
||||
|
||||
blank_gps = [
|
||||
"$GPRMC,,V,,,,,,,,,,N*53".encode("utf-8"),
|
||||
"$GPVTG,,,,,,,,,N*30".encode("utf-8"),
|
||||
"$GPGGA,,,,,,0,00,99.99,,,,,,*48".encode("utf-8"),
|
||||
"$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30".encode("utf-8"),
|
||||
"$GPGSV,6,1,21,01,,,30,03,,,28,04,,,28,05,,,30*7E".encode("utf-8"),
|
||||
"$GPGSV,6,2,21,06,,,30,08,,,26,11,,,29,12,,,31*7D".encode("utf-8"),
|
||||
"$GPGSV,6,3,21,14,,,29,16,,,28,17,,,30,19,,,30*72".encode("utf-8"),
|
||||
"$GPGSV,6,4,21,20,,,29,21,,,29,22,,,28,23,,,31*70".encode("utf-8"),
|
||||
"$GPGSV,6,5,21,24,,,29,25,,,26,26,,,29,28,,,29*79".encode("utf-8"),
|
||||
"$GPGSV,6,6,21,31,,,30*7B".encode("utf-8"),
|
||||
"$GPGLL,,,,,,V,N*64".encode("utf-8")
|
||||
blank_gps = [
|
||||
"$GPRMC,,V,,,,,,,,,,N*53\n".encode("utf-8"),
|
||||
"$GPVTG,,,,,,,,,N*30\n".encode("utf-8"),
|
||||
"$GPGGA,,,,,,0,00,99.99,,,,,,*48\n".encode("utf-8"),
|
||||
"$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30\n".encode("utf-8"),
|
||||
"$GPGSV,6,1,21,01,,,30,03,,,28,04,,,28,05,,,30*7E\n".encode("utf-8"),
|
||||
"$GPGSV,6,2,21,06,,,30,08,,,26,11,,,29,12,,,31*7D\n".encode("utf-8"),
|
||||
"$GPGSV,6,3,21,14,,,29,16,,,28,17,,,30,19,,,30*72\n".encode("utf-8"),
|
||||
"$GPGSV,6,4,21,20,,,29,21,,,29,22,,,28,23,,,31*70\n".encode("utf-8"),
|
||||
"$GPGSV,6,5,21,24,,,29,25,,,26,26,,,29,28,,,29*79\n".encode("utf-8"),
|
||||
"$GPGSV,6,6,21,31,,,30*7B\n".encode("utf-8"),
|
||||
"$GPGLL,,,,,,V,N*64\n".encode("utf-8")
|
||||
]
|
||||
|
||||
messageQueue = []
|
||||
@@ -26,19 +26,21 @@ readerRunning = False
|
||||
connected = False
|
||||
server = None
|
||||
|
||||
|
||||
def serialReader(path):
|
||||
global connected
|
||||
index = 0
|
||||
while True:
|
||||
if path.exists():
|
||||
if path.exists():
|
||||
try:
|
||||
print("device connected")
|
||||
ser = serial.Serial(str(path))
|
||||
ser.timeout = 3
|
||||
ser.timeout = 3
|
||||
connected = True
|
||||
while path.exists():
|
||||
message = ser.readline()
|
||||
messageQueue.insert(0, message)
|
||||
time.sleep(0.1)
|
||||
except serial.SerialException:
|
||||
pass
|
||||
connected = False
|
||||
@@ -60,6 +62,7 @@ class Handler(StreamRequestHandler):
|
||||
return
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sockPath = Path('/var/run/gps-share.sock')
|
||||
devPath = Path('/dev/gps')
|
||||
@@ -72,6 +75,6 @@ if __name__ == '__main__':
|
||||
sockPath.unlink()
|
||||
|
||||
print("starting server")
|
||||
server = ThreadingUnixStreamServer(str(sockPath), Handler)
|
||||
sockPath.chmod(0o666)
|
||||
server = ThreadingUnixStreamServer(str(sockPath), Handler)
|
||||
sockPath.chmod(0o666)
|
||||
server.serve_forever()
|
||||
|
||||
Reference in New Issue
Block a user