-
Notifications
You must be signed in to change notification settings - Fork 404
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
[WIP] fix for #226 #247
Changes from 1 commit
933d910
5dc129b
c1f5309
0e52bf8
7b697da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
At least that's what it does presently. |
||||||
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() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
https://docs.python.org/3/library/stdtypes.html#str.casefold Though I've heard debate on their example being proper... |
||||||
if textValue in ["false", "off"]: | ||||||
return "0" | ||||||
elif textValue in ["true", "on"]: | ||||||
return "1" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know where we are on this 'officially' but do we and
lowerCamel
orsnake_case
? I'll add this to the refactor ticket to consider.#236 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... so you preferre
snake_case
. I tried to create new features insnake_case
but this time, I missed my intentThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I change the linked ticket to just state it will be 'snake_case'? I suppose that we could instead be picking an existing coding standard/checker (black, or something configurable) and that would cover many of these questions.