Exemple #1
0
static int16_t OSP_ParseSensorDataPkt(SensorPacketTypes_t *pOut,
	uint8_t *pPacket, uint16_t pktSize)
{
	HostIFPackets_t *pHif = (HostIFPackets_t*)pPacket;
	int errCode = -EPROTONOSUPPORT;
	uint8_t sensType;
	uint8_t sensSubType, dSize, dFormat, timeFormat,
		tSize, isPrivateType, hasMetaData;

	/* Sanity... */
	if ((pOut == NULL) || (pPacket == NULL))
		return (-ENOMEM);
	gOSP->isFlushcompleted = 0;
	/* Get sensor type. */
	sensType = M_SensorType(pHif->SensPktRaw.Q.SensorIdByte);
	sensSubType = M_ParseSensorSubType(pHif->SensPktRaw.Q.AttributeByte);
	isPrivateType = pHif->SensPktRaw.Q.ControlByte &
			SENSOR_ANDROID_TYPE_MASK;
	hasMetaData = M_ParseSensorMetaData (pHif->SensPktRaw.Q.SensorIdByte);
	dSize = pHif->SensPktRaw.Q.AttributeByte & DATA_SIZE_MASK;
	dFormat = pHif->SensPktRaw.Q.ControlByte & DATA_FORMAT_MASK;
	timeFormat = pHif->SensPktRaw.Q.ControlByte & TIME_FORMAT_MASK;
	tSize = pHif->SensPktRaw.Q.AttributeByte & TIME_STAMP_SIZE_MASK;
	gOSP->isFlushcompleted = M_FLUSH_COMPLETED(pHif->SensPktRaw.Q.AttributeByte);
	if(gOSP->isFlushcompleted) {
		pr_debug("%s :: %d Flush completed %d for sensor : %d\n",
				__func__, __LINE__, gOSP->isFlushcompleted, sensType);
		pOut->SType = (ASensorType_t)sensType;
		pOut->SubType = SENSOR_SUBTYPE_UNUSED;
		return 3;
	}
	/* Check Sensor enumeration type Android or Private */
	if (!isPrivateType) {
		/*Sensor Enumeration type is Android*/
		errCode = OSP_ParseSensorDataPkt_Android(pOut, pHif,
			(ASensorType_t)sensType,
			sensSubType, dSize,
			dFormat, timeFormat, tSize,
			hasMetaData);
	} else {
		/*Sensor Enumeration type is Private*/
		errCode = OSP_ParseSensorDataPkt_Private(pOut, pHif,
			(ASensorType_t)sensType,
			sensSubType, dSize,
			dFormat, timeFormat, tSize,
			hasMetaData);
	}
	return errCode;
}
/****************************************************************************************************
 * @fn      FormatControlPacketHeader
 *          Fill in packed Control packet header from the parameters provided.
 *
 * @param   [OUT]pDest - Destination buffer supplied by the caller.
 * @param   [IN]packetID - Control Packet type ID
 * @param   [IN]parameterID - Parameter ID for the Control packet
 * @param   [IN]sType - Sensor Type for the Control packet
 * @param   [IN]subType - Sub type for the sensor type used (not applicable for all sensor types)
 * @param   [IN]seqNum - Sequence number to set in the Control packet
 *
 * @return  Negative packed error code corresponding to the error encountered
 *
 ***************************************************************************************************/
static int32_t FormatControlPacketHeader( HostIFPackets_t *pDest, uint8_t packetID, uint8_t parameterID,
                                          ASensorType_t sType, uint8_t subType, uint8_t seqNum )
{
    HifControlPktNoData_t *pOut = (HifControlPktNoData_t *) pDest;

    /* Get packet payload size */
    const int16_t packetPayloadSize = GetControlPacketPayloadSize(packetID, parameterID );

    if ( packetPayloadSize < 0 )
    {
        return SET_ERROR( packetPayloadSize );
    }

    /* Check Sensor enumeration type Android or User defined */
    if (!(IsPrivateNotAndroid(sType)))
    {
        pOut->Q.ControlByte = SENSOR_TYPE_ANDROID;
    }
    else
    {
        pOut->Q.ControlByte = SENSOR_TYPE_PRIVATE;
    }

    /* Setup Control Byte */
    SetPacketID( &(pOut->Q.ControlByte), packetID );

    /* Setup Sensor ID Byte */
    pOut->Q.SensorIdByte = M_SensorType(sType);

    /* Setup Attribute Byte 1 */
    pOut->Q.AttributeByte = M_SensorSubType(subType) | M_SequenceNum(seqNum);

    /* Attribute Byte 2 */
    pOut->AttrByte2 = M_SetParamId(parameterID);

    return packetPayloadSize;
}