Skip to content

Commit

Permalink
fix writing octet to eds files and adding/moving objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpdx committed Feb 22, 2023
1 parent c3e7361 commit 6318b53
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
12 changes: 6 additions & 6 deletions eds_utils/core/eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,17 +350,17 @@ def copy_object(self, index: int, subindex: int, new_index: int, new_subindex: i
move: bool = False):
'''Move or copy an object in the OD'''

if index not in self._data:
if index not in self.indexes:
raise EDSError(f'no object exists at index 0x{index:X}')
if subindex is not None and subindex not in self._data[index]:
if subindex is not None and subindex not in self._data[index].subindexes:
raise EDSError(f'no object exists at index 0x{index:X} subindex 0x{subindex:02X}')

if new_subindex is None and new_index in self._data:
raise EDSError(f'object already exist at index 0x{new_index:X}')
if new_subindex is not None:
if isinstance(self._data[new_index], Variable):
raise EDSError('cannot move an object to a subindex of an Variable')
if new_subindex in self._data[new_index]:
if new_subindex in self._data[new_index].subindexes:
raise EDSError(f'object already exist at index 0x{new_index:X} subindex '
f'0x{new_subindex:02X}')

Expand All @@ -372,10 +372,10 @@ def copy_object(self, index: int, subindex: int, new_index: int, new_subindex: i
if new_subindex is None:
self._data[new_index] = obj
else:
self._eds[new_index][new_subindex] = obj
self._data[new_index][new_subindex] = obj

if move:
if new_subindex is None:
if subindex is None:
del self._data[index]
else:
del self._eds[index][subindex]
del self._data[index][subindex]
2 changes: 1 addition & 1 deletion eds_utils/core/file_io/write_eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def _variable_lines(variable: Variable, index: int, subindex=None, dcf=False,
if variable.default_value: # optional
if variable.data_type == DataType.OCTET_STRING:
value_ns = variable.default_value.replace(' ', '')
tmp = [value_ns[i: i + 2] for i in range(0, len(value_ns), 2)]
tmp = ' '.join([value_ns[i: i + 2] for i in range(0, len(value_ns), 2)])
lines.append(f'DefaultValue={tmp}')
else:
lines.append(f'DefaultValue={variable.default_value}')
Expand Down
3 changes: 2 additions & 1 deletion eds_utils/eds_editor/dialogs/add_object_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def __init__(self, parent: Gtk.Window, eds: EDS):
label = Gtk.Label(label='Index:')
label.set_halign(Gtk.Align.START)
self._index_entry = Gtk.Entry()
self._index_entry.set_text('0x1000')
max_index = eds.indexes[-1]
self._index_entry.set_text(f'0x{max_index + 1:04X}')
grid.attach(label, column=0, row=1, width=1, height=1)
grid.attach(self._index_entry, column=1, row=1, width=1, height=1)

Expand Down
2 changes: 0 additions & 2 deletions eds_utils/eds_editor/dialogs/copy_object_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ def __init__(self, parent: Gtk.Window, eds: EDS, index: int, subindex: int = Non
self.subindex_entry = Gtk.Entry()
if self.subindex is not None:
self.subindex_entry.set_text(f'0x{self.subindex:02X}')
else:
self.subindex_entry.set_text(f'0x{0:02X}')
grid.attach(label, column=2, row=1, width=1, height=1)
grid.attach(self.subindex_entry, column=3, row=1, width=1, height=1)

Expand Down
2 changes: 1 addition & 1 deletion eds_utils/eds_editor/pages/object_dictionary_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def add_treeview_object_response(self, dialog: Gtk.Dialog, response: int):
self._eds[new_index] = obj
else:
obj = Variable()
if new_obj_type == ObjectType.ARRAY:
if isinstance(self._eds[new_index], Array):
# all data types in arrays must match
obj.data_type = self._eds[new_index].data_type
self._eds[new_index][new_subindex] = obj
Expand Down

0 comments on commit 6318b53

Please sign in to comment.