buildcommands: Convert to Python3 string encoding

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-10-01 19:27:00 -04:00
parent 8714282570
commit 1717263b5a
1 changed files with 7 additions and 6 deletions

View File

@ -283,7 +283,8 @@ class HandleCommandGeneration:
def create_message_ids(self): def create_message_ids(self):
# Create unique ids for each message type # Create unique ids for each message type
msgid = max(self.msg_to_id.values()) msgid = max(self.msg_to_id.values())
for msgname in self.commands.keys() + [m for n, m in self.encoders]: mlist = list(self.commands.keys()) + [m for n, m in self.encoders]
for msgname in mlist:
msg = self.messages_by_name.get(msgname, msgname) msg = self.messages_by_name.get(msgname, msgname)
if msg not in self.msg_to_id: if msg not in self.msg_to_id:
msgid += 1 msgid += 1
@ -546,17 +547,17 @@ class HandleIdentify:
# Write data dictionary # Write data dictionary
if options.write_dictionary: if options.write_dictionary:
f = open(options.write_dictionary, 'wb') f = open(options.write_dictionary, 'w')
f.write(datadict) f.write(datadict)
f.close() f.close()
# Format compressed info into C code # Format compressed info into C code
zdatadict = zlib.compress(datadict, 9) zdatadict = bytearray(zlib.compress(datadict.encode(), 9))
out = [] out = []
for i in range(len(zdatadict)): for i in range(len(zdatadict)):
if i % 8 == 0: if i % 8 == 0:
out.append('\n ') out.append('\n ')
out.append(" 0x%02x," % (ord(zdatadict[i]),)) out.append(" 0x%02x," % (zdatadict[i],))
fmt = """ fmt = """
const uint8_t command_identify_data[] PROGMEM = {%s const uint8_t command_identify_data[] PROGMEM = {%s
}; };
@ -595,7 +596,7 @@ def main():
# Parse request file # Parse request file
ctr_dispatch = { k: v for h in Handlers for k, v in h.ctr_dispatch.items() } ctr_dispatch = { k: v for h in Handlers for k, v in h.ctr_dispatch.items() }
f = open(incmdfile, 'rb') f = open(incmdfile, 'r')
data = f.read() data = f.read()
f.close() f.close()
for req in data.split('\n'): for req in data.split('\n'):
@ -609,7 +610,7 @@ def main():
# Write output # Write output
code = "".join([FILEHEADER] + [h.generate_code(options) for h in Handlers]) code = "".join([FILEHEADER] + [h.generate_code(options) for h in Handlers])
f = open(outcfile, 'wb') f = open(outcfile, 'w')
f.write(code) f.write(code)
f.close() f.close()