-
Notifications
You must be signed in to change notification settings - Fork 73
/
ntrip.py
executable file
·51 lines (37 loc) · 1.21 KB
/
ntrip.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
#!/usr/bin/env python
import socket
import base64
import sys
dummy, server, port, username, password, mountpoint = sys.argv
pwd = base64.b64encode("{}:{}".format(username, password))
header =\
"GET /{} HTTP/1.1\r\n".format(mountpoint) +\
"Host \r\n".format(server) +\
"Ntrip-Version: Ntrip/2.0\r\n" +\
"User-Agent: NTRIP pyUblox/0.0\r\n" +\
"Connection: close\r\n" +\
"Authorization: Basic {}\r\n\r\n".format(pwd)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((server,int(port)))
s.send(header)
resp = s.recv(1024)
if resp.startswith("STREAMTABLE"):
raise NTRIPError("Invalid or No Mountpoint")
elif not resp.startswith("HTTP/1.1 200 OK"):
raise NTRIPError("Invalid Server Response")
try:
while True:
# There are some length bytes at the head here but it actually
# seems more robust to simply let the higher level RTCMv3 parser
# frame everything itself and bin the garbage as required.
#length = s.recv(4)
#try:
# length = int(length.strip(), 16)
#except ValueError:
# continue
data = s.recv(1024)
print(data)
#print >>sys.stderr, [ord(d) for d in data]
sys.stdout.flush()
finally:
s.close()