Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fix for #226 #247

Merged
merged 5 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 28 additions & 20 deletions src/canmatrix/arxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1200,19 +1204,31 @@ def getSignals(signalarray, Bo, xmlRoot, ns, multiplexId, float_factory):
newSig.addValues(1, "TRUE")
newSig.addValues(0, "FALSE")

def guess_value(textValue):
"""
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.casefold()
if textValue in ["false", "off"]:
return "0"
elif textValue in ["true", "on"]:
return "1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably use a dict, though I'm not certain it is 'better'. Just keep it in mind.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has the cost of being less flexible for handling situations like if you only want some things to be case insensitive etc. But either way, it's small now and could be easily readjusted either direction in the future as needed.

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 = guess_value(initvalue.text)
newSig._initValue = int(initvalue.text)
newSig.addAttribute("GenSigStartValue", str(newSig._initValue))
else:
newSig._initValue = 0

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)


Expand Down Expand Up @@ -1395,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)
Expand Down Expand Up @@ -1557,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')
Expand Down Expand Up @@ -1646,19 +1662,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
2 changes: 1 addition & 1 deletion src/canmatrix/canmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import struct

from past.builtins import basestring
import copy
import copy


class ExceptionTemplate(Exception):
Expand Down