-
Notifications
You must be signed in to change notification settings - Fork 1
/
pro93-dump-create
executable file
·81 lines (73 loc) · 2.47 KB
/
pro93-dump-create
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
#!/usr/bin/env python3
import argparse
import csv
import decoder
import mmap
import datetime
import shutil
import re
parser = argparse.ArgumentParser(description='Builds an image.')
parser.add_argument('base_image', help='base image to pull all other fields from')
parser.add_argument('channel_csv', help='channel CSV')
parser.add_argument('bank_names_csv', help='bank name CSV')
args = parser.parse_args()
infilename = args.base_image
dt = datetime.datetime.now().isoformat()
outfilename = f"{args.base_image}.{dt}.image"
channels = []
channel_tags = []
bank_names = []
with open(args.channel_csv) as channelfile:
channelreader = csv.reader(channelfile)
found_headers = False
for row in channelreader:
if not found_headers:
found_headers = True
continue
#0,1 2 3 4 5 6 7
#i,memory_slot,text_tag,freq,delay,attenuated,lockout,mode
mode = 0
atten = False
delay = False
lockout = False
freq = 148034250 # x090909, e.g. unused
# If there is a frequency, then it's not unused
unused = row[3].strip() == ''
if not unused:
mode = decoder.inv_mode_map[row[7]]
lockout = row[6] == 'True'
atten = row[5] == 'True'
delay = row[4] == 'True'
freq = int(row[3])
flags = decoder.chan_flags(
mode=mode,
atten=atten,
delay=delay,
lockout=lockout
)
freq = decoder.frequency(freq=freq, unused=unused)
channel = decoder.channel(freq=freq, flags=flags)
channels.append(channel)
# validation and cleanup is in the decoder
channel_tags.append(decoder.text_tag(row[2]))
with open(args.bank_names_csv) as bnfile:
bnreader = csv.reader(bnfile)
found_headers = False
for row in bnreader:
if not found_headers:
found_headers = True
continue
bank_names.append(decoder.text_tag(row[1]))
with open(outfilename, "wb") as outfile:
with open(infilename, "rb") as infile:
outfile.write(infile.read())
outfile.seek(0)
for channel in channels:
outfile.write(channel.encode())
for tag in channel_tags:
outfile.write(tag.encode())
outfile.seek(0x4db0)
outfile.write(decoder.make_has_label_bitfield(channel_tags))
outfile.seek(0x4e3c)
for bank_name in bank_names:
outfile.write(bank_name.encode())