Skip to content

Commit

Permalink
[WIP] - Refactoring Snail case (#292)
Browse files Browse the repository at this point in the history
#236
* refactor api to snail_case
* rename BoardUnits to ecus
* fix some utils
  • Loading branch information
ebroecker authored Feb 22, 2019
1 parent 309d414 commit 4ec6fd4
Show file tree
Hide file tree
Showing 30 changed files with 877 additions and 879 deletions.
2 changes: 1 addition & 1 deletion examples/BusmasterRestbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def tickerBoardUnits(db, dbcname):

MyBuList = []

for bu in db.boardUnits:
for bu in db.ecus:
if bu.name not in MyBuList:
MyBuList.append(bu.name) # no duplicate Nodes
else:
Expand Down
8 changes: 4 additions & 4 deletions examples/createCMacros.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


def createStoreMacro(signal, prefix="", frame="frame"):
startBit = signal.getStartbit(bitNumbering=1, startLittle=1)
startBit = signal.get_startbit(bit_numbering=1, start_little=1)
byteOrder = signal.is_little_endian
length = signal.signalsize
startByte = int(startBit / 8)
Expand Down Expand Up @@ -58,7 +58,7 @@ def createStoreMacro(signal, prefix="", frame="frame"):

def createDecodeMacro(
signal, prefix="", macrosource="source", source="source"):
startBit = signal.getStartbit(bitNumbering=1, startLittle=1)
startBit = signal.get_startbit(bit_numbering=1, start_little=1)
byteOrder = signal.is_little_endian
length = signal.signalsize

Expand Down Expand Up @@ -152,9 +152,9 @@ def main():
if cmdlineOptions.exportframe is not None:
for frameId in cmdlineOptions.exportframe.split(','):
try:
frame = db.frameById(int(frameId))
frame = db.frame_by_id(int(frameId))
except ValueError:
frame = db.frameByName(frameId)
frame = db.frame_by_name(frameId)
if frame is not None:
sourceCode += createDecodeMacrosForFrame(
frame, "_" + frame.name + "_")
Expand Down
16 changes: 8 additions & 8 deletions examples/createJ1939Dbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
comment = "J1939 packet containing >8 byte payload")
for i in range(1,9):
sig = canmatrix.Signal("ch%d" % i, size = 32, is_float = True, is_little_endian = False, startBit = (i-1)*32)
frame1.addSignal(sig)
cm.addFrame(frame1)
frame1.add_signal(sig)
cm.add_frame(frame1)

#
# create frame Node605
Expand All @@ -22,9 +22,9 @@

sig = canmatrix.Signal("ch1", size=32, is_float=True, is_little_endian=False, startBit=0)
sig2 = canmatrix.Signal("ch2", size=32, is_float=True, is_little_endian=False, startBit=32)
frame2.addSignal(sig)
frame2.addSignal(sig2)
cm.addFrame(frame2)
frame2.add_signal(sig)
frame2.add_signal(sig2)
cm.add_frame(frame2)


#
Expand All @@ -34,11 +34,11 @@
j1939_source = 0x80,
comment="J1939 packet containing <8 byte payload")
sig = canmatrix.Signal("ch1", size=32, is_float=True, is_little_endian=False, startBit=0)
frame3.addSignal(sig)
cm.addFrame(frame3)
frame3.add_signal(sig)
cm.add_frame(frame3)


cm.recalcDLC("force")
cm.recalc_dlc("force")

# save dbc
canmatrix.formats.dumpp({"":cm}, "example_j1939.dbc")
106 changes: 53 additions & 53 deletions src/canmatrix/arxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def dump(dbs, f, **options):
signalRef.set('DEST', 'I-SIGNAL')

createSubElement(signalToPduMapping, 'START-POSITION',
str(signal.getStartbit(bitNumbering=1)))
str(signal.get_startbit(bit_numbering=1)))
# missing: TRANSFER-PROPERTY: PENDING/...

for group in frame.signalGroups:
Expand Down Expand Up @@ -663,7 +663,7 @@ def dump(dbs, f, **options):
elements = createSubElement(arPackage, 'ELEMENTS')
for name in dbs:
db = dbs[name]
for ecu in db.boardUnits:
for ecu in db.ecus:
ecuInstance = createSubElement(elements, 'ECU-INSTANCE')
createSubElement(ecuInstance, 'SHORT-NAME', ecu.name)
if ecu.comment:
Expand Down Expand Up @@ -961,7 +961,7 @@ def getSysSignals(syssignal, syssignalarray, Bo, Id, ns):
members = []
for signal in syssignalarray:
members.append(arGetName(signal, ns))
Bo.addSignalGroup(arGetName(syssignal, ns), 1, members)
Bo.add_signal_group(arGetName(syssignal, ns), 1, members)


