Ejemplo n.º 1
0
	def extract_raw_packet(self, packet_type, packetbuf, has_seq):
		if packet_type == SK6_RAW_DATA_ACC:
			self.data.accx = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
			self.data.accy = pyshake_sk_common.convert_raw_data_value(packetbuf[5:7])
			self.data.accz = pyshake_sk_common.convert_raw_data_value(packetbuf[7:9])
			if has_seq:
				self.data.internal_timestamps[SHAKE_SENSOR_ACC] = ord(packetbuf[9:10])
			if self.__shake.data_callback:
				self.__shake.data_callback(SHAKE_SENSOR_ACC, [self.data.accx, self.data.accy, self.data.accz], self.data.internal_timestamps[SHAKE_SENSOR_ACC])
		elif packet_type == SK6_RAW_DATA_GYRO:
			self.data.gyrx = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
			self.data.gyry = pyshake_sk_common.convert_raw_data_value(packetbuf[5:7])
			self.data.gyrz = pyshake_sk_common.convert_raw_data_value(packetbuf[7:9])
			if has_seq:
				self.data.internal_timestamps[SHAKE_SENSOR_GYRO] = ord(packet[9:10])
			if self.__shake.data_callback:
				self.__shake.data_callback(SHAKE_SENSOR_GYRO, [self.data.gyrx, self.data.gyry, self.data.gyrz], self.data.internal_timestamps[SHAKE_SENSOR_GYRO])
		elif packet_type == SK6_RAW_DATA_MAG:
			self.data.magx = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
			self.data.magy = pyshake_sk_common.convert_raw_data_value(packetbuf[5:7])
			self.data.magz = pyshake_sk_common.convert_raw_data_value(packetbuf[7:9])
			if has_seq:
				self.data.internal_timestamps[SHAKE_SENSOR_MAG] = ord(packetbuf[9:10])
			if self.__shake.data_callback:
				self.__shake.data_callback(SHAKE_SENSOR_MAG, [self.data.magx, self.data.magy, self.data.magz], self.data.internal_timestamps[SHAKE_SENSOR_MAG])
		elif packet_type == SK6_RAW_DATA_HEADING:
			self.data.heading = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
			if has_seq:
				self.data.internal_timestamps[SHAKE_SENSOR_HEADING] = ord(packetbuf[5:6])
			if self.__shake.data_callback:
				self.__shake.data_callback(SHAKE_SENSOR_HEADING, [self.data.heading], self.data.internal_timestamps[SHAKE_SENSOR_HEADING])
		elif packet_type == SK6_RAW_DATA_CAP0:
			self.data.cap_sk6[0] = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
			if has_seq:
				self.data.internal_timestamps[SHAKE_SENSOR_CAP0] = ord(packetbuf[5:6])
			if self.__shake.data_callback:
				self.__shake.data_callback(SHAKE_SENSOR_CAP0, [self.data.cap_sk6[0]], self.data.internal_timestamps[SHAKE_SENSOR_CAP0])
		elif packet_type == SK6_RAW_DATA_CAP1:
			self.data.cap_sk6[1] = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
			if has_seq:
				self.data.internal_timestamps[SHAKE_SENSOR_CAP1] = ord(packetbuf[5:6])
			if self.__shake.data_callback:
				self.__shake.data_callback(SHAKE_SENSOR_CAP1, [self.data.cap_sk6[1]], self.data.internal_timestamps[SHAKE_SENSOR_CAP1])
		elif packet_type == SK6_RAW_DATA_ANALOG0:
			self.data.ana0 = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
			if has_seq:
				self.data.internal_timestamps[SHAKE_SENSOR_ANA0] = ord(packetbuf[5:6])
			if self.__shake.data_callback:
				self.__shake.data_callback(SHAKE_SENSOR_ANA0, [self.data.ana0], self.data.internal_timestamps[SHAKE_SENSOR_ANA0])
		elif packet_type == SK6_RAW_DATA_ANALOG1:
			self.data.ana1 = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
			if has_seq:
				self.data.internal_timestamps[SHAKE_SENSOR_ANA1] = ord(packetbuf[5:6])
			if self.__shake.data_callback:
				self.__shake.data_callback(SHAKE_SENSOR_ANA1, [self.data.ana1], self.data.internal_timestamps[SHAKE_SENSOR_ANA1])
		elif packet_type == SK6_RAW_DATA_EVENT:
			if self.__shake.navcb != None:
				event = -1
				val = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
				if val == 1:
					event = SHAKE_NAV_UP
				elif val == 2:
					event = SHAKE_NAV_DOWN
				elif val == 3:
					event = SHAKE_NAV_CENTRE
				elif val == 4:
					event = SHAKE_NAV_NORMAL
				self.__shake.navcb(event)
		elif packet_type == SK6_RAW_DATA_SHAKING:
			if self.__shake.navcb != None:
				self.__shake.navcb(SHAKE_SHAKING_EVENT)
		else:
			return SHAKE_ERROR

		return SHAKE_SUCCESS
