예제 #1
0
    def setPayloadId(self, id):
        '''
        Set payload id
        '''
        if isinstance(id, str):
            id = protocols.shortFrom8bit(id)

        self._payload_id = id
예제 #2
0
    def updateData(self, packet):
        '''
        Update with data var with latest data from datalog

        Loops through packet payload decoding the variables, updates
        the self._data list, and then calls refreshDisplay()

        Packet parameter is the basicDatalog packet received.
        '''
        # Data store
        data = self.data

        # Units
        units = self.units

        # Basic datalog packet payloads consist of 4 bytes of data for each of the 27 variables logged
        # These 4 bytes contain two ints, and we shall average the two for display
        # Loop through playload 4 bytes at a time
        payload = packet.getPayload()
        payload_length = len(payload)

        i = 0
        for key in self._structure:
            # Decode binary and cast to float
            value = float(protocols.shortFrom8bit(payload[i:i+2]))

            # Process display
            if key in units:
                if units[key] == 'temp':
                    value = '%.2f' % ((value / 100) - 273.15)
                elif units[key] == 'percent_tps':
                    value = '%.3f' % (value / 640)
                elif units[key] == 'percent':
                    value = '%.3f' % (value / 512)
                elif units[key] == 'lambda':
                    value = '%d' % (value / 32768)
                elif units[key] == 'pressure':
                    value = '%.2f' % (value / 100)
                elif units[key] == 'volts':
                    value = '%.3f' % (value / 1000)
                elif units[key] == 'rpm':
                    value = '%.1f' % (value / 2)
            else:
                value = '%d' % value

            # Update display
            data[key] = value

            # Next var
            i += 2

        self._data_updated = True
예제 #3
0
    def _processIncomingPacket(self, packet):
        '''
        Takes a raw packet, checks it and returns the correct packet class
        '''
        # Check for special bytes n packet that shouldn't be there
        if protocol.START_BYTE in packet or protocol.END_BYTE in packet:
            raise ParsingException, 'Unescaped bytes found in packet: %s' % protocols.toHex(packet)

        # Process escapes
        processed = 0
        while protocol.ESCAPE_BYTE in packet[processed:]:
            i = packet.index(protocol.ESCAPE_BYTE, processed)
            processed = i+1

            # Convert escaped byte to an integer to XOR, and then convert back to a string
            unescaped = chr(ord(packet[i+1]) ^ 0xFF)

            if unescaped in protocol.SPECIAL_BYTES:
                packet = packet[:i] + unescaped + packet[i+2:]
            else:
                raise ParsingException, 'Wrongly escaped byte found in packet (%s): %s' % (hex(ord(unescaped)), protocols.toHex(packet))

        if not len(packet):
            raise IgnorableParsingException, 'Packet is empty'

        if len(packet) < 4:
            raise ParsingException, 'Packet does not contain required information. Packet content: %s' % protocols.toHex(packet)

        # Split up packet
        contents = {
                'flags':        packet[0],
                'payload_id':   protocols.shortFrom8bit(packet[1:3]),
                'payload':      packet[3:-1],
                'checksum':     packet[-1]
        }

        # Check checksum
        gen_checksum = packetlib.getChecksum(packet[:-1])

        if contents['checksum'] != gen_checksum:
            raise ParsingException, 'Checksum is incorrect! Provided: %d, generated: %d, packet: [%s]' % (ord(contents['checksum']), ord(gen_checksum), protocols.toHex(packet))

        # Create response packet object
        response = responses.getPacket(contents['payload_id'])

        # Populate data
        response.parseHeaderFlags(contents['flags'])
        response.setPayloadId(contents['payload_id'])
        response.parsePayload(contents['payload'])
        response.validate()

        return response
예제 #4
0
    def updateData(self, packet):
        '''
        Updating tuning table data to reflect
        loaded table data
        '''
        payload = packet.getPayload()

        # Get table memory location
        self.table_id = protocols.shortFrom8bit(payload[0:2])

        # Get rpm axis max length
        self.max_length_rpm = protocols.shortFrom8bit(payload[2:4])

        # Get load axis max length
        self.max_length_load = protocols.shortFrom8bit(payload[4:6])

        # Get table max length
        self.max_length_table = protocols.shortFrom8bit(payload[6:8])

        # Get rpm axis length
        self.length_rpm = protocols.shortFrom8bit(payload[8:10])

        # Get load axis length
        self.length_load = protocols.shortFrom8bit(payload[10:12])

        # Get rpm axis
        self.axis_rpm = []
        offset = 12
        i = 0
        while i < self.max_length_rpm:
            if i < self.length_rpm:
                value = float(protocols.shortFrom8bit(payload[offset:offset+2])) / 2
                self.axis_rpm.append(value)

            offset += 2
            i += 1

        # Get load axis
        self.axis_load = []
        i = 0
        while i < self.max_length_load:
            if i < self.length_load:
                value = float(protocols.shortFrom8bit(payload[offset:offset+2])) / 100
                self.axis_load.append(value)

            offset += 2
            i += 1

        # Update cell values
        rpm = 0
        self.cells = []
        while rpm < self.length_rpm:
            load = 0
            self.cells.insert(rpm, [])
            while load < self.length_load:
                value = protocols.shortFrom8bit(payload[offset:offset+2])
                self.cells[rpm].append(value)
                offset += 2
                load += 1

            rpm += 1

        self.updateDisplay()
예제 #5
0
 def setPayloadLength(self, length):
     '''
     Set payload length defined in packet
     '''
     self._payload_length = protocols.shortFrom8bit(length)