Ejemplo n.º 1
0
    def extract_sort_data(data):
        """Extract timestamp, message length, apid, ctid from a bytestring in DLT storage format (speed optimized)"""
        htyp_data = ord(chr(data[16])) if six.PY3 else ord(data[16])
        len_data = data[19:17:-1]
        len_value = ctypes.cast(len_data, ctypes.POINTER(
            ctypes.c_ushort)).contents.value + 16
        apid = b""
        ctid = b""
        tmsp_value = 0.0

        bytes_offset = 0  # We know where data will be in the message, but ...
        if not htyp_data & DLT_HTYP_WEID:  # if there is no ECU ID and/or Session ID, then it will be earlier
            bytes_offset -= 4
        if not htyp_data & DLT_HTYP_WSID:
            bytes_offset -= 4

        if htyp_data & DLT_HTYP_WTMS:
            tmsp_base = 31 + bytes_offset  # Typical timestamp end offset
            tmsp_data = data[tmsp_base:tmsp_base - 4:-1]
            tmsp_value = ctypes.cast(tmsp_data, ctypes.POINTER(
                ctypes.c_uint32)).contents.value / 10000.0

        if htyp_data & DLT_HTYP_UEH:
            apid_base = 38 + bytes_offset  # Typical APID end offset
            apid = data[apid_base - 4:apid_base].rstrip(b"\x00")
            ctid = data[apid_base:apid_base + 4].rstrip(b"\x00")

        apid = bytes_to_str(apid)
        ctid = bytes_to_str(ctid)

        return tmsp_value, len_value, apid, ctid
Ejemplo n.º 2
0
    def payload_decoded(self):  # pylint: disable=invalid-overridden-method
        """Get the payload string

        :returns: Payload string
        :rtype: str
        """
        return bytes_to_str(super(DLTMessage, self).payload_decoded)
Ejemplo n.º 3
0
    def ecuid(self):  # pylint: disable=invalid-overridden-method
        """Get the ECU ID

        :returns: ECU ID
        :rtype: str
        """
        return bytes_to_str(self.storageheader.ecu or self.headerextra.ecu)
Ejemplo n.º 4
0
    def ctid(self):  # pylint: disable=invalid-overridden-method
        """Get the Context ID

        :returns: Context ID
        :rtype: str
        """
        return bytes_to_str(
            self.extendedheader.ctid if self.extendedheader else "")
Ejemplo n.º 5
0
    def apid(self):  # pylint: disable=invalid-overridden-method
        """Get the Application ID

        :returns: Application ID
        :rtype: str
        """
        return bytes_to_str(
            self.extendedheader.apid if self.extendedheader else "")
Ejemplo n.º 6
0
 def __str__(self):
     """Construct DLTViewer-like string"""
     out = [time.asctime(time.gmtime(self.storage_timestamp))]
     if self.headerextra:
         out.append(self.headerextra.tmsp / 10000.0)
     out += [self.standardheader.mcnt, self.storageheader.ecu]
     if self.extendedheader:
         out += [self.extendedheader.apid, self.extendedheader.ctid]
     if self.headerextra:
         out.append(self.headerextra.seid)
     out += [
         self.type_string, self.subtype_string, self.mode_string, self.noar,
         self.payload_decoded
     ]
     return " ".join(bytes_to_str(item) for item in out)