Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# create target Matrix
#
db = canmatrix.CanMatrix()
db.boardUnits.add(canmatrix.BoardUnit("testBU"))
db.boardUnits.add(canmatrix.BoardUnit("recBU"))
myFrame1 = canmatrix.Frame("canFdStandard1",Id=1, dlc=24, is_fd = True, transmitter=["testBU"])
myFrame2 = canmatrix.Frame("CanFdExtended2",Id=2, dlc=16, extended = True, is_fd = True, transmitter=["testBU"])
myFrame3 = canmatrix.Frame("CanExtended3", Id=3, dlc=8, extended = True, transmitter=["testBU"])
myFrame4 = canmatrix.Frame("CanStandard4", Id=4, dlc=8)
mySignal1 = canmatrix.Signal("signal1", signalSize=64, startBit=0, is_little_endian=True, min=0, max=0, is_signed=True, receiver=["recBU"])
mySignal2 = canmatrix.Signal("signal2", signalSize=64, startBit=64, is_little_endian=True, min=0, max=0, is_signed=True, receiver=["recBU"])
mySignal3 = canmatrix.Signal("signal3", signalSize=64, startBit=128, is_little_endian=True, min=0, max=0, is_signed=True)
myFrame1.addSignal(mySignal3)
myFrame1.addSignal(mySignal2)
myFrame1.addSignal(mySignal1)
myFrame2.addSignal(mySignal2)
myFrame2.addSignal(mySignal1)
db.frames.addFrame(myFrame1)
db.frames.addFrame(myFrame2)
db.frames.addFrame(myFrame3)
db.frames.addFrame(myFrame4)
import canmatrix
#
# create target Matrix
#
db = canmatrix.CanMatrix()
db.ecus.add(canmatrix.ecu("testBU"))
db.ecus.add(canmatrix.ecu("recBU"))
myFrame1 = canmatrix.Frame("canFdStandard1",Id=1, dlc=24, is_fd = True, transmitter=["testBU"])
myFrame2 = canmatrix.Frame("CanFdExtended2",Id=2, dlc=16, extended = True, is_fd = True, transmitter=["testBU"])
myFrame3 = canmatrix.Frame("CanExtended3", Id=3, dlc=8, extended = True, transmitter=["testBU"])
myFrame4 = canmatrix.Frame("CanStandard4", Id=4, dlc=8)
mySignal1 = canmatrix.Signal("signal1", signalSize=64, startBit=0, is_little_endian=True, min=0, max=0, is_signed=True, receiver=["recBU"])
mySignal2 = canmatrix.Signal("signal2", signalSize=64, startBit=64, is_little_endian=True, min=0, max=0, is_signed=True, receiver=["recBU"])
mySignal3 = canmatrix.Signal("signal3", signalSize=64, startBit=128, is_little_endian=True, min=0, max=0, is_signed=True)
myFrame1.add_signal(mySignal3)
myFrame1.add_signal(mySignal2)
myFrame1.add_signal(mySignal1)
myFrame2.add_signal(mySignal2)
myFrame2.add_signal(mySignal1)
db.frames.add_frame(myFrame1)
db.frames.add_frame(myFrame2)
db.frames.add_frame(myFrame3)
db.frames.add_frame(myFrame4)
# create target Matrix
#
db = canmatrix.CanMatrix()
db.ecus.add(canmatrix.ecu("testBU"))
db.ecus.add(canmatrix.ecu("recBU"))
myFrame1 = canmatrix.Frame("canFdStandard1",Id=1, dlc=24, is_fd = True, transmitter=["testBU"])
myFrame2 = canmatrix.Frame("CanFdExtended2",Id=2, dlc=16, extended = True, is_fd = True, transmitter=["testBU"])
myFrame3 = canmatrix.Frame("CanExtended3", Id=3, dlc=8, extended = True, transmitter=["testBU"])
myFrame4 = canmatrix.Frame("CanStandard4", Id=4, dlc=8)
mySignal1 = canmatrix.Signal("signal1", signalSize=64, startBit=0, is_little_endian=True, min=0, max=0, is_signed=True, receiver=["recBU"])
mySignal2 = canmatrix.Signal("signal2", signalSize=64, startBit=64, is_little_endian=True, min=0, max=0, is_signed=True, receiver=["recBU"])
mySignal3 = canmatrix.Signal("signal3", signalSize=64, startBit=128, is_little_endian=True, min=0, max=0, is_signed=True)
myFrame1.add_signal(mySignal3)
myFrame1.add_signal(mySignal2)
myFrame1.add_signal(mySignal1)
myFrame2.add_signal(mySignal2)
myFrame2.add_signal(mySignal1)
db.frames.add_frame(myFrame1)
db.frames.add_frame(myFrame2)
db.frames.add_frame(myFrame3)
db.frames.add_frame(myFrame4)
# motorola set/convert start bit
signal.set_startbit(start_bit)
frame.add_signal(signal)
signal.comments[multiplexor] = comment
else:
# signal = Signal(sigName, startBit, signalLength, intel, is_signed, factor, offset, min, max, unit, "", multiplexor)
extras = {}
if calc_min_for_none is not None:
extras['calc_min_for_none'] = calc_min_for_none
if calc_max_for_none is not None:
extras['calc_max_for_none'] = calc_max_for_none
# if float_factory is not None:
# extras['float_factory'] = float_factory
signal = canmatrix.Signal(
sig_name,
start_bit=int(start_bit),
size=int(signal_length),
is_little_endian=intel,
is_signed=is_signed,
is_float=is_float,
factor=factor,
offset=offset,
unit=unit,
multiplex=multiplexor,
comment=comment,
**extras)
if min_value is not None:
signal.min = float_factory(min_value)
if max_value is not None:
signal.max = float_factory(max_value)
if 'i' in signal_byte_order:
is_little_endian = True
else:
is_little_endian = False
else:
is_little_endian = True # Default Intel
is_signed = False
if signal_name != "-":
for x in range(index['ECUstart'], index['ECUend']):
if 's' in sh.cell(row_num, x).value:
new_frame.add_transmitter(sh.cell(0, x).value.strip())
if 'r' in sh.cell(row_num, x).value:
receiver.append(sh.cell(0, x).value.strip())
new_signal = canmatrix.Signal(
signal_name,
start_bit=(start_byte - 1) * 8 + start_bit,
size=int(signal_length),
is_little_endian=is_little_endian,
is_signed=is_signed,
receivers=receiver,
multiplex=multiplex)
if not is_little_endian:
# motorola
if motorola_bit_format == "msb":
new_signal.set_startbit((start_byte - 1) * 8 + start_bit, bitNumbering=1)
elif motorola_bit_format == "msbreverse":
new_signal.set_startbit((start_byte - 1) * 8 + start_bit)
else: # motorola_bit_format == "lsb"
new_signal.set_startbit(
# timeout = 0
for attribute in attributes:
if attribute.text.endswith("ComBitPosition"):
start_bit = int(attribute.getparent().find(".//" + ns + "VALUE").text)
if attribute.text.endswith("ComBitSize"):
size = int(attribute.getparent().find(".//" + ns + "VALUE").text)
if attribute.text.endswith("ComSignalEndianness"):
endianness = attribute.getparent().find(".//" + ns + "VALUE").text
is_little = "LITTLE_ENDIAN" in endianness
if attribute.text.endswith("ComSignalInitValue"):
init_value = int(attribute.getparent().find(".//" + ns + "VALUE").text)
if attribute.text.endswith("ComSignalType"):
signal_type = attribute.getparent().find(".//" + ns + "VALUE").text
if attribute.text.endswith("ComTimeout"):
timeout = int(attribute.getparent().find(".//" + ns + "VALUE").text)
return canmatrix.Signal(get_element_name(signal_node, ns), start_bit=start_bit, size=size, is_little_endian=is_little)
if 'intercept' in values.attrib:
offset = values.get('intercept')
if 'unit' in values.attrib:
unit = values.get('unit')
if 'min' in values.attrib:
min_value = values.get('min')
if 'max' in values.attrib:
max_value = values.get('max')
receiver = []
consumers = signal.findall('./' + namespace + 'Consumer')
for consumer in consumers:
noderefs = consumer.findall('./' + namespace + 'NodeRef')
for noderef in noderefs:
receiver.append(nodelist[noderef.get('id')])
new_sig = canmatrix.Signal(
signal.get('name'),
start_bit=int(start_bit),
size=int(signal_size),
is_little_endian=is_little_endian,
is_signed=is_signed,
factor=factor,
offset=offset,
unit=unit,
receivers=receiver,
is_float=is_float,
multiplex=mux)
if min_value is not None:
new_sig.min = float_factory(min_value)
if max_value is not None:
new_sig.max = float_factory(max_value)
multiplex = None
is_float = False
is_signed = False
if sign == "U":
is_signed = False
elif sign == "F" or sign == "D":
is_float = True
else:
is_signed = True
start_bit = int(start_bit)
start_bit += (int(start_byte) - 1) * 8
new_signal = new_frame.add_signal(
canmatrix.Signal(
name,
start_bit=int(start_bit),
size=int(size),
is_little_endian=(int(byteorder) == 1),
is_signed=is_signed,
factor=factor,
offset=offset,
min=min_val * factor,
max=max_val * factor,
unit=unit,
receivers=receiver,
is_float=is_float,
multiplex=multiplex))
if int(byteorder) == 0:
# this is dummy here, because internal lsb is default - for now
is_little_endian = False
if motorola is not None:
if motorola.text == 'MOST-SIGNIFICANT-BYTE-LAST':
is_little_endian = True
else:
logger.debug('no name byte order for signal' + name.text)
if name is None:
logger.debug('no name for signal given')
if start_bit is None:
logger.debug('no startBit for signal given')
if length is None:
logger.debug('no length for signal given')
if start_bit is not None:
new_signal = canmatrix.Signal(
name.text,
start_bit=int(start_bit.text) + bit_offset,
size=int(length.text),
is_little_endian=is_little_endian,
is_signed=is_signed,
factor=factor,
offset=offset,
unit=signal_unit,
receivers=receiver,
multiplex=multiplex_id,
comment=signal_description,
is_float=is_float)
if signal_min is not None:
new_signal.min = signal_min
if signal_max is not None:
frame1 = canmatrix.Frame("Node604", j1939_pgn = 0xff00, j1939_prio = 0x6,
j1939_source = 0x80,
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.add_signal(sig)
cm.add_frame(frame1)
#
# create frame Node605
#
frame2 = canmatrix.Frame("Node605", j1939_pgn = 0xff01, j1939_prio = 0x6,
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)
sig2 = canmatrix.Signal("ch2", size=32, is_float=True, is_little_endian=False, startBit=32)
frame2.add_signal(sig)
frame2.add_signal(sig2)
cm.add_frame(frame2)
#
# create frame Node606
#
frame3 = canmatrix.Frame("Node606", j1939_pgn = 0xff02, j1939_prio = 0x6,
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.add_signal(sig)
cm.add_frame(frame3)