Ejemplo n.º 2
0
    def extract_raw_packet(self, packet_type, packetbuf, has_seq):
        if packet_type == SK7_RAW_DATA_ACC:
            self.data.accx = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
            self.data.accy = pyshake_sk_common.convert_raw_data_value(packetbuf[5:7])
            self.data.accz = pyshake_sk_common.convert_raw_data_value(packetbuf[7:9])
            if has_seq:
                self.data.internal_timestamps[SHAKE_SENSOR_ACC] = ord(packetbuf[9:10])
            if self.__shake.data_callback:
                self.__shake.data_callback(SHAKE_SENSOR_ACC, [self.data.accx, self.data.accy, self.data.accz], self.data.internal_timestamps[SHAKE_SENSOR_ACC])
        elif packet_type == SK7_RAW_DATA_GYRO:
            self.data.gyrx = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
            self.data.gyry = pyshake_sk_common.convert_raw_data_value(packetbuf[5:7])
            self.data.gyrz = pyshake_sk_common.convert_raw_data_value(packetbuf[7:9])
            if has_seq:
                self.data.internal_timestamps[SHAKE_SENSOR_GYRO] = ord(packetbuf[9:10])
            if self.__shake.data_callback:
                self.__shake.data_callback(SHAKE_SENSOR_GYRO, [self.data.gyrx, self.data.gyry, self.data.gyrz], self.data.internal_timestamps[SHAKE_SENSOR_GYRO])
        elif packet_type == SK7_RAW_DATA_MAG:
            self.data.magx = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
            self.data.magy = pyshake_sk_common.convert_raw_data_value(packetbuf[5:7])
            self.data.magz = pyshake_sk_common.convert_raw_data_value(packetbuf[7:9])
            if has_seq:
                self.data.internal_timestamps[SHAKE_SENSOR_MAG] = ord(packetbuf[9:10])
            if self.__shake.data_callback:
                self.__shake.data_callback(SHAKE_SENSOR_MAG, [self.data.magx, self.data.magy, self.data.magz], self.data.internal_timestamps[SHAKE_SENSOR_MAG])
        elif packet_type == SK7_RAW_DATA_HEADING:
            self.data.heading = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
            if has_seq:
                self.data.internal_timestamps[SHAKE_SENSOR_HEADING] = ord(packetbuf[5:6])
            if self.__shake.data_callback:
                self.__shake.data_callback(SHAKE_SENSOR_HEADING, [self.data.heading], self.data.internal_timestamps[SHAKE_SENSOR_HEADING])
        elif packet_type == SK7_RAW_DATA_CAP:
            for i in range(12):
                self.data.cap_sk7[0][i] = ord(packetbuf[SK7_RAW_HEADER_LEN+i])
            if self.__shake.data_callback:
                self.__shake.data_callback(SHAKE_SENSOR_CAP, [self.data.cap_sk7[0], 0], self.data.internal_timestamps[SHAKE_SENSOR_CAP])
        elif packet_type == SK7_RAW_DATA_CAP_B:
            for i in range(12):
                self.data.cap_sk7[1][i] = ord(packetbuf[SK7_RAW_HEADER_LEN+i])
            if self.__shake.data_callback:
                self.__shake.data_callback(SHAKE_SENSOR_CAP, [self.data.cap_sk7[1], 1], self.data.internal_timestamps[SHAKE_SENSOR_CAP])
        elif packet_type == SK7_RAW_DATA_CAP_C:
            for i in range(12):
                self.data.cap_sk7[2][i] = ord(packetbuf[SK7_RAW_HEADER_LEN+i])
            if self.__shake.data_callback:
                self.__shake.data_callback(SHAKE_SENSOR_CAP, [self.data.cap_sk7[2], 2], self.data.internal_timestamps[SHAKE_SENSOR_CAP])
        elif packet_type == SK7_RAW_DATA_ANALOG0:
            self.data.ana0 = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
            if has_seq:
                self.data.internal_timestamps[SHAKE_SENSOR_ANA0] = ord(packetbuf[5:6])
            if self.__shake.data_callback:
                self.__shake.data_callback(SHAKE_SENSOR_ANA0, [self.data.ana0], self.data.internal_timestamps[SHAKE_SENSOR_ANA0])
        elif packet_type == SK7_RAW_DATA_ANALOG1:
            self.data.ana1 = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
            if has_seq:
                self.data.internal_timestamps[SHAKE_SENSOR_ANA1] = ord(packetbuf[5:6])
            if self.__shake.data_callback:
                self.__shake.data_callback(SHAKE_SENSOR_ANA1, [self.data.ana1], self.data.internal_timestamps[SHAKE_SENSOR_ANA1])
        elif packet_type == SK7_RAW_DATA_RPH:
            self.data.rph[0] = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
            self.data.rph[1] = pyshake_sk_common.convert_raw_data_value(packetbuf[5:7])
            self.data.rph[2] = pyshake_sk_common.convert_raw_data_value(packetbuf[7:9])
        elif packet_type == SK7_RAW_DATA_RPH_QUATERNION:
            self.data.rphq[0] = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
            self.data.rphq[1] = pyshake_sk_common.convert_raw_data_value(packetbuf[5:7])
            self.data.rphq[2] = pyshake_sk_common.convert_raw_data_value(packetbuf[7:9])
            self.data.rphq[3] = pyshake_sk_common.convert_raw_data_value(packetbuf[9:11])
        elif packet_type == SK7_RAW_DATA_EVENT:
            if self.__shake.navcb != None:
                event = -1
                val = pyshake_sk_common.convert_raw_data_value(packetbuf[3:5])
                if val == 1:
                    event = SHAKE_NAV_UP
                elif val == 2:
                    event = SHAKE_NAV_DOWN
                elif val == 3:
                    event = SHAKE_NAV_CENTRE
                elif val == 4:
                    event = SHAKE_NAV_NORMAL
                else:
                    event = SK7_CS0_UPPER + (val - SK7_DATA_CU0)
                self.__shake.navcb(event)
        elif packet_type == SK7_RAW_DATA_SHAKING:
            if self.__shake.navcb != None:
                self.__shake.navcb(SHAKE_SHAKING_EVENT)
        else:
            return SHAKE_ERROR

        return SHAKE_SUCCESS