How to use the cantools.errors.Error function in cantools

To help you get started, we’ve selected a few cantools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eerimoq / cantools / cantools / tester.py View on Github external
self._is_running = False

        # DUT name validation.
        node_names = [node.name for node in database.nodes]

        if not any([name == dut_name for name in node_names]):
            raise Error(
                "expected DUT name in {}, but got '{}'".format(node_names,
                                                               dut_name))

        # BUS name validation.
        bus_names = [bus.name for bus in database.buses]

        if len(bus_names) == 0:
            if bus_name is not None:
                raise Error(
                    "expected bus name None as there are no buses defined in "
                    "the database, but got '{}'".format(bus_name))
        elif not any([name == bus_name for name in bus_names]):
            raise Error(
                "expected bus name in {}, but got '{}'".format(bus_names,
                                                               bus_name))

        for message in database.messages:
            if message.bus_name == bus_name:
                self._messages[message.name] = Message(message,
                                                       can_bus,
                                                       self._input_list,
                                                       self._input_queue,
                                                       decode_choices,
                                                       scaling,
                                                       padding)
github eerimoq / cantools / cantools / tester.py View on Github external
def __missing__(self, key):
        raise Error("invalid message name '{}'".format(key))
github eerimoq / cantools / cantools / j1939.py View on Github external
pdu_specific))

    try:
        packed = bitstruct.pack('u1u1u8u8',
                                reserved,
                                data_page,
                                pdu_format,
                                pdu_specific)
    except bitstruct.Error:
        if reserved > 1:
            raise Error('Expected reserved 0..1, but got {}.'.format(reserved))
        elif data_page > 1:
            raise Error('Expected data page 0..1, but got {}.'.format(
                data_page))
        elif pdu_format > 255:
            raise Error('Expected PDU format 0..255, but got {}.'.format(
                pdu_format))
        elif pdu_specific > 255:
            raise Error('Expected PDU specific 0..255, but got {}.'.format(
                pdu_specific))
        else:
            raise Error('Internal error.')

    return bitstruct.unpack('u18', packed)[0]
github eerimoq / cantools / cantools / j1939.py View on Github external
raise Error('Expected priority 0..7, but got {}.'.format(priority))
        elif reserved > 1:
            raise Error('Expected reserved 0..1, but got {}.'.format(reserved))
        elif data_page > 1:
            raise Error('Expected data page 0..1, but got {}.'.format(data_page))
        elif pdu_format > 255:
            raise Error('Expected PDU format 0..255, but got {}.'.format(
                pdu_format))
        elif pdu_specific > 255:
            raise Error('Expected PDU specific 0..255, but got {}.'.format(
                pdu_specific))
        elif source_address > 255:
            raise Error('Expected source address 0..255, but got {}.'.format(
                source_address))
        else:
            raise Error('Internal error.')

    return bitstruct.unpack('u29', packed)[0]
github eerimoq / cantools / cantools / database / errors.py View on Github external
from ..errors import Error as _Error


class Error(_Error):
    pass


class ParseError(Error):
    pass


class EncodeError(Error):
    pass


class DecodeError(Error):
    pass
github eerimoq / cantools / cantools / j1939.py View on Github external
def frame_id_unpack(frame_id):
    """Unpack given frame id and return a tuple of priority, reserved,
    data page, PDU format, PDU specific and source address.

    """

    try:
        packed = bitstruct.pack('u29', frame_id)
    except bitstruct.Error:
        raise Error(
            'Expected a frame id 0..0x1fffffff, but got {}.'.format(
                hex(frame_id)))

    return FrameId(*bitstruct.unpack('u3u1u1u8u8u8', packed))
github eerimoq / cantools / cantools / j1939.py View on Github external
source_address):
    """Pack given values as a frame id and return it as an integer.

    """

    try:
        packed = bitstruct.pack('u3u1u1u8u8u8',
                                priority,
                                reserved,
                                data_page,
                                pdu_format,
                                pdu_specific,
                                source_address)
    except bitstruct.Error:
        if priority > 7:
            raise Error('Expected priority 0..7, but got {}.'.format(priority))
        elif reserved > 1:
            raise Error('Expected reserved 0..1, but got {}.'.format(reserved))
        elif data_page > 1:
            raise Error('Expected data page 0..1, but got {}.'.format(data_page))
        elif pdu_format > 255:
            raise Error('Expected PDU format 0..255, but got {}.'.format(
                pdu_format))
        elif pdu_specific > 255:
            raise Error('Expected PDU specific 0..255, but got {}.'.format(
                pdu_specific))
        elif source_address > 255:
            raise Error('Expected source address 0..255, but got {}.'.format(
                source_address))
        else:
            raise Error('Internal error.')
github eerimoq / cantools / cantools / j1939.py View on Github external
if pdu_format < 240 and pdu_specific != 0:
        raise Error(
            'Expected PDU specific 0 when PDU format is 0..239, but got {}.'.format(
                pdu_specific))

    try:
        packed = bitstruct.pack('u1u1u8u8',
                                reserved,
                                data_page,
                                pdu_format,
                                pdu_specific)
    except bitstruct.Error:
        if reserved > 1:
            raise Error('Expected reserved 0..1, but got {}.'.format(reserved))
        elif data_page > 1:
            raise Error('Expected data page 0..1, but got {}.'.format(
                data_page))
        elif pdu_format > 255:
            raise Error('Expected PDU format 0..255, but got {}.'.format(
                pdu_format))
        elif pdu_specific > 255:
            raise Error('Expected PDU specific 0..255, but got {}.'.format(
                pdu_specific))
        else:
            raise Error('Internal error.')

    return bitstruct.unpack('u18', packed)[0]
github eerimoq / cantools / cantools / j1939.py View on Github external
pdu_format,
                                pdu_specific)
    except bitstruct.Error:
        if reserved > 1:
            raise Error('Expected reserved 0..1, but got {}.'.format(reserved))
        elif data_page > 1:
            raise Error('Expected data page 0..1, but got {}.'.format(
                data_page))
        elif pdu_format > 255:
            raise Error('Expected PDU format 0..255, but got {}.'.format(
                pdu_format))
        elif pdu_specific > 255:
            raise Error('Expected PDU specific 0..255, but got {}.'.format(
                pdu_specific))
        else:
            raise Error('Internal error.')

    return bitstruct.unpack('u18', packed)[0]
github eerimoq / cantools / cantools / j1939.py View on Github external
def pgn_unpack(pgn):
    """Unpack given parameter group number (PGN) and return a tuple of
    Reserved, Data Page, PDU Format and PDU Specific.

    """

    try:
        packed = bitstruct.pack('u18', pgn)
    except bitstruct.Error:
        raise Error(
            'Expected a parameter group number 0..0x3ffff, but got {}.'.format(
                hex(pgn)))

    return PGN(*bitstruct.unpack('u1u1u8u8', packed))