forked from mjuenema/python-TSIP
-
Notifications
You must be signed in to change notification settings - Fork 1
/
read_tsip.py
executable file
·60 lines (40 loc) · 915 Bytes
/
read_tsip.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
#!/usr/bin/env python
"""
Read TSIP from a device of file.
(c) Markus Juenemann, 2015
"""
import sys
import os.path
import serial
import tsip
import time
import binascii
import logging
logging.basicConfig(level=logging.INFO)
def help():
sys.stderr.write("%s <file|device> [<baudrate>]\n")
sys.exit(1)
def main():
try:
source = sys.argv[1]
except IndexError:
help()
if os.path.isfile(source):
conn = open(source)
else:
try:
baud = int(sys.argv[2])
except IndexError:
baud = 9600
except TypeError:
help()
conn = serial.Serial(source ,baud)
gps = tsip.GPS(conn)
while True:
packet = gps.read()
if packet:
print "0x%0x %s" % (packet.code, packet.values)
else:
print 'None'
if __name__ == '__main__':
main()