More import stuff.
This commit is contained in:
29
grmn/tlv.py
29
grmn/tlv.py
@@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from . import devices
|
from . import devices
|
||||||
from binascii import hexlify
|
from binascii import hexlify, unhexlify
|
||||||
from struct import pack, unpack
|
from struct import pack, unpack
|
||||||
|
|
||||||
TLV_TYPES = {
|
TLV_TYPES = {
|
||||||
@@ -101,7 +101,10 @@ class TLV:
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def load_dump(self, values):
|
def load_dump(self, values):
|
||||||
pass
|
for (k, v) in values:
|
||||||
|
if k == "value":
|
||||||
|
self.value = unhexlify("".join(v.split(" ")))
|
||||||
|
self.length = len(self.value)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_from_dump(values):
|
def create_from_dump(values):
|
||||||
@@ -121,9 +124,9 @@ class TLV1(TLV):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def load_dump(self, values):
|
def load_dump(self, values):
|
||||||
for (k, v) in values:
|
# Will be calculated in a final pass
|
||||||
if k == "value":
|
self.value = 0x00
|
||||||
self.value = int(v, 0)
|
self.length = 1
|
||||||
|
|
||||||
class TLV2(TLV):
|
class TLV2(TLV):
|
||||||
def dump(self):
|
def dump(self):
|
||||||
@@ -132,6 +135,12 @@ class TLV2(TLV):
|
|||||||
data.append(("length", self.get_actual_length(), "Length of padding block"))
|
data.append(("length", self.get_actual_length(), "Length of padding block"))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def load_dump(self, values):
|
||||||
|
for (k, v) in values:
|
||||||
|
if k == "length":
|
||||||
|
self.value = b"\x00" * int(v)
|
||||||
|
self.length = len(self.value)
|
||||||
|
|
||||||
class TLV5(TLV):
|
class TLV5(TLV):
|
||||||
def dump(self):
|
def dump(self):
|
||||||
data = []
|
data = []
|
||||||
@@ -140,6 +149,16 @@ class TLV5(TLV):
|
|||||||
data.append(("text", self.value.decode("utf-8"), None))
|
data.append(("text", self.value.decode("utf-8"), None))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def load_dump(self, values):
|
||||||
|
for (k, v) in values:
|
||||||
|
if k == "text":
|
||||||
|
self.value = v.encode("utf-8")
|
||||||
|
elif k == "length":
|
||||||
|
self.length = int(v)
|
||||||
|
if len(self.value) != self.length:
|
||||||
|
print("WARNING: Imported copyright text doesn't match supposed length.")
|
||||||
|
self.length = len(self.value)
|
||||||
|
|
||||||
class TLV6(TLV):
|
class TLV6(TLV):
|
||||||
"""
|
"""
|
||||||
Describes following TLV7:
|
Describes following TLV7:
|
||||||
|
|||||||
Reference in New Issue
Block a user