-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgps_base.py
60 lines (48 loc) · 1.62 KB
/
gps_base.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
"""
This script interfaces with the sparkfun GPS module in Base station mode
It publishes RTCM corrections on port 8290 for the rover to use
"""
import serial, pynmea2, time
from UDPComms import Publisher
pub = Publisher(8290)
ser = serial.Serial("/dev/serial0", timeout = 0, writeTimeout = 0)
# Message format
# https://forum.u-blox.com/index.php/16898/decoding-rtcm3-message
def get_length(msg):
assert( msg[0] == chr(0xd3))
return (ord(msg[1])* 8 + ord(msg[2])) & 0x3ff
rtcm_stream = []
try:
while 1:
line = ser.readline()
if line == "":
continue
if line[0:2] == b'$G':
msg = pynmea2.parse(str(line))
if(msg.sentence_type == "GGA"):
print(repr(msg))
rtcm = b''.join(rtcm_stream)
print(ser.in_waiting, ser.out_waiting, len(rtcm))
rtcm_stream = []
timestamp = (msg.timestamp - datetime(1970, 1, 1)).total_seconds()
to_send = { "time": timestamp,
"lat": msg.latitude,
"lon": msg.longitude,
"alt": msg.altitude,
"sats": msg.num_sats,
"rtcm": rtcm}
pub.send(to_send)
else:
rtcm_stream.append(line)
# elif line[0] == chr(0xd3):
# length = get_length(line)
# print("RTCM", length, len(line) , len(line) - length)
# else:
# print("unknown", len(line))
except KeyboardInterrupt:
print('closing')
ser.close()
raise
except:
ser.close()
raise