Skip to content

Commit

Permalink
consider review comments
Browse files Browse the repository at this point in the history
thanks to [at]kayoub5, as usual!

Signed-off-by: Andreas Lauser <[email protected]>
Signed-off-by: Gerrit Ecke <[email protected]>
  • Loading branch information
andlaus committed Feb 19, 2024
1 parent f3c151a commit bc4c8ae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions odxtools/dynamiclengthfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,26 @@ def _resolve_snrefs(self, diag_layer: "DiagLayer") -> None:

def convert_physical_to_bytes(
self,
physical_values: ParameterValue,
physical_value: ParameterValue,
encode_state: EncodeState,
bit_position: int = 0,
) -> bytes:

odxassert(bit_position == 0, "No bit position can be specified for dynamic length fields!")
if not isinstance(physical_values, list):
if not isinstance(physical_value, list):
odxraise(
f"Expected a list of values for dynamic length field {self.short_name}, "
f"got {type(physical_values)}", EncodeError)
f"got {type(physical_value)}", EncodeError)

det_num_items = self.determine_number_of_items
num_item = det_num_items.dop.convert_physical_to_bytes(
len(physical_values), encode_state, det_num_items.bit_position or 0)
field_len = det_num_items.dop.convert_physical_to_bytes(
len(physical_value), encode_state, det_num_items.bit_position or 0)

# hack to emplace the length specifier at the correct location
tmp = encode_state.coded_message
encode_state.coded_message = bytearray()
encode_state.emplace_atomic_value(num_item, det_num_items.byte_position,
self.short_name + ".num_items")
encode_state.emplace_atomic_value(field_len, self.short_name + ".num_items",
det_num_items.byte_position)
result = encode_state.coded_message
encode_state.coded_message = tmp

Expand All @@ -80,7 +80,7 @@ def convert_physical_to_bytes(
odxraise(f"The length specifier of field {self.short_name} overlaps "
f"with the first item!")

for value in physical_values:
for value in physical_value:
result += self.structure.convert_physical_to_bytes(value, encode_state)

return result
Expand Down
6 changes: 3 additions & 3 deletions odxtools/encodestate.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class EncodeState:

def emplace_atomic_value(self,
new_data: bytes,
pos: Optional[int] = None,
param_name: str = "unknown") -> None:
param_name: str,
pos: Optional[int] = None) -> None:
if pos is None:
pos = len(self.coded_message)

Expand All @@ -51,7 +51,7 @@ def emplace_atomic_value(self,
# insert byte value
if self.coded_message[byte_idx_rpc] & new_data[byte_idx_val] != 0:
warnings.warn(
f"Parameter '{param_name}' overlaps with another parameter (bytes are already set)",
f"Object '{param_name}' overlaps with another parameter (bytes are already set)",
OdxWarning,
stacklevel=1,
)
Expand Down
2 changes: 1 addition & 1 deletion odxtools/parameters/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ def encode_into_pdu(self, encode_state: EncodeState) -> bytes:
else:
byte_position = len(msg_blob)

encode_state.emplace_atomic_value(param_blob, byte_position, self.short_name)
encode_state.emplace_atomic_value(param_blob, self.short_name, byte_position)

return encode_state.coded_message

0 comments on commit bc4c8ae

Please sign in to comment.