Skip to content

Commit 4ec6fd4

Browse files
authored
[WIP] - Refactoring Snail case (#292)
#236 * refactor api to snail_case * rename BoardUnits to ecus * fix some utils
1 parent 309d414 commit 4ec6fd4

30 files changed

+877
-879
lines changed

examples/BusmasterRestbus.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def tickerBoardUnits(db, dbcname):
163163

164164
MyBuList = []
165165

166-
for bu in db.boardUnits:
166+
for bu in db.ecus:
167167
if bu.name not in MyBuList:
168168
MyBuList.append(bu.name) # no duplicate Nodes
169169
else:

examples/createCMacros.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
def createStoreMacro(signal, prefix="", frame="frame"):
29-
startBit = signal.getStartbit(bitNumbering=1, startLittle=1)
29+
startBit = signal.get_startbit(bit_numbering=1, start_little=1)
3030
byteOrder = signal.is_little_endian
3131
length = signal.signalsize
3232
startByte = int(startBit / 8)
@@ -58,7 +58,7 @@ def createStoreMacro(signal, prefix="", frame="frame"):
5858

5959
def createDecodeMacro(
6060
signal, prefix="", macrosource="source", source="source"):
61-
startBit = signal.getStartbit(bitNumbering=1, startLittle=1)
61+
startBit = signal.get_startbit(bit_numbering=1, start_little=1)
6262
byteOrder = signal.is_little_endian
6363
length = signal.signalsize
6464

@@ -152,9 +152,9 @@ def main():
152152
if cmdlineOptions.exportframe is not None:
153153
for frameId in cmdlineOptions.exportframe.split(','):
154154
try:
155-
frame = db.frameById(int(frameId))
155+
frame = db.frame_by_id(int(frameId))
156156
except ValueError:
157-
frame = db.frameByName(frameId)
157+
frame = db.frame_by_name(frameId)
158158
if frame is not None:
159159
sourceCode += createDecodeMacrosForFrame(
160160
frame, "_" + frame.name + "_")

examples/createJ1939Dbc.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
comment = "J1939 packet containing >8 byte payload")
1111
for i in range(1,9):
1212
sig = canmatrix.Signal("ch%d" % i, size = 32, is_float = True, is_little_endian = False, startBit = (i-1)*32)
13-
frame1.addSignal(sig)
14-
cm.addFrame(frame1)
13+
frame1.add_signal(sig)
14+
cm.add_frame(frame1)
1515

1616
#
1717
# create frame Node605
@@ -22,9 +22,9 @@
2222

2323
sig = canmatrix.Signal("ch1", size=32, is_float=True, is_little_endian=False, startBit=0)
2424
sig2 = canmatrix.Signal("ch2", size=32, is_float=True, is_little_endian=False, startBit=32)
25-
frame2.addSignal(sig)
26-
frame2.addSignal(sig2)
27-
cm.addFrame(frame2)
25+
frame2.add_signal(sig)
26+
frame2.add_signal(sig2)
27+
cm.add_frame(frame2)
2828

2929

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

4040

41-
cm.recalcDLC("force")
41+
cm.recalc_dlc("force")
4242

4343
# save dbc
4444
canmatrix.formats.dumpp({"":cm}, "example_j1939.dbc")

src/canmatrix/arxml.py

+53-53
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def dump(dbs, f, **options):
429429
signalRef.set('DEST', 'I-SIGNAL')
430430

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

435435
for group in frame.signalGroups:
@@ -663,7 +663,7 @@ def dump(dbs, f, **options):
663663
elements = createSubElement(arPackage, 'ELEMENTS')
664664
for name in dbs:
665665
db = dbs[name]
666-
for ecu in db.boardUnits:
666+
for ecu in db.ecus:
667667
ecuInstance = createSubElement(elements, 'ECU-INSTANCE')
668668
createSubElement(ecuInstance, 'SHORT-NAME', ecu.name)
669669
if ecu.comment:
@@ -961,7 +961,7 @@ def getSysSignals(syssignal, syssignalarray, Bo, Id, ns):
961961
members = []
962962
for signal in syssignalarray:
963963
members.append(arGetName(signal, ns))
964-
Bo.addSignalGroup(arGetName(syssignal, ns), 1, members)
964+
Bo.add_signal_group(arGetName(syssignal, ns), 1, members)
965965

