예제 #1
0
    def read_message(self, verbose=False):
        """Read new message

        :param bool verbose: Log every dlt_message_read(). Set True only for debugging.
        :returns: A new DLTMessage on successful read, None otherwise
        :rtype: DLTMessage|None
        """
        msg = DLTMessage(verbose=verbose)
        res = dltlib.dlt_message_read(
            ctypes.byref(msg),
            ctypes.cast(self.receiver.buf, ctypes.POINTER(ctypes.c_uint8)),
            ctypes.c_uint(self.receiver.bytesRcvd),  # length
            ctypes.c_int(0),  # resync
            ctypes.c_int(verbose))  # verbose

        if res != DLT_MESSAGE_ERROR_OK:
            # - failed to read a complete message, possibly read an incomplete
            # message
            return None

        # prepare storage header
        if msg.standardheader.htyp & DLT_HTYP_WEID:
            dltlib.dlt_set_storageheader(msg.p_storageheader,
                                         msg.headerextra.ecu)
        else:
            dltlib.dlt_set_storageheader(msg.p_storageheader,
                                         ctypes.c_char_p(""))

        return msg
예제 #2
0
    def from_bytes(data):
        """Create a class instance from a byte string in DLT storage format"""

        msg = DLTMessage()
        storageheader, remainder = msg.extract_storageheader(data)

        buf = ctypes.create_string_buffer(remainder)

        dltlib.dlt_message_read(ctypes.byref(msg),
                                ctypes.cast(buf, ctypes.POINTER(ctypes.c_uint8)),
                                ctypes.c_uint(len(remainder)),
                                0,  # resync
                                0)  # verbose
        msg.p_storageheader.contents = storageheader
        msg.initialized_as_object = False

        return msg