Skip to content

Commit

Permalink
Merge branch 'development' into eds_bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
ebroecker authored Jan 24, 2025
2 parents f72fa94 + 9a70a85 commit 2d5eafc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
22 changes: 16 additions & 6 deletions src/canmatrix/canmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 12 additions & 6 deletions src/canmatrix/formats/arxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions src/canmatrix/formats/ldf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/canmatrix/formats/xls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand Down

0 comments on commit 2d5eafc

Please sign in to comment.