966966

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

11801180
if startBit is not None:
11811181
newSig = Signal(name.text,
1182-
startBit=int(startBit.text),
1182+
start_bit=int(startBit.text),
11831183
size=int(length.text),
11841184
is_little_endian=is_little_endian,
11851185
is_signed=is_signed,
@@ -1198,30 +1198,30 @@ def getSignals(signalarray, Bo, xmlRoot, ns, multiplexId, float_factory):
11981198

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

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

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

12121212

12131213
if initvalue is not None and initvalue.text is not None:
12141214
initvalue.text = canmatrix.utils.guess_value(initvalue.text)
12151215
newSig._initValue = int(initvalue.text)
1216-
newSig.addAttribute("GenSigStartValue", str(newSig._initValue))
1216+
newSig.add_attribute("GenSigStartValue", str(newSig._initValue))
12171217
else:
12181218
newSig._initValue = 0
12191219

12201220
for key, value in list(values.items()):
1221-
newSig.addValues(key, value)
1221+
newSig.add_values(key, value)
12221222
if sig_long_name is not None:
1223-
newSig.addAttribute("LongName", sig_long_name)
1224-
Bo.addSignal(newSig)
1223+
newSig.add_attribute("LongName", sig_long_name)
1224+
Bo.add_signal(newSig)
12251225

12261226

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

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

13091309
if newFrame.comment is None:
1310-
newFrame.addComment(getDesc(pdu, xmlRoot, ns))
1310+
newFrame.add_comment(getDesc(pdu, xmlRoot, ns))
13111311

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

13301330
if cyclicTiming is not None and eventTiming is not None:
1331-
newFrame.addAttribute("GenMsgSendType", "cyclicAndSpontanX") # CycleAndSpontan
1331+
newFrame.add_attribute("GenMsgSendType", "cyclicAndSpontanX") # CycleAndSpontan
13321332
if minimumDelay is not None:
1333-
newFrame.addAttribute("GenMsgDelayTime", str(int(float_factory(minimumDelay.text) * 1000)))
1333+
newFrame.add_attribute("GenMsgDelayTime", str(int(float_factory(minimumDelay.text) * 1000)))
13341334
if repeats is not None:
1335-
newFrame.addAttribute("GenMsgNrOfRepetitions", repeats.text)
1335+
newFrame.add_attribute("GenMsgNrOfRepetitions", repeats.text)
13361336
elif cyclicTiming is not None:
1337-
newFrame.addAttribute("GenMsgSendType", "cyclicX") # CycleX
1337+
newFrame.add_attribute("GenMsgSendType", "cyclicX") # CycleX
13381338
if minimumDelay is not None:
1339-
newFrame.addAttribute("GenMsgDelayTime", str(int(float_factory(minimumDelay.text) * 1000)))
1339+
newFrame.add_attribute("GenMsgDelayTime", str(int(float_factory(minimumDelay.text) * 1000)))
13401340
if repeats is not None:
1341-
newFrame.addAttribute("GenMsgNrOfRepetitions", repeats.text)
1341+
newFrame.add_attribute("GenMsgNrOfRepetitions", repeats.text)
13421342
else:
1343-
newFrame.addAttribute("GenMsgSendType", "spontanX") # Spontan
1343+
newFrame.add_attribute("GenMsgSendType", "spontanX") # Spontan
13441344
if minimumDelay is not None:
1345-
newFrame.addAttribute("GenMsgDelayTime", str(int(float_factory(minimumDelay.text) * 1000)))
1345+
newFrame.add_attribute("GenMsgDelayTime", str(int(float_factory(minimumDelay.text) * 1000)))
13461346
if repeats is not None:
1347-
newFrame.addAttribute("GenMsgNrOfRepetitions", repeats.text)
1347+
newFrame.add_attribute("GenMsgNrOfRepetitions", repeats.text)
13481348

13491349
if startingTime is not None:
13501350
value = arGetChild(startingTime, "VALUE", xmlRoot, ns)
1351-
newFrame.addAttribute("GenMsgStartDelayTime",str(int(float_factory(value.text) * 1000)))
1351+
newFrame.add_attribute("GenMsgStartDelayTime", str(int(float_factory(value.text) * 1000)))
13521352
elif cyclicTiming is not None:
13531353
value = arGetChild(timeOffset, "VALUE", xmlRoot, ns)
13541354
if value is not None:
1355-
newFrame.addAttribute("GenMsgStartDelayTime",str(int(float_factory(value.text) * 1000)))
1355+
newFrame.add_attribute("GenMsgStartDelayTime", str(int(float_factory(value.text) * 1000)))
13561356

13571357
value = arGetChild(repeatingTime, "VALUE", xmlRoot, ns)
13581358
if value is not None:
1359-
newFrame.addAttribute("GenMsgCycleTime",str(int(float_factory(value.text) * 1000)))
1359+
newFrame.add_attribute("GenMsgCycleTime", str(int(float_factory(value.text) * 1000)))
13601360
elif cyclicTiming is not None:
13611361
value = arGetChild(timePeriod, "VALUE", xmlRoot, ns)
13621362
if value is not None:
1363-
newFrame.addAttribute("GenMsgCycleTime",str(int(float_factory(value.text) * 1000)))
1363+
newFrame.add_attribute("GenMsgCycleTime", str(int(float_factory(value.text) * 1000)))
13641364

13651365

13661366
# pdusigmappings = arGetChild(pdu, "SIGNAL-TO-PDU-MAPPINGS", arDict, ns)
@@ -1471,9 +1471,9 @@ def processEcu(ecu, db, arDict, multiplexTranslation, ns):
14711471
for out in outFrame:
14721472
if out in multiplexTranslation:
14731473
out = multiplexTranslation[out]
1474-
frame = db.frameByName(out)
1474+
frame = db.frame_by_name(out)
14751475
if frame is not None:
1476-
frame.addTransmitter(arGetName(ecu, ns))
1476+
frame.add_transmitter(arGetName(ecu, ns))
14771477
else:
14781478
pass
14791479

@@ -1488,13 +1488,13 @@ def processEcu(ecu, db, arDict, multiplexTranslation, ns):
14881488
# signal.receiver.append(recname)
14891489
# else:
14901490
# print "in not found: " + inf
1491-
bu = BoardUnit(arGetName(ecu, ns))
1491+
bu = ecu(arGetName(ecu, ns))
14921492
if nmAddress is not None:
1493-
bu.addAttribute("NWM-Stationsadresse", nmAddress.text)
1494-
bu.addAttribute("NWM-Knoten", "ja")
1493+
bu.add_attribute("NWM-Stationsadresse", nmAddress.text)
1494+
bu.add_attribute("NWM-Knoten", "ja")
14951495
else:
1496-
bu.addAttribute("NWM-Stationsadresse", "0")
1497-
bu.addAttribute("NWM-Knoten", "nein")
1496+
bu.add_attribute("NWM-Stationsadresse", "0")
1497+
bu.add_attribute("NWM-Knoten", "nein")
14981498
return bu
14991499

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

15271527
def extract_cm_from_ecuc(com_module, search_point, ns):
15281528
db = CanMatrix()
@@ -1531,16 +1531,16 @@ def extract_cm_from_ecuc(com_module, search_point, ns):
15311531
if definition.text.endswith("ComIPdu"):
15321532
container = definition.getparent()
15331533
frame = canmatrix.Frame(arGetName(container, ns))
1534-
db.addFrame(frame)
1534+
db.add_frame(frame)
15351535
allReferences = arGetChildren(container,"ECUC-REFERENCE-VALUE",search_point,ns)
15361536
for reference in allReferences:
15371537
value = arGetChild(reference,"VALUE",search_point,ns)
15381538
if value is not None:
15391539
signal_definition = value.find('./' + ns + "DEFINITION-REF")
15401540
if signal_definition.text.endswith("ComSignal"):
15411541
signal = ecuc_extract_signal(value,ns)
1542-
frame.addSignal(signal)
1543-
db.recalcDLC(strategy = "max")
1542+
frame.add_signal(signal)
1543+
db.recalc_dlc(strategy = "max")
15441544
return {"": db}
15451545

15461546
def load(file, **options):
@@ -1616,18 +1616,18 @@ def load(file, **options):
16161616
for cc in ccs:
16171617
db = CanMatrix()
16181618
# Defines not jet imported...
1619-
db.addBUDefines("NWM-Stationsadresse", 'HEX 0 63')
1620-
db.addBUDefines("NWM-Knoten", 'ENUM "nein","ja"')
1621-
db.addSignalDefines("LongName", 'STRING')
1622-
db.addFrameDefines("GenMsgCycleTime", 'INT 0 65535')
1623-
db.addFrameDefines("GenMsgDelayTime", 'INT 0 65535')
1624-
db.addFrameDefines("GenMsgNrOfRepetitions", 'INT 0 65535')
1625-
db.addFrameDefines("GenMsgStartValue", 'STRING')
1626-
db.addFrameDefines("GenMsgStartDelayTime", 'INT 0 65535')
1627-
db.addFrameDefines(
1619+
db.add_ecu_defines("NWM-Stationsadresse", 'HEX 0 63')
1620+
db.add_ecu_defines("NWM-Knoten", 'ENUM "nein","ja"')
1621+
db.add_signal_defines("LongName", 'STRING')
1622+
db.add_frame_defines("GenMsgCycleTime", 'INT 0 65535')
1623+
db.add_frame_defines("GenMsgDelayTime", 'INT 0 65535')
1624+
db.add_frame_defines("GenMsgNrOfRepetitions", 'INT 0 65535')
1625+
db.add_frame_defines("GenMsgStartValue", 'STRING')
1626+
db.add_frame_defines("GenMsgStartDelayTime", 'INT 0 65535')
1627+
db.add_frame_defines(
16281628
"GenMsgSendType",
16291629
'ENUM "cyclicX","spontanX","cyclicIfActiveX","spontanWithDelay","cyclicAndSpontanX","cyclicAndSpontanWithDelay","spontanWithRepitition","cyclicIfActiveAndSpontanWD","cyclicIfActiveFast","cyclicWithRepeatOnDemand","none"')
1630-
db.addSignalDefines("GenSigStartValue", 'HEX 0 4294967295')
1630+
db.add_signal_defines("GenSigStartValue", 'HEX 0 4294967295')
16311631

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

16711671
if ignoreClusterInfo == True:
16721672
pass
@@ -1706,15 +1706,15 @@ def load(file, **options):
17061706
desc = arGetChild(node, "DESC", searchPoint, ns)
17071707
l2 = arGetChild(desc, "L-2", searchPoint, ns)
17081708
if l2 is not None:
1709-
bu.addComment(l2.text)
1709+
bu.add_comment(l2.text)
17101710

1711-
db.addEcu(bu)
1711+
db.add_ecu(bu)
17121712

17131713
for frame in db.frames:
17141714
sig_value_hash = dict()
17151715
for sig in frame.signals:
17161716
sig_value_hash[sig.name] = sig._initValue
17171717
frameData = frame.encode(sig_value_hash)
1718-
frame.addAttribute("GenMsgStartValue", "".join(["%02x" % x for x in frameData]))
1718+
frame.add_attribute("GenMsgStartValue", "".join(["%02x" % x for x in frameData]))
17191719
result[busname] = db
17201720
return result

src/canmatrix/cancluster.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def updateFrames(self):
1515
else:
1616
index = frameArrayName.index(frame.name)
1717
for transmitter in frame.transmitters:
18-
frameArray[index].addTransmitter(transmitter)
18+
frameArray[index].add_transmitter(transmitter)
1919
for receiver in frame.receiver:
20-
frameArray[index].addReceiver(receiver)
20+
frameArray[index].add_receiver(receiver)
2121
self._frames = frameArray
2222
return frameArray
2323

@@ -33,14 +33,14 @@ def updateSignals(self):
3333
else:
3434
index = signalArrayName.index(signal.name)
3535
for receiver in signal.receiver:
36-
signalArray[index].addReceiver(receiver)
36+
signalArray[index].add_receiver(receiver)
3737
self._signals = signalArray
3838

3939
def updateECUs(self):
4040
ECUArray = []
4141
ECUArrayName = []
4242
for matrixName in self:
43-
for ecu in self[matrixName].boardUnits:
43+
for ecu in self[matrixName].ecus:
4444
if ecu.name not in ECUArrayName:
4545
ECUArrayName.append(ecu.name)
4646
ECUArray.append(ecu)

0 commit comments

Comments
 (0)