Also set length of binary blocks correctly when compiling new GCD.
This commit is contained in:
parent
b985f4b6a5
commit
d37ec0752d
@ -196,15 +196,18 @@ class Gcd:
|
|||||||
filename = rcp[s]["from_file"]
|
filename = rcp[s]["from_file"]
|
||||||
file_type_id = tlv7.binary_type_id
|
file_type_id = tlv7.binary_type_id
|
||||||
|
|
||||||
|
running_count = 0
|
||||||
with open(filename, "rb") as bf:
|
with open(filename, "rb") as bf:
|
||||||
while True:
|
while True:
|
||||||
read_bytes = bf.read(0xff00)
|
read_bytes = bf.read(0xff00)
|
||||||
btlv = TLVbinary(file_type_id, len(read_bytes))
|
btlv = TLVbinary(file_type_id, len(read_bytes))
|
||||||
btlv.value = read_bytes
|
btlv.value = read_bytes
|
||||||
gcd.struct.append(btlv)
|
gcd.struct.append(btlv)
|
||||||
|
running_count += len(read_bytes)
|
||||||
if len(read_bytes) < 0xff00:
|
if len(read_bytes) < 0xff00:
|
||||||
break
|
break
|
||||||
bf.close()
|
bf.close()
|
||||||
|
tlv7.set_binary_length(running_count)
|
||||||
else:
|
else:
|
||||||
tlv = TLV.create_from_dump(params)
|
tlv = TLV.create_from_dump(params)
|
||||||
gcd.struct.append(tlv)
|
gcd.struct.append(tlv)
|
||||||
|
17
grmn/tlv.py
17
grmn/tlv.py
@ -200,6 +200,9 @@ class TLV6(TLV):
|
|||||||
if len(self.value) % 2 != 0:
|
if len(self.value) % 2 != 0:
|
||||||
raise Exception("Invalid TLV6 payload length!")
|
raise Exception("Invalid TLV6 payload length!")
|
||||||
|
|
||||||
|
self.fids = []
|
||||||
|
self.format = ""
|
||||||
|
self.fields = []
|
||||||
for i in range(0, len(self.value), 2):
|
for i in range(0, len(self.value), 2):
|
||||||
fid = unpack("<H", self.value[i:i+2])[0]
|
fid = unpack("<H", self.value[i:i+2])[0]
|
||||||
self.add_fid(fid)
|
self.add_fid(fid)
|
||||||
@ -247,6 +250,7 @@ class TLV7(TLV):
|
|||||||
if not self.tlv6.is_parsed:
|
if not self.tlv6.is_parsed:
|
||||||
# Make sure we have the structure analysed
|
# Make sure we have the structure analysed
|
||||||
self.tlv6.parse()
|
self.tlv6.parse()
|
||||||
|
self.attr = []
|
||||||
values = unpack("<" + self.tlv6.format, self.value)
|
values = unpack("<" + self.tlv6.format, self.value)
|
||||||
for i, v in enumerate(values):
|
for i, v in enumerate(values):
|
||||||
fid = self.tlv6.fids[i]
|
fid = self.tlv6.fids[i]
|
||||||
@ -270,6 +274,19 @@ class TLV7(TLV):
|
|||||||
txt += "\n - Field {:d}: {:>20}: 0x{:04x} / {:d}".format(i+1, fdesc, v, v)
|
txt += "\n - Field {:d}: {:>20}: 0x{:04x} / {:d}".format(i+1, fdesc, v, v)
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
|
def set_binary_length(self, new_length):
|
||||||
|
self.tlv6.parse()
|
||||||
|
values = unpack("<" + self.tlv6.format, self.value)
|
||||||
|
new_values = []
|
||||||
|
for i, v in enumerate(values):
|
||||||
|
fid = self.tlv6.fids[i]
|
||||||
|
if fid == 0x2015:
|
||||||
|
new_values.append(new_length)
|
||||||
|
else:
|
||||||
|
new_values.append(v)
|
||||||
|
self.value = pack("<" + self.tlv6.format, *new_values)
|
||||||
|
self.is_parsed = False
|
||||||
|
|
||||||
def dump(self):
|
def dump(self):
|
||||||
# Dump nothing as important info will be chained in binary dump
|
# Dump nothing as important info will be chained in binary dump
|
||||||
return []
|
return []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user