diff --git a/src/canmatrix/canmatrix.py b/src/canmatrix/canmatrix.py index f88f5a53..b1c50759 100644 --- a/src/canmatrix/canmatrix.py +++ b/src/canmatrix/canmatrix.py @@ -191,7 +191,7 @@ class Signal(object): cycle_time = attr.ib(default=0) # type: int initial_value = attr.ib(converter=float_factory, default=float_factory(0.0)) # type: canmatrix.types.PhysicalValue - + scale_ranges = attr.ib(factory=list) min = attr.ib( converter=lambda value, float_factory=float_factory: ( float_factory(value) @@ -1793,7 +1793,7 @@ class CanMatrix(object): frames_dict_name = attr.ib(factory=dict) # type: typing.MutableSequence[Frame] frames_dict_id = attr.ib(factory=dict) # type: typing.MutableSequence[Frame] - + _frames_dict_id_extend = {} signal_defines = attr.ib(factory=dict) # type: typing.MutableMapping[str, Define] frame_defines = attr.ib(factory=dict) # type: typing.MutableMapping[str, Define] global_defines = attr.ib(factory=dict) # type: typing.MutableMapping[str, Define] @@ -1985,10 +1985,16 @@ def frame_by_id(self, arbitration_id): # type: (ArbitrationId) -> typing.Union[ :param ArbitrationId arbitration_id: Frame id as canmatrix.ArbitrationId :rtype: Frame or None """ - for test in self.frames: - if test.arbitration_id == arbitration_id: + hash_name = f"{arbitration_id.id}_{arbitration_id.extended}" + + frame = self._frames_dict_id_extend.get(hash_name, None) + if frame is not None: + return frame + for frame in self.frames: + if frame.arbitration_id == arbitration_id: # found ID while ignoring extended or standard - return test + self._frames_dict_id_extend[hash_name] = frame + return frame return None def frame_by_header_id(self, header_id): # type: (HeaderId) -> typing.Union[Frame, None] @@ -2090,7 +2096,7 @@ def add_frame(self, frame): # type: (Frame) -> Frame :return: the inserted Frame """ self.frames.append(frame) - + self._frames_dict_id_extend = {} self.frames_dict_name[frame.name] = frame if frame.header_id: self.frames_dict_id[frame.header_id] = frame @@ -2105,6 +2111,7 @@ def remove_frame(self, frame): # type: (Frame) -> None :param Frame frame: frame to remove from CAN Matrix """ self.frames.remove(frame) + self._frames_dict_id_extend = {} def add_signal(self, signal): # type: (Signal) -> Signal """ @@ -2199,6 +2206,8 @@ def add_ecu(self, ecu): # type(Ecu) -> None # todo return Ecu? if bu.name.strip() == ecu.name: return self.ecus.append(ecu) + self._frames_dict_id_extend = {} + def del_ecu(self, ecu_or_glob): # type: (typing.Union[Ecu, str]) -> None """Remove ECU from Matrix and all Frames. @@ -2369,6 +2378,7 @@ def merge(self, mergeArray): # type: (typing.Sequence[CanMatrix]) -> None else: logger.error( "Name Conflict, could not copy/merge EnvVar " + envVar) + self._frames_dict_id_extend = {} def set_fd_type(self) -> None: """Try to guess and set the CAN type for every frame. diff --git a/src/canmatrix/formats/arxml.py b/src/canmatrix/formats/arxml.py index bff1970e..717c907a 100644 --- a/src/canmatrix/formats/arxml.py +++ b/src/canmatrix/formats/arxml.py @@ -1960,18 +1960,20 @@ def decode_ethernet_helper(ea, float_factory): try: target_frame.header_id = int(pdu_triggering_header_id_map[ipdu_triggering], 0) except: - target_frame.header_id = 0 - # continue - + pass + + # In Case Neither transmitter Nor receiver if comm_direction.text == "OUT": target_frame.add_transmitter(ecu.name) - else: + elif comm_direction.text == "IN": target_frame.add_receiver(ecu.name) + else: + pass pdu_sig_mapping = ea.findall("I-SIGNAL-TO-I-PDU-MAPPING", ipdu) get_signals(pdu_sig_mapping, target_frame, ea, None, float_factory) - target_frame.update_receiver() + # target_frame.update_receiver() # It will make transmitter and receiver worse db.add_frame(target_frame) return found_matrixes @@ -2089,10 +2091,14 @@ def decode_can_helper(ea, float_factory, ignore_cluster_info): else: ecu = process_ecu(ecu_elem, ea) nodes[ecu_elem] = ecu + + # In Case Neither transmitter Nor receiver if comm_direction.text == "OUT": frame.add_transmitter(ecu.name) - else: + elif comm_direction.text == "IN": frame.add_receiver(ecu.name) + else: + pass db.add_ecu(ecu) db.add_frame(frame) for frame in db.frames: diff --git a/src/canmatrix/formats/ldf.py b/src/canmatrix/formats/ldf.py index 51de6da8..7b4ba715 100644 --- a/src/canmatrix/formats/ldf.py +++ b/src/canmatrix/formats/ldf.py @@ -25,6 +25,12 @@ def load(f, **options): # type: (typing.IO, **typing.Any) -> canmatrix.CanMatri if isinstance(converter, ldfparser.encoding.LogicalValue): cm_signal.add_values(converter.phy_value, converter.info) if isinstance(converter, ldfparser.encoding.PhysicalValue): + cm_signal.scale_ranges.append({ + "min" : converter.phy_min, + "max" : converter.phy_max, + "factor" : converter.scale, + "offset" : converter.offset, + "unit" : converter.unit}) cm_signal.offset = converter.offset cm_signal.factor = converter.scale cm_signal.unit = converter.unit diff --git a/src/canmatrix/formats/xls.py b/src/canmatrix/formats/xls.py index b25bb280..b7d2a77c 100644 --- a/src/canmatrix/formats/xls.py +++ b/src/canmatrix/formats/xls.py @@ -545,7 +545,9 @@ def load(file, **options): unit = unit.strip() new_signal.unit = unit try: - new_signal.factor = float_factory(factor) + # if prevents overwriting explicit factor (if given) + if new_signal.factor in (1, 1.0): + new_signal.factor = float_factory(factor) except: logger.warning( "Some error occurred while decoding scale of Signal %s: '%s'",