Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _load_signal_type_and_length(type_, tokens, enums):
# Default values.
is_signed = False
is_float = False
length = 0
enum = None
minimum = None
maximum = None
decimal = SignalDecimal()
if type_ == 'signed':
is_signed = True
length = int(tokens[0])
elif type_ == 'unsigned':
length = int(tokens[0])
elif type_ == 'float':
is_float = True
length = 32
elif type_ == 'double':
is_float = True
length = 64
elif type_ == 'bit':
# As unsigned integer for now.
length = 1
minimum = 0
def load_signal(self, i_signal_to_i_pdu_mapping):
"""Load given signal and return a signal object.
"""
# Default values.
minimum = None
maximum = None
factor = 1
offset = 0
unit = None
choices = None
comment = None
receivers = []
decimal = SignalDecimal(Decimal(factor), Decimal(offset))
i_signal_ref = i_signal_to_i_pdu_mapping.find(
I_SIGNAL_REF_XPATH,
NAMESPACES)
if i_signal_ref is None:
# Probably a signal group (I-SIGNAL-GROUP-REF).
return None
i_signal = self.find_i_signal(i_signal_ref.text)
# Name, start position, length and byte order.
name = self.load_signal_name(i_signal_to_i_pdu_mapping)
start_position = self.load_signal_start_position(
i_signal_to_i_pdu_mapping)
length = self.load_signal_length(i_signal)
# Default values.
name = None
offset = None
length = 1
byte_order = 'little_endian'
is_signed = False
is_float = False
minimum = None
maximum = None
slope = 1
intercept = 0
unit = None
labels = None
notes = None
receivers = []
decimal = SignalDecimal(Decimal(slope), Decimal(intercept))
# Signal XML attributes.
for key, value in signal.attrib.items():
if key == 'name':
name = value
elif key == 'offset':
offset = int(value)
elif key == 'length':
length = int(value)
elif key == 'endianess':
byte_order = '{}_endian'.format(value)
else:
LOGGER.debug("Ignoring unsupported signal attribute '%s'.", key)
# Value XML element.
value = signal.find('ns:Value', NAMESPACES)
return None
name = ecuc_container_value.find(SHORT_NAME_XPATH, NAMESPACES).text
# Default values.
is_signed = False
is_float = False
minimum = None
maximum = None
factor = 1
offset = 0
unit = None
choices = None
comment = None
receivers = []
decimal = SignalDecimal(Decimal(factor), Decimal(offset))
# Bit position, length, byte order, is_signed and is_float.
bit_position = None
length = None
byte_order = None
for parameter, value in self.iter_parameter_values(ecuc_container_value):
if parameter == 'ComBitPosition':
bit_position = int(value)
elif parameter == 'ComBitSize':
length = int(value)
elif parameter == 'ComSignalEndianness':
byte_order = value.lower()
elif parameter == 'ComSignalType':
if value in ['SINT8', 'SINT16', 'SINT32']:
is_signed = True
for signal in tokens:
signals.append(
Signal(name=get_signal_name(frame_id_dbc, signal[1][0]),
start=int(signal[3]),
length=int(signal[5]),
receivers=get_receivers(signal[20]),
byte_order=('big_endian'
if signal[7] == '0'
else 'little_endian'),
is_signed=(signal[8] == '-'),
initial=get_signal_initial_value(frame_id_dbc, signal[1][0]),
scale=num(signal[10]),
offset=num(signal[12]),
minimum=get_minimum(signal[15], signal[17]),
maximum=get_maximum(signal[15], signal[17]),
decimal=SignalDecimal(Decimal(signal[10]),
Decimal(signal[12]),
get_minimum_decimal(signal[15],
signal[17]),
get_maximum_decimal(signal[15],
signal[17])),
unit=(None if signal[19] == '' else signal[19]),
choices=get_choices(frame_id_dbc,
signal[1][0]),
dbc_specifics=DbcSpecifics(
attributes=get_attributes(frame_id_dbc, signal[1][0]),
attribute_definitions=definitions),
comment=get_comment(frame_id_dbc,
signal[1][0]),
is_multiplexer=get_is_multiplexer(signal),
multiplexer_ids=get_multiplexer_ids(signal[1],
multiplexer_signal),