From bc4c8ae7c4b9d0299b5665f01a73ca59bde805b0 Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Mon, 19 Feb 2024 15:11:07 +0100 Subject: [PATCH] consider review comments thanks to [at]kayoub5, as usual! Signed-off-by: Andreas Lauser Signed-off-by: Gerrit Ecke --- odxtools/dynamiclengthfield.py | 16 ++++++++-------- odxtools/encodestate.py | 6 +++--- odxtools/parameters/parameter.py | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/odxtools/dynamiclengthfield.py b/odxtools/dynamiclengthfield.py index 2bf8b809..7001a0df 100644 --- a/odxtools/dynamiclengthfield.py +++ b/odxtools/dynamiclengthfield.py @@ -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 @@ -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 diff --git a/odxtools/encodestate.py b/odxtools/encodestate.py index 2d39d7aa..6b6154b2 100644 --- a/odxtools/encodestate.py +++ b/odxtools/encodestate.py @@ -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) @@ -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, ) diff --git a/odxtools/parameters/parameter.py b/odxtools/parameters/parameter.py index 470f8572..932c08f3 100644 --- a/odxtools/parameters/parameter.py +++ b/odxtools/parameters/parameter.py @@ -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