-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtcm_slac.py
75 lines (52 loc) · 1.68 KB
/
rtcm_slac.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
66
67
68
69
from httplib import HTTPConnection
from base64 import b64encode
import pynmea2, time
from user_pass import user
from UDPComms import Publisher
publish_interval = 1
pub = Publisher(8290)
server ="rtgpsout.unavco.org:2101"
headers = {
'Ntrip-Version': 'Ntrip/2.0',
'User-Agent': 'NTRIP ntrip_ros',
'Connection': 'close',
'Authorization': 'Basic ' + b64encode(user)
}
connection = HTTPConnection(server)
connection.request('GET', '/SLAC_RTCM3',body=None, headers=headers)
response = connection.getresponse()
# 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
buf = ""
msgs = []
last_message = time.time()
while 1:
if response.isclosed():
print "responce closed"
break
buf += response.read(100)
length = get_length(buf)
next_header = buf[length:].find( chr(0xd3) )
# print(length,next_header, len(buf), len(msgs))
# print buf[length: length + next_header].encode("hex")
if (next_header == -1):
print "no header found"
continue
msgs.append( buf[:length + next_header ] )
buf = buf[length + next_header:]
if (time.time() - last_message) > publish_interval:
rtcm = "".join(msgs)
print(len("".join(msgs)))
msgs = []
last_message = time.time()
# timestamp = (msg.timestamp - datetime(1970, 1, 1)).total_seconds()
to_send = { "time": 0,
"lat": 37.41652,
"lon": -122.20427,
"alt": 64,
"sats": 0,
"rtcm": rtcm}
pub.send(to_send)