From 933d910ccf0ba050d76a7f44f998c2fe83260135 Mon Sep 17 00:00:00 2001 From: ebroecker Date: Mon, 5 Nov 2018 20:21:31 +0100 Subject: [PATCH 1/4] fix for #226 fix for missing "putSignalIntoFrame" --- src/canmatrix/arxml.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/canmatrix/arxml.py b/src/canmatrix/arxml.py index 6638d8db..96a19ac4 100644 --- a/src/canmatrix/arxml.py +++ b/src/canmatrix/arxml.py @@ -1200,12 +1200,22 @@ def getSignals(signalarray, Bo, xmlRoot, ns, multiplexId, float_factory): newSig.addValues(1, "TRUE") newSig.addValues(0, "FALSE") + def guessValue(textValue): + """ + returns a numerical value for common strings. + method is far from complete but helping with odd arxmls + :param textValue: value in text like "true" + :return: string for value like "1" + """ + textValue = textValue.lower() + if textValue in ["false", "off"]: + return "0" + elif textValue in ["true", "on"]: + return "1" + return textValue if initvalue is not None and initvalue.text is not None: - if initvalue.text == "false": - initvalue.text = "0" - elif initvalue.text == "true": - initvalue.text = "1" + initvalue.text = guessValue(initvalue.text) newSig._initValue = int(initvalue.text) newSig.addAttribute("GenSigStartValue", str(newSig._initValue)) else: @@ -1646,19 +1656,11 @@ def load(file, **options): db.addEcu(bu) - for bo in db.frames: - frame = 0 - for sig in bo.signals: - if sig._initValue != 0: - stbit = sig.getStartbit(bitNumbering=1, startLittle=True) - frame |= computeSignalValueInFrame( - sig.getStartbit( - bitNumbering=1, - startLittle=True), - sig.size, - sig.is_little_endian, - sig._initValue) - fmt = "%0" + "%d" % bo.size + "X" - bo.addAttribute("GenMsgStartValue", fmt % frame) + for frame in db.frames: + sig_value_hash = dict() + for sig in frame.signals: + sig_value_hash[sig.name] = sig._initValue + frameData = frame.encode(sig_value_hash) + frame.addAttribute("GenMsgStartValue", "".join(["%02x" % x for x in frameData])) result[busname] = db return result From 5dc129b5181c0cc9c60993db1bbf93d3f1702314 Mon Sep 17 00:00:00 2001 From: ebroecker Date: Mon, 5 Nov 2018 21:04:40 +0100 Subject: [PATCH 2/4] add long names from isignals to sig_attrib["LongName"] #201 --- src/canmatrix/arxml.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/canmatrix/arxml.py b/src/canmatrix/arxml.py index 96a19ac4..37c117e0 100644 --- a/src/canmatrix/arxml.py +++ b/src/canmatrix/arxml.py @@ -1029,7 +1029,11 @@ def getSignals(signalarray, Bo, xmlRoot, ns, multiplexId, float_factory): Bo.name,arGetChild(signal,"SHORT-NAME",xmlRoot,ns).text) baseType = arGetChild(isignal,"BASE-TYPE", xmlRoot, ns) - + sig_long_name = arGetChild(isignal, "LONG-NAME", xmlRoot, ns) + if sig_long_name is not None: + sig_long_name = arGetChild(sig_long_name, "L-4", xmlRoot, ns) + if sig_long_name is not None: + sig_long_name = sig_long_name.text syssignal = arGetChild(isignal, "SYSTEM-SIGNAL", xmlRoot, ns) if syssignal is None: logger.debug('Frame %s, signal %s has no systemsignal',isignal.tag,Bo.name) @@ -1223,6 +1227,8 @@ def guessValue(textValue): for key, value in list(values.items()): newSig.addValues(key, value) + if sig_long_name is not None: + newSig.addAttribute("LongName", sig_long_name) Bo.addSignal(newSig) @@ -1405,7 +1411,6 @@ def getDesc(element, arDict, ns): else: return "" - def processEcu(ecu, db, arDict, multiplexTranslation, ns): global pduFrameMapping connectors = arGetChild(ecu, "CONNECTORS", arDict, ns) @@ -1567,6 +1572,7 @@ def load(file, **options): # Defines not jet imported... db.addBUDefines("NWM-Stationsadresse", 'HEX 0 63') db.addBUDefines("NWM-Knoten", 'ENUM "nein","ja"') + db.addSignalDefines("LongName", 'STRING') db.addFrameDefines("GenMsgCycleTime", 'INT 0 65535') db.addFrameDefines("GenMsgDelayTime", 'INT 0 65535') db.addFrameDefines("GenMsgNrOfRepetitions", 'INT 0 65535') From c1f53091e6d7d34445b38529791621aa3fada441 Mon Sep 17 00:00:00 2001 From: ebroecker Date: Tue, 20 Nov 2018 21:26:18 +0100 Subject: [PATCH 3/4] switch to snake_case --- src/canmatrix/arxml.py | 8 ++++---- src/canmatrix/canmatrix.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/canmatrix/arxml.py b/src/canmatrix/arxml.py index 37c117e0..8283dff1 100644 --- a/src/canmatrix/arxml.py +++ b/src/canmatrix/arxml.py @@ -1204,14 +1204,14 @@ def getSignals(signalarray, Bo, xmlRoot, ns, multiplexId, float_factory): newSig.addValues(1, "TRUE") newSig.addValues(0, "FALSE") - def guessValue(textValue): + def guess_value(textValue): """ - returns a numerical value for common strings. + returns a string value for common strings. method is far from complete but helping with odd arxmls :param textValue: value in text like "true" :return: string for value like "1" """ - textValue = textValue.lower() + textValue = textValue.casefold() if textValue in ["false", "off"]: return "0" elif textValue in ["true", "on"]: @@ -1219,7 +1219,7 @@ def guessValue(textValue): return textValue if initvalue is not None and initvalue.text is not None: - initvalue.text = guessValue(initvalue.text) + initvalue.text = guess_value(initvalue.text) newSig._initValue = int(initvalue.text) newSig.addAttribute("GenSigStartValue", str(newSig._initValue)) else: diff --git a/src/canmatrix/canmatrix.py b/src/canmatrix/canmatrix.py index 4a64d044..32f3d2fe 100644 --- a/src/canmatrix/canmatrix.py +++ b/src/canmatrix/canmatrix.py @@ -51,7 +51,7 @@ import struct from past.builtins import basestring -import copy +import canmatrix.copy as copy class ExceptionTemplate(Exception): From 0e52bf80d81574f8beb78f19516cd5f4ed8261f1 Mon Sep 17 00:00:00 2001 From: ebroecker Date: Tue, 20 Nov 2018 21:50:50 +0100 Subject: [PATCH 4/4] revert import copy --- src/canmatrix/canmatrix.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/canmatrix/canmatrix.py b/src/canmatrix/canmatrix.py index 32f3d2fe..28ca21aa 100644 --- a/src/canmatrix/canmatrix.py +++ b/src/canmatrix/canmatrix.py @@ -51,7 +51,7 @@ import struct from past.builtins import basestring -import canmatrix.copy as copy +import copy class ExceptionTemplate(Exception):