Skip to content

Commit

Permalink
Merge pull request #25 from ltbam/eg0104
Browse files Browse the repository at this point in the history
added EG0104 parser
  • Loading branch information
All4Gis authored Mar 7, 2021
2 parents 489918f + 9532944 commit b536550
Show file tree
Hide file tree
Showing 7 changed files with 710 additions and 3 deletions.
3 changes: 2 additions & 1 deletion klvdata/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .streamparser import StreamParser
from . import misb0601
from . import misb0102
from . import misb0102
from . import misbEG0104
11 changes: 11 additions & 0 deletions klvdata/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ def bytes_to_float(value, _domain, _range):
return linear_map(src_value, _domain, _range)


def ieee754_bytes_to_fp(value):
"""Convert the fixed point value self.value to a ieee754 double point value."""
#src_value = int().from_bytes(value, byteorder='big', signed=False)
l = len(value)
if l == 4:
return unpack('>f', value)[0]
elif l == 8:
return unpack('>d', value)[0]
else:
raise ValueError

def float_to_bytes(value, _domain, _range):
"""Convert the fixed point value self.value to a floating point value."""
# Some classes like MappedElement are calling float_to_bytes with arguments _domain
Expand Down
20 changes: 20 additions & 0 deletions klvdata/elementparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
from klvdata.common import datetime_to_bytes
from klvdata.common import float_to_bytes
from klvdata.common import str_to_bytes
from klvdata.common import ieee754_bytes_to_fp



class ElementParser(Element, metaclass=ABCMeta):
Expand Down Expand Up @@ -166,6 +168,24 @@ def __str__(self):
def __float__(self):
return self.value

class IEEE754ElementParser(ElementParser, metaclass=ABCMeta):
def __init__(self, value):
super().__init__(IEEE754Value(value))


class IEEE754Value(BaseValue):
def __init__(self, value):
try:
self.value = ieee754_bytes_to_fp(value)
except TypeError:
self.value = value

def __bytes__(self):
#TODO
return ieee754_double_to_bytes(self.value)

def __str__(self):
return bytes_to_hexstr(self.value, start='0x', sep='')



1 change: 1 addition & 0 deletions klvdata/misb0102.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class SecurityLocalMetadataSet(SetParser):
Must be a subclass of Element or duck type Element.
"""
key, name = b'\x30', "Security Local Metadata Set"
key_length = 1
parsers = {}

_unknown_element = UnknownElement
Expand Down
2 changes: 1 addition & 1 deletion klvdata/misb0601.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class UASLocalMetadataSet(SetParser):
"""
key = hexstr_to_bytes('06 0E 2B 34 - 02 0B 01 01 – 0E 01 03 01 - 01 00 00 00')
name = 'UAS Datalink Local Set'

key_length = 1
parsers = {}

_unknown_element = UnknownElement
Expand Down
Loading

0 comments on commit b536550

Please sign in to comment.