Skip to content

Commit 6920ddb

Browse files
committed
make SOME/IP at least work a bit #238
1 parent 8e00681 commit 6920ddb

File tree

5 files changed

+75
-25
lines changed

5 files changed

+75
-25
lines changed

src/canmatrix/canmatrix.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,8 @@ class Frame(object):
836836
# ('sendType', '_sendType', str, None),
837837

838838
pdus = attr.ib(factory=list) # type: typing.MutableSequence[Pdu]
839-
839+
header_id = attr.ib(default=None) #type: int
840+
# header_id
840841

841842
@property
842843
def is_multiplexed(self): # type: () -> bool
@@ -1501,6 +1502,12 @@ def update(self): # type: () -> None
15011502
return
15021503
self.definition = 'ENUM "' + '","' .join(self.values) +'"'
15031504

1505+
import enum
1506+
1507+
class matrix_class(enum.Enum):
1508+
CAN = 1
1509+
FLEXRAY = 2
1510+
SOMEIP = 3
15041511

15051512
@attr.s(cmp=False)
15061513
class CanMatrix(object):
@@ -1516,6 +1523,7 @@ class CanMatrix(object):
15161523
value_tables (global defined values)
15171524
"""
15181525

1526+
type = attr.ib(default=matrix_class.CAN) #type: matrix_class
15191527
attributes = attr.ib(factory=dict) # type: typing.MutableMapping[str, typing.Any]
15201528
ecus = attr.ib(factory=list) # type: typing.MutableSequence[Ecu]
15211529
frames = attr.ib(factory=list) # type: typing.MutableSequence[Frame]

src/canmatrix/formats/arxml.py

+33-7
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ def get_signals(signal_array, frame, ea, multiplex_id, float_factory, bit_offset
11071107
if compu_method is None and datdefprops is not None:
11081108
compu_method = ea.follow_ref(datdefprops, "COMPU-METHOD-REF")
11091109
if compu_method is None: # AR4
1110-
compu_method = ea.get_child(isignal, "COMPU-METHOD")
1110+
compu_method = ea.follow_ref(isignal, "COMPU-METHOD-REF")
11111111
base_type = ea.follow_ref(isignal, "BASE-TYPE-REF")
11121112
encoding = ea.get_child(base_type, "BASE-TYPE-ENCODING")
11131113
if encoding is not None and encoding.text == "IEEE754":
@@ -1128,7 +1128,7 @@ def get_signals(signal_array, frame, ea, multiplex_id, float_factory, bit_offset
11281128
#####################################################################################################
11291129
if compu_method is None:
11301130
logger.debug('No Compmethod found!! - fuzzy search in syssignal.')
1131-
compu_method = ea.get_child(system_signal, "COMPU-METHOD")
1131+
compu_method = ea.follow_ref(system_signal, "COMPU-METHOD-REF")
11321132

11331133
# decode compuMethod:
11341134
(values, factor, offset, unit_elem, const) = decode_compu_method(compu_method, ea, float_factory)
@@ -1664,25 +1664,51 @@ def extract_cm_from_ecuc(com_module, ea):
16641664

16651665
def decode_ethernet_helper(ea, float_factory):
16661666
found_matrixes = {}
1667+
1668+
socket_connetions = ea.findall("SOCKET-CONNECTION-IPDU-IDENTIFIER")
1669+
pdu_triggering_header_id_map = {}
1670+
# network_endpoints = pc.findall('.//' + ns + "NETWORK-ENDPOINT")
1671+
for socket_connetion in socket_connetions:
1672+
header_id = ea.get_child(socket_connetion, "HEADER-ID")
1673+
ipdu_triggering = ea.follow_ref(socket_connetion, "PDU-TRIGGERING-REF")
1674+
try:
1675+
pdu_triggering_header_id_map[ipdu_triggering] = header_id.text
1676+
except:
1677+
pass
1678+
1679+
16671680
ecs = ea.findall('ETHERNET-CLUSTER')
16681681
for ec in ecs:
16691682
baudrate_elem = ea.find("BAUDRATE", ec)
16701683
physical_channels = ea.findall("ETHERNET-PHYSICAL-CHANNEL", ec)
16711684
for pc in physical_channels:
1672-
db = canmatrix.CanMatrix()
1685+
db = canmatrix.CanMatrix(type=canmatrix.matrix_class.SOMEIP)
16731686
db.baudrate = baudrate_elem.text if baudrate_elem is not None else 0
16741687
db.add_signal_defines("LongName", 'STRING')
16751688
channel_name = ea.get_element_name(pc)
16761689
found_matrixes[channel_name] = db
1677-
ipdu_triggerings = ea.findall("PDU-TRIGGERING", pc)
16781690

1679-
#network_endpoints = pc.findall('.//' + ns + "NETWORK-ENDPOINT")
1680-
for ipdu_triggering in ipdu_triggerings:
1691+
for socket_connetion in ea.findall("SOCKET-CONNECTION-IPDU-IDENTIFIER", pc):
1692+
header_id = ea.get_child(socket_connetion, "HEADER-ID")
1693+
ipdu_triggering = ea.follow_ref(socket_connetion, "PDU-TRIGGERING-REF")
1694+
# for ipdu_triggering in ea.findall("PDU-TRIGGERING", pc):
16811695
ipdu = ea.follow_ref(ipdu_triggering, "I-PDU-REF")
1696+
if ipdu is not None and 'SECURED-I-PDU' in ipdu.tag:
1697+
payload = ea.follow_ref(ipdu, "PAYLOAD-REF")
1698+
ipdu = ea.follow_ref(payload, "I-PDU-REF")
1699+
16821700
ipdu_name = ea.get_element_name(ipdu)
16831701
logger.info("ETH PDU " + ipdu_name + " found")
16841702
target_frame = canmatrix.Frame(name = ipdu_name)
1685-
pdu_sig_mapping = ea.follow_all_ref(ipdu, "I-SIGNAL-TO-I-PDU-MAPPING-REF")
1703+
try:
1704+
target_frame.header_id = int(header_id.text)
1705+
except:
1706+
try:
1707+
target_frame.header_id = int(pdu_triggering_header_id_map[ipdu_triggering])
1708+
except:
1709+
target_frame.header_id = 0
1710+
# continue
1711+
pdu_sig_mapping = ea.findall("I-SIGNAL-TO-I-PDU-MAPPING", ipdu)
16861712
get_signals(pdu_sig_mapping, target_frame, ea, None, float_factory)
16871713
db.add_frame(target_frame)
16881714
return found_matrixes

src/canmatrix/formats/xls.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,22 @@ def dump(db, file, **options):
172172
worksheet.col(head_start + 1).width = 5555
173173

174174
frame_hash = {}
175-
logger.debug("Length of db.frames is %d", len(db.frames))
176-
for frame in db.frames:
177-
if frame.is_complex_multiplexed:
178-
logger.error("export complex multiplexers is not supported - ignoring frame %s", frame.name)
179-
continue
180-
frame_hash[int(frame.arbitration_id.id)] = frame
175+
if db.type == canmatrix.matrix_class.CAN:
176+
logger.debug("Length of db.frames is %d", len(db.frames))
177+
for frame in db.frames:
178+
if frame.is_complex_multiplexed:
179+
logger.error("export complex multiplexers is not supported - ignoring frame %s", frame.name)
180+
continue
181+
frame_hash[int(frame.arbitration_id.id)] = frame
182+
else:
183+
frame_hash = {a.name:a for a in db.frames}
184+
181185

182186
# set row to first Frame (row = 0 is header)
183187
row = 1
184188

189+
190+
185191
# iterate over the frames
186192
for idx in sorted(frame_hash.keys()):
187193

src/canmatrix/formats/xls_common.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,18 @@
3030
def get_frame_info(db, frame):
3131
# type: (canmatrix.CanMatrix, canmatrix.Frame) -> typing.List[str]
3232
ret_array = [] # type: typing.List[str]
33-
# frame-id
34-
if frame.arbitration_id.extended:
35-
ret_array.append("%3Xxh" % frame.arbitration_id.id)
36-
else:
37-
ret_array.append("%3Xh" % frame.arbitration_id.id)
33+
34+
if db.type == canmatrix.matrix_class.CAN:
35+
# frame-id
36+
if frame.arbitration_id.extended:
37+
ret_array.append("%3Xxh" % frame.arbitration_id.id)
38+
else:
39+
ret_array.append("%3Xh" % frame.arbitration_id.id)
40+
elif db.type == canmatrix.matrix_class.FLEXRAY:
41+
ret_array.append("TODO")
42+
elif db.type == canmatrix.matrix_class.SOMEIP:
43+
ret_array.append("%3Xh" % frame.header_id)
44+
3845
# frame-Name
3946
ret_array.append(frame.name)
4047

src/canmatrix/formats/xlsx.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,15 @@ def dump(db, filename, **options):
195195

196196
write_excel_line(worksheet, 0, 0, row_array, sty_header)
197197

198-
frame_hash = {}
199-
logger.debug("DEBUG: Length of db.frames is %d", len(db.frames))
200-
for frame in db.frames:
201-
if frame.is_complex_multiplexed:
202-
logger.error("Export complex multiplexers is not supported - frame %s might be uncomplete", frame.name)
203-
frame_hash[int(frame.arbitration_id.id)] = frame
198+
if db.type == canmatrix.matrix_class.CAN:
199+
frame_hash = {}
200+
logger.debug("DEBUG: Length of db.frames is %d", len(db.frames))
201+
for frame in db.frames:
202+
if frame.is_complex_multiplexed:
203+
logger.error("Export complex multiplexers is not supported - frame %s might be uncomplete", frame.name)
204+
frame_hash[int(frame.arbitration_id.id)] = frame
205+
else:
206+
frame_hash = {a.name:a for a in db.frames}
204207

205208
# set row to first Frame (row = 0 is header)
206209
row = 1

0 commit comments

Comments
 (0)