Skip to content

Commit

Permalink
feat: Fix Comment Parsing a little
Browse files Browse the repository at this point in the history
  • Loading branch information
hutcheb committed Jul 4, 2024
1 parent 5bf60df commit ee90d19
Show file tree
Hide file tree
Showing 10 changed files with 411 additions and 13 deletions.
2 changes: 1 addition & 1 deletion acd/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __post_init__(self):
return

query: str = "INSERT INTO comments VALUES (?, ?, ?, ?, ?, ?, ?)"
if (r.header.record_type == 0x0D) or (r.header.record_type == 0x0E):
if (r.header.record_type == 0x03) or (r.header.record_type == 0x04) or (r.header.record_type == 0x0D) or (r.header.record_type == 0x0E):
try:
entry: tuple = (
r.header.seq_number,
Expand Down
8 changes: 4 additions & 4 deletions acd/generated/comments/fafa_coments.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ def _read(self):
if _on == 14:
self._raw_body = self._io.read_bytes((self.record_length - 10))
_io__raw_body = KaitaiStream(BytesIO(self._raw_body))
self.body = FafaComents.Utf16Record(self.header.record_type, _io__raw_body, self, self._root)
self.body = FafaComents.Utf16Record(12, _io__raw_body, self, self._root)
elif _on == 4:
self._raw_body = self._io.read_bytes((self.record_length - 10))
_io__raw_body = KaitaiStream(BytesIO(self._raw_body))
self.body = FafaComents.AsciiRecord4(_io__raw_body, self, self._root)
self.body = FafaComents.Utf16Record(12, _io__raw_body, self, self._root)
elif _on == 1:
self._raw_body = self._io.read_bytes((self.record_length - 10))
_io__raw_body = KaitaiStream(BytesIO(self._raw_body))
self.body = FafaComents.AsciiRecord(_io__raw_body, self, self._root)
elif _on == 13:
self._raw_body = self._io.read_bytes((self.record_length - 10))
_io__raw_body = KaitaiStream(BytesIO(self._raw_body))
self.body = FafaComents.Utf16Record(self.header.record_type, _io__raw_body, self, self._root)
self.body = FafaComents.Utf16Record(12, _io__raw_body, self, self._root)
elif _on == 3:
self._raw_body = self._io.read_bytes((self.record_length - 10))
_io__raw_body = KaitaiStream(BytesIO(self._raw_body))
self.body = FafaComents.AsciiRecord(_io__raw_body, self, self._root)
self.body = FafaComents.Utf16Record(12, _io__raw_body, self, self._root)
elif _on == 23:
self._raw_body = self._io.read_bytes((self.record_length - 10))
_io__raw_body = KaitaiStream(BytesIO(self._raw_body))
Expand Down
23 changes: 22 additions & 1 deletion acd/generated/comps/rx_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def _read(self):
self.record_format_version = self._io.read_u2le()
self.comment_id = self._io.read_u4le()
_on = self.record_format_version
if _on == 60:
if _on == 0:
self.body = RxTag.V0(self._io, self, self._root)
elif _on == 60:
self.body = RxTag.V60(self._io, self, self._root)
elif _on == 63:
self.body = RxTag.V63(self._io, self, self._root)
Expand Down Expand Up @@ -307,6 +309,25 @@ def _read(self):
self.position_4 = self._io.read_u4le()


class V0(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()

def _read(self):
pass

@property
def valid(self):
if hasattr(self, '_m_valid'):
return self._m_valid

self._m_valid = False
return getattr(self, '_m_valid', None)


class VUnknown(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
Expand Down
Empty file.
263 changes: 263 additions & 0 deletions acd/generated/controller/rx_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
# This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

import kaitaistruct
from kaitaistruct import KaitaiStruct, KaitaiStream, BytesIO


if getattr(kaitaistruct, 'API_VERSION', (0, 9)) < (0, 9):
raise Exception("Incompatible Kaitai Struct Python API: 0.9 or later is required, but you have %s" % (kaitaistruct.__version__))

class RxController(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()

def _read(self):
self.parent_id = self._io.read_u4le()
self.unique_tag_identifier = self._io.read_u4le()
self.record_format_version = self._io.read_u2le()
self.comment_id = self._io.read_u4le()
_on = self.record_format_version
if _on == 95:
self.body = RxController.V95(self._io, self, self._root)
elif _on == 103:
self.body = RxController.V103(self._io, self, self._root)
else:
self.body = RxController.VUnknown(self._io, self, self._root)

class VUnknown(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()

def _read(self):
pass

@property
def valid(self):
if hasattr(self, '_m_valid'):
return self._m_valid

self._m_valid = False
return getattr(self, '_m_valid', None)


class V95(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()

def _read(self):
pass

@property
def len_most_recent(self):
if hasattr(self, '_m_len_most_recent'):
return self._m_len_most_recent

_pos = self._io.pos()
self._io.seek(363)
self._m_len_most_recent = self._io.read_u4le()
self._io.seek(_pos)
return getattr(self, '_m_len_most_recent', None)

@property
def record(self):
if hasattr(self, '_m_record'):
return self._m_record

_pos = self._io.pos()
self._io.seek(74)
self._m_record = self._io.read_bytes(self.len_record)
self._io.seek(_pos)
return getattr(self, '_m_record', None)

@property
def len_current_active(self):
if hasattr(self, '_m_len_current_active'):
return self._m_len_current_active

_pos = self._io.pos()
self._io.seek(327)
self._m_len_current_active = self._io.read_u4le()
self._io.seek(_pos)
return getattr(self, '_m_len_current_active', None)

@property
def most_recent(self):
if hasattr(self, '_m_most_recent'):
return self._m_most_recent

_pos = self._io.pos()
self._io.seek(367)
self._m_most_recent = (self._io.read_bytes(self.len_most_recent)).decode(u"utf-16")
self._io.seek(_pos)
return getattr(self, '_m_most_recent', None)

@property
def serial_number(self):
if hasattr(self, '_m_serial_number'):
return self._m_serial_number

_pos = self._io.pos()
self._io.seek(459)
self._m_serial_number = self._io.read_u4le()
self._io.seek(_pos)
return getattr(self, '_m_serial_number', None)

@property
def valid(self):
if hasattr(self, '_m_valid'):
return self._m_valid

self._m_valid = True
return getattr(self, '_m_valid', None)

@property
def len_record(self):
if hasattr(self, '_m_len_record'):
return self._m_len_record

_pos = self._io.pos()
self._io.seek(74)
self._m_len_record = self._io.read_u4le()
self._io.seek(_pos)
return getattr(self, '_m_len_record', None)

@property
def current_acive(self):
if hasattr(self, '_m_current_acive'):
return self._m_current_acive

_pos = self._io.pos()
self._io.seek(331)
self._m_current_acive = (self._io.read_bytes(self.len_current_active)).decode(u"utf-16")
self._io.seek(_pos)
return getattr(self, '_m_current_acive', None)


class V103(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()

def _read(self):
pass

@property
def len_most_recent(self):
if hasattr(self, '_m_len_most_recent'):
return self._m_len_most_recent

_pos = self._io.pos()
self._io.seek(232)
self._m_len_most_recent = self._io.read_u4le()
self._io.seek(_pos)
return getattr(self, '_m_len_most_recent', None)

@property
def record(self):
if hasattr(self, '_m_record'):
return self._m_record

_pos = self._io.pos()
self._io.seek(74)
self._m_record = self._io.read_bytes(self.len_record)
self._io.seek(_pos)
return getattr(self, '_m_record', None)

@property
def len_current_active(self):
if hasattr(self, '_m_len_current_active'):
return self._m_len_current_active

_pos = self._io.pos()
self._io.seek(196)
self._m_len_current_active = self._io.read_u4le()
self._io.seek(_pos)
return getattr(self, '_m_len_current_active', None)

@property
def most_recent(self):
if hasattr(self, '_m_most_recent'):
return self._m_most_recent

_pos = self._io.pos()
self._io.seek(236)
self._m_most_recent = (self._io.read_bytes(self.len_most_recent)).decode(u"utf-16")
self._io.seek(_pos)
return getattr(self, '_m_most_recent', None)

@property
def serial_number(self):
if hasattr(self, '_m_serial_number'):
return self._m_serial_number

_pos = self._io.pos()
self._io.seek(328)
self._m_serial_number = self._io.read_u4le()
self._io.seek(_pos)
return getattr(self, '_m_serial_number', None)

@property
def valid(self):
if hasattr(self, '_m_valid'):
return self._m_valid

self._m_valid = True
return getattr(self, '_m_valid', None)

@property
def len_record(self):
if hasattr(self, '_m_len_record'):
return self._m_len_record

_pos = self._io.pos()
self._io.seek(74)
self._m_len_record = self._io.read_u4le()
self._io.seek(_pos)
return getattr(self, '_m_len_record', None)

@property
def path(self):
if hasattr(self, '_m_path'):
return self._m_path

_pos = self._io.pos()
self._io.seek(388)
self._m_path = (self._io.read_bytes(self.len_path)).decode(u"utf-16")
self._io.seek(_pos)
return getattr(self, '_m_path', None)

@property
def len_path(self):
if hasattr(self, '_m_len_path'):
return self._m_len_path

_pos = self._io.pos()
self._io.seek(384)
self._m_len_path = self._io.read_u4le()
self._io.seek(_pos)
return getattr(self, '_m_len_path', None)

@property
def current_acive(self):
if hasattr(self, '_m_current_acive'):
return self._m_current_acive

_pos = self._io.pos()
self._io.seek(200)
self._m_current_acive = (self._io.read_bytes(self.len_current_active)).decode(u"utf-16")
self._io.seek(_pos)
return getattr(self, '_m_current_acive', None)



20 changes: 17 additions & 3 deletions acd/l5x/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from acd.exceptions.CompsRecordException import UnknownRxTagVersion
from acd.generated.comps.rx_tag import RxTag
from acd.generated.controller.rx_controller import RxController


@dataclass
Expand Down Expand Up @@ -53,6 +54,8 @@ class Program(L5xElement):

@dataclass
class Controller(L5xElement):
serial_number: str
path: str
data_types: List[DataType]
tags: List[Tag]
programs: List[Program]
Expand Down Expand Up @@ -100,7 +103,9 @@ def build(self) -> Tag:

r = RxTag.from_bytes(results[0][3])

if not r.body.valid:
if r.record_format_version == 0x00:
return Tag(results[0][0], 0, "", [])
elif not r.body.valid:
raise UnknownRxTagVersion(r.record_format_version)

if r.body.data_type == 4294967295:
Expand Down Expand Up @@ -258,10 +263,19 @@ class ControllerBuilder(L5xElementBuilder):

def build(self) -> Controller:
self._cur.execute(
"SELECT comp_name, object_id, parent_id, record_type FROM comps WHERE parent_id=0 AND record_type=256")
"SELECT comp_name, object_id, parent_id, record_type, record FROM comps WHERE parent_id=0 AND record_type=256")
results = self._cur.fetchall()
if len(results) != 1:
raise Exception("Does not contain exactly one root controller node")
serial_number = ""
path = ""
try:
r = RxController.from_bytes(results[0][4])
serial_number = hex(r.body.serial_number)
if r.record_format_version == 103:
path = r.body.path
except:
pass

self._object_id = results[0][1]
controller_name = results[0][0]
Expand Down Expand Up @@ -337,7 +351,7 @@ def build(self) -> Controller:
_aoi_object_id = result[1]
aois.append(AoiBuilder(self._cur, _aoi_object_id).build())

return Controller(controller_name, data_types, tags, programs, aois)
return Controller(controller_name, serial_number, path, data_types, tags, programs, aois)

@dataclass
class DumpCompsRecords(L5xElementBuilder):
Expand Down
Loading

0 comments on commit ee90d19

Please sign in to comment.