Skip to content

Commit 19fd2c5

Browse files
authored
[WIP] fix for #226 (#247)
* fix for #226 fix for missing "putSignalIntoFrame" * add long names from isignals to sig_attrib["LongName"] #201 * switch to snake_case
1 parent 38ccd16 commit 19fd2c5

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

src/canmatrix/arxml.py

+28-20
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,11 @@ def getSignals(signalarray, Bo, xmlRoot, ns, multiplexId, float_factory):
10291029
Bo.name,arGetChild(signal,"SHORT-NAME",xmlRoot,ns).text)
10301030

10311031
baseType = arGetChild(isignal,"BASE-TYPE", xmlRoot, ns)
1032-
1032+
sig_long_name = arGetChild(isignal, "LONG-NAME", xmlRoot, ns)
1033+
if sig_long_name is not None:
1034+
sig_long_name = arGetChild(sig_long_name, "L-4", xmlRoot, ns)
1035+
if sig_long_name is not None:
1036+
sig_long_name = sig_long_name.text
10331037
syssignal = arGetChild(isignal, "SYSTEM-SIGNAL", xmlRoot, ns)
10341038
if syssignal is None:
10351039
logger.debug('Frame %s, signal %s has no systemsignal',isignal.tag,Bo.name)
@@ -1200,19 +1204,31 @@ def getSignals(signalarray, Bo, xmlRoot, ns, multiplexId, float_factory):
12001204
newSig.addValues(1, "TRUE")
12011205
newSig.addValues(0, "FALSE")
12021206

1207+
def guess_value(textValue):
1208+
"""
1209+
returns a string value for common strings.
1210+
method is far from complete but helping with odd arxmls
1211+
:param textValue: value in text like "true"
1212+
:return: string for value like "1"
1213+
"""
1214+
textValue = textValue.casefold()
1215+
if textValue in ["false", "off"]:
1216+
return "0"
1217+
elif textValue in ["true", "on"]:
1218+
return "1"
1219+
return textValue
12031220

12041221
if initvalue is not None and initvalue.text is not None:
1205-
if initvalue.text == "false":
1206-
initvalue.text = "0"
1207-
elif initvalue.text == "true":
1208-
initvalue.text = "1"
1222+
initvalue.text = guess_value(initvalue.text)
12091223
newSig._initValue = int(initvalue.text)
12101224
newSig.addAttribute("GenSigStartValue", str(newSig._initValue))
12111225
else:
12121226
newSig._initValue = 0
12131227

12141228
for key, value in list(values.items()):
12151229
newSig.addValues(key, value)
1230+
if sig_long_name is not None:
1231+
newSig.addAttribute("LongName", sig_long_name)
12161232
Bo.addSignal(newSig)
12171233

12181234

@@ -1395,7 +1411,6 @@ def getDesc(element, arDict, ns):
13951411
else:
13961412
return ""
13971413

1398-
13991414
def processEcu(ecu, db, arDict, multiplexTranslation, ns):
14001415
global pduFrameMapping
14011416
connectors = arGetChild(ecu, "CONNECTORS", arDict, ns)
@@ -1557,6 +1572,7 @@ def load(file, **options):
15571572
# Defines not jet imported...
15581573
db.addBUDefines("NWM-Stationsadresse", 'HEX 0 63')
15591574
db.addBUDefines("NWM-Knoten", 'ENUM "nein","ja"')
1575+
db.addSignalDefines("LongName", 'STRING')
15601576
db.addFrameDefines("GenMsgCycleTime", 'INT 0 65535')
15611577
db.addFrameDefines("GenMsgDelayTime", 'INT 0 65535')
15621578
db.addFrameDefines("GenMsgNrOfRepetitions", 'INT 0 65535')
@@ -1646,19 +1662,11 @@ def load(file, **options):
16461662

16471663
db.addEcu(bu)
16481664

1649-
for bo in db.frames:
1650-
frame = 0
1651-
for sig in bo.signals:
1652-
if sig._initValue != 0:
1653-
stbit = sig.getStartbit(bitNumbering=1, startLittle=True)
1654-
frame |= computeSignalValueInFrame(
1655-
sig.getStartbit(
1656-
bitNumbering=1,
1657-
startLittle=True),
1658-
sig.size,
1659-
sig.is_little_endian,
1660-
sig._initValue)
1661-
fmt = "%0" + "%d" % bo.size + "X"
1662-
bo.addAttribute("GenMsgStartValue", fmt % frame)
1665+
for frame in db.frames:
1666+
sig_value_hash = dict()
1667+
for sig in frame.signals:
1668+
sig_value_hash[sig.name] = sig._initValue
1669+
frameData = frame.encode(sig_value_hash)
1670+
frame.addAttribute("GenMsgStartValue", "".join(["%02x" % x for x in frameData]))
16631671
result[busname] = db
16641672
return result

src/canmatrix/canmatrix.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
import struct
5252

5353
from past.builtins import basestring
54-
import copy
54+
import copy
5555

5656

5757
class ExceptionTemplate(Exception):

0 commit comments

Comments
 (0)