def decodeCompuMethod(compuMethod, arDict, ns, float_factory):
Expand Down Expand Up @@ -1179,7 +1179,7 @@ def getSignals(signalarray, Bo, xmlRoot, ns, multiplexId, float_factory):

if startBit is not None:
newSig = Signal(name.text,
startBit=int(startBit.text),
start_bit=int(startBit.text),
size=int(length.text),
is_little_endian=is_little_endian,
is_signed=is_signed,
Expand All @@ -1198,30 +1198,30 @@ def getSignals(signalarray, Bo, xmlRoot, ns, multiplexId, float_factory):

if newSig.is_little_endian == 0:
# startbit of motorola coded signals are MSB in arxml
newSig.setStartbit(int(startBit.text), bitNumbering=1)
newSig.set_startbit(int(startBit.text), bitNumbering=1)

# save signal, to determin receiver-ECUs for this signal later
signalRxs[syssignal] = newSig

if baseType is not None:
temp = arGetChild(baseType, "SHORT-NAME", xmlRoot, ns)
if temp is not None and "boolean" == temp.text:
newSig.addValues(1, "TRUE")
newSig.addValues(0, "FALSE")
newSig.add_values(1, "TRUE")
newSig.add_values(0, "FALSE")


if initvalue is not None and initvalue.text is not None:
initvalue.text = canmatrix.utils.guess_value(initvalue.text)
newSig._initValue = int(initvalue.text)
newSig.addAttribute("GenSigStartValue", str(newSig._initValue))
newSig.add_attribute("GenSigStartValue", str(newSig._initValue))
else:
newSig._initValue = 0

for key, value in list(values.items()):
newSig.addValues(key, value)
newSig.add_values(key, value)
if sig_long_name is not None:
newSig.addAttribute("LongName", sig_long_name)
Bo.addSignal(newSig)
newSig.add_attribute("LongName", sig_long_name)
Bo.add_signal(newSig)


def getFrame(frameTriggering, xmlRoot, multiplexTranslation, ns, float_factory):
Expand Down Expand Up @@ -1251,7 +1251,7 @@ def getFrame(frameTriggering, xmlRoot, multiplexTranslation, ns, float_factory):
newFrame = Frame(arGetName(frameR, ns), id=idNum, size=int(dlc.text))
comment = getDesc(frameR, xmlRoot, ns)
if comment is not None:
newFrame.addComment(comment)
newFrame.add_comment(comment)
else:
# without frameinfo take short-name of frametriggering and dlc = 8
logger.debug("Frame %s has no FRAME-REF" % (sn))
Expand All @@ -1276,11 +1276,11 @@ def getFrame(frameTriggering, xmlRoot, multiplexTranslation, ns, float_factory):
if selectorByteOrder.text == 'MOST-SIGNIFICANT-BYTE-LAST':
is_little_endian = True
is_signed = False # unsigned
multiplexor = Signal("Multiplexor",startBit=int(selectorStart.text),size=int(selectorLen.text),
multiplexor = Signal("Multiplexor",start_bit=int(selectorStart.text),size=int(selectorLen.text),
is_little_endian=is_little_endian,multiplex="Multiplexor")

multiplexor._initValue = 0
newFrame.addSignal(multiplexor)
newFrame.add_signal(multiplexor)
staticPart = arGetChild(pdu, "STATIC-PART", xmlRoot, ns)
ipdu = arGetChild(staticPart, "I-PDU", xmlRoot, ns)
if ipdu is not None:
Expand All @@ -1307,7 +1307,7 @@ def getFrame(frameTriggering, xmlRoot, multiplexTranslation, ns, float_factory):
getSignals(pdusigmapping,newFrame,xmlRoot,ns,selectorId.text, float_factory)

if newFrame.comment is None:
newFrame.addComment(getDesc(pdu, xmlRoot, ns))
newFrame.add_comment(getDesc(pdu, xmlRoot, ns))

if extEle is not None:
if extEle.text == 'EXTENDED':
Expand All @@ -1328,39 +1328,39 @@ def getFrame(frameTriggering, xmlRoot, multiplexTranslation, ns, float_factory):
timePeriod = arGetChild(cyclicTiming, "TIME-PERIOD", xmlRoot, ns)

if cyclicTiming is not None and eventTiming is not None:
newFrame.addAttribute("GenMsgSendType", "cyclicAndSpontanX") # CycleAndSpontan
newFrame.add_attribute("GenMsgSendType", "cyclicAndSpontanX") # CycleAndSpontan
if minimumDelay is not None:
newFrame.addAttribute("GenMsgDelayTime", str(int(float_factory(minimumDelay.text) * 1000)))
newFrame.add_attribute("GenMsgDelayTime", str(int(float_factory(minimumDelay.text) * 1000)))
if repeats is not None:
newFrame.addAttribute("GenMsgNrOfRepetitions", repeats.text)
newFrame.add_attribute("GenMsgNrOfRepetitions", repeats.text)
elif cyclicTiming is not None:
newFrame.addAttribute("GenMsgSendType", "cyclicX") # CycleX
newFrame.add_attribute("GenMsgSendType", "cyclicX") # CycleX
if minimumDelay is not None:
newFrame.addAttribute("GenMsgDelayTime", str(int(float_factory(minimumDelay.text) * 1000)))
newFrame.add_attribute("GenMsgDelayTime", str(int(float_factory(minimumDelay.text) * 1000)))
if repeats is not None:
newFrame.addAttribute("GenMsgNrOfRepetitions", repeats.text)
newFrame.add_attribute("GenMsgNrOfRepetitions", repeats.text)
else:
newFrame.addAttribute("GenMsgSendType", "spontanX") # Spontan
newFrame.add_attribute("GenMsgSendType", "spontanX") # Spontan
if minimumDelay is not None:
newFrame.addAttribute("GenMsgDelayTime", str(int(float_factory(minimumDelay.text) * 1000)))
newFrame.add_attribute("GenMsgDelayTime", str(int(float_factory(minimumDelay.text) * 1000)))
if repeats is not None:
newFrame.addAttribute("GenMsgNrOfRepetitions", repeats.text)
newFrame.add_attribute("GenMsgNrOfRepetitions", repeats.text)

if startingTime is not None:
value = arGetChild(startingTime, "VALUE", xmlRoot, ns)
newFrame.addAttribute("GenMsgStartDelayTime",str(int(float_factory(value.text) * 1000)))
newFrame.add_attribute("GenMsgStartDelayTime", str(int(float_factory(value.text) * 1000)))
elif cyclicTiming is not None:
value = arGetChild(timeOffset, "VALUE", xmlRoot, ns)
if value is not None:
newFrame.addAttribute("GenMsgStartDelayTime",str(int(float_factory(value.text) * 1000)))
newFrame.add_attribute("GenMsgStartDelayTime", str(int(float_factory(value.text) * 1000)))

value = arGetChild(repeatingTime, "VALUE", xmlRoot, ns)
if value is not None:
newFrame.addAttribute("GenMsgCycleTime",str(int(float_factory(value.text) * 1000)))
newFrame.add_attribute("GenMsgCycleTime", str(int(float_factory(value.text) * 1000)))
elif cyclicTiming is not None:
value = arGetChild(timePeriod, "VALUE", xmlRoot, ns)
if value is not None:
newFrame.addAttribute("GenMsgCycleTime",str(int(float_factory(value.text) * 1000)))
newFrame.add_attribute("GenMsgCycleTime", str(int(float_factory(value.text) * 1000)))


# pdusigmappings = arGetChild(pdu, "SIGNAL-TO-PDU-MAPPINGS", arDict, ns)
Expand Down Expand Up @@ -1471,9 +1471,9 @@ def processEcu(ecu, db, arDict, multiplexTranslation, ns):
for out in outFrame:
if out in multiplexTranslation:
out = multiplexTranslation[out]
frame = db.frameByName(out)
frame = db.frame_by_name(out)
if frame is not None:
frame.addTransmitter(arGetName(ecu, ns))
frame.add_transmitter(arGetName(ecu, ns))
else:
pass

Expand All @@ -1488,13 +1488,13 @@ def processEcu(ecu, db, arDict, multiplexTranslation, ns):
# signal.receiver.append(recname)
# else:
# print "in not found: " + inf
bu = BoardUnit(arGetName(ecu, ns))
bu = ecu(arGetName(ecu, ns))
if nmAddress is not None:
bu.addAttribute("NWM-Stationsadresse", nmAddress.text)
bu.addAttribute("NWM-Knoten", "ja")
bu.add_attribute("NWM-Stationsadresse", nmAddress.text)
bu.add_attribute("NWM-Knoten", "ja")
else:
bu.addAttribute("NWM-Stationsadresse", "0")
bu.addAttribute("NWM-Knoten", "nein")
bu.add_attribute("NWM-Stationsadresse", "0")
bu.add_attribute("NWM-Knoten", "nein")
return bu

def ecuc_extract_signal(signal_node, ns):
Expand Down Expand Up @@ -1522,7 +1522,7 @@ def ecuc_extract_signal(signal_node, ns):
signal_type = (attribute.getparent().find(".//" +ns + "VALUE").text)
if attribute.text.endswith("ComTimeout"):
timeout = int(attribute.getparent().find(".//" +ns + "VALUE").text)
return canmatrix.Signal(arGetName(signal_node,ns), startBit = start_bit, size=size, is_little_endian = is_little)
return canmatrix.Signal(arGetName(signal_node,ns), start_bit = start_bit, size=size, is_little_endian = is_little)

def extract_cm_from_ecuc(com_module, search_point, ns):
db = CanMatrix()
Expand All @@ -1531,16 +1531,16 @@ def extract_cm_from_ecuc(com_module, search_point, ns):
if definition.text.endswith("ComIPdu"):
container = definition.getparent()
frame = canmatrix.Frame(arGetName(container, ns))
db.addFrame(frame)
db.add_frame(frame)
allReferences = arGetChildren(container,"ECUC-REFERENCE-VALUE",search_point,ns)
for reference in allReferences:
value = arGetChild(reference,"VALUE",search_point,ns)
if value is not None:
signal_definition = value.find('./' + ns + "DEFINITION-REF")
if signal_definition.text.endswith("ComSignal"):
signal = ecuc_extract_signal(value,ns)
frame.addSignal(signal)
db.recalcDLC(strategy = "max")
frame.add_signal(signal)
db.recalc_dlc(strategy = "max")
return {"": db}

def load(file, **options):
Expand Down Expand Up @@ -1616,18 +1616,18 @@ def load(file, **options):
for cc in ccs:
db = CanMatrix()
# 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')
db.addFrameDefines("GenMsgStartValue", 'STRING')
db.addFrameDefines("GenMsgStartDelayTime", 'INT 0 65535')
db.addFrameDefines(
db.add_ecu_defines("NWM-Stationsadresse", 'HEX 0 63')
db.add_ecu_defines("NWM-Knoten", 'ENUM "nein","ja"')
db.add_signal_defines("LongName", 'STRING')
db.add_frame_defines("GenMsgCycleTime", 'INT 0 65535')
db.add_frame_defines("GenMsgDelayTime", 'INT 0 65535')
db.add_frame_defines("GenMsgNrOfRepetitions", 'INT 0 65535')
db.add_frame_defines("GenMsgStartValue", 'STRING')
db.add_frame_defines("GenMsgStartDelayTime", 'INT 0 65535')
db.add_frame_defines(
"GenMsgSendType",
'ENUM "cyclicX","spontanX","cyclicIfActiveX","spontanWithDelay","cyclicAndSpontanX","cyclicAndSpontanWithDelay","spontanWithRepitition","cyclicIfActiveAndSpontanWD","cyclicIfActiveFast","cyclicWithRepeatOnDemand","none"')
db.addSignalDefines("GenSigStartValue", 'HEX 0 4294967295')
db.add_signal_defines("GenSigStartValue", 'HEX 0 4294967295')

if ignoreClusterInfo == True:
canframetrig = root.findall('.//' + ns + 'CAN-FRAME-TRIGGERING')
Expand Down Expand Up @@ -1666,7 +1666,7 @@ def load(file, **options):
for frameTrig in canframetrig:
frameObject = getFrame(frameTrig,searchPoint,multiplexTranslation,ns, float_factory)
if frameObject is not None:
db.addFrame(frameObject)
db.add_frame(frameObject)

if ignoreClusterInfo == True:
pass
Expand Down Expand Up @@ -1706,15 +1706,15 @@ def load(file, **options):
desc = arGetChild(node, "DESC", searchPoint, ns)
l2 = arGetChild(desc, "L-2", searchPoint, ns)
if l2 is not None:
bu.addComment(l2.text)
bu.add_comment(l2.text)

db.addEcu(bu)
db.add_ecu(bu)

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]))
frame.add_attribute("GenMsgStartValue", "".join(["%02x" % x for x in frameData]))
result[busname] = db
return result
8 changes: 4 additions & 4 deletions src/canmatrix/cancluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def updateFrames(self):
else:
index = frameArrayName.index(frame.name)
for transmitter in frame.transmitters:
frameArray[index].addTransmitter(transmitter)
frameArray[index].add_transmitter(transmitter)
for receiver in frame.receiver:
frameArray[index].addReceiver(receiver)
frameArray[index].add_receiver(receiver)
self._frames = frameArray
return frameArray

Expand All @@ -33,14 +33,14 @@ def updateSignals(self):
else:
index = signalArrayName.index(signal.name)
for receiver in signal.receiver:
signalArray[index].addReceiver(receiver)
signalArray[index].add_receiver(receiver)
self._signals = signalArray

def updateECUs(self):
ECUArray = []
ECUArrayName = []
for matrixName in self:
for ecu in self[matrixName].boardUnits:
for ecu in self[matrixName].ecus:
if ecu.name not in ECUArrayName:
ECUArrayName.append(ecu.name)
ECUArray.append(ecu)
Expand Down
Loading

0 comments on commit 4ec6fd4

Please sign in to comment.