-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdecode_screens.py
106 lines (88 loc) · 2.79 KB
/
decode_screens.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/python
#
# Script decode 'screen data' from Zoom G1Four
# (c) Simon Wood, 10 Dec 2020
#
# read with:
# $ amidi -p hw:1,0,0 -S 'F0 52 00 6e 64 02 00 09 00 F7' -r temp.bin -t 2
#
from construct import *
#--------------------------------------------------
# Define ZPTC file format using Construct (v2.9)
# requires:
# https://github.com/construct/construct
Info = Struct(
"screen1" / Byte,
"param1" / Byte,
"type1" / Enum(Byte,
VALUE = 0x00,
NAME = 0x01,
INVERT = 0x07,
),
"invert1" / Byte,
"value" / PaddedString(10, "ascii"),
"screen2" / Byte,
"param2" / Byte,
"type2" / Enum(Byte,
VALUE = 0x00,
NAME = 0x01,
INVERT = 0x07,
),
"invert2" / Byte,
"name" / PaddedString(10, "ascii"),
)
Screen = Struct(
"info" / Array(6, Info),
)
Display = Struct(
GreedyRange(Const(b"\x00")), # get rid of leading zeros
Const(b"\xf0\x52\x00\x6e\x64\x01"),
"screens" / GreedyRange(Screen),
#Const(b"\xf7"), # not seen if we ask for too
# many screens worth of data
)
#--------------------------------------------------
def main():
from argparse import ArgumentParser
parser = ArgumentParser(prog="decode_effect")
parser.add_argument('files', metavar='FILE', nargs=1,
help='File to process')
parser.add_argument("-d", "--dump",
help="dump configuration to text",
action="store_true", dest="dump")
parser.add_argument("-a", "--all",
help="display all parameters (include 'Dummy')",
action="store_true", dest="all")
options = parser.parse_args()
if not len(options.files):
parser.error("FILE not specified")
# Read data from file
infile = open(options.files[0], "rb")
if not infile:
sys.exit("Unable to open FILE for reading")
else:
data = infile.read()
infile.close()
if data:
config = Display.parse(data)
if options.dump:
print(config)
for screen in config['screens']:
for info in screen['info']:
if info['param1'] == 0:
if info['name'] == "Dummy":
on_off = None
else:
if info['value'] == "1":
on_off = "On"
else:
on_off = "Off"
print("---")
elif info['param1'] == 1:
if on_off:
print("Effect: %s (%s)" % (info['name'], on_off))
else:
if info['name'] != "Dummy" or options.all:
print("%s : %s" % (info['name'], info['value']))
if __name__ == "__main__":
main()