-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_pv_uart_ann.py
49 lines (39 loc) · 1.55 KB
/
parse_pv_uart_ann.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
"""PulseView UART annotation parser
This script takes a file created by PulseView UART protocol decoder.
In PulseView, right click somwwhere in the UART:RX row and choose "Export all annotations for this row"
or if you want to export from somwehere in the timeline, choose "Export all annotations for this row, starting here"
This will lokk for lines with
UART: RX: Start bit
UART: RX: <Data>
UART: RX: Parity bit
UART: RX: Stop bit
And if it matches write the data as binary to the file <inputfile>.bin
"""
import sys
import binascii
def stripRx(line):
if "UART: RX: " in line:
return line[(line.index("UART: RX: ")+10):].strip()
return None
def main(file):
with open(file) as infile:
ofile = file+".bin"
print("parsing "+file+" into binary file "+ofile)
with open(ofile, "wb") as outfile:
line = infile.readline()
while line:
if "UART: RX: " in line:
code = stripRx(line)
if code == "Start bit":
line = infile.readline()
hex = stripRx(line)
line = infile.readline()
code = stripRx(line)
if code == "Parity bit":
line = infile.readline()
code = stripRx(line)
if code == "Stop bit":
outfile.write(binascii.unhexlify(hex))
line = infile.readline()
if __name__ == "__main__":
main(sys.argv[1])