def test_get_consumed_messages(self): cn = CANNetwork() cn.add_node(CANNode('SendingNode')) cn.add_node(CANNode('ReceivingNode')) cn.nodes['SendingNode'].add_message(CANMessage(1, 'Message', 1)) sig = CANSignal('Signal', 0, 8) sig.add_receiver(cn.nodes['ReceivingNode']) cn.nodes['SendingNode'].messages[1].add_signal(sig) assert cn.nodes['SendingNode'].messages[1] in cn.get_consumed_messages( cn.nodes['ReceivingNode'])
def _parse_signal(self, signal_str): """Parses a signal string and updates the CANBus Args: signal_str: String with signal informations Raises: RuntimeError: If signal definition is not in a message block """ if self._mode[0] != 'MESSAGE': raise RuntimeError('Signal description not in message block') pattern = 'SG_\s+(?P<name>\S+)\s*(?P<is_multipexer>M)?(?P<multiplexer_id>m\d+)?\s*:\s*' pattern += '(?P<start_bit>\d+)\|(?P<length>\d+)\@(?P<endianness>[0|1])(?P<sign>[\+|\-])\s*' pattern += '\(\s*(?P<factor>\S+)\s*,\s*(?P<offset>\S+)\s*\)\s*' pattern += '\[\s*(?P<min_value>\S+)\s*\|\s*(?P<max_value>\S+)\s*\]\s*"(?P<unit>\S*)"\s+(?P<receivers>.+)' reg = re.search(pattern, signal_str) little_endian = True if reg.group( 'endianness').strip() == '1' else False signed = True if reg.group('sign').strip() == '-' else False receivers = [ receiver.strip() for receiver in re.sub( '\s+', ' ', reg.group('receivers')).strip().split(' ') ] is_multiplexer = True if reg.group('is_multipexer') else False multiplexer_id = int(reg.group('multiplexer_id').strip() [1:]) if reg.group('multiplexer_id') else None signal = CANSignal(name=reg.group('name').strip(), start_bit=int(reg.group('start_bit')), length=int(reg.group('length')), little_endian=little_endian, signed=signed, factor=float(reg.group('factor')), offset=float(reg.group('offset')), value_min=float(reg.group('min_value')), value_max=float(reg.group('max_value')), unit=reg.group('unit').strip(), is_multiplexer=is_multiplexer, multiplexer_id=multiplexer_id) for node_name in receivers: node = self._can_network.nodes[node_name] signal.add_receiver(node) self._mode[1].add_signal(signal)
def test_add_receiver(self): node = CANNode('TestNode') sig = CANSignal('Signal', 0, 8) sig.add_receiver(node) assert len(sig.receiver) == 1