-
Notifications
You must be signed in to change notification settings - Fork 0
/
ubxcfg.py
53 lines (48 loc) · 1.2 KB
/
ubxcfg.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
#!/usr/bin/python
#
# Jake Hawkins
#
# Ublox Configuration. Converts ASCI config file to binary format and sends to GPS
#
# Usage:
#
# ubxcfg.py [UBlox Config File] [port] [baud_default] [baud_programed]
#
#
import binascii, serial, sys
from time import sleep
header = bytearray.fromhex('b5 62')
inputfile = open(sys.argv[1])
# outputfile= open('SAM8.bin', 'w+')
s = serial.Serial(port=sys.argv[2], baudrate=sys.argv[3], timeout=1)
postponed_commands = []
for line in inputfile:
cs0=0
cs1=0
payload_bin = bytearray()
payload_bin += header
message=(line[:line.find(' - ')])
payload_hex=(line[(3+line.find(' - ')):]).split()
for d in payload_hex:
c = binascii.unhexlify(d)
payload_bin += c
cs0 += ord(c)
cs0 &= 255
cs1 += cs0
cs1 &= 255
payload_bin += bytes([cs0])
payload_bin += bytes([cs1])
if message == 'CFG-PRT':
postponed_commands.append(payload_bin)
elif message == 'MON-VER':
pass
else:
s.write(payload_bin)
s.write(b'\n')
sleep (0.05)
for line in postponed_commands:
s.write(line)
s.write(b'\n')
sleep (0.05)
inputfile.close()
s.baudrate = sys.argv